Search in sources :

Example 26 with XmlElement

use of com.intellij.psi.xml.XmlElement in project android by JetBrains.

the class DimensionConverter method getVariants.

@NotNull
@Override
public Collection<String> getVariants(ConvertContext context) {
    final XmlElement element = context.getXmlElement();
    if (element == null) {
        return Collections.emptyList();
    }
    final String value = ResourceReferenceConverter.getValue(element);
    if (value == null) {
        return Collections.emptyList();
    }
    final String intPrefix = getIntegerPrefix(value);
    if (intPrefix.isEmpty()) {
        return Collections.emptyList();
    }
    final List<String> result = new ArrayList<>(ourUnits.size());
    for (String unit : ourUnits.keySet()) {
        result.add(intPrefix + unit);
    }
    return result;
}
Also used : XmlElement(com.intellij.psi.xml.XmlElement) NotNull(org.jetbrains.annotations.NotNull)

Example 27 with XmlElement

use of com.intellij.psi.xml.XmlElement in project intellij-community by JetBrains.

the class ExtendsClassChecker method checkExtendsClassInReferences.

public static List<DomElementProblemDescriptor> checkExtendsClassInReferences(final GenericDomValue element, final DomElementAnnotationHolder holder) {
    if (!isPsiClassType(element)) {
        return Collections.emptyList();
    }
    final Object valueObject = element.getValue();
    if (!(valueObject instanceof PsiClass))
        return Collections.emptyList();
    final XmlElement valueElement = DomUtil.getValueElement(element);
    if (valueElement == null)
        return Collections.emptyList();
    final PsiReference[] references = ourProvider.getReferencesByElement(valueElement, new ProcessingContext());
    for (PsiReference reference : references) {
        if (reference instanceof JavaClassReference) {
            final PsiReferenceProvider psiReferenceProvider = ((JavaClassReference) reference).getProvider();
            final String[] value = psiReferenceProvider instanceof JavaClassReferenceProvider ? JavaClassReferenceProvider.EXTEND_CLASS_NAMES.getValue(((JavaClassReferenceProvider) psiReferenceProvider).getOptions()) : null;
            if (value != null && value.length != 0) {
                for (String className : value) {
                    final List<DomElementProblemDescriptor> problemDescriptors = checkExtendClass(element, ((PsiClass) valueObject), className, false, false, true, false, true, true, holder);
                    if (!problemDescriptors.isEmpty()) {
                        return problemDescriptors;
                    }
                }
            }
        }
    }
    return Collections.emptyList();
}
Also used : ProcessingContext(com.intellij.util.ProcessingContext) JavaClassReference(com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReference) JavaClassReferenceProvider(com.intellij.psi.impl.source.resolve.reference.impl.providers.JavaClassReferenceProvider) DomElementProblemDescriptor(com.intellij.util.xml.highlighting.DomElementProblemDescriptor) XmlElement(com.intellij.psi.xml.XmlElement)

Example 28 with XmlElement

use of com.intellij.psi.xml.XmlElement in project intellij-plugins by JetBrains.

the class Struts2ModelInspectionVisitor method checkExtendableClassConverter.

