Search in sources :

Example 66 with XmlElement

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

the class ActionScriptImportHandler method _resolveTypeName.

// TODO _str should be JSReferenceExpression for caching!
@Nullable
private JSImportedElementResolveResult _resolveTypeName(@Nullable final String _name, @NotNull PsiElement context) {
    String name = _name;
    if (name == null)
        return null;
    JSResolveUtil.GenericSignature genericSignature = JSResolveUtil.extractGenericSignature(name);
    if (genericSignature != null) {
        name = genericSignature.elementType;
    }
    final Ref<JSImportedElementResolveResult> resultRef = new Ref<>();
    final String name1 = name;
    JSResolveUtil.walkOverStructure(context, context1 -> {
        JSImportedElementResolveResult resolved = null;
        if (context1 instanceof XmlBackedJSClassImpl) {
            XmlTag rootTag = ((XmlBackedJSClassImpl) context1).getParent();
            if (rootTag != null && name1.equals(rootTag.getLocalName())) {
                final XmlElementDescriptor descriptor = rootTag.getDescriptor();
                PsiElement element = descriptor != null ? descriptor.getDeclaration() : null;
                if (element instanceof XmlFile) {
                    element = XmlBackedJSClassFactory.getXmlBackedClass((XmlFile) element);
                }
                final String s = element instanceof JSClass ? ((JSClass) element).getQualifiedName() : rootTag.getLocalName();
                resolved = new JSImportedElementResolveResult(s);
            } else {
                resolved = resolveTypeNameUsingImports(name1, context1);
            }
        } else if (context1 instanceof JSQualifiedNamedElement) {
            if (context1 instanceof JSClass && name1.equals(context1.getName())) {
                resolved = new JSImportedElementResolveResult(((JSQualifiedNamedElement) context1).getQualifiedName());
            } else {
                resolved = resolveTypeNameUsingImports(name1, context1);
                if (resolved == null && context1.getParent() instanceof JSFile) {
                    final String qName = ((JSQualifiedNamedElement) context1).getQualifiedName();
                    final String packageName = qName == null ? "" : context1 instanceof JSPackageStatement ? qName + "." : qName.substring(0, qName.lastIndexOf('.') + 1);
                    if (packageName.length() != 0) {
                        final PsiElement byQName = JSClassResolver.findClassFromNamespace(packageName + name1, context1);
                        if (byQName instanceof JSQualifiedNamedElement) {
                            resolved = new JSImportedElementResolveResult(((JSQualifiedNamedElement) byQName).getQualifiedName());
                        }
                    }
                }
            }
        } else {
            resolved = resolveTypeNameUsingImports(name1, context1);
            PsiElement contextOfContext;
            if (resolved == null && context1 instanceof JSFile && (contextOfContext = context1.getContext()) != null) {
                XmlBackedJSClassImpl clazz = contextOfContext instanceof XmlElement ? (XmlBackedJSClassImpl) XmlBackedJSClassImpl.getContainingComponent((XmlElement) contextOfContext) : null;
                if (clazz != null) {
                    SinkResolveProcessor r = new SinkResolveProcessor(name1, new ResolveResultSink(null, name1));
                    r.setForceImportsForPlace(true);
                    boolean b = clazz.doImportFromScripts(r, clazz);
                    if (!b) {
                        PsiElement resultFromProcessor = r.getResult();
                        JSQualifiedNamedElement clazzFromComponent = resultFromProcessor instanceof JSQualifiedNamedElement ? (JSQualifiedNamedElement) resultFromProcessor : null;
                        if (clazzFromComponent != null) {
                            resolved = new JSImportedElementResolveResult(clazzFromComponent.getQualifiedName(), clazz, null);
                        }
                    }
                }
            }
        }
        if (resolved != null) {
            resultRef.set(resolved);
            return false;
        }
        if (context1 instanceof JSPackageStatement)
            return false;
        return true;
    });
    JSImportedElementResolveResult result = resultRef.get();
    if (genericSignature != null && result != null) {
        // TODO: more than one type parameter
        StringBuilder genericSignatureBuffer = new StringBuilder();
        genericSignatureBuffer.append(".<");
        genericSignatureBuffer.append(resolveTypeName(genericSignature.genericType, context).getQualifiedName());
        genericSignatureBuffer.append(">");
        result = result.appendSignature(genericSignatureBuffer.toString());
    }
    return result;
}
Also used : XmlBackedJSClassImpl(com.intellij.lang.javascript.flex.XmlBackedJSClassImpl) XmlFile(com.intellij.psi.xml.XmlFile) JSPackageStatement(com.intellij.lang.javascript.psi.ecmal4.JSPackageStatement) JSQualifiedNamedElement(com.intellij.lang.javascript.psi.ecmal4.JSQualifiedNamedElement) Ref(com.intellij.openapi.util.Ref) XmlElement(com.intellij.psi.xml.XmlElement) JSFile(com.intellij.lang.javascript.psi.JSFile) XmlElementDescriptor(com.intellij.xml.XmlElementDescriptor) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 67 with XmlElement

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

the class ExtendableClassConverterImpl method fromString.

public PsiClass fromString(@Nullable @NonNls final String s, final ConvertContext context) {
    if (s == null) {
        return null;
    }
    // resolve JAVA-class directly
    final PsiClass psiClass = DomJavaUtil.findClass(s, context.getInvocationElement());
    if (psiClass != null) {
        return psiClass;
    }
    // first match in additional providers
    final XmlElement element = context.getReferenceXmlElement();
    assert element != null;
    final ExtendClass extendClass = getExtendsAnnotation(context.getInvocationElement());
    for (final ExtendableClassConverterContributor contributor : Extensions.getExtensions(EP_NAME)) {
        if (contributor.isSuitable(context)) {
            final PsiReference[] add = contributor.getReferences(context, element, extendClass);
            if (add.length == 1) {
                final PsiElement resolveElement = add[0].resolve();
                if (resolveElement != null) {
                    return (PsiClass) resolveElement;
                }
            }
        }
    }
    return null;
}
Also used : PsiClass(com.intellij.psi.PsiClass) XmlElement(com.intellij.psi.xml.XmlElement) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement)

Example 68 with XmlElement

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

the class FieldNameConverterImpl method findBeanPropertyClass.

@Override
protected PsiClass findBeanPropertyClass(@NotNull final DomElement domElement) {
    final XmlElement xmlElement = domElement.getXmlElement();
    assert xmlElement != null;
    final PsiFile psiFile = xmlElement.getContainingFile().getOriginalFile();
    final PsiDirectory containingDirectory = psiFile.getContainingDirectory();
    if (containingDirectory == null) {
        return null;
    }
    final PsiPackage containingPackage = JavaDirectoryService.getInstance().getPackage(containingDirectory);
    if (containingPackage == null) {
        return null;
    }
    // ClassName-[method-]validation.xml
    final String validationFileName = psiFile.getName();
    final String actionClassName = StringUtil.split(validationFileName, "-").get(0);
    final String qualifiedActionClassName = StringUtil.getQualifiedName(containingPackage.getQualifiedName(), actionClassName);
    final JavaPsiFacade psiFacade = JavaPsiFacade.getInstance(psiFile.getProject());
    return psiFacade.findClass(qualifiedActionClassName, new PackageScope(containingPackage, false, false));
}
Also used : PackageScope(com.intellij.psi.search.PackageScope) XmlElement(com.intellij.psi.xml.XmlElement)

Example 69 with XmlElement

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

the class StrutsDataModel method addNode.

private void addNode(final BasicStrutsNode node) {
    if (!node.getIdentifyingElement().isValid()) {
        return;
    }
    myNodes.add(node);
    if (isGroupElements()) {
        final XmlElement element = node.getIdentifyingElement().getXmlElement();
        assert element != null;
        final PsiFile file = element.getContainingFile();
        if (file != null && !myGroups.containsKey(file)) {
            final String name = file.getName();
            final BasicNodesGroup group = new BasicNodesGroup(name) {

                @Nullable
                public GroupNodeRealizer getGroupNodeRealizer() {
                    final GroupNodeRealizer groupNodeRealizer = super.getGroupNodeRealizer();
                    assert groupNodeRealizer != null;
                    final NodeLabel nodeLabel = groupNodeRealizer.getLabel();
                    nodeLabel.setText("      " + getGroupName());
                    nodeLabel.setModel(NodeLabel.INTERNAL);
                    nodeLabel.setPosition(NodeLabel.TOP_RIGHT);
                    return groupNodeRealizer;
                }
            };
            // collapse all other files
            group.setClosed(file != myFile);
            myGroups.put(file, group);
        }
    }
}
Also used : GroupNodeRealizer(com.intellij.openapi.graph.view.hierarchy.GroupNodeRealizer) NodeLabel(com.intellij.openapi.graph.view.NodeLabel) XmlElement(com.intellij.psi.xml.XmlElement) PsiFile(com.intellij.psi.PsiFile) BasicNodesGroup(com.intellij.openapi.graph.builder.components.BasicNodesGroup)

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