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));
}
};
}
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();
}
}
}
}
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;
}
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());
}
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);
}
Aggregations