Search in sources :

Example 61 with DomElement

use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.

the class InspectionDescriptionInfo method doFindExtension.

@Nullable
private static Extension doFindExtension(Module module, PsiClass psiClass) {
    // Try search in narrow scopes first
    Project project = module.getProject();
    Set<DomFileElement<IdeaPlugin>> processed = new HashSet<>();
    for (GlobalSearchScope scope : DescriptionCheckerUtil.searchScopes(module)) {
        List<DomFileElement<IdeaPlugin>> origElements = DomService.getInstance().getFileElements(IdeaPlugin.class, project, scope);
        origElements.removeAll(processed);
        List<DomFileElement<IdeaPlugin>> elements = PluginDescriptorChooser.findAppropriateIntelliJModule(module.getName(), origElements);
        Query<PsiReference> query = ReferencesSearch.search(psiClass, new LocalSearchScope(elements.stream().map(DomFileElement::getFile).toArray(PsiElement[]::new)));
        Ref<Extension> result = Ref.create(null);
        query.forEach(ref -> {
            PsiElement element = ref.getElement();
            if (element instanceof XmlAttributeValue) {
                PsiElement parent = element.getParent();
                if (parent instanceof XmlAttribute && "implementationClass".equals(((XmlAttribute) parent).getName())) {
                    DomElement domElement = DomUtil.getDomElement(parent.getParent());
                    if (domElement instanceof Extension) {
                        Extension extension = (Extension) domElement;
                        ExtensionPoint extensionPoint = extension.getExtensionPoint();
                        if (extensionPoint != null && InheritanceUtil.isInheritor(extensionPoint.getBeanClass().getValue(), InspectionEP.class.getName())) {
                            result.set(extension);
                            return false;
                        }
                    }
                }
            }
            return true;
        });
        Extension extension = result.get();
        if (extension != null)
            return extension;
        processed.addAll(origElements);
    }
    return null;
}
Also used : LocalSearchScope(com.intellij.psi.search.LocalSearchScope) XmlAttribute(com.intellij.psi.xml.XmlAttribute) ExtensionPoint(org.jetbrains.idea.devkit.dom.ExtensionPoint) DomFileElement(com.intellij.util.xml.DomFileElement) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) Extension(org.jetbrains.idea.devkit.dom.Extension) Project(com.intellij.openapi.project.Project) DomElement(com.intellij.util.xml.DomElement) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) HashSet(java.util.HashSet) Nullable(org.jetbrains.annotations.Nullable)

Example 62 with DomElement

use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.

the class AddWithTagFix method applyFix.

@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
    DomElement element = DomUtil.getDomElement(descriptor.getPsiElement());
    if (!(element instanceof ExtensionPoint)) {
        return;
    }
    ExtensionPoint extensionPoint = (ExtensionPoint) element;
    List<PsiField> fields = extensionPoint.collectMissingWithTags();
    PsiElement navTarget = null;
    for (PsiField field : fields) {
        With with = extensionPoint.addWith();
        String tagName = PluginFieldNameConverter.getAnnotationValue(field, Tag.class);
        if (tagName != null) {
            with.getTag().setStringValue(tagName);
        } else {
            String attributeName = PluginFieldNameConverter.getAttributeAnnotationValue(field);
            if (attributeName == null) {
                attributeName = field.getName();
            }
            if (attributeName.equals("forClass")) {
                continue;
            }
            with.getAttribute().setStringValue(attributeName);
        }
        String epName = extensionPoint.getName().getStringValue();
        String className = "";
        if (epName != null) {
            int pos = epName.lastIndexOf('.');
            epName = StringUtil.capitalize(pos >= 0 ? epName.substring(pos + 1) : epName);
            PsiClass[] classesByName = PsiShortNamesCache.getInstance(project).getClassesByName(epName, ProjectScope.getAllScope(project));
            if (classesByName.length == 1) {
                className = classesByName[0].getQualifiedName();
            }
        }
        with.getImplements().setStringValue(className);
        if (navTarget == null) {
            navTarget = with.getImplements().getXmlAttributeValue();
        }
    }
    if (navTarget != null) {
        PsiNavigateUtil.navigate(navTarget);
    }
}
Also used : DomElement(com.intellij.util.xml.DomElement) ExtensionPoint(org.jetbrains.idea.devkit.dom.ExtensionPoint) PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass) PsiElement(com.intellij.psi.PsiElement) ExtensionPoint(org.jetbrains.idea.devkit.dom.ExtensionPoint) With(org.jetbrains.idea.devkit.dom.With)

Example 63 with DomElement

use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.

the class PsiClassControl method initReferenceEditorWithBrowseButton.

