mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
dsld: don't fail on unknown pointcuts
This commit is contained in:
@@ -6,10 +6,11 @@ import com.intellij.openapi.util.text.StringUtil
|
||||
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
|
||||
|
||||
/**
|
||||
/**
|
||||
* @author ilyas
|
||||
*/
|
||||
|
||||
@@ -37,6 +38,10 @@ public class GroovyDslExecutor {
|
||||
def mc = new ExpandoMetaClass(script.class, false)
|
||||
def enhancer = new GdslMetaClassProperties(this)
|
||||
|
||||
mc.methodMissing = { String name, Object args ->
|
||||
return new Context([:])
|
||||
}
|
||||
|
||||
// Fill script with necessary properties
|
||||
def properties = enhancer.metaClass.properties
|
||||
for (MetaProperty p in properties) {
|
||||
@@ -45,6 +50,24 @@ public class GroovyDslExecutor {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def contribute = {cts, Closure toDo ->
|
||||
if (cts instanceof Map) {
|
||||
cts = new Context(cts)
|
||||
}
|
||||
if (!(cts instanceof List)) {
|
||||
assert cts instanceof Context: "The contributor() argument must be a context"
|
||||
cts = [cts]
|
||||
}
|
||||
def contexts = cts.findAll { it != null } as List
|
||||
if (contexts) {
|
||||
def filters = contexts.collect { return it.filter }
|
||||
addClassEnhancer(filters, toDo)
|
||||
}
|
||||
}
|
||||
mc.contributor = contribute
|
||||
mc.contribute = contribute
|
||||
|
||||
mc.supportsVersion = { String ver ->
|
||||
StringUtil.compareVersionNumbers(ideaVersion, ver) >= 0
|
||||
}
|
||||
|
||||
-18
@@ -24,24 +24,6 @@ class GdslMetaClassProperties {
|
||||
*/
|
||||
Closure context = {Map args -> return new Context(args) }
|
||||
|
||||
/**
|
||||
* Contributor definition
|
||||
*/
|
||||
Closure contributor = {cts, Closure toDo ->
|
||||
if (cts instanceof Map) {
|
||||
cts = new Context(cts)
|
||||
}
|
||||
if (!(cts instanceof List)) {
|
||||
assert cts instanceof Context: "The contributor() argument must be a context"
|
||||
cts = [cts]
|
||||
}
|
||||
def contexts = cts.findAll { it != null } as List
|
||||
if (contexts) {
|
||||
def filters = contexts.collect { return it.filter }
|
||||
myExecutor.addClassEnhancer(filters, toDo)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Auxiliary methods for context definition
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
package org.jetbrains.plugins.groovy.dsl
|
||||
|
||||
import org.jetbrains.plugins.groovy.LightGroovyTestCase
|
||||
import org.jetbrains.plugins.groovy.codeInspection.untypedUnresolvedAccess.GroovyUnresolvedAccessInspection
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
class DsldTest extends LightGroovyTestCase {
|
||||
@Override
|
||||
protected String getBasePath() {
|
||||
return ''
|
||||
}
|
||||
|
||||
public void testUnknownPointcut() {
|
||||
def file = myFixture.addFileToProject('a.gdsl', "contribute(asdfsadf()) { property name:'foo', type:'String' }")
|
||||
GroovyDslFileIndex.activateUntilModification(file.virtualFile)
|
||||
|
||||
checkHighlighting('println foo.substring(2) + <warning>bar</warning>')
|
||||
}
|
||||
|
||||
private def checkHighlighting(String text) {
|
||||
myFixture.configureByText('a.groovy', text)
|
||||
myFixture.enableInspections(new GroovyUnresolvedAccessInspection())
|
||||
myFixture.checkHighlighting(true, false, false)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user