From fa1d70f954b56b68be948a617484f978a4131663 Mon Sep 17 00:00:00 2001 From: Andreas Stadelmeier Date: Tue, 17 Dec 2024 16:34:54 +0100 Subject: [PATCH] Use Log.printRawLine instead of System.out --- .../sun/tools/javac/api/BasicJavacTask.java | 2 +- .../tools/javac/api/WildcardFinderPlugin.java | 25 ++++++++++++++++--- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/src/jdk.compiler/share/classes/com/sun/tools/javac/api/BasicJavacTask.java b/src/jdk.compiler/share/classes/com/sun/tools/javac/api/BasicJavacTask.java index 8e1be65f086..2913d6de08a 100644 --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/api/BasicJavacTask.java +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/api/BasicJavacTask.java @@ -201,7 +201,7 @@ public class BasicJavacTask extends JavacTask { PlatformDescription platformProvider = context.get(PlatformDescription.class); //ANDI: Init our own plugin to count CC's - initPlugin(new WildcardFinderPlugin()); + initPlugin(new WildcardFinderPlugin((s -> Log.instance(context).printRawLines(s)))); if (platformProvider != null) { for (PluginInfo pluginDesc : platformProvider.getPlugins()) { java.util.List options = 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 e20be8e59b4..990d2807c44 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 @@ -5,8 +5,15 @@ import com.sun.source.tree.MethodInvocationTree; import com.sun.source.util.*; import java.io.IOException; +import java.util.function.Consumer; public class WildcardFinderPlugin extends TreeScanner implements Plugin, TaskListener { + + private final Consumer logger; + + public WildcardFinderPlugin(Consumer logger){ + this.logger = logger; + } @Override public void started(TaskEvent e) { TaskListener.super.started(e); @@ -58,7 +65,18 @@ public class WildcardFinderPlugin extends TreeScanner implements Plu @Override public Void visitMethodInvocation(MethodInvocationTree node, Void unused) { var args = node.getArguments(); + String methString = ""; + try{ + var meth_field = node.getClass().getField("meth"); + meth_field.setAccessible(true); + var meth = meth_field.get(node); + var sym_field = meth.getClass().getField("sym"); + sym_field.setAccessible(true); + methString = sym_field.get(meth).toString(); + //System.out.println(methString); + }catch (Throwable e){} try { + int argumentNumber = 0; for(var arg : args){ var type_field = arg.getClass().getField("type"); var pos_field = arg.getClass().getField("pos"); @@ -66,12 +84,13 @@ public class WildcardFinderPlugin extends TreeScanner implements Plu pos_field.setAccessible(true); String typeText = type_field.get(arg).toString(); int methodPos = pos_field.getInt(node); - if(typeText.contains("capture#")){ //we found a capture conversion + if(typeText.contains("capture#") && methString.startsWith("<")){ //we found a capture conversion //System.out.println(node.getClass().getMethod("getStartPosition").invoke(node)); - System.out.println(preText + "CC: " + typeText + " in " + currentSource + " " + lineOfPosition(currentClassContent,methodPos)); + logger.accept(preText + "CC: "+ "Arg#"+argumentNumber + ": " + typeText + " in " + currentSource + " " + lineOfPosition(currentClassContent,methodPos) + " of method " + methString); }else{ - System.out.println(preText + "normal Method call"); + logger.accept(preText + "normal Method call"); } + argumentNumber++; } } catch (NoSuchFieldException e) { //System.out.println("Argument has no 'type' field");