diff --git a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/XPathPanelController.java b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/XPathPanelController.java index 181172d7c0..1002a452a5 100644 --- a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/XPathPanelController.java +++ b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/XPathPanelController.java @@ -125,9 +125,7 @@ public class XPathPanelController implements Initializable, SettingsOwner { .subscribe(t -> { try { if (xpathExpressionArea.getText().contains("/")) { - if (t.getInserted().equals("/")) { - autoComplete(xpathExpressionArea.getText().substring(xpathExpressionArea.getText().indexOf("/"))); - } else { + if (!t.getInserted().equals("/")) { autoComplete(xpathExpressionArea.getText().substring(xpathExpressionArea.getText().lastIndexOf("/"))); } } @@ -145,7 +143,7 @@ public class XPathPanelController implements Initializable, SettingsOwner { List resultToDisplay = new ArrayList<>(); String language = parent.getLanguageVersion().getName().replaceAll("[0-9]", "").replaceAll("//s", "").toLowerCase().trim(); - XPathSuggestions xPathSuggestions = new XPathSuggestions("net.sourceforge.pmd.lang." + language + ".ast"); + XPathSuggestions xPathSuggestions = new XPathSuggestions(language); List suggestions = xPathSuggestions.getXPathSuggestions(); for (String s1 : suggestions) { @@ -171,7 +169,6 @@ public class XPathPanelController implements Initializable, SettingsOwner { xpathExpressionArea.insertText(xpathExpressionArea.getCaretPosition(), ((MenuItem) e.getTarget()).getText().replace(temp.get(temp.size() - 1) .replace("/", "").trim(), "").trim()); autoCompletePopup.hide(); - }); } }); diff --git a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/model/XPathSuggestions.java b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/model/XPathSuggestions.java index 2da0710e2f..03cecaa5d1 100644 --- a/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/model/XPathSuggestions.java +++ b/pmd-ui/src/main/java/net/sourceforge/pmd/util/fxdesigner/model/XPathSuggestions.java @@ -17,10 +17,12 @@ import java.util.List; public class XPathSuggestions { private List xPathSuggestions = new ArrayList<>(); - String packagename; + private String packagename; + private String language; - public XPathSuggestions(String packageName) { - this.packagename = packageName; + public XPathSuggestions(String language) { + this.packagename = "net.sourceforge.pmd.lang." + language + ".ast"; + this.language = language; } @@ -87,7 +89,6 @@ public class XPathSuggestions { } private List evaluateXpathSuggestions(List fileNameList) { - String language = packagename.replace("net.sourceforge.pmd.lang.", "").replace(".ast", "").trim(); for (String s : fileNameList) { xPathSuggestions.add(s.replace("AST", "").replace("." + language, "").replace("net.sourceforge.pmd.lang.ast" + ".", "")); } return xPathSuggestions;