From 3fe35f647606da89faa5d558e5f575251a9f4592 Mon Sep 17 00:00:00 2001 From: Andreas Stadelmeier Date: Wed, 18 Dec 2024 00:44:09 +0100 Subject: [PATCH] Add Additional output. For Fields using CC and more verbose for method calls --- .../tools/javac/api/WildcardFinderPlugin.java | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/api/WildcardFinderPlugin.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/api/WildcardFinderPlugin.java index 990d2807c44..39677ce4376 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/api/WildcardFinderPlugin.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/api/WildcardFinderPlugin.java @@ -1,6 +1,7 @@ package com.sun.tools.javac.api; import com.sun.source.tree.CompilationUnitTree; +import com.sun.source.tree.MemberSelectTree; import com.sun.source.tree.MethodInvocationTree; import com.sun.source.util.*; @@ -62,6 +63,36 @@ public class WildcardFinderPlugin extends TreeScanner implements Plu return count; } public static final String preText = "[ANDI] "; + + @Override + public Void visitMemberSelect(MemberSelectTree node, Void unused) { + try { + var type_field = node.getClass().getField("type"); + var pos_field = node.getClass().getField("pos"); + type_field.setAccessible(true); + pos_field.setAccessible(true); + String typeText = 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)); + logger.accept(preText + "Field-CC: " + typeText + " in " + currentSource + " " + lineOfPosition(currentClassContent,methodPos)); + var expr = node.getExpression(); + var expr_type_field = node.getClass().getField("type"); + expr_type_field.setAccessible(true); + String exprTypeText = expr_type_field.get(expr).toString(); + if(exprTypeText.contains("capture") || exprTypeText.contains("?")){ + logger.accept(preText + "Field-CC!: " + typeText + " in " + currentSource + " " + lineOfPosition(currentClassContent,methodPos)); + } + }else{ + logger.accept(preText + "normal field access"); + } + } catch (Throwable e){ + //System.out.println("Error in method invocation: " + e.getMessage()+ + // " in "+currentSource);i + } + return super.visitMemberSelect(node, unused); + } + @Override public Void visitMethodInvocation(MethodInvocationTree node, Void unused) { var args = node.getArguments(); @@ -86,6 +117,8 @@ public class WildcardFinderPlugin extends TreeScanner implements Plu int methodPos = pos_field.getInt(node); if(typeText.contains("capture#") && methString.startsWith("<")){ //we found a capture conversion //System.out.println(node.getClass().getMethod("getStartPosition").invoke(node)); + logger.accept(preText + "CC!: "+ "Arg#"+argumentNumber + ": " + typeText + " in " + currentSource + " " + lineOfPosition(currentClassContent,methodPos) + " of method " + methString); + }else if(typeText.contains("capture#")) { logger.accept(preText + "CC: "+ "Arg#"+argumentNumber + ": " + typeText + " in " + currentSource + " " + lineOfPosition(currentClassContent,methodPos) + " of method " + methString); }else{ logger.accept(preText + "normal Method call");