Skip to content

Commit

Permalink
Quick fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanue1 committed Nov 1, 2019
1 parent 9506382 commit 7fa1b8f
Show file tree
Hide file tree
Showing 11 changed files with 76 additions and 51 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies {
testCompile 'org.apache.commons:commons-collections4:4.1'
}

version='1.1.0'
version='1.1.1'

tasks.withType(JavaCompile) {
sourceCompatibility = targetCompatibility = '1.8'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,6 @@ protected static Type createItemType(Expression expression) {
Type type = expression.getType();
int dimension = type.getDimension();

assert (type == TYPE_UNDEFINED_OBJECT) || (dimension > 0) : "ArrayExpression.createItemType(exp) : zero or negative dimension";

return type.createType((dimension > 0) ? dimension-1 : 0);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public int getDimension() {

@Override
public Type createType(int dimension) {
assert dimension >= 0 : "ObjectType.createType(dim) : create type with zero or negative dimension";
assert dimension >= 0 : "ObjectType.createType(dim) : create type with negative dimension";

if (this.dimension == dimension) {
return this;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public int getRightFlags() {

@Override
public Type createType(int dimension) {
assert dimension >= 0 : "PrimitiveType.createType(dim) : create type with zero or negative dimension";
assert dimension >= 0 : "PrimitiveType.createType(dim) : create type with negative dimension";
if (dimension == 0) {
return this;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,15 @@ public String toString() {

@Override
public boolean isAssignableFrom(Type type) {
if (type.isObject()) {
return typeMaker.isAssignable((ObjectType) this.type, (ObjectType) type);
} else if (type.isGeneric()) {
if (this.type.isObject()) {
if (this.type.equals(TYPE_OBJECT)) {
return true;
if ((type.getDimension() > 0) || !type.isPrimitive()) {
return true;
}
}

if (type.isObject()) {
return typeMaker.isAssignable((ObjectType) this.type, (ObjectType) type);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import static org.jd.core.v1.model.javasyntax.declaration.Declaration.FLAG_STATIC;
import static org.jd.core.v1.model.javasyntax.declaration.Declaration.FLAG_SYNTHETIC;
import static org.jd.core.v1.model.javasyntax.statement.ReturnStatement.RETURN;
import static org.jd.core.v1.model.javasyntax.type.ObjectType.TYPE_OBJECT;
import static org.jd.core.v1.model.javasyntax.type.ObjectType.TYPE_UNDEFINED_OBJECT;
import static org.jd.core.v1.model.javasyntax.type.PrimitiveType.*;

Expand Down Expand Up @@ -261,7 +262,7 @@ public void parse(BasicBlock basicBlock, Statements statements, DefaultStack<Exp
expression1 = stack.pop();
Class clazz = expression1.getClass();
if ((clazz != ClassFileLocalVariableReferenceExpression.class) && (clazz != FieldReferenceExpression.class)) {
typeParametersToTypeArgumentsBinder.bindParameterTypesWithArgumentTypes(TYPE_VOID, expression1);
typeParametersToTypeArgumentsBinder.bindParameterTypesWithArgumentTypes(TYPE_OBJECT, expression1);
statements.add(new ExpressionStatement(expression1));
}
break;
Expand Down Expand Up @@ -726,7 +727,7 @@ public void parse(BasicBlock basicBlock, Statements statements, DefaultStack<Exp
if (opcode == 184) { // INVOKESTATIC
expression1 = typeParametersToTypeArgumentsBinder.newMethodInvocationExpression(lineNumber, new ObjectTypeReferenceExpression(lineNumber, ot), ot, name, descriptor, methodTypes, parameters);
if (TYPE_VOID.equals(methodTypes.returnedType)) {
typeParametersToTypeArgumentsBinder.bindParameterTypesWithArgumentTypes(TYPE_VOID, expression1);
typeParametersToTypeArgumentsBinder.bindParameterTypesWithArgumentTypes(TYPE_OBJECT, expression1);
statements.add(new ExpressionStatement(expression1));
} else {
stack.push(expression1);
Expand Down Expand Up @@ -755,7 +756,7 @@ public void parse(BasicBlock basicBlock, Statements statements, DefaultStack<Exp
} else {
expression1 = typeParametersToTypeArgumentsBinder.newMethodInvocationExpression(
lineNumber, getMethodInstanceReference(expression1, ot, name, descriptor), ot, name, descriptor, methodTypes, parameters);
typeParametersToTypeArgumentsBinder.bindParameterTypesWithArgumentTypes(TYPE_VOID, expression1);
typeParametersToTypeArgumentsBinder.bindParameterTypesWithArgumentTypes(TYPE_OBJECT, expression1);
statements.add(new ExpressionStatement(expression1));
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -941,7 +941,7 @@ private ObjectType searchSuperParameterizedType(long superHashCode, String super
BindTypeParametersToTypeArgumentsVisitor bindTypeParametersToTypeArgumentsVisitor = new BindTypeParametersToTypeArgumentsVisitor();
HashMap<String, TypeArgument> bindings = new HashMap<>();

if (rightTypeTypes.typeParameters.isList()) {
if (rightTypeTypes.typeParameters.isList() && objectType.getTypeArguments().isTypeArgumentList()) {
Iterator<TypeParameter> iteratorTypeParameter = rightTypeTypes.typeParameters.iterator();
Iterator<TypeArgument> iteratorTypeArgument = objectType.getTypeArguments().getTypeArgumentList().iterator();

Expand Down Expand Up @@ -1213,7 +1213,7 @@ private Type loadFieldType(ObjectType objectType, String fieldName, String descr
BindTypeParametersToTypeArgumentsVisitor bindTypeParametersToTypeArgumentsVisitor = new BindTypeParametersToTypeArgumentsVisitor();
HashMap<String, TypeArgument> bindings = new HashMap<>();

if (typeTypes.typeParameters.isList()) {
if (typeTypes.typeParameters.isList() && typeArguments.isTypeArgumentList()) {
Iterator<TypeParameter> iteratorTypeParameter = typeTypes.typeParameters.iterator();
Iterator<TypeArgument> iteratorTypeArgument = typeArguments.getTypeArgumentList().iterator();

Expand Down Expand Up @@ -1303,7 +1303,7 @@ private MethodTypes loadMethodTypes(ObjectType objectType, String methodName, St
HashMap<String, TypeArgument> bindings = new HashMap<>();
MethodTypes newMethodTypes = new MethodTypes();

if (typeTypes.typeParameters.isList()) {
if (typeTypes.typeParameters.isList() && typeArguments.isTypeArgumentList()) {
Iterator<TypeParameter> iteratorTypeParameter = typeTypes.typeParameters.iterator();
Iterator<TypeArgument> iteratorTypeArgument = typeArguments.getTypeArgumentList().iterator();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.*;

import static org.jd.core.v1.model.javasyntax.declaration.Declaration.FLAG_STATIC;
import static org.jd.core.v1.model.javasyntax.type.ObjectType.TYPE_OBJECT;

public class TypeParametersToTypeArgumentsBinder {
protected PopulateBindingsWithTypeParameterVisitor populateBindingsWithTypeParameterVisitor = new PopulateBindingsWithTypeParameterVisitor();
Expand Down Expand Up @@ -75,7 +76,7 @@ public ClassFileConstructorInvocationExpression newConstructorInvocationExpressi
TypeMaker.MethodTypes methodTypes, BaseExpression parameters) {

BaseType parameterTypes = clone(methodTypes.parameterTypes);
Map<String, TypeArgument> bindings = createBindings(null, null, null, methodTypes.typeParameters, PrimitiveType.TYPE_VOID, null, parameterTypes, parameters);
Map<String, TypeArgument> bindings = createBindings(null, null, null, methodTypes.typeParameters, TYPE_OBJECT, null, parameterTypes, parameters);

parameterTypes = bindParameterTypesWithArgumentTypes(bindings, parameterTypes);
bindParameterTypesWithArgumentTypes(parameterTypes, parameters);
Expand All @@ -99,7 +100,7 @@ public ClassFileSuperConstructorInvocationExpression newSuperConstructorInvocati
BaseTypeArgument typeArguments = typeTypes.superType.getTypeArguments();
BaseTypeParameter methodTypeParameters = methodTypes.typeParameters;

bindings = createBindings(null, typeParameters, typeArguments, methodTypeParameters, PrimitiveType.TYPE_VOID, null, parameterTypes, parameters);
bindings = createBindings(null, typeParameters, typeArguments, methodTypeParameters, TYPE_OBJECT, null, parameterTypes, parameters);
}
}

Expand Down Expand Up @@ -139,7 +140,7 @@ public FieldReferenceExpression newFieldReferenceExpression(
BaseTypeParameter typeParameters = typeTypes.typeParameters;
BaseTypeArgument typeArguments = expressionObjectType.getTypeArguments();

bindings = createBindings(expression, typeParameters, typeArguments, null, PrimitiveType.TYPE_VOID, null, null, null);
bindings = createBindings(expression, typeParameters, typeArguments, null, TYPE_OBJECT, null, null, null);
}

type = (Type)bindParameterTypesWithArgumentTypes(bindings, type);
Expand Down Expand Up @@ -303,7 +304,7 @@ protected void bindParameterTypesWithArgumentTypes(Type type, ClassFileNewExpres

protected void bindParameterTypesWithArgumentTypes(BaseType types, BaseExpression expressions) {
if (types != null) {
if (types.isList()) {
if (types.isList() && expressions.isList()) {
Iterator<Type> parameterTypesIterator = types.iterator();
Iterator<Expression> parametersIterator = expressions.iterator();

Expand Down Expand Up @@ -344,7 +345,7 @@ protected Map<String, TypeArgument> createBindings(
typeParameters.accept(populateBindingsWithTypeParameterVisitor);

if (typeArguments != null) {
if (typeParameters.isList()) {
if (typeParameters.isList() && typeArguments.isTypeArgumentList()) {
Iterator<TypeParameter> iteratorTypeParameter = typeParameters.iterator();
Iterator<TypeArgument> iteratorTypeArgument = typeArguments.getTypeArgumentList().iterator();

Expand All @@ -363,13 +364,13 @@ protected Map<String, TypeArgument> createBindings(
methodTypeParameters.accept(populateBindingsWithTypeParameterVisitor);
}

if ((returnType != PrimitiveType.TYPE_VOID) && (returnExpressionType != null)) {
if (!TYPE_OBJECT.equals(returnType) && (returnExpressionType != null)) {
populateBindingsWithTypeArgumentVisitor.init(contextualTypeBounds, bindings, typeBounds, returnType);
returnExpressionType.accept(populateBindingsWithTypeArgumentVisitor);
}

if (parameterTypes != null) {
if (parameterTypes.isList()) {
if (parameterTypes.isList() && parameters.isList()) {
Iterator<Type> parameterTypesIterator = parameterTypes.iterator();
Iterator<Expression> parametersIterator = parameters.iterator();

Expand Down Expand Up @@ -548,7 +549,7 @@ public void visit(NewExpression expression) {

@Override
public void visit(CastExpression expression) {
assert (type.getDimension() == expression.getType().getDimension()) : "TypeParametersToTypeArgumentsBinder.visit(CastExpression ce) : invalid array type";
assert TYPE_OBJECT.equals(type) || (type.getDimension() == expression.getType().getDimension()) : "TypeParametersToTypeArgumentsBinder.visit(CastExpression ce) : invalid array type";

if (type.isObject()) {
ObjectType objectType = (ObjectType)type;
Expand Down Expand Up @@ -582,15 +583,19 @@ public void visit(CastExpression expression) {

@Override
public void visit(TernaryOperatorExpression expression) {
expression.setType(type);
bindParameterTypesWithArgumentTypes(type, expression.getExpressionTrue());
bindParameterTypesWithArgumentTypes(type, expression.getExpressionFalse());
Type t = type;

expression.setType(t);
bindParameterTypesWithArgumentTypes(t, expression.getExpressionTrue());
bindParameterTypesWithArgumentTypes(t, expression.getExpressionFalse());
}

@Override
public void visit(BinaryOperatorExpression expression) {
bindParameterTypesWithArgumentTypes(type, expression.getLeftExpression());
bindParameterTypesWithArgumentTypes(type, expression.getRightExpression());
Type t = type;

bindParameterTypesWithArgumentTypes(t, expression.getLeftExpression());
bindParameterTypesWithArgumentTypes(t, expression.getRightExpression());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,28 @@ public void visit(LocalVariableDeclarator declarator) {

@Override
public void visit(ArrayVariableInitializer declaration) {
Type t = type;
if (type.getDimension() == 0) {
acceptListDeclaration(declaration);
} else {
Type t = type;

type = type.createType(type.getDimension() - 1);
acceptListDeclaration(declaration);
type = t;
type = type.createType(type.getDimension() - 1);
acceptListDeclaration(declaration);
type = t;
}
}

@Override
public void visit(ExpressionVariableInitializer declaration) {
Expression expression = declaration.getExpression();

if (expression.getClass() == NewInitializedArray.class) {
((NewInitializedArray)expression).getArrayInitializer().accept(this);
NewInitializedArray nia = (NewInitializedArray)expression;
Type t = type;

type = nia.getType();
nia.getArrayInitializer().accept(this);
type = t;
} else {
declaration.setExpression(updateExpression(type, expression));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ public void visit(GenericType type) {
} else {
typeArgumentToTypeVisitor.init();
ta.accept(typeArgumentToTypeVisitor);
result = typeArgumentToTypeVisitor.getType().createType(type.getDimension());
Type t = typeArgumentToTypeVisitor.getType();
result = t.createType(t.getDimension() + type.getDimension());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@
import org.jd.core.v1.model.javasyntax.type.*;
import org.jd.core.v1.service.converter.classfiletojavasyntax.util.TypeMaker;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import static org.jd.core.v1.model.javasyntax.type.ObjectType.TYPE_CLASS;
Expand Down Expand Up @@ -63,7 +61,7 @@ public void visit(TypeArguments arguments) {
}

if (typeArgument == null) {
bindings.put(typeName, convertCurrentTypeArgument());
bindings.put(typeName, checkTypeClassCheckDimensionAndReturnCurrentAsTypeArgument(type));
} else if (!current.equals(typeArgument)) {
typeArgumentToTypeVisitor.init();
typeArgument.accept(typeArgumentToTypeVisitor);
Expand All @@ -76,14 +74,14 @@ public void visit(TypeArguments arguments) {
if (!t1.createType(0).equals(t2.createType(0))) {
if (t1.isObject() && t2.isObject()) {
ObjectType ot1 = (ObjectType)t1;
ObjectType ot2 = (ObjectType)t2;

if (typeMaker.isAssignable(ot1, ot2)) {
bindings.put(typeName, typeArgument);
} else if (typeMaker.isAssignable(ot2, ot1)) {
bindings.put(typeName, convertCurrentTypeArgument());
} else {
bindings.put(typeName, WildcardTypeArgument.WILDCARD_TYPE_ARGUMENT);
ObjectType ot2 = (ObjectType)t2.createType(t2.getDimension() - type.getDimension());

if (!typeMaker.isAssignable(ot1, ot2)) {
if (typeMaker.isAssignable(ot2, ot1)) {
bindings.put(typeName, checkTypeClassCheckDimensionAndReturnCurrentAsTypeArgument(type));
} else {
bindings.put(typeName, WildcardTypeArgument.WILDCARD_TYPE_ARGUMENT);
}
}
}
}
Expand All @@ -100,16 +98,25 @@ protected boolean equals(BaseType bt1, BaseType bt2) {
}
}

protected TypeArgument convertCurrentTypeArgument() {
if ((current != null) && (current.getClass() == ObjectType.class)) {
ObjectType ot = (ObjectType)current;
protected TypeArgument checkTypeClassCheckDimensionAndReturnCurrentAsTypeArgument(GenericType type) {
if (current != null) {
Class currentClass = current.getClass();

if (currentClass == ObjectType.class) {
ObjectType ot = (ObjectType) current;

if ((ot.getTypeArguments() == null) && ot.getInternalName().equals(TYPE_CLASS.getInternalName())) {
return TYPE_CLASS_WILDCARD.createType(ot.getDimension());
}

if ((ot.getTypeArguments() == null) && ot.getInternalName().equals(TYPE_CLASS.getInternalName())) {
return TYPE_CLASS_WILDCARD;
return ot.createType(ot.getDimension() - type.getDimension());
} else if ((currentClass == InnerObjectType.class) || (currentClass == GenericType.class) || (currentClass == PrimitiveType.class)) {
Type t = (Type)current;
return t.createType(t.getDimension() - type.getDimension());
}
}

return (TypeArgument)current;
return current.getTypeArgumentFirst();
}

@Override
Expand Down

0 comments on commit 7fa1b8f

Please sign in to comment.