Merge mit bigRefactoring
This commit is contained in:
commit
9492c43e70
@ -427,6 +427,9 @@ public class SyntaxTreeGenerator{
|
|||||||
GenericsRegistry ret = new GenericsRegistry(this.globalGenerics);
|
GenericsRegistry ret = new GenericsRegistry(this.globalGenerics);
|
||||||
ret.putAll(generics);
|
ret.putAll(generics);
|
||||||
if(ctx == null || ctx.typeParameterList() == null)return ret;
|
if(ctx == null || ctx.typeParameterList() == null)return ret;
|
||||||
|
for(Java8Parser.TypeParameterContext tp : ctx.typeParameterList().typeParameter()){
|
||||||
|
ret.put(tp.Identifier().getText(), new GenericContext(parentClass, parentMethod));
|
||||||
|
}
|
||||||
for(Java8Parser.TypeParameterContext tp : ctx.typeParameterList().typeParameter()){
|
for(Java8Parser.TypeParameterContext tp : ctx.typeParameterList().typeParameter()){
|
||||||
TypeGenerator.convert(tp, parentClass, parentMethod, reg, ret);
|
TypeGenerator.convert(tp, parentClass, parentMethod, reg, ret);
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,6 @@ public class TypeGenerator {
|
|||||||
List<RefTypeOrTPHOrWildcardOrGeneric> bounds = TypeGenerator.convert(typeParameter.typeBound(),reg, generics);
|
List<RefTypeOrTPHOrWildcardOrGeneric> bounds = TypeGenerator.convert(typeParameter.typeBound(),reg, generics);
|
||||||
|
|
||||||
GenericTypeVar ret = new GenericTypeVar(name, bounds, typeParameter.getStart(), typeParameter.getStop());
|
GenericTypeVar ret = new GenericTypeVar(name, bounds, typeParameter.getStart(), typeParameter.getStop());
|
||||||
generics.put(name, new GenericContext(parentClass, parentMethod));
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +91,7 @@ public class TypeGenerator {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
if(typeBoundContext.classOrInterfaceType() != null){
|
if(typeBoundContext.classOrInterfaceType() != null){
|
||||||
ret.add(convert(typeBoundContext.classOrInterfaceType()));
|
ret.add(convert(typeBoundContext.classOrInterfaceType(), reg, generics));
|
||||||
if(typeBoundContext.additionalBound() != null)
|
if(typeBoundContext.additionalBound() != null)
|
||||||
for(Java8Parser.AdditionalBoundContext addCtx : typeBoundContext.additionalBound()){
|
for(Java8Parser.AdditionalBoundContext addCtx : typeBoundContext.additionalBound()){
|
||||||
ret.add(convert(addCtx.interfaceType()));
|
ret.add(convert(addCtx.interfaceType()));
|
||||||
@ -103,8 +102,9 @@ public class TypeGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ClassOrInterfaceTypeContext classOrInterfaceTypeContext) {
|
private static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ClassOrInterfaceTypeContext classOrInterfaceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) {
|
||||||
throw new NotImplementedException();
|
Java8Parser.ClassType_lfno_classOrInterfaceTypeContext ctx = classOrInterfaceTypeContext.classType_lfno_classOrInterfaceType();
|
||||||
|
return convertTypeName(ctx.Identifier().toString(), ctx.typeArguments(),classOrInterfaceTypeContext.getStart(), reg, generics);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.InterfaceTypeContext interfaceTypeContext) {
|
private static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.InterfaceTypeContext interfaceTypeContext) {
|
||||||
@ -114,8 +114,7 @@ public class TypeGenerator {
|
|||||||
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ReferenceTypeContext referenceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) {
|
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ReferenceTypeContext referenceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) {
|
||||||
if(referenceTypeContext.classOrInterfaceType() != null){
|
if(referenceTypeContext.classOrInterfaceType() != null){
|
||||||
if(referenceTypeContext.classOrInterfaceType().classType_lfno_classOrInterfaceType()!= null){
|
if(referenceTypeContext.classOrInterfaceType().classType_lfno_classOrInterfaceType()!= null){
|
||||||
Java8Parser.ClassType_lfno_classOrInterfaceTypeContext ctx = referenceTypeContext.classOrInterfaceType().classType_lfno_classOrInterfaceType();
|
return convert(referenceTypeContext.classOrInterfaceType(), reg, generics);//return convertTypeName(referenceTypeContext.getText(), ctx.typeArguments(),referenceTypeContext.getStart(), reg, generics);
|
||||||
return convertTypeName(ctx.Identifier().toString(), ctx.typeArguments(),referenceTypeContext.getStart(), reg, generics);
|
|
||||||
}else{
|
}else{
|
||||||
throw new NotImplementedException();
|
throw new NotImplementedException();
|
||||||
}
|
}
|
||||||
|
@ -66,10 +66,10 @@ public abstract class AbstractASTWalker implements ASTVisitor{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(ParameterList formalParameters) {
|
public void visit(ParameterList formalParameters) {
|
||||||
Iterator<FormalParameter> genericIterator = formalParameters.getFormalparalist().iterator();
|
Iterator<FormalParameter> it = formalParameters.getFormalparalist().iterator();
|
||||||
if(genericIterator.hasNext()){
|
if(it.hasNext()){
|
||||||
while(genericIterator.hasNext()){
|
while(it.hasNext()){
|
||||||
genericIterator.next().accept(this);
|
it.next().accept(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
|||||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||||
import org.antlr.v4.runtime.Token;
|
import org.antlr.v4.runtime.Token;
|
||||||
|
|
||||||
|
import java.lang.reflect.Modifier;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -33,6 +34,7 @@ public class ClassOrInterface extends SyntaxTreeNode implements TypeScope{
|
|||||||
public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters,
|
public ClassOrInterface(int modifiers, JavaClassName name, List<Field> fielddecl, List<Method> methods, List<Constructor> constructors, GenericDeclarationList genericClassParameters,
|
||||||
RefType superClass, Boolean isInterface, List<RefType> implementedInterfaces, Token offset){
|
RefType superClass, Boolean isInterface, List<RefType> implementedInterfaces, Token offset){
|
||||||
super(offset);
|
super(offset);
|
||||||
|
if(isInterface && !Modifier.isInterface(modifiers))modifiers += Modifier.INTERFACE;
|
||||||
this.modifiers = modifiers;
|
this.modifiers = modifiers;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.fields = fielddecl;
|
this.fields = fielddecl;
|
||||||
|
@ -38,7 +38,7 @@ public class ASTFactory {
|
|||||||
methoden.add(createMethod(method, jreClass));
|
methoden.add(createMethod(method, jreClass));
|
||||||
}
|
}
|
||||||
List<Field> felder = new ArrayList<>();
|
List<Field> felder = new ArrayList<>();
|
||||||
for(java.lang.reflect.Field field : jreClass.getFields()){
|
for(java.lang.reflect.Field field : jreClass.getDeclaredFields()){
|
||||||
felder.add(createField(field, name));
|
felder.add(createField(field, name));
|
||||||
}
|
}
|
||||||
int modifier = jreClass.getModifiers();
|
int modifier = jreClass.getModifiers();
|
||||||
|
@ -59,13 +59,11 @@ class TypeInsertPlacerClass extends AbstractASTWalker{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visit(ParameterList params) {
|
public void visit(FormalParameter param) {
|
||||||
for(FormalParameter param : params){
|
|
||||||
if(param.getType() instanceof TypePlaceholder)
|
if(param.getType() instanceof TypePlaceholder)
|
||||||
inserts.add(TypeInsertFactory.createInsertPoints(
|
inserts.add(TypeInsertFactory.createInsertPoints(
|
||||||
param.getType(), param.getType().getOffset(), cl, method, results));
|
param.getType(), param.getType().getOffset(), cl, method, results));
|
||||||
}
|
super.visit(param);
|
||||||
super.visit(params);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
package astfactory;
|
package astfactory;
|
||||||
|
|
||||||
//import javafx.collections.ObservableList;
|
//import javafx.collections.ObservableList;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.ClassOrInterface;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.factory.ASTFactory;
|
||||||
|
import de.dhbwstuttgart.syntaxtree.type.GenericRefType;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.lang.reflect.ParameterizedType;
|
import java.lang.reflect.ParameterizedType;
|
||||||
@ -19,4 +22,13 @@ public class ASTFactoryTest<A> extends HashMap<String, A>{
|
|||||||
System.out.println(Arrays.toString(arguments));
|
System.out.println(Arrays.toString(arguments));
|
||||||
System.out.println(((TypeVariable)arguments[1]).getGenericDeclaration());
|
System.out.println(((TypeVariable)arguments[1]).getGenericDeclaration());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class GenericFieldTest<G>{
|
||||||
|
public G testField;
|
||||||
|
}
|
||||||
|
@Test
|
||||||
|
public void genericFieldTest(){
|
||||||
|
ClassOrInterface test = ASTFactory.createClass(GenericFieldTest.class);
|
||||||
|
assertTrue(test.getFieldDecl().get(0).getType() instanceof GenericRefType);
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,3 +1,4 @@
|
|||||||
|
import java.lang.String;
|
||||||
|
|
||||||
class Generics<B> {
|
class Generics<B> {
|
||||||
//<A extends B> A mt1(A a, B b){
|
//<A extends B> A mt1(A a, B b){
|
||||||
|
@ -42,7 +42,7 @@ public class GeneralParserTest{
|
|||||||
filenames.add("StructuralTypes.jav");
|
filenames.add("StructuralTypes.jav");
|
||||||
*/
|
*/
|
||||||
// filenames.add("ExtendsTest.jav");
|
// filenames.add("ExtendsTest.jav");
|
||||||
filenames.add("OpratorTest.jav");
|
filenames.add("PackageNameTest.jav");
|
||||||
try{
|
try{
|
||||||
new JavaTXCompiler(filenames.stream().map(s -> new File(rootDirectory + s)).collect(Collectors.toList()));
|
new JavaTXCompiler(filenames.stream().map(s -> new File(rootDirectory + s)).collect(Collectors.toList()));
|
||||||
}catch(Exception exc){
|
}catch(Exception exc){
|
||||||
|
Loading…
Reference in New Issue
Block a user