Skip to content

Commit

Permalink
fix to mario's fix for array type declarations.
Browse files Browse the repository at this point in the history
  • Loading branch information
mikebrock committed Nov 2, 2011
1 parent e6468e8 commit f82790f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<version>4.8.2</version>
<scope>test</scope>
</dependency>

Expand Down
10 changes: 9 additions & 1 deletion src/main/java/org/mvel2/ast/TypeDescriptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,15 @@ public int getEndRange() {
public void setEndRange(int endRange) {
this.endRange = endRange;
}


public Class<?> getClassReference() throws ClassNotFoundException {
return getClassReference(null, this);
}

public Class<?> getClassReference(ParserContext ctx) throws ClassNotFoundException {
return getClassReference(ctx,this);
}

public static Class getClassReference(Class baseType,
TypeDescriptor tDescr,
VariableResolverFactory factory, ParserContext ctx) throws ClassNotFoundException {
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/org/mvel2/compiler/AbstractParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -1041,11 +1041,11 @@ else if ((cursor - 1) != start || (!isDigit(expr[cursor - 1])) && isDigit(lookAh
}

if (isCast) {
st = cursor;
captureToEOS();
st = cursor;
captureToEOS();

return lastNode = new TypeCast(expr, st, cursor - st,
cls, fields, pCtx);
return lastNode = new TypeCast(expr, st, cursor - st,
cls, fields, pCtx);
}
}
}
Expand Down Expand Up @@ -1333,10 +1333,16 @@ else if (lastWasIdentifier) {
}

if (pCtx != null && pCtx.hasImports() && isArrayType(expr, st, end)) {
if (pCtx.hasImport(tmp = new String(expr, st, cursor - st - 2))) {
if (pCtx.hasImport(new String(expr, st, cursor - st - 2))) {
lastWasIdentifier = true;
Class<?> arrayClass = java.lang.reflect.Array.newInstance((Class<?>)pCtx.getStaticOrClassImport(tmp), 0).getClass();
return lastNode = new LiteralNode(arrayClass);
TypeDescriptor typeDescriptor = new TypeDescriptor(expr, st, cursor - st, fields);

try {
return lastNode = new LiteralNode(typeDescriptor.getClassReference(pCtx));
}
catch (ClassNotFoundException e) {
throw new CompileException("could not resolve class: " + typeDescriptor.getClassName(), expr, st);
}
}
}

Expand Down

0 comments on commit f82790f

Please sign in to comment.