private void checkExtendableClassConverter(final GenericAttributeValue clazzAttributeValue) {
    if (myIgnoreExtendableClass)
        return;
    final XmlElement xmlElement = DomUtil.getValueElement(clazzAttributeValue);
    if (xmlElement == null) {
        return;
    }
    final PsiReference[] psiReferences = xmlElement.getReferences();
    for (final PsiReference psiReference : psiReferences) {
        final PsiElement resolveElement = psiReference.resolve();
        if (resolveElement instanceof PsiClass) {
            return;
        }
    }
    final String[] referenceTypesUserData = clazzAttributeValue.getUserData(ExtendableClassConverter.REFERENCES_TYPES);
    final String referenceTypes = referenceTypesUserData != null ? StringUtil.join(referenceTypesUserData, "|") : StrutsBundle.message("dom.extendable.class.converter.type.class");
    final String message = StrutsBundle.message("dom.extendable.class.converter.cannot.resolve", referenceTypes, clazzAttributeValue.getStringValue());
    // merge all available QuickFixes (create class/package(s)..)
    LocalQuickFix[] quickFixes = LocalQuickFix.EMPTY_ARRAY;
    for (final PsiReference psiReference : psiReferences) {
        if (psiReference instanceof LocalQuickFixProvider) {
            final LocalQuickFix[] fixes = ((LocalQuickFixProvider) psiReference).getQuickFixes();
            if (fixes != null) {
                quickFixes = ArrayUtil.mergeArrays(fixes, quickFixes);
            }
        }
    }
    holder.createProblem(clazzAttributeValue, message, quickFixes);
}
Also used : LocalQuickFixProvider(com.intellij.codeInspection.LocalQuickFixProvider) PsiClass(com.intellij.psi.PsiClass) XmlElement(com.intellij.psi.xml.XmlElement) PsiReference(com.intellij.psi.PsiReference) LocalQuickFix(com.intellij.codeInspection.LocalQuickFix) PsiElement(com.intellij.psi.PsiElement)

Example 29 with XmlElement

use of com.intellij.psi.xml.XmlElement in project intellij-plugins by JetBrains.

the class StrutsPathReferenceConverterImpl method fromString.

public PathReference fromString(@Nullable final String value, final ConvertContext context) {
    if (value == null) {
        return null;
    }
    final XmlElement element = context.getReferenceXmlElement();
    if (element == null) {
        return null;
    }
    final Module module = context.getModule();
    if (module == null) {
        return null;
    }
    return PathReferenceManager.getInstance().getCustomPathReference(value, module, element, getResultContributors());
}
Also used : XmlElement(com.intellij.psi.xml.XmlElement) Module(com.intellij.openapi.module.Module)

Example 30 with XmlElement

use of com.intellij.psi.xml.XmlElement in project intellij-plugins by JetBrains.

the class IncludeFileResolvingConverterImpl method fromString.

public PsiFile fromString(@Nullable @NonNls final String value, final ConvertContext context) {
    if (value == null) {
        return null;
    }
    final XmlElement xmlElement = context.getReferenceXmlElement();
    if (xmlElement == null) {
        return null;
    }
    final PsiReference[] references = createReferences((GenericDomValue) context.getInvocationElement(), xmlElement, context);
    if (references.length == 0) {
        return null;
    }
    final PsiElement element = references[references.length - 1].resolve();
    return element instanceof PsiFile ? (PsiFile) element : null;
}
Also used : XmlElement(com.intellij.psi.xml.XmlElement) PsiReference(com.intellij.psi.PsiReference) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement)

Aggregations

XmlElement (com.intellij.psi.xml.XmlElement)69 PsiElement (com.intellij.psi.PsiElement)16 NotNull (org.jetbrains.annotations.NotNull)16 Nullable (org.jetbrains.annotations.Nullable)11 XmlTag (com.intellij.psi.xml.XmlTag)10 PsiFile (com.intellij.psi.PsiFile)7 PsiReference (com.intellij.psi.PsiReference)6 XmlAttribute (com.intellij.psi.xml.XmlAttribute)6 XmlFile (com.intellij.psi.xml.XmlFile)6 Manifest (org.jetbrains.android.dom.manifest.Manifest)5 Module (com.intellij.openapi.module.Module)4 Project (com.intellij.openapi.project.Project)4 DomElement (com.intellij.util.xml.DomElement)4 ArrayList (java.util.ArrayList)4 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)3 CompositePsiElement (com.intellij.psi.impl.source.tree.CompositePsiElement)3 SmartList (com.intellij.util.SmartList)3 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)3 ResourceType (com.android.resources.ResourceType)2 Result (com.intellij.openapi.application.Result)2