mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-06 06:21:16 +07:00
groovy: package dependency visitor implementation
This commit is contained in:
@@ -1105,6 +1105,9 @@
|
||||
level="WARNING"
|
||||
implementationClass="org.jetbrains.plugins.groovy.codeInspection.bugs.GrEqualsBetweenInconvertibleTypesInspection"/>
|
||||
|
||||
<packageDependencies.visitor language="Groovy"
|
||||
implementationClass="org.jetbrains.plugins.groovy.codeInspection.dependencies.GrDependencyVisitorFactory"/>
|
||||
|
||||
<implicitUsageProvider implementation="org.jetbrains.plugins.groovy.findUsages.GrImplicitUsageProvider"/>
|
||||
|
||||
<scratch.rootType implementation="org.jetbrains.plugins.groovy.console.GroovyConsoleRootType"/>
|
||||
|
||||
+85
@@ -0,0 +1,85 @@
|
||||
/*
|
||||
* 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.openapi.progress.ProgressIndicatorProvider
|
||||
import com.intellij.packageDependencies.DependenciesBuilder
|
||||
import com.intellij.packageDependencies.DependencyVisitorFactory
|
||||
import com.intellij.psi.PsiElement
|
||||
import com.intellij.psi.PsiElementVisitor
|
||||
import com.intellij.psi.PsiFile
|
||||
import org.jetbrains.annotations.NotNull
|
||||
import org.jetbrains.plugins.groovy.lang.groovydoc.psi.api.GrDocComment
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyElementVisitor
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFile
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyPsiElement
|
||||
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
|
||||
|
||||
class GrDependencyVisitorFactory extends DependencyVisitorFactory {
|
||||
@NotNull
|
||||
@Override
|
||||
PsiElementVisitor getVisitor(@NotNull DependenciesBuilder.DependencyProcessor processor,
|
||||
@NotNull DependencyVisitorFactory.VisitorOptions options) {
|
||||
GroovyElementVisitor visitor = new MyVisitor(processor, options)
|
||||
new PsiElementVisitor() {
|
||||
@Override
|
||||
void visitFile(PsiFile file) {
|
||||
if (file instanceof GroovyFile) {
|
||||
file.accept(visitor)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static class MyVisitor extends GroovyRecursiveElementVisitor {
|
||||
private final DependenciesBuilder.DependencyProcessor myProcessor
|
||||
private final DependencyVisitorFactory.VisitorOptions myOptions
|
||||
|
||||
MyVisitor(DependenciesBuilder.DependencyProcessor processor, DependencyVisitorFactory.VisitorOptions options) {
|
||||
myOptions = options
|
||||
myProcessor = processor
|
||||
}
|
||||
|
||||
@Override
|
||||
void visitElement(GroovyPsiElement element) {
|
||||
ProgressIndicatorProvider.checkCanceled()
|
||||
|
||||
super.visitElement(element)
|
||||
|
||||
element.references.each {
|
||||
PsiElement resolved = it.resolve();
|
||||
if (resolved != null) {
|
||||
myProcessor.process(it.element, resolved);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void visitImportStatement(GrImportStatement statement) {
|
||||
if (!myOptions.skipImports()) {
|
||||
visitElement(statement);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
void visitDocComment(GrDocComment comment) {}
|
||||
|
||||
@Override
|
||||
void visitLiteralExpression(GrLiteral literal) {}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user