Search in sources :

Example 1 with MavenDomShortArtifactCoordinates

use of org.jetbrains.idea.maven.dom.model.MavenDomShortArtifactCoordinates in project intellij-community by JetBrains.

the class IntroducePropertyDialog method getSuggestions.

private String[] getSuggestions(int level) {
    Collection<String> result = new THashSet<>();
    String value = mySelectedString.trim();
    boolean addUnqualifiedForm = true;
    XmlTag parent = PsiTreeUtil.getParentOfType(myContext, XmlTag.class, false);
    DomElement domParent = DomUtil.getDomElement(parent);
    if (domParent != null) {
        DomElement domSuperParent = domParent.getParent();
        DomFileElement<DomElement> domFile = DomUtil.getFileElement(domParent);
        if (domSuperParent != null && domFile != null && domFile.getRootElement() == domSuperParent) {
            value = domSuperParent.getXmlElementName();
            addUnqualifiedForm = false;
        } else {
            MavenDomShortArtifactCoordinates coordinates = DomUtil.getParentOfType(domParent, MavenDomShortArtifactCoordinates.class, false);
            if (coordinates != null && !(coordinates instanceof MavenDomProjectModel) && domParent != coordinates.getArtifactId()) {
                String artifactId = coordinates.getArtifactId().getStringValue();
                if (!StringUtil.isEmptyOrSpaces(artifactId)) {
                    value = artifactId;
                    addUnqualifiedForm = false;
                }
            }
        }
    }
    while (true) {
        String newValue = value.replaceAll("  ", " ");
        if (newValue.equals(value))
            break;
        value = newValue;
    }
    value = value.replaceAll(" ", ".");
    List<String> parts = StringUtil.split(value, ".");
    String shortValue = parts.get(parts.size() - 1);
    if (addUnqualifiedForm) {
        result.add(value);
        result.add(shortValue);
    }
    String suffix = "";
    while (parent != null && level != 0) {
        suffix = parent.getName() + suffix;
        result.add(suffix);
        result.add(value + "." + suffix);
        result.add(shortValue + "." + suffix);
        suffix = "." + suffix;
        parent = parent.getParentTag();
        level--;
    }
    result = new ArrayList<>(result);
    Collections.sort((List) result, CodeStyleSettingsManager.getSettings(myProject).PREFER_LONGER_NAMES ? StringLenComparator.getDescendingInstance() : StringLenComparator.getInstance());
    return ArrayUtil.toStringArray(result);
}
Also used : MavenDomProjectModel(org.jetbrains.idea.maven.dom.model.MavenDomProjectModel) DomElement(com.intellij.util.xml.DomElement) MavenDomShortArtifactCoordinates(org.jetbrains.idea.maven.dom.model.MavenDomShortArtifactCoordinates) THashSet(gnu.trove.THashSet) XmlTag(com.intellij.psi.xml.XmlTag)

Aggregations

XmlTag (com.intellij.psi.xml.XmlTag)1 DomElement (com.intellij.util.xml.DomElement)1 THashSet (gnu.trove.THashSet)1 MavenDomProjectModel (org.jetbrains.idea.maven.dom.model.MavenDomProjectModel)1 MavenDomShortArtifactCoordinates (org.jetbrains.idea.maven.dom.model.MavenDomShortArtifactCoordinates)1