From a0c25a517d5c522c8a8973bae0f26cef98257439 Mon Sep 17 00:00:00 2001 From: Victorious3 Date: Wed, 19 Apr 2023 15:33:53 +0200 Subject: [PATCH] Use old method of creating signatures in case the classloader is null --- .../syntaxtree/factory/ASTFactory.java | 21 +++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java index 65e4c087..82d76983 100644 --- a/src/main/java/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java +++ b/src/main/java/de/dhbwstuttgart/syntaxtree/factory/ASTFactory.java @@ -84,7 +84,6 @@ public class ASTFactory { classReader.accept(classVisitor, new Attribute[]{new JavaTXSignatureAttribute()}, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES); classSignature = classVisitor.classSignature; } - } catch (IOException e) { // Skip } @@ -133,7 +132,7 @@ public class ASTFactory { implementedInterfaces.add((RefType) createType(jreInterface)); } - GenericDeclarationList genericDeclarationList = createGenerics(classSignature); + GenericDeclarationList genericDeclarationList = createGenerics(jreClass.getTypeParameters(), jreClass, null, classSignature); Token offset = new NullToken(); //Braucht keinen Offset, da diese Klasse nicht aus einem Quellcode geparst wurde @@ -162,7 +161,7 @@ public class ASTFactory { } ParameterList parameterList = new ParameterList(params, new NullToken()); Block block = new Block(new ArrayList(), new NullToken()); - GenericDeclarationList gtvDeclarations = createGenerics(signature); + GenericDeclarationList gtvDeclarations = createGenerics(constructor.getTypeParameters(), inClass, constructor.getName(), signature); Token offset = new NullToken(); int modifier = constructor.getModifiers(); @@ -194,12 +193,25 @@ public class ASTFactory { } ParameterList parameterList = new ParameterList(params, new NullToken()); Block block = new Block(new ArrayList(), new NullToken()); - GenericDeclarationList gtvDeclarations = createGenerics(signature); + GenericDeclarationList gtvDeclarations = createGenerics(jreMethod.getTypeParameters(), inClass, jreMethod.getName(), signature); Token offset = new NullToken(); return new Method(jreMethod.getModifiers(), name,returnType, parameterList, block, gtvDeclarations, offset, isInherited); } + public static GenericDeclarationList createGenerics(TypeVariable[] typeParameters, Class context, String methodName, String signature) { + if (signature == null) { + List gtvs = new ArrayList<>(); + for(TypeVariable jreTV : typeParameters){ + de.dhbwstuttgart.syntaxtree.GenericTypeVar gtv = createGeneric(jreTV, jreTV.getName(), context, methodName); + gtvs.add(gtv); + } + return new GenericDeclarationList(gtvs, new NullToken()); + } else { + return createGenerics(signature); + } + } + public static GenericDeclarationList createGenerics(String signature) { if (signature == null) return new GenericDeclarationList(new ArrayList<>(), new NullToken()); @@ -288,6 +300,7 @@ public class ASTFactory { var sr = new SignatureReader(signature); sr.accept(signatureVisitor); + System.out.println(signature); return new GenericDeclarationList(gtvs, new NullToken()); }