From 5dd1921b2ddcc8c6faef60d23c0e3a2c237a8ec5 Mon Sep 17 00:00:00 2001 From: Martin Monperrus Date: Mon, 15 Jul 2019 14:42:44 +0200 Subject: [PATCH 1/6] test: add test for fully untested class JavaIdentifiers --- src/main/java/spoon/ContractVerifier.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/spoon/ContractVerifier.java b/src/main/java/spoon/ContractVerifier.java index eccc28d7008..39826cf0a50 100644 --- a/src/main/java/spoon/ContractVerifier.java +++ b/src/main/java/spoon/ContractVerifier.java @@ -36,6 +36,7 @@ import spoon.reflect.reference.CtTypeReference; import spoon.reflect.visitor.CtBiScannerDefault; import spoon.reflect.visitor.CtScanner; +import spoon.reflect.visitor.JavaIdentifiers; import spoon.reflect.visitor.PrinterHelper; import spoon.reflect.visitor.filter.TypeFilter; import spoon.support.Experimental; @@ -89,6 +90,7 @@ public void verify() { checkElementIsContainedInAttributeOfItsParent(); checkElementToPathToElementEquivalence(); checkRoleInParent(); + (); } /** verifies that the explicit modifier should be present in the original source code */ @@ -585,4 +587,17 @@ public void checkGenericContracts() { // type parameter reference. checkBoundAndUnboundTypeReference(); } + + public void checkJavaIdentifiers() { + // checking method JavaIdentifiers.isLegalJavaPackageIdentifier + _rootPackage.getPackage("spoon").getElements(new TypeFilter<>(CtPackage.class)).parallelStream().forEach(element -> { + JavaIdentifiers.isLegalJavaPackageIdentifier(element.getSimpleName()); + }); + + // checking method JavaIdentifiers.isLegalJavaExecutableIdentifier + _rootPackage.getPackage("spoon").getElements(new TypeFilter<>(CtExecutable.class)).parallelStream().forEach(element -> { + JavaIdentifiers.isLegalJavaExecutableIdentifier(element.getSimpleName()); + }); + + } } From 9d4a0daef3b38e8c932fcbc548439c5466b1f206 Mon Sep 17 00:00:00 2001 From: Martin Monperrus Date: Mon, 15 Jul 2019 14:48:37 +0200 Subject: [PATCH 2/6] up --- src/main/java/spoon/ContractVerifier.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/spoon/ContractVerifier.java b/src/main/java/spoon/ContractVerifier.java index 39826cf0a50..83a0c88b987 100644 --- a/src/main/java/spoon/ContractVerifier.java +++ b/src/main/java/spoon/ContractVerifier.java @@ -591,12 +591,12 @@ public void checkGenericContracts() { public void checkJavaIdentifiers() { // checking method JavaIdentifiers.isLegalJavaPackageIdentifier _rootPackage.getPackage("spoon").getElements(new TypeFilter<>(CtPackage.class)).parallelStream().forEach(element -> { - JavaIdentifiers.isLegalJavaPackageIdentifier(element.getSimpleName()); + assertTrue("isLegalJavaPackageIdentifier is broken", JavaIdentifiers.isLegalJavaPackageIdentifier(element.getSimpleName())); }); // checking method JavaIdentifiers.isLegalJavaExecutableIdentifier _rootPackage.getPackage("spoon").getElements(new TypeFilter<>(CtExecutable.class)).parallelStream().forEach(element -> { - JavaIdentifiers.isLegalJavaExecutableIdentifier(element.getSimpleName()); + assertTrue("isLegalJavaExecutableIdentifier is broken", JavaIdentifiers.isLegalJavaExecutableIdentifier(element.getSimpleName())); }); } From 127d742ef9c58794e45f832a94d13263e446ae60 Mon Sep 17 00:00:00 2001 From: Martin Monperrus Date: Mon, 15 Jul 2019 14:52:45 +0200 Subject: [PATCH 3/6] up --- src/main/java/spoon/ContractVerifier.java | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/main/java/spoon/ContractVerifier.java b/src/main/java/spoon/ContractVerifier.java index 83a0c88b987..437f2745c7d 100644 --- a/src/main/java/spoon/ContractVerifier.java +++ b/src/main/java/spoon/ContractVerifier.java @@ -14,6 +14,7 @@ import spoon.reflect.code.CtVariableWrite; import spoon.reflect.cu.CompilationUnit; import spoon.reflect.cu.SourcePosition; +import spoon.reflect.declaration.CtAnonymousExecutable; import spoon.reflect.declaration.CtConstructor; import spoon.reflect.declaration.CtElement; import spoon.reflect.declaration.CtExecutable; @@ -90,7 +91,7 @@ public void verify() { checkElementIsContainedInAttributeOfItsParent(); checkElementToPathToElementEquivalence(); checkRoleInParent(); - (); + checkJavaIdentifiers(); } /** verifies that the explicit modifier should be present in the original source code */ @@ -588,15 +589,19 @@ public void checkGenericContracts() { checkBoundAndUnboundTypeReference(); } + /** checks that the identifiers are valid */ public void checkJavaIdentifiers() { // checking method JavaIdentifiers.isLegalJavaPackageIdentifier _rootPackage.getPackage("spoon").getElements(new TypeFilter<>(CtPackage.class)).parallelStream().forEach(element -> { - assertTrue("isLegalJavaPackageIdentifier is broken", JavaIdentifiers.isLegalJavaPackageIdentifier(element.getSimpleName())); + assertTrue("isLegalJavaPackageIdentifier is broken for" + element.getPosition(), JavaIdentifiers.isLegalJavaPackageIdentifier(element.getSimpleName())); }); - // checking method JavaIdentifiers.isLegalJavaExecutableIdentifier _rootPackage.getPackage("spoon").getElements(new TypeFilter<>(CtExecutable.class)).parallelStream().forEach(element -> { - assertTrue("isLegalJavaExecutableIdentifier is broken", JavaIdentifiers.isLegalJavaExecutableIdentifier(element.getSimpleName())); + + // static methods have an empty string as identifier + if (element instanceof CtAnonymousExecutable) { return; } + + assertTrue("isLegalJavaExecutableIdentifier is broken" + element.getPosition(), JavaIdentifiers.isLegalJavaExecutableIdentifier(element.getSimpleName())); }); } From 447ef11c21d30e84ad66284e8a6c4a9fde4cb18c Mon Sep 17 00:00:00 2001 From: Martin Monperrus Date: Mon, 15 Jul 2019 20:23:21 +0200 Subject: [PATCH 4/6] Commit by Martin Monperrus on 15 July 2019 --- src/main/java/spoon/ContractVerifier.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/spoon/ContractVerifier.java b/src/main/java/spoon/ContractVerifier.java index 437f2745c7d..2a47e7366c7 100644 --- a/src/main/java/spoon/ContractVerifier.java +++ b/src/main/java/spoon/ContractVerifier.java @@ -597,9 +597,11 @@ public void checkJavaIdentifiers() { }); // checking method JavaIdentifiers.isLegalJavaExecutableIdentifier _rootPackage.getPackage("spoon").getElements(new TypeFilter<>(CtExecutable.class)).parallelStream().forEach(element -> { - + // static methods have an empty string as identifier - if (element instanceof CtAnonymousExecutable) { return; } + if (element instanceof CtAnonymousExecutable) { + return; + } assertTrue("isLegalJavaExecutableIdentifier is broken" + element.getPosition(), JavaIdentifiers.isLegalJavaExecutableIdentifier(element.getSimpleName())); }); From 3be8cc4d669293260d65c471653990dea20f483b Mon Sep 17 00:00:00 2001 From: Martin Monperrus Date: Mon, 15 Jul 2019 22:34:28 +0200 Subject: [PATCH 5/6] Commit by Martin Monperrus on 15 July 2019 --- src/main/java/spoon/ContractVerifier.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/spoon/ContractVerifier.java b/src/main/java/spoon/ContractVerifier.java index 2a47e7366c7..d88824c2fae 100644 --- a/src/main/java/spoon/ContractVerifier.java +++ b/src/main/java/spoon/ContractVerifier.java @@ -592,11 +592,11 @@ public void checkGenericContracts() { /** checks that the identifiers are valid */ public void checkJavaIdentifiers() { // checking method JavaIdentifiers.isLegalJavaPackageIdentifier - _rootPackage.getPackage("spoon").getElements(new TypeFilter<>(CtPackage.class)).parallelStream().forEach(element -> { + _rootPackage.getElements(new TypeFilter<>(CtPackage.class)).parallelStream().forEach(element -> { assertTrue("isLegalJavaPackageIdentifier is broken for" + element.getPosition(), JavaIdentifiers.isLegalJavaPackageIdentifier(element.getSimpleName())); }); // checking method JavaIdentifiers.isLegalJavaExecutableIdentifier - _rootPackage.getPackage("spoon").getElements(new TypeFilter<>(CtExecutable.class)).parallelStream().forEach(element -> { + _rootPackage.getElements(new TypeFilter<>(CtExecutable.class)).parallelStream().forEach(element -> { // static methods have an empty string as identifier if (element instanceof CtAnonymousExecutable) { From ae27dd28f3bd5102f319fe0cb5a01abcb316597a Mon Sep 17 00:00:00 2001 From: Martin Monperrus Date: Tue, 16 Jul 2019 11:10:03 +0200 Subject: [PATCH 6/6] Commit by Martin Monperrus on 16 July 2019 --- src/main/java/spoon/ContractVerifier.java | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/java/spoon/ContractVerifier.java b/src/main/java/spoon/ContractVerifier.java index d88824c2fae..16ebb027da6 100644 --- a/src/main/java/spoon/ContractVerifier.java +++ b/src/main/java/spoon/ContractVerifier.java @@ -6,6 +6,7 @@ package spoon; +import spoon.reflect.CtModelImpl; import spoon.reflect.code.CtArrayWrite; import spoon.reflect.code.CtAssignment; import spoon.reflect.code.CtExpression; @@ -593,7 +594,13 @@ public void checkGenericContracts() { public void checkJavaIdentifiers() { // checking method JavaIdentifiers.isLegalJavaPackageIdentifier _rootPackage.getElements(new TypeFilter<>(CtPackage.class)).parallelStream().forEach(element -> { - assertTrue("isLegalJavaPackageIdentifier is broken for" + element.getPosition(), JavaIdentifiers.isLegalJavaPackageIdentifier(element.getSimpleName())); + // the default package is excluded (called "unnamed package") + if (element instanceof CtModelImpl.CtRootPackage) { + return; + } + + + assertTrue("isLegalJavaPackageIdentifier is broken for " + element.getSimpleName() + " " + element.getPosition(), JavaIdentifiers.isLegalJavaPackageIdentifier(element.getSimpleName())); }); // checking method JavaIdentifiers.isLegalJavaExecutableIdentifier _rootPackage.getElements(new TypeFilter<>(CtExecutable.class)).parallelStream().forEach(element -> { @@ -603,7 +610,7 @@ public void checkJavaIdentifiers() { return; } - assertTrue("isLegalJavaExecutableIdentifier is broken" + element.getPosition(), JavaIdentifiers.isLegalJavaExecutableIdentifier(element.getSimpleName())); + assertTrue("isLegalJavaExecutableIdentifier is broken " + element.getSimpleName() + " " + element.getPosition(), JavaIdentifiers.isLegalJavaExecutableIdentifier(element.getSimpleName())); }); }