use of com.intellij.util.xml.DomElement 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 com.intellij.util.xml.DomElement 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);
}
}
use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.
the class PsiClassControl method initReferenceEditorWithBrowseButton.
protected static <T extends JPanel> T initReferenceEditorWithBrowseButton(final T boundedComponent, final ReferenceEditorWithBrowseButton editor, final EditorTextFieldControl control) {
boundedComponent.removeAll();
boundedComponent.add(editor);
final GlobalSearchScope resolveScope = control.getDomWrapper().getResolveScope();
editor.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
final DomElement domElement = control.getDomElement();
ExtendClass extend = domElement.getAnnotation(ExtendClass.class);
PsiClass baseClass = null;
ClassFilter filter = null;
if (extend != null) {
baseClass = JavaPsiFacade.getInstance(control.getProject()).findClass(extend.value(), resolveScope);
if (extend.instantiatable()) {
filter = ClassFilter.INSTANTIABLE;
}
}
PsiClass initialClass = null;
if (domElement instanceof GenericDomValue) {
final Object value = ((GenericDomValue) domElement).getValue();
if (value instanceof PsiClass)
initialClass = (PsiClass) value;
}
TreeClassChooser chooser = TreeClassChooserFactory.getInstance(control.getProject()).createInheritanceClassChooser(UIBundle.message("choose.class"), resolveScope, baseClass, initialClass, filter);
chooser.showDialog();
final PsiClass psiClass = chooser.getSelected();
if (psiClass != null) {
control.setValue(psiClass.getQualifiedName());
}
}
});
return boundedComponent;
}
use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.
the class PsiTypeControl method setValue.
protected void setValue(String value) {
final PsiType type = JvmPsiTypeConverterImpl.convertFromString(value, new AbstractConvertContext() {
@NotNull
public DomElement getInvocationElement() {
return getDomElement();
}
});
if (type != null) {
value = type.getCanonicalText();
}
super.setValue(value);
}
use of com.intellij.util.xml.DomElement in project intellij-community by JetBrains.
the class MavenPluginDescriptor method processDescriptors.
public static boolean processDescriptors(Processor<MavenPluginDescriptor> processor, MavenDomConfiguration cfg) {
Map<String, Map<String, Map<String, List<MavenPluginDescriptor>>>> map = getDescriptorsMap();
DomElement parent = cfg.getParent();
MavenDomPlugin plugin = DomUtil.getParentOfType(parent, MavenDomPlugin.class, false);
if (plugin == null)
return true;
Map<String, Map<String, List<MavenPluginDescriptor>>> groupMap = map.get(plugin.getArtifactId().getStringValue());
if (groupMap == null)
return true;
Map<String, List<MavenPluginDescriptor>> goalsMap = groupMap.get(plugin.getGroupId().getStringValue());
if (goalsMap == null)
return true;
List<MavenPluginDescriptor> descriptorsForAllGoals = goalsMap.get(null);
if (descriptorsForAllGoals != null) {
for (MavenPluginDescriptor descriptor : descriptorsForAllGoals) {
if (!processor.process(descriptor))
return false;
}
}
if (parent instanceof MavenDomPluginExecution) {
for (MavenDomGoal goal : ((MavenDomPluginExecution) parent).getGoals().getGoals()) {
List<MavenPluginDescriptor> descriptors = goalsMap.get(goal.getStringValue());
if (descriptors != null) {
for (MavenPluginDescriptor descriptor : descriptors) {
if (!processor.process(descriptor))
return false;
}
}
}
}
return true;
}
Aggregations