mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Type comparisons in GDSL are cached now
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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<Closure> myFilters = []
|
||||
|
||||
private final Set<Pair<String, String>> ASSIGNABLE_TYPES = new HashSet<Pair<String, String>>();
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user