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);
}
Aggregations