diff --git a/src/main/java/spoon/Launcher.java b/src/main/java/spoon/Launcher.java index 607525ff7a6..b6aed43ef97 100644 --- a/src/main/java/spoon/Launcher.java +++ b/src/main/java/spoon/Launcher.java @@ -378,7 +378,14 @@ protected static JSAP defineArgs() { sw1 = new Switch("enable-comments"); sw1.setShortFlag('c'); sw1.setLongFlag("enable-comments"); - sw1.setHelp("Adds all code comments in the Spoon AST (Javadoc, line-based comments), rewrites them when pretty-printing."); + sw1.setHelp("[DEPRECATED] Adds all code comments in the Spoon AST (Javadoc, line-based comments), rewrites them when pretty-printing. (deprecated: by default, the comments are enabled.)"); + sw1.setDefault("false"); + jsap.registerParameter(sw1); + + // Disable generation of javadoc. + sw1 = new Switch("disable-comments"); + sw1.setLongFlag("disable-comments"); + sw1.setHelp("Disable the parsing of comments in Spoon."); sw1.setDefault("false"); jsap.registerParameter(sw1); @@ -425,7 +432,19 @@ protected void processArguments() { environment.setTabulationSize(jsapActualArgs.getInt("tabsize")); environment.useTabulations(jsapActualArgs.getBoolean("tabs")); environment.setCopyResources(!jsapActualArgs.getBoolean("no-copy-resources")); - environment.setCommentEnabled(jsapActualArgs.getBoolean("enable-comments")); + + if (jsapActualArgs.getBoolean("enable-comments")) { + Launcher.LOGGER.warn("The option --enable-comments (-c) is deprecated as it is now the default behaviour in Spoon."); + } else { + Launcher.LOGGER.warn("Spoon now parse by default the comments. Consider using the option --disable-comments if you want the old behaviour."); + } + + if (jsapActualArgs.getBoolean("disable-comments")) { + environment.setCommentEnabled(false); + } else { + environment.setCommentEnabled(true); + } + environment.setShouldCompile(jsapActualArgs.getBoolean("compile")); environment.setSelfChecks(jsapActualArgs.getBoolean("disable-model-self-checks")); diff --git a/src/main/java/spoon/support/StandardEnvironment.java b/src/main/java/spoon/support/StandardEnvironment.java index d94180def88..68118bd93f1 100644 --- a/src/main/java/spoon/support/StandardEnvironment.java +++ b/src/main/java/spoon/support/StandardEnvironment.java @@ -80,7 +80,7 @@ public class StandardEnvironment implements Serializable, Environment { private boolean copyResources = true; - private boolean enableComments = false; + private boolean enableComments = true; private Logger logger = Launcher.LOGGER; diff --git a/src/main/java/spoon/testing/utils/ModelUtils.java b/src/main/java/spoon/testing/utils/ModelUtils.java index 0bf065b4733..0068f862fe0 100644 --- a/src/main/java/spoon/testing/utils/ModelUtils.java +++ b/src/main/java/spoon/testing/utils/ModelUtils.java @@ -39,7 +39,9 @@ public static Factory createFactory() { /** Utility method for testing: creates the model of `packageName` from src/test/java and returns the CtType corresponding to `className` */ public static > T build(String packageName, String className) throws Exception { - SpoonModelBuilder comp = new Launcher().createCompiler(); + Launcher launcher = new Launcher(); + launcher.getEnvironment().setCommentEnabled(false); // we don't want to parse the comments for equals + SpoonModelBuilder comp = launcher.createCompiler(); comp.addInputSources(SpoonResourceHelper.resources("./src/test/java/" + packageName.replace('.', '/') + "/" + className + ".java")); comp.build(); return comp.getFactory().Package().get(packageName).getType(className); @@ -61,7 +63,9 @@ public Factory createFactory() { /** Utility method for testing: creates the model of the given `classesToBuild` from src/test/java and returns the factory */ public static Factory build(Class... classesToBuild) throws Exception { - SpoonModelBuilder comp = new Launcher().createCompiler(); + Launcher launcher = new Launcher(); + launcher.getEnvironment().setCommentEnabled(false); + SpoonModelBuilder comp = launcher.createCompiler(); for (Class classToBuild : classesToBuild) { comp.addInputSources(SpoonResourceHelper.resources("./src/test/java/" + classToBuild.getName().replace('.', '/') + ".java")); } diff --git a/src/test/java/spoon/reflect/visitor/CtScannerTest.java b/src/test/java/spoon/reflect/visitor/CtScannerTest.java index 4ce9c1ce7ac..d674248bf9c 100644 --- a/src/test/java/spoon/reflect/visitor/CtScannerTest.java +++ b/src/test/java/spoon/reflect/visitor/CtScannerTest.java @@ -262,9 +262,10 @@ public void exit(CtElement o) { assertEquals(0, counter.nObject); // this is a coarse-grain check to see if the scanner changes // no more exec ref in paramref - assertEquals(3616, counter.nElement); - assertEquals(2396, counter.nEnter); - assertEquals(2396, counter.nExit); + // also takes into account the comments + assertEquals(3655, counter.nElement); + assertEquals(2435, counter.nEnter); + assertEquals(2435, counter.nExit); // contract: all AST nodes which are part of Collection or Map are visited first by method "scan(Collection|Map)" and then by method "scan(CtElement)" Counter counter2 = new Counter(); diff --git a/src/test/java/spoon/test/annotation/AnnotationValuesTest.java b/src/test/java/spoon/test/annotation/AnnotationValuesTest.java index 106bd357e7f..fd7c24e7e17 100644 --- a/src/test/java/spoon/test/annotation/AnnotationValuesTest.java +++ b/src/test/java/spoon/test/annotation/AnnotationValuesTest.java @@ -124,6 +124,7 @@ public void testAnnotationPrintAnnotation() throws Exception { Launcher launcher = new Launcher(); launcher.addInputResource("src/test/resources/printer-test/spoon/test/AnnotationSpecTest.java"); launcher.getEnvironment().setNoClasspath(true); + launcher.getEnvironment().setCommentEnabled(false); // avoid getting the comment for the equals launcher.buildModel(); assertEquals(strCtClassOracle, diff --git a/src/test/java/spoon/test/api/NoClasspathTest.java b/src/test/java/spoon/test/api/NoClasspathTest.java index 123864ece96..b1ee305d0e8 100644 --- a/src/test/java/spoon/test/api/NoClasspathTest.java +++ b/src/test/java/spoon/test/api/NoClasspathTest.java @@ -37,6 +37,7 @@ public void test() throws Exception { Launcher spoon = new Launcher(); spoon.getEnvironment().setNoClasspath(true); spoon.getEnvironment().setLevel("OFF"); + spoon.getEnvironment().setCommentEnabled(false); // avoid getting the comments for the equals spoon.addInputResource("./src/test/resources/spoon/test/noclasspath/fields"); spoon.getEnvironment().setSourceOutputDirectory(new File("target/spooned/apitest")); spoon.run(); diff --git a/src/test/java/spoon/test/javadoc/JavaDocTest.java b/src/test/java/spoon/test/javadoc/JavaDocTest.java index de97c626896..3214b842168 100644 --- a/src/test/java/spoon/test/javadoc/JavaDocTest.java +++ b/src/test/java/spoon/test/javadoc/JavaDocTest.java @@ -2,6 +2,7 @@ import org.junit.Test; import spoon.Launcher; +import spoon.OutputType; import spoon.SpoonAPI; import spoon.reflect.code.CtComment; import spoon.reflect.declaration.CtClass; @@ -61,7 +62,7 @@ public void testJavadocNotPresentInAST() throws Exception { Launcher launcher = new Launcher(); launcher.getEnvironment().setCommentEnabled(false); launcher.getEnvironment().setNoClasspath(true); - launcher.setArgs(new String[] {"--output-type", "nooutput" }); + launcher.getEnvironment().setOutputType(OutputType.NO_OUTPUT); launcher.addInputResource("./src/test/java/spoon/test/javadoc/testclasses/"); launcher.run(); diff --git a/src/test/java/spoon/test/main/MainTest.java b/src/test/java/spoon/test/main/MainTest.java index fc008efd866..64a80d94b63 100644 --- a/src/test/java/spoon/test/main/MainTest.java +++ b/src/test/java/spoon/test/main/MainTest.java @@ -530,6 +530,7 @@ public void testTest() throws Exception { "-i", "src/test/java", "-o", "target/spooned", "--noclasspath", + "--disable-comments", "--compliance", "8", "--level", "OFF" }); diff --git a/src/test/java/spoon/test/prettyprinter/PrinterTest.java b/src/test/java/spoon/test/prettyprinter/PrinterTest.java index 93e6060f82e..25c046c6a6d 100644 --- a/src/test/java/spoon/test/prettyprinter/PrinterTest.java +++ b/src/test/java/spoon/test/prettyprinter/PrinterTest.java @@ -236,6 +236,7 @@ public void testPrintingOfOrphanFieldReference() throws Exception { public void testPrinterTokenListener() throws Exception { Launcher spoon = new Launcher(); Factory factory = spoon.createFactory(); + factory.getEnvironment().setCommentEnabled(false); spoon.createCompiler( factory, SpoonResourceHelper