Search in sources :

Example 1 with ReflectedProject

use of com.intellij.lang.ant.ReflectedProject 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)

Example 2 with ReflectedProject

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

the class AntDomProject method getProperties.

private Map<String, String> getProperties() {
    Map<String, String> properties = myProperties;
    if (properties == null) {
        final ReflectedProject reflected = ReflectedProject.getProject(getClassLoader());
        Map<String, String> externals = Collections.emptyMap();
        final PsiFile containingFile = getXmlTag().getContainingFile();
        if (containingFile != null) {
            final AntBuildFileImpl buildFile = (AntBuildFileImpl) AntConfigurationBase.getInstance(containingFile.getProject()).getAntBuildFile(containingFile);
            if (buildFile != null) {
                externals = buildFile.getExternalProperties();
            }
        }
        myProperties = (properties = loadPredefinedProperties(reflected.getProperties(), externals));
    }
    return properties;
}
Also used : ReflectedProject(com.intellij.lang.ant.ReflectedProject) AntBuildFileImpl(com.intellij.lang.ant.config.impl.AntBuildFileImpl) PsiFile(com.intellij.psi.PsiFile)

Aggregations

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