protected static <T extends JPanel> T initReferenceEditorWithBrowseButton(final T boundedComponent, final ReferenceEditorWithBrowseButton editor, final EditorTextFieldControl control) {
    boundedComponent.removeAll();
    boundedComponent.add(editor);
    final GlobalSearchScope resolveScope = control.getDomWrapper().getResolveScope();
    editor.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            final DomElement domElement = control.getDomElement();
            ExtendClass extend = domElement.getAnnotation(ExtendClass.class);
            PsiClass baseClass = null;
            ClassFilter filter = null;
            if (extend != null) {
                baseClass = JavaPsiFacade.getInstance(control.getProject()).findClass(extend.value(), resolveScope);
                if (extend.instantiatable()) {
                    filter = ClassFilter.INSTANTIABLE;
                }
            }
            PsiClass initialClass = null;
            if (domElement instanceof GenericDomValue) {
                final Object value = ((GenericDomValue) domElement).getValue();
                if (value instanceof PsiClass)
                    initialClass = (PsiClass) value;
            }
            TreeClassChooser chooser = TreeClassChooserFactory.getInstance(control.getProject()).createInheritanceClassChooser(UIBundle.message("choose.class"), resolveScope, baseClass, initialClass, filter);
            chooser.showDialog();
            final PsiClass psiClass = chooser.getSelected();
            if (psiClass != null) {
                control.setValue(psiClass.getQualifiedName());
            }
        }
    });
    return boundedComponent;
}
Also used : ExtendClass(com.intellij.util.xml.ExtendClass) TreeClassChooser(com.intellij.ide.util.TreeClassChooser) DomElement(com.intellij.util.xml.DomElement) ActionListener(java.awt.event.ActionListener) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) ActionEvent(java.awt.event.ActionEvent) ClassFilter(com.intellij.ide.util.ClassFilter) GenericDomValue(com.intellij.util.xml.GenericDomValue)

Example 64 with DomElement

use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.

the class PsiTypeControl method setValue.

protected void setValue(String value) {
    final PsiType type = JvmPsiTypeConverterImpl.convertFromString(value, new AbstractConvertContext() {

        @NotNull
        public DomElement getInvocationElement() {
            return getDomElement();
        }
    });
    if (type != null) {
        value = type.getCanonicalText();
    }
    super.setValue(value);
}
Also used : DomElement(com.intellij.util.xml.DomElement) AbstractConvertContext(com.intellij.util.xml.AbstractConvertContext) NotNull(org.jetbrains.annotations.NotNull) PsiType(com.intellij.psi.PsiType)

Example 65 with DomElement

use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.

the class MavenPluginDescriptor method processDescriptors.

public static boolean processDescriptors(Processor<MavenPluginDescriptor> processor, MavenDomConfiguration cfg) {
    Map<String, Map<String, Map<String, List<MavenPluginDescriptor>>>> map = getDescriptorsMap();
    DomElement parent = cfg.getParent();
    MavenDomPlugin plugin = DomUtil.getParentOfType(parent, MavenDomPlugin.class, false);
    if (plugin == null)
        return true;
    Map<String, Map<String, List<MavenPluginDescriptor>>> groupMap = map.get(plugin.getArtifactId().getStringValue());
    if (groupMap == null)
        return true;
    Map<String, List<MavenPluginDescriptor>> goalsMap = groupMap.get(plugin.getGroupId().getStringValue());
    if (goalsMap == null)
        return true;
    List<MavenPluginDescriptor> descriptorsForAllGoals = goalsMap.get(null);
    if (descriptorsForAllGoals != null) {
        for (MavenPluginDescriptor descriptor : descriptorsForAllGoals) {
            if (!processor.process(descriptor))
                return false;
        }
    }
    if (parent instanceof MavenDomPluginExecution) {
        for (MavenDomGoal goal : ((MavenDomPluginExecution) parent).getGoals().getGoals()) {
            List<MavenPluginDescriptor> descriptors = goalsMap.get(goal.getStringValue());
            if (descriptors != null) {
                for (MavenPluginDescriptor descriptor : descriptors) {
                    if (!processor.process(descriptor))
                        return false;
                }
            }
        }
    }
    return true;
}
Also used : MavenDomPluginExecution(org.jetbrains.idea.maven.dom.model.MavenDomPluginExecution) DomElement(com.intellij.util.xml.DomElement) MavenDomPlugin(org.jetbrains.idea.maven.dom.model.MavenDomPlugin) List(java.util.List) SmartList(com.intellij.util.SmartList) HashMap(java.util.HashMap) Map(java.util.Map) MavenDomGoal(org.jetbrains.idea.maven.dom.model.MavenDomGoal)

Aggregations

DomElement (com.intellij.util.xml.DomElement)97 XmlTag (com.intellij.psi.xml.XmlTag)34 PsiElement (com.intellij.psi.PsiElement)19 Nullable (org.jetbrains.annotations.Nullable)19 NotNull (org.jetbrains.annotations.NotNull)15 Project (com.intellij.openapi.project.Project)11 PsiFile (com.intellij.psi.PsiFile)11 XmlFile (com.intellij.psi.xml.XmlFile)11 XmlAttribute (com.intellij.psi.xml.XmlAttribute)10 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)9 ArrayList (java.util.ArrayList)8 LayoutViewElement (org.jetbrains.android.dom.layout.LayoutViewElement)7 ResourceElement (org.jetbrains.android.dom.resources.ResourceElement)6 DomManager (com.intellij.util.xml.DomManager)5 Style (org.jetbrains.android.dom.resources.Style)5 AntDomTarget (com.intellij.lang.ant.dom.AntDomTarget)4 XmlElement (com.intellij.psi.xml.XmlElement)4 DomElementProblemDescriptor (com.intellij.util.xml.highlighting.DomElementProblemDescriptor)4 LookupElement (com.intellij.codeInsight.lookup.LookupElement)3 TextRange (com.intellij.openapi.util.TextRange)3