Merge branch 'bigRefactoring' of ssh://gohorb.ba-horb.de/bahome/projekt/git/JavaCompilerCore into sat

This commit is contained in:
JanUlrich 2018-08-21 14:03:16 +02:00
commit 0776f128ed
6 changed files with 39 additions and 55 deletions

View File

@ -745,6 +745,7 @@ public class StatementGenerator {
if(e.classInstanceCreationExpression_lf_primary() != null){ if(e.classInstanceCreationExpression_lf_primary() != null){
throw new NotImplementedException(); throw new NotImplementedException();
}else if(e.fieldAccess_lf_primary() != null){ }else if(e.fieldAccess_lf_primary() != null){
throw new NotImplementedException(); throw new NotImplementedException();
}else if(e.arrayAccess_lf_primary() != null){ }else if(e.arrayAccess_lf_primary() != null){
throw new NotImplementedException(); throw new NotImplementedException();
@ -799,8 +800,6 @@ public class StatementGenerator {
if(newExpression.typeArgumentsOrDiamond()!= null){ if(newExpression.typeArgumentsOrDiamond()!= null){
if(newExpression.typeArgumentsOrDiamond().typeArguments()!=null){ if(newExpression.typeArgumentsOrDiamond().typeArguments()!=null){
genericArgs = newExpression.typeArgumentsOrDiamond().typeArguments(); genericArgs = newExpression.typeArgumentsOrDiamond().typeArguments();
}else {
throw new NotImplementedException();
} }
} }
if(newExpression.typeArguments()!= null)throw new NotImplementedException(); if(newExpression.typeArguments()!= null)throw new NotImplementedException();

View File

@ -17,6 +17,7 @@ import de.dhbwstuttgart.syntaxtree.type.Void;
import de.dhbwstuttgart.syntaxtree.*; import de.dhbwstuttgart.syntaxtree.*;
import de.dhbwstuttgart.syntaxtree.statement.Block; import de.dhbwstuttgart.syntaxtree.statement.Block;
import de.dhbwstuttgart.syntaxtree.statement.Statement; import de.dhbwstuttgart.syntaxtree.statement.Statement;
import de.dhbwstuttgart.syntaxtree.type.WildcardType;
import org.antlr.v4.runtime.Token; import org.antlr.v4.runtime.Token;
/** /**
@ -50,15 +51,15 @@ public class ASTFactory {
java.lang.Class superjreClass = jreClass.getSuperclass(); java.lang.Class superjreClass = jreClass.getSuperclass();
RefType superClass; RefType superClass;
if(parameterSuperClass != null){ if(parameterSuperClass != null){
superClass = (RefType) convertType(parameterSuperClass); superClass = (RefType) createType(parameterSuperClass);
}else if(superjreClass != null){ }else if(superjreClass != null){
superClass = (RefType) convertType(superjreClass); superClass = (RefType) createType(superjreClass);
}else{//Jede Klasse und jedes Interface erbt von Object: (auch Object selbst!) }else{//Jede Klasse und jedes Interface erbt von Object: (auch Object selbst!)
superClass = (RefType) createType(java.lang.Object.class, name, ""); superClass = (RefType) createType(java.lang.Object.class);
} }
List<RefType> implementedInterfaces = new ArrayList<>(); List<RefType> implementedInterfaces = new ArrayList<>();
for(Type jreInterface : jreClass.getGenericInterfaces()){ for(Type jreInterface : jreClass.getGenericInterfaces()){
implementedInterfaces.add((RefType) createType(jreInterface, name, "")); implementedInterfaces.add((RefType) createType(jreInterface));
} }
GenericDeclarationList genericDeclarationList = createGenerics(jreClass.getTypeParameters(), jreClass, null); GenericDeclarationList genericDeclarationList = createGenerics(jreClass.getTypeParameters(), jreClass, null);
@ -67,29 +68,8 @@ public class ASTFactory {
return new ClassOrInterface(modifier, name, felder, methoden, konstruktoren, genericDeclarationList, superClass,isInterface, implementedInterfaces, offset); return new ClassOrInterface(modifier, name, felder, methoden, konstruktoren, genericDeclarationList, superClass,isInterface, implementedInterfaces, offset);
} }
private static RefTypeOrTPHOrWildcardOrGeneric convertType(Type type){
if(type instanceof ParameterizedType){
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
for(Type paramType : ((ParameterizedType)type).getActualTypeArguments()){
params.add(convertType(paramType));
}
JavaClassName name = new JavaClassName(((ParameterizedType) type).getRawType().getTypeName());
return new RefType(name, params, new NullToken());
}else if(type instanceof TypeVariable){
return new GenericRefType(((TypeVariable) type).getName(), new NullToken());
}else if(type instanceof Class){
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
Class paramClass = (Class) type;
for(TypeVariable tv : paramClass.getTypeParameters()){
params.add(new GenericRefType(tv.getName(), new NullToken()));
}
JavaClassName name = new JavaClassName(paramClass.getName());
return new RefType(name, params, new NullToken());
}else throw new NotImplementedException();
}
private static Field createField(java.lang.reflect.Field field, JavaClassName jreClass) { private static Field createField(java.lang.reflect.Field field, JavaClassName jreClass) {
return new Field(field.getName(), createType(field.getGenericType(), jreClass, null), field.getModifiers(), new NullToken()); return new Field(field.getName(), createType(field.getType()), field.getModifiers(), new NullToken());
} }
//private static RefType createType(Class classType) { //private static RefType createType(Class classType) {
@ -98,13 +78,13 @@ public class ASTFactory {
private static de.dhbwstuttgart.syntaxtree.Constructor createConstructor(Constructor constructor, Class inClass) { private static de.dhbwstuttgart.syntaxtree.Constructor createConstructor(Constructor constructor, Class inClass) {
String name = constructor.getName(); String name = constructor.getName();
RefTypeOrTPHOrWildcardOrGeneric returnType = createType(inClass, new JavaClassName(inClass.getName()), name); RefTypeOrTPHOrWildcardOrGeneric returnType = createType(inClass);
Parameter[] jreParams = constructor.getParameters(); Parameter[] jreParams = constructor.getParameters();
Type[] jreGenericParams = constructor.getGenericParameterTypes(); Type[] jreGenericParams = constructor.getGenericParameterTypes();
List<FormalParameter> params = new ArrayList<>(); List<FormalParameter> params = new ArrayList<>();
int i = 0; int i = 0;
for(Type jreParam : jreGenericParams){ for(Type jreParam : jreGenericParams){
RefTypeOrTPHOrWildcardOrGeneric paramType = createType(jreParam,new JavaClassName(inClass.getName()), name); RefTypeOrTPHOrWildcardOrGeneric paramType = createType(jreParam);
params.add(new FormalParameter(jreParams[i].getName(),paramType, new NullToken())); params.add(new FormalParameter(jreParams[i].getName(),paramType, new NullToken()));
i++; i++;
} }
@ -130,13 +110,13 @@ public class ASTFactory {
}else{ }else{
jreRetType = jreMethod.getReturnType(); jreRetType = jreMethod.getReturnType();
} }
returnType = createType(jreRetType,new JavaClassName(inClass.getName()), name); returnType = createType(jreRetType);
Parameter[] jreParams = jreMethod.getParameters(); Parameter[] jreParams = jreMethod.getParameters();
Type[] jreGenericParams = jreMethod.getGenericParameterTypes(); Type[] jreGenericParams = jreMethod.getGenericParameterTypes();
List<FormalParameter> params = new ArrayList<>(); List<FormalParameter> params = new ArrayList<>();
int i = 0; int i = 0;
for(Type jreParam : jreGenericParams){ for(Type jreParam : jreGenericParams){
RefTypeOrTPHOrWildcardOrGeneric paramType = createType(jreParam,new JavaClassName(inClass.getName()), name); RefTypeOrTPHOrWildcardOrGeneric paramType = createType(jreParam);
params.add(new FormalParameter(jreParams[i].getName(),paramType, new NullToken())); params.add(new FormalParameter(jreParams[i].getName(),paramType, new NullToken()));
i++; i++;
} }
@ -157,18 +137,7 @@ public class ASTFactory {
return new GenericDeclarationList(gtvs,new NullToken()); return new GenericDeclarationList(gtvs,new NullToken());
} }
/* private static RefTypeOrTPHOrWildcardOrGeneric createType(java.lang.reflect.Type type){
public RefType createType(java.lang.Class jreClass){
List<RefTypeOrTPH> params = new ArrayList<>();
for(TypeVariable jreTV : jreClass.getTypeParameters()){
RefType gtv = createType(jreTV);
params.add(gtv);
}
return new RefType(names.getName(jreClass.getName()), params, new NullToken());
}
*/
private static RefTypeOrTPHOrWildcardOrGeneric createType(java.lang.reflect.Type type, JavaClassName parentClass, String parentMethod){
if(type.getTypeName().equals("void")){ if(type.getTypeName().equals("void")){
return new Void(new NullToken()); return new Void(new NullToken());
}else if(type.getTypeName().equals("int")){ }else if(type.getTypeName().equals("int")){
@ -193,7 +162,7 @@ public class ASTFactory {
List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> params = new ArrayList<>();
if(type instanceof ParameterizedType){ if(type instanceof ParameterizedType){
for(Type t : ((ParameterizedType)type).getActualTypeArguments()){ for(Type t : ((ParameterizedType)type).getActualTypeArguments()){
params.add(createType(t, parentClass, parentMethod)); params.add(createType(t));
} }
} }
String name = type.getTypeName(); String name = type.getTypeName();
@ -201,10 +170,21 @@ public class ASTFactory {
//Diese entfernen: //Diese entfernen:
name = name.split("<")[0]; name = name.split("<")[0];
} }
if(type instanceof java.lang.reflect.WildcardType){
java.lang.reflect.WildcardType wildcardType = (java.lang.reflect.WildcardType) type;
if(wildcardType.getLowerBounds().length > 0){
return new SuperWildcardType(createType(wildcardType.getLowerBounds()[0]), new NullToken());
}else if(wildcardType.getUpperBounds().length > 0){
return new ExtendsWildcardType(createType(wildcardType.getUpperBounds()[0]), new NullToken());
}else{//Es handelt sich um den '?'-Typ:
return new ExtendsWildcardType(createObjectType(), new NullToken());
}
}else{
RefType ret = new RefType(new JavaClassName(name), params, new NullToken()); RefType ret = new RefType(new JavaClassName(name), params, new NullToken());
return ret; return ret;
} }
} }
}
public static de.dhbwstuttgart.syntaxtree.GenericTypeVar createGeneric(TypeVariable jreTypeVar, String jreTVName, Class context, String parentMethod){ public static de.dhbwstuttgart.syntaxtree.GenericTypeVar createGeneric(TypeVariable jreTypeVar, String jreTVName, Class context, String parentMethod){
JavaClassName parentClass = new JavaClassName(context.getName()); JavaClassName parentClass = new JavaClassName(context.getName());
@ -212,7 +192,7 @@ public class ASTFactory {
java.lang.reflect.Type[] bounds = jreTypeVar.getBounds(); java.lang.reflect.Type[] bounds = jreTypeVar.getBounds();
if(bounds.length > 0){ if(bounds.length > 0){
for(java.lang.reflect.Type bound : bounds){ for(java.lang.reflect.Type bound : bounds){
genericBounds.add((RefType) createType(bound, parentClass, parentMethod)); genericBounds.add((RefType) createType(bound));
} }
} }
return new de.dhbwstuttgart.syntaxtree.GenericTypeVar(jreTVName, genericBounds, new NullToken(), new NullToken()); return new de.dhbwstuttgart.syntaxtree.GenericTypeVar(jreTVName, genericBounds, new NullToken(), new NullToken());

View File

@ -34,6 +34,10 @@ public class ExtendsWildcardType extends WildcardType{
return false; return false;
} }
@Override
public String toString() {
return "? extends "+innerType.toString();
}
@Override @Override
public void accept(ASTVisitor visitor) { public void accept(ASTVisitor visitor) {

View File

@ -35,6 +35,11 @@ public class SuperWildcardType extends WildcardType{
return this.innerType; return this.innerType;
} }
@Override
public String toString() {
return "? super "+innerType.toString();
}
@Override @Override
public boolean isExtends() { public boolean isExtends() {
return false; return false;

View File

@ -38,16 +38,13 @@ public class MethodAssumption extends Assumption{
} }
public RefTypeOrTPHOrWildcardOrGeneric getReturnType(GenericsResolver resolver) { public RefTypeOrTPHOrWildcardOrGeneric getReturnType(GenericsResolver resolver) {
if(retType instanceof GenericRefType)return resolver.resolve(retType); return resolver.resolve(retType);
return retType;
} }
public List<RefTypeOrTPHOrWildcardOrGeneric> getArgTypes(GenericsResolver resolver) { public List<RefTypeOrTPHOrWildcardOrGeneric> getArgTypes(GenericsResolver resolver) {
List<RefTypeOrTPHOrWildcardOrGeneric> ret = new ArrayList<>(); List<RefTypeOrTPHOrWildcardOrGeneric> ret = new ArrayList<>();
for(RefTypeOrTPHOrWildcardOrGeneric param : params){ for(RefTypeOrTPHOrWildcardOrGeneric param : params){
if(param instanceof GenericRefType){ //Generics in den Assumptions müssen umgewandelt werden. param = resolver.resolve(param);
param = resolver.resolve((GenericRefType) param);
}
ret.add(param); ret.add(param);
} }
return ret; return ret;

View File

@ -60,7 +60,6 @@ public class TYPE {
return new TypeInferenceInformation(classes); return new TypeInferenceInformation(classes);
} }
*/ */
private ConstraintSet getConstraintsMethod(Method m, TypeInferenceInformation info, ClassOrInterface currentClass) { private ConstraintSet getConstraintsMethod(Method m, TypeInferenceInformation info, ClassOrInterface currentClass) {
if(m.block == null)return new ConstraintSet(); //Abstrakte Methoden generieren keine Constraints if(m.block == null)return new ConstraintSet(); //Abstrakte Methoden generieren keine Constraints