Compare commits
5 Commits
849209b8cb
...
21aa7e0e9c
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
21aa7e0e9c | ||
|
|
3fe35f6476 | ||
|
|
bc4d7d1bc9 | ||
|
|
7c06bd67df | ||
|
|
fa1d70f954 |
@@ -245,24 +245,6 @@ public final class Collectors {
|
|||||||
CH_ID);
|
CH_ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Returns a {@code Collector} that accumulates the input elements into a
|
|
||||||
* new {@code List}. There are no guarantees on the type, mutability,
|
|
||||||
* serializability, or thread-safety of the {@code List} returned; if more
|
|
||||||
* control over the returned {@code List} is required, use {@link #toCollection(Supplier)}.
|
|
||||||
*
|
|
||||||
* @param <T> the type of the input elements
|
|
||||||
* @return a {@code Collector} which collects all the input elements into a
|
|
||||||
* {@code List}, in encounter order
|
|
||||||
*/
|
|
||||||
public static <T>
|
|
||||||
Collector<T, ArrayList<Object>, List<T>> toList2() {
|
|
||||||
return new CollectorImpl<>(ArrayList::new, List::add,
|
|
||||||
(left, right) -> { left.addAll(right); return left; },
|
|
||||||
CH_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a {@code Collector} that accumulates the input elements into an
|
* Returns a {@code Collector} that accumulates the input elements into an
|
||||||
* <a href="../List.html#unmodifiable">unmodifiable List</a> in encounter
|
* <a href="../List.html#unmodifiable">unmodifiable List</a> in encounter
|
||||||
@@ -922,9 +904,8 @@ public final class Collectors {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CollectorImpl<>(
|
return new CollectorImpl<>(
|
||||||
OptionalBox::new, OptionalBox::accept,
|
OptionalBox::new, Consumer<T>::accept,
|
||||||
(a, b) -> {
|
(a, b) -> {
|
||||||
if (b.present) a.accept(b.value);
|
if (b.present) a.accept(b.value);
|
||||||
return a;
|
return a;
|
||||||
@@ -970,7 +951,7 @@ public final class Collectors {
|
|||||||
* @see #reducing(BinaryOperator)
|
* @see #reducing(BinaryOperator)
|
||||||
*/
|
*/
|
||||||
public static <T, U>
|
public static <T, U>
|
||||||
Collector<T, ?, U> reducing(U identity,
|
Collector<T, U[], U> reducing(U identity,
|
||||||
Function<? super T, ? extends U> mapper,
|
Function<? super T, ? extends U> mapper,
|
||||||
BinaryOperator<U> op) {
|
BinaryOperator<U> op) {
|
||||||
return new CollectorImpl<>(
|
return new CollectorImpl<>(
|
||||||
|
|||||||
@@ -201,7 +201,7 @@ public class BasicJavacTask extends JavacTask {
|
|||||||
PlatformDescription platformProvider = context.get(PlatformDescription.class);
|
PlatformDescription platformProvider = context.get(PlatformDescription.class);
|
||||||
|
|
||||||
//ANDI: Init our own plugin to count CC's
|
//ANDI: Init our own plugin to count CC's
|
||||||
initPlugin(new WildcardFinderPlugin());
|
initPlugin(new WildcardFinderPlugin((s -> Log.instance(context).printRawLines(s))));
|
||||||
if (platformProvider != null) {
|
if (platformProvider != null) {
|
||||||
for (PluginInfo<Plugin> pluginDesc : platformProvider.getPlugins()) {
|
for (PluginInfo<Plugin> pluginDesc : platformProvider.getPlugins()) {
|
||||||
java.util.List<String> options =
|
java.util.List<String> options =
|
||||||
|
|||||||
@@ -1,12 +1,20 @@
|
|||||||
package com.sun.tools.javac.api;
|
package com.sun.tools.javac.api;
|
||||||
|
|
||||||
import com.sun.source.tree.CompilationUnitTree;
|
import com.sun.source.tree.CompilationUnitTree;
|
||||||
|
import com.sun.source.tree.MemberSelectTree;
|
||||||
import com.sun.source.tree.MethodInvocationTree;
|
import com.sun.source.tree.MethodInvocationTree;
|
||||||
import com.sun.source.util.*;
|
import com.sun.source.util.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
public class WildcardFinderPlugin extends TreeScanner<Void, Void> implements Plugin, TaskListener {
|
public class WildcardFinderPlugin extends TreeScanner<Void, Void> implements Plugin, TaskListener {
|
||||||
|
|
||||||
|
private final Consumer<String> logger;
|
||||||
|
|
||||||
|
public WildcardFinderPlugin(Consumer<String> logger){
|
||||||
|
this.logger = logger;
|
||||||
|
}
|
||||||
@Override
|
@Override
|
||||||
public void started(TaskEvent e) {
|
public void started(TaskEvent e) {
|
||||||
TaskListener.super.started(e);
|
TaskListener.super.started(e);
|
||||||
@@ -55,10 +63,51 @@ public class WildcardFinderPlugin extends TreeScanner<Void, Void> implements Plu
|
|||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
public static final String preText = "[ANDI] ";
|
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
|
@Override
|
||||||
public Void visitMethodInvocation(MethodInvocationTree node, Void unused) {
|
public Void visitMethodInvocation(MethodInvocationTree node, Void unused) {
|
||||||
var args = node.getArguments();
|
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 {
|
try {
|
||||||
|
int argumentNumber = 0;
|
||||||
for(var arg : args){
|
for(var arg : args){
|
||||||
var type_field = arg.getClass().getField("type");
|
var type_field = arg.getClass().getField("type");
|
||||||
var pos_field = arg.getClass().getField("pos");
|
var pos_field = arg.getClass().getField("pos");
|
||||||
@@ -66,12 +115,15 @@ public class WildcardFinderPlugin extends TreeScanner<Void, Void> implements Plu
|
|||||||
pos_field.setAccessible(true);
|
pos_field.setAccessible(true);
|
||||||
String typeText = type_field.get(arg).toString();
|
String typeText = type_field.get(arg).toString();
|
||||||
int methodPos = pos_field.getInt(node);
|
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(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 if(typeText.contains("capture#")) {
|
||||||
|
logger.accept(preText + "CC: "+ "Arg#"+argumentNumber + ": " + typeText + " in " + currentSource + " " + lineOfPosition(currentClassContent,methodPos) + " of method " + methString);
|
||||||
}else{
|
}else{
|
||||||
System.out.println(preText + "normal Method call");
|
logger.accept(preText + "normal Method call");
|
||||||
}
|
}
|
||||||
|
argumentNumber++;
|
||||||
}
|
}
|
||||||
} catch (NoSuchFieldException e) {
|
} catch (NoSuchFieldException e) {
|
||||||
//System.out.println("Argument has no 'type' field");
|
//System.out.println("Argument has no 'type' field");
|
||||||
|
|||||||
Reference in New Issue
Block a user