Search in sources :

Example 1 with AntIntrospector

use of com.intellij.lang.ant.AntIntrospector in project intellij-community by JetBrains.

the class AntBuilderMethod method processNestedElements.

public boolean processNestedElements(PsiScopeProcessor processor) {
    final AntIntrospector introspector = AntDomExtender.getIntrospector(myAntClass);
    if (introspector != null) {
        String expectedName = ResolveUtil.getNameHint(processor);
        final PsiType stringType = getParameterList().getParameters()[1].getType();
        final PsiType closureType = getParameterList().getParameters()[2].getType();
        for (String name : Collections.list(introspector.getNestedElements())) {
            if (expectedName == null || expectedName.equals(name)) {
                final AntBuilderMethod method = new AntBuilderMethod(myPlace, name, closureType, introspector.getElementType(name), stringType);
                if (!processor.execute(method, ResolveState.initial()))
                    return false;
            }
        }
    }
    return true;
}
Also used : AntIntrospector(com.intellij.lang.ant.AntIntrospector)

Example 2 with AntIntrospector

use of com.intellij.lang.ant.AntIntrospector in project intellij-community by JetBrains.

the class AntDomExtender method registerExtensions.

public void registerExtensions(@NotNull final AntDomElement antDomElement, @NotNull DomExtensionsRegistrar registrar) {
    final XmlElement xmlElement = antDomElement.getXmlElement();
    if (xmlElement instanceof XmlTag) {
        final XmlTag xmlTag = (XmlTag) xmlElement;
        final String tagName = xmlTag.getName();
        final AntDomProject antProject = antDomElement.getAntProject();
        if (antProject == null) {
            return;
        }
        final ReflectedProject reflected = ReflectedProject.getProject(antProject.getClassLoader());
        if (reflected.getProject() == null) {
            return;
        }
        final DomGenericInfo genericInfo = antDomElement.getGenericInfo();
        AntIntrospector classBasedIntrospector = null;
        final Hashtable<String, Class> coreTaskDefs = reflected.getTaskDefinitions();
        final Hashtable<String, Class> coreTypeDefs = reflected.getDataTypeDefinitions();
        final boolean isCustom = antDomElement instanceof AntDomCustomElement;
        if ("project".equals(tagName)) {
            classBasedIntrospector = getIntrospector(reflected.getProject().getClass());
        } else if ("target".equals(tagName)) {
            classBasedIntrospector = getIntrospector(reflected.getTargetClass());
        } else {
            if (isCustom) {
                final AntDomCustomElement custom = (AntDomCustomElement) antDomElement;
                final Class definitionClass = custom.getDefinitionClass();
                if (definitionClass != null) {
                    classBasedIntrospector = getIntrospector(definitionClass);
                }
            } else {
                Class elemType = antDomElement.getChildDescription().getUserData(ELEMENT_IMPL_CLASS_KEY);
                if (elemType == null) {
                    if (coreTaskDefs != null) {
                        elemType = coreTaskDefs.get(tagName);
                    }
                }
                if (elemType == null) {
                    if (coreTypeDefs != null) {
                        elemType = coreTypeDefs.get(tagName);
                    }
                }
                if (elemType != null) {
                    classBasedIntrospector = getIntrospector(elemType);
                }
            }
        }
        AbstractIntrospector parentIntrospector = null;
        if (classBasedIntrospector != null) {
            parentIntrospector = new ClassIntrospectorAdapter(classBasedIntrospector, coreTaskDefs, coreTypeDefs);
        } else {
            if (isCustom) {
                final AntDomNamedElement declaringElement = ((AntDomCustomElement) antDomElement).getDeclaringElement();
                if (declaringElement instanceof AntDomMacroDef) {
                    parentIntrospector = new MacrodefIntrospectorAdapter((AntDomMacroDef) declaringElement);
                } else if (declaringElement instanceof AntDomMacrodefElement) {
                    parentIntrospector = new MacrodefElementOccurrenceIntrospectorAdapter((AntDomMacrodefElement) declaringElement);
                } else if (declaringElement instanceof AntDomScriptDef) {
                    parentIntrospector = new ScriptdefIntrospectorAdapter((AntDomScriptDef) declaringElement);
                }
            }
        }
        if (parentIntrospector != null) {
            defineAttributes(xmlTag, registrar, genericInfo, parentIntrospector);
            if ("project".equals(tagName) || parentIntrospector.isContainer()) {
                // can contain any task or/and type definition
                if (coreTaskDefs != null) {
                    for (Map.Entry<String, Class> entry : coreTaskDefs.entrySet()) {
                        final DomExtension extension = registerChild(registrar, genericInfo, entry.getKey());
                        if (extension != null) {
                            final Class type = entry.getValue();
                            if (type != null) {
                                extension.putUserData(ELEMENT_IMPL_CLASS_KEY, type);
                            }
                            extension.putUserData(AntDomElement.ROLE, AntDomElement.Role.TASK);
                        }
                    }
                }
                if (coreTypeDefs != null) {
                    for (Map.Entry<String, Class> entry : coreTypeDefs.entrySet()) {
                        final DomExtension extension = registerChild(registrar, genericInfo, entry.getKey());
                        if (extension != null) {
                            final Class type = entry.getValue();
                            if (type != null) {
                                extension.putUserData(ELEMENT_IMPL_CLASS_KEY, type);
                            }
                            extension.putUserData(AntDomElement.ROLE, AntDomElement.Role.DATA_TYPE);
                        }
                    }
                }
                registrar.registerCustomChildrenExtension(AntDomCustomElement.class, new AntCustomTagNameDescriptor());
            } else {
                final Iterator<String> nested = parentIntrospector.getNestedElementsIterator();
                while (nested.hasNext()) {
                    final String nestedElementName = nested.next();
                    final DomExtension extension = registerChild(registrar, genericInfo, nestedElementName);
                    if (extension != null) {
                        Class type = parentIntrospector.getNestedElementType(nestedElementName);
                        if (type != null && CommonClassNames.JAVA_LANG_OBJECT.equals(type.getName())) {
                            // hack to support badly written tasks 
                            type = null;
                        }
                        if (type == null) {
                            if (coreTypeDefs != null) {
                                type = coreTypeDefs.get(nestedElementName);
                            }
                        }
                        if (type != null) {
                            extension.putUserData(ELEMENT_IMPL_CLASS_KEY, type);
                        }
                        AntDomElement.Role role = AntDomElement.Role.DATA_TYPE;
                        if (coreTaskDefs != null && coreTaskDefs.containsKey(nestedElementName)) {
                            role = AntDomElement.Role.TASK;
                        } else if (type != null && isAssignableFrom(Task.class.getName(), type)) {
                            role = AntDomElement.Role.TASK;
                        }
                        if (role != null) {
                            extension.putUserData(AntDomElement.ROLE, role);
                        }
                    }
                }
                registrar.registerCustomChildrenExtension(AntDomCustomElement.class, new AntCustomTagNameDescriptor());
            }
        }
    }
}
Also used : Task(org.apache.tools.ant.Task) ReflectedProject(com.intellij.lang.ant.ReflectedProject) AntIntrospector(com.intellij.lang.ant.AntIntrospector) XmlElement(com.intellij.psi.xml.XmlElement) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

AntIntrospector (com.intellij.lang.ant.AntIntrospector)2 ReflectedProject (com.intellij.lang.ant.ReflectedProject)1 XmlElement (com.intellij.psi.xml.XmlElement)1 XmlTag (com.intellij.psi.xml.XmlTag)1 Task (org.apache.tools.ant.Task)1