Skip to content

Commit 6a0664a

Browse files
author
dlsmith
committed
DynamicJava: Fixed process of assigning type arguments to static inner classes.
git-svn-id: file:///tmp/test-svn/trunk@4960 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent 5d5ee31 commit 6a0664a

File tree

2 files changed

+24
-33
lines changed

2 files changed

+24
-33
lines changed

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

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
import koala.dynamicjava.tree.*;
1313
import koala.dynamicjava.interpreter.TypeUtil;
1414
import koala.dynamicjava.interpreter.NodeProperties;
15-
import edu.rice.cs.dynamicjava.symbol.TypeSystem.InvalidTypeArgumentException;
1615
import edu.rice.cs.dynamicjava.symbol.type.*;
1716

1817
import static edu.rice.cs.plt.debug.DebugUtil.debug;
@@ -1429,7 +1428,7 @@ public boolean matches() {
14291428

14301429
public boolean matchesWithVarargs() {
14311430
if (_matchesAllButLast && _paramForVarargs instanceof VarargArrayType) {
1432-
ArrayType arrayT = (ArrayType) substitute((ArrayType) _paramForVarargs, _tparams, _targs);
1431+
ArrayType arrayT = (ArrayType) substitute(_paramForVarargs, _tparams, _targs);
14331432
Type elementT = arrayT.ofType();
14341433
_argForVarargs = boxingConvert(_argForVarargs, elementT);
14351434
// TODO: Allow unchecked conversion of raw types?
@@ -1557,7 +1556,7 @@ public EmptyVarargChecker(Iterable<? extends Type> params, Iterable<? extends Ex
15571556
boxArgs();
15581557
if (super.matches()) {
15591558
_params = IterUtil.compose(_params, _varargParam);
1560-
ArrayType arrayT = (ArrayType) substitute((ArrayType) _varargParam, _tparams, _targs);
1559+
ArrayType arrayT = (ArrayType) substitute(_varargParam, _tparams, _targs);
15611560
_args = IterUtil.compose(_args, makeArray(arrayT, EMPTY_EXPRESSION_ITERABLE));
15621561
return true;
15631562
}
@@ -1590,7 +1589,7 @@ public EmptyVarargInferenceChecker(Iterable<? extends Type> params, Iterable<? e
15901589
boxArgs();
15911590
if (super.matches()) {
15921591
_params = IterUtil.compose(_params, _varargParam);
1593-
ArrayType arrayT = (ArrayType) substitute((ArrayType) _varargParam, _tparams, _targs);
1592+
ArrayType arrayT = (ArrayType) substitute(_varargParam, _tparams, _targs);
15941593
_args = IterUtil.compose(_args, makeArray(arrayT, EMPTY_EXPRESSION_ITERABLE));
15951594
return true;
15961595
}
@@ -1625,7 +1624,7 @@ public MultiVarargChecker(Iterable<? extends Type> params, Iterable<? extends Ex
16251624
if (_varargParam instanceof VarargArrayType) {
16261625
boxArgs();
16271626
if (super.matches()) {
1628-
ArrayType arrayT = (ArrayType) substitute((ArrayType) _varargParam, _tparams, _targs);
1627+
ArrayType arrayT = (ArrayType) substitute(_varargParam, _tparams, _targs);
16291628
Type elementT = arrayT.ofType();
16301629
Iterable<Expression> boxedVarargArgs = EMPTY_EXPRESSION_ITERABLE;
16311630
for (Expression arg : _varargArgs) {
@@ -2534,7 +2533,7 @@ private ClassType lookupClass(Type t, Lambda<? super Boolean, ? extends Predicat
25342533
}
25352534

25362535
@Override public ClassType forRawClassType(RawClassType t) {
2537-
return t; // TODO: Handle parameterized raw members (such as Foo.Bar<T> vs. Foo<X>.Bar<T>)
2536+
return t;
25382537
}
25392538

25402539
@Override public ClassType forParameterizedClassType(ParameterizedClassType t) {
@@ -2560,7 +2559,9 @@ private ClassType lookupClass(Type t, Lambda<? super Boolean, ? extends Predicat
25602559
/**
25612560
* Produces a list of all inner classes matching the given predicate in type {@code t}. No
25622561
* errors are thrown. The given type arguments are applied to the result, but no checks are
2563-
* made for their correctness.
2562+
* made for their correctness (a ParameterizedClassType result may have the wrong number of
2563+
* arguments, including the case of missing arguments from a raw outer type; a SimpleClassType
2564+
* result may be missing arguments).
25642565
*/
25652566
private Iterable<? extends ClassType>
25662567
lookupClasses(Type t, Lambda<? super Boolean, ? extends Predicate<? super DJClass>> makePred,
@@ -2576,33 +2577,23 @@ public LookupClass(Predicate<? super DJClass> matchInner) {
25762577

25772578
public Iterable<ClassType> defaultCase(Type t) { return IterUtil.empty(); }
25782579

2579-
@Override public Iterable<ClassType> forSimpleClassType(SimpleClassType t) {
2580-
Lambda<DJClass, ClassType> makeType;
2581-
if (IterUtil.isEmpty(typeArgs)) {
2582-
makeType = new Lambda<DJClass, ClassType>() {
2583-
public ClassType value(DJClass c) { return new SimpleClassType(c); }
2584-
};
2585-
}
2586-
else {
2587-
makeType = new Lambda<DJClass, ClassType>() {
2588-
public ClassType value(DJClass c) { return new ParameterizedClassType(c, typeArgs); }
2589-
};
2590-
}
2591-
return IterUtil.mapSnapshot(IterUtil.filter(t.ofClass().declaredClasses(), _matchInner), makeType);
2592-
}
2593-
2594-
@Override public Iterable<ClassType> forRawClassType(RawClassType t) {
2595-
// TODO: Handle raw member access warnings
2596-
Lambda<DJClass, ClassType> makeType = new Lambda<DJClass, ClassType>() {
2597-
public ClassType value(DJClass c) { return new RawClassType(c); }
2598-
};
2599-
return IterUtil.mapSnapshot(IterUtil.filter(t.ofClass().declaredClasses(), _matchInner), makeType);
2600-
}
2601-
2602-
@Override public Iterable<ClassType> forParameterizedClassType(final ParameterizedClassType t) {
2580+
@Override public Iterable<ClassType> forClassType(final ClassType t) {
26032581
Lambda<DJClass, ClassType> makeType = new Lambda<DJClass, ClassType>() {
26042582
public ClassType value(DJClass c) {
2605-
return new ParameterizedClassType(c, IterUtil.compose(t.typeArguments(), typeArgs));
2583+
ClassType dynamicOuter; // may be null
2584+
if (c.isStatic()) { dynamicOuter = SymbolUtil.dynamicOuterClassType(t); }
2585+
else { dynamicOuter = t; }
2586+
if (dynamicOuter instanceof ParameterizedClassType) {
2587+
Iterable<? extends Type> outerTypeArgs = ((ParameterizedClassType) dynamicOuter).typeArguments();
2588+
return new ParameterizedClassType(c, IterUtil.compose(outerTypeArgs, typeArgs));
2589+
}
2590+
else if (dynamicOuter instanceof RawClassType) {
2591+
// malformed if type args is nonempty -- that should be caught by the caller
2592+
return IterUtil.isEmpty(typeArgs) ? new RawClassType(c) : new ParameterizedClassType(c, typeArgs);
2593+
}
2594+
else {
2595+
return IterUtil.isEmpty(typeArgs) ? new SimpleClassType(c) : new ParameterizedClassType(c, typeArgs);
2596+
}
26062597
}
26072598
};
26082599
return IterUtil.mapSnapshot(IterUtil.filter(t.ofClass().declaredClasses(), _matchInner), makeType);

dynamicjava/src/koala/dynamicjava/parser/grammar.jj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3505,7 +3505,7 @@ PARSER_END(Parser)
35053505
TypeParameter typeParameter() :
35063506
{
35073507
List<IdentifierToken> name;
3508-
TypeName bound = new ReferenceTypeName("Object");
3508+
TypeName bound = new ReferenceTypeName("java.lang.Object");
35093509
List<ReferenceTypeName> interfaceBoundsList = new LinkedList<ReferenceTypeName>();
35103510
ReferenceTypeName interf;
35113511
}

0 commit comments

Comments
 (0)