mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
structural search: groovy should work in community
This commit is contained in:
@@ -1517,6 +1517,7 @@
|
||||
<classTypePointerFactory implementation="org.jetbrains.plugins.groovy.lang.psi.impl.smartPointers.GrClassReferenceTypePointerFactory"/>
|
||||
<hierarchy.referenceProcessor implementation="org.jetbrains.plugins.groovy.hierarchy.call.GrCallReferenceProcessor"/>
|
||||
<structuralsearch.profile implementation="com.intellij.structuralsearch.GroovyStructuralSearchProfile"/>
|
||||
<equivalenceDescriptorProvider implementation="com.intellij.structuralsearch.GroovyEquivalenceDescriptorProvider"/>
|
||||
</extensions>
|
||||
|
||||
<extensions defaultExtensionNs="com.intellij.debugger">
|
||||
|
||||
+99
@@ -0,0 +1,99 @@
|
||||
package com.intellij.structuralsearch;
|
||||
|
||||
import com.intellij.dupLocator.equivalence.EquivalenceDescriptor;
|
||||
import com.intellij.dupLocator.equivalence.EquivalenceDescriptorBuilder;
|
||||
import com.intellij.dupLocator.equivalence.EquivalenceDescriptorProvider;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.groovy.GroovyLanguage;
|
||||
import org.jetbrains.plugins.groovy.lang.lexer.TokenSets;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariableDeclaration;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.blocks.GrCodeBlock;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.clauses.GrForInClause;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.params.GrParameter;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrReferenceList;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinitionBody;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.members.GrMethod;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.util.GrStatementOwner;
|
||||
|
||||
/**
|
||||
* @author Eugene.Kudelevsky
|
||||
*/
|
||||
public class GroovyEquivalenceDescriptorProvider extends EquivalenceDescriptorProvider {
|
||||
private static final TokenSet IGNORED_TOKENS = TokenSet.orSet(TokenSets.WHITE_SPACES_OR_COMMENTS, TokenSets.SEPARATORS);
|
||||
|
||||
@Override
|
||||
public boolean isMyContext(@NotNull PsiElement context) {
|
||||
return context.getLanguage().isKindOf(GroovyLanguage.INSTANCE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EquivalenceDescriptor buildDescriptor(@NotNull PsiElement e) {
|
||||
final EquivalenceDescriptorBuilder builder = new EquivalenceDescriptorBuilder();
|
||||
|
||||
if (e instanceof GrVariableDeclaration) {
|
||||
return builder.elements(((GrVariableDeclaration)e).getVariables());
|
||||
}
|
||||
else if (e instanceof GrParameter) {
|
||||
final GrParameter p = (GrParameter)e;
|
||||
return builder
|
||||
.element(p.getNameIdentifierGroovy())
|
||||
.optionally(p.getTypeElementGroovy())
|
||||
.optionallyInPattern(p.getInitializerGroovy());
|
||||
}
|
||||
else if (e instanceof GrVariable) {
|
||||
final GrVariable v = (GrVariable)e;
|
||||
return builder
|
||||
.element(v.getNameIdentifierGroovy())
|
||||
.optionally(v.getTypeElementGroovy())
|
||||
.optionallyInPattern(v.getInitializerGroovy());
|
||||
}
|
||||
else if (e instanceof GrMethod) {
|
||||
final GrMethod m = (GrMethod)e;
|
||||
return builder
|
||||
.element(m.getNameIdentifierGroovy())
|
||||
.elements(m.getParameters())
|
||||
.optionally(m.getReturnTypeElementGroovy())
|
||||
.optionallyInPattern(m.getBlock());
|
||||
}
|
||||
else if (e instanceof GrTypeDefinitionBody) {
|
||||
final GrTypeDefinitionBody b = (GrTypeDefinitionBody)e;
|
||||
return builder
|
||||
.inAnyOrder(b.getFields())
|
||||
.inAnyOrder(b.getMethods())
|
||||
.inAnyOrder(b.getInitializers())
|
||||
.inAnyOrder(b.getInnerClasses());
|
||||
}
|
||||
else if (e instanceof GrTypeDefinition) {
|
||||
GrTypeDefinition d = (GrTypeDefinition)e;
|
||||
return builder.element(d.getNameIdentifierGroovy())
|
||||
.optionallyInPattern(d.getExtendsClause())
|
||||
.optionallyInPattern(d.getImplementsClause())
|
||||
.optionallyInPattern(d.getBody());
|
||||
}
|
||||
else if (e instanceof GrForInClause) {
|
||||
final GrForInClause f = (GrForInClause)e;
|
||||
return builder
|
||||
.element(f.getDeclaredVariable())
|
||||
.element(f.getIteratedExpression());
|
||||
}
|
||||
else if (e instanceof GrReferenceList) {
|
||||
return builder.inAnyOrder(((GrReferenceList)e).getReferenceElementsGroovy());
|
||||
}
|
||||
else if (e instanceof GrCodeBlock) {
|
||||
return builder.codeBlock(((GrStatementOwner)e).getStatements());
|
||||
}
|
||||
|
||||
// todo: support 'object method()' <-> 'object.method()'
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TokenSet getIgnoredTokens() {
|
||||
return IGNORED_TOKENS;
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@
|
||||
<orderEntry type="module" module-name="lang-impl" />
|
||||
<orderEntry type="module" module-name="structuralsearch-tests" scope="TEST" />
|
||||
<orderEntry type="module" module-name="testFramework-java" scope="TEST" />
|
||||
<orderEntry type="module" module-name="duplicates-analysis" scope="TEST" />
|
||||
<orderEntry type="module" module-name="duplicates-analysis" />
|
||||
</component>
|
||||
</module>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user