IDEA-CR-2791 (static compilation; test)

This commit is contained in:
Roman Shevchenko
2015-05-20 16:08:44 +02:00
parent 1bf710baf3
commit 7031b474cf
2 changed files with 47 additions and 3 deletions
@@ -21,6 +21,8 @@ import com.intellij.packageDependencies.DependencyVisitorFactory
import com.intellij.psi.PsiElement
import com.intellij.psi.PsiElementVisitor
import com.intellij.psi.PsiFile
import com.intellij.psi.PsiReference
import groovy.transform.CompileStatic
import org.jetbrains.annotations.NotNull
import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment
import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor
@@ -30,6 +32,7 @@ import org.jetbrains.plugins.groovy.lang.psi.GroovyRecursiveElementVisitor
import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.literals.GrLiteral
import org.jetbrains.plugins.groovy.lang.psi.api.toplevel.imports.GrImportStatement
@CompileStatic
class GrDependencyVisitorFactory extends DependencyVisitorFactory {
@NotNull
@Override
@@ -46,6 +49,7 @@ class GrDependencyVisitorFactory extends DependencyVisitorFactory {
}
}
@CompileStatic
private static class MyVisitor extends GroovyRecursiveElementVisitor {
private final DependenciesBuilder.DependencyProcessor myProcessor
private final DependencyVisitorFactory.VisitorOptions myOptions
@@ -61,10 +65,10 @@ class GrDependencyVisitorFactory extends DependencyVisitorFactory {
super.visitElement(element)
element.references.each {
PsiElement resolved = it.resolve();
element.references.each { PsiReference ref ->
PsiElement resolved = ref.resolve();
if (resolved != null) {
myProcessor.process(it.element, resolved);
myProcessor.process(ref.element, resolved);
}
}
}
@@ -0,0 +1,40 @@
/*
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.plugins.groovy.codeInspection.dependencies
import com.intellij.packageDependencies.DependenciesBuilder
import com.intellij.packageDependencies.DependencyVisitorFactory
import groovy.transform.CompileStatic
import org.jetbrains.plugins.groovy.LightGroovyTestCase
@CompileStatic
class GrDependencyVisitorTest extends LightGroovyTestCase {
@Override
protected String getBasePath() {
return ""
}
void test() {
def file = myFixture.addFileToProject("C.groovy", "import groovy.util.ConfigObject\nclass C { }")
def deps = []
DependenciesBuilder.analyzeFileDependencies(file, { _, dep -> deps << dep }, DependencyVisitorFactory.VisitorOptions.SKIP_IMPORTS)
assert deps.size() == 0
DependenciesBuilder.analyzeFileDependencies(file, { _, dep -> deps << dep }, DependencyVisitorFactory.VisitorOptions.INCLUDE_IMPORTS)
assert deps.size() == 3
}
}