Search in sources :

Example 1 with With

use of org.jetbrains.idea.devkit.dom.With 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);
    }
}
Also used : DomElement(com.intellij.util.xml.DomElement) ExtensionPoint(org.jetbrains.idea.devkit.dom.ExtensionPoint) PsiField(com.intellij.psi.PsiField) PsiClass(com.intellij.psi.PsiClass) PsiElement(com.intellij.psi.PsiElement) ExtensionPoint(org.jetbrains.idea.devkit.dom.ExtensionPoint) With(org.jetbrains.idea.devkit.dom.With)

Aggregations

PsiClass (com.intellij.psi.PsiClass)1 PsiElement (com.intellij.psi.PsiElement)1 PsiField (com.intellij.psi.PsiField)1 DomElement (com.intellij.util.xml.DomElement)1 ExtensionPoint (org.jetbrains.idea.devkit.dom.ExtensionPoint)1 With (org.jetbrains.idea.devkit.dom.With)1