Search in sources :

Example 71 with XmlAttributeValue

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

the class ParentStyleConverter method createReferences.

@NotNull
@Override
public PsiReference[] createReferences(GenericDomValue<ResourceValue> value, PsiElement element, ConvertContext context) {
    if (element instanceof XmlAttributeValue) {
        // parent="" is allowed; it's used to deliberately allow style A.B.C to not be a child of A.B
        XmlAttributeValue attributeValue = (XmlAttributeValue) element;
        if (attributeValue.isValid() && attributeValue.getValue().isEmpty()) {
            return PsiReference.EMPTY_ARRAY;
        }
    }
    final PsiReference[] refsFromSuper = super.createReferences(value, element, context);
    final ResourceValue resValue = value.getValue();
    if (resValue == null || resValue.getNamespace() != null) {
        return refsFromSuper;
    }
    final AndroidFacet facet = AndroidFacet.getInstance(context);
    if (facet != null) {
        final PsiReference[] refs = getReferencesInStyleName(value, facet);
        if (refs.length > 0) {
            return ArrayUtil.mergeArrays(refsFromSuper, refs);
        }
    }
    return refsFromSuper;
}
Also used : ResourceValue(org.jetbrains.android.dom.resources.ResourceValue) PsiReference(com.intellij.psi.PsiReference) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) AndroidFacet(org.jetbrains.android.facet.AndroidFacet) NotNull(org.jetbrains.annotations.NotNull)

Example 72 with XmlAttributeValue

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

the class AndroidResourceReferenceBase method isReferenceTo.

