Skip to content

Commit da2030e

Browse files
committed
Clean up.
1 parent 5cfc47f commit da2030e

File tree

9 files changed

+43
-69
lines changed

9 files changed

+43
-69
lines changed

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/OrderingInference.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ private Spliterator<?> getSpliterator(Object instance, String calledMethodName)
8787

8888
Spliterator<?> spliterator = null;
8989

90-
if (instance instanceof Iterable) {
90+
if (instance instanceof Iterable)
9191
try {
9292
spliterator = ((Iterable<?>) instance).spliterator();
9393
} catch (NullPointerException e) {
9494
LOGGER.log(Level.WARNING, "Possible trouble creating instance (most likely private type).", e);
9595
return null;
9696
}
97-
} else {
97+
else {
9898
// try to call the stream() method to get the spliterator.
9999
BaseStream<?, ?> baseStream = null;
100100
try {
@@ -148,18 +148,16 @@ private Ordering inferOrdering(Collection<TypeAbstraction> possibleTypes, String
148148
CannotExtractSpliteratorException {
149149
Ordering ret = null;
150150

151-
for (TypeAbstraction typeAbstraction : possibleTypes) {
151+
for (TypeAbstraction typeAbstraction : possibleTypes)
152152
if (typeAbstraction != TypeAbstraction.TOP) {
153153
Ordering ordering = this.inferOrdering(typeAbstraction, calledMethodName);
154154

155155
if (ret == null)
156156
ret = ordering;
157-
else if (ret != ordering) {
157+
else if (ret != ordering)
158158
throw new InconsistentPossibleOrderingException(
159159
"Types have inconsistent orderings: " + possibleTypes);
160-
}
161160
}
162-
}
163161

164162
return ret;
165163
}

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/Stream.java

Lines changed: 22 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ protected void check() {
213213

214214
// let's check that execution modes are consistent.
215215
if (this.isConsistent(possibleExecutionModes, PreconditionFailure.INCONSISTENT_POSSIBLE_EXECUTION_MODES,
216-
"Stream: " + creation + " has inconsitent possible execution modes.", creation)) {
216+
"Stream: " + creation + " has inconsitent possible execution modes.", creation))
217217
// do we have consistent ordering?
218218
if (this.isConsistent(possibleOrderings, PreconditionFailure.INCONSISTENT_POSSIBLE_ORDERINGS,
219219
"Stream: " + creation + " has inconsitent possible orderings.", creation)) {
@@ -242,26 +242,22 @@ protected void check() {
242242
if (hasPossibleSideEffects)
243243
this.addStatusEntry(PreconditionFailure.HAS_SIDE_EFFECTS2, "Stream: " + creation
244244
+ " is associated with a behavioral parameter containing possible side-effects");
245-
else {
246-
// check SIO.
247-
if (!hasPossibleStatefulIntermediateOperations) {
248-
// it passed P2.
249-
this.setRefactoring(Refactoring.CONVERT_SEQUENTIAL_STREAM_TO_PARALLEL);
250-
this.setTransformationAction(TransformationAction.CONVERT_TO_PARALLEL);
251-
this.setPassingPrecondition(PreconditionSuccess.P2);
252-
} else {
253-
// check ROM.
254-
if (!reduceOrderingPossiblyMatters) {
255-
// it passes P3.
256-
this.setRefactoring(Refactoring.CONVERT_SEQUENTIAL_STREAM_TO_PARALLEL);
257-
this.setTransformationAction(TransformationAction.UNORDER,
258-
TransformationAction.CONVERT_TO_PARALLEL);
259-
this.setPassingPrecondition(PreconditionSuccess.P3);
260-
} else
261-
this.addStatusEntry(PreconditionFailure.REDUCE_ORDERING_MATTERS,
262-
"Ordering of the result produced by a terminal operation must be preserved");
263-
}
264-
}
245+
else // check SIO.
246+
if (!hasPossibleStatefulIntermediateOperations) {
247+
// it passed P2.
248+
this.setRefactoring(Refactoring.CONVERT_SEQUENTIAL_STREAM_TO_PARALLEL);
249+
this.setTransformationAction(TransformationAction.CONVERT_TO_PARALLEL);
250+
this.setPassingPrecondition(PreconditionSuccess.P2);
251+
} else // check ROM.
252+
if (!reduceOrderingPossiblyMatters) {
253+
// it passes P3.
254+
this.setRefactoring(Refactoring.CONVERT_SEQUENTIAL_STREAM_TO_PARALLEL);
255+
this.setTransformationAction(TransformationAction.UNORDER,
256+
TransformationAction.CONVERT_TO_PARALLEL);
257+
this.setPassingPrecondition(PreconditionSuccess.P3);
258+
} else
259+
this.addStatusEntry(PreconditionFailure.REDUCE_ORDERING_MATTERS,
260+
"Ordering of the result produced by a terminal operation must be preserved");
265261
break;
266262
}
267263
break;
@@ -292,7 +288,6 @@ protected void check() {
292288
}
293289
}
294290
}
295-
}
296291
}
297292

298293
protected InstanceKey computeInstanceKey(Collection<InstanceKey> trackedInstances,
@@ -459,14 +454,13 @@ Optional<SSAInvokeInstruction> getInstructionForCreation(EclipseProjectAnalysisE
459454
int lineNumberFromIR = getLineNumberFromIR(method, instruction);
460455
int lineNumberFromAST = getLineNumberFromAST(methodName);
461456

462-
if (lineNumberFromIR == lineNumberFromAST) {
457+
if (lineNumberFromIR == lineNumberFromAST)
463458
// lines from the AST and the IR match. Let's dive a little
464459
// deeper to be more confident of the correspondence.
465460
if (matches(instruction, this.getCreation(), Optional.of(LOGGER))) {
466461
this.instructionForCreation = Optional.of((SSAInvokeInstruction) instruction);
467462
return this.instructionForCreation;
468463
}
469-
}
470464
}
471465
this.instructionForCreation = Optional.empty();
472466
}
@@ -529,13 +523,12 @@ public TypeReference getTypeReference() {
529523
// try to get the top-most type.
530524
ITypeBinding[] allSuperTypes = Bindings.getAllSuperTypes(typeBinding);
531525

532-
for (ITypeBinding supertype : allSuperTypes) {
526+
for (ITypeBinding supertype : allSuperTypes)
533527
// if it's the top-most interface.
534528
if (supertype.isInterface() && supertype.getName().startsWith(BASE_STREAM_TYPE_NAME)) {
535529
typeBinding = supertype; // use it.
536530
break;
537531
}
538-
}
539532

540533
TypeReference typeRef = mapper.getTypeRef(typeBinding);
541534
return typeRef;
@@ -599,7 +592,7 @@ private void inferInitialOrdering(EclipseProjectAnalysisEngine<InstanceKey> engi
599592
String expressionTypeQualifiedName = expressionTypeBinding.getErasure().getQualifiedName();
600593
IMethodBinding calledMethodBinding = this.getCreation().resolveMethodBinding();
601594

602-
if (JdtFlags.isStatic(calledMethodBinding)) {
595+
if (JdtFlags.isStatic(calledMethodBinding))
603596
// static methods returning unordered streams.
604597
switch (expressionTypeQualifiedName) {
605598
case JAVA_UTIL_STREAM_STREAM:
@@ -619,8 +612,8 @@ private void inferInitialOrdering(EclipseProjectAnalysisEngine<InstanceKey> engi
619612
+ ". Falling back to: " + defaultOrdering + ".");
620613
this.setInitialOrdering(defaultOrdering);
621614
}
622-
} else { // instance method.
623-
// get the use value number for the stream creation.
615+
else { // instance method.
616+
// get the use value number for the stream creation.
624617
int valueNumber = this.getUseValueNumberForCreation(engine);
625618

626619
if (valueNumber < 0) {

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/analysis/Util.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,14 +272,11 @@ public static Set<Entrypoint> findEntryPoints(IClassHierarchy classHierarchy, Se
272272
final Set<Entrypoint> result = new HashSet<>();
273273

274274
for (IClass klass : classHierarchy)
275-
if (!(isJDKClass(klass) || isLibraryClass(klass))) {
275+
if (!(isJDKClass(klass) || isLibraryClass(klass)))
276276
// iterate over all declared methods
277-
for (com.ibm.wala.classLoader.IMethod method : klass.getDeclaredMethods()) {
278-
if (signatures.contains(method.getSignature())) {
277+
for (com.ibm.wala.classLoader.IMethod method : klass.getDeclaredMethods())
278+
if (signatures.contains(method.getSignature()))
279279
addEntryPoint(result, method, classHierarchy);
280-
}
281-
}
282-
}
283280
return result;
284281
}
285282

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/safe/Util.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,16 @@ public static boolean instanceKeyCorrespondsWithInstantiationInstruction(Instanc
112112
ClassLoaderReference methodClassLoader = method.getReference().getDeclaringClass().getClassLoader();
113113

114114
// if we haven't encountered application code in the call string yet.
115-
if (!applicationCodeInCallString) {
116-
// get the class loaders.
117-
115+
if (!applicationCodeInCallString)
118116
// if either the call site reference class loader or the (enclosing) method
119117
// class loader is of type Application.
120118
if (callSiteReferenceClassLoaderReference.equals(ClassLoaderReference.Application)
121119
|| methodClassLoader.equals(ClassLoaderReference.Application))
122120
// then, we've seen application code.
123121
applicationCodeInCallString = true;
124-
}
125122

126123
// if all non-application code in the call strings return streams.
127-
if (allNonApplicationCodeReturnsStreams) {
124+
if (allNonApplicationCodeReturnsStreams)
128125
// find out if this one does as well.
129126
if (!callSiteReferenceClassLoaderReference.equals(ClassLoaderReference.Application)) {
130127
IMethod target = engine.getClassHierarchy()
@@ -139,7 +136,6 @@ public static boolean instanceKeyCorrespondsWithInstantiationInstruction(Instanc
139136
// we found one that doesn't.
140137
allNonApplicationCodeReturnsStreams = false;
141138
}
142-
}
143139

144140
// if the call site reference equals the call site corresponding
145141
// to the creation instruction.

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/wala/AnalysisUtils.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ public static boolean isAnnotatedFactoryMethod(IMethod callee) {
3232
if (annotations == null)
3333
return false;
3434

35-
for (Annotation annotation : annotations) {
36-
if (annotation.getType().getName().getClassName().toString().contains("JFlowFactory")) {
35+
for (Annotation annotation : annotations)
36+
if (annotation.getType().getName().getClassName().toString().contains("JFlowFactory"))
3737
return true;
38-
}
39-
}
4038
return false;
4139
}
4240

edu.cuny.hunter.streamrefactoring.core/src/edu/cuny/hunter/streamrefactoring/core/wala/TestableJavaEclipseProjectPath.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,9 @@ protected void resolveLibraryPathEntry(EclipseProjectPath.ILoader loader, IPath
5555
// should ignore directories as well..
5656
return;
5757
}
58-
if (this.isPrimordialJarFile(j)) {
58+
if (this.isPrimordialJarFile(j))
5959
// force it.
6060
loader = Loader.PRIMORDIAL;
61-
}
6261
List<Module> s = MapUtil.findOrCreateList(this.modules, loader);
6362
s.add(file.isDirectory() ? (Module) new BinaryDirectoryTreeModule(file) : (Module) new JarFileModule(j));
6463
}

edu.cuny.hunter.streamrefactoring.eval/src/edu/cuny/hunter/streamrefactoring/eval/utils/Util.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,13 @@ public static String getMethodIdentifier(IMethod method) throws JavaModelExcepti
1818
return null;
1919

2020
StringBuilder sb = new StringBuilder();
21-
sb.append((method.getElementName()) + "(");
21+
sb.append(method.getElementName() + "(");
2222
ILocalVariable[] parameters = method.getParameters();
2323
for (int i = 0; i < parameters.length; i++) {
2424
sb.append(edu.cuny.hunter.streamrefactoring.core.utils.Util
2525
.getQualifiedNameFromTypeSignature(parameters[i].getTypeSignature(), method.getDeclaringType()));
26-
if (i != (parameters.length - 1)) {
26+
if (i != parameters.length - 1)
2727
sb.append(",");
28-
}
2928
}
3029
sb.append(")");
3130
return sb.toString();

edu.cuny.hunter.streamrefactoring.tests/test cases/edu/cuny/hunter/streamrefactoring/ui/tests/ConvertStreamToParallelRefactoringTest.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ public static Test suite() {
186186

187187
private static void tryDeletingAllJavaClassFiles(IPackageFragment pack) throws JavaModelException {
188188
IJavaElement[] kids = pack.getChildren();
189-
for (int i = 0; i < kids.length; i++) {
190-
if (kids[i] instanceof ISourceManipulation) {
189+
for (int i = 0; i < kids.length; i++)
190+
if (kids[i] instanceof ISourceManipulation)
191191
if (kids[i].exists() && !kids[i].isReadOnly()) {
192192
IPath path = kids[i].getPath();
193193

@@ -226,8 +226,6 @@ private static void tryDeletingAllJavaClassFiles(IPackageFragment pack) throws J
226226
"Class file for " + kids[i].getElementName() + " does not exist.", e);
227227
}
228228
}
229-
}
230-
}
231229
}
232230

233231
public ConvertStreamToParallelRefactoringTest(String name) {
@@ -262,9 +260,9 @@ protected ICompilationUnit createCUfromTestFile(IPackageFragment pack, String cu
262260
throws Exception {
263261
String testFileName;
264262

265-
if (input) {
263+
if (input)
266264
testFileName = this.getInputTestFileName(cuName);
267-
} else // output case.
265+
else // output case.
268266
testFileName = this.getOutputTestFileName(cuName);
269267

270268
String contents = this.getFileContents(testFileName);

edu.cuny.hunter.streamrefactoring.ui/src/edu/cuny/hunter/streamrefactoring/ui/handlers/ConvertStreamToParallelHandler.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,9 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
4343

4444
Set<IJavaProject> javaProjectSet = new HashSet<>();
4545

46-
if (list != null) {
46+
if (list != null)
4747
try {
48-
for (Object obj : list) {
48+
for (Object obj : list)
4949
if (obj instanceof IJavaElement) {
5050
IJavaElement jElem = (IJavaElement) obj;
5151
switch (jElem.getElementType()) {
@@ -64,7 +64,6 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
6464
break;
6565
}
6666
}
67-
}
6867

6968
Shell shell = HandlerUtil.getActiveShellChecked(event);
7069
ConvertStreamToParallelRefactoringWizard.startRefactoring(
@@ -73,7 +72,6 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
7372
JavaPlugin.log(e);
7473
throw new ExecutionException("Failed to start refactoring", e);
7574
}
76-
}
7775
// TODO: What do we do if there was no input? Do we display some
7876
// message?
7977
return null;
@@ -83,7 +81,7 @@ private Set<IMethod> extractMethodsFromClass(IType type, Optional<IProgressMonit
8381
throws JavaModelException {
8482
Set<IMethod> methodSet = new HashSet<>();
8583

86-
if (type.isClass()) {
84+
if (type.isClass())
8785
for (IMethod method : type.getMethods())
8886
// if (RefactoringAvailabilityTester.isInterfaceMigrationAvailable(method,
8987
// monitor)) {
@@ -93,8 +91,6 @@ private Set<IMethod> extractMethodsFromClass(IType type, Optional<IProgressMonit
9391
} else
9492
this.logNonMigratableMethod(method);
9593

96-
}
97-
9894
return methodSet;
9995
}
10096

0 commit comments

Comments
 (0)