Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 7348665

Browse filesBrowse files
author
dlsmith
committed
DynamicJava: Fixed Java5Class handling of parameterized static nested classes: Map.Entry<K,V> was being treated incorrectly as a raw type (because "Map" is raw). Improved error printing of anonymous class names.
git-svn-id: file:///tmp/test-svn/trunk@5065 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent ede26ce commit 7348665
Copy full SHA for 7348665

2 files changed

+37-48Lines changed: 37 additions & 48 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎dynamicjava/src/edu/rice/cs/dynamicjava/symbol/Java5Class.java‎

Copy file name to clipboardExpand all lines: dynamicjava/src/edu/rice/cs/dynamicjava/symbol/Java5Class.java
+16-22Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -134,35 +134,29 @@ private static Type classAsType(Class<?> c) {
134134

135135
private static Type convertParameterizedType(ParameterizedType paramT,
136136
final PrecomputedRecursionStack<java.lang.reflect.Type, Type> stack) {
137-
Iterable<Type> targsBuilder = IterUtil.empty();
138-
boolean raw = false; // true iff an enclosing type is raw, and so this type must also be raw
137+
// assumes getRawType and getOwnerType return class types
138+
ClassType rawT = (ClassType) convertType(paramT.getRawType(), stack);
139+
ClassType ownerT = (paramT.getOwnerType() == null) ? null : (ClassType) convertType(paramT.getOwnerType(), stack);
140+
ClassType enclosingT = rawT.ofClass().isStatic() ? SymbolUtil.dynamicOuterClassType(ownerT) : ownerT;
139141

140-
if (paramT.getOwnerType() != null) {
141-
Type ownerT = convertType(paramT.getOwnerType(), stack);
142-
Iterable<? extends Type> outerArgs = ownerT.apply(new TypeAbstractVisitor<Iterable<? extends Type>>() {
143-
144-
public Iterable<? extends Type> defaultCase(Type ownerT) {
145-
throw new IllegalArgumentException("Owner of ParameterizedType must be a class type");
146-
}
147-
148-
@Override public Iterable<? extends Type> forSimpleClassType(SimpleClassType ownerT) {
142+
Iterable<? extends Type> outerArgs = IterUtil.empty();
143+
boolean raw = false; // true iff an enclosing type is raw, and so this type must also be raw
144+
if (enclosingT != null) {
145+
Iterable<? extends Type> ts = enclosingT.apply(new TypeAbstractVisitor<Iterable<? extends Type>>() {
146+
@Override public Iterable<? extends Type> forSimpleClassType(SimpleClassType enclosingT) {
149147
return IterUtil.empty();
150148
}
151-
152-
@Override public Iterable<? extends Type> forRawClassType(RawClassType ownerT) { return null; }
153-
154-
@Override public Iterable<? extends Type> forParameterizedClassType(ParameterizedClassType ownerT) {
155-
return ownerT.typeArguments();
149+
@Override public Iterable<? extends Type> forRawClassType(RawClassType enclosingT) { return null; }
150+
@Override public Iterable<? extends Type> forParameterizedClassType(ParameterizedClassType enclosingT) {
151+
return enclosingT.typeArguments();
156152
}
157153
});
158-
if (outerArgs == null) { raw = true; }
159-
else { targsBuilder = IterUtil.compose(targsBuilder, outerArgs); }
154+
if (ts == null) { raw = true; }
155+
else { outerArgs = ts; }
160156
}
161157

162-
targsBuilder = IterUtil.compose(targsBuilder, convertTypes(paramT.getActualTypeArguments(), stack));
163-
164-
Type rawT = convertType(paramT.getRawType(), stack);
165-
final Iterable<Type> targs = targsBuilder; // targsBuilder must be redeclared as final
158+
Iterable<Type> directArgs = convertTypes(paramT.getActualTypeArguments(), stack);
159+
final Iterable<Type> targs = IterUtil.compose(outerArgs, directArgs);
166160
Type result = rawT.apply(new TypeAbstractVisitor<Type>() {
167161

168162
public Type defaultCase(Type t) {
Collapse file

‎dynamicjava/src/edu/rice/cs/dynamicjava/symbol/StandardTypeSystem.java‎

Copy file name to clipboardExpand all lines: dynamicjava/src/edu/rice/cs/dynamicjava/symbol/StandardTypeSystem.java
+21-26Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ public String userRepresentation(Type t) {
627627

628628
public String userRepresentation(Iterable<? extends Type> ts) {
629629
TypeWriter w = new TypeWriter();
630-
w.runOnList(ts);
630+
w.runOnList(ts, ", ");
631631
w.appendConstraints();
632632
return w.result();
633633
}
@@ -636,7 +636,7 @@ public String userRepresentation(Function f) {
636636
TypeWriter w = new TypeWriter();
637637
if (!IterUtil.isEmpty(f.typeParameters())) {
638638
w.append("<");
639-
w.runOnList(f.typeParameters());
639+
w.runOnList(f.typeParameters(), ", ");
640640
w.append("> ");
641641
}
642642
if (!(f instanceof DJConstructor)) {
@@ -645,7 +645,7 @@ public String userRepresentation(Function f) {
645645
}
646646
w.append(f.declaredName());
647647
w.append("(");
648-
w.runOnList(SymbolUtil.parameterTypes(f));
648+
w.runOnList(SymbolUtil.parameterTypes(f), ", ");
649649
w.append(")");
650650
w.appendConstraints();
651651
return w.result();
@@ -688,10 +688,10 @@ public void appendConstraints() {
688688
_stack.run(recur, dontRecur, t/*, 2*/);
689689
}
690690

691-
public void runOnList(Iterable<? extends Type> ts) {
691+
public void runOnList(Iterable<? extends Type> ts, String delim) {
692692
boolean first = true;
693693
for (Type t : ts) {
694-
if (!first) { _result.append(", "); }
694+
if (!first) { _result.append(delim); }
695695
first = false;
696696
run(t);
697697
}
@@ -720,20 +720,18 @@ public void forVarargArrayType(VarargArrayType t) {
720720
_result.append("...");
721721
}
722722

723-
public void forSimpleClassType(SimpleClassType t) {
724-
_result.append(SymbolUtil.shortName(t.ofClass()));
725-
}
723+
public void forSimpleClassType(SimpleClassType t) { appendClassName(t.ofClass()); }
726724

727725
public void forRawClassType(RawClassType t) {
728726
_result.append("raw ");
729-
_result.append(SymbolUtil.shortName(t.ofClass()));
727+
appendClassName(t.ofClass());
730728
}
731729

732730
public void forParameterizedClassType(ParameterizedClassType t) {
733731
Iterator<DJClass> classes = SymbolUtil.outerClassChain(t.ofClass()).iterator();
734732
Iterator<? extends Type> targs = t.typeArguments().iterator();
735733
DJClass c = classes.next();
736-
_result.append(SymbolUtil.shortName(c));
734+
appendClassName(c);
737735
DJClass inner;
738736
while (c != null) {
739737
inner = classes.hasNext() ? classes.next() : null; // next in the chain, or null if c is last
@@ -755,6 +753,14 @@ public void forParameterizedClassType(ParameterizedClassType t) {
755753
}
756754
}
757755

756+
private void appendClassName(DJClass c) {
757+
if (c.isAnonymous()) {
758+
_result.append("anonymous ");
759+
runOnList(c.declaredSupertypes(), " & ");
760+
}
761+
else { _result.append(SymbolUtil.shortName(c)); }
762+
}
763+
758764
public void forVariableType(VariableType t) {
759765
String name = _variableHandler.registerVariable(t);
760766
_result.append(name);
@@ -768,14 +774,7 @@ else if (size == 1) {
768774
run(IterUtil.first(t.ofTypes()));
769775
_result.append(")");
770776
}
771-
else {
772-
boolean first = true;
773-
for (Type componentT : t.ofTypes()) {
774-
if (first) { first = false; }
775-
else { _result.append(" & "); }
776-
run(componentT);
777-
}
778-
}
777+
else { runOnList(t.ofTypes(), " & "); }
779778
}
780779

781780
public void forUnionType(UnionType t) {
@@ -786,14 +785,7 @@ else if (size == 1) {
786785
run(IterUtil.first(t.ofTypes()));
787786
_result.append(")");
788787
}
789-
else {
790-
boolean first = true;
791-
for (Type componentT : t.ofTypes()) {
792-
if (first) { first = false; }
793-
else { _result.append(" | "); }
794-
run(componentT);
795-
}
796-
}
788+
else { runOnList(t.ofTypes(), " | "); }
797789
}
798790

799791
public void forWildcard(Wildcard t) {
@@ -1783,6 +1775,9 @@ protected MethodFinder(String name, Access.Module accessModule, boolean onlyStat
17831775
debug.logStart(new String[]{"t","name","onlyStatic"}, wrap(t), _name, _onlyStatic); try {
17841776

17851777
PredicateSet<DJMethod> candidates = findAll(t);
1778+
if (_name.equals("entrySet")) {
1779+
Type foo = candidates.iterator().next().returnType();
1780+
}
17861781
Iterable<FunctionInvocationCandidate<DJMethod>> best = bestInvocations(candidates, targs, args, expected);
17871782
// TODO: provide more error-message information
17881783
int matches = IterUtil.sizeOf(best);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.