mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
name pointcut for types
This commit is contained in:
@@ -106,6 +106,24 @@ public abstract class DslPointcut<T,V> {
|
||||
};
|
||||
}
|
||||
|
||||
public static DslPointcut<Object, String> name(final Object arg) {
|
||||
return new DslPointcut<Object, String>() {
|
||||
@Override
|
||||
List<String> matches(Object src, ProcessingContext context) {
|
||||
if (src instanceof GdslType) {
|
||||
return arg.equals(((GdslType)src).getName()) ? Arrays.asList((String)arg) : null;
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean operatesOn(Class c) {
|
||||
return c == GdslType.class;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public static DslPointcut<GroovyClassDescriptor, GdslMethod> enclosingMethod(final Object arg) {
|
||||
return new DslPointcut<GroovyClassDescriptor, GdslMethod>() {
|
||||
@Override
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.jetbrains.plugins.groovy.dsl;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiClassType;
|
||||
import com.intellij.psi.PsiType;
|
||||
@@ -15,6 +16,10 @@ public class GdslType {
|
||||
this.psiType = psiType;
|
||||
}
|
||||
|
||||
public String getShortName() {
|
||||
return StringUtil.getShortName(getName());
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
PsiType type = psiType;
|
||||
if (type instanceof PsiWildcardType) {
|
||||
|
||||
@@ -27,6 +27,15 @@ class DsldTest extends LightGroovyTestCase {
|
||||
'println "".foo + [].<warning>foo</warning>'
|
||||
}
|
||||
|
||||
public void testTypeName() {
|
||||
checkHighlighting 'contribute(currentType(name("Foo"))) { property name:"foo" }',
|
||||
'''
|
||||
class Foo {}
|
||||
class Bar extends Foo {}
|
||||
println new Foo().foo + new Bar().<warning>foo</warning>
|
||||
'''
|
||||
}
|
||||
|
||||
public void testBind() {
|
||||
checkHighlighting 'contribute(bind(types:currentType("java.lang.CharSequence"))) { property name:types[0].name[-3..-1] }',
|
||||
'println "".ing + "".<warning>foo</warning>'
|
||||
@@ -43,6 +52,9 @@ class DsldTest extends LightGroovyTestCase {
|
||||
class Foo {
|
||||
def goo() { println foo + "".foo }
|
||||
}
|
||||
class Bar extends Foo {
|
||||
def goo() { println <warning>foo</warning> }
|
||||
}
|
||||
println new Foo().<warning>foo</warning>
|
||||
println <warning>foo</warning>
|
||||
'''
|
||||
|
||||
Reference in New Issue
Block a user