From d2e266e6dc0165f97e4c8a75c36ea25681504c78 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Thu, 21 Oct 2010 21:45:27 +0400 Subject: [PATCH] supported "extension point" types (IDEA-59873) --- .../intellij/lang/ant/dom/AntDomExtender.java | 49 +++++++++++++++++-- 1 file changed, 46 insertions(+), 3 deletions(-) diff --git a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomExtender.java b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomExtender.java index e2da0d24508d..049acd6840ec 100644 --- a/plugins/ant/src/com/intellij/lang/ant/dom/AntDomExtender.java +++ b/plugins/ant/src/com/intellij/lang/ant/dom/AntDomExtender.java @@ -138,7 +138,7 @@ public class AntDomExtender extends DomExtender{ AbstractIntrospector parentIntrospector = null; if (classBasedIntrospector != null) { - parentIntrospector = new ClassIntrospectorAdapter(classBasedIntrospector); + parentIntrospector = new ClassIntrospectorAdapter(classBasedIntrospector, coreTaskDefs, coreTypeDefs); } else { if (isCustom) { @@ -438,9 +438,19 @@ public class AntDomExtender extends DomExtender{ private static class ClassIntrospectorAdapter extends AbstractIntrospector { private final AntIntrospector myIntrospector; + private final Map myCoreTaskDefs; + private final Map myCoreTypeDefs; + private List myNestedElements; + private Map myNestedElementTypes; private ClassIntrospectorAdapter(AntIntrospector introspector) { + this(introspector, null, null); + } + + public ClassIntrospectorAdapter(AntIntrospector introspector, Map coreTaskDefs, Map coreTypeDefs) { myIntrospector = introspector; + myCoreTaskDefs = coreTaskDefs != null? coreTaskDefs : Collections.emptyMap(); + myCoreTypeDefs = coreTypeDefs != null? coreTypeDefs : Collections.emptyMap(); } @NotNull @@ -458,11 +468,44 @@ public class AntDomExtender extends DomExtender{ @NotNull public Iterator getNestedElementsIterator() { - return new EnumerationToIteratorAdapter(myIntrospector.getNestedElements()); + initNestedElements(); + return myNestedElements.iterator(); } public Class getNestedElementType(String attribName) { - return myIntrospector.getElementType(attribName); + initNestedElements(); + return myNestedElementTypes.get(attribName); + } + + private void initNestedElements() { + if (myNestedElements != null) { + return; + } + myNestedElements = new ArrayList(); + myNestedElementTypes = new HashMap(); + final Enumeration nestedElements = myIntrospector.getNestedElements(); + while (nestedElements.hasMoreElements()) { + final String elemName = nestedElements.nextElement(); + myNestedElements.add(elemName); + myNestedElementTypes.put(elemName, myIntrospector.getElementType(elemName)); + } + + final Set extensionPointTypes = myIntrospector.getExtensionPointTypes(); + for (String extPoint : extensionPointTypes) { + processEntries(extPoint, myCoreTaskDefs); + processEntries(extPoint, myCoreTypeDefs); + } + } + + private void processEntries(String extPoint, final Map definitions) { + for (Map.Entry entry : definitions.entrySet()) { + final String elementName = entry.getKey(); + final Class taskClass = entry.getValue(); + if (isAssignableFrom(extPoint, taskClass)) { + myNestedElements.add(elementName); + myNestedElementTypes.put(elementName, taskClass); + } + } } }