Skip to content

Commit

Permalink
fix(FieldAccessTest): adapt FieldAccessTest to oracle jdk 11/jdt chan…
Browse files Browse the repository at this point in the history
…ges (#2789)

Related to adding a travis build with jdk 11 See #2782 

`CtFieldWrite.getTarget()` on `array.length` used to return a `CtVariableWrite` for some reasons... But with jdk 11 now returns  a `CtVariableRead`...

`FieldAccessTest#testFieldAccessOnUnknownType()` has been changed to handle both... by expecting a `CtVariableAccess`.

This (combined with #2787) fixes tests for jdk 11 as can be seen here ( https://travis-ci.org/INRIA/spoon/jobs/460289160 ).
Wether this is satisfaying or not, is up to debate. WDYT?
  • Loading branch information
nharrand authored and surli committed Dec 3, 2018
1 parent 829e91e commit ee5167e
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 14 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.core</artifactId>
<version>3.13.102</version>
<version>3.15.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
Expand Down Expand Up @@ -95,7 +95,7 @@
<artifactId>commons-lang3</artifactId>
<version>3.5</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.tukaani/xz -->
<!-- https://mvnrepository.com/artifact/org.tukaani/xz -->
<dependency>
<groupId>org.tukaani</groupId>
<artifactId>xz</artifactId>
Expand Down
10 changes: 5 additions & 5 deletions src/main/java/spoon/support/compiler/jdt/JDTBatchCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public JDTBatchCompiler(JDTBasedSpoonCompiler jdtCompiler) {
@Override
public CompilationUnit[] getCompilationUnits() {

Map<String, CompilationUnit> pathToModCU = new HashMap<>();
Map<String, char[]> pathToModName = new HashMap<>();

for (int round = 0; round < 2; round++) {
for (CompilationUnit compilationUnit : this.compilationUnits) {
Expand All @@ -94,21 +94,21 @@ public CompilationUnit[] getCompilationUnits() {
int lastSlash = CharOperation.lastIndexOf(File.separatorChar, charName);
if (lastSlash != -1) {
char[] modulePath = CharOperation.subarray(charName, 0, lastSlash);
pathToModCU.put(String.valueOf(modulePath), compilationUnit);

lastSlash = CharOperation.lastIndexOf(File.separatorChar, modulePath);
if (lastSlash == -1) {
lastSlash = 0;
} else {
lastSlash += 1;
}

//TODO the module name parsed by JDK compiler is in `this.modNames`
compilationUnit.module = CharOperation.subarray(modulePath, lastSlash, modulePath.length);
pathToModName.put(String.valueOf(modulePath), compilationUnit.module);
}
} else {
for (Map.Entry<String, CompilationUnit> entry : pathToModCU.entrySet()) {
for (Map.Entry<String, char[]> entry : pathToModName.entrySet()) {
if (fileName.startsWith(entry.getKey())) { // associate CUs to module by common prefix
compilationUnit.setModule(entry.getValue());
compilationUnit.module = entry.getValue();
break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/spoon/test/fieldaccesses/FieldAccessTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -388,8 +388,8 @@ class CounterScanner extends CtScanner {
@Override
public <T> void visitCtFieldWrite(CtFieldWrite<T> fieldWrite) {
visited++;
assertEquals("array", ((CtVariableWrite) fieldWrite.getTarget()).getVariable().getSimpleName());
assertEquals("length", fieldWrite.getVariable().getSimpleName());
assertEquals("a", ((CtVariableWrite) fieldWrite.getTarget()).getVariable().getSimpleName());
assertEquals("l", fieldWrite.getVariable().getSimpleName());
}
}

Expand Down
11 changes: 8 additions & 3 deletions src/test/java/spoon/test/type/TypeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,14 @@ public void testIntersectionTypeReferenceInGenericsAndCasts() {
assertEquals(1, lambdas.get(0).getTypeCasts().size());
assertTrue(lambdas.get(0).getTypeCasts().get(0) instanceof CtIntersectionTypeReference);
final CtIntersectionTypeReference<?> intersectionType = lambdas.get(0).getTypeCasts().get(0).asCtIntersectionTypeReference();
assertEquals("java.lang.Runnable & java.io.Serializable", intersectionType.toString());
assertEquals(aPozole.getFactory().Type().createReference(Runnable.class), intersectionType.getBounds().stream().collect(Collectors.toList()).get(0));
assertEquals(aPozole.getFactory().Type().createReference(Serializable.class), intersectionType.getBounds().stream().collect(Collectors.toList()).get(1));
assertTrue(intersectionType.toString().contains("java.lang.Runnable")
&& intersectionType.toString().contains("java.io.Serializable"));
CtTypeReference refRunnable = aPozole.getFactory().Type().createReference(Runnable.class);
CtTypeReference refSerializable = aPozole.getFactory().Type().createReference(Serializable.class);
CtTypeReference ref0 = intersectionType.getBounds().stream().collect(Collectors.toList()).get(0);
CtTypeReference ref1 = intersectionType.getBounds().stream().collect(Collectors.toList()).get(1);
assertTrue((ref0.equals(refRunnable) || ref0.equals(refSerializable))
&& (ref1.equals(refRunnable) || ref1.equals(refSerializable)));

canBeBuilt(target, 8, true);
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/resources/noclasspath/FieldAccessRes.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
public class FieldAccessRes {

void method() {
A [] array = new A[10];
array.length = 5;
A a = new A();
a.l = 5;
}

}

0 comments on commit ee5167e

Please sign in to comment.