Skip to content

Commit 3faedb8

Browse files
authored
Merge pull request #159 from ponder-lab/work
Work on several issues but mainly #155.
2 parents 4ecfd96 + d14631e commit 3faedb8

File tree

6 files changed

+65
-16
lines changed

6 files changed

+65
-16
lines changed

README.md

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ Explicit entry points may be marked using the appropriate annotation found in th
1919

2020
There are currently some limitations with embedded streams (i.e., streams declared as part of lambda expressions sent as arguments to intermediate stream operations). This is due to model differences between the Eclipse JDT and WALA. See [#155](https://github.com/ponder-lab/Java-8-Stream-Refactoring/issues/155) for details.
2121

22+
In general, there are some issues with the mapping between the Eclipse DOM and WALA DOM, particuarly when using Anonymous Inner Classes (AICs). We are currently working with the WALA developers to solve [this issue](https://github.com/ponder-lab/Java-8-Stream-Refactoring/issues/155).
23+
2224
## Contributing
2325

2426
Please see [the wiki](http://github.com/ponder-lab/Java-8-Stream-Refactoring/wiki) for more information regarding development.

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

+17-11
Original file line numberDiff line numberDiff line change
@@ -329,10 +329,14 @@ public MethodDeclaration getEnclosingMethodDeclaration() {
329329
}
330330

331331
private IR getEnclosingMethodIR(EclipseProjectAnalysisEngine<InstanceKey> engine)
332-
throws IOException, CoreException {
332+
throws IOException, CoreException, UnhandledCaseException {
333333
if (enclosingMethodDeclarationIR == null) {
334334
// get the IR for the enclosing method.
335335
com.ibm.wala.classLoader.IMethod resolvedMethod = getEnclosingWalaMethod(engine);
336+
337+
if (resolvedMethod == null)
338+
throw new UnhandledCaseException("Couldn't retrieve enclosing WALA method. Most likely an AIC #155.");
339+
336340
enclosingMethodDeclarationIR = engine.getCache().getIR(resolvedMethod);
337341

338342
if (enclosingMethodDeclarationIR == null)
@@ -361,12 +365,13 @@ protected CGNode getEnclosingMethodNode(EclipseProjectAnalysisEngine<InstanceKey
361365
}
362366

363367
MethodReference getEnclosingMethodReference() {
364-
JDTIdentityMapper mapper = getJDTIdentifyMapper(getEnclosingMethodDeclaration());
365-
MethodReference methodRef = mapper.getMethodRef(getEnclosingMethodDeclaration().resolveBinding());
368+
MethodDeclaration enclosingMethodDeclaration = getEnclosingMethodDeclaration();
369+
JDTIdentityMapper mapper = getJDTIdentifyMapper(enclosingMethodDeclaration);
370+
MethodReference methodRef = mapper.getMethodRef(enclosingMethodDeclaration.resolveBinding());
366371

367372
if (methodRef == null)
368373
throw new IllegalStateException(
369-
"Could not get method reference for: " + getEnclosingMethodDeclaration().getName());
374+
"Could not get method reference for: " + enclosingMethodDeclaration.getName());
370375
return methodRef;
371376
}
372377

@@ -405,8 +410,8 @@ protected Ordering getInitialOrdering() {
405410
}
406411

407412
public InstanceKey getInstanceKey(Collection<InstanceKey> trackedInstances,
408-
EclipseProjectAnalysisEngine<InstanceKey> engine)
409-
throws InvalidClassFileException, IOException, CoreException, InstanceKeyNotFoundException {
413+
EclipseProjectAnalysisEngine<InstanceKey> engine) throws InvalidClassFileException, IOException,
414+
CoreException, InstanceKeyNotFoundException, UnhandledCaseException {
410415
if (instanceKey == null) {
411416
instanceKey = this.getInstructionForCreation(engine)
412417
.flatMap(instruction -> trackedInstances.stream()
@@ -420,13 +425,14 @@ public InstanceKey getInstanceKey(Collection<InstanceKey> trackedInstances,
420425
}
421426

422427
Optional<SSAInvokeInstruction> getInstructionForCreation(EclipseProjectAnalysisEngine<InstanceKey> engine)
423-
throws InvalidClassFileException, IOException, CoreException {
428+
throws InvalidClassFileException, IOException, CoreException, UnhandledCaseException {
424429
if (this.instructionForCreation == null) {
425-
IBytecodeMethod method = (IBytecodeMethod) this.getEnclosingMethodIR(engine).getMethod();
430+
IR enclosingMethodIR = this.getEnclosingMethodIR(engine);
431+
432+
IBytecodeMethod method = (IBytecodeMethod) enclosingMethodIR.getMethod();
426433
SimpleName methodName = this.getCreation().getName();
427434

428-
for (Iterator<SSAInstruction> it = this.getEnclosingMethodIR(engine).iterateNormalInstructions(); it
429-
.hasNext();) {
435+
for (Iterator<SSAInstruction> it = enclosingMethodIR.iterateNormalInstructions(); it.hasNext();) {
430436
SSAInstruction instruction = it.next();
431437

432438
int lineNumberFromIR = getLineNumberFromIR(method, instruction);
@@ -515,7 +521,7 @@ public TypeReference getTypeReference() {
515521
}
516522

517523
private int getUseValueNumberForCreation(EclipseProjectAnalysisEngine<InstanceKey> engine)
518-
throws InvalidClassFileException, IOException, CoreException {
524+
throws InvalidClassFileException, IOException, CoreException, UnhandledCaseException {
519525
return getInstructionForCreation(engine).map(i -> i.getUse(0)).orElse(-1);
520526
}
521527

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

+6
Original file line numberDiff line numberDiff line change
@@ -1185,6 +1185,12 @@ private void fillInstanceToStreamMap(Set<Stream> streamSet, EclipseProjectAnalys
11851185
}
11861186
++skippedStreams;
11871187
continue; // next stream.
1188+
} catch (UnhandledCaseException e) {
1189+
String msg = "Encountered possible unhandled case (AIC #155) while processing: " + stream.getCreation();
1190+
LOGGER.log(Level.WARNING, msg, e);
1191+
stream.addStatusEntry(PreconditionFailure.CURRENTLY_NOT_HANDLED, msg);
1192+
++skippedStreams;
1193+
continue; // next stream.
11881194
}
11891195
instanceToStreamMap.put(instanceKey, stream);
11901196
} // end each stream.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package p;
2+
3+
import java.util.ArrayList;
4+
5+
import edu.cuny.hunter.streamrefactoring.annotations.EntryPoint;
6+
7+
class A {
8+
@EntryPoint
9+
void m() {
10+
new A() {
11+
@Override
12+
void m() {
13+
new ArrayList().stream().count();
14+
}
15+
};
16+
}
17+
}

edu.cuny.hunter.streamrefactoring.tests/resources/ConvertStreamToParallel/testArraysAsList/in/A.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@
77
class A {
88
@EntryPoint
99
void m() {
10-
Arrays.asList().stream();
10+
Arrays.asList().stream().count();
1111
}
1212
}

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

+22-4
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,10 @@ protected void tearDown() throws Exception {
348348
* Test #34.
349349
*/
350350
public void testArraysAsList() throws Exception {
351-
helper(new StreamAnalysisExpectedResult("Arrays.asList().stream()",
352-
Collections.singleton(ExecutionMode.SEQUENTIAL), Collections.singleton(Ordering.ORDERED), false, false,
353-
false, null, null, null, RefactoringStatus.ERROR,
354-
Collections.singleton(PreconditionFailure.NO_TERMINAL_OPERATIONS)));
351+
helper(new StreamAnalysisExpectedResult("Arrays.asList().stream()", EnumSet.of(ExecutionMode.SEQUENTIAL),
352+
EnumSet.of(Ordering.ORDERED), false, false, false, EnumSet.of(TransformationAction.CONVERT_TO_PARALLEL),
353+
PreconditionSuccess.P2, Refactoring.CONVERT_SEQUENTIAL_STREAM_TO_PARALLEL, RefactoringStatus.OK,
354+
Collections.emptySet()));
355355
}
356356

357357
/**
@@ -371,6 +371,24 @@ public void testConstructor() throws Exception {
371371
Refactoring.CONVERT_SEQUENTIAL_STREAM_TO_PARALLEL, RefactoringStatus.OK, Collections.emptySet()));
372372
}
373373

374+
/**
375+
* There is a problem between mapping methods declared within AICs from the
376+
* Eclipse DOM to the WALA DOM #155.
377+
*/
378+
public void testAnonymousInnerClass() throws Exception {
379+
boolean passed = false;
380+
try {
381+
helper(new StreamAnalysisExpectedResult("new ArrayList().stream()",
382+
Collections.singleton(ExecutionMode.SEQUENTIAL), EnumSet.of(Ordering.ORDERED), false, false, false,
383+
EnumSet.of(TransformationAction.CONVERT_TO_PARALLEL), PreconditionSuccess.P2,
384+
Refactoring.CONVERT_SEQUENTIAL_STREAM_TO_PARALLEL, RefactoringStatus.OK, Collections.emptySet()));
385+
} catch (NullPointerException e) {
386+
LOGGER.throwing(this.getClass().getName(), "testArraysAsList", e);
387+
passed = true;
388+
}
389+
assertTrue("Should throw exception per AIC issue.", passed);
390+
}
391+
374392
public void testBitSet() throws Exception {
375393
helper(new StreamAnalysisExpectedResult("set.stream()", Collections.singleton(ExecutionMode.SEQUENTIAL),
376394
Collections.singleton(Ordering.ORDERED), false, false, false,

0 commit comments

Comments
 (0)