Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Basic PHP support (AST edges etc.) and DeclarationUsage edge providing #38

Merged
merged 7 commits into from
Jan 24, 2023

Conversation

max-martynov
Copy link
Collaborator

No description provided.

@egor-bogomolov
Copy link
Collaborator

Begins implementation of #32

Copy link
Collaborator

@egor-bogomolov egor-bogomolov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome job 🚀 Could you please fix a few minor comments before merging?

build.gradle.kts Outdated
@@ -57,7 +57,7 @@ allprojects {
type.set(getProperty("platformType"))
downloadSources.set(getProperty("platformDownloadSources").toBoolean())
updateSinceUntilBuild.set(true)
plugins.set(getProperty("platformPlugins").split(',').map(String::trim).filter(String::isNotEmpty))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's avoid duplicating string constants and load them from gradle.properties when possible. In future, we should do the same for different lib versions that are shared in multiple places.

        val platformVersion = getProperty("platformVersion")
        version.set(platformVersion)
        type.set(getProperty("platformType"))
        downloadSources.set(getProperty("platformDownloadSources").toBoolean())
        updateSinceUntilBuild.set(true)
        plugins.set(
            getProperty("platformPlugins").split(',').map(String::trim).filter(String::isNotEmpty) +
                    listOf("com.jetbrains.php:$platformVersion")
        )

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I moved the declaration of this plugin to the gradle.properties, however the version specification is still required. So it builds only when like this:

kotlin.code.style=official

platformType=IU
platformVersion=222.4345.14
platformDownloadSources=true
platformPlugins = com.intellij.java, org.jetbrains.kotlin, android, maven, gradle, Groovy, com.jetbrains.php:222.4345.14
...

Is it okay?

when (language) {
Language.Java -> JsonGraphStorage(outputDirectory, JavaGraphMiner())
Language.PHP -> JsonGraphStorage(outputDirectory, PhpGraphMiner())
else -> throw IllegalArgumentException("rip")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's write more elaborate error messages 🤣

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops 🤪
Wanted to change it but forgot...

@@ -24,7 +24,8 @@ enum class Dataset(val folderName: String) {

enum class Language(val extensions: List<String>) {
Java(listOf("java")),
Kotlin(listOf("kt", "kts"))
Kotlin(listOf("kt", "kts")),
PHP(listOf("php"))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In theory, there are older PHP extensions such as php3, php4, php5, phps. Will parsing work for them and should we add them to the list?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, hard to say because I didn't manage to find any examples of such files. Even the oldest PHP files on GitHub have .php extension so I'd rather not support any other formats. If you have another opinion, we can always change it quickly.


override fun getBodyNode(root: PsiElement): PsiElement? =
(root as? MethodImpl)?.lastChild
?: throw IllegalArgumentException("Try to extract name not from the method")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Error message should mention body. Let's move the exceptions to a separate file in order to avoid duplicating and keeping them consistent across languages.

?: throw IllegalArgumentException("Try to extract name not from the method")

override fun getDocComment(root: PsiElement): PsiElement? {
return PsiTreeUtil.collectElementsOfType(root, PhpDocCommentImpl::class.java).firstOrNull()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be cleaner to use the PhpDocComment interface rather than its implementation, as in the future there might be a different implementation of this interface.

}

override fun getNonDocComments(root: PsiElement): Collection<PsiElement> {
return PsiTreeUtil.collectElementsOfType(root, PsiComment::class.java).filterNot { it is PhpDocCommentImpl }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same about PhpDocComment

(root as? MethodImpl)?.name == "__construct"

override fun hasModifier(root: PsiElement, modifier: String): Boolean =
(root as? MethodImpl)?.modifier?.toString()?.split(' ')?.contains(modifier)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you cast to PsiMethod or MethodImpl is strictly necessary here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tested casting to PsiMethod and it didn't work :(

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, let's put here a comment with TODO to investigate it later

import psi.transformations.PhpTreeTransformation

class ExcludePhpSymbolsTransformation : PhpTreeTransformation, ExcludeNodeTransformation() {
private val skipElementTypes = listOf("(", ")", "{", "}", "arrow", "semicolon", "comma", "dot")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to use in it might be a good idea to make a set rather than a list.

Copy link
Collaborator

@egor-bogomolov egor-bogomolov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great, now the PR looks good!

(root as? MethodImpl)?.name == "__construct"

override fun hasModifier(root: PsiElement, modifier: String): Boolean =
(root as? MethodImpl)?.modifier?.toString()?.split(' ')?.contains(modifier)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Weird, let's put here a comment with TODO to investigate it later

@@ -19,4 +19,7 @@ abstract class MethodProvider {
open fun stringsToCommentString(c: Collection<String>): String {
return c.filterNot { it.none { s -> s.isLetterOrDigit() } }.flatMap { splitToSubtokens(it) }.joinToString("|")
}

open class NotAMethodException(absentToken: String) :
IllegalArgumentException("Try to extract $absentToken not from the method")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change wording here. I suggest something like this: "Cannot extract $absentToken : class $className is not a method". For this, you should also pass the encountered class name.

@@ -3,7 +3,7 @@ kotlin.code.style=official
platformType=IU
platformVersion=222.4345.14
platformDownloadSources=true
platformPlugins = com.intellij.java, org.jetbrains.kotlin, android, maven, gradle, Groovy
platformPlugins = com.intellij.java, org.jetbrains.kotlin, android, maven, gradle, Groovy, com.jetbrains.php:222.4345.14
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did not know it, but gradle.properties actually does not support string interpolation 😞

Let's keep it like this for now, but I guess we should move constants to build file or some separate file in the future.

@egor-bogomolov egor-bogomolov merged commit 5ac3e75 into main Jan 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants