use of com.intellij.pom.PomTarget 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.PomTarget in project android by JetBrains.
the class AndroidXmlDocumentationProvider method generateDoc.
@Override
public String generateDoc(PsiElement element, @Nullable PsiElement originalElement) {
if (element instanceof ProvidedDocumentationPsiElement) {
return ((ProvidedDocumentationPsiElement) element).getDocumentation();
}
if (element instanceof LazyValueResourceElementWrapper) {
LazyValueResourceElementWrapper wrapper = (LazyValueResourceElementWrapper) element;
ValueResourceInfo resourceInfo = wrapper.getResourceInfo();
ResourceType type = resourceInfo.getType();
String name = resourceInfo.getName();
Module module = ModuleUtilCore.findModuleForPsiElement(element);
if (module == null) {
return null;
}
AndroidFacet facet = AndroidFacet.getInstance(element);
if (facet == null) {
return null;
}
ResourceUrl url;
ResourceUrl originalUrl = originalElement != null ? ResourceUrl.parse(originalElement.getText()) : null;
if (originalUrl != null && name.equals(originalUrl.name)) {
url = originalUrl;
} else {
boolean isFramework = false;
if (originalUrl != null) {
isFramework = originalUrl.framework;
} else {
// Figure out if this resource is a framework file.
// We really should store that info in the ValueResourceInfo instances themselves.
// For now, attempt to figure it out
SystemResourceManager systemResourceManager = facet.getSystemResourceManager();
VirtualFile containingFile = resourceInfo.getContainingFile();
if (systemResourceManager != null) {
VirtualFile parent = containingFile.getParent();
if (parent != null) {
VirtualFile resDir = parent.getParent();
if (resDir != null) {
isFramework = systemResourceManager.isResourceDir(resDir);
}
}
}
}
url = ResourceUrl.create(type, name, isFramework, false);
}
return generateDoc(element, url);
} else if (element instanceof MyResourceElement) {
return getResourceDocumentation(element, ((MyResourceElement) element).myResource);
} else if (element instanceof XmlAttributeValue) {
return getResourceDocumentation(element, ((XmlAttributeValue) element).getValue());
}
if (originalElement instanceof XmlToken) {
XmlToken token = (XmlToken) originalElement;
if (token.getTokenType() == XML_ATTRIBUTE_VALUE_START_DELIMITER) {
PsiElement next = token.getNextSibling();
if (next instanceof XmlToken) {
token = (XmlToken) next;
}
} else if (token.getTokenType() == XML_ATTRIBUTE_VALUE_END_DELIMITER) {
PsiElement prev = token.getPrevSibling();
if (prev instanceof XmlToken) {
token = (XmlToken) prev;
}
}
if (token.getTokenType() == XML_ATTRIBUTE_VALUE_TOKEN) {
String documentation = getResourceDocumentation(originalElement, token.getText());
if (documentation != null) {
return documentation;
}
} else if (token.getTokenType() == XML_DATA_CHARACTERS) {
String text = token.getText().trim();
String documentation = getResourceDocumentation(originalElement, text);
if (documentation != null) {
return documentation;
}
}
}
if (element instanceof PomTargetPsiElement && originalElement != null) {
final PomTarget target = ((PomTargetPsiElement) element).getTarget();
if (target instanceof DomAttributeChildDescription) {
synchronized (ANDROID_ATTRIBUTE_DOCUMENTATION_CACHE_KEY) {
return generateDocForXmlAttribute((DomAttributeChildDescription) target, originalElement);
}
}
}
if (element instanceof MyDocElement) {
return ((MyDocElement) element).myDocumentation;
}
return null;
}
use of com.intellij.pom.PomTarget in project intellij-community by JetBrains.
the class GrUnresolvedAccessChecker method shouldHighlightAsUnresolved.
private static boolean shouldHighlightAsUnresolved(@NotNull GrReferenceExpression referenceExpression) {
if (GrHighlightUtil.isDeclarationAssignment(referenceExpression))
return false;
GrExpression qualifier = referenceExpression.getQualifier();
if (qualifier != null && qualifier.getType() == null && !isRefToPackage(qualifier))
return false;
if (qualifier != null && referenceExpression.getDotTokenType() == GroovyTokenTypes.mMEMBER_POINTER && referenceExpression.multiResolve(false).length > 0) {
return false;
}
if (!GroovyUnresolvedHighlightFilter.shouldHighlight(referenceExpression))
return false;
CollectConsumer<PomTarget> consumer = new CollectConsumer<>();
for (PomDeclarationSearcher searcher : PomDeclarationSearcher.EP_NAME.getExtensions()) {
searcher.findDeclarationsAt(referenceExpression, 0, consumer);
if (!consumer.getResult().isEmpty())
return false;
}
return true;
}
use of com.intellij.pom.PomTarget 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.PomTarget in project intellij-community by JetBrains.
the class TargetElementUtil method getNamedElement.
@Override
@Nullable
public PsiElement getNamedElement(@Nullable final PsiElement element, final int offsetInElement) {
if (element == null)
return null;
final List<PomTarget> targets = ContainerUtil.newArrayList();
final Consumer<PomTarget> consumer = target -> {
if (target instanceof PsiDeclaredTarget) {
final PsiDeclaredTarget declaredTarget = (PsiDeclaredTarget) target;
final PsiElement navigationElement = declaredTarget.getNavigationElement();
final TextRange range = declaredTarget.getNameIdentifierRange();
if (range != null && !range.shiftRight(navigationElement.getTextRange().getStartOffset()).contains(element.getTextRange().getStartOffset() + offsetInElement)) {
return;
}
}
targets.add(target);
};
PsiElement parent = element;
int offset = offsetInElement;
while (parent != null) {
for (PomDeclarationSearcher searcher : PomDeclarationSearcher.EP_NAME.getExtensions()) {
searcher.findDeclarationsAt(parent, offset, consumer);
if (!targets.isEmpty()) {
final PomTarget target = targets.get(0);
return target == null ? null : PomService.convertToPsi(element.getProject(), target);
}
}
offset += parent.getStartOffsetInParent();
parent = parent.getParent();
}
return getNamedElement(element);
}
Aggregations