Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test: add test for untested class JavaIdentifiers #3048

Merged
merged 6 commits into from
Jul 20, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions src/main/java/spoon/ContractVerifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -14,6 +15,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;
Expand All @@ -36,6 +38,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;
Expand Down Expand Up @@ -89,6 +92,7 @@ public void verify() {
checkElementIsContainedInAttributeOfItsParent();
checkElementToPathToElementEquivalence();
checkRoleInParent();
checkJavaIdentifiers();
}

/** verifies that the explicit modifier should be present in the original source code */
Expand Down Expand Up @@ -585,4 +589,29 @@ public void checkGenericContracts() {
// type parameter reference.
checkBoundAndUnboundTypeReference();
}

/** checks that the identifiers are valid */
public void checkJavaIdentifiers() {
// checking method JavaIdentifiers.isLegalJavaPackageIdentifier
_rootPackage.getElements(new TypeFilter<>(CtPackage.class)).parallelStream().forEach(element -> {
// 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 -> {

// static methods have an empty string as identifier
if (element instanceof CtAnonymousExecutable) {
return;
}

assertTrue("isLegalJavaExecutableIdentifier is broken " + element.getSimpleName() + " " + element.getPosition(), JavaIdentifiers.isLegalJavaExecutableIdentifier(element.getSimpleName()));
});

}
}