forked from JavaTX/JavaCompilerCore
Merge mit bigRefactoring
This commit is contained in:
commit
9492c43e70
@ -427,6 +427,9 @@ public class SyntaxTreeGenerator{
|
||||
GenericsRegistry ret = new GenericsRegistry(this.globalGenerics);
|
||||
ret.putAll(generics);
|
||||
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()){
|
||||
TypeGenerator.convert(tp, parentClass, parentMethod, reg, ret);
|
||||
}
|
||||
|
@ -77,7 +77,6 @@ public class TypeGenerator {
|
||||
List<RefTypeOrTPHOrWildcardOrGeneric> bounds = TypeGenerator.convert(typeParameter.typeBound(),reg, generics);
|
||||
|
||||
GenericTypeVar ret = new GenericTypeVar(name, bounds, typeParameter.getStart(), typeParameter.getStop());
|
||||
generics.put(name, new GenericContext(parentClass, parentMethod));
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -92,7 +91,7 @@ public class TypeGenerator {
|
||||
return ret;
|
||||
}
|
||||
if(typeBoundContext.classOrInterfaceType() != null){
|
||||
ret.add(convert(typeBoundContext.classOrInterfaceType()));
|
||||
ret.add(convert(typeBoundContext.classOrInterfaceType(), reg, generics));
|
||||
if(typeBoundContext.additionalBound() != null)
|
||||
for(Java8Parser.AdditionalBoundContext addCtx : typeBoundContext.additionalBound()){
|
||||
ret.add(convert(addCtx.interfaceType()));
|
||||
@ -103,8 +102,9 @@ public class TypeGenerator {
|
||||
}
|
||||
}
|
||||
|
||||
private static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ClassOrInterfaceTypeContext classOrInterfaceTypeContext) {
|
||||
throw new NotImplementedException();
|
||||
private static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ClassOrInterfaceTypeContext classOrInterfaceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) {
|
||||
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) {
|
||||
@ -114,8 +114,7 @@ public class TypeGenerator {
|
||||
public static RefTypeOrTPHOrWildcardOrGeneric convert(Java8Parser.ReferenceTypeContext referenceTypeContext, JavaClassRegistry reg, GenericsRegistry generics) {
|
||||
if(referenceTypeContext.classOrInterfaceType() != null){
|
||||
if(referenceTypeContext.classOrInterfaceType().classType_lfno_classOrInterfaceType()!= null){
|
||||
Java8Parser.ClassType_lfno_classOrInterfaceTypeContext ctx = referenceTypeContext.classOrInterfaceType().classType_lfno_classOrInterfaceType();
|
||||
return convertTypeName(ctx.Identifier().toString(), ctx.typeArguments(),referenceTypeContext.getStart(), reg, generics);
|
||||
return convert(referenceTypeContext.classOrInterfaceType(), reg, generics);//return convertTypeName(referenceTypeContext.getText(), ctx.typeArguments(),referenceTypeContext.getStart(), reg, generics);
|
||||
}else{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
@ -66,10 +66,10 @@ public abstract class AbstractASTWalker implements ASTVisitor{
|
||||
|
||||
@Override
|
||||
public void visit(ParameterList formalParameters) {
|
||||
Iterator<FormalParameter> genericIterator = formalParameters.getFormalparalist().iterator();
|
||||
if(genericIterator.hasNext()){
|
||||
while(genericIterator.hasNext()){
|
||||
genericIterator.next().accept(this);
|
||||
Iterator<FormalParameter> it = formalParameters.getFormalparalist().iterator();
|
||||
if(it.hasNext()){
|
||||
while(it.hasNext()){
|
||||
it.next().accept(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ import de.dhbwstuttgart.typeinference.constraints.ConstraintSet;
|
||||
import de.dhbwstuttgart.typeinference.assumptions.TypeInferenceInformation;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
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,
|
||||
RefType superClass, Boolean isInterface, List<RefType> implementedInterfaces, Token offset){
|
||||
super(offset);
|
||||
if(isInterface && !Modifier.isInterface(modifiers))modifiers += Modifier.INTERFACE;
|
||||
this.modifiers = modifiers;
|
||||
this.name = name;
|
||||
this.fields = fielddecl;
|
||||
|
@ -38,7 +38,7 @@ public class ASTFactory {
|
||||
methoden.add(createMethod(method, jreClass));
|
||||
}
|
||||
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));
|
||||
}
|
||||
int modifier = jreClass.getModifiers();
|
||||
|
@ -59,13 +59,11 @@ class TypeInsertPlacerClass extends AbstractASTWalker{
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visit(ParameterList params) {
|
||||
for(FormalParameter param : params){
|
||||
public void visit(FormalParameter param) {
|
||||
if(param.getType() instanceof TypePlaceholder)
|
||||
inserts.add(TypeInsertFactory.createInsertPoints(
|
||||
param.getType(), param.getType().getOffset(), cl, method, results));
|
||||
}
|
||||
super.visit(params);
|
||||
super.visit(param);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -1,6 +1,9 @@
|
||||
package astfactory;
|
||||
|
||||
//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 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(((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> {
|
||||
//<A extends B> A mt1(A a, B b){
|
||||
|
@ -42,7 +42,7 @@ public class GeneralParserTest{
|
||||
filenames.add("StructuralTypes.jav");
|
||||
*/
|
||||
// filenames.add("ExtendsTest.jav");
|
||||
filenames.add("OpratorTest.jav");
|
||||
filenames.add("PackageNameTest.jav");
|
||||
try{
|
||||
new JavaTXCompiler(filenames.stream().map(s -> new File(rootDirectory + s)).collect(Collectors.toList()));
|
||||
}catch(Exception exc){
|
||||
|
Loading…
Reference in New Issue
Block a user