use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.
the class AntDomMacrodefAttributeReference method getParentMacrodef.
@Nullable
private AntDomMacroDef getParentMacrodef() {
final PsiElement element = getElement();
if (element == null) {
return null;
}
final DomElement domElement = DomUtil.getDomElement(element);
if (domElement == null) {
return null;
}
return domElement.getParentOfType(AntDomMacroDef.class, false);
}
use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.
the class InspectionMappingConsistencyInspection method buildVisitor.
@NotNull
@Override
public PsiElementVisitor buildVisitor(@NotNull final ProblemsHolder holder, boolean isOnTheFly, @NotNull LocalInspectionToolSession session) {
return new XmlElementVisitor() {
@Override
public void visitXmlTag(XmlTag tag) {
DomElement element = DomUtil.getDomElement(tag);
if (element instanceof Extension) {
ExtensionPoint extensionPoint = ((Extension) element).getExtensionPoint();
if (extensionPoint != null && InheritanceUtil.isInheritor(extensionPoint.getBeanClass().getValue(), "com.intellij.codeInspection.InspectionEP")) {
boolean key = tag.getAttribute("key") != null;
boolean groupKey = tag.getAttribute("groupKey") != null;
if (key) {
if (tag.getAttribute("bundle") == null) {
checkDefaultBundle(element, holder);
}
} else if (tag.getAttribute("displayName") == null) {
registerProblem(element, holder, "displayName or key should be specified", "displayName", "key");
}
if (groupKey) {
if (tag.getAttribute("bundle") == null && tag.getAttribute("groupBundle") == null) {
checkDefaultBundle(element, holder);
}
} else if (tag.getAttribute("groupName") == null) {
registerProblem(element, holder, "groupName or groupKey should be specified", "groupName", "groupKey");
}
}
}
}
};
}
use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.
the class AntReferenceInjector method addMacrodefParameterRefs.
public static void addMacrodefParameterRefs(@NotNull XmlAttributeValue element, final Collection<PsiReference> refs) {
final DomElement domElement = DomUtil.getDomElement(element);
if (domElement == null) {
return;
}
final AntDomMacroDef macrodef = domElement.getParentOfType(AntDomMacroDef.class, true);
if (macrodef == null) {
return;
}
final String text = ElementManipulators.getValueText(element);
final int valueBeginingOffset = Math.abs(element.getTextRange().getStartOffset() - element.getValueTextRange().getStartOffset());
int startIndex;
int endIndex = -1;
while ((startIndex = text.indexOf("@{", endIndex + 1)) > endIndex) {
startIndex += 2;
endIndex = startIndex;
int nestedBrackets = 0;
while (text.length() > endIndex) {
final char ch = text.charAt(endIndex);
if (ch == '}') {
if (nestedBrackets == 0) {
break;
}
--nestedBrackets;
} else if (ch == '{') {
++nestedBrackets;
}
++endIndex;
}
if (nestedBrackets > 0 || endIndex == text.length())
return;
if (endIndex >= startIndex) {
//final String name = text.substring(startIndex, endIndex);
refs.add(new AntDomMacrodefAttributeReference(element, new TextRange(valueBeginingOffset + startIndex, valueBeginingOffset + endIndex)));
}
endIndex = startIndex;
}
}
use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.
the class AntCreatePropertyFix method applyFix.
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
final PsiElement psiElement = descriptor.getPsiElement();
final PsiFile containingFile = psiElement.getContainingFile();
final FileModificationService modificationService = FileModificationService.getInstance();
Navigatable result = null;
if (myPropFile != null) {
final VirtualFile vFile = myPropFile.getVirtualFile();
boolean canModify = true;
if (myPropFile instanceof PsiFile) {
canModify = modificationService.prepareFileForWrite((PsiFile) myPropFile);
} else if (vFile != null) {
canModify = modificationService.prepareVirtualFilesForWrite(project, Collections.singleton(vFile));
}
if (canModify) {
final IProperty generatedProperty = myPropFile.addProperty(myCanonicalText, "");
result = vFile != null ? new OpenFileDescriptor(project, vFile, generatedProperty.getPsiElement().getTextRange().getEndOffset()) : generatedProperty;
}
} else {
if (containingFile instanceof XmlFile) {
final XmlFile xmlFile = (XmlFile) containingFile;
final XmlTag rootTag = xmlFile.getRootTag();
if (rootTag != null && modificationService.prepareFileForWrite(xmlFile)) {
final XmlTag propTag = rootTag.createChildTag(PROPERTY, rootTag.getNamespace(), null, false);
propTag.setAttribute(NAME_ATTR, myCanonicalText);
propTag.setAttribute(VALUE_ATTR, "");
final DomElement contextElement = DomUtil.getDomElement(descriptor.getPsiElement());
PsiElement generated;
if (contextElement == null) {
generated = rootTag.addSubTag(propTag, true);
} else {
final AntDomTarget containingTarget = contextElement.getParentOfType(AntDomTarget.class, false);
final DomElement anchor = containingTarget != null ? containingTarget : contextElement;
final XmlTag tag = anchor.getXmlTag();
if (!rootTag.equals(tag)) {
generated = tag.getParent().addBefore(propTag, tag);
} else {
generated = rootTag.addSubTag(propTag, true);
}
}
if (generated instanceof XmlTag) {
final XmlAttribute valueAttrib = ((XmlTag) generated).getAttribute(VALUE_ATTR);
if (valueAttrib != null) {
final XmlAttributeValue valueElement = valueAttrib.getValueElement();
if (valueElement instanceof Navigatable) {
result = (Navigatable) valueElement;
}
}
}
if (result == null && generated instanceof Navigatable) {
result = (Navigatable) generated;
}
}
}
}
if (result != null) {
result.navigate(true);
}
}
use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.
the class AntResolveTest method testPropertyInMacrodefParam.
public void testPropertyInMacrodefParam() throws Exception {
PsiReference ref = configure();
final PsiElement result = ref.resolve();
assertTrue(result instanceof PomTargetPsiElement);
final PsiElement naviElem = ((DomTarget) ((PomTargetPsiElement) result).getTarget()).getNavigationElement();
final DomElement domElement = DomUtil.getDomElement(naviElem);
assertNotNull(domElement);
assertNotNull(domElement.getParentOfType(AntDomMacrodefAttribute.class, false));
}
Aggregations