use of org.jetbrains.idea.devkit.dom.Extension 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 org.jetbrains.idea.devkit.dom.Extension in project intellij-community by JetBrains.
the class LanguageResolvingUtil method calculateAnyLanguageId.
private static String calculateAnyLanguageId(ConvertContext context) {
final Extension extension = context.getInvocationElement().getParentOfType(Extension.class, true);
if (extension == null) {
return ANY_LANGUAGE_DEFAULT_ID;
}
final ExtensionPoint extensionPoint = extension.getExtensionPoint();
if (extensionPoint == null) {
return ANY_LANGUAGE_DEFAULT_ID;
}
final GenericAttributeValue<PsiClass> epBeanClass = extensionPoint.getBeanClass();
if (EP_WITH_ANY_LANGUAGE_ID.contains(epBeanClass.getStringValue())) {
return "any";
}
return ANY_LANGUAGE_DEFAULT_ID;
}
use of org.jetbrains.idea.devkit.dom.Extension in project intellij-community by JetBrains.
the class InspectionDescriptionInfo method create.
public static InspectionDescriptionInfo create(Module module, PsiClass psiClass) {
PsiMethod method = PsiUtil.findNearestMethod("getShortName", psiClass);
if (method != null && method.getContainingClass().hasModifierProperty(PsiModifier.ABSTRACT)) {
method = null;
}
String filename = null;
if (method == null) {
String className = psiClass.getQualifiedName();
if (className != null) {
Extension extension = findExtension(module, psiClass);
if (extension != null) {
filename = extension.getXmlTag().getAttributeValue("shortName");
}
}
} else {
filename = PsiUtil.getReturnedLiteral(method, psiClass);
}
if (filename == null) {
final String className = psiClass.getName();
LOG.assertTrue(className != null, psiClass);
filename = InspectionProfileEntry.getShortName(className);
}
PsiFile descriptionFile = resolveInspectionDescriptionFile(module, filename);
return new InspectionDescriptionInfo(filename, method, descriptionFile);
}
use of org.jetbrains.idea.devkit.dom.Extension in project intellij-community by JetBrains.
the class ExtensionPointLocator method isRegisteredExtension.
public static boolean isRegisteredExtension(@NotNull PsiClass psiClass) {
String name = psiClass.getQualifiedName();
if (name == null)
return false;
Project project = psiClass.getProject();
GlobalSearchScope scope = getCandidatesScope(project);
return !PsiSearchHelper.SERVICE.getInstance(project).processUsagesInNonJavaFiles(name, new PsiNonJavaFileReferenceProcessor() {
@Override
public boolean process(PsiFile file, int startOffset, int endOffset) {
PsiElement at = file.findElementAt(startOffset);
String tokenText = at instanceof XmlToken ? at.getText() : null;
if (!StringUtil.equals(name, tokenText))
return true;
XmlTag tag = PsiTreeUtil.getParentOfType(at, XmlTag.class);
if (tag == null)
return true;
DomElement dom = DomUtil.getDomElement(tag);
return !(dom instanceof Extension && ((Extension) dom).getExtensionPoint() != null);
}
}, scope);
}
use of org.jetbrains.idea.devkit.dom.Extension in project intellij-community by JetBrains.
the class RegisterExtensionFix method registerExtension.
private void registerExtension(final DomFileElement<IdeaPlugin> selectedValue, final ExtensionPointCandidate candidate) {
PsiElement navTarget = new WriteCommandAction<PsiElement>(selectedValue.getFile().getProject(), selectedValue.getFile()) {
@Override
protected void run(@NotNull Result<PsiElement> result) throws Throwable {
Extensions extensions = PluginDescriptorChooser.findOrCreateExtensionsForEP(selectedValue, candidate.epName);
Extension extension = extensions.addExtension(candidate.epName);
XmlTag tag = extension.getXmlTag();
PsiElement navTarget = null;
String keyAttrName = KEY_MAP.get(candidate.beanClassName);
if (keyAttrName != null) {
XmlAttribute attr = tag.setAttribute(keyAttrName, "");
navTarget = attr.getValueElement();
}
if (candidate.attributeName != null) {
tag.setAttribute(candidate.attributeName, myExtensionClass.getQualifiedName());
} else {
XmlTag subTag = tag.createChildTag(candidate.tagName, null, myExtensionClass.getQualifiedName(), false);
tag.addSubTag(subTag, false);
}
result.setResult(navTarget != null ? navTarget : extension.getXmlTag());
}
}.execute().throwException().getResultObject();
PsiNavigateUtil.navigate(navTarget);
}
Aggregations