Fix owner class name compare. Add error output

This commit is contained in:
Andreas Stadelmeier 2024-12-22 08:05:40 +01:00
parent 09ab9a7e02
commit 4c94a9b869

@ -45,7 +45,7 @@ public class WildcardFinderPlugin extends TreeScanner<Void, Void> implements Plu
public Void visitClass(ClassTree node, Void unused) {
noIncompatibleFields = true;
try {
currentClassName = node.getSimpleName().toString();
currentClassName = currentPackage + "." + node.getSimpleName().toString();
node.getMembers().forEach(typeDecl -> {
if (typeDecl instanceof VariableTree) {
logger.accept(preText + "Field Type: " + ((VariableTree) typeDecl).getType().toString());
@ -66,16 +66,18 @@ public class WildcardFinderPlugin extends TreeScanner<Void, Void> implements Plu
return super.visitClass(node, unused);
}
String currentPackage = "";
String currentSource = "";
String currentClassContent = "";
@Override
public Void visitCompilationUnit(CompilationUnitTree node, Void unused) {
//System.out.println(node.getSourceFile().getName());
currentPackage = node.getPackageName()!=null?node.getPackageName().toString():"";
currentSource = node.getSourceFile().getName();
try {
currentClassContent = String.valueOf(node.getSourceFile().getCharContent(true));
} catch (IOException e) {
logger.accept(preText + "error5: " + e);
}
return super.visitCompilationUnit(node, unused);
}
@ -98,7 +100,8 @@ public class WildcardFinderPlugin extends TreeScanner<Void, Void> implements Plu
var pos_field = node.getClass().getField("pos");
type_field.setAccessible(true);
pos_field.setAccessible(true);
String typeText = type_field.get(node).toString();
//Some fields (or "members") do not have a type... TODO: fix this
String typeText = type_field.get(node)!=null?type_field.get(node).toString():"";
int methodPos = pos_field.getInt(node);
if(typeText.contains("capture#")){ //we found a capture conversion
//System.out.println(node.getClass().getMethod("getStartPosition").invoke(node));
@ -115,7 +118,8 @@ public class WildcardFinderPlugin extends TreeScanner<Void, Void> implements Plu
}
} catch (Throwable e){
//System.out.println("Error in method invocation: " + e.getMessage()+
// " in "+currentSource);i
// " in "+currentSource);
logger.accept(preText + "error4: " + e);
}
return super.visitMemberSelect(node, unused);
}
@ -147,10 +151,6 @@ public class WildcardFinderPlugin extends TreeScanner<Void, Void> implements Plu
logger.accept(preText + "CC!: "+ "Arg#"+argumentNumber + ": " + typeText + " in " + currentSource + " " + lineOfPosition(currentClassContent,methodPos) + " of method " + methString);
logger.accept(preText + " in class:" + node.getOwner());
String ownerName = node.getOwner();
int i = node.getOwner().lastIndexOf('.');
if (i > 0) {
ownerName = node.getOwner().substring(i+1);
}
if(ownerName.equals(currentClassName)){
logger.accept(preText + " in same class");
}
@ -163,11 +163,14 @@ public class WildcardFinderPlugin extends TreeScanner<Void, Void> implements Plu
}
} catch (NoSuchFieldException e) {
//System.out.println("Argument has no 'type' field");
logger.accept(preText + "error1: " + e);
} catch (IllegalAccessException e) {
//System.out.println("Illegal access of 'type' field");
logger.accept(preText + "error2: " + e);
} catch (Throwable e){
//System.out.println("Error in method invocation: " + e.getMessage()+
// " in "+currentSource);
logger.accept(preText + "error3: " + e);
}
return super.visitMethodInvocation(node, unused);
}