Permalink
Browse files

model support for autocompleting overloaded decs

  • Loading branch information...
gavinking committed Feb 27, 2012
1 parent adb68ca commit 8c4cfe957f6b85feb4060c79ec533d6f92e58b23
@@ -120,12 +120,12 @@ else if (getContainer()!=null) {
}
}
- public Map<String, DeclarationWithProximity> getMatchingDeclarations(Unit unit, String startingWith, int proximity) {
- Map<String, DeclarationWithProximity> result = getContainer()
+ public Map<DeclarationKey, DeclarationWithProximity> getMatchingDeclarations(Unit unit, String startingWith, int proximity) {
+ Map<DeclarationKey, DeclarationWithProximity> result = getContainer()
.getMatchingDeclarations(unit, startingWith, proximity+1);
for (Declaration d: getMembers()) {
if (isResolvable(d) && isNameMatching(startingWith, d)) {
- result.put(d.getName(), new DeclarationWithProximity(d, proximity));
+ result.put(new DeclarationKey(d), new DeclarationWithProximity(d, proximity));
}
}
return result;
@@ -73,7 +73,7 @@ public void setContainer(Package container) {
}
@Override
- public Map<String, DeclarationWithProximity> getMatchingDeclarations(Unit unit,
+ public Map<DeclarationKey, DeclarationWithProximity> getMatchingDeclarations(Unit unit,
String startingWith, int proximity) {
if (importedPackage!=null) {
return importedPackage.getImportableDeclarations(unit, startingWith, imports, proximity);
@@ -17,12 +17,12 @@ public void setParameterList(ParameterList parameterList) {
}
@Override
- public Map<String, DeclarationWithProximity> getMatchingDeclarations(Unit unit, String startingWith, int proximity) {
- Map<String, DeclarationWithProximity> result = super.getMatchingDeclarations(unit, startingWith, proximity+1);
+ public Map<DeclarationKey, DeclarationWithProximity> getMatchingDeclarations(Unit unit, String startingWith, int proximity) {
+ Map<DeclarationKey, DeclarationWithProximity> result = super.getMatchingDeclarations(unit, startingWith, proximity+1);
if (getParameterList()!=null) {
for (Parameter p: getParameterList().getParameters()) {
if (p.getName().startsWith(startingWith) && !getArgumentNames().contains(p.getName())) {
- result.put(p.getName(), new DeclarationWithProximity(p, proximity));
+ result.put(new DeclarationKey(p), new DeclarationWithProximity(p, proximity));
}
}
}
@@ -6,9 +6,9 @@
import static com.redhat.ceylon.compiler.typechecker.model.Util.lookupMember;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.TreeMap;
public class Package implements Scope {
@@ -155,11 +155,11 @@ public TypeDeclaration getInheritingDeclaration(Declaration d) {
}
@Override
- public Map<String, DeclarationWithProximity> getMatchingDeclarations(Unit unit, String startingWith, int proximity) {
- Map<String, DeclarationWithProximity> result = new TreeMap<String, DeclarationWithProximity>();
+ public Map<DeclarationKey, DeclarationWithProximity> getMatchingDeclarations(Unit unit, String startingWith, int proximity) {
+ Map<DeclarationKey, DeclarationWithProximity> result = new HashMap<DeclarationKey, DeclarationWithProximity>();
for (Declaration d: getMembers()) {
if (isResolvable(d) && isNameMatching(startingWith, d)) {
- result.put(d.getName(), new DeclarationWithProximity(d, proximity+1));
+ result.put(new DeclarationKey(d), new DeclarationWithProximity(d, proximity+1));
}
}
if (unit!=null) {
@@ -168,8 +168,8 @@ public TypeDeclaration getInheritingDeclaration(Declaration d) {
return result;
}
- Map<String, DeclarationWithProximity> getImportableDeclarations(Unit unit, String startingWith, List<Import> imports, int proximity) {
- Map<String, DeclarationWithProximity> result = new TreeMap<String, DeclarationWithProximity>();
+ Map<DeclarationKey, DeclarationWithProximity> getImportableDeclarations(Unit unit, String startingWith, List<Import> imports, int proximity) {
+ Map<DeclarationKey, DeclarationWithProximity> result = new HashMap<DeclarationKey, DeclarationWithProximity>();
for (Declaration d: getMembers()) {
if (isResolvable(d) && d.isShared() && isNameMatching(startingWith, d) ) {
boolean already = false;
@@ -180,7 +180,7 @@ public TypeDeclaration getInheritingDeclaration(Declaration d) {
}
}
if (!already) {
- result.put(d.getName(), new DeclarationWithProximity(d, proximity));
+ result.put(new DeclarationKey(d), new DeclarationWithProximity(d, proximity));
}
}
}
@@ -26,7 +26,7 @@
public Scope getContainer();
- public Map<String, DeclarationWithProximity> getMatchingDeclarations(Unit unit, String startingWith, int proximity);
+ public Map<DeclarationKey, DeclarationWithProximity> getMatchingDeclarations(Unit unit, String startingWith, int proximity);
@Deprecated
public List<Declaration> getMembers();
@@ -509,16 +509,16 @@ public ProducedType getSelfType() {
}
@Override
- public Map<String, DeclarationWithProximity> getMatchingDeclarations(Unit unit, String startingWith, int proximity) {
- Map<String, DeclarationWithProximity> result = getMatchingMemberDeclarations(startingWith, proximity);
+ public Map<DeclarationKey, DeclarationWithProximity> getMatchingDeclarations(Unit unit, String startingWith, int proximity) {
+ Map<DeclarationKey, DeclarationWithProximity> result = getMatchingMemberDeclarations(startingWith, proximity);
//TODO: is this correct? I thought inherited declarations hide outer
// declarations! I think this is a bug
result.putAll(super.getMatchingDeclarations(unit, startingWith, proximity));
return result;
}
- public Map<String, DeclarationWithProximity> getMatchingMemberDeclarations(String startingWith, int proximity) {
- Map<String, DeclarationWithProximity> result = new TreeMap<String, DeclarationWithProximity>();
+ public Map<DeclarationKey, DeclarationWithProximity> getMatchingMemberDeclarations(String startingWith, int proximity) {
+ Map<DeclarationKey, DeclarationWithProximity> result = new HashMap<DeclarationKey, DeclarationWithProximity>();
TypeDeclaration et = getExtendedTypeDeclaration();
for (TypeDeclaration st: getSatisfiedTypeDeclarations()) {
//TODO: account for the case where one interface refines
@@ -534,7 +534,7 @@ public ProducedType getSelfType() {
for (Declaration d: getMembers()) {
if (isResolvable(d) && d.isShared() &&
isNameMatching(startingWith, d)) {
- result.put(d.getName(), new DeclarationWithProximity(d, proximity));
+ result.put(new DeclarationKey(d), new DeclarationWithProximity(d, proximity));
}
}
//TODO: self type?
@@ -87,16 +87,16 @@ public boolean isVariable() {
}
@Override
- public Map<String, DeclarationWithProximity> getMatchingDeclarations(Unit unit, String startingWith, int proximity) {
- Map<String, DeclarationWithProximity> result = super.getMatchingDeclarations(unit, startingWith, proximity);
+ public Map<DeclarationKey, DeclarationWithProximity> getMatchingDeclarations(Unit unit, String startingWith, int proximity) {
+ Map<DeclarationKey, DeclarationWithProximity> result = super.getMatchingDeclarations(unit, startingWith, proximity);
TypeDeclaration td = getTypeDeclaration();
if (td instanceof Class && !((Class) td).isAbstract()) {
//in case this is a named argument style definition,
//add the parameters of the return type
//TODO: they should not hide locals with the same name!
for ( Parameter p: ((Class) td).getParameterList().getParameters() ) {
if ( isNameMatching(startingWith, p) ) {
- result.put(p.getName(), new DeclarationWithProximity(p, proximity));
+ result.put(new DeclarationKey(p), new DeclarationWithProximity(p, proximity));
}
}
}
@@ -63,10 +63,10 @@ else if (getCaseTypes().size()==1) {
}
@Override
- public Map<String, DeclarationWithProximity> getMatchingMemberDeclarations(String startingWith, int proximity) {
+ public Map<DeclarationKey, DeclarationWithProximity> getMatchingMemberDeclarations(String startingWith, int proximity) {
//TODO: this can result in the wrong parameter types, and the
// same bug also affects intersection types
- Map<String, DeclarationWithProximity> result = super.getMatchingMemberDeclarations(startingWith, proximity);
+ Map<DeclarationKey, DeclarationWithProximity> result = super.getMatchingMemberDeclarations(startingWith, proximity);
result.putAll(getCaseTypes().get(0).getDeclaration().getMatchingMemberDeclarations(startingWith, proximity));
for (ProducedType ct: getCaseTypes()) {
result.keySet().retainAll(ct.getDeclaration().getMatchingMemberDeclarations(startingWith, proximity).keySet());
@@ -5,11 +5,11 @@
import static com.redhat.ceylon.compiler.typechecker.model.Util.unionType;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
-import java.util.TreeMap;
import com.redhat.ceylon.compiler.typechecker.tree.Tree.Identifier;
@@ -113,12 +113,12 @@ public Declaration getImportedDeclaration(TypeDeclaration td, String name,
return null;
}
- public Map<String, DeclarationWithProximity> getMatchingImportedDeclarations(String startingWith, int proximity) {
- Map<String, DeclarationWithProximity> result = new TreeMap<String, DeclarationWithProximity>();
+ public Map<DeclarationKey, DeclarationWithProximity> getMatchingImportedDeclarations(String startingWith, int proximity) {
+ Map<DeclarationKey, DeclarationWithProximity> result = new HashMap<DeclarationKey, DeclarationWithProximity>();
for (Import i: getImports()) {
if (i.getAlias()!=null &&
i.getAlias().toLowerCase().startsWith(startingWith.toLowerCase())) {
- result.put(i.getAlias(), new DeclarationWithProximity(i, proximity));
+ result.put(new DeclarationKey(i), new DeclarationWithProximity(i, proximity));
}
}
return result;
@@ -201,6 +201,11 @@ static boolean isNameMatching(String startingWith, Declaration d) {
d.getName().toLowerCase().startsWith(startingWith.toLowerCase());
}
+ static boolean isAbstraction(Declaration d) {
+ return d instanceof Functional ?
+ ((Functional) d).isAbstraction() : false;
+ }
+
/**
* Collect together type arguments given a list of
* type arguments to a declaration and the receiving

0 comments on commit 8c4cfe9

Please sign in to comment.