diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/CustomMembersGenerator.groovy b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/CustomMembersGenerator.groovy index 16c005e6e15e..c718c1b31bb4 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/CustomMembersGenerator.groovy +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/CustomMembersGenerator.groovy @@ -31,17 +31,32 @@ public class CustomMembersGenerator implements GdslMembersHolderConsumer { myQualifiedName = qualifiedName; } - def methodMissing(String name, args) { + private Object[] constructNewArgs(Object args) { final def newArgs = new Object[args.length + 1] for (int i = 0; i < args.length; i++) { newArgs[i] = args[i] } newArgs[args.length] = this + return newArgs + } + + def methodMissing(String name, args) { + final def newArgs = constructNewArgs(args) // Get other DSL methods from extensions for (d in GdslMembersProvider.EP_NAME.getExtensions()) { final def variants = d.metaClass.respondsTo(d, name, newArgs) if (variants.size() == 1) { + + /*def cachedMethod = { Object[] args1 -> + final def newArgs1 = constructNewArgs(args1) + return d.invokeMethod(name, newArgs1) + } + + // Cache method + this.class.metaClass."$name" = cachedMethod + + return cachedMethod(args)*/ return d.invokeMethod(name, newArgs) } } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/toplevel/Context.groovy b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/toplevel/Context.groovy index f01699fc44b8..8a47cc78ad6b 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/toplevel/Context.groovy +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/dsl/toplevel/Context.groovy @@ -1,5 +1,6 @@ package org.jetbrains.plugins.groovy.dsl.toplevel +import com.intellij.openapi.util.Pair import com.intellij.openapi.util.text.StringUtil import com.intellij.psi.search.GlobalSearchScope import com.intellij.psi.util.PsiTreeUtil @@ -15,6 +16,7 @@ import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrRefere import org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.path.GrMethodCallExpression import org.jetbrains.plugins.groovy.lang.psi.api.statements.typedef.GrTypeDefinition import com.intellij.psi.* +import com.intellij.util.containers.HashSet /** * @author ilyas @@ -23,6 +25,8 @@ class Context { private List myFilters = [] + private final Set> ASSIGNABLE_TYPES = new HashSet>(); + public Context(Map args) { // Basic filter, all contexts are applicable for reference expressions only myFilters << {PsiElement elem, fqn -> elem instanceof GrReferenceExpression} @@ -32,12 +36,21 @@ class Context { Closure getClassTypeFilter(ctype) { return {GrReferenceExpression ref, String fqn -> + if (!(ctype instanceof String)) return false + final def pair = new Pair(((String) ctype), fqn) + + if (ASSIGNABLE_TYPES.contains(pair)) return true PsiManager manager = PsiManager.getInstance(ref.getProject()) def scope = GlobalSearchScope.allScope(ref.getProject()) - PsiType superType = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createTypeByFQClassName(ctype, scope) + PsiType superType = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory(). + createTypeByFQClassName(((String)ctype), scope) if (!superType) return false def type = JavaPsiFacade.getInstance(manager.getProject()).getElementFactory().createTypeByFQClassName(fqn, scope) - return type && superType?.isAssignableFrom(type) && type.isAssignableFrom(superType) + def result = type && superType?.isAssignableFrom(type) && type.isAssignableFrom(superType) + if (result) { + ASSIGNABLE_TYPES.add(pair) + } + return result } }