mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
implicit bind
This commit is contained in:
@@ -11,6 +11,18 @@ import java.util.*;
|
||||
* @author peter
|
||||
*/
|
||||
public abstract class DslPointcut<T,V> {
|
||||
public static final DslPointcut UNKNOWN = new DslPointcut() {
|
||||
|
||||
@Override
|
||||
List matches(Object src, ProcessingContext context) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean operatesOn(Class c) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
public static Key<Map<String, List>> BOUND = Key.create("gdsl.bound");
|
||||
|
||||
@Nullable
|
||||
@@ -63,18 +75,4 @@ public abstract class DslPointcut<T,V> {
|
||||
};
|
||||
}
|
||||
|
||||
public static DslPointcut unknownPointcut() {
|
||||
return new DslPointcut() {
|
||||
|
||||
@Override
|
||||
List matches(Object src, ProcessingContext context) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
boolean operatesOn(Class c) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,11 +43,11 @@ public class GroovyDslExecutor {
|
||||
|
||||
def mc = new ExpandoMetaClass(script.class, false)
|
||||
|
||||
mc.methodMissing = { String name, Object args ->
|
||||
return DslPointcut.unknownPointcut()
|
||||
}
|
||||
mc.methodMissing = { String name, Object args -> return DslPointcut.UNKNOWN }
|
||||
|
||||
def contribute = {cts, Closure toDo ->
|
||||
cts = handleImplicitBind(cts)
|
||||
|
||||
if (cts instanceof DslPointcut) {
|
||||
assert cts.operatesOn(GroovyClassDescriptor) : "A non top-level pointcut passed to contributor"
|
||||
addClassEnhancer([new PointcutContextFilter(cts)], toDo)
|
||||
@@ -70,7 +70,7 @@ public class GroovyDslExecutor {
|
||||
mc.contributor = contribute
|
||||
mc.contribute = contribute
|
||||
|
||||
mc.currentType = { arg -> DslPointcut.currentType(arg) }
|
||||
mc.currentType = { arg -> DslPointcut.currentType(handleImplicitBind(arg)) }
|
||||
mc.bind = { arg -> DslPointcut.bind(arg) }
|
||||
|
||||
oldStylePrimitives(mc)
|
||||
@@ -82,6 +82,13 @@ public class GroovyDslExecutor {
|
||||
locked = true
|
||||
}
|
||||
|
||||
private def handleImplicitBind(arg) {
|
||||
if (arg instanceof Map && arg.size() == 1 && arg.keySet().iterator().next() instanceof String && arg.values().iterator().next() instanceof DslPointcut) {
|
||||
return DslPointcut.bind(arg)
|
||||
}
|
||||
return arg
|
||||
}
|
||||
|
||||
private void oldStylePrimitives(MetaClass mc) {
|
||||
mc.supportsVersion = { String ver ->
|
||||
StringUtil.compareVersionNumbers(ideaVersion, ver) >= 0
|
||||
|
||||
@@ -27,6 +27,11 @@ class DsldTest extends LightGroovyTestCase {
|
||||
'println "".ing + "".<warning>foo</warning>'
|
||||
}
|
||||
|
||||
public void testImplicitBind() {
|
||||
checkHighlighting 'contribute(types:currentType("java.lang.CharSequence")) { property name:types[0].name[-3..-1] }',
|
||||
'println "".ing + "".<warning>foo</warning>'
|
||||
}
|
||||
|
||||
private def checkHighlighting(String dsl, String code) {
|
||||
def file = myFixture.addFileToProject('a.gdsl', dsl)
|
||||
GroovyDslFileIndex.activateUntilModification(file.virtualFile)
|
||||
|
||||
Reference in New Issue
Block a user