Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get the number of methods #195

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.MethodInvocation;
import org.eclipse.jdt.internal.corext.util.JdtFlags;

Expand Down Expand Up @@ -61,6 +62,10 @@ public class StreamAnalyzer extends ASTVisitor {

private static final int N_FOR_STREAMS_DEFAULT = 2;

private int numberOfMethodForStreamReturnType;

private int numberOfMethodForStreamParameter;

private static void addImplicitEntryPoints(Collection<Entrypoint> target, Iterable<Entrypoint> source) {
for (Entrypoint implicitEntryPoint : source)
if (target.add(implicitEntryPoint))
Expand Down Expand Up @@ -511,4 +516,35 @@ public boolean visit(MethodInvocation node) {

return super.visit(node);
}

@Override
public boolean visit(MethodDeclaration methodDeclaration) {
IMethodBinding methodBinding = methodDeclaration.resolveBinding();
ITypeBinding returnType = methodBinding.getReturnType();
boolean returnTypeImplementsBaseStream = Util.implementsBaseStream(returnType);
if (returnTypeImplementsBaseStream) {
numberOfMethodForStreamReturnType++;
super.visit(methodDeclaration);
}
ITypeBinding parameterTypes[] = methodBinding.getParameterTypes();
if (parameterTypes.length < 1)
return false;
else {
for (ITypeBinding parameterBinding : parameterTypes) {
if (Util.implementsBaseStream(parameterBinding)) {
numberOfMethodForStreamParameter++;
break;
}
}
}
return super.visit(methodDeclaration);
}

public int getNumberOfMethodForStreamReturnType() {
return this.numberOfMethodForStreamReturnType;
}

public int getNumberMethodForStreamParameter() {
return this.numberOfMethodForStreamParameter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ public static void setLoggingLevel(int level) {
private boolean useImplicitJavaFXEntrypoints = false;

private boolean useImplicitTestEntrypoints = false;

private int numberOfMethodForStreamReturnType;

private int numberOfMethodForStreamParameter;

public OptimizeStreamsRefactoringProcessor() throws JavaModelException {
this(null, null, false, true, false, false, false, Optional.empty());
Expand Down Expand Up @@ -211,6 +215,11 @@ private RefactoringStatus checkExistence(IMember member, PreconditionFailure fai
// }
return new RefactoringStatus();
}

private void setNumberOfMethods(int methodForStreamReturnType, int methodForStreamParameter) {
this.numberOfMethodForStreamReturnType = methodForStreamReturnType;
this.numberOfMethodForStreamParameter = methodForStreamParameter;
}

@Override
public RefactoringStatus checkFinalConditions(final IProgressMonitor monitor, final CheckConditionsContext context)
Expand Down Expand Up @@ -253,6 +262,9 @@ public RefactoringStatus checkFinalConditions(final IProgressMonitor monitor, fi
this.projectToEntryPoints = analyzer.analyze(Optional.of(this.getExcludedTimeCollector()),
subMonitor.split(IProgressMonitor.UNKNOWN, SubMonitor.SUPPRESS_NONE));
subMonitor.worked(1);

this.setNumberOfMethods(analyzer.getNumberOfMethodForStreamReturnType(),
analyzer.getNumberMethodForStreamParameter());

// set statistics for stream instances.
this.setNumberOfProcessedStreamInstances(analyzer.getNumberOfProcessedStreamInstances());
Expand Down Expand Up @@ -580,4 +592,12 @@ public void setUseImplicitJavaFXEntrypoints(boolean useImplicitJavaFXEntrypoints
public void setUseImplicitTestEntrypoints(boolean useImplicitTestEntrypoints) {
this.useImplicitTestEntrypoints = useImplicitTestEntrypoints;
}

public int getNumberOfMethodForStreamReturnType() {
return this.numberOfMethodForStreamReturnType;
}

public int getNumberMethodForStreamParameter() {
return this.numberOfMethodForStreamParameter;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
CSVPrinter streamExecutionModePrinter = null;
CSVPrinter streamOrderingPrinter = null;
CSVPrinter entryPointsPrinter = null;
CSVPrinter streamStatisticsPrinter = null;
PrintWriter entryPointsTXTPrinter = null;

OptimizeStreamsRefactoringProcessor processor = null;
Expand Down Expand Up @@ -369,6 +370,9 @@ public Object execute(ExecutionEvent event) throws ExecutionException {

entryPointsPrinter = createCSVPrinter("entry_points.csv",
new String[] { "subject", "method", "type FQN" });

streamStatisticsPrinter = createCSVPrinter("stream_statistics.csv",
new String[] {"subject", "number of methods for stream return type", "number of method for stream parameter"});

entryPointsTXTPrinter = new PrintWriter("entry_points.txt");

Expand Down Expand Up @@ -454,6 +458,10 @@ public Object execute(ExecutionEvent event) throws ExecutionException {

resultsPrinter.print(candidates.size()); // number.

streamStatisticsPrinter.printRecord(javaProject.getElementName(),
processor.getNumberOfMethodForStreamReturnType(),
processor.getNumberMethodForStreamParameter());

// candidate streams.
for (Stream stream : candidates)
candidateStreamPrinter.printRecord(javaProject.getElementName(), stream.getCreation(),
Expand Down Expand Up @@ -619,6 +627,8 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
entryPointsPrinter.close();
if (entryPointsTXTPrinter != null)
entryPointsTXTPrinter.close();
if (streamStatisticsPrinter != null)
streamStatisticsPrinter.close();

// clear cache.
if (processor != null)
Expand Down