Skip to content

Commit

Permalink
new option: useXbaseGenerated = true
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoBettini committed Aug 4, 2024
1 parent d0f3cf6 commit d802287
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,7 @@

class XtendA {
val public String foo = ""

def dispatch m(String s) {}
def dispatch m(int i) {}
}
Original file line number Diff line number Diff line change
Expand Up @@ -486,16 +486,23 @@ class BatchCompilerTest {
assertTrue(batchCompiler.compile)
assertEquals(0, new File(TEMP_DIRECTORY).list.size)
}

@Test
def void testNoSuppressWarningsAnnotations() {
batchCompiler.generateSyntheticSuppressWarnings = false
batchCompiler.sourcePath = "./batch-compiler-data/xtendClass"
assertTrue(batchCompiler.compile)
assertFalse((OUTPUT_DIRECTORY + "/XtendA.java").contents.contains("@SuppressWarnings"))
}



@Test
def void testNoXbaseGenerated() {
batchCompiler.useXbaseGenerated = false
batchCompiler.sourcePath = "./batch-compiler-data/xtendClass"
assertTrue(batchCompiler.compile)
assertFalse((OUTPUT_DIRECTORY + "/XtendA.java").contents.contains("@XbaseGenerated"))
}

@Test(expected = IllegalArgumentException)
def void testJavaVersion5() {
batchCompiler.javaSourceVersion = "1.5"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -730,6 +730,14 @@ public void testNoSuppressWarningsAnnotations() {
Assert.assertFalse(this.getContents((BatchCompilerTest.OUTPUT_DIRECTORY + "/XtendA.java")).contains("@SuppressWarnings"));
}

@Test
public void testNoXbaseGenerated() {
this.batchCompiler.setUseXbaseGenerated(false);
this.batchCompiler.setSourcePath("./batch-compiler-data/xtendClass");
Assert.assertTrue(this.batchCompiler.compile());
Assert.assertFalse(this.getContents((BatchCompilerTest.OUTPUT_DIRECTORY + "/XtendA.java")).contains("@XbaseGenerated"));
}

@Test(expected = IllegalArgumentException.class)
public void testJavaVersion5() {
this.batchCompiler.setJavaSourceVersion("1.5");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public static void main(String[] args) {
compiler.setJavaSourceVersion(arguments.next().trim());
} else if ("-noSuppressWarningsAnnotation".equals(argument)) {
compiler.setGenerateSyntheticSuppressWarnings(false);
} else if ("-noUseXbaseGenerated".equals(argument)) {
compiler.setUseXbaseGenerated(false);
} else if ("-generateGeneratedAnnotation".equals(argument)) {
compiler.setGenerateGeneratedAnnotation(true);
} else if ("-includeDateInGeneratedAnnnotation".equals(argument)) {
Expand Down Expand Up @@ -90,6 +92,7 @@ private static void printUsage() {
out.println("-encoding <encoding> Specify character encoding used by source files");
out.println("-javaSourceVersion <version> Create Java Source compatible to this version. Can be: " + allVersionQualifiers);
out.println("-noSuppressWarningsAnnotation Don't put @SuppressWarnings() into generated Java Code");
out.println("-noUseXbaseGenerated Don't put @XbaseGenerated() into generated Java Code");
out.println("-generateGeneratedAnnotation Put @Generated into generated Java Code");
out.println("-includeDateInGeneratedAnnnotation If -generateGeneratedAnnotation is used, add the current date/time.");
out.println("-generateAnnotationComment <string> If -generateGeneratedAnnotation is used, add a comment.");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2012, 2023 itemis AG (http://www.itemis.eu) and others.
* Copyright (c) 2012, 2023, 2024 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
Expand Down Expand Up @@ -315,6 +315,20 @@ public void setGenerateSyntheticSuppressWarnings(final boolean generateSynthetic
generatorConfig.setGenerateSyntheticSuppressWarnings(generateSyntheticSuppressWarnings);
}

/**
* @since 2.36
*/
public boolean isUseXbaseGenerated() {
return generatorConfig.isUseXbaseGenerated();
}

/**
* @since 2.36
*/
public void setUseXbaseGenerated(final boolean useXbaseGenerated) {
generatorConfig.setUseXbaseGenerated(useXbaseGenerated);
}

/**
* @since 2.8
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -490,7 +490,9 @@ protected void appendSyntheticDispatchMethods(XtendTypeDeclaration source, final
JvmOperation operation = deriveGenericDispatchOperationSignature(localOperations, target);
if (operation != null) {
dispatchHelper.markAsDispatcherFunction(operation);
operation.getAnnotations().add(_annotationTypesBuilder.annotationRef(XbaseGenerated.class));
if (generatorConfig.isUseXbaseGenerated()) {
operation.getAnnotations().add(_annotationTypesBuilder.annotationRef(XbaseGenerated.class));
}
operation.setSimpleName(signature.getSimpleName());
operation.setReturnType(jvmTypesBuilder.inferredType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@ public boolean apply(String filePath) {
@Parameter(defaultValue="true")
private boolean generateSyntheticSuppressWarnings;

/**
* Whether <code>@XbaseGenerated</code> shall be generated for synthetic members.
* @since 2.36
*/
@Parameter(defaultValue="true")
private boolean useXbaseGenerated;

/**
* Whether <code>@Generated</code> shall be generated for non-nested types.
*/
Expand Down Expand Up @@ -129,6 +136,8 @@ protected void compile(String classPath, List<String> sourcePaths, String output
compiler.setJavaSourceVersion(javaSourceVersion);
log.debug("Set generateSyntheticSuppressWarnings: " + generateSyntheticSuppressWarnings);
compiler.setGenerateSyntheticSuppressWarnings(generateSyntheticSuppressWarnings);
log.debug("Set useXbaseGenerated: " + useXbaseGenerated);
compiler.setUseXbaseGenerated(useXbaseGenerated);
log.debug("Set generateGeneratedAnnotation: " + generateGeneratedAnnotation);
compiler.setGenerateGeneratedAnnotation(generateGeneratedAnnotation);
log.debug("Set includeDateInGeneratedAnnotation: " + includeDateInGeneratedAnnotation);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2015 itemis AG (http://www.itemis.eu) and others.
* Copyright (c) 2015, 2024 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
Expand Down Expand Up @@ -28,12 +28,13 @@
* Builder configuration block that adds compiler settings for Xbase.
*
* @author Miro Spoenemann - Initial contribution and API
* @author Lorenzo Bettini - useXbaseGenerated
*/
public class XbaseBuilderConfigurationBlock extends BuilderConfigurationBlock {

@Inject
private XbaseBuilderPreferenceAccess preferenceAccess;

private Combo versionCombo;

private Button useComplianceButton;
Expand Down Expand Up @@ -67,6 +68,8 @@ public void widgetSelected(SelectionEvent e) {

addCheckBox(composite, "Generate @SuppressWarnings annotations",
PREF_GENERATE_SUPPRESS_WARNINGS, BOOLEAN_VALUES, 0);
addCheckBox(composite, "Annotate synthetic members with @XbaseGenerated",
USE_XBASE_GENERATED, BOOLEAN_VALUES, 0);

final Button generateGeneratedButton = addCheckBox(composite, "Generate @Generated annotations",
PREF_GENERATE_GENERATED, BOOLEAN_VALUES, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,21 @@

/**
* @author Miro Spoenemann - Initial contribution and API
* @author Lorenzo Bettini - useXbaseGenerated
*/
public class XbaseBuilderPreferenceAccess {

/**
* Preference identifier for generating <code>@SuppressWarnings</code>.
*/
public static final String PREF_GENERATE_SUPPRESS_WARNINGS = "generateSuppressWarnings"; //$NON-NLS-1$

/**
* Preference identifier for generating <code>@XbaseGenerated</code>.
* @since 2.36
*/
public static final String USE_XBASE_GENERATED = "useXbaseGenerated"; //$NON-NLS-1$

/**
* Preference identifier for generating <code>@Generated</code>.
*/
Expand Down Expand Up @@ -59,6 +67,7 @@ public static class Initializer extends BuilderPreferenceAccess.Initializer {
protected void initializeBuilderPreferences(IPreferenceStore store) {
super.initializeBuilderPreferences(store);
store.setDefault(PREF_GENERATE_SUPPRESS_WARNINGS, true);
store.setDefault(USE_XBASE_GENERATED, true);
store.setDefault(PREF_GENERATE_GENERATED, false);
store.setDefault(PREF_DATE_IN_GENERATED, false);
store.setDefault(PREF_JAVA_VERSION, JavaVersion.JAVA8.toString());
Expand All @@ -73,6 +82,7 @@ protected void initializeBuilderPreferences(IPreferenceStore store) {
public void loadBuilderPreferences(GeneratorConfig generatorConfig, Object context) {
IPreferenceStore preferenceStore = preferenceStoreAccess.getContextPreferenceStore(context);
generatorConfig.setGenerateSyntheticSuppressWarnings(preferenceStore.getBoolean(PREF_GENERATE_SUPPRESS_WARNINGS));
generatorConfig.setUseXbaseGenerated(preferenceStore.getBoolean(USE_XBASE_GENERATED));
generatorConfig.setGenerateGeneratedAnnotation(preferenceStore.getBoolean(PREF_GENERATE_GENERATED));
if (generatorConfig.isGenerateGeneratedAnnotation()) {
generatorConfig.setIncludeDateInGeneratedAnnotation(preferenceStore.getBoolean(PREF_DATE_IN_GENERATED));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2013, 2020 itemis AG (http://www.itemis.eu) and others.
* Copyright (c) 2013, 2020, 2024 itemis AG (http://www.itemis.eu) and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
Expand All @@ -13,6 +13,7 @@
/**
* @author Holger Schill - Initial contribution and API
* @author Miro Spoenemann
* @author Lorenzo Bettini - useXbaseGenerated
*/
public class GeneratorConfig {
/**
Expand All @@ -26,6 +27,11 @@ public class GeneratorConfig {
*/
private boolean generateSyntheticSuppressWarnings = true;

/**
* Whether <code>@XbaseGenerated</code> shall be generated for synthetic members.
*/
private boolean useXbaseGenerated = true;

/**
* Whether <code>@Generated</code> shall be generated for non-nested types.
*/
Expand Down Expand Up @@ -80,6 +86,20 @@ public void setGenerateSyntheticSuppressWarnings(boolean generateSyntheticSuppre
this.generateSyntheticSuppressWarnings = generateSyntheticSuppressWarnings;
}

/**
* @since 2.36
*/
public boolean isUseXbaseGenerated() {
return useXbaseGenerated;
}

/**
* @since 2.36
*/
public void setUseXbaseGenerated(boolean useXbaseGenerated) {
this.useXbaseGenerated = useXbaseGenerated;
}

public boolean isGenerateGeneratedAnnotation() {
return generateGeneratedAnnotation;
}
Expand Down

0 comments on commit d802287

Please sign in to comment.