@Override
public boolean isReferenceTo(PsiElement element) {
    if (element instanceof LazyValueResourceElementWrapper) {
        element = ((LazyValueResourceElementWrapper) element).computeElement();
        if (element == null) {
            return false;
        }
    }
    final ResolveResult[] results = multiResolve(false);
    final PsiFile psiFile = element.getContainingFile();
    final VirtualFile vFile = psiFile != null ? psiFile.getVirtualFile() : null;
    for (ResolveResult result : results) {
        final PsiElement target = result.getElement();
        if (element.getManager().areElementsEquivalent(target, element)) {
            return true;
        }
        if (target instanceof LazyValueResourceElementWrapper && vFile != null) {
            final ValueResourceInfo info = ((LazyValueResourceElementWrapper) target).getResourceInfo();
            if (info.getContainingFile().equals(vFile)) {
                final XmlAttributeValue realTarget = info.computeXmlElement();
                if (element.getManager().areElementsEquivalent(realTarget, element)) {
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LazyValueResourceElementWrapper(org.jetbrains.android.dom.wrappers.LazyValueResourceElementWrapper) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) ValueResourceInfo(org.jetbrains.android.resourceManagers.ValueResourceInfo)

Example 73 with XmlAttributeValue

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

the class AndroidLayoutUtil method getAlias.

@Nullable
public static /*invalid type*/
String getAlias(Import anImport) {
    String aliasValue = null;
    String typeValue = null;
    GenericAttributeValue<String> alias = anImport.getAlias();
    if (alias != null && alias.getXmlAttributeValue() != null) {
        aliasValue = alias.getXmlAttributeValue().getValue();
    }
    GenericAttributeValue<PsiClass> type = anImport.getType();
    if (type != null) {
        XmlAttributeValue value = type.getXmlAttributeValue();
        if (value != null) {
            typeValue = value.getValue();
        }
    }
    return getAlias(typeValue, aliasValue);
}
Also used : PsiClass(com.intellij.psi.PsiClass) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) Nullable(org.jetbrains.annotations.Nullable)

Example 74 with XmlAttributeValue

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

the class ActionScriptAnnotatingVisitor method visitJSReferenceExpression.

@Override
public void visitJSReferenceExpression(JSReferenceExpression node) {
    super.visitJSReferenceExpression(node);
    final PsiElement parent = node.getParent();
    if (node.getQualifier() == null) {
        String nodeText = node.getText();
        if (!(parent instanceof JSCallExpression) && JSResolveUtil.isExprInStrictTypeContext(node) && JSCommonTypeNames.VECTOR_CLASS_NAME.equals(nodeText)) {
            myHolder.createWarningAnnotation(node, JSBundle.message("javascript.validation.message.vector.without.parameters"));
        } else if (parent instanceof JSNewExpression && JSCommonTypeNames.VECTOR_CLASS_NAME.equals(nodeText)) {
            myHolder.createWarningAnnotation(node, JSBundle.message("javascript.validation.message.vector.without.parameters2"));
        }
    }
    if (parent instanceof JSNamedElement) {
        JSNamedElement namedElement = (JSNamedElement) parent;
        final ASTNode nameIdentifier = namedElement.findNameIdentifier();
        if (nameIdentifier != null && nameIdentifier.getPsi() == node) {
            if (parent instanceof JSPackageStatement) {
                checkPackageStatement((JSPackageStatement) parent);
            } else if (!(parent instanceof JSImportStatement) && parent.getParent() instanceof JSPackageStatement) {
                checkNamedObjectIsInCorrespondingFile(namedElement);
            } else if (parent instanceof JSVariable) {
                if (parent.getParent().getParent() instanceof JSPackageStatement) {
                    checkNamedObjectIsInCorrespondingFile((JSVariable) parent);
                }
            } else if (parent instanceof JSNamespaceDeclaration) {
                DuplicatesCheckUtil.checkDuplicates((JSNamespaceDeclaration) parent, myProblemReporter);
            }
            if (parent instanceof JSClass) {
                final JSClass jsClass = (JSClass) parent;
                final JSFunction constructor = jsClass.getConstructor();
                if (constructor == null)
                    createConstructorChecker().checkMissedConstructor(jsClass);
                PsiElement clazzParent = jsClass.getParent();
                final PsiElement context = clazzParent.getContext();
                boolean clazzParentIsInjectedJsFile = clazzParent instanceof JSFile && (context instanceof XmlAttributeValue || context instanceof XmlText) && !XmlBackedJSClassImpl.isImplementsAttribute((JSFile) clazzParent);
                if (PsiTreeUtil.getParentOfType(jsClass, JSFunction.class, JSClass.class) != null || clazzParentIsInjectedJsFile) {
                    myHolder.createErrorAnnotation(node, JSBundle.message("javascript.validation.message.nested.classes.are.not.allowed"));
                }
                checkClass(jsClass);
            }
        }
    }
    JSFunction fun;
    if (JSSymbolUtil.isAccurateReferenceExpressionName(node, JSFunction.ARGUMENTS_VAR_NAME) && (fun = PsiTreeUtil.getParentOfType(node, JSFunction.class)) != null && node.resolve() instanceof ImplicitJSVariableImpl) {
        JSParameterList parameterList = fun.getParameterList();
        if (parameterList != null) {
            for (JSParameter p : parameterList.getParameterVariables()) {
                if (p.isRest()) {
                    myHolder.createErrorAnnotation(node, JSBundle.message("javascript.validation.message.arguments.with.rest.parameter"));
                }
            }
        }
    }
}
Also used : XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) ASTNode(com.intellij.lang.ASTNode) XmlText(com.intellij.psi.xml.XmlText)

Example 75 with XmlAttributeValue

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

the class DataBindingCompletionUtil method fillAliases.

/**
   * Add completion suggestions for classes included via {@code <import>}s.
   * @param resultSet the set to add the suggestions to.
   */
private static void fillAliases(@NotNull CompletionResultSet resultSet, @NotNull String packagePrefix, @NotNull PsiElement originalPosition, @NotNull Module module, @NotNull PsiElement originalParent) {
    PsiFile containingFile = getRealContainingFile(originalParent.getContainingFile());
    if (containingFile instanceof XmlFile) {
        final Project project = module.getProject();
        DomManager domManager = DomManager.getDomManager(project);
        XmlTag tag = PsiTreeUtil.getParentOfType(originalPosition, XmlTag.class, false, PsiFile.class);
        if (domManager.getDomElement(tag) instanceof Import) {
            // No referencing aliases in import tags.
            return;
        }
        DomFileElement<Layout> file = domManager.getFileElement((XmlFile) containingFile, Layout.class);
        if (file != null) {
            JavaPsiFacade facade = JavaPsiFacade.getInstance(project);
            for (Data data : file.getRootElement().getDatas()) {
                for (Import anImport : data.getImports()) {
                    String alias = AndroidLayoutUtil.getAlias(anImport);
                    if (packagePrefix.isEmpty()) {
                        XmlAttributeValue type = anImport.getType().getXmlAttributeValue();
                        if (type != null && alias != null) {
                            String typeValue = type.getValue().replace('$', '.');
                            PsiClass aClass = facade.findClass(typeValue, module.getModuleWithDependenciesAndLibrariesScope(false));
                            if (aClass != null) {
                                resultSet.addElement(getClassReferenceElement(alias, aClass));
                            }
                        }
                    } else {
                        int i = packagePrefix.indexOf('.');
                        String possibleAlias = i < 0 ? packagePrefix : packagePrefix.substring(0, i);
                        if (possibleAlias.equals(alias)) {
                            String type = anImport.getType().getStringValue();
                            if (type != null) {
                                String fqcn = packagePrefix.equals(alias) ? type : type + packagePrefix.substring(alias.length());
                                PsiClass aClass = facade.findClass(fqcn, module.getModuleWithDependenciesAndLibrariesScope(false));
                                if (aClass != null) {
                                    for (PsiClass innerClass : aClass.getInnerClasses()) {
                                        String name = innerClass.getQualifiedName();
                                        if (name != null) {
                                            resultSet.addElement(getClassReferenceElement(name.substring(type.length() + 1), innerClass));
                                        }
                                    }
                                    break;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
}
Also used : Import(org.jetbrains.android.dom.layout.Import) XmlFile(com.intellij.psi.xml.XmlFile) DomManager(com.intellij.util.xml.DomManager) Data(org.jetbrains.android.dom.layout.Data) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) Project(com.intellij.openapi.project.Project) Layout(org.jetbrains.android.dom.layout.Layout) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)127 XmlAttribute (com.intellij.psi.xml.XmlAttribute)57 XmlTag (com.intellij.psi.xml.XmlTag)50 NotNull (org.jetbrains.annotations.NotNull)38 PsiElement (com.intellij.psi.PsiElement)31 Nullable (org.jetbrains.annotations.Nullable)24 PsiReference (com.intellij.psi.PsiReference)20 XmlFile (com.intellij.psi.xml.XmlFile)19 TextRange (com.intellij.openapi.util.TextRange)18 VirtualFile (com.intellij.openapi.vfs.VirtualFile)15 ArrayList (java.util.ArrayList)13 Project (com.intellij.openapi.project.Project)12 AndroidFacet (org.jetbrains.android.facet.AndroidFacet)10 DomElement (com.intellij.util.xml.DomElement)9 PsiFile (com.intellij.psi.PsiFile)8 LazyValueResourceElementWrapper (org.jetbrains.android.dom.wrappers.LazyValueResourceElementWrapper)7 XmlAttributeDescriptor (com.intellij.xml.XmlAttributeDescriptor)6 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)5 Module (com.intellij.openapi.module.Module)5 ValueResourceElementWrapper (org.jetbrains.android.dom.wrappers.ValueResourceElementWrapper)5