mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
inline GdslMetaClassProperties
This commit is contained in:
@@ -3,12 +3,17 @@ package org.jetbrains.plugins.groovy.dsl
|
||||
import com.intellij.openapi.application.ApplicationInfo
|
||||
import com.intellij.openapi.util.Pair
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.patterns.ElementPattern
|
||||
import com.intellij.patterns.PsiJavaPatterns
|
||||
import com.intellij.util.ProcessingContext
|
||||
import org.jetbrains.plugins.groovy.dsl.psi.PsiEnhancerCategory
|
||||
import org.jetbrains.plugins.groovy.dsl.toplevel.CompositeContextFilter
|
||||
import org.jetbrains.plugins.groovy.dsl.toplevel.Context
|
||||
import org.jetbrains.plugins.groovy.dsl.toplevel.ContextFilter
|
||||
import org.jetbrains.plugins.groovy.dsl.toplevel.GdslMetaClassProperties
|
||||
import org.jetbrains.plugins.groovy.dsl.toplevel.scopes.AnnotatedScope
|
||||
import org.jetbrains.plugins.groovy.dsl.toplevel.scopes.ClassScope
|
||||
import org.jetbrains.plugins.groovy.dsl.toplevel.scopes.ClosureScope
|
||||
import org.jetbrains.plugins.groovy.dsl.toplevel.scopes.ScriptScope
|
||||
|
||||
/**
|
||||
* @author ilyas
|
||||
@@ -36,21 +41,11 @@ public class GroovyDslExecutor {
|
||||
def script = shell.parse(text, fileName)
|
||||
|
||||
def mc = new ExpandoMetaClass(script.class, false)
|
||||
def enhancer = new GdslMetaClassProperties(this)
|
||||
|
||||
mc.methodMissing = { String name, Object args ->
|
||||
return DslPointcut.unknownPointcut()
|
||||
}
|
||||
|
||||
// Fill script with necessary properties
|
||||
def properties = enhancer.metaClass.properties
|
||||
for (MetaProperty p in properties) {
|
||||
if (p.getType() == Closure.class) {
|
||||
mc."$p.name" = p.getProperty(enhancer)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def contribute = {cts, Closure toDo ->
|
||||
if (cts instanceof DslPointcut) {
|
||||
assert cts.operatesOn(GroovyClassDescriptor) : "A non top-level pointcut passed to contributor"
|
||||
@@ -74,12 +69,10 @@ public class GroovyDslExecutor {
|
||||
mc.contributor = contribute
|
||||
mc.contribute = contribute
|
||||
|
||||
mc.supportsVersion = { String ver ->
|
||||
StringUtil.compareVersionNumbers(ideaVersion, ver) >= 0
|
||||
}
|
||||
|
||||
mc.currentType = { arg -> DslPointcut.currentType(arg) }
|
||||
|
||||
oldStylePrimitives(mc)
|
||||
|
||||
mc.initialize()
|
||||
script.metaClass = mc
|
||||
script.run()
|
||||
@@ -87,6 +80,33 @@ public class GroovyDslExecutor {
|
||||
locked = true
|
||||
}
|
||||
|
||||
private void oldStylePrimitives(MetaClass mc) {
|
||||
mc.supportsVersion = { String ver ->
|
||||
StringUtil.compareVersionNumbers(ideaVersion, ver) >= 0
|
||||
}
|
||||
|
||||
/**
|
||||
* Context definition
|
||||
*/
|
||||
mc.context = {Map args -> return new Context(args) }
|
||||
|
||||
/**
|
||||
* Auxiliary methods for context definition
|
||||
*/
|
||||
mc.closureScope = {Map args -> return new ClosureScope(args)}
|
||||
mc.scriptScope = {Map args -> return new ScriptScope(args)}
|
||||
mc.classScope = {Map args -> return new ClassScope(args)}
|
||||
|
||||
/**
|
||||
* @since 10
|
||||
*/
|
||||
mc.annotatedScope = {Map args -> return new AnnotatedScope(args)}
|
||||
|
||||
mc.hasAnnotation = { String annoQName -> PsiJavaPatterns.psiModifierListOwner().withAnnotation(annoQName) }
|
||||
mc.hasField = { ElementPattern fieldCondition -> PsiJavaPatterns.psiClass().withField(true, PsiJavaPatterns.psiField().and(fieldCondition)) }
|
||||
mc.hasMethod = { ElementPattern methodCondition -> PsiJavaPatterns.psiClass().withMethod(true, PsiJavaPatterns.psiMethod().and(methodCondition)) }
|
||||
}
|
||||
|
||||
def addClassEnhancer(List<ContextFilter> cts, Closure toDo) {
|
||||
assert !locked : 'Contributing to GDSL is only allowed at the top-level of the *.gdsl script'
|
||||
enhancers << Pair.create(CompositeContextFilter.compose(cts, false), toDo)
|
||||
|
||||
-45
@@ -1,45 +0,0 @@
|
||||
package org.jetbrains.plugins.groovy.dsl.toplevel
|
||||
|
||||
import com.intellij.patterns.ElementPattern
|
||||
import com.intellij.patterns.PsiJavaPatterns
|
||||
import org.jetbrains.plugins.groovy.dsl.GroovyDslExecutor
|
||||
import org.jetbrains.plugins.groovy.dsl.toplevel.scopes.AnnotatedScope
|
||||
import org.jetbrains.plugins.groovy.dsl.toplevel.scopes.ClassScope
|
||||
import org.jetbrains.plugins.groovy.dsl.toplevel.scopes.ClosureScope
|
||||
import org.jetbrains.plugins.groovy.dsl.toplevel.scopes.ScriptScope
|
||||
|
||||
/**
|
||||
* @author ilyas
|
||||
*/
|
||||
class GdslMetaClassProperties {
|
||||
|
||||
private final GroovyDslExecutor myExecutor
|
||||
|
||||
public GdslMetaClassProperties(GroovyDslExecutor executor) {
|
||||
myExecutor = executor
|
||||
}
|
||||
|
||||
/**
|
||||
* Context definition
|
||||
*/
|
||||
Closure context = {Map args -> return new Context(args) }
|
||||
|
||||
/**
|
||||
* Auxiliary methods for context definition
|
||||
*/
|
||||
Closure closureScope = {Map args -> return new ClosureScope(args)}
|
||||
Closure scriptScope = {Map args -> return new ScriptScope(args)}
|
||||
Closure classScope = {Map args -> return new ClassScope(args)}
|
||||
|
||||
/**
|
||||
* @since 10
|
||||
*/
|
||||
Closure annotatedScope = {Map args -> return new AnnotatedScope(args)}
|
||||
|
||||
Closure hasAnnotation = { String annoQName -> PsiJavaPatterns.psiModifierListOwner().withAnnotation(annoQName) }
|
||||
Closure hasField = { ElementPattern fieldCondition -> PsiJavaPatterns.psiClass().withField(true, PsiJavaPatterns.psiField().and(fieldCondition)) }
|
||||
Closure hasMethod = { ElementPattern methodCondition -> PsiJavaPatterns.psiClass().withMethod(true, PsiJavaPatterns.psiMethod().and(methodCondition)) }
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user