use of org.jetbrains.idea.devkit.dom.ExtensionPoint 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.ExtensionPoint 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.ExtensionPoint in project intellij-community by JetBrains.
the class PluginFieldNameConverter method getEPBeanClass.
@Nullable
private static PsiClass getEPBeanClass(ConvertContext context) {
ExtensionPoint ep = context.getInvocationElement().getParentOfType(ExtensionPoint.class, true);
if (ep == null)
return null;
PsiClass value = ep.getBeanClass().getValue();
if (value == null)
return null;
return value;
}
use of org.jetbrains.idea.devkit.dom.ExtensionPoint in project intellij-community by JetBrains.
the class InspectionDescriptionInfo method doFindExtension.
@Nullable
private static Extension doFindExtension(Module module, PsiClass psiClass) {
// Try search in narrow scopes first
Project project = module.getProject();
Set<DomFileElement<IdeaPlugin>> processed = new HashSet<>();
for (GlobalSearchScope scope : DescriptionCheckerUtil.searchScopes(module)) {
List<DomFileElement<IdeaPlugin>> origElements = DomService.getInstance().getFileElements(IdeaPlugin.class, project, scope);
origElements.removeAll(processed);
List<DomFileElement<IdeaPlugin>> elements = PluginDescriptorChooser.findAppropriateIntelliJModule(module.getName(), origElements);
Query<PsiReference> query = ReferencesSearch.search(psiClass, new LocalSearchScope(elements.stream().map(DomFileElement::getFile).toArray(PsiElement[]::new)));
Ref<Extension> result = Ref.create(null);
query.forEach(ref -> {
PsiElement element = ref.getElement();
if (element instanceof XmlAttributeValue) {
PsiElement parent = element.getParent();
if (parent instanceof XmlAttribute && "implementationClass".equals(((XmlAttribute) parent).getName())) {
DomElement domElement = DomUtil.getDomElement(parent.getParent());
if (domElement instanceof Extension) {
Extension extension = (Extension) domElement;
ExtensionPoint extensionPoint = extension.getExtensionPoint();
if (extensionPoint != null && InheritanceUtil.isInheritor(extensionPoint.getBeanClass().getValue(), InspectionEP.class.getName())) {
result.set(extension);
return false;
}
}
}
}
return true;
});
Extension extension = result.get();
if (extension != null)
return extension;
processed.addAll(origElements);
}
return null;
}
use of org.jetbrains.idea.devkit.dom.ExtensionPoint in project intellij-community by JetBrains.
the class AddWithTagFix method applyFix.
@Override
public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) {
DomElement element = DomUtil.getDomElement(descriptor.getPsiElement());
if (!(element instanceof ExtensionPoint)) {
return;
}
ExtensionPoint extensionPoint = (ExtensionPoint) element;
List<PsiField> fields = extensionPoint.collectMissingWithTags();
PsiElement navTarget = null;
for (PsiField field : fields) {
With with = extensionPoint.addWith();
String tagName = PluginFieldNameConverter.getAnnotationValue(field, Tag.class);
if (tagName != null) {
with.getTag().setStringValue(tagName);
} else {
String attributeName = PluginFieldNameConverter.getAttributeAnnotationValue(field);
if (attributeName == null) {
attributeName = field.getName();
}
if (attributeName.equals("forClass")) {
continue;
}
with.getAttribute().setStringValue(attributeName);
}
String epName = extensionPoint.getName().getStringValue();
String className = "";
if (epName != null) {
int pos = epName.lastIndexOf('.');
epName = StringUtil.capitalize(pos >= 0 ? epName.substring(pos + 1) : epName);
PsiClass[] classesByName = PsiShortNamesCache.getInstance(project).getClassesByName(epName, ProjectScope.getAllScope(project));
if (classesByName.length == 1) {
className = classesByName[0].getQualifiedName();
}
}
with.getImplements().setStringValue(className);
if (navTarget == null) {
navTarget = with.getImplements().getXmlAttributeValue();
}
}
if (navTarget != null) {
PsiNavigateUtil.navigate(navTarget);
}
}
Aggregations