use of com.intellij.util.xml.reflect.DomAttributeChildDescription in project intellij-community by JetBrains.
the class PluginXmlDomInspection method annotateExtension.
private static void annotateExtension(Extension extension, DomElementAnnotationHolder holder) {
final ExtensionPoint extensionPoint = extension.getExtensionPoint();
if (extensionPoint == null)
return;
final GenericAttributeValue<PsiClass> interfaceAttribute = extensionPoint.getInterface();
if (DomUtil.hasXml(interfaceAttribute)) {
final PsiClass value = interfaceAttribute.getValue();
if (value != null && value.isDeprecated()) {
holder.createProblem(extension, ProblemHighlightType.LIKE_DEPRECATED, "Deprecated EP '" + extensionPoint.getEffectiveQualifiedName() + "'", null);
return;
}
}
if (ExtensionPoints.ERROR_HANDLER.equals(extensionPoint.getEffectiveQualifiedName()) && extension.exists()) {
String implementation = extension.getXmlTag().getAttributeValue("implementation");
if (ITNReporter.class.getName().equals(implementation)) {
IdeaPlugin plugin = extension.getParentOfType(IdeaPlugin.class, true);
if (plugin != null) {
Vendor vendor = plugin.getVendor();
if (DomUtil.hasXml(vendor) && PluginManagerMain.isDevelopedByJetBrains(vendor.getValue())) {
LocalQuickFix fix = new RemoveDomElementQuickFix(extension);
holder.createProblem(extension, ProblemHighlightType.LIKE_UNUSED_SYMBOL, "Exceptions from plugins developed by JetBrains are reported via ITNReporter automatically," + " there is no need to specify it explicitly", null, fix).highlightWholeElement();
}
}
}
}
final List<? extends DomAttributeChildDescription> descriptions = extension.getGenericInfo().getAttributeChildrenDescriptions();
for (DomAttributeChildDescription attributeDescription : descriptions) {
final GenericAttributeValue attributeValue = attributeDescription.getDomAttributeValue(extension);
if (attributeValue == null || !DomUtil.hasXml(attributeValue))
continue;
// IconsReferencesContributor
if ("icon".equals(attributeDescription.getXmlElementName())) {
annotateResolveProblems(holder, attributeValue);
}
final PsiElement declaration = attributeDescription.getDeclaration(extension.getManager().getProject());
if (declaration instanceof PsiField) {
PsiField psiField = (PsiField) declaration;
if (psiField.isDeprecated()) {
holder.createProblem(attributeValue, ProblemHighlightType.LIKE_DEPRECATED, "Deprecated attribute '" + attributeDescription.getName() + "'", null).highlightWholeElement();
}
}
}
}
use of com.intellij.util.xml.reflect.DomAttributeChildDescription 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.util.xml.reflect.DomAttributeChildDescription in project intellij-community by JetBrains.
the class DomBasicsTest method testAttributeChildrenGenerics.
public void testAttributeChildrenGenerics() throws Throwable {
final StaticGenericInfo genericInfo = DomApplicationComponent.getInstance().getStaticGenericInfo(MyElement.class);
final List<? extends DomAttributeChildDescription> descriptions = genericInfo.getAttributeChildrenDescriptions();
assertEquals(1, descriptions.size());
final DomAttributeChildDescription description = descriptions.get(0);
final MyElement element = createElement("");
assertEquals(element.getAttr(), description.getValues(element).get(0));
assertEquals(element.getAttr(), description.getDomAttributeValue(element));
}
Aggregations