mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
name pointcut for methods
This commit is contained in:
@@ -113,18 +113,29 @@ public abstract class DslPointcut<T,V> {
|
||||
if (src instanceof GdslType) {
|
||||
return arg.equals(((GdslType)src).getName()) ? Arrays.asList((String)arg) : null;
|
||||
}
|
||||
if (src instanceof GdslMethod) {
|
||||
return arg.equals(((GdslMethod)src).getName()) ? Arrays.asList((String)arg) : null;
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean operatesOn(Class c) {
|
||||
return c == GdslType.class;
|
||||
return c == GdslType.class || c == GdslMethod.class;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public static DslPointcut<GroovyClassDescriptor, GdslMethod> enclosingMethod(final Object arg) {
|
||||
final DslPointcut<? super GdslMethod,?> inner;
|
||||
if (arg instanceof String) {
|
||||
inner = name(arg);
|
||||
} else {
|
||||
inner = (DslPointcut<GdslMethod, ?>)arg;
|
||||
assert inner.operatesOn(GdslMethod.class) : "The argument to enclosingMethod should be a pointcut working with types, e.g. name";
|
||||
}
|
||||
|
||||
return new DslPointcut<GroovyClassDescriptor, GdslMethod>() {
|
||||
@Override
|
||||
List<GdslMethod> matches(GroovyClassDescriptor src, ProcessingContext context) {
|
||||
@@ -135,8 +146,9 @@ public abstract class DslPointcut<T,V> {
|
||||
if (method == null) {
|
||||
break;
|
||||
}
|
||||
if (arg.equals(method.getName())) {
|
||||
result.add(new GdslMethod());
|
||||
final GdslMethod wrapper = new GdslMethod(method);
|
||||
if (inner.matches(wrapper, context) != null) {
|
||||
result.add(wrapper);
|
||||
}
|
||||
place = method;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,18 @@
|
||||
package org.jetbrains.plugins.groovy.dsl;
|
||||
|
||||
import com.intellij.psi.PsiMethod;
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
public class GdslMethod {
|
||||
public final PsiMethod psiMethod;
|
||||
|
||||
public GdslMethod(PsiMethod psiMethod) {
|
||||
this.psiMethod = psiMethod;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return psiMethod.getName();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,6 +70,14 @@ class Foo {
|
||||
'''
|
||||
}
|
||||
|
||||
public void testMethodName() {
|
||||
checkHighlighting 'contribute(enclosingMethod(name("goo"))) { property name:"foo" }',
|
||||
'''
|
||||
def goo() { println foo + "".foo }
|
||||
def doo() { println <warning>foo</warning> }
|
||||
'''
|
||||
}
|
||||
|
||||
|
||||
private def checkHighlighting(String dsl, String code) {
|
||||
def file = myFixture.addFileToProject('a.gdsl', dsl)
|
||||
|
||||
Reference in New Issue
Block a user