From 0eb11ebe434e1f166ef4e8982bb7e2af6030378c Mon Sep 17 00:00:00 2001 From: Yiming Date: Wed, 11 Jul 2018 17:12:22 -0400 Subject: [PATCH 1/4] get number --- .../core/analysis/StreamAnalyzer.java | 36 +++++++++++++++++++ .../OptimizeStreamsRefactoringProcessor.java | 20 +++++++++++ ...ertToParallelStreamRefactoringHandler.java | 10 ++++++ 3 files changed, 66 insertions(+) diff --git a/edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/StreamAnalyzer.java b/edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/StreamAnalyzer.java index 58a00913..1082fc50 100644 --- a/edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/StreamAnalyzer.java +++ b/edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/StreamAnalyzer.java @@ -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; @@ -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 target, Iterable source) { for (Entrypoint implicitEntryPoint : source) if (target.add(implicitEntryPoint)) @@ -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 returnTypes[] = methodBinding.getParameterTypes(); + if (returnTypes.length < 1) + return false; + else { + for (ITypeBinding returnTypeBinding : returnTypes) { + if (Util.implementsBaseStream(returnTypeBinding)) { + numberOfMethodForStreamParameter++; + break; + } + } + } + return super.visit(methodDeclaration); + } + + public int getNumberOfMethodForStreamReturnType() { + return this.numberOfMethodForStreamReturnType; + } + + public int getNumberMethodForStreamParameter() { + return this.numberOfMethodForStreamParameter; + } } diff --git a/edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/refactorings/OptimizeStreamsRefactoringProcessor.java b/edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/refactorings/OptimizeStreamsRefactoringProcessor.java index 02eeb7e9..a068295a 100644 --- a/edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/refactorings/OptimizeStreamsRefactoringProcessor.java +++ b/edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/refactorings/OptimizeStreamsRefactoringProcessor.java @@ -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()); @@ -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) @@ -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()); @@ -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; + } } diff --git a/edu.cuny.hunter.streamrefactoring.eval/src/edu/cuny/hunter/streamrefactoring/eval/handlers/EvaluateConvertToParallelStreamRefactoringHandler.java b/edu.cuny.hunter.streamrefactoring.eval/src/edu/cuny/hunter/streamrefactoring/eval/handlers/EvaluateConvertToParallelStreamRefactoringHandler.java index eef51a54..70bae07f 100644 --- a/edu.cuny.hunter.streamrefactoring.eval/src/edu/cuny/hunter/streamrefactoring/eval/handlers/EvaluateConvertToParallelStreamRefactoringHandler.java +++ b/edu.cuny.hunter.streamrefactoring.eval/src/edu/cuny/hunter/streamrefactoring/eval/handlers/EvaluateConvertToParallelStreamRefactoringHandler.java @@ -311,6 +311,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException { CSVPrinter streamExecutionModePrinter = null; CSVPrinter streamOrderingPrinter = null; CSVPrinter entryPointsPrinter = null; + CSVPrinter streamStaticsPrinter = null; PrintWriter entryPointsTXTPrinter = null; OptimizeStreamsRefactoringProcessor processor = null; @@ -369,6 +370,9 @@ public Object execute(ExecutionEvent event) throws ExecutionException { entryPointsPrinter = createCSVPrinter("entry_points.csv", new String[] { "subject", "method", "type FQN" }); + + streamStaticsPrinter = createCSVPrinter("stream_statics.csv", + new String[] {"subject", "number of methods for stream return type", "number of method for stream parameter"}); entryPointsTXTPrinter = new PrintWriter("entry_points.txt"); @@ -454,6 +458,10 @@ public Object execute(ExecutionEvent event) throws ExecutionException { resultsPrinter.print(candidates.size()); // number. + streamStaticsPrinter.printRecord(javaProject.getElementName(), + processor.getNumberOfMethodForStreamReturnType(), + processor.getNumberMethodForStreamParameter()); + // candidate streams. for (Stream stream : candidates) candidateStreamPrinter.printRecord(javaProject.getElementName(), stream.getCreation(), @@ -619,6 +627,8 @@ public Object execute(ExecutionEvent event) throws ExecutionException { entryPointsPrinter.close(); if (entryPointsTXTPrinter != null) entryPointsTXTPrinter.close(); + if (streamStaticsPrinter != null) + streamStaticsPrinter.close(); // clear cache. if (processor != null) From 97a5f3268738294234b3917e8c1b3eef02d0062c Mon Sep 17 00:00:00 2001 From: Yiming Date: Thu, 12 Jul 2018 10:00:01 -0400 Subject: [PATCH 2/4] rename variable --- .../streamrefactoring/core/analysis/StreamAnalyzer.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/StreamAnalyzer.java b/edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/StreamAnalyzer.java index 1082fc50..115b2d55 100644 --- a/edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/StreamAnalyzer.java +++ b/edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/StreamAnalyzer.java @@ -526,12 +526,12 @@ public boolean visit(MethodDeclaration methodDeclaration) { numberOfMethodForStreamReturnType++; super.visit(methodDeclaration); } - ITypeBinding returnTypes[] = methodBinding.getParameterTypes(); - if (returnTypes.length < 1) + ITypeBinding parameterTypes[] = methodBinding.getParameterTypes(); + if (parameterTypes.length < 1) return false; else { - for (ITypeBinding returnTypeBinding : returnTypes) { - if (Util.implementsBaseStream(returnTypeBinding)) { + for (ITypeBinding parameterBinding : parameterTypes) { + if (Util.implementsBaseStream(parameterBinding)) { numberOfMethodForStreamParameter++; break; } From 4c8a1f48148c115b9e1dd44a4af688967fc0491f Mon Sep 17 00:00:00 2001 From: Yiming Date: Thu, 12 Jul 2018 10:05:32 -0400 Subject: [PATCH 3/4] rename file --- ...luateConvertToParallelStreamRefactoringHandler.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/edu.cuny.hunter.streamrefactoring.eval/src/edu/cuny/hunter/streamrefactoring/eval/handlers/EvaluateConvertToParallelStreamRefactoringHandler.java b/edu.cuny.hunter.streamrefactoring.eval/src/edu/cuny/hunter/streamrefactoring/eval/handlers/EvaluateConvertToParallelStreamRefactoringHandler.java index 70bae07f..8d65f071 100644 --- a/edu.cuny.hunter.streamrefactoring.eval/src/edu/cuny/hunter/streamrefactoring/eval/handlers/EvaluateConvertToParallelStreamRefactoringHandler.java +++ b/edu.cuny.hunter.streamrefactoring.eval/src/edu/cuny/hunter/streamrefactoring/eval/handlers/EvaluateConvertToParallelStreamRefactoringHandler.java @@ -311,7 +311,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException { CSVPrinter streamExecutionModePrinter = null; CSVPrinter streamOrderingPrinter = null; CSVPrinter entryPointsPrinter = null; - CSVPrinter streamStaticsPrinter = null; + CSVPrinter streamStatisticsPrinter = null; PrintWriter entryPointsTXTPrinter = null; OptimizeStreamsRefactoringProcessor processor = null; @@ -371,7 +371,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException { entryPointsPrinter = createCSVPrinter("entry_points.csv", new String[] { "subject", "method", "type FQN" }); - streamStaticsPrinter = createCSVPrinter("stream_statics.csv", + 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"); @@ -458,7 +458,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException { resultsPrinter.print(candidates.size()); // number. - streamStaticsPrinter.printRecord(javaProject.getElementName(), + streamStatisticsPrinter.printRecord(javaProject.getElementName(), processor.getNumberOfMethodForStreamReturnType(), processor.getNumberMethodForStreamParameter()); @@ -627,8 +627,8 @@ public Object execute(ExecutionEvent event) throws ExecutionException { entryPointsPrinter.close(); if (entryPointsTXTPrinter != null) entryPointsTXTPrinter.close(); - if (streamStaticsPrinter != null) - streamStaticsPrinter.close(); + if (streamStatisticsPrinter != null) + streamStatisticsPrinter.close(); // clear cache. if (processor != null) From b16259539e99baa6b2fe96345eb561fc9edd9a8b Mon Sep 17 00:00:00 2001 From: Yiming Date: Sun, 15 Jul 2018 14:59:13 -0400 Subject: [PATCH 4/4] add field --- .../core/analysis/StreamAnalyzer.java | 19 +++++++++++++- .../OptimizeStreamsRefactoringProcessor.java | 25 ++++++++++++------- ...ertToParallelStreamRefactoringHandler.java | 16 +++++------- 3 files changed, 40 insertions(+), 20 deletions(-) diff --git a/edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/StreamAnalyzer.java b/edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/StreamAnalyzer.java index 115b2d55..cbe5b0d2 100644 --- a/edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/StreamAnalyzer.java +++ b/edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/StreamAnalyzer.java @@ -26,6 +26,7 @@ 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; @@ -66,6 +67,8 @@ public class StreamAnalyzer extends ASTVisitor { private int numberOfMethodForStreamParameter; + private int numberOfFieldForStream; + private static void addImplicitEntryPoints(Collection target, Iterable source) { for (Entrypoint implicitEntryPoint : source) if (target.add(implicitEntryPoint)) @@ -540,11 +543,25 @@ public boolean visit(MethodDeclaration methodDeclaration) { 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 getNumberMethodForStreamParameter() { + public int getNumberOfMethodForStreamParameter() { return this.numberOfMethodForStreamParameter; } + + public int getNumberOfFieldForStream() { + return this.numberOfFieldForStream; + } + } diff --git a/edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/refactorings/OptimizeStreamsRefactoringProcessor.java b/edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/refactorings/OptimizeStreamsRefactoringProcessor.java index a068295a..6641cacc 100644 --- a/edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/refactorings/OptimizeStreamsRefactoringProcessor.java +++ b/edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/refactorings/OptimizeStreamsRefactoringProcessor.java @@ -149,11 +149,13 @@ public static void setLoggingLevel(int level) { private boolean useImplicitJavaFXEntrypoints = false; 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()); } @@ -215,10 +217,11 @@ private RefactoringStatus checkExistence(IMember member, PreconditionFailure fai // } return new RefactoringStatus(); } - - private void setNumberOfMethods(int methodForStreamReturnType, int methodForStreamParameter) { + + private void setStatistics(int methodForStreamReturnType, int methodForStreamParameter, int fieldForStream) { this.numberOfMethodForStreamReturnType = methodForStreamReturnType; this.numberOfMethodForStreamParameter = methodForStreamParameter; + this.numberOfFieldForStream = fieldForStream; } @Override @@ -262,9 +265,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()); + + this.setStatistics(analyzer.getNumberOfMethodForStreamReturnType(), + analyzer.getNumberOfMethodForStreamParameter(), analyzer.getNumberOfFieldForStream()); // set statistics for stream instances. this.setNumberOfProcessedStreamInstances(analyzer.getNumberOfProcessedStreamInstances()); @@ -592,12 +595,16 @@ public void setUseImplicitJavaFXEntrypoints(boolean useImplicitJavaFXEntrypoints public void setUseImplicitTestEntrypoints(boolean useImplicitTestEntrypoints) { this.useImplicitTestEntrypoints = useImplicitTestEntrypoints; } - + public int getNumberOfMethodForStreamReturnType() { return this.numberOfMethodForStreamReturnType; } - public int getNumberMethodForStreamParameter() { + public int getNumberOfMethodForStreamParameter() { return this.numberOfMethodForStreamParameter; } + + public int getNumberOfFieldForStream() { + return this.numberOfFieldForStream; + } } diff --git a/edu.cuny.hunter.streamrefactoring.eval/src/edu/cuny/hunter/streamrefactoring/eval/handlers/EvaluateConvertToParallelStreamRefactoringHandler.java b/edu.cuny.hunter.streamrefactoring.eval/src/edu/cuny/hunter/streamrefactoring/eval/handlers/EvaluateConvertToParallelStreamRefactoringHandler.java index 8d65f071..da913e3c 100644 --- a/edu.cuny.hunter.streamrefactoring.eval/src/edu/cuny/hunter/streamrefactoring/eval/handlers/EvaluateConvertToParallelStreamRefactoringHandler.java +++ b/edu.cuny.hunter.streamrefactoring.eval/src/edu/cuny/hunter/streamrefactoring/eval/handlers/EvaluateConvertToParallelStreamRefactoringHandler.java @@ -311,7 +311,6 @@ 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; @@ -340,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()])); @@ -370,9 +371,6 @@ 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"); @@ -458,10 +456,6 @@ 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(), @@ -593,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(); @@ -627,8 +625,6 @@ public Object execute(ExecutionEvent event) throws ExecutionException { entryPointsPrinter.close(); if (entryPointsTXTPrinter != null) entryPointsTXTPrinter.close(); - if (streamStatisticsPrinter != null) - streamStatisticsPrinter.close(); // clear cache. if (processor != null)