Search in sources :

Example 11 with XmlText

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

the class XmlTextTest method testPhysicalToDisplayIfHasGaps2.

public void testPhysicalToDisplayIfHasGaps2() throws Exception {
    String xml = "<div>&amp;abc</div>";
    XmlFile file = (XmlFile) PsiFileFactory.getInstance(getProject()).createFileFromText("foo.xml", xml);
    XmlTag root = file.getDocument().getRootTag();
    final XmlText text = root.getValue().getTextElements()[0];
    assertEquals("&abc", text.getValue());
    assertEquals(0, text.physicalToDisplay(0));
    assertEquals(1, text.physicalToDisplay(5));
    assertEquals(2, text.physicalToDisplay(6));
    assertEquals(3, text.physicalToDisplay(7));
    assertEquals(4, text.physicalToDisplay(8));
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) XmlText(com.intellij.psi.xml.XmlText) XmlTag(com.intellij.psi.xml.XmlTag)

Example 12 with XmlText

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

the class XmlTextTest method testDisplayToPhysical2.

public void testDisplayToPhysical2() throws Exception {
    String xml = "<div><![CDATA[ ]]></div>";
    XmlFile file = (XmlFile) PsiFileFactory.getInstance(getProject()).createFileFromText("foo.xml", xml);
    XmlTag root = file.getDocument().getRootTag();
    final XmlText text = root.getValue().getTextElements()[0];
    assertEquals(" ", text.getValue());
    assertEquals(9, text.displayToPhysical(0));
    assertEquals(13, text.displayToPhysical(1));
}
Also used : XmlFile(com.intellij.psi.xml.XmlFile) XmlText(com.intellij.psi.xml.XmlText) XmlTag(com.intellij.psi.xml.XmlTag)

Example 13 with XmlText

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

the class ActionScriptAnnotatingVisitor method visitJSPackageStatement.

public void visitJSPackageStatement(final JSPackageStatement packageStatement) {
    final JSFile jsFile = PsiTreeUtil.getParentOfType(packageStatement, JSFile.class);
    final PsiElement context = jsFile == null ? null : jsFile.getContext();
    boolean injected = context instanceof XmlAttributeValue || context instanceof XmlText;
    if (injected) {
        myHolder.createErrorAnnotation(packageStatement.getFirstChild().getNode(), JSBundle.message("javascript.validation.message.nested.packages.are.not.allowed"));
        return;
    }
    for (PsiElement el = packageStatement.getPrevSibling(); el != null; el = el.getPrevSibling()) {
        if (!(el instanceof PsiWhiteSpace) && !(el instanceof PsiComment)) {
            myHolder.createErrorAnnotation(packageStatement.getFirstChild().getNode(), JSBundle.message("javascript.validation.message.package.shouldbe.first.statement"));
            break;
        }
    }
    final ASTNode node = packageStatement.findNameIdentifier();
    if (node == null)
        checkPackageStatement(packageStatement);
}
Also used : ASTNode(com.intellij.lang.ASTNode) XmlText(com.intellij.psi.xml.XmlText) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue)

Example 14 with XmlText

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

the class TypographyQuickFix method apply.

@Override
public void apply(@NotNull PsiElement startElement, @NotNull PsiElement endElement, @NotNull AndroidQuickfixContexts.Context context) {
    final XmlTag tag = PsiTreeUtil.getParentOfType(startElement, XmlTag.class);
    if (tag == null) {
        return;
    }
    for (PsiElement child : tag.getChildren()) {
        if (child instanceof XmlText) {
            final XmlText xmlText = (XmlText) child;
            final String value = xmlText.getValue();
            if (value != null) {
                final List<TypographyDetector.ReplaceEdit> edits = TypographyDetector.getEdits(myIssue.getId(), myMessage, value);
                final StringBuilder builder = new StringBuilder(value);
                for (TypographyDetector.ReplaceEdit edit : edits) {
                    String with = edit.replaceWith;
                    if (ApplicationManager.getApplication().isUnitTestMode()) {
                        with = with.replace('–', '~').replace('‘', '{').replace('’', '}');
                    }
                    builder.replace(edit.offset, edit.offset + edit.length, with);
                }
                final String newValue = builder.toString();
                if (!newValue.equals(value)) {
                    xmlText.setValue(newValue);
                }
            }
        }
    }
}
Also used : TypographyDetector(com.android.tools.lint.checks.TypographyDetector) XmlText(com.intellij.psi.xml.XmlText) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 15 with XmlText

use of com.intellij.psi.xml.XmlText 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)

Aggregations

XmlText (com.intellij.psi.xml.XmlText)24 XmlTag (com.intellij.psi.xml.XmlTag)16 PsiElement (com.intellij.psi.PsiElement)12 ASTNode (com.intellij.lang.ASTNode)5 TextRange (com.intellij.openapi.util.TextRange)3 XmlAttributeValue (com.intellij.psi.xml.XmlAttributeValue)3 XmlFile (com.intellij.psi.xml.XmlFile)3 Nullable (org.jetbrains.annotations.Nullable)3 LookupElement (com.intellij.codeInsight.lookup.LookupElement)2 Language (com.intellij.lang.Language)2 Project (com.intellij.openapi.project.Project)2 PsiWhiteSpace (com.intellij.psi.PsiWhiteSpace)2 XmlDocument (com.intellij.psi.xml.XmlDocument)2 XmlTagValue (com.intellij.psi.xml.XmlTagValue)2 DomElement (com.intellij.util.xml.DomElement)2 NotNull (org.jetbrains.annotations.NotNull)2 MavenProjectIndicesManager (org.jetbrains.idea.maven.indices.MavenProjectIndicesManager)2 TypographyDetector (com.android.tools.lint.checks.TypographyDetector)1 NegatingComparable (com.intellij.codeInsight.completion.impl.NegatingComparable)1 LookupElementWeigher (com.intellij.codeInsight.lookup.LookupElementWeigher)1