From 77c89d580d034571347b1897a770906ccbbd9f46 Mon Sep 17 00:00:00 2001 From: Martin Monperrus Date: Wed, 7 Dec 2016 20:57:26 +0100 Subject: [PATCH] fix(ThisAccess): shorter this access --- .../generating/replace/ReplaceScanner.java | 7 ++ .../visitor/DefaultJavaPrettyPrinter.java | 103 ++++++++++-------- .../reflect/visitor/PrintingContext.java | 14 +-- .../visitor/printer/PrinterHelper.java | 11 ++ .../reflect/declaration/CtEnumImpl.java | 5 +- .../reflect/declaration/CtTypeImpl.java | 4 +- .../java/spoon/test/comment/CommentTest.java | 8 +- src/test/java/spoon/test/field/FieldTest.java | 17 ++- .../test/field/testclasses/AddFieldAtTop.java | 7 ++ .../spoon/test/generics/GenericsTest.java | 6 +- src/test/java/spoon/test/loop/LoopTest.java | 2 +- .../DefaultPrettyPrinterTest.java | 11 -- .../prettyprinter/QualifiedThisRefTest.java | 15 +-- .../testclasses/QualifiedThisRef.java | 3 + .../spoon/test/signature/SignatureTest.java | 4 +- .../test/targeted/TargetedExpressionTest.java | 50 ++++----- .../java/spoon/test/variable/AccessTest.java | 2 +- .../resources/expected/AddFieldAtTop.java | 16 --- 18 files changed, 150 insertions(+), 135 deletions(-) delete mode 100644 src/test/resources/expected/AddFieldAtTop.java diff --git a/src/main/java/spoon/generating/replace/ReplaceScanner.java b/src/main/java/spoon/generating/replace/ReplaceScanner.java index 1dcca04be14..37439a928dc 100644 --- a/src/main/java/spoon/generating/replace/ReplaceScanner.java +++ b/src/main/java/spoon/generating/replace/ReplaceScanner.java @@ -18,11 +18,15 @@ import spoon.SpoonException; import spoon.generating.ReplacementVisitorGenerator; +import spoon.reflect.code.CtAssignment; import spoon.reflect.code.CtBlock; import spoon.reflect.code.CtComment; import spoon.reflect.code.CtConstructorCall; import spoon.reflect.code.CtExpression; +import spoon.reflect.code.CtFieldAccess; import spoon.reflect.code.CtInvocation; +import spoon.reflect.code.CtThisAccess; +import spoon.reflect.code.CtTypeAccess; import spoon.reflect.declaration.CtClass; import spoon.reflect.declaration.CtConstructor; import spoon.reflect.declaration.CtField; @@ -187,6 +191,9 @@ public boolean matches(CtTypeReference reference) { private CtParameter updateConstructor(CtClass listener, CtTypeReference type) { final CtConstructor ctConstructor = (CtConstructor) listener.getConstructors().toArray(new CtConstructor[listener.getConstructors().size()])[0]; + CtAssignment assign = (CtAssignment) ctConstructor.getBody().getStatement(1); + CtThisAccess fieldAccess = (CtThisAccess) ((CtFieldAccess) assign.getAssigned()).getTarget(); + ((CtTypeAccess) fieldAccess.getTarget()).getAccessedType().setImplicit(true); final CtParameter aParameter = (CtParameter) ctConstructor.getParameters().get(0); aParameter.setType(type); return aParameter; diff --git a/src/main/java/spoon/reflect/visitor/DefaultJavaPrettyPrinter.java b/src/main/java/spoon/reflect/visitor/DefaultJavaPrettyPrinter.java index aba4b419d65..659cbe502aa 100644 --- a/src/main/java/spoon/reflect/visitor/DefaultJavaPrettyPrinter.java +++ b/src/main/java/spoon/reflect/visitor/DefaultJavaPrettyPrinter.java @@ -477,7 +477,6 @@ public void visitCtCatch(CtCatch catchBlock) { @Override public void visitCtClass(CtClass ctClass) { context.pushCurrentThis(ctClass); - if (ctClass.getSimpleName() != null && !CtType.NAME_UNKNOWN.equals(ctClass.getSimpleName()) && !ctClass.isAnonymous()) { visitCtType(ctClass); if (ctClass.isLocalType()) { @@ -682,8 +681,9 @@ private void printCtFieldAccess(CtFieldAccess f) { } if (f.getTarget() != null) { if (!isInitializeStaticFinalField(f.getTarget())) { + printer.snapshotLength(); scan(f.getTarget()); - if (!f.getTarget().isImplicit()) { + if (printer.hasNewContent()) { printer.write("."); } } @@ -719,45 +719,50 @@ private boolean isInitializeStaticFinalField(CtExpression targetExp) { @Override public void visitCtThisAccess(CtThisAccess thisAccess) { - enterCtExpression(thisAccess); - if (thisAccess.getTarget() != null && thisAccess.getTarget() instanceof CtTypeAccess - && !tryToInitializeFinalFieldInConstructor(thisAccess) - && !thisAccess.isImplicit() - && !thisAccess.getTarget().isImplicit()) { - final CtTypeReference accessedType = ((CtTypeAccess) thisAccess.getTarget()).getAccessedType(); - if (accessedType.isLocalType()) { - printer.write(accessedType.getSimpleName().replaceAll("^[0-9]*", "") + "."); - } else if (!accessedType.isAnonymous()) { - visitCtTypeReferenceWithoutGenerics(accessedType); - printer.write("."); + try { + enterCtExpression(thisAccess); + + // we only write qualified this when this is required + // this is good both in fully-qualified mode and in readable (with-imports) mode + // the implicit information is used for analysis (eg are visibility caused by implicit bugs?) but + // not for pretty-printing + CtTypeAccess target = (CtTypeAccess) thisAccess.getTarget(); + CtTypeReference targetType = target.getAccessedType(); + + // readable mode as close as possible to the original code + if (thisAccess.isImplicit()) { + // write nothing, "this" is implicit and we unfortunately cannot always know + // what the good target is in JDTTreeBuilder + return; } - } - if (!thisAccess.isImplicit()) { - printer.write("this"); - } - exitCtExpression(thisAccess); - } - /** - * Check if the this access expression is a target of a private final field in a constructor. - */ - private boolean tryToInitializeFinalFieldInConstructor(CtThisAccess thisAccess) { - try { - final CtElement parent = thisAccess.getParent(); - if (!(parent instanceof CtFieldWrite) || !thisAccess.equals(((CtFieldWrite) parent).getTarget()) || thisAccess.getParent(CtConstructor.class) == null) { - return false; + // the simplest case: we always print "this" if we're in the top-level class, + // this is shorter (no qualified this), explicit, and less fragile wrt transformation + if (targetType == null || (thisAccess.getParent(CtType.class) != null && thisAccess.getParent(CtType.class).isTopLevel())) { + printer.write("this"); + return; // still go through finally block below } - final CtFieldReference variable = ((CtFieldWrite) parent).getVariable(); - if (variable == null) { - return false; + + // we cannot have fully-qualified this in anonymous classes + // we simply print "this" and it always works + // this has to come after the implicit test just before + if (targetType.isAnonymous()) { + printer.write("this"); + return; } - final CtField declaration = variable.getDeclaration(); - if (declaration == null) { - return true; + + // complex case of qualifed this + if (context.currentThis.peekLast() != null + && !context.currentThis.peekLast().type.getQualifiedName().equals(targetType.getQualifiedName())) { + visitCtTypeReferenceWithoutGenerics(targetType); + printer.write(".this"); + return; } - return declaration.getModifiers().contains(ModifierKind.FINAL); - } catch (ParentNotInitializedException e) { - return false; + + // the default super simple case only comes at the end + printer.write("this"); + } finally { + exitCtExpression(thisAccess); } } @@ -855,7 +860,7 @@ public void visitCtFieldReference(CtFieldReference reference) { if (reference.isFinal() && reference.isStatic()) { CtTypeReference declTypeRef = reference.getDeclaringType(); - if ("".equals(declTypeRef.getSimpleName())) { + if (declTypeRef.isAnonymous()) { //never print anonymous class ref printType = false; } else { @@ -980,25 +985,26 @@ public void visitCtInvocation(CtInvocation invocation) { if (parentType != null && parentType.getQualifiedName() != null && parentType.getQualifiedName().equals(invocation.getExecutable().getDeclaringType().getQualifiedName())) { printer.write("this"); } else { - if (invocation.getTarget() != null) { - scan(invocation.getTarget()); + printer.snapshotLength(); + scan(invocation.getTarget()); + if (printer.hasNewContent()) { printer.write("."); } printer.write("super"); } } else { // It's a method invocation - if (invocation.getTarget() != null) { - try (Writable _context = context.modify()) { - if (invocation.getTarget() instanceof CtTypeAccess) { - _context.ignoreGenerics(true); - } - scan(invocation.getTarget()); - } - if (!invocation.getTarget().isImplicit()) { - printer.write("."); + printer.snapshotLength(); + try (Writable _context = context.modify()) { + if (invocation.getTarget() instanceof CtTypeAccess) { + _context.ignoreGenerics(true); } + scan(invocation.getTarget()); } + if (printer.hasNewContent()) { + printer.write("."); + } + elementPrinterHelper.writeActualTypeArguments(invocation); if (env.isPreserveLineNumbers()) { printer.adjustPosition(invocation, sourceCompilationUnit); @@ -1708,6 +1714,7 @@ public String getResult() { public void reset() { printer = new PrinterHelper(env); elementPrinterHelper.setPrinter(printer); + context = new PrintingContext(); } @Override diff --git a/src/main/java/spoon/reflect/visitor/PrintingContext.java b/src/main/java/spoon/reflect/visitor/PrintingContext.java index 5ef588a86ef..ef041c05e24 100644 --- a/src/main/java/spoon/reflect/visitor/PrintingContext.java +++ b/src/main/java/spoon/reflect/visitor/PrintingContext.java @@ -16,16 +16,14 @@ */ package spoon.reflect.visitor; -import java.util.ArrayDeque; -import java.util.ArrayList; -import java.util.Deque; -import java.util.List; - import spoon.reflect.code.CtExpression; import spoon.reflect.declaration.CtElement; import spoon.reflect.declaration.CtType; import spoon.reflect.reference.CtTypeReference; +import java.util.ArrayDeque; +import java.util.Deque; + public class PrintingContext { private long NO_TYPE_DECL = 1 << 0; @@ -92,7 +90,7 @@ public Writable modify() { return new Writable(); } - List currentThis = new ArrayList<>(); + Deque currentThis = new ArrayDeque<>(); /** * @return top level type @@ -109,7 +107,7 @@ public CtTypeReference getCurrentTypeReference() { } private TypeContext getCurrentTypeContext() { if (currentThis != null && currentThis.size() > 0) { - TypeContext tc = currentThis.get(currentThis.size() - 1); + TypeContext tc = currentThis.peek(); return tc; } return null; @@ -119,7 +117,7 @@ public void pushCurrentThis(CtType type) { currentThis.add(new TypeContext(type)); } public void popCurrentThis() { - currentThis.remove(currentThis.size() - 1); + currentThis.pop(); } diff --git a/src/main/java/spoon/reflect/visitor/printer/PrinterHelper.java b/src/main/java/spoon/reflect/visitor/printer/PrinterHelper.java index a454c6af819..fe602ab45d0 100644 --- a/src/main/java/spoon/reflect/visitor/printer/PrinterHelper.java +++ b/src/main/java/spoon/reflect/visitor/printer/PrinterHelper.java @@ -23,6 +23,7 @@ import spoon.reflect.cu.CompilationUnit; import spoon.reflect.declaration.CtElement; +import java.util.ArrayDeque; import java.util.HashMap; import java.util.Map; @@ -389,4 +390,14 @@ public Map getLineNumberMapping() { public String toString() { return sbf.toString(); } + + private ArrayDeque lengths = new ArrayDeque<>(); + /** stores the length of the printer */ + public void snapshotLength() { + lengths.addLast(toString().length()); + } + /** returns true if something has been written since the last call to snapshotLength() */ + public boolean hasNewContent() { + return lengths.pollLast() < toString().length(); + } } diff --git a/src/main/java/spoon/support/reflect/declaration/CtEnumImpl.java b/src/main/java/spoon/support/reflect/declaration/CtEnumImpl.java index ac13c2944d8..fe363e990bd 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtEnumImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtEnumImpl.java @@ -23,13 +23,12 @@ import spoon.reflect.declaration.ModifierKind; import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtVisitor; -import spoon.support.comparator.SignatureComparator; +import spoon.support.util.SignatureBasedSortedSet; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Set; -import java.util.TreeSet; public class CtEnumImpl> extends CtClassImpl implements CtEnum { private static final long serialVersionUID = 1L; @@ -47,7 +46,7 @@ public void accept(CtVisitor visitor) { @Override public Set> getAllMethods() { - Set> allMethods = new TreeSet<>(new SignatureComparator()); + Set> allMethods = new SignatureBasedSortedSet(); allMethods.addAll(getMethods()); allMethods.addAll(getFactory().Type().get(Enum.class).getMethods()); allMethods.add(valuesMethod()); diff --git a/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java b/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java index 198abbf3d67..2279f49588b 100644 --- a/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java +++ b/src/main/java/spoon/support/reflect/declaration/CtTypeImpl.java @@ -46,7 +46,6 @@ import spoon.reflect.visitor.filter.ReferenceTypeFilter; import spoon.support.UnsettableProperty; import spoon.support.SpoonClassNotFoundException; -import spoon.support.comparator.SignatureComparator; import spoon.support.compiler.SnippetCompilationHelper; import spoon.support.util.QualifiedNameBasedSortedSet; import spoon.support.util.SignatureBasedSortedSet; @@ -59,7 +58,6 @@ import java.util.EnumSet; import java.util.List; import java.util.Set; -import java.util.TreeSet; import static spoon.reflect.ModelElementContainerDefaultCapacities.TYPE_TYPE_PARAMETERS_CONTAINER_DEFAULT_CAPACITY; @@ -884,7 +882,7 @@ public Collection> getDeclaredExecutables() { @Override public Collection> getAllExecutables() { - Set> l = new TreeSet(new SignatureComparator()); + Set> l = new SignatureBasedSortedSet(); for (CtMethod m : getAllMethods()) { l.add((CtExecutableReference) m.getReference()); } diff --git a/src/test/java/spoon/test/comment/CommentTest.java b/src/test/java/spoon/test/comment/CommentTest.java index 475c6bd6090..5f39704ed97 100644 --- a/src/test/java/spoon/test/comment/CommentTest.java +++ b/src/test/java/spoon/test/comment/CommentTest.java @@ -198,7 +198,7 @@ public void testInLineComment() { CtInvocation ctInvocation = m1.getBody().getStatement(4); assertEquals(createFakeComment(f, "comment invocation"), ctInvocation.getComments().get(0)); assertEquals("// comment invocation" + newLine - + "spoon.test.comment.testclasses.InlineComment.this.m()", ctInvocation.toString()); + + "this.m()", ctInvocation.toString()); CtLocalVariable ctLocalVariable = m1.getBody().getStatement(5); assertEquals(createFakeComment(f, "comment local variable"), ctLocalVariable.getComments().get(0)); @@ -232,7 +232,7 @@ public void testInLineComment() { CtSynchronized ctSynchronized = m1.getBody().getStatement(9); assertEquals(createFakeComment(f, "comment synchronized"), ctSynchronized.getComments().get(0)); assertEquals("// comment synchronized" + newLine - + "synchronized(spoon.test.comment.testclasses.InlineComment.this) {" + newLine + + "synchronized(this) {" + newLine + " // comment in synchronized" + newLine + "}", ctSynchronized.toString()); @@ -378,7 +378,7 @@ public void testBlockComment() { CtInvocation ctInvocation = m1.getBody().getStatement(4); assertEquals(createFakeBlockComment(f, "comment invocation"), ctInvocation.getComments().get(0)); assertEquals("/* comment invocation */" + newLine - + "spoon.test.comment.testclasses.BlockComment.this.m()", ctInvocation.toString()); + + "this.m()", ctInvocation.toString()); CtLocalVariable ctLocalVariable = m1.getBody().getStatement(5); assertEquals(createFakeBlockComment(f, "comment local variable"), ctLocalVariable.getComments().get(0)); @@ -412,7 +412,7 @@ public void testBlockComment() { CtSynchronized ctSynchronized = m1.getBody().getStatement(9); assertEquals(createFakeBlockComment(f, "comment synchronized"), ctSynchronized.getComments().get(0)); assertEquals("/* comment synchronized */" + newLine - + "synchronized(spoon.test.comment.testclasses.BlockComment.this) {" + newLine + + "synchronized(this) {" + newLine + " /* comment in synchronized */" + newLine + "}", ctSynchronized.toString()); diff --git a/src/test/java/spoon/test/field/FieldTest.java b/src/test/java/spoon/test/field/FieldTest.java index fae127110ec..f9f957fa634 100644 --- a/src/test/java/spoon/test/field/FieldTest.java +++ b/src/test/java/spoon/test/field/FieldTest.java @@ -18,6 +18,7 @@ package spoon.test.field; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; import static spoon.testing.Assert.assertThat; import static spoon.testing.utils.ModelUtils.build; import static spoon.testing.utils.ModelUtils.buildClass; @@ -25,13 +26,16 @@ import java.io.File; import java.util.HashSet; +import java.util.List; import org.junit.Test; +import spoon.reflect.code.CtFieldRead; import spoon.reflect.declaration.CtClass; import spoon.reflect.declaration.CtField; import spoon.reflect.declaration.ModifierKind; import spoon.reflect.factory.Factory; +import spoon.reflect.visitor.filter.TypeFilter; import spoon.test.field.testclasses.AddFieldAtTop; public class FieldTest { @@ -76,8 +80,19 @@ public void testAddFieldsAtTop() throws Exception { assertEquals(generated2, aClass.getTypeMembers().get(0)); assertEquals(generated, aClass.getTypeMembers().get(1)); assertEquals(aClass.getAnonymousExecutables().get(0), aClass.getTypeMembers().get(3)); + } + + @Test + public void testFieldImplicitTarget() throws Exception { + // contract: no "." when target is implicit + final CtClass aClass = (CtClass) buildClass(AddFieldAtTop.class); - assertThat(aClass).isEqualTo(build(new File("./src/test/resources/expected/AddFieldAtTop.java")).Type().get("AddFieldAtTop")); + List fieldReads = aClass.getElements(new TypeFilter<>(CtFieldRead.class)); + assertEquals(1, fieldReads.size()); + assertEquals("i", fieldReads.get(0).toString()); + fieldReads.get(0).getTarget().setImplicit(false); + assertEquals(false, fieldReads.get(0).getTarget().isImplicit()); + assertEquals("this.i", fieldReads.get(0).toString()); } private CtField createField(Factory factory, HashSet modifiers, String name) { diff --git a/src/test/java/spoon/test/field/testclasses/AddFieldAtTop.java b/src/test/java/spoon/test/field/testclasses/AddFieldAtTop.java index 7534cdd138f..9c777b89b5f 100644 --- a/src/test/java/spoon/test/field/testclasses/AddFieldAtTop.java +++ b/src/test/java/spoon/test/field/testclasses/AddFieldAtTop.java @@ -9,4 +9,11 @@ public class AddFieldAtTop { void m() { } + + class Foo { + int i; + void m() { + int x = i; + } + } } diff --git a/src/test/java/spoon/test/generics/GenericsTest.java b/src/test/java/spoon/test/generics/GenericsTest.java index fb5ca8a3b42..6beb8c6a4a7 100644 --- a/src/test/java/spoon/test/generics/GenericsTest.java +++ b/src/test/java/spoon/test/generics/GenericsTest.java @@ -85,7 +85,7 @@ public void testModelBuildingTree() throws Exception { CtMethod node5 = type.getElements( new NameFilter>("node5")).get(0); assertEquals( - "spoon.test.generics.Tree.this.>foo()", + "this.>foo()", node5.getBody().getStatement(0).toString()); } @@ -368,11 +368,11 @@ public void testInvocationGenerics() throws Exception { final CtMethod m = aTacos.getMethodsByName("m2").get(0); final CtInvocation invocation1 = m.getBody().getStatement(0).getElements(new TypeFilter<>(CtInvocation.class)).get(0); assertEquals(1, invocation1.getExecutable().getActualTypeArguments().size()); - assertEquals("spoon.test.generics.testclasses.Tacos.this.makeTacos(null)", invocation1.toString()); + assertEquals("this.makeTacos(null)", invocation1.toString()); final CtInvocation invocation2 = m.getBody().getStatement(1).getElements(new TypeFilter<>(CtInvocation.class)).get(0); assertEquals(0, invocation2.getExecutable().getActualTypeArguments().size()); - assertEquals("spoon.test.generics.testclasses.Tacos.this.makeTacos(null)", invocation2.toString()); + assertEquals("this.makeTacos(null)", invocation2.toString()); canBeBuilt("./target/spooned/spoon/test/generics/testclasses/", 8); } diff --git a/src/test/java/spoon/test/loop/LoopTest.java b/src/test/java/spoon/test/loop/LoopTest.java index 67a35e3330f..b20aabd6687 100644 --- a/src/test/java/spoon/test/loop/LoopTest.java +++ b/src/test/java/spoon/test/loop/LoopTest.java @@ -43,7 +43,7 @@ public void testForeachShouldHaveAlwaysABlockInItsBody() throws Exception { assertTrue(ctLoop.getBody() instanceof CtBlock); String expected = // "for (spoon.test.loop.testclasses.Condition condition : conditions)" + nl // - + " spoon.test.loop.testclasses.Join.this.conditions.add(spoon.test.loop.testclasses.Join.notNull(condition));" + nl; + + " this.conditions.add(spoon.test.loop.testclasses.Join.notNull(condition));" + nl; assertEquals(expected, ctLoop.toString()); } } diff --git a/src/test/java/spoon/test/prettyprinter/DefaultPrettyPrinterTest.java b/src/test/java/spoon/test/prettyprinter/DefaultPrettyPrinterTest.java index e6f290af647..dd89f331cd6 100644 --- a/src/test/java/spoon/test/prettyprinter/DefaultPrettyPrinterTest.java +++ b/src/test/java/spoon/test/prettyprinter/DefaultPrettyPrinterTest.java @@ -175,11 +175,6 @@ public void autoImportUsesFullyQualifiedNameWhenImportedNameAlreadyPresent() thr String computed = aClass.getMethodsByName("setFieldUsingExternallyDefinedEnumWithSameNameAsLocal").get(0).toString(); assertEquals( "the externally defined enum should be fully qualified to avoid a name clash with the local enum of the same name", expected, computed ); - expected = //This is what is expected - "public void setFieldUsingLocallyDefinedEnum() {" +nl+ - " localField = ENUM.E1.ordinal();" +nl+ - "}" - ; expected = //This is correct however it could be more concise. "public void setFieldUsingLocallyDefinedEnum() {" +nl+ " localField = TypeIdentifierCollision.ENUM.E1.ordinal();" +nl+ @@ -196,12 +191,6 @@ public void autoImportUsesFullyQualifiedNameWhenImportedNameAlreadyPresent() thr computed = aClass.getMethodsByName("setFieldOfClassWithSameNameAsTheCompilationUnitClass").get(0).toString(); assertEquals( "The static field of an external type with the same identifier as the compilation unit should be fully qualified", expected, computed ); - expected = //This is what is expected - "public void referToTwoInnerClassesWithTheSameName() {" +nl+ - " ClassA.VAR0 = ClassA.getNum();" +nl+ - " Class1.ClassA.VAR1 = Class1.ClassA.getNum();" +nl+ - "}" - ; expected = //This is correct however it could be more concise. "public void referToTwoInnerClassesWithTheSameName() {" +nl+ " TypeIdentifierCollision.Class0.ClassA.VAR0 = TypeIdentifierCollision.Class0.ClassA.getNum();" +nl+ diff --git a/src/test/java/spoon/test/prettyprinter/QualifiedThisRefTest.java b/src/test/java/spoon/test/prettyprinter/QualifiedThisRefTest.java index 6094796af3d..a97bd67d958 100644 --- a/src/test/java/spoon/test/prettyprinter/QualifiedThisRefTest.java +++ b/src/test/java/spoon/test/prettyprinter/QualifiedThisRefTest.java @@ -23,6 +23,7 @@ import java.util.Collection; import java.util.List; +import static javax.swing.text.html.HTML.Tag.HEAD; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; @@ -55,7 +56,8 @@ public void testQualifiedThisRef() { ctTypes.add(ctClass); printer.getElementPrinterHelper().writeHeader(ctTypes, imports); printer.scan(ctClass); - assertTrue(printer.getResult().contains("Object o = QualifiedThisRef.Sub.this")); + Assert.assertTrue(printer.getResult().contains("Object o = this")); + Assert.assertTrue(printer.getResult().contains("Object o2 = QualifiedThisRef.this")); } @Test @@ -68,15 +70,10 @@ public void testCloneThisAccess() throws Exception { CtThisAccess th = (CtThisAccess) m2.getElements(new TypeFilter(CtThisAccess.class)).get(0); assertEquals(true,th.isImplicit()); assertEquals("notify()",th.getParent().toString()); - assertEquals("spoon.test.delete.testclasses.Adobada", ((CtTypeAccess)th.getTarget()).getAccessedType().toString()); - CtMethod clone = m2.clone(); - CtInvocation stat = clone.getBody().getStatement(0); - assertNotEquals("java.lang.Object.this.notify()", stat.toString()); // the original bug + CtInvocation clone = m2.clone().getBody().getStatement(0); // clone preserves implicitness - assertTrue(stat.getTarget().isImplicit()); - assertEquals("notify()", stat.toString()); - stat.getTarget().setImplicit(false); - assertEquals("spoon.test.delete.testclasses.Adobada.this.notify()", stat.toString()); + assertEquals(true, clone.getTarget().isImplicit()); + assertEquals("notify()", clone.toString()); // the original bug // note that this behavior means that you can only keep cloned "this" in the same class, // and you cannot "transplant" a cloned "this" to another class diff --git a/src/test/java/spoon/test/prettyprinter/testclasses/QualifiedThisRef.java b/src/test/java/spoon/test/prettyprinter/testclasses/QualifiedThisRef.java index f4e5b15d6fe..2854350b316 100644 --- a/src/test/java/spoon/test/prettyprinter/testclasses/QualifiedThisRef.java +++ b/src/test/java/spoon/test/prettyprinter/testclasses/QualifiedThisRef.java @@ -6,5 +6,8 @@ class Sub { void foo() { Object o = spoon.test.prettyprinter.testclasses.QualifiedThisRef.Sub.this; } + void foo2() { + Object o2 = spoon.test.prettyprinter.testclasses.QualifiedThisRef.this; + } } } diff --git a/src/test/java/spoon/test/signature/SignatureTest.java b/src/test/java/spoon/test/signature/SignatureTest.java index 208ccae8452..24e63d48b39 100644 --- a/src/test/java/spoon/test/signature/SignatureTest.java +++ b/src/test/java/spoon/test/signature/SignatureTest.java @@ -282,9 +282,9 @@ public void testUnboundFieldSignature(){ CtAssignment invoToInt1 = (CtAssignment) methodString.getBody().getStatement(0); CtExpression left = invoToInt1.getAssigned(); - assertEquals("PR.this.mfield",left.toString()); + assertEquals("this.mfield",left.toString()); assertEquals(null,left.getType());// null because noclasspath - assertEquals("PR.this.mfield = p",invoToInt1.toString()); + assertEquals("this.mfield = p",invoToInt1.toString()); } diff --git a/src/test/java/spoon/test/targeted/TargetedExpressionTest.java b/src/test/java/spoon/test/targeted/TargetedExpressionTest.java index f7417381557..6423451fefa 100644 --- a/src/test/java/spoon/test/targeted/TargetedExpressionTest.java +++ b/src/test/java/spoon/test/targeted/TargetedExpressionTest.java @@ -72,7 +72,7 @@ public void testCtThisAccess() throws Exception { CtMethod meth1 = type.getElements(new NameFilter>("method2")).get(0); assertEquals( - "spoon.test.targeted.testclasses.InnerClassThisAccess.this.method()", + "this.method()", meth1.getBody().getStatements().get(0).toString()); CtClass c = type.getElements(new NameFilter>("1InnerClass")).get(0); @@ -103,7 +103,7 @@ public void testNotTargetedExpression() throws Exception { CtFieldAccess fieldAccess = factory.Core().createFieldRead(); fieldAccess.setVariable((CtFieldReference) iField.getReference()); fieldAccess.setTarget(factory.Code().createThisAccess(fooClass.getReference())); - assertEquals("spoon.test.targeted.testclasses.Foo.this.i", fieldAccess.toString()); + assertEquals("this.i", fieldAccess.toString()); // this test is made for this line. Check that we can setTarget(null) // without NPE fieldAccess.setTarget(null); @@ -135,13 +135,13 @@ public void testTargetsOfFieldAccess() throws Exception { final List> elements = fieldMethod.getElements(new TypeFilter>(CtFieldAccess.class)); assertEquals(10, elements.size()); - assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedType).target(expectedThisAccess).result("spoon.test.targeted.testclasses.Foo.this.i"), elements.get(0)); + assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedType).target(expectedThisAccess).result("this.i"), elements.get(0)); assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedType).target(expectedThisAccess).result("i"), elements.get(1)); - assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedBarType).target(elements.get(3)).result("spoon.test.targeted.testclasses.Foo.this.bar.i"), elements.get(2)); - assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedType).target(expectedThisAccess).result("spoon.test.targeted.testclasses.Foo.this.bar"), elements.get(3)); + assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedBarType).target(elements.get(3)).result("this.bar.i"), elements.get(2)); + assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedType).target(expectedThisAccess).result("this.bar"), elements.get(3)); assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedBarType).target(elements.get(5)).result("bar.i"), elements.get(4)); assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedType).target(expectedThisAccess).result("bar"), elements.get(5)); - assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedSuperClassType).target(expectedThisAccess).result("spoon.test.targeted.testclasses.Foo.this.o"), elements.get(6)); + assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedSuperClassType).target(expectedThisAccess).result("this.o"), elements.get(6)); assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedSuperClassType).target(expectedThisAccess).result("o"), elements.get(7)); assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedFuuType).target(elements.get(9)).result("fuu.p"), elements.get(8)); assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedType).target(expectedThisAccess).result("fuu"), elements.get(9)); @@ -161,10 +161,10 @@ public void testTargetsOfStaticFieldAccess() throws Exception { final List> elements = constructor.getElements(new TypeFilter>(CtFieldAccess.class)); assertEquals(10, elements.size()); - assertEqualsFieldAccess(new ExpectedTargetedExpression().type(CtFieldRead.class).declaringType(expectedType).target(expectedThisAccess).result("spoon.test.targeted.testclasses.Foo.this.k"), elements.get(0)); + assertEqualsFieldAccess(new ExpectedTargetedExpression().type(CtFieldRead.class).declaringType(expectedType).target(expectedThisAccess).result("this.k"), elements.get(0)); assertEqualsFieldAccess(new ExpectedTargetedExpression().type(CtFieldRead.class).declaringType(expectedType).target(expectedTypeAccess).result("spoon.test.targeted.testclasses.Foo.k"), elements.get(1)); assertEqualsFieldAccess(new ExpectedTargetedExpression().type(CtFieldRead.class).declaringType(expectedType).target(expectedTypeAccess).result("spoon.test.targeted.testclasses.Foo.k"), elements.get(2)); - assertEqualsFieldAccess(new ExpectedTargetedExpression().type(CtFieldWrite.class).declaringType(expectedType).target(expectedThisAccess).result("spoon.test.targeted.testclasses.Foo.this.k"), elements.get(3)); + assertEqualsFieldAccess(new ExpectedTargetedExpression().type(CtFieldWrite.class).declaringType(expectedType).target(expectedThisAccess).result("this.k"), elements.get(3)); assertEqualsFieldAccess(new ExpectedTargetedExpression().type(CtFieldWrite.class).declaringType(expectedType).target(expectedTypeAccess).result("spoon.test.targeted.testclasses.Foo.k"), elements.get(4)); assertEqualsFieldAccess(new ExpectedTargetedExpression().type(CtFieldWrite.class).declaringType(expectedType).target(expectedTypeAccess).result("spoon.test.targeted.testclasses.Foo.k"), elements.get(5)); assertEqualsFieldAccess(new ExpectedTargetedExpression().type(CtFieldRead.class).declaringType(expectedBarType).target(expectedBarTypeAccess).result("spoon.test.targeted.testclasses.Bar.FIELD"), elements.get(6)); @@ -197,16 +197,17 @@ public void testTargetsOfFieldAccessInInnerClass() throws Exception { final CtMethod innerInvMethod = innerClass.getMethodsByName("innerField").get(0); final List> elements = innerInvMethod.getElements(new TypeFilter<>(CtFieldAccess.class)); assertEquals(6, elements.size()); - assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedInnerClass).target(expectedInnerClassAccess).result("spoon.test.targeted.testclasses.Foo.InnerClass.this.i"), elements.get(0)); + assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedInnerClass).target(expectedInnerClassAccess).result("this.i"), elements.get(0)); assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedInnerClass).target(expectedInnerClassAccess).result("i"), elements.get(1)); - assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedType).target(expectedThisAccess).result("spoon.test.targeted.testclasses.Foo.this.i"), elements.get(2)); + assertEquals(true, elements.get(1).getTarget().isImplicit()); + assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedType).target(expectedThisAccess).result("this.i"), elements.get(2)); assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedType).target(fooTypeAccess).result("spoon.test.targeted.testclasses.Foo.k"), elements.get(3)); - assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedSuperClassType).target(expectedThisAccess).result("spoon.test.targeted.testclasses.Foo.this.o"), elements.get(4)); + assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedSuperClassType).target(expectedThisAccess).result("this.o"), elements.get(4)); assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedSuperClassType).target(expectedThisAccess).result("o"), elements.get(5)); final List> newElements = nestedTypeScanner.getMethodsByName("checkField").get(0).getElements(new TypeFilter<>(CtFieldAccess.class)); assertEquals(2, newElements.size()); - assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedNested).target(expectedNestedAccess).result("NestedTypeScanner.this.type").isLocal(), newElements.get(0)); + assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedNested).target(expectedNestedAccess).result("this.type").isLocal(), newElements.get(0)); assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedNested).target(expectedNestedAccess).result("type").isLocal(), newElements.get(1)); } @@ -228,7 +229,7 @@ public boolean matches(CtClass element) { final CtMethod method = anonymousClass.getMethodsByName("invStatic").get(0); final List elements = method.getElements(new TypeFilter<>(CtFieldAccess.class)); assertEquals(3, elements.size()); - assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedType).target(expectedThisAccess).result("spoon.test.targeted.testclasses.Foo.this.i"), elements.get(0)); + assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedType).target(expectedThisAccess).result("this.i"), elements.get(0)); assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedAnonymousType).target(expectedAnonymousThisAccess).result("this.i"), elements.get(1)); assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedAnonymousType).target(expectedAnonymousThisAccess).result("i"), elements.get(2)); } @@ -254,7 +255,7 @@ public void testStaticTargetsOfFieldAccessNoClasspath() throws Exception { assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedFoo).target(CtConstructorCallImpl.class).result("new Foo().i"), elements.get(0)); assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedFoo).target(elements.get(2)).result("foo.i"), elements.get(1)); assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedFoo).target(expectedThisAccess).result("foo"), elements.get(2)); - assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedFoo).target(expectedThisAccess).result("Foo.this.i"), elements.get(3)); + assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedFoo).target(expectedThisAccess).result("this.i"), elements.get(3)); assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedFoo).target(expectedThisAccess).result("foo"), elements.get(4)); assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(expectedFoo).target(expectedTypeAccess.toString()).result("Foo.staticField"), elements.get(5)); assertEqualsFieldAccess(new ExpectedTargetedExpression().result("staticField"), elements.get(6)); @@ -285,7 +286,7 @@ public void testTargetsOfInv() throws Exception { assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedType).target(CtConstructorCallImpl.class).result("new spoon.test.targeted.testclasses.Foo(0, 0).method()"), elements.get(0)); assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedType).target(CtFieldReadImpl.class).result("foo.method()"), elements.get(1)); - assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedType).target(expectedThisAccess).result("spoon.test.targeted.testclasses.Foo.this.method()"), elements.get(2)); + assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedType).target(expectedThisAccess).result("this.method()"), elements.get(2)); assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedType).target(expectedThisAccess).result("method()"), elements.get(3)); assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedBarType).target(CtFieldReadImpl.class).result("bar.methodBar()"), elements.get(4)); assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedFuuType).target(CtFieldReadImpl.class).result("fuu.method()"), elements.get(5)); @@ -293,7 +294,6 @@ public void testTargetsOfInv() throws Exception { assertEquals(fooTypeAccess.getType().getQualifiedName(), ((CtThisAccess) elements.get(2).getTarget()).getTarget().getType().getQualifiedName()); assertEquals(fooTypeAccess.getType().getQualifiedName(), ((CtThisAccess) elements.get(3).getTarget()).getTarget().getType().getQualifiedName()); - assertEquals(fooTypeAccess, ((CtThisAccess) elements.get(6).getTarget()).getTarget()); } @Test @@ -315,7 +315,7 @@ public void testStaticTargetsOfInv() throws Exception { assertEquals(8, elements.size()); assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedType).target(CtConstructorCallImpl.class).result("new spoon.test.targeted.testclasses.Foo(0, 0).staticMethod()"), elements.get(0)); assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedType).target(CtFieldReadImpl.class).result("foo.staticMethod()"), elements.get(1)); - assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedType).target(expectedThisAccess).result("spoon.test.targeted.testclasses.Foo.this.staticMethod()"), elements.get(2)); + assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedType).target(expectedThisAccess).result("this.staticMethod()"), elements.get(2)); assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedType).target(expectedTypeAccess).result("spoon.test.targeted.testclasses.Foo.staticMethod()"), elements.get(3)); assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedType).target(expectedTypeAccess).result("spoon.test.targeted.testclasses.Foo.staticMethod()"), elements.get(4)); assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedBarType).target(expectedBarTypeAccess).result("spoon.test.targeted.testclasses.Bar.staticMethodBar()"), elements.get(5)); @@ -347,18 +347,18 @@ public void testTargetsOfInvInInnerClass() throws Exception { expectedThisAccess.setType(expectedInnerClass); assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedType).target(expectedThisAccess).result("inv()"), elements.get(0)); expectedThisAccess.setType(expectedType); - assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedType).target(expectedThisAccess).result("spoon.test.targeted.testclasses.Foo.this.inv()"), elements.get(1)); + assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedType).target(expectedThisAccess).result("this.inv()"), elements.get(1)); assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedType).target(fooTypeAccess).result("spoon.test.targeted.testclasses.Foo.staticMethod()"), elements.get(2)); assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedType).target(fooTypeAccess).result("spoon.test.targeted.testclasses.Foo.staticMethod()"), elements.get(3)); expectedSuperThisAccess.setType(expectedInnerClass); assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedSuperClassType).target(expectedSuperThisAccess).result("superMethod()"), elements.get(4)); - assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedSuperClassType).target(expectedThisAccess).result("spoon.test.targeted.testclasses.Foo.this.superMethod()"), elements.get(5)); + assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedSuperClassType).target(expectedThisAccess).result("this.superMethod()"), elements.get(5)); assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedInnerClass).target(expectedInnerClassAccess).result("method()"), elements.get(6)); - assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedInnerClass).target(expectedInnerClassAccess).result("spoon.test.targeted.testclasses.Foo.InnerClass.this.method()"), elements.get(7)); + assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedInnerClass).target(expectedInnerClassAccess).result("this.method()"), elements.get(7)); final List newElements = nestedTypeScanner.getMethodsByName("checkType").get(0).getElements(new TypeFilter<>(CtInvocation.class)); assertEquals(1, newElements.size()); - assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedNested).target(expectedNestedAccess).result("NestedTypeScanner.this.checkType(type)"), newElements.get(0)); + assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedNested).target(expectedNestedAccess).result("this.checkType(type)"), newElements.get(0)); } @Test @@ -380,7 +380,7 @@ public boolean matches(CtClass element) { final CtMethod method = anonymousClass.getMethodsByName("m").get(0); final List elements = method.getElements(new TypeFilter<>(CtInvocation.class)); assertEquals(2, elements.size()); - assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedType).target(expectedThisAccess).result("spoon.test.targeted.testclasses.Foo.this.invStatic()"), elements.get(0)); + assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedType).target(expectedThisAccess).result("this.invStatic()"), elements.get(0)); assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(expectedAnonymousType).target(expectedAnonymousThisAccess).result("this.invStatic()"), elements.get(1)); } @@ -405,7 +405,7 @@ public void testStaticTargetsOfInvNoClasspath() throws Exception { assertEquals(8, elements.size()); assertEqualsInvocation(new ExpectedTargetedExpression().target(CtConstructorCallImpl.class).result("new Foo(0, 0).staticMethod()"), elements.get(0)); assertEqualsInvocation(new ExpectedTargetedExpression().target(CtFieldReadImpl.class).result("foo.staticMethod()"), elements.get(1)); - assertEqualsInvocation(new ExpectedTargetedExpression().target(expectedThisAccess).result("Foo.this.staticMethod()"), elements.get(2)); + assertEqualsInvocation(new ExpectedTargetedExpression().target(expectedThisAccess).result("this.staticMethod()"), elements.get(2)); assertEqualsInvocation(new ExpectedTargetedExpression().target(expectedTypeAccess).result("Foo.staticMethod()"), elements.get(3)); assertEqualsInvocation(new ExpectedTargetedExpression().target(expectedThisAccess).result("staticMethod()"), elements.get(4)); assertEqualsInvocation(new ExpectedTargetedExpression().declaringType(bar).target(expectedBarTypeAccess).result("Bar.staticMethodBar()"), elements.get(5)); @@ -439,11 +439,11 @@ public void testClassDeclaredInALambda() throws Exception { final CtTypeReference firstExpected = type.getFactory().Type().createReference("spoon.test.targeted.testclasses.Tapas$1$InnerSubscriber"); CtThisAccess expectedThisAccess = type.getFactory().Code().createThisAccess(firstExpected); - assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(firstExpected).target(expectedThisAccess).type(CtFieldWrite.class).result("InnerSubscriber.this.index"), elements.get(0)); + assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(firstExpected).target(expectedThisAccess).type(CtFieldWrite.class).result("this.index"), elements.get(0)); final CtTypeReference secondExpectedInner = type.getFactory().Type().createReference("spoon.test.targeted.testclasses.Tapas$3InnerSubscriber"); expectedThisAccess = type.getFactory().Code().createThisAccess(secondExpectedInner); - assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(secondExpectedInner).target(expectedThisAccess).type(CtFieldWrite.class).result("InnerSubscriber.this.index").isLocal(), elements.get(1)); + assertEqualsFieldAccess(new ExpectedTargetedExpression().declaringType(secondExpectedInner).target(expectedThisAccess).type(CtFieldWrite.class).result("this.index").isLocal(), elements.get(1)); final CtTypeReference thirdExpectedInner = type.getFactory().Type().createReference("spoon.test.targeted.testclasses.Tapas$4InnerSubscriber"); expectedThisAccess = type.getFactory().Code().createThisAccess(thirdExpectedInner); diff --git a/src/test/java/spoon/test/variable/AccessTest.java b/src/test/java/spoon/test/variable/AccessTest.java index cb6d4b1815a..a84d02fb2b7 100644 --- a/src/test/java/spoon/test/variable/AccessTest.java +++ b/src/test/java/spoon/test/variable/AccessTest.java @@ -196,7 +196,7 @@ public void testVariableAccessInNoClasspath() throws Exception { } assertEquals("java.lang.Class mclass = ((java.lang.Class) (org.argouml.model.ModelFacade.USE_CASE))", elements.get(0).getParent().toString()); - assertEquals("new org.argouml.uml.ui.PropPanelButton(org.argouml.uml.ui.behavior.use_cases.PropPanelUseCase.this, buttonPanel, _navUpIcon, org.argouml.i18n.Translator.localize(\"UMLMenu\", \"button.go-up\"), \"navigateNamespace\", null)", elements.get(2).getParent().toString()); + assertEquals("new org.argouml.uml.ui.PropPanelButton(this, buttonPanel, _navUpIcon, org.argouml.i18n.Translator.localize(\"UMLMenu\", \"button.go-up\"), \"navigateNamespace\", null)", elements.get(2).getParent().toString()); } @Test diff --git a/src/test/resources/expected/AddFieldAtTop.java b/src/test/resources/expected/AddFieldAtTop.java deleted file mode 100644 index 6d3cf2ec7cf..00000000000 --- a/src/test/resources/expected/AddFieldAtTop.java +++ /dev/null @@ -1,16 +0,0 @@ -public class AddFieldAtTop { - java.lang.String generated2; - - java.lang.String generated; - - public AddFieldAtTop() { - } - - static { - } - - int i; - - void m() { - } -} \ No newline at end of file