use of com.intellij.pom.PomTargetPsiElement in project intellij-community by JetBrains.
the class DomIncludesTest method testNavigationToIncluded.
public void testNavigationToIncluded() throws Throwable {
final MyElement rootElement = createDomFile("a.xml", "<root xmlns:xi=\"http://www.w3.org/2001/XInclude\">" + "<xi:include href=\"b.xml\" xpointer=\"xpointer(/xxx/*)\"/>" + "<child ref=\"b\"/>" + "</root>");
final XmlFile includedFile = (XmlFile) createFile("b.xml", "<xxx><child xxx=\"b\"/></xxx>");
final List<Child> children = rootElement.getChildren();
final MyElement domTarget = children.get(0);
final GenericAttributeValue<Child> ref = children.get(1).getRef();
final MyElement value = ref.getValue();
assertEquals(domTarget, value);
myFixture.configureFromTempProjectFile("a.xml");
final int offset = ref.getXmlAttributeValue().getTextRange().getStartOffset() + 1;
myFixture.getEditor().getCaretModel().moveToOffset(offset);
final PsiElement target = GotoDeclarationAction.findTargetElement(getProject(), myFixture.getEditor(), offset);
PsiElement element = ((DomTarget) ((PomTargetPsiElement) target).getTarget()).getNavigationElement();
// assertSame(PomService.convertToPsi(DomTarget.getTarget(domTarget)), target);
assertSame(includedFile.getDocument().getRootTag().getSubTags()[0].getAttributes()[0].getValueElement(), element);
}
use of com.intellij.pom.PomTargetPsiElement in project intellij-community by JetBrains.
the class HighlightUsagesHandler method getNameIdentifierRange.
@Nullable
public static TextRange getNameIdentifierRange(PsiFile file, PsiElement element) {
final InjectedLanguageManager injectedManager = InjectedLanguageManager.getInstance(element.getProject());
if (element instanceof PomTargetPsiElement) {
final PomTarget target = ((PomTargetPsiElement) element).getTarget();
if (target instanceof PsiDeclaredTarget) {
final PsiDeclaredTarget declaredTarget = (PsiDeclaredTarget) target;
final TextRange range = declaredTarget.getNameIdentifierRange();
if (range != null) {
if (range.getStartOffset() < 0 || range.getLength() <= 0) {
return null;
}
final PsiElement navElement = declaredTarget.getNavigationElement();
if (PsiUtilBase.isUnderPsiRoot(file, navElement)) {
return injectedManager.injectedToHost(navElement, range.shiftRight(navElement.getTextRange().getStartOffset()));
}
}
}
}
if (!PsiUtilBase.isUnderPsiRoot(file, element)) {
return null;
}
PsiElement identifier = IdentifierUtil.getNameIdentifier(element);
if (identifier != null && PsiUtilBase.isUnderPsiRoot(file, identifier)) {
return injectedManager.injectedToHost(identifier, identifier.getTextRange());
}
return null;
}
use of com.intellij.pom.PomTargetPsiElement in project intellij-community by JetBrains.
the class EditSourceUtil method getDescriptor.
@Nullable
public static Navigatable getDescriptor(@NotNull PsiElement element) {
PsiElement original = getNavigatableOriginalElement(element);
if (original != null) {
element = original;
} else if (!canNavigate(element)) {
return null;
}
if (element instanceof PomTargetPsiElement) {
return ((PomTargetPsiElement) element).getTarget();
}
final PsiElement navigationElement = element.getNavigationElement();
if (navigationElement instanceof PomTargetPsiElement) {
return ((PomTargetPsiElement) navigationElement).getTarget();
}
final int offset = navigationElement instanceof PsiFile ? -1 : navigationElement.getTextOffset();
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(navigationElement);
if (virtualFile == null || !virtualFile.isValid()) {
return null;
}
OpenFileDescriptor desc = new OpenFileDescriptor(navigationElement.getProject(), virtualFile, offset);
desc.setUseCurrentWindow(FileEditorManager.USE_CURRENT_WINDOW.isIn(navigationElement));
return desc;
}
use of com.intellij.pom.PomTargetPsiElement in project intellij-community by JetBrains.
the class AntDomDocumentationProvider method getQuickNavigateInfo.
@Nullable
public String getQuickNavigateInfo(PsiElement element, PsiElement originalElement) {
// todo!
if (element instanceof PomTargetPsiElement) {
final PomTarget pomTarget = ((PomTargetPsiElement) element).getTarget();
if (pomTarget instanceof DomTarget) {
final DomElement domElement = ((DomTarget) pomTarget).getDomElement();
if (domElement instanceof AntDomTarget) {
final AntDomTarget antTarget = (AntDomTarget) domElement;
final String description = antTarget.getDescription().getRawText();
if (description != null && description.length() > 0) {
final String targetName = antTarget.getName().getRawText();
final StringBuilder builder = StringBuilderSpinAllocator.alloc();
try {
builder.append("Target");
if (targetName != null) {
builder.append(" \"").append(targetName).append("\"");
}
final XmlElement xmlElement = antTarget.getXmlElement();
if (xmlElement != null) {
final PsiFile containingFile = xmlElement.getContainingFile();
if (containingFile != null) {
final String fileName = containingFile.getName();
builder.append(" [").append(fileName).append("]");
}
}
return builder.append(" ").append(description).toString();
} finally {
StringBuilderSpinAllocator.dispose(builder);
}
}
}
} else if (pomTarget instanceof DomChildrenDescription) {
final DomChildrenDescription description = (DomChildrenDescription) pomTarget;
Type type = null;
try {
type = description.getType();
} catch (UnsupportedOperationException e) {
LOG.info(e);
}
if (type instanceof Class && AntDomElement.class.isAssignableFrom(((Class) type))) {
final String elemName = description.getName();
if (elemName != null) {
final AntDomElement.Role role = description.getUserData(AntDomElement.ROLE);
final StringBuilder builder = StringBuilderSpinAllocator.alloc();
try {
if (role == AntDomElement.Role.TASK) {
builder.append("Task ");
} else if (role == AntDomElement.Role.DATA_TYPE) {
builder.append("Data structure ");
}
builder.append(elemName);
return builder.toString();
} finally {
StringBuilderSpinAllocator.dispose(builder);
}
}
}
}
}
return null;
}
use of com.intellij.pom.PomTargetPsiElement 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