Search in sources :

Example 16 with XmlToken

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

the class AngularJSXmlCompletionContributor method fillCompletionVariants.

@Override
public void fillCompletionVariants(@NotNull CompletionParameters parameters, @NotNull CompletionResultSet result) {
    final PsiElement originalPosition = parameters.getOriginalPosition();
    if (originalPosition != null && AngularIndexUtil.hasAngularJS(originalPosition.getProject())) {
        final PsiElement position = originalPosition instanceof XmlToken ? originalPosition.getParent() : originalPosition;
        if (AngularJSReferencesContributor.NG_APP_REF.accepts(position)) {
            final Collection<String> keys = AngularIndexUtil.getAllKeys(AngularModuleIndex.KEY, originalPosition.getProject());
            addCompletionVariants(result, keys, " (AngularJS module)");
            result.stopHere();
        } else if (AngularJSReferencesContributor.UI_VIEW_REF.accepts(position)) {
            final Collection<String> keys = AngularIndexUtil.getAllKeys(AngularUiRouterStatesIndex.KEY, originalPosition.getProject());
            addCompletionVariants(result, keys, " (angular-ui-router state)");
            result.stopHere();
        }
    }
}
Also used : Collection(java.util.Collection) PsiElement(com.intellij.psi.PsiElement) XmlToken(com.intellij.psi.xml.XmlToken)

Example 17 with XmlToken

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

the class AndroidInlineLayoutHandler method getLayoutUsageDataFromContext.

@Nullable
private static LayoutUsageData getLayoutUsageDataFromContext(Editor editor) {
    if (editor == null) {
        return null;
    }
    final PsiElement element = PsiUtilBase.getElementAtCaret(editor);
    if (!(element instanceof XmlToken) || AndroidFacet.getInstance(element) == null) {
        return null;
    }
    final XmlTag tag = PsiTreeUtil.getParentOfType(element, XmlTag.class);
    return tag != null ? AndroidInlineUtil.getLayoutUsageData(tag) : null;
}
Also used : PsiElement(com.intellij.psi.PsiElement) XmlToken(com.intellij.psi.xml.XmlToken) XmlTag(com.intellij.psi.xml.XmlTag) Nullable(org.jetbrains.annotations.Nullable)

Example 18 with XmlToken

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

the class XmlBackedClassLineMarkerProvider method collectSlowLineMarkers.

public void collectSlowLineMarkers(@NotNull List<PsiElement> elements, @NotNull Collection<LineMarkerInfo> result) {
    for (PsiElement element : elements) {
        ProgressManager.checkCanceled();
        if (element instanceof XmlTag && element.getParent() instanceof XmlDocument && element.getContainingFile() != null && JavaScriptSupportLoader.isFlexMxmFile(element.getContainingFile())) {
            final XmlBackedJSClass clazz = XmlBackedJSClassFactory.getInstance().getXmlBackedClass((XmlTag) element);
            Query<JSClass> classQuery = JSClassSearch.searchClassInheritors(clazz, true);
            XmlToken nameElement = XmlTagUtil.getStartTagNameElement((XmlTag) element);
            if (classQuery.findFirst() != null && nameElement != null) {
                result.add(new LineMarkerInfo<>(clazz, nameElement.getTextRange(), AllIcons.Gutter.OverridenMethod, Pass.LINE_MARKERS, JavaScriptLineMarkerProvider.ourClassInheritorsTooltipProvider, JavaScriptLineMarkerProvider.ourClassInheritorsNavHandler, GutterIconRenderer.Alignment.RIGHT));
            }
        }
    }
}
Also used : XmlBackedJSClass(com.intellij.lang.javascript.psi.ecmal4.XmlBackedJSClass) XmlDocument(com.intellij.psi.xml.XmlDocument) XmlBackedJSClass(com.intellij.lang.javascript.psi.ecmal4.XmlBackedJSClass) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag) XmlToken(com.intellij.psi.xml.XmlToken)

Example 19 with XmlToken

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

the class ActionScriptTypeEvaluator method addTypeFromElementResolveResult.

@Override
protected boolean addTypeFromElementResolveResult(PsiElement resolveResult, boolean hasSomeType) {
    if (resolveResult instanceof JSOffsetBasedImplicitElement && JavaScriptSupportLoader.isFlexMxmFile(resolveResult.getContainingFile())) {
        resolveResult = ((JSOffsetBasedImplicitElement) resolveResult).getElementAtOffset();
    }
    if (resolveResult instanceof XmlToken) {
        final XmlToken xmlToken = (XmlToken) resolveResult;
        final XmlAttribute xmlAttribute = PsiTreeUtil.getParentOfType(xmlToken, XmlAttribute.class);
        final XmlTag xmlTag = PsiTreeUtil.getParentOfType(xmlToken, XmlTag.class);
        if (xmlToken.getTokenType() == XmlTokenType.XML_ATTRIBUTE_VALUE_TOKEN && xmlAttribute != null && "id".equals(xmlAttribute.getName()) && xmlTag != null && isInsideRepeaterTag(xmlTag)) {
            final PsiElement arrayClass = ActionScriptClassResolver.findClassByQNameStatic(ARRAY_CLASS_NAME, xmlToken);
            if (arrayClass != null) {
                final String arrayType = new JSTagContextBuilder(resolveResult, null).typeName;
                JSTypeSource source = JSTypeSourceFactory.createTypeSource(resolveResult);
                JSType type;
                if (arrayType != null) {
                    JSType baseType = JSNamedType.createType(arrayType, source, JSContext.INSTANCE);
                    type = new JSArrayTypeImpl(baseType, source);
                } else {
                    type = new JSPrimitiveArrayType(source, JSTypeContext.INSTANCE);
                }
                addType(type, arrayClass);
            }
        } else {
            final XmlTag tag = PsiTreeUtil.getParentOfType(resolveResult, XmlTag.class, false);
            final JSClass clazz = JSResolveUtil.getClassFromTagNameInMxml(tag);
            if (clazz != null) {
                final String name = clazz.getQualifiedName();
                if (name != null) {
                    addType(name, clazz);
                }
            }
        }
        return hasSomeType;
    }
    return super.addTypeFromElementResolveResult(resolveResult, hasSomeType);
}
Also used : XmlAttribute(com.intellij.psi.xml.XmlAttribute) JSPrimitiveArrayType(com.intellij.lang.javascript.psi.types.primitives.JSPrimitiveArrayType) JSOffsetBasedImplicitElement(com.intellij.lang.javascript.psi.impl.JSOffsetBasedImplicitElement) JSClass(com.intellij.lang.javascript.psi.ecmal4.JSClass) PsiElement(com.intellij.psi.PsiElement) XmlToken(com.intellij.psi.xml.XmlToken) XmlTag(com.intellij.psi.xml.XmlTag)

Example 20 with XmlToken

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

the class JavaFxCollapseSubTagToAttributeIntention method isAvailable.

@Override
public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
    if (element instanceof XmlToken && ((XmlToken) element).getTokenType() == XmlTokenType.XML_NAME && element.getParent() instanceof XmlTag) {
        final XmlTag tag = (XmlTag) element.getParent();
        for (XmlTag xmlTag : tag.getSubTags()) {
            if (xmlTag.getAttribute(FxmlConstants.FX_VALUE) == null)
                return false;
        }
        final XmlTag parentTag = tag.getParentTag();
        if (parentTag != null && tag.getDescriptor() instanceof JavaFxPropertyTagDescriptor && parentTag.getDescriptor() instanceof JavaFxClassTagDescriptorBase) {
            setText("Collapse tag '" + tag.getName() + "' to attribute");
            return true;
        }
    }
    return false;
}
Also used : JavaFxClassTagDescriptorBase(org.jetbrains.plugins.javaFX.fxml.descriptors.JavaFxClassTagDescriptorBase) JavaFxPropertyTagDescriptor(org.jetbrains.plugins.javaFX.fxml.descriptors.JavaFxPropertyTagDescriptor) XmlToken(com.intellij.psi.xml.XmlToken) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

XmlToken (com.intellij.psi.xml.XmlToken)29 PsiElement (com.intellij.psi.PsiElement)18 XmlTag (com.intellij.psi.xml.XmlTag)12 TextRange (com.intellij.openapi.util.TextRange)6 IElementType (com.intellij.psi.tree.IElementType)6 Nullable (org.jetbrains.annotations.Nullable)5 NotNull (org.jetbrains.annotations.NotNull)4 ASTNode (com.intellij.lang.ASTNode)3 Document (com.intellij.openapi.editor.Document)3 PsiErrorElement (com.intellij.psi.PsiErrorElement)3 XmlAttribute (com.intellij.psi.xml.XmlAttribute)3 ArrayList (java.util.ArrayList)3 ResourceUrl (com.android.ide.common.resources.ResourceUrl)2 ResourceType (com.android.resources.ResourceType)2 JSClass (com.intellij.lang.javascript.psi.ecmal4.JSClass)2 Editor (com.intellij.openapi.editor.Editor)2 Project (com.intellij.openapi.project.Project)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 PsiFile (com.intellij.psi.PsiFile)2 HtmlTag (com.intellij.psi.html.HtmlTag)2