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 all 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 @@ -26,8 +26,10 @@
import org.eclipse.core.runtime.SubMonitor;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.FieldDeclaration;
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 +63,12 @@ public class StreamAnalyzer extends ASTVisitor {

private static final int N_FOR_STREAMS_DEFAULT = 2;

private int numberOfMethodForStreamReturnType;

private int numberOfMethodForStreamParameter;

private int numberOfFieldForStream;

private static void addImplicitEntryPoints(Collection<Entrypoint> target, Iterable<Entrypoint> source) {
for (Entrypoint implicitEntryPoint : source)
if (target.add(implicitEntryPoint))
Expand Down Expand Up @@ -511,4 +519,49 @@ 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);
}

@Override
public boolean visit(FieldDeclaration fieldDeclaration) {
ITypeBinding fieldBinding = fieldDeclaration.getType().resolveBinding();
if (Util.implementsBaseStream(fieldBinding)) {
numberOfFieldForStream++;
}
return super.visit(fieldDeclaration);
}

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

public int getNumberOfMethodForStreamParameter() {
return this.numberOfMethodForStreamParameter;
}

public int getNumberOfFieldForStream() {
return this.numberOfFieldForStream;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ public static void setLoggingLevel(int level) {

private boolean useImplicitTestEntrypoints = false;

private int numberOfMethodForStreamReturnType;

private int numberOfMethodForStreamParameter;

private int numberOfFieldForStream;

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

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

@Override
public RefactoringStatus checkFinalConditions(final IProgressMonitor monitor, final CheckConditionsContext context)
throws CoreException, OperationCanceledException {
Expand Down Expand Up @@ -254,6 +266,9 @@ public RefactoringStatus checkFinalConditions(final IProgressMonitor monitor, fi
subMonitor.split(IProgressMonitor.UNKNOWN, SubMonitor.SUPPRESS_NONE));
subMonitor.worked(1);

this.setStatistics(analyzer.getNumberOfMethodForStreamReturnType(),
analyzer.getNumberOfMethodForStreamParameter(), analyzer.getNumberOfFieldForStream());

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

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

public int getNumberOfMethodForStreamParameter() {
return this.numberOfMethodForStreamParameter;
}

public int getNumberOfFieldForStream() {
return this.numberOfFieldForStream;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
resultsHeader.add(action.toString());

resultsHeader.add("time (s)");
resultsHeader.addAll(Arrays.asList("#methods for stream return type", "#methods for stream parameter",
"#number of fields for stream"));

resultsPrinter = createCSVPrinter("results.csv",
resultsHeader.toArray(new String[resultsHeader.size()]));
Expand Down Expand Up @@ -585,6 +587,10 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
resultsPrinter.print((resultsTimeCollector.getCollectedTime()
- processor.getExcludedTimeCollector().getCollectedTime()) / 1000.0);

resultsPrinter.print(processor.getNumberOfMethodForStreamReturnType());
resultsPrinter.print(processor.getNumberOfMethodForStreamParameter());
resultsPrinter.print(processor.getNumberOfFieldForStream());

// end the record.
resultsPrinter.println();

Expand Down