Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -28,61 +27,62 @@
* @author leon, [email protected]
*/
public class CompletionHelper {

private CompletionHelper() {
}

public static String getCanonicalPath(List<EntityNameReference> qts, String name) {
Map<String, String> alias2Type = new HashMap<String, String>();
for (Iterator<EntityNameReference> iter = qts.iterator(); iter.hasNext();) {
EntityNameReference qt = iter.next();
alias2Type.put(qt.getAlias(), qt.getEntityName());
Map<String, String> alias2Type = new HashMap<>();
for ( EntityNameReference qt : qts ) {
alias2Type.put( qt.getAlias(), qt.getEntityName() );
}
if (qts.size() == 1) {
EntityNameReference visible = (EntityNameReference) qts.get(0);
if (qts.size() == 1) {
EntityNameReference visible = qts.get(0);
String alias = visible.getAlias();
if (name.equals(alias)) {
return visible.getEntityName();
} else if (alias == null || alias.length() == 0 || alias.equals(visible.getEntityName())) {
}
else if (alias == null || alias.isEmpty() || alias.equals(visible.getEntityName())) {
return visible.getEntityName() + "/" + name;
}
}
return getCanonicalPath(new HashSet<String>(), alias2Type, name);
return getCanonicalPath( new HashSet<>(), alias2Type, name);
}


private static String getCanonicalPath(Set<String> resolved, Map<String, String> alias2Type, String name) {
if (resolved.contains(name)) {
// To prevent a stack overflow
return name;
}
resolved.add(name);
String type = (String) alias2Type.get(name);
String type = alias2Type.get(name);
if (type != null) {
return name.equals(type) ? name : getCanonicalPath(resolved, alias2Type, type);
}
int idx = name.lastIndexOf('.');
if (idx == -1) {
return type != null ? type : name;
return name;
}
String baseName = name.substring(0, idx);
String prop = name.substring(idx + 1);
if (isAliasNown(alias2Type, baseName)) {
if (isAliasKnown(alias2Type, baseName)) {
return getCanonicalPath(resolved, alias2Type, baseName) + "/" + prop;
} else {
}
else {
return name;
}
}
private static boolean isAliasNown(Map<String, String> alias2Type, String alias) {

private static boolean isAliasKnown(Map<String, String> alias2Type, String alias) {
if (alias2Type.containsKey(alias)) {
return true;
}
int idx = alias.lastIndexOf('.');
if (idx == -1) {
return false;
}
return isAliasNown(alias2Type, alias.substring(0, idx));
}
return isAliasKnown(alias2Type, alias.substring(0, idx));
}

}
Loading