Java Code Examples for spoon.compiler.Environment#setCommentEnabled()
The following examples show how to use
spoon.compiler.Environment#setCommentEnabled() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Spoonerism.java From spoon-examples with GNU General Public License v2.0 | 5 votes |
Spoonerism writeTransformedClasses () { // And now just write the transformed classes Environment env = spoonUniverse.getEnvironment(); // replace FQN with imports and short names env.setAutoImports(true); // include comments - source is for human consumption env.setCommentEnabled(true); // where to write spoonUniverse.setSourceOutputDirectory(OUT_DIR); // default printing, use a different printer for even fancier formatting spoonUniverse.prettyprint(); return this; }
Example 2
Source File: ProcessorMainTest.java From spoon-examples with GNU General Public License v2.0 | 5 votes |
@Test public void main() { String projectPath = "."; MavenLauncher launcher = new MavenLauncher(projectPath, MavenLauncher.SOURCE_TYPE.APP_SOURCE); Environment environment = launcher.getEnvironment(); environment.setCommentEnabled(true); environment.setAutoImports(true); launcher.addProcessor(new APICheckingProcessor()); launcher.run(); }
Example 3
Source File: BigTransfoScenarioTest.java From spoon-examples with GNU General Public License v2.0 | 4 votes |
@SuppressWarnings("all") @Test public void main() { MavenLauncher launcher = new MavenLauncher( "./src/test/resources/project/", MavenLauncher.SOURCE_TYPE.APP_SOURCE); CtModel model = launcher.buildModel(); List<CtMethod> methodList = model. filterChildren(new NamedElementFilter<CtPackage>(CtPackage.class, "ow2con")). filterChildren(new NamedElementFilter<CtPackage>(CtPackage.class, "publicapi")). filterChildren(new TypeFilter<CtMethod>(CtMethod.class)). filterChildren(new Filter<CtMethod>() { @Override public boolean matches(CtMethod element) { boolean isPublic = element.isPublic(); CtTypeReference returnType = element.getType(); String privateApiPackage = "ow2con.privateapi"; boolean isTypeFromPrivateApi = returnType.getQualifiedName().contains(privateApiPackage); return isPublic && isTypeFromPrivateApi; } }).list(); Factory factory = launcher.getFactory(); CtClass<? extends Throwable> exceptionClass = factory.createClass("ow2con.PrivateAPIException"); CtConstructorCall<? extends Throwable> exceptionInstance = factory.createConstructorCall(exceptionClass.getReference()); for (CtMethod method : methodList) { CtBlock methodBody = method.getBody(); List<CtComment> bodyComments = new ArrayList<>(); ArrayList<CtStatement> ctStatements = new ArrayList<>(methodBody.getStatements()); for (CtStatement ctStatement : ctStatements) { String statement = ctStatement.toString(); CtComment statementAsComment = factory.createInlineComment(statement); bodyComments.add(statementAsComment); methodBody.removeStatement(ctStatement); } CtThrow throwMyException = factory.createThrow(); CtConstructorCall<? extends Throwable> constructorCall = exceptionInstance.clone(); throwMyException.setThrownExpression(constructorCall); methodBody.addStatement(throwMyException); bodyComments.add( factory.createInlineComment( "FIXME: The private API type should never be return in a public API." ) ); for (CtComment bodyComment : bodyComments) { throwMyException.addComment(bodyComment); } } Environment environment = launcher.getEnvironment(); environment.setCommentEnabled(true); environment.setAutoImports(true); // the transformation must produce compilable code environment.setShouldCompile(true); launcher.prettyprint(); // look in folder spooned/ow2con/publicapi/ the transformed code }