Search in sources :

Example 46 with XmlAttributeValue

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

the class HardcodedActionUrlInspection method buildVisitor.

@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly) {
    final boolean isJspFileWithStrutsSupport = JspPsiUtil.getJspFile(holder.getFile()) != null && StrutsFacet.getInstance(holder.getFile()) != null;
    @Nullable final String actionExtension;
    if (isJspFileWithStrutsSupport) {
        actionExtension = ContainerUtil.getFirstItem(StrutsConstantHelper.getActionExtensions(holder.getFile()));
    } else {
        actionExtension = null;
    }
    return new XmlElementVisitor() {

        @Override
        public void visitXmlAttributeValue(XmlAttributeValue value) {
            if (!isJspFileWithStrutsSupport || actionExtension == null) {
                return;
            }
            XmlTag tag = PsiTreeUtil.getParentOfType(value, XmlTag.class);
            if (tag == null)
                return;
            URL parsedURL = parseURL(value, actionExtension);
            if (parsedURL == null)
                return;
            if (buildTag("", parsedURL, "", false, actionExtension) == null)
                return;
            TextRange range = ElementManipulators.getValueTextRange(value);
            holder.registerProblem(value, range, "Use Struts <url> tag instead of hardcoded URL", new WrapWithSUrl(actionExtension));
        }
    };
}
Also used : TextRange(com.intellij.openapi.util.TextRange) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) Nullable(org.jetbrains.annotations.Nullable) URL(java.net.URL) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 47 with XmlAttributeValue

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

the class TilesOgnlInjector method getLanguagesToInject.

@Override
public void getLanguagesToInject(@NotNull MultiHostRegistrar registrar, @NotNull PsiElement context) {
    final PsiFile containingFile = context.getContainingFile();
    if (!JamCommonUtil.isPlainXmlFile(containingFile)) {
        return;
    }
    assert context instanceof XmlAttributeValue;
    if (!((XmlAttributeValue) context).getValue().startsWith(OGNL_PREFIX)) {
        return;
    }
    PsiElement parent = context.getParent();
    if (parent instanceof XmlAttribute) {
        String name = ((XmlAttribute) parent).getLocalName();
        if ("expression".equals(name) || "templateExpression".equals(name)) {
            DomElement domElement = DomManager.getDomManager(context.getProject()).getDomElement((XmlTag) parent.getParent());
            if (domElement instanceof Put || domElement instanceof Add || domElement instanceof Definition) {
                final TextRange attributeTextRange = ElementManipulators.getValueTextRange(context);
                final TextRange ognlTextRange = TextRange.from(attributeTextRange.getStartOffset() + OGNL_PREFIX.length(), attributeTextRange.getLength() - OGNL_PREFIX.length());
                registrar.startInjecting(OgnlLanguage.INSTANCE).addPlace(OgnlLanguage.EXPRESSION_PREFIX, OgnlLanguage.EXPRESSION_SUFFIX, (PsiLanguageInjectionHost) context, ognlTextRange).doneInjecting();
            }
        }
    }
}
Also used : Add(com.intellij.struts.dom.tiles.Add) XmlAttribute(com.intellij.psi.xml.XmlAttribute) DomElement(com.intellij.util.xml.DomElement) PsiLanguageInjectionHost(com.intellij.psi.PsiLanguageInjectionHost) Definition(com.intellij.struts.dom.tiles.Definition) PsiFile(com.intellij.psi.PsiFile) TextRange(com.intellij.openapi.util.TextRange) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) PsiElement(com.intellij.psi.PsiElement) Put(com.intellij.struts.dom.tiles.Put)

Example 48 with XmlAttributeValue

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

the class FlexXmlBackedMembersIndex method getItemsByName.

public static Collection<NavigationItem> getItemsByName(final String name, Project project) {
    Collection<VirtualFile> files = FileBasedIndex.getInstance().getContainingFiles(NAME, name, GlobalSearchScope.projectScope(project));
    final Collection<NavigationItem> result = new ArrayList<>();
    for (VirtualFile vFile : files) {
        PsiFile file = PsiManager.getInstance(project).findFile(vFile);
        if (!(file instanceof XmlFile)) {
            continue;
        }
        process((XmlFile) file, element -> {
            if (name.equals(getName(element))) {
                if (element instanceof JSNamedElement) {
                    result.add((JSNamedElement) element);
                } else {
                    XmlAttribute id = ((XmlTag) element).getAttribute("id");
                    if (id != null) {
                        XmlAttributeValue valueElement = id.getValueElement();
                        PsiElement[] children;
                        if (valueElement != null && (children = valueElement.getChildren()).length == 3) {
                            result.add(new TagNavigationItem(children[1], name));
                        }
                    }
                }
            }
        }, true);
    }
    return result;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlAttribute(com.intellij.psi.xml.XmlAttribute) XmlFile(com.intellij.psi.xml.XmlFile) ArrayList(java.util.ArrayList) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) NavigationItem(com.intellij.navigation.NavigationItem) PsiElementNavigationItem(com.intellij.navigation.PsiElementNavigationItem) JSNamedElement(com.intellij.lang.javascript.psi.JSNamedElement) FakePsiElement(com.intellij.psi.impl.FakePsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 49 with XmlAttributeValue

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

the class AndroidValueResourcesTest method testNavigationInPlatformXml3.

public void testNavigationInPlatformXml3() throws Exception {
    VirtualFile themes_holo = LocalFileSystem.getInstance().findFileByPath(TestUtils.getPlatformFile("data/res/values/themes_holo.xml").toString());
    assertNotNull(themes_holo);
    VirtualFile colors_holo = LocalFileSystem.getInstance().findFileByPath(TestUtils.getPlatformFile("data/res/values/colors_holo.xml").toString());
    assertNotNull(colors_holo);
    // In themes_holo.xml: point to value of "bright_foreground_holo_light" on line:
    //    <item name="colorForeground">@color/bright_foreground_holo_light</item>
    // Goto action should navigate to "bright_foreground_holo_light" in colors_holo.xml, on line:
    //    <color name="bright_foreground_holo_light">@color/background_holo_dark</color>
    myFixture.configureFromExistingVirtualFile(themes_holo);
    myFixture.getEditor().getCaretModel().moveToLogicalPosition(new LogicalPosition(407, 60));
    PsiElement[] targets = GotoDeclarationAction.findAllTargetElements(myFixture.getProject(), myFixture.getEditor(), myFixture.getCaretOffset());
    assertNotNull(targets);
    assertEquals(1, targets.length);
    PsiElement targetElement = LazyValueResourceElementWrapper.computeLazyElement(targets[0]);
    assertInstanceOf(targetElement, XmlAttributeValue.class);
    XmlAttributeValue targetAttrValue = (XmlAttributeValue) targetElement;
    assertEquals("bright_foreground_holo_light", targetAttrValue.getValue());
    assertEquals("name", ((XmlAttribute) targetAttrValue.getParent()).getName());
    assertEquals("color", ((XmlTag) targetAttrValue.getParent().getParent()).getName());
    assertEquals(colors_holo, targetElement.getContainingFile().getVirtualFile());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) LogicalPosition(com.intellij.openapi.editor.LogicalPosition) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) PsiElement(com.intellij.psi.PsiElement)

Example 50 with XmlAttributeValue

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

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