diff --git a/jsonschema2pojo-ant/src/main/java/org/jsonschema2pojo/ant/Jsonschema2PojoTask.java b/jsonschema2pojo-ant/src/main/java/org/jsonschema2pojo/ant/Jsonschema2PojoTask.java index 1af7ae2f7..f847de196 100644 --- a/jsonschema2pojo-ant/src/main/java/org/jsonschema2pojo/ant/Jsonschema2PojoTask.java +++ b/jsonschema2pojo-ant/src/main/java/org/jsonschema2pojo/ant/Jsonschema2PojoTask.java @@ -46,7 +46,6 @@ import org.jsonschema2pojo.GenerationConfig; import org.jsonschema2pojo.InclusionLevel; import org.jsonschema2pojo.Jsonschema2Pojo; -import org.jsonschema2pojo.Language; import org.jsonschema2pojo.NoopAnnotator; import org.jsonschema2pojo.RuleLogger; import org.jsonschema2pojo.SourceSortOrder; @@ -192,8 +191,6 @@ public class Jsonschema2PojoTask extends Task implements GenerationConfig { private SourceSortOrder sourceSortOrder = SourceSortOrder.OS; - private Language targetLanguage = Language.JAVA; - private Map formatTypeMapping = new HashMap<>(); /** @@ -955,10 +952,6 @@ public void setSourceSortOrder(SourceSortOrder sourceSortOrder) { this.sourceSortOrder = sourceSortOrder; } - public void setTargetLanguage(Language targetLanguage) { - this.targetLanguage = targetLanguage; - } - /** * Sets the 'useInnerClassBuilders' property of this class * @@ -1305,11 +1298,6 @@ public SourceSortOrder getSourceSortOrder() { return sourceSortOrder; } - @Override - public Language getTargetLanguage() { - return targetLanguage; - } - @Override public Map getFormatTypeMapping() { return formatTypeMapping; diff --git a/jsonschema2pojo-ant/src/site/Jsonschema2PojoTask.html b/jsonschema2pojo-ant/src/site/Jsonschema2PojoTask.html index 396f74a56..c1ffda118 100644 --- a/jsonschema2pojo-ant/src/site/Jsonschema2PojoTask.html +++ b/jsonschema2pojo-ant/src/site/Jsonschema2PojoTask.html @@ -433,18 +433,6 @@

Parameters

No (default JSONSCHEMA) - - targetLanguage - The type of code that will be generated. -

- Supported values: -

- - No - targetPackage Package name used for generated Java classes (for types where a fully qualified diff --git a/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/Arguments.java b/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/Arguments.java index dbc4240d1..1b3cf58b3 100644 --- a/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/Arguments.java +++ b/jsonschema2pojo-cli/src/main/java/org/jsonschema2pojo/cli/Arguments.java @@ -32,7 +32,6 @@ import org.jsonschema2pojo.Annotator; import org.jsonschema2pojo.GenerationConfig; import org.jsonschema2pojo.InclusionLevel; -import org.jsonschema2pojo.Language; import org.jsonschema2pojo.NoopAnnotator; import org.jsonschema2pojo.SourceSortOrder; import org.jsonschema2pojo.SourceType; @@ -236,9 +235,6 @@ public class Arguments implements GenerationConfig { @Parameter(names = { "-sso", "--source-sort-order" }, description = "The sort order to be applied to the source files. Available options are: OS, FILES_FIRST or SUBDIRS_FIRST") private SourceSortOrder sourceSortOrder = SourceSortOrder.OS; - @Parameter(names = { "-tl", "--target-language" }, description = "The type of code that will be generated. Available options are: JAVA or SCALA") - private Language targetLanguage = Language.JAVA; - @Parameter(names = { "-ftm", "--format-type-mapping" }, description = "Mapping from format identifier to type: :.", variableArity = true) private List formatTypeMapping = new ArrayList<>(); @@ -597,11 +593,6 @@ public SourceSortOrder getSourceSortOrder() { return sourceSortOrder; } - @Override - public Language getTargetLanguage() { - return targetLanguage; - } - @Override public Map getFormatTypeMapping() { return formatTypeMapping diff --git a/jsonschema2pojo-core/pom.xml b/jsonschema2pojo-core/pom.xml index 7ab344bb0..f03da8639 100644 --- a/jsonschema2pojo-core/pom.xml +++ b/jsonschema2pojo-core/pom.xml @@ -13,11 +13,6 @@ jsonschema2pojo-core - - org.jsonschema2pojo - jsonschema2pojo-scalagen - ${project.version} - com.fasterxml.jackson.core jackson-databind @@ -26,10 +21,6 @@ com.fasterxml.jackson.dataformat jackson-dataformat-yaml - - org.scala-lang - scala-library - com.google.code.javaparser javaparser @@ -82,6 +73,10 @@ com.github.tomakehurst wiremock + + org.apache.commons + commons-lang3 + org.slf4j slf4j-simple diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/DefaultGenerationConfig.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/DefaultGenerationConfig.java index 63771c04b..b53fca525 100644 --- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/DefaultGenerationConfig.java +++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/DefaultGenerationConfig.java @@ -457,14 +457,6 @@ public SourceSortOrder getSourceSortOrder() { return SourceSortOrder.OS; } - /** - * @return {@link Language#JAVA} - */ - @Override - public Language getTargetLanguage() { - return Language.JAVA; - } - /** * @return {@link Collections#emptyMap} */ diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/GenerationConfig.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/GenerationConfig.java index 2b989f449..a61ab9b94 100644 --- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/GenerationConfig.java +++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/GenerationConfig.java @@ -594,19 +594,6 @@ public interface GenerationConfig { */ SourceSortOrder getSourceSortOrder(); - /** - * Gets the 'targetLanguage' configuration option. - * - * @return The type of code that will be generated. - *

- * Supported values: - *

    - *
  • JAVA (Generate .java source files)
  • - *
  • SCALA (Generate .scala source files, using scalagen)
  • - *
- */ - Language getTargetLanguage(); - /** * Gets the 'formatTypeMapping' configuration option. * diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/Jsonschema2Pojo.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/Jsonschema2Pojo.java index b8d365991..0c02e494b 100644 --- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/Jsonschema2Pojo.java +++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/Jsonschema2Pojo.java @@ -81,15 +81,9 @@ public static void generate(GenerationConfig config, RuleLogger logger) throws I } if (config.getTargetDirectory().exists() || config.getTargetDirectory().mkdirs()) { - if (config.getTargetLanguage() == Language.SCALA) { - CodeWriter sourcesWriter = new ScalaFileCodeWriter(config.getTargetDirectory(), config.getOutputEncoding()); - CodeWriter resourcesWriter = new FileCodeWriterWithEncoding(config.getTargetDirectory(), config.getOutputEncoding()); - codeModel.build(sourcesWriter, resourcesWriter); - } else { - CodeWriter sourcesWriter = new FileCodeWriterWithEncoding(config.getTargetDirectory(), config.getOutputEncoding()); - CodeWriter resourcesWriter = new FileCodeWriterWithEncoding(config.getTargetDirectory(), config.getOutputEncoding()); - codeModel.build(sourcesWriter, resourcesWriter); - } + CodeWriter sourcesWriter = new FileCodeWriterWithEncoding(config.getTargetDirectory(), config.getOutputEncoding()); + CodeWriter resourcesWriter = new FileCodeWriterWithEncoding(config.getTargetDirectory(), config.getOutputEncoding()); + codeModel.build(sourcesWriter, resourcesWriter); } else { throw new GenerationException("Could not create or access target directory " + config.getTargetDirectory().getAbsolutePath()); } diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/Language.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/Language.java deleted file mode 100644 index fd36bf961..000000000 --- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/Language.java +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright © 2010-2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jsonschema2pojo; - -public enum Language { - - JAVA, SCALA - -} diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/ScalaFileCodeWriter.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/ScalaFileCodeWriter.java deleted file mode 100644 index b86f99886..000000000 --- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/ScalaFileCodeWriter.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright © 2010-2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jsonschema2pojo; - -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FilterOutputStream; -import java.io.IOException; -import java.io.OutputStream; - -import org.apache.commons.io.FileUtils; - -import com.mysema.scalagen.ConversionSettings; -import com.mysema.scalagen.Converter; -import com.sun.codemodel.JPackage; - -public class ScalaFileCodeWriter extends com.sun.codemodel.writer.FileCodeWriter { - - public ScalaFileCodeWriter(final File target, final String encoding) throws IOException { - super(target, encoding); - } - - public OutputStream openBinary(JPackage pkg, String fileName) throws IOException { - final ByteArrayOutputStream javaSourceStream = new ByteArrayOutputStream(); - - final String javaFileName = getFile(pkg, fileName).getAbsolutePath(); - final String scalaFileName = javaFileName.replaceAll("\\.java$", ".scala"); - - return new FilterOutputStream(javaSourceStream) { - public void close() throws IOException { - super.close(); - - final String javaSource = new String(javaSourceStream.toByteArray(), encoding); - final String scalaSource = Converter.instance210().convert(javaSource, new ConversionSettings(false)); - - FileUtils.writeStringToFile(new File(scalaFileName), scalaSource, encoding); - } - }; - } - -} diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/ScalaSingleStreamCodeWriter.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/ScalaSingleStreamCodeWriter.java deleted file mode 100644 index 1345cee16..000000000 --- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/ScalaSingleStreamCodeWriter.java +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright © 2010-2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jsonschema2pojo; - -import com.mysema.scalagen.ConversionSettings; -import com.mysema.scalagen.Converter; -import com.sun.codemodel.JPackage; -import com.sun.codemodel.writer.SingleStreamCodeWriter; -import java.io.ByteArrayOutputStream; -import java.io.FilterOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.nio.charset.StandardCharsets; - -public class ScalaSingleStreamCodeWriter extends SingleStreamCodeWriter { - - public ScalaSingleStreamCodeWriter(OutputStream os) { - super(os); - } - - @Override - public OutputStream openBinary(final JPackage pkg, String fileName) { - final ByteArrayOutputStream javaSourceStream = new ByteArrayOutputStream(); - - final String scalaFileName = fileName.replaceAll("\\.java$", ".scala"); - - return new FilterOutputStream(javaSourceStream) { - @Override - public void close() throws IOException { - super.close(); - - final String javaSource = new String(javaSourceStream.toByteArray(), StandardCharsets.UTF_8); - final String scalaSource = Converter.instance210().convert(javaSource, new ConversionSettings(false)); - - OutputStream parentStream = ScalaSingleStreamCodeWriter.super.openBinary(pkg, scalaFileName); - parentStream.write(scalaSource.getBytes(StandardCharsets.UTF_8)); - } - }; - } - -} diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/ScalaZipCodeWriter.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/ScalaZipCodeWriter.java deleted file mode 100644 index 637ad3c76..000000000 --- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/ScalaZipCodeWriter.java +++ /dev/null @@ -1,56 +0,0 @@ -/** - * Copyright © 2010-2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jsonschema2pojo; - -import java.io.ByteArrayOutputStream; -import java.io.FilterOutputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.nio.charset.StandardCharsets; - -import com.mysema.scalagen.ConversionSettings; -import com.mysema.scalagen.Converter; -import com.sun.codemodel.JPackage; -import com.sun.codemodel.writer.ZipCodeWriter; - -public class ScalaZipCodeWriter extends ZipCodeWriter { - - public ScalaZipCodeWriter(OutputStream target) { - super(target); - } - - @Override - public OutputStream openBinary(final JPackage pkg, String fileName) { - final ByteArrayOutputStream javaSourceStream = new ByteArrayOutputStream(); - - final String scalaFileName = fileName.replaceAll("\\.java$", ".scala"); - - return new FilterOutputStream(javaSourceStream) { - @Override - public void close() throws IOException { - super.close(); - - final String javaSource = new String(javaSourceStream.toByteArray(), StandardCharsets.UTF_8); - final String scalaSource = Converter.instance210().convert(javaSource, new ConversionSettings(false)); - - OutputStream parentStream = ScalaZipCodeWriter.super.openBinary(pkg, scalaFileName); - parentStream.write(scalaSource.getBytes(StandardCharsets.UTF_8)); - } - }; - } - -} diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/DefaultRule.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/DefaultRule.java index f7ebb32a2..fa48c9998 100644 --- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/DefaultRule.java +++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/DefaultRule.java @@ -45,7 +45,6 @@ import com.sun.codemodel.JFieldVar; import com.sun.codemodel.JInvocation; import com.sun.codemodel.JType; -import scala.annotation.meta.field; /** * Applies the "default" schema rule. diff --git a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/ValidRule.java b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/ValidRule.java index f0d1f4239..92a672da7 100644 --- a/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/ValidRule.java +++ b/jsonschema2pojo-core/src/main/java/org/jsonschema2pojo/rules/ValidRule.java @@ -21,7 +21,6 @@ import com.fasterxml.jackson.databind.JsonNode; import org.jsonschema2pojo.Schema; import com.sun.codemodel.JFieldVar; -import scala.annotation.meta.field; public class ValidRule implements Rule { diff --git a/jsonschema2pojo-gradle-plugin/src/main/groovy/org/jsonschema2pojo/gradle/JsonSchemaExtension.groovy b/jsonschema2pojo-gradle-plugin/src/main/groovy/org/jsonschema2pojo/gradle/JsonSchemaExtension.groovy index d070789ad..2e52c18ba 100644 --- a/jsonschema2pojo-gradle-plugin/src/main/groovy/org/jsonschema2pojo/gradle/JsonSchemaExtension.groovy +++ b/jsonschema2pojo-gradle-plugin/src/main/groovy/org/jsonschema2pojo/gradle/JsonSchemaExtension.groovy @@ -20,7 +20,6 @@ import org.jsonschema2pojo.Annotator import org.jsonschema2pojo.AllFileFilter import org.jsonschema2pojo.GenerationConfig import org.jsonschema2pojo.InclusionLevel -import org.jsonschema2pojo.Language import org.jsonschema2pojo.NoopAnnotator import org.jsonschema2pojo.SourceSortOrder import org.jsonschema2pojo.SourceType @@ -95,7 +94,6 @@ public class JsonSchemaExtension implements GenerationConfig { String customDateTimePattern String refFragmentPathDelimiters SourceSortOrder sourceSortOrder - Language targetLanguage Map formatTypeMapping public JsonSchemaExtension() { @@ -281,7 +279,6 @@ public class JsonSchemaExtension implements GenerationConfig { |customDateTimePattern = ${customDateTimePattern} |refFragmentPathDelimiters = ${refFragmentPathDelimiters} |sourceSortOrder = ${sourceSortOrder} - |targetLanguage = ${targetLanguage} |formatTypeMapping = ${formatTypeMapping} |useInnerClassBuilders = ${useInnerClassBuilders} |includeConstructorPropertiesAnnotation = ${includeConstructorPropertiesAnnotation} diff --git a/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/config/ScalaIT.java b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/config/ScalaIT.java deleted file mode 100644 index c1cabfdb7..000000000 --- a/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/config/ScalaIT.java +++ /dev/null @@ -1,38 +0,0 @@ -/** - * Copyright © 2010-2020 Nokia - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.jsonschema2pojo.integration.config; - -import org.jsonschema2pojo.integration.util.Jsonschema2PojoRule; -import org.junit.Rule; -import org.junit.Test; -import static org.junit.Assert.*; -import static org.jsonschema2pojo.integration.util.CodeGenerationHelper.*; - -import java.io.File; - -public class ScalaIT { - - @Rule public Jsonschema2PojoRule schemaRule = new Jsonschema2PojoRule(); - - @Test - public void scalaFilesAreGeneratedAndJavaFilesAreNot() { - File outputDirectory = schemaRule.generate("/schema/properties/primitiveProperties.json", "com.example", - config("targetLanguage", "scala")); - - assertTrue(new File(outputDirectory, "com/example/PrimitiveProperties.scala").exists()); - } -} diff --git a/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/config/UseTitleAsClassnameIT.java b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/config/UseTitleAsClassnameIT.java index cfac291b7..5c1fce232 100644 --- a/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/config/UseTitleAsClassnameIT.java +++ b/jsonschema2pojo-integration-tests/src/test/java/org/jsonschema2pojo/integration/config/UseTitleAsClassnameIT.java @@ -25,7 +25,6 @@ import org.jsonschema2pojo.integration.util.Jsonschema2PojoRule; import org.junit.Rule; import org.junit.Test; -import scala.annotation.meta.getter; import java.lang.reflect.Field; import java.lang.reflect.Method; diff --git a/jsonschema2pojo-maven-plugin/src/main/java/org/jsonschema2pojo/maven/Jsonschema2PojoMojo.java b/jsonschema2pojo-maven-plugin/src/main/java/org/jsonschema2pojo/maven/Jsonschema2PojoMojo.java index 76817d0cb..9c46dc470 100644 --- a/jsonschema2pojo-maven-plugin/src/main/java/org/jsonschema2pojo/maven/Jsonschema2PojoMojo.java +++ b/jsonschema2pojo-maven-plugin/src/main/java/org/jsonschema2pojo/maven/Jsonschema2PojoMojo.java @@ -42,7 +42,6 @@ import org.jsonschema2pojo.GenerationConfig; import org.jsonschema2pojo.InclusionLevel; import org.jsonschema2pojo.Jsonschema2Pojo; -import org.jsonschema2pojo.Language; import org.jsonschema2pojo.NoopAnnotator; import org.jsonschema2pojo.RuleLogger; import org.jsonschema2pojo.SourceSortOrder; @@ -772,21 +771,6 @@ public class Jsonschema2PojoMojo extends AbstractMojo implements GenerationConfi */ private String sourceSortOrder = SourceSortOrder.OS.toString(); - /** - * The type of code that will be generated. - *

- * Supported values: - *

    - *
  • java (Generate .java source files)
  • - *
  • scala (Generate .scala source files, using scalagen)
  • - *
- * - * @parameter property="jsonschema2pojo.targetLanguage" - * default-value="java" - * @since 0.5.0 - */ - private String targetLanguage = "java"; - /** * @parameter property="jsonschema2pojo.formatTypeMapping" * default-value="" @@ -1246,11 +1230,6 @@ public SourceSortOrder getSourceSortOrder() { return SourceSortOrder.valueOf(sourceSortOrder.toUpperCase()); } - @Override - public Language getTargetLanguage() { - return Language.valueOf(targetLanguage.toUpperCase()); - } - @Override public Map getFormatTypeMapping() { return formatTypeMapping; diff --git a/jsonschema2pojo-scalagen/LICENSE.txt b/jsonschema2pojo-scalagen/LICENSE.txt deleted file mode 100644 index 29f81d812..000000000 --- a/jsonschema2pojo-scalagen/LICENSE.txt +++ /dev/null @@ -1,201 +0,0 @@ - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/jsonschema2pojo-scalagen/README.md b/jsonschema2pojo-scalagen/README.md deleted file mode 100644 index a18303e06..000000000 --- a/jsonschema2pojo-scalagen/README.md +++ /dev/null @@ -1,3 +0,0 @@ -Forked from https://github.com/timowest/scalagen/tree/master/scalagen - -© Timo Westkämper diff --git a/jsonschema2pojo-scalagen/pom.xml b/jsonschema2pojo-scalagen/pom.xml deleted file mode 100644 index b4c49c570..000000000 --- a/jsonschema2pojo-scalagen/pom.xml +++ /dev/null @@ -1,211 +0,0 @@ - - - - 4.0.0 - - - jsonschema2pojo - org.jsonschema2pojo - 1.0.3-SNAPSHOT - - - org.jsonschema2pojo - jsonschema2pojo-scalagen - 1.0.3-SNAPSHOT - - - 4.01 - 2.3.0 - 2.11 - 2.11 - 1.4 - scala210_and_up - - - - - - com.google.code.javaparser - javaparser - - - net.sourceforge.collections - collections-generic - ${commons.collections.version} - - - org.apache.commons - commons-lang3 - 3.2.1 - - - commons-io - commons-io - - - - - org.scala-lang - scala-library - provided - - - org.scala-lang - scala-compiler - test - - - - - - junit - junit - - - javax.servlet - servlet-api - - - - - com.mysema.querydsl - querydsl-core - ${querydsl.version} - test - - - com.jsuereth - scala-arm_${scalaArm.scalaVersion} - ${scalaArm.libVersion} - test - - - - - - - - org.scala-tools - maven-scala-plugin - 2.15.2 - - - - compile - testCompile - - - - ${scalac.incrementalBuildArg} - -dependencyfile - ${project.build.directory}/.scala_dependencies - - - -Xms64m - -Xmx1024m - - - - - - - - org.apache.maven.plugins - maven-eclipse-plugin - 2.8 - - - org.scala-ide.sdt.core.scalanature - org.eclipse.jdt.core.javanature - - - org.scala-ide.sdt.core.scalabuilder - - - org.scala-ide.sdt.launching.SCALA_CONTAINER - org.eclipse.jdt.launching.JRE_CONTAINER - - - org.scala-lang:scala-library - - - **/*.scala - **/*.java - - - - - - org.codehaus.mojo - build-helper-maven-plugin - - - add-source - generate-sources - - add-source - - - - src/main/scala - - - - - add-test-source - generate-sources - - add-test-source - - - - src/test/scala - src/test/${test.scalaSourceFolder} - - - - - - - - org.apache.maven.plugins - maven-surefire-plugin - - -Xms256m -Xmx512m - - - - - - org.apache.maven.plugins - maven-dependency-plugin - - - copy-dependencies - package - - copy-dependencies - - - runtime - true - true - ${basedir}/target/dependencies - - - - - - - - org.apache.maven.plugins - maven-compiler-plugin - - 1.7 - 1.7 - - - - - - diff --git a/jsonschema2pojo-scalagen/scalagen b/jsonschema2pojo-scalagen/scalagen deleted file mode 100755 index 68316af8f..000000000 --- a/jsonschema2pojo-scalagen/scalagen +++ /dev/null @@ -1,2 +0,0 @@ -#!/usr/bin/env bash -scala -cp target/dependencies/*:target/classes/ com.mysema.scalagen.Cli $1 $2 diff --git a/jsonschema2pojo-scalagen/src/main/scala/PlaceHolder.java b/jsonschema2pojo-scalagen/src/main/scala/PlaceHolder.java deleted file mode 100644 index db600d9f5..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/PlaceHolder.java +++ /dev/null @@ -1,2 +0,0 @@ -//hack to generate package javadoc -public class PlaceHolder {} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scala/BeanUtils.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scala/BeanUtils.scala deleted file mode 100644 index b8279cefc..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scala/BeanUtils.scala +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scala - -import java.beans.Introspector -import org.apache.commons.lang3.StringUtils - -object BeanUtils { - - def capitalize(name: String): String = { - if (name.length > 1 && Character.isUpperCase(name.charAt(1))) { - name - } else { - StringUtils.capitalize(name) - } - } - - def uncapitalize(name: String): String = Introspector.decapitalize(name); - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Annotations.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Annotations.scala deleted file mode 100644 index 59b8dd438..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Annotations.scala +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import japa.parser.ast.visitor._ -import java.util.ArrayList -import japa.parser.ast.ImportDeclaration -import japa.parser.ast.expr.NameExpr -import japa.parser.ast.visitor.ModifierVisitorAdapter -import UnitTransformer._ - -/** - * Annotations turns Annotation type declarations into normal classes which extend - * StaticAnnotation - */ -class Annotations(targetVersion: ScalaVersion) extends UnitTransformerBase { - - private val staticAnnotationType = new ClassOrInterface("StaticAnnotation") - - def transform(cu: CompilationUnit): CompilationUnit = { - cu.accept(this, cu).asInstanceOf[CompilationUnit] - } - - override def visit(n: AnnotationDecl, arg: CompilationUnit) = { - // turns annotations into StaticAnnotation subclasses - if (targetVersion >= Scala210) { - //StaticAnnotation was in the "scala" package in 2.9, so it was imported by default - //in scala 2.10+, it was moved to the scala.annotation package, so we need an explicit import - arg.getImports().add(new ImportDeclaration(new NameExpr("scala.annotation.StaticAnnotation"), false, false)) - } - val clazz = new ClassOrInterfaceDecl() - clazz.setName(n.getName) - clazz.setExtends(staticAnnotationType :: Nil) - clazz.setMembers(createMembers(n)) - clazz - } - - private def createMembers(n: AnnotationDecl): JavaList[BodyDecl] = { - // TODO : default values - val params = n.getMembers.collect { case m: AnnotationMember => m } - .map(m => new Parameter(PROPERTY, m.getType, new VariableDeclaratorId(m.getName))) - - if (!params.isEmpty) { - val constructor = new Constructor() - constructor.setParameters(params) - constructor.setBlock(new Block()) - constructor :: Nil - } else { - Nil - } - } - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/BeanHelpers.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/BeanHelpers.scala deleted file mode 100644 index 0c78669c5..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/BeanHelpers.scala +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import com.mysema.scala.BeanUtils -import Types._ - -/** - * - */ -trait BeanHelpers extends Helpers { - - private val getter = "get\\w+".r - - private val setter = "set\\w+".r - - private val booleanGetter = "is\\w+".r - - def isBeanGetter(method: Method): Boolean = method match { - case Method(getter(_*), t, Nil, Return(field(_))) => true - case Method(getter(_*), t, Nil, b: Block) => isLazyCreation(b, getProperty(method)) - case _ => false - } - - def isBooleanBeanGetter(method: Method): Boolean = method match { - case Method(booleanGetter(_*), Type.Boolean, Nil, Return(field(_))) => true - case Method(booleanGetter(_*), Type.Boolean, Nil, b: Block) => isLazyCreation(b, getProperty(method)) - case _ => false - } - - def isBeanSetter(method: Method): Boolean = method match { - case Method(setter(_*), Type.Void, _ :: Nil, Stmt(_ set _)) => true - case _ => false - } - - def getProperty(method: Method) = { - val name = method.getName - BeanUtils.uncapitalize(name.substring(if (name.startsWith("is")) 2 else 3)) - } -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/BeanProperties.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/BeanProperties.scala deleted file mode 100644 index 74790f66d..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/BeanProperties.scala +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import japa.parser.ast.body.ModifierSet -import java.util.ArrayList -import com.mysema.scala.BeanUtils -import UnitTransformer._ - -/** - * BeanProperties turns field + accessor combinations into @BeanProperty annotated - * Scala properties - */ -class BeanProperties(targetVersion: ScalaVersion) extends UnitTransformerBase with BeanHelpers { - - val BEAN_PROPERTY_IMPORT = - if (targetVersion >= Scala210) new Import("scala.beans.{BeanProperty, BooleanBeanProperty}", false, false) - else new Import("scala.reflect.{BeanProperty, BooleanBeanProperty}", false, false) - - def transform(cu: CompilationUnit): CompilationUnit = { - cu.accept(this, cu).asInstanceOf[CompilationUnit] - } - - override def visit(n: ClassOrInterfaceDecl, cu: CompilationUnit): ClassOrInterfaceDecl = { - // merges getters and setters into properties - val t = super.visit(n, cu).asInstanceOf[ClassOrInterfaceDecl] - - // accessors - val methods = t.getMembers.collect { case m: Method => m } - val getters = methods.filter(m => isBeanGetter(m) || isBooleanBeanGetter(m)) - .map(m => (getProperty(m) ,m)).toMap - val setters = methods.filter(m => isBeanSetter(m)) - .map(m => (getProperty(m), m)).toMap - - // fields with accessors - val fields = t.getMembers.collect { case f: Field => f } - .filter(_.getModifiers.isPrivate) - .flatMap( f => f.getVariables.map( v => (v.getId.getName,v,f) )) - .filter { case (name,_,_) => getters.contains(name) } - - // remove accessors - for ( (name, variable, field) <- fields) { - var getter = getters(name) - //t.getMembers.remove(getter) - t.setMembers(t.getMembers.filterNot(_ == getter)) - setters.get(name).foreach { s => t.setMembers(t.getMembers.filterNot(_ == s)) } - - // make field public - val isFinal = field.getModifiers.isFinal - field.setModifiers(getter.getModifiers - .addModifier(if (isFinal) ModifierSet.FINAL else 0)) - val annotation = if (getter.getName.startsWith("is")) BOOLEAN_BEAN_PROPERTY else BEAN_PROPERTY - if (field.getAnnotations == null || !field.getAnnotations.contains(annotation)) { - field.setAnnotations(field.getAnnotations :+ annotation) - } - - // handle lazy init - if (isLazyCreation(getter.getBody, name)) { - variable.setInit(getLazyInit(getter.getBody)) - field.addModifier(LAZY) - if (!setters.contains(name)) { - field.addModifier(ModifierSet.FINAL) - } - } - } - - // add BeanProperty import, if properties have been found - if (!fields.isEmpty && !cu.getImports.contains(BEAN_PROPERTY_IMPORT)) { - cu.setImports(cu.getImports :+ BEAN_PROPERTY_IMPORT) - } - t - } - -} diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Cli.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Cli.scala deleted file mode 100644 index 441d62c26..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Cli.scala +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright (C) 2011, James McMahon - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import java.io.File - -/** - * Simple harness to facilitate running scalagen from the command line - */ -object Cli { - val usage = "USAGE: scalagen " - - def main(args: Array[String]) { - if (args.length != 2) { - println(usage) - return - } - - val in = new File(args(0)) - if (in.exists) { - val out = new File(args(1)) - Converter.instance.convert(in, out) - } - } -} diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/CompanionObject.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/CompanionObject.scala deleted file mode 100644 index 06df2a9d8..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/CompanionObject.scala +++ /dev/null @@ -1,101 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import java.util.ArrayList -import UnitTransformer._ - -object CompanionObject extends CompanionObject - -/** - * CompanionObject moves static members into companion objects - */ -// TODO : use ModifierVisitorAdapter -// TODO : get totally rid of mutable lists -class CompanionObject extends UnitTransformer { - - def transform(cu: CompilationUnit): CompilationUnit = { - if (cu.getTypes != null) { - val types = cu.getTypes.filter(!_.getModifiers.isObject) - val cuTypes = new ArrayList[TypeDecl](cu.getTypes) - handleTypes(cu, types, cuTypes) - cu.setTypes(cuTypes) - } - cu - } - - private def handleTypes(cu: CompilationUnit, types: Seq[TypeDecl], members: JavaList[_ >: TypeDecl]) { - types.foreach { t => handleType(cu,t) } - - // get companion objects - val typeToCompanion = types.map(t => (t, getCompanionObject(t))) - .filter(_._2 != null).toMap - - for ( (cl, companion) <- typeToCompanion) { - handleClassAndCompanion(cu, members, cl, companion) - } - } - - private def handleType(cu: CompilationUnit, clazz: TypeDecl) { - if (clazz.getMembers != null) { - val types = clazz.getMembers.collect { case t: TypeDecl => t } - .filter(!_.getModifiers.isObject) - val members = new ArrayList[BodyDecl](clazz.getMembers) - handleTypes(cu, types, members) - clazz.setMembers(members) - } - } - - private def handleClassAndCompanion(cu: CompilationUnit, members: JavaList[_ >: TypeDecl], - clazz: TypeDecl, companion: TypeDecl) { - // add companion - members.add(members.indexOf(clazz), companion) - if (clazz.getMembers.isEmpty) { - members.remove(clazz) - } else if (clazz.getMembers.size == 1) { - clazz.getMembers.get(0) match { - case c: Constructor => { - // remove private empty constructor - if (c.getModifiers.isPrivate && isEmpty(c.getParameters)) { - members.remove(clazz) - } - } - case _ => - } - } - - // add import for companion object members, if class has not been removed - if (members.contains(clazz)) { - cu.setImports(cu.getImports :+ new Import(clazz.getName, false, true)) - } - } - - private def getCompanionObject(t: TypeDecl): TypeDecl = { - if (t.getMembers == null) { - return null - } - - val staticMembers = t.getMembers.filter(isStatic) - if (!staticMembers.isEmpty) { - t.setMembers(t.getMembers.filterNot(staticMembers.contains)) - var companion = new ClassOrInterfaceDecl(OBJECT, false, t.getName) - companion.setMembers(staticMembers) - companion - } else { - null - } - } - - -} diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Constructors.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Constructors.scala deleted file mode 100644 index 1fe15f869..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Constructors.scala +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import japa.parser.ast.body.ModifierSet -import java.util.ArrayList -import UnitTransformer._ - -object Constructors extends Constructors - -/** - * Constructors reorders and normalizes constructors - */ -class Constructors extends UnitTransformerBase { - - def transform(cu: CompilationUnit): CompilationUnit = { - cu.accept(this, cu).asInstanceOf[CompilationUnit] - } - - override def visit(n: ClassOrInterfaceDecl, cu: CompilationUnit): ClassOrInterfaceDecl = { - val t = super.visit(n, cu).asInstanceOf[ClassOrInterfaceDecl] - // make members list mutable - t.setMembers(new ArrayList[BodyDecl](t.getMembers)) - - // get all constructors - val constr = t.getMembers.collect { case c: Constructor => c } - - if (constr.isEmpty) { - return t - } - - // get first without delegating - val first = constr.find( c => - c.getBlock.isEmpty || !isThisConstructor(c.getBlock()(0))) - - // move in front of others - first.filter(_ != constr(0)).foreach { c => - t.getMembers.remove(c) - t.getMembers.add(t.getMembers.indexOf(constr(0)), c) - } - - // copy initializer, if constructor block has non-constructor statements - val c = first.getOrElse(constr(0)) - - // add empty constructor invocation for all other constructors without - // constructor invocations - constr.filter(_ != c).foreach { c => - if (c.getBlock.isEmpty) {// || !c.getBlock()(0).isInstanceOf[ConstructorInvocation]) { - c.getBlock.add(new ConstructorInvocation(true, null, null)) - } - } - - if (!c.getBlock.isEmpty && - !c.getBlock.getStmts.filter(!_.isInstanceOf[ConstructorInvocation]).isEmpty) { - - processStatements(cu, t, c) - - if (!c.getBlock.isEmpty && - !(c.getBlock.size == 1 && c.getBlock()(0).isInstanceOf[ConstructorInvocation] && - !c.getBlock()(0).asInstanceOf[ConstructorInvocation].isThis())) { - val initializer = new Initializer(false, c.getBlock) - t.getMembers.add(t.getMembers.indexOf(c), initializer) - } - - } - - // add missing delegations - t.getMembers.collect { case c: Constructor => c }.filter(_ != c) - .foreach { c => - if (!c.getBlock.isEmpty && !c.getBlock()(0).isInstanceOf[ConstructorInvocation]) { - //c.getBlock.getStmts.add(0, new ConstructorInvocation(true, null, null)) - c.getBlock.setStmts(new ConstructorInvocation(true, null, null) :: c.getBlock.getStmts) - } - } - t - } - - private def processStatements(cu: CompilationUnit, t: TypeDecl, c: Constructor) { - val fields = t.getMembers.collect { case f: Field => f } - val variables = fields.flatMap(_.getVariables).map(v => (v.getId.getName, v)).toMap - val variableToField = fields.flatMap(f => f.getVariables.map(v => (v.getId.getName,f)) ).toMap - - var replacements = Map[String, String]() - - // go through statements and map assignments to variable initializers - c.getBlock.getStmts.collect { case s: ExpressionStmt => s } - .filter(isAssignment(_)) - .foreach { s => - val assign = s.getExpression.asInstanceOf[Assign] - if (assign.getTarget.isInstanceOf[FieldAccess]) { - val fieldAccess = assign.getTarget.asInstanceOf[FieldAccess] - processFieldAssign(s, assign, fieldAccess, c, variables, variableToField) - } else if (assign.getTarget.isInstanceOf[Name]) { - val namedTarget = assign.getTarget.asInstanceOf[Name] - if (variables.contains(namedTarget.getName)) { - if (assign.getValue.isInstanceOf[Name]) { // field = parameter - val namedValue = assign.getValue.asInstanceOf[Name] - c.getParameters.find(_.getId.getName == namedValue.getName).foreach { param => - val field = variableToField(namedTarget.getName) - // rename parameter to field name - param.setId(namedTarget.getName) - replacements = replacements.+((param.getId.getName, namedTarget.getName)) - copyAnnotationsAndModifiers(field, param) - // remove field - field.setVariables(field.getVariables.filterNot(_ == variables(namedTarget.getName))) - } - } else { // field = ?!? - variables(namedTarget.getName).setInit(assign.getValue) - } - c.getBlock.remove(s) - } - } - } - - // remove empty field declarations - fields.filter(_.getVariables.isEmpty).foreach { t.getMembers.remove(_) } - - // modify variables in other statements - val renameTransformer = new RenameTransformer(replacements) - c.getBlock.setStmts(c.getBlock.getStmts.map(stmt => { - if (!stmt.isInstanceOf[ExpressionStmt]) { - stmt.accept(renameTransformer, cu).asInstanceOf[Statement] - } else { - stmt - } - })) - - } - - private def processFieldAssign(s: ExpressionStmt, assign: Assign, fieldAccess: FieldAccess, - c: Constructor, variables: Map[String, Variable], variableToField: Map[String, Field] ) { - if (fieldAccess.getScope.isInstanceOf[This] && - variables.contains(fieldAccess.getField)) { - if (fieldAccess.getField == assign.getValue.toString) { - val field = variableToField(fieldAccess.getField) - c.getParameters.find(_.getId.getName == fieldAccess.getField) - .foreach(copyAnnotationsAndModifiers(field,_)) - // remove field, as constructor parameter can be used - //field.getVariables.remove(variables(fieldAccess.getField)) - field.setVariables(field.getVariables.filterNot(_ == variables(fieldAccess.getField))) - - } else { - // remove statement, put init to field - variables(fieldAccess.getField).setInit(assign.getValue) - } - c.getBlock.remove(s) - } - } - - private def copyAnnotationsAndModifiers(f: Field, p: Parameter) { - if (f.getAnnotations != null) { - p.setAnnotations(p.getAnnotations.union(f.getAnnotations)) - } - - val modifiers = f.getModifiers.addModifier(PROPERTY) - p.setModifiers(modifiers) - } - -} diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/ControlStatements.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/ControlStatements.scala deleted file mode 100644 index 69988945b..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/ControlStatements.scala +++ /dev/null @@ -1,172 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import japa.parser.ast.visitor._ -import java.util.ArrayList -import UnitTransformer._ -import com.mysema.scalagen.ast.BeginClosureExpr - -object ControlStatements extends ControlStatements - -/** - * ControlStatements transform ForStmt, SwitchEntryStmt and If statements - */ -class ControlStatements extends UnitTransformerBase { - - private val KEY = new Name("key") - - private val VALUE = new Name("value") - - private val toUnderscore = new ModifierVisitor[Set[String]] { - override def visitName(n: String, arg: Set[String]): String = { - if (arg.contains(n)) "_" else n - } - } - - private def numMatchingNames(n: Node, variableName: String): Int = { - var matched = 0 - val visitor = new ModifierVisitor[Null] { - override def visitName(n: String, dummy: Null): String = { - if (n == variableName) matched += 1 - n - } - } - n.accept(visitor, null) - matched - } - - private val toKeyAndValue = new ModifierVisitor[String] { - override def visit(nn: MethodCall, arg: String): Node = { - val n = super.visit(nn, arg).asInstanceOf[MethodCall] - n match { - case MethodCall(str(`arg`), "getKey", Nil) => KEY - case MethodCall(str(`arg`), "getValue", Nil) => VALUE - case _ => n - } - } - } - - def transform(cu: CompilationUnit): CompilationUnit = { - cu.accept(this, cu).asInstanceOf[CompilationUnit] - } - - override def visit(nn: For, arg: CompilationUnit): Node = { - // transform - // for (int i = 0; i < x; i++) block - // into - // for (i <- 0 until x) block - val n = super.visit(nn, arg).asInstanceOf[For] - n match { - case For((init: VariableDeclaration) :: Nil, l lt r, incr(_) :: Nil, _) => { - val until = new MethodCall(init.getVars.get(0).getInit, "until", r :: Nil) - init.getVars.get(0).setInit(null) - new Foreach(init, until, n.getBody) - } - case _ => n - } - } - - override def visit(nn: MethodCall, arg: CompilationUnit): Node = { - // transform - // System.out.println - // into - // println - val n = super.visit(nn, arg).asInstanceOf[MethodCall] - n match { - case MethodCall(str("System.out"), "println", args) => { - new MethodCall(null, "println", args) - } - case _ => n - } - } - - override def visit(nn: Foreach, arg: CompilationUnit): Node = { - val n = super.visit(nn, arg).asInstanceOf[Foreach] - n match { - case Foreach( - VariableDeclaration(t, v :: Nil), - MethodCall(scope, "entrySet", Nil), body) => { - val vid = v.getId.toString - new Foreach( - VariableDeclaration(0, "(key, value)", Type.Object), - scope, n.getBody.accept(toKeyAndValue, vid).asInstanceOf[Statement]) - } - case _ => n - } - } - - // TODO : maybe move this to own class - override def visit(nn: Block, arg: CompilationUnit): Node = { - // simplify - // for (format <- values if format.mimetype == contentType) return format - // defaultFormat - // into - // values.find(_.mimetype == contenType).getOrElse(defaultFormat) - val n = super.visit(nn, arg).asInstanceOf[Block] - n match { - case Block( - Foreach(v, it, If(cond, Return(rv1), null)) :: - Return(rv2) :: Nil) => createFindCall(it, v, cond, rv1, rv2) - case _ => n - } - } - - private def createClosure(vid: String, expr: Expression): List[Expression] = numMatchingNames(expr, vid) match { - case 0 => List(new BeginClosureExpr("_"), expr) - case 1 => List(expr.accept(toUnderscore, Set(vid)).asInstanceOf[Expression]) - case _ => List(new BeginClosureExpr(vid), expr) - } - - private def createFindCall(it: Expression, v: VariableDeclaration, - cond: Expression, rv1: Expression, rv2: Expression): Statement = { - val vid = v.getVars.get(0).getId.toString - val newCond = createClosure(vid, cond) - val newIt = it match { - case MethodCall(_, "until", _ :: Nil) => new Enclosed(it) - case _ => it - } - val findCall = new MethodCall(newIt, "find", newCond) - val expr = if (vid == rv1.toString) findCall - else new MethodCall(findCall, "map", createClosure(vid, rv1)) - val getOrElse = new MethodCall(expr, "getOrElse", rv2 :: Nil) - new Block(new ExpressionStmt(getOrElse) :: Nil) - } - - override def visit(nn: If, arg: CompilationUnit): Node = { - // transform - // if (condition) target = x else target = y - // into - // target = if (condition) e else y - val n = super.visit(nn, arg).asInstanceOf[If] - n match { - case If(cond, Stmt(t1 set v1), Stmt(t2 set v2)) if t1 == t2 => { - new ExpressionStmt(new Assign(t1, new Conditional(n.getCondition, v1, v2), Assign.assign)) - } - case _ => n - } - } - - override def visit(nn: SwitchEntry, arg: CompilationUnit) = { - // remove break - val n = super.visit(nn, arg).asInstanceOf[SwitchEntry] - val size = if (n.getStmts == null) 0 else n.getStmts.size - if (size > 1 && n.getStmts.get(size-1).isInstanceOf[Break]) { - //n.getStmts.remove(size-1) - n.setStmts(n.getStmts.dropRight(1)) - } - n - } - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/ConversionSettings.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/ConversionSettings.scala deleted file mode 100644 index 5ef75f7fc..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/ConversionSettings.scala +++ /dev/null @@ -1,7 +0,0 @@ -package com.mysema.scalagen - -case class ConversionSettings(splitLongLines: Boolean = true) - -object ConversionSettings { - def defaultSettings = ConversionSettings() -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Converter.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Converter.scala deleted file mode 100644 index b576df67b..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Converter.scala +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import java.io.{File, ByteArrayInputStream} -import japa.parser.JavaParser -import japa.parser.ast.{ImportDeclaration, CompilationUnit} -import org.apache.commons.io.FileUtils -import java.util.ArrayList -import japa.parser.ParseException -import java.io.ByteArrayInputStream -import java.util.regex.Pattern - -object Converter { - - /** - * default instance for Converter type - */ - lazy val instance = instance29 - - /** - * Converter targeting scala 2.9 - */ - lazy val instance29 = createConverter(Scala29) - - /** - * Converter targeting scala 2.10 - */ - lazy val instance210 = createConverter(Scala210) - - /** - * Converter targeting scala 2.11 - */ - lazy val instance211 = createConverter(Scala211) - - def getInstance(version: ScalaVersion) = version match { - case Scala29 => instance29 - case Scala210 => instance210 - case Scala211 => instance211 - } - - /** - * Converter for the current runtime scala version - */ - def getInstance(): Converter = { - getInstance(ScalaVersion.current) - } - - private def createConverter(version: ScalaVersion) = { - new Converter("UTF-8",List[UnitTransformer]( - Rethrows, - VarToVal, - Synchronized, - RemoveAsserts, - new Annotations(version), - Enums, - Primitives, - SerialVersionUID, - ControlStatements, - CompanionObject, - Underscores, - Setters, - new BeanProperties(version), - Properties, - Constructors, - Initializers, - SimpleEquals)) - } - -} - -/** - * Converter converts Java sources into Scala sources - */ -class Converter(encoding: String, transformers: List[UnitTransformer]) { - - def convert(inFolder: File, outFolder: File) { - val inFolderLength = inFolder.getPath.length + 1 - val inToOut = getJavaFiles(inFolder) - .map(in => (in, toOut(inFolderLength, outFolder, in))) - - // create out folders - inToOut.foreach(_._2.getParentFile.mkdirs() ) - JavaParser.setCacheParser(false) - inToOut.foreach{ case (in,out) => convertFile(in,out) } - } - - def convertFile(in: File, out: File) { - try { - val compilationUnit = JavaParser.parse(in, encoding) - val sources = toScala(compilationUnit) - FileUtils.writeStringToFile(out, sources, "UTF-8") - } catch { - case e: Exception => throw new RuntimeException("Caught Exception for " + in.getPath, e) - } - } - - def convert(javaSource: String, settings: ConversionSettings = ConversionSettings()): String = { - val compilationUnit = JavaParser.parse(new ByteArrayInputStream(javaSource.getBytes(encoding)), encoding) - toScala(compilationUnit, settings) - } - - def toScala(unit: CompilationUnit, settings: ConversionSettings = ConversionSettings()): String = { - if (unit.getImports == null) { - unit.setImports(new ArrayList[ImportDeclaration]()) - } - val transformed = transformers.foldLeft(unit) { case (u,t) => t.transform(u) } - var visitor = new ScalaDumpVisitor(settings) - transformed.accept(visitor, new ScalaDumpVisitor.Context()) - visitor.getSource - } - - private def toOut(inFolderLength: Int, outFolder: File, in: File): File = { - val offset = if (in.getName == "package-info.java") 10 else 5 - new File(outFolder, in.getPath.substring(inFolderLength, in.getPath.length-offset)+".scala") - } - - private def getJavaFiles(file: File): Seq[File] = { - if (file.isDirectory) { - file.listFiles.toSeq - .filter(f => f.isDirectory || f.getName.endsWith(".java")) - .flatMap(f => getJavaFiles(f)) - } else { - if (file.exists) file :: Nil else Nil - } - } - -} diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Enums.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Enums.scala deleted file mode 100644 index ac951819d..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Enums.scala +++ /dev/null @@ -1,68 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import japa.parser.ast.body.ModifierSet -import japa.parser.ast.visitor._ -import java.util.ArrayList -import UnitTransformer._ - -object Enums extends Enums - -/** - * Enums converts Java enum type declarations into Scala enumerations - */ -class Enums extends UnitTransformerBase { - - private val enumerationType = new ClassOrInterface("Enumeration") - - private val valType = new ClassOrInterface("Val") - - private val valueType = new ClassOrInterface("Value") - - def transform(cu: CompilationUnit): CompilationUnit = { - cu.accept(this, cu).asInstanceOf[CompilationUnit] - } - - override def visit(n: EnumDecl, arg: CompilationUnit) = { - // transform enums into Scala Enumerations - val clazz = new ClassOrInterfaceDecl() - clazz.setExtends(enumerationType :: Nil) - clazz.setName(n.getName) - clazz.setModifiers(OBJECT) - clazz.setMembers(createMembers(n)) - clazz - } - - private def createMembers(n: EnumDecl): JavaList[BodyDecl] = { - val typeDecl = new ClassOrInterfaceDecl(0, false, n.getName) - typeDecl.setExtends(valType :: Nil) - typeDecl.setImplements(n.getImplements) - typeDecl.setMembers(n.getMembers.filterNot(isStatic)) - - // entries - val ty = new ClassOrInterface(n.getName) - val entries = n.getEntries.map(e => { - val init = new ObjectCreation(null, ty, e.getArgs) - new Field(ModifierSet.FINAL, ty, new Variable(e.getName, init)) }) - - // conversion function - val conversion = new Method(IMPLICIT, ty, "convertValue") - conversion.setBody(new Return(new Cast(ty, "v"))) - conversion.setParameters(new Parameter(valueType, "v") :: Nil) - - entries ::: typeDecl :: n.getMembers.filter(isStatic) ::: conversion :: Nil - } - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Helpers.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Helpers.scala deleted file mode 100644 index 36f4d2ea8..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Helpers.scala +++ /dev/null @@ -1,169 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import java.lang.reflect.Modifier -import japa.parser.ast.body.ModifierSet -import _root_.scala.collection.JavaConversions -import _root_.scala.collection.Set -import java.util.ArrayList - -/** - * Common helper methods for transformers and ScalaDumpVisitor - */ -trait Helpers { - import Types._ - - val PRIVATE = Modifier.PRIVATE - val PROPERTY = 0x00001000 - val LAZY = 0x00002000 - val OBJECT = 0x00004000 - val IMPLICIT = 0x00008000 - - implicit def toRichModifiers(i: Int) = new RichModifiers(i) - - class RichModifiers(i: Int) { - def isAbstract = ModifierSet.isAbstract(i) - def isFinal = ModifierSet.isFinal(i) - def isImplicit = ModifierSet.hasModifier(i, IMPLICIT) - def isLazy = ModifierSet.hasModifier(i, LAZY) - def isNative = ModifierSet.isNative(i) - def isObject = ModifierSet.hasModifier(i, OBJECT) - def isPrivate = ModifierSet.isPrivate(i) - def isProtected = ModifierSet.isProtected(i) - def isProperty = ModifierSet.hasModifier(i, PROPERTY) - def isPublic = ModifierSet.isPublic(i) - def isStatic = ModifierSet.isStatic(i) - def isStrictfp = ModifierSet.isStrictfp(i) - def isSynchronized = ModifierSet.isSynchronized(i) - def isTransient = ModifierSet.isTransient(i) - def isVolatile = ModifierSet.isVolatile(i) - def hasModifier(mod: Int) = ModifierSet.hasModifier(i,mod) - def addModifier(mod: Int) = ModifierSet.addModifier(i,mod) - def removeModifier(mod: Int) = ModifierSet.removeModifier(i,mod) - } - - type WithModifiers = { def getModifiers(): Int ; def setModifiers(v: Int): Unit } - - implicit def toRichWithModifiers(wm: WithModifiers) = new RichWithModifiers(wm) - - class RichWithModifiers(wm: WithModifiers) { - def addModifier(mod: Int): RichWithModifiers = { - wm.setModifiers(ModifierSet.addModifier(wm.getModifiers, mod)) - this - } - def removeModifier(mod: Int): RichWithModifiers = { - wm.setModifiers(ModifierSet.removeModifier(wm.getModifiers, mod)) - this - } - } - - implicit def toRichBlock(b: Block) = new RichBlockStmt(b) - - class RichBlockStmt(b: Block) { - def apply(i: Int) = if (isEmpty) null else b.getStmts.get(i) - def isEmpty = b.getStmts == null || b.getStmts.isEmpty - def add(s: Statement) { - b.setStmts(b.getStmts :+ s) - } - def addAll(s: List[Statement]) { - b.setStmts(b.getStmts ++ s) - } - def remove(s: Statement) { - b.setStmts(b.getStmts.filterNot(_ == s)) - } - def removeAll(s: List[Statement]) { - b.setStmts(b.getStmts.filterNot(s.contains)) - } - def copy(): Block = { - def block = new Block() - def stmts = new ArrayList[Statement]() - stmts.addAll(b.getStmts) - block.setStmts(stmts) - block - } - - def size = if (b.getStmts != null) b.getStmts.size else 0 - } - - //@inline - def isEmpty(col: JavaCollection[_]): Boolean = col == null || col.isEmpty - - def getAssignment(s: Statement): Assign = s match { - case Stmt(a: Assign) => a - case _ => null - } - - // TODO use pattern matching - def getLazyInit(block: Block) = { - block.getStmts.get(0).asInstanceOf[If] - .getThenStmt.asInstanceOf[Block] - .getStmts().get(0).asInstanceOf[ExpressionStmt] - .getExpression.asInstanceOf[Assign] - .getValue - } - - def isLazyCreation(block: Block, f: String): Boolean = block match { - case Block( - If(isnull(field(`f`)), Stmt(field(`f`) set init), null) :: - Return(field(`f`)) :: Nil) => true - case _ => false - } - - def isAssignment(s: Statement): Boolean = s match { - case Stmt(_ set _) => true - case _ => false - } - - def isThisConstructor(s: Statement): Boolean = s match { - case ci: ConstructorInvocation => ci.isThis - case _ => false - } - - def isStatic(member: BodyDecl): Boolean = member match { - case t: ClassOrInterfaceDecl => t.getModifiers.isStatic || t.getModifiers.isObject || t.isInterface - case t: TypeDecl => t.getModifiers.isStatic || t.getModifiers.isObject - case f: Field => f.getModifiers.isStatic - case m: Method => m.getModifiers.isStatic - case i: Initializer => i.isStatic - case _ => false - } - - def isHashCode(n: Method): Boolean = n match { - case Method("hashCode", Type.Int, Nil, _) => true - case _ => false - } - - def isEquals(n: Method): Boolean = n match { - case Method("equals", Type.Boolean,_ :: Nil, _) => true - case _ => false - } - - def isReturnFieldStmt(stmt: Statement): Boolean = stmt match { - case Return(field(_)) => true - case _ => false - } - - def isSetFieldStmt(stmt: Statement): Boolean = stmt match { - case Stmt(_ set _) => true - case _ => false - } - - def isToString(n: Method): Boolean = n match { - case Method("toString", Type.String, Nil, _) => true - case _ => false - } - - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Initializers.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Initializers.scala deleted file mode 100644 index 8ec507113..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Initializers.scala +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import java.util.ArrayList -import UnitTransformer._ - -object Initializers extends Initializers - -/** - * Initializers normalizes initializer blocks - */ -class Initializers extends UnitTransformerBase { - - def transform(cu: CompilationUnit): CompilationUnit = { - cu.accept(this, cu).asInstanceOf[CompilationUnit] - } - - override def visit(ci: ClassOrInterfaceDecl, cu: CompilationUnit): Node = { - val t = super.visit(ci, cu).asInstanceOf[ClassOrInterfaceDecl] - if (t.getMembers == null) { - return t - } - - val initializers = t.getMembers.collect { case i: Initializer => i } - if (!initializers.isEmpty) { - val fields = t.getMembers.collect { case f: Field => f } - val variables = fields.flatMap(_.getVariables).map(v => (v.getId.getName, v)).toMap - - for (i <- initializers) { - i.getBlock.setStmts(i.getBlock.getStmts.filter(_ match { - case Stmt((t: Name) set v) if variables.contains(t.getName) => { - variables(t.getName).setInit(v) - false - } - case _ => true - })) - } - - // remove empty initializers - val emptyInitializerBlocks = initializers.filter(_.getBlock.isEmpty) - t.setMembers( t.getMembers.filterNot(emptyInitializerBlocks.contains) ) - } - t - } - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/ModifierVisitor.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/ModifierVisitor.scala deleted file mode 100644 index f3dee10e7..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/ModifierVisitor.scala +++ /dev/null @@ -1,520 +0,0 @@ -package com.mysema.scalagen - -import japa.parser.ast.BlockComment -import japa.parser.ast.CompilationUnit -import japa.parser.ast.ImportDeclaration -import japa.parser.ast.LineComment -import japa.parser.ast.Node -import japa.parser.ast.PackageDeclaration -import japa.parser.ast.TypeParameter -import japa.parser.ast.body._ -import japa.parser.ast.expr._ -import japa.parser.ast.stmt._ -import japa.parser.ast.`type`.ClassOrInterfaceType -import japa.parser.ast.`type`.PrimitiveType -import japa.parser.ast.`type`.ReferenceType -import japa.parser.ast.`type`.Type -import japa.parser.ast.`type`.VoidType -import japa.parser.ast.`type`.WildcardType -import japa.parser.ast.visitor.GenericVisitor -import java.util.{ArrayList, Collections} -import com.mysema.scalagen.ast.BeginClosureExpr - -/** - * - */ -abstract class ModifierVisitor[A] extends GenericVisitor[Node, A] { - - protected def filter[T <: Node](node: T, arg: A): T = { - if (node != null) node.accept(this, arg).asInstanceOf[T] else node - } - - protected def filter[T <: Node](list: JavaList[T], arg: A): JavaList[T] = { - if (list == null) { - return null - } else if (list.isEmpty) { - Collections.emptyList[T]() - } else { - //list.map(_.accept(this, arg).asInstanceOf[T]).filter(_ != null) - val rv = new ArrayList[T](list.size) - val it = list.iterator() - while (it.hasNext) { - val node = it.next().accept(this, arg).asInstanceOf[T] - if (node != null) rv.add(node) - } - rv - } - } - - def visitName(name: String, arg: A) = name - - def visit(n: AnnotationDeclaration, arg: A) : Node = { - val rv = new AnnotationDeclaration() - rv.setAnnotations(filter(n.getAnnotations, arg)) - rv.setJavaDoc(filter(n.getJavaDoc, arg)) - rv.setMembers(filter(n.getMembers, arg)) - rv.setModifiers(n.getModifiers) - rv.setName(n.getName) - rv - } - - def visit(n: AnnotationMemberDeclaration, arg: A): Node = { - val rv = new AnnotationMemberDeclaration() - rv.setAnnotations(filter(n.getAnnotations, arg)) - rv.setDefaultValue(filter(n.getDefaultValue, arg)) - rv.setJavaDoc(filter(n.getJavaDoc, arg)) - rv.setModifiers(n.getModifiers) - rv.setName(n.getName) - rv.setType(filter(n.getType, arg)) - - n - } - - def visit(n: ArrayAccessExpr, arg: A): Node = { - val rv = new ArrayAccessExpr() - rv.setIndex(filter(n.getIndex, arg)) - rv.setName(filter(n.getName, arg)) - rv - } - - def visit(n: ArrayCreationExpr, arg: A): Node = { - val rv = new ArrayCreationExpr() - rv.setArrayCount(n.getArrayCount) - rv.setDimensions(filter(n.getDimensions, arg)) - rv.setInitializer(filter(n.getInitializer, arg)) - rv.setType(filter(n.getType, arg)) - rv - } - - def visit(n: ArrayInitializerExpr, arg: A): Node = { - val rv = new ArrayInitializerExpr() - rv.setValues(filter(n.getValues, arg)) - rv - } - - def visit(n: AssertStmt, arg: A): Node = { - val rv = new AssertStmt() - rv.setCheck(filter(n.getCheck, arg)) - rv.setMessage(filter(n.getMessage, arg)) - rv - } - - def visit(n: AssignExpr, arg: A): Node = { - val rv = new AssignExpr() - rv.setOperator(n.getOperator) - rv.setTarget(filter(n.getTarget, arg)) - rv.setValue(filter(n.getValue, arg)) - rv - } - - def visit(n: BinaryExpr, arg: A): Node = { - val rv = new BinaryExpr() - rv.setOperator(n.getOperator) - rv.setLeft(filter(n.getLeft, arg)) - rv.setRight(filter(n.getRight, arg)) - rv - } - - def visit(n: BlockStmt, arg: A): Node = new BlockStmt(filter(n.getStmts, arg)) - - def visit(n: BooleanLiteralExpr, arg: A): Node = new BooleanLiteralExpr(n.getValue) - - def visit(n: BreakStmt, arg: A): Node = new BreakStmt(n.getId) - - def visit(n: CastExpr, arg: A): Node = { - new CastExpr(filter(n.getType, arg), filter(n.getExpr, arg)) - } - - def visit(n: CatchClause, arg: A): Node = { - new CatchClause(filter(n.getExcept, arg), filter(n.getCatchBlock, arg)) - } - - def visit(n: CharLiteralExpr, arg: A): Node = new CharLiteralExpr(n.getValue) - - def visit(n: ClassExpr, arg: A): Node = new ClassExpr(filter(n.getType, arg)) - - def visit(n: ClassOrInterfaceDeclaration, arg: A): Node = { - val rv = new ClassOrInterfaceDeclaration() - rv.setAnnotations(filter(n.getAnnotations, arg)) - rv.setExtends(filter(n.getExtends, arg)) - rv.setImplements(filter(n.getImplements, arg)) - rv.setInterface(n.isInterface) - rv.setJavaDoc(filter(n.getJavaDoc, arg)) - rv.setMembers(filter(n.getMembers, arg)) - rv.setModifiers(n.getModifiers) - rv.setName(n.getName) - rv.setTypeParameters(filter(n.getTypeParameters, arg)) - rv - } - - def visit(n: ClassOrInterfaceType, arg: A): Node = { - val rv = new ClassOrInterfaceType() - rv.setName(n.getName) - rv.setScope(filter(n.getScope, arg)) - rv.setTypeArgs(filter(n.getTypeArgs, arg)) - rv - } - - def visit(n: CompilationUnit, arg: A): Node = { - val rv = new CompilationUnit() - rv.setPackage(filter(n.getPackage, arg)) - rv.setImports(filter(n.getImports, arg)) - rv.setTypes(filter(n.getTypes, arg)) - rv - } - - def visit(n: ConditionalExpr, arg: A): Node = { - val rv = new ConditionalExpr() - rv.setCondition(filter(n.getCondition, arg)) - rv.setThenExpr(filter(n.getThenExpr, arg)) - rv.setElseExpr(filter(n.getElseExpr, arg)) - rv - } - - def visit(n: ConstructorDeclaration, arg: A): Node = { - val rv = new ConstructorDeclaration() - rv.setAnnotations(filter(n.getAnnotations, arg)) - rv.setBlock(filter(n.getBlock, arg)) - rv.setJavaDoc(filter(n.getJavaDoc, arg)) - rv.setModifiers(n.getModifiers) - rv.setName(n.getName) - rv.setParameters(filter(n.getParameters, arg)) - rv.setThrows(filter(n.getThrows, arg)) - rv.setTypeParameters(filter(n.getTypeParameters, arg)) - rv - } - - def visit(n: ContinueStmt, arg: A): Node = new ContinueStmt(n.getId) - - def visit(n: DoStmt, arg: A): Node = { - val rv = new DoStmt() - rv.setBody(filter(n.getBody, arg)) - rv.setCondition(filter(n.getCondition, arg)) - rv - } - - def visit(n: DoubleLiteralExpr, arg: A): Node = new DoubleLiteralExpr(n.getValue) - - def visit(n: EmptyMemberDeclaration, arg: A): Node = { - new EmptyMemberDeclaration(filter(n.getJavaDoc, arg)) - } - - def visit(n: EmptyStmt, arg: A): Node = new EmptyStmt() - - def visit(n: EmptyTypeDeclaration, arg: A): Node = { - new EmptyTypeDeclaration(filter(n.getJavaDoc, arg)) - } - - def visit(n: EnclosedExpr, arg: A): Node = { - new EnclosedExpr(filter(n.getInner, arg)) - } - - def visit(n: EnumConstantDeclaration, arg: A): Node = { - val rv = new EnumConstantDeclaration() - rv.setAnnotations(filter(n.getAnnotations, arg)) - rv.setArgs(filter(n.getArgs, arg)) - rv.setClassBody(filter(n.getClassBody, arg)) - rv.setJavaDoc(filter(n.getJavaDoc, arg)) - rv.setName(n.getName) - rv - } - - def visit(n: EnumDeclaration, arg: A): Node = { - val rv = new EnumDeclaration() - rv.setAnnotations(filter(n.getAnnotations, arg)) - rv.setEntries(filter(n.getEntries, arg)) - rv.setImplements(filter(n.getImplements, arg)) - rv.setJavaDoc(filter(n.getJavaDoc, arg)) - rv.setMembers(filter(n.getMembers, arg)) - rv.setModifiers(n.getModifiers) - rv.setName(n.getName) - rv - } - - def visit(n: ExplicitConstructorInvocationStmt, arg: A): Node = { - val rv = new ExplicitConstructorInvocationStmt() - rv.setArgs(filter(n.getArgs, arg)) - rv.setExpr(filter(n.getExpr, arg)) - rv.setThis(n.isThis) - rv.setTypeArgs(filter(n.getTypeArgs, arg)) - rv - } - - def visit(n: ExpressionStmt, arg: A): Node = { - new ExpressionStmt(filter(n.getExpression, arg)) - } - - def visit(n: FieldAccessExpr, arg: A): Node = { - new FieldAccessExpr(filter(n.getScope, arg), visitName(n.getField, arg)) - } - - def visit(n: FieldDeclaration, arg: A): Node = { - val rv = new FieldDeclaration() - rv.setAnnotations(filter(n.getAnnotations, arg)) - rv.setJavaDoc(filter(n.getJavaDoc, arg)) - rv.setModifiers(n.getModifiers) - rv.setType(filter(n.getType, arg)) - rv.setVariables(filter(n.getVariables, arg)) - rv - } - - def visit(n: ForeachStmt, arg: A): Node = { - val rv = new ForeachStmt() - rv.setVariable(filter(n.getVariable, arg)) - rv.setIterable(filter(n.getIterable, arg)) - rv.setBody(filter(n.getBody, arg)) - rv - } - - def visit(n: ForStmt, arg: A): Node = { - val rv = new ForStmt() - rv.setInit(filter(n.getInit, arg)) - rv.setCompare(filter(n.getCompare, arg)) - rv.setUpdate(filter(n.getUpdate, arg)) - rv.setBody(filter(n.getBody, arg)) - rv - } - - def visit(n: IfStmt, arg: A): Node = { - val rv = new IfStmt() - rv.setCondition(filter(n.getCondition, arg)) - rv.setThenStmt(filter(n.getThenStmt, arg)) - rv.setElseStmt(filter(n.getElseStmt, arg)) - rv - } - - def visit(n: ImportDeclaration, arg: A): Node = { - new ImportDeclaration(n.getName, n.isStatic, n.isAsterisk) - } - - def visit(n: InitializerDeclaration, arg: A): Node = { - val rv = new InitializerDeclaration() - rv.setAnnotations(filter(n.getAnnotations, arg)) - rv.setBlock(filter(n.getBlock, arg)) - rv.setJavaDoc(filter(n.getJavaDoc, arg)) - rv.setStatic(n.isStatic) - rv - } - - def visit(n: InstanceOfExpr, arg: A): Node = { - val rv = new InstanceOfExpr() - rv.setExpr(filter(n.getExpr, arg)) - rv.setType(filter(n.getType, arg)) - rv - } - - def visit(n: IntegerLiteralExpr, arg: A): Node = new IntegerLiteralExpr(n.getValue) - - def visit(n: IntegerLiteralMinValueExpr, arg: A): Node = new IntegerLiteralMinValueExpr() - - def visit(n: JavadocComment, arg: A): Node = new JavadocComment(n.getContent) - - def visit(n: LabeledStmt, arg: A): Node = new LabeledStmt(n.getLabel, filter(n.getStmt, arg)) - - def visit(n: LongLiteralExpr, arg: A): Node = new LongLiteralExpr(n.getValue) - - def visit(n: LongLiteralMinValueExpr, arg: A): Node = new LongLiteralMinValueExpr() - - def visit(n: MarkerAnnotationExpr, arg: A): Node = { - new MarkerAnnotationExpr(filter(n.getName, arg)) - } - - def visit(n: MemberValuePair, arg: A): Node = { - new MemberValuePair(n.getName, filter(n.getValue, arg)) - } - - def visit(n: MethodCallExpr, arg: A): Node = { - val rv = new MethodCallExpr() - rv.setArgs(filter(n.getArgs, arg)) - rv.setName(n.getName) - rv.setScope(filter(n.getScope, arg)) - rv.setTypeArgs(filter(n.getTypeArgs, arg)) - rv - } - - def visit(n: MethodDeclaration, arg: A): Node = { - val rv = new MethodDeclaration() - rv.setAnnotations(filter(n.getAnnotations, arg)) - rv.setArrayCount(n.getArrayCount) - rv.setBody(filter(n.getBody, arg)) - rv.setJavaDoc(filter(n.getJavaDoc, arg)) - rv.setModifiers(n.getModifiers) - rv.setName(n.getName) - rv.setParameters(filter(n.getParameters, arg)) - rv.setThrows(filter(n.getThrows, arg)) - rv.setType(filter(n.getType, arg)) - rv.setTypeParameters(filter(n.getTypeParameters, arg)) - rv - } - - def visit(n: NameExpr, arg: A): Node = n match { - case closure: BeginClosureExpr => closure - case _ => new NameExpr(visitName(n.getName, arg)) - } - - def visit(n: NormalAnnotationExpr, arg: A): Node = { - val rv = new NormalAnnotationExpr() - rv.setName(filter(n.getName, arg)) - rv.setPairs(filter(n.getPairs, arg)) - rv - } - - def visit(n: NullLiteralExpr, arg: A): Node = new NullLiteralExpr() - - def visit(n: ObjectCreationExpr, arg: A): Node = { - val rv = new ObjectCreationExpr() - rv.setAnonymousClassBody(filter(n.getAnonymousClassBody, arg)) - rv.setArgs(filter(n.getArgs, arg)) - rv.setScope(filter(n.getScope, arg)) - rv.setType(filter(n.getType, arg)) - rv.setTypeArgs(filter(n.getTypeArgs, arg)) - rv - } - - def visit(n: PackageDeclaration, arg: A): Node = { - val rv = new PackageDeclaration() - rv.setAnnotations(filter(n.getAnnotations, arg)) - rv.setName(filter(n.getName, arg)) - rv - } - - def visit(n: Parameter, arg: A): Node = { - val rv = new Parameter() - visit(n, rv, arg) - rv.setType(filter(n.getType, arg)) - rv.setVarArgs(n.isVarArgs) - rv - } - - def visit(n: MultiTypeParameter, arg: A): Node = { - val rv = new MultiTypeParameter() - visit(n, rv, arg) - rv.setTypes(n.getTypes().map(tpe => filter(tpe, arg))) - rv - } - - def visit(n: BaseParameter, rv: BaseParameter, arg: A): Node = { - rv.setAnnotations(filter(n.getAnnotations, arg)) - rv.setId(filter(n.getId, arg)) - rv.setModifiers(n.getModifiers) - rv - } - - def visit(n: PrimitiveType, arg: A): Node = new PrimitiveType(n.getType) - - def visit(n: QualifiedNameExpr, arg: A): Node = { - val rv = new QualifiedNameExpr() - rv.setName(n.getName) - rv.setQualifier(filter(n.getQualifier, arg)) - rv - } - - def visit(n: ReferenceType, arg: A): Node = { - new ReferenceType(filter(n.getType, arg), n.getArrayCount) - } - - def visit(n: ReturnStmt, arg: A): Node = { - new ReturnStmt(filter(n.getExpr, arg)) - } - - def visit(n: SingleMemberAnnotationExpr, arg: A): Node = { - new SingleMemberAnnotationExpr(filter(n.getName, arg), filter(n.getMemberValue, arg)) - } - - def visit(n: StringLiteralExpr, arg: A): Node = new StringLiteralExpr(n.getValue) - - def visit(n: SuperExpr, arg: A): Node = { - new SuperExpr(filter(n.getClassExpr, arg)) - } - - def visit(n: SwitchEntryStmt, arg: A): Node = { - val rv = new SwitchEntryStmt() - rv.setLabel(filter(n.getLabel, arg)) - rv.setStmts(filter(n.getStmts, arg)) - rv - } - - def visit(n: SwitchStmt, arg: A): Node = { - val rv = new SwitchStmt() - rv.setSelector(filter(n.getSelector, arg)) - rv.setEntries(filter(n.getEntries, arg)) - rv - } - - def visit(n: SynchronizedStmt, arg: A): Node = { - val rv = new SynchronizedStmt() - rv.setExpr(filter(n.getExpr, arg)) - rv.setBlock(filter(n.getBlock, arg)) - rv - } - - def visit(n: ThisExpr, arg: A): Node = { - new ThisExpr(filter(n.getClassExpr, arg)) - } - - def visit(n: ThrowStmt, arg: A): Node = { - new ThrowStmt(filter(n.getExpr, arg)) - } - - def visit(n: TryStmt, arg: A): Node = { - val rv = new TryStmt() - rv.setResources(filter(n.getResources, arg)) - rv.setTryBlock(filter(n.getTryBlock, arg)) - rv.setCatchs(filter(n.getCatchs, arg)) - rv.setFinallyBlock(filter(n.getFinallyBlock, arg)) - rv - } - - def visit(n: TypeDeclarationStmt, arg: A): Node = { - new TypeDeclarationStmt(filter(n.getTypeDeclaration, arg)) - } - - def visit(n: TypeParameter, arg: A): Node = { - new TypeParameter(n.getName, filter(n.getTypeBound, arg)) - } - - def visit(n: UnaryExpr, arg: A): Node = { - new UnaryExpr(filter(n.getExpr, arg), n.getOperator) - } - - def visit(n: VariableDeclarationExpr, arg: A): Node = { - val rv = new VariableDeclarationExpr() - rv.setAnnotations(filter(n.getAnnotations, arg)) - rv.setModifiers(n.getModifiers) - rv.setType(filter(n.getType, arg)) - rv.setVars(filter(n.getVars, arg)) - rv - } - - def visit(n: VariableDeclarator, arg: A): Node = { - new VariableDeclarator(filter(n.getId, arg), filter(n.getInit, arg)) - } - - def visit(n: VariableDeclaratorId, arg: A): Node = { - val rv = new VariableDeclaratorId() - rv.setArrayCount(n.getArrayCount) - rv.setName(visitName(n.getName, arg)) - rv - } - - def visit(n: VoidType, arg: A): Node = new VoidType() - - def visit(n: WhileStmt, arg: A): Node = { - val rv = new WhileStmt() - rv.setCondition(filter(n.getCondition, arg)) - rv.setBody(filter(n.getBody, arg)) - rv - } - - def visit(n: WildcardType, arg: A): Node = { - val rv = new WildcardType() - rv.setExtends(filter(n.getExtends, arg)) - rv.setSuper(filter(n.getSuper, arg)) - rv - } - - def visit(n: BlockComment, arg: A): Node = new BlockComment(n.getContent) - - def visit(n: LineComment, arg: A): Node = new LineComment(n.getContent) - -} diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Primitives.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Primitives.scala deleted file mode 100644 index f763c3bd1..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Primitives.scala +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import java.util.ArrayList -import UnitTransformer._ -import japa.parser.ast.expr._ - -object Primitives extends Primitives - -/** - * Primitives modifies primitive type related constants and method calls - */ -class Primitives extends UnitTransformerBase { - - private val TRUE = new BooleanLiteral(true) - - private val FALSE = new BooleanLiteral(false) - - private val primitives = Set("Boolean","Byte","Char","Double","Float","Integer","Long","Short") - - def transform(cu: CompilationUnit): CompilationUnit = { - cu.accept(this, cu).asInstanceOf[CompilationUnit] - } - - override def visit(n: FieldAccess, arg: CompilationUnit): Node = n match { - case FieldAccess(str("Boolean"), "TRUE") => TRUE - case FieldAccess(str("Boolean"), "FALSE") => FALSE - case _ => super.visit(n, arg) - } - -// override def visit(n: MethodCall, arg: CompilationUnit): Node = n match { -// case MethodCall(str(scope), "valueOf", a :: Nil) => a.accept(this, arg) -// case _ => super.visit(n, arg) -// } - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Properties.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Properties.scala deleted file mode 100644 index 0b4918f0c..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Properties.scala +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import japa.parser.ast.body.ModifierSet -import java.util.ArrayList -import com.mysema.scala.BeanUtils -import UnitTransformer._ - -object Properties extends Properties - -/** - * Properties turns field + accessor combinations into annotated - * Scala properties - */ -class Properties extends UnitTransformerBase { - - def transform(cu: CompilationUnit): CompilationUnit = { - cu.accept(this, cu).asInstanceOf[CompilationUnit] - } - - override def visit(n: ClassOrInterfaceDecl, cu: CompilationUnit): ClassOrInterfaceDecl = { - val t = super.visit(n, cu).asInstanceOf[ClassOrInterfaceDecl] - - // accessors - val getters = t.getMembers.collect { case m: Method => m } - .filter(m => isGetter(m)) - .map(m => (m.getName,m)).toMap - - // fields with accessors - val fields = t.getMembers.collect { case f: Field => f } - .filter(_.getModifiers.isPrivate) - .flatMap( f => f.getVariables.map( v => (v.getId.getName,v,f) )) - .filter { case (name,_,_) => getters.contains(name) } - - // remove accessors - for ( (name, variable, field) <- fields) { - var getter = getters(name) - val body = getter.getBody - if (getter.getModifiers.isAbstract) { - t.setMembers(t.getMembers.filterNot(_ == getter)) - field.removeModifier(PRIVATE) - } else if (isReturnFieldStmt(body(0))) { - //t.getMembers.remove(getter) - t.setMembers(t.getMembers.filterNot(_ == getter)) - field.setModifiers(getter.getModifiers) - } else if (isLazyCreation(body,name)) { - //t.getMembers.remove(getter) - t.setMembers(t.getMembers.filterNot(_ == getter)) - variable.setInit(getLazyInit(body)) - field.setModifiers(getter.getModifiers - .addModifier(LAZY).addModifier(ModifierSet.FINAL)) - } - } - t - } - - private def isGetter(method: Method): Boolean = method match { - case Method(n, t, Nil, Block(_ :: rest)) if !t.isInstanceOf[VoidType] => true - case _ => false - } - -} diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/RemoveAsserts.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/RemoveAsserts.scala deleted file mode 100644 index 2c24e41b5..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/RemoveAsserts.scala +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import java.util.ArrayList -import UnitTransformer._ - -object RemoveAsserts extends RemoveAsserts - -/** - * RemoveAsserts unwraps assertion method call - */ -class RemoveAsserts extends UnitTransformerBase { - - private val methods = Set("hasLength","hasText","notEmpty","notNull") - - def transform(cu: CompilationUnit): CompilationUnit = { - cu.accept(this, cu).asInstanceOf[CompilationUnit] - } - - // TODO : don't remove method calls when used as statements - - override def visit(n: MethodCall, arg: CompilationUnit) = n match { - case MethodCall(str("Assert"), _, a :: rest) => a.accept(this, arg) - case _ => super.visit(n, arg) - } - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Rename.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Rename.scala deleted file mode 100644 index 9a69145bc..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Rename.scala +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import japa.parser.ast.body.ModifierSet -import java.util.ArrayList -import UnitTransformer._ - -class RenameTransformer(replacements: Map[String, String]) extends UnitTransformerBase { - - def transform(cu: CompilationUnit): CompilationUnit = { - cu.accept(this, cu).asInstanceOf[CompilationUnit] - } - - override def visit(n: Name, arg: CompilationUnit): Node = { - if (replacements.contains(n.getName)) { - new Name(replacements(n.getName)) - } else { - n - } - } - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Rethrows.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Rethrows.scala deleted file mode 100644 index 837d10d72..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Rethrows.scala +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import java.util.ArrayList -import UnitTransformer._ - -object Rethrows extends Rethrows - -/** - * Rethrows unwraps try/catch blocks with simple rethrows - */ -class Rethrows extends UnitTransformerBase { - - def transform(cu: CompilationUnit): CompilationUnit = { - cu.accept(this, cu).asInstanceOf[CompilationUnit] - } - - override def visit(n: Try, arg: CompilationUnit): Node = { - if (n.getFinallyBlock == null && !isEmpty(n.getCatchs) && n.getCatchs.filter(isPrinted).isEmpty) { - extract(super.visit(n.getTryBlock, arg).asInstanceOf[Statement]) - } else { - super.visit(n, arg) - } - } - - private def isPrinted(c: Catch): Boolean = { - val block = c.getCatchBlock() - block.isEmpty || block.size > 1 || (block.size == 1 && !block(0).isInstanceOf[Throw]) - } - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/ScalaDumpVisitor.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/ScalaDumpVisitor.scala deleted file mode 100644 index ef480533b..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/ScalaDumpVisitor.scala +++ /dev/null @@ -1,1604 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import japa.parser.ast._ -import japa.parser.ast.body._ -import japa.parser.ast.expr._ -import japa.parser.ast.stmt._ -import japa.parser.ast.`type`._ -import japa.parser.ast.visitor.VoidVisitor -import java.util.ArrayList -import java.util.HashMap -import java.util.Iterator -import java.util.List -import org.apache.commons.lang3.StringUtils -import japa.parser.ast.visitor.GenericVisitorAdapter -import com.mysema.scalagen.ast.BeginClosureExpr - -object ScalaDumpVisitor { - - private val NL_THRESHOLD = 100 - - private val PARAMETRIZED = Set("Class","Comparable","Enum","Iterable") - - private val UTIL_PARAMETRIZED = Set("Collection","List","Set","Map") - - private val METHOD_REPLACEMENTS = Map("equals"->"==") - - private val SKIPPED_ANNOTATIONS = Set("Override","SuppressWarnings","Nullable") - - private val PRIMITIVES = Map("Boolean"->"Boolean","Byte"->"Byte","Character"->"Char","Double"->"Double", - "Float"->"Float","Integer"->"Int","Long"->"Long","Short"->"Short") - - private val NO_ARGS_SHORT = Set("toString","asc","desc","hashCode","hasNext","keys","keySet","length","size","values") - - private val SHORT_FORM = Set("eq","equals","gt","lt","ne","query","until","!=") - - private val RESERVED = Set("def","match","object","type","val","var") - - private val JAVA_TYPES = Set("Iterable") - - private val DEFAULTS = Map( - PrimitiveType.Primitive.Boolean -> "false", - PrimitiveType.Primitive.Byte -> "0", - PrimitiveType.Primitive.Char -> "0", - PrimitiveType.Primitive.Double -> "0.0", - PrimitiveType.Primitive.Float -> "0.0f", - PrimitiveType.Primitive.Int -> "0", - PrimitiveType.Primitive.Long -> "0l", - PrimitiveType.Primitive.Short -> "0.0") - - class Context { - var arrayAccess = false - var classOf = false - var label: String = _ - var skip = false - var assignType: Type = _ - var inObjectEquals = false - var returnOn = false - var typeArg = false - var imports = Map[String,String]() - var noUnwrap = Set[Any]() - } - -} - - -/** - * ScalaDumpVisitor is a serializing visitor for CompilationUnit instances - * - */ -class ScalaDumpVisitor(settings: ConversionSettings) extends VoidVisitor[ScalaDumpVisitor.Context] with Helpers { - import ScalaDumpVisitor._ - - private val printer = new SourcePrinter() - - def getSource: String = printer.source - - private def print(node: Node, arg: Context): String = { - val v = new ScalaDumpVisitor(settings) - node.accept(v, arg) - v.getSource - } - - private def printMethodModifiers(m: Int) { - printModifiers(ModifierSet.removeModifier(m, ModifierSet.ABSTRACT)) - } - - private def printModifiers(m: Int) { - val modifiers: RichModifiers = new RichModifiers(m) - if (modifiers.isTransient) { - printer.print("@transient ") - } - if (modifiers.isVolatile) { - printer.print("@volatile ") - } - - if (modifiers.isPrivate) { - printer.print("private ") - } else if (modifiers.isProtected) { - printer.print("protected ") - } else if (modifiers.isPublic) { - } - - if (modifiers.isLazy) { - printer.print("lazy ") - } - - if (modifiers.isImplicit) { - printer.print("implicit ") - } - - if (modifiers.isAbstract) { - printer.print("abstract ") - } - if (modifiers.isStatic) { - // skip - } - if (modifiers.isFinal) { - // skip - } - if (modifiers.isNative) { - printer.print("/* native */ ") - } - if (modifiers.isStrictfp) { - printer.print("/* strictfp */ ") - } - if (modifiers.isSynchronized) { - printer.print("/* synchronized */ ") - } - } - - private def printMembers(members: List[BodyDeclaration], arg: Context) { - for (member <- members) { - printer.printLn() - member.accept(this, arg) - printer.printLn() - } - } - - private def printMemberAnnotations(annotations: List[AnnotationExpr], arg: Context): Boolean = { - var hasOverride = false - if (annotations != null) { - for (a <- annotations) { - if (!SKIPPED_ANNOTATIONS.contains(a.getName.getName)) { - a.accept(this, arg) - printer.printLn() - } else { - hasOverride |= a.getName.getName == "Override" - } - } - } - hasOverride - } - - private def printAnnotations(annotations: List[AnnotationExpr], arg: Context) { - if (annotations != null) { - for (a <- annotations if !SKIPPED_ANNOTATIONS.contains(a.getName.getName)) { - a.accept(this, arg) - printer.print(" ") - } - } - } - - private def printTypeArgs(args: List[Type], arg: Context) { - if (args != null && !args.isEmpty) { - val typeArg = arg.typeArg - arg.typeArg = true - printer.print("[") - var i = args.iterator() - while (i.hasNext) { - var t = i.next() - t.accept(this, arg) - if (i.hasNext) { - printer.print(", ") - } - } - printer.print("]") - arg.typeArg = typeArg - } - } - - private def printTypeParameters(args: List[TypeParameter], arg: Context) { - if (args != null) { - printer.print("[") - var i = args.iterator() - while (i.hasNext) { - var t = i.next() - t.accept(this, arg) - if (i.hasNext) { - printer.print(", ") - } - } - printer.print("]") - } - } - - private def printArguments(args: List[Expression], arg: Context) { - printer.print("(") - if (args != null) { - val i = args.iterator() - while (i.hasNext) { - i.next() match { - case closure: BeginClosureExpr => { - printer.print(closure.params + " => ") - } - case e => { - e.accept(this, arg) - if (i.hasNext) { - printer.print(", ") - } - } - } - - if (i.hasNext && settings.splitLongLines && printer.lineLength > NL_THRESHOLD) { - printer.printLn() - printer.print(" ") - } - } - } - printer.print(")") - } - - private def printJavadoc(javadoc: JavadocComment, arg: Context) { - if (javadoc != null) { - javadoc.accept(this, arg) - } - } - - def visit(n: CompilationUnit, arg: Context) { - if (n.getPackage != null) { - n.getPackage.accept(this, arg) - } - for (i <- n.getImports) { - i.accept(this, arg) - } - - arg.imports = n.getImports - .filter(i => !i.isAsterisk && !i.isStatic) - .map(i => split(i.getName).swap).toMap - - printer.printLn("//remove if not needed") - printer.printLn("import scala.collection.JavaConversions._") - if (hasTryWithResources(n)) { - printer.printLn("import resource._ //use scala-arm from http://jsuereth.com/scala-arm/") - } - printer.printLn() - - if (n.getPackage != null && !isEmpty(n.getPackage.getAnnotations)) { - printMemberAnnotations(n.getPackage.getAnnotations, arg) - printer.printLn("package object " + split(n.getPackage.getName)._2 + " {") - printer.printLn("}") - printer.printLn() - } - - if (n.getTypes != null) { - var i = n.getTypes.iterator() - while (i.hasNext) { - i.next().accept(this, arg) - printer.printLn() - if (i.hasNext) { - printer.printLn() - } - } - } - - arg.imports = Map[String,String]() - } - - private def hasTryWithResources(n: CompilationUnit): Boolean = { - val hasResourcesVisitor = new GenericVisitorAdapter[java.lang.Boolean, Null]() { - override def visit(n: TryStmt, arg: Null): java.lang.Boolean = { - if (n.getResources.isEmpty) null - else true - } - } - Option(n.accept(hasResourcesVisitor, null)).map(_.booleanValue).getOrElse(false) - } - - private def split(name: NameExpr): (String, String) = { - val str = name.toString - val separator = str.lastIndexOf('.') - (str.substring(0,separator), str.substring(separator+1)) - } - - def visit(n: PackageDeclaration, arg: Context) { - printer.print("package ") - if (!isEmpty(n.getAnnotations)) { - printer.print(split(n.getName)._1) - } else { - n.getName.accept(this, arg) - } - printer.printLn() - printer.printLn() - } - - def visit(n: NameExpr, arg: Context) { - visitName(n.getName) - } - - def visitName(name: String) { - if (RESERVED.contains(name)) { - printer.print("`"+name+"`") - } else if (PRIMITIVES.contains(name)) { - printer.print("java.lang."+ name) - } else { - printer.print(name) - } - } - - def visit(n: QualifiedNameExpr, arg: Context) { - n.getQualifier.accept(this, arg) - printer.print(".") - visitName(n.getName) - } - - def visit(n: ImportDeclaration, arg: Context) { - printer.print("import ") - if (n.getName.getName.endsWith(".Array") && !n.isAsterisk) { - val className = n.getName.getName - val pkg = className.substring(0, className.lastIndexOf('.')) - printer.print(pkg + ".{Array => _Array}") - } else { - n.getName.accept(this, arg) - if (n.isAsterisk) { - printer.print("._") - } - } - - printer.printLn() - } - - def visit(n: ClassOrInterfaceDeclaration, arg: Context) { - // TODO : simplify - printJavadoc(n.getJavaDoc, arg) - printMemberAnnotations(n.getAnnotations, arg) - printModifiers(n.getModifiers) - if (n.getModifiers.isObject) { - printer.print("object ") - } else if (n.isInterface) { - printer.print("trait ") - } else { - printer.print("class ") - } - printer.print(n.getName) - printTypeParameters(n.getTypeParameters, arg) - var constr = getFirstConstructor(n.getMembers) - if (constr != null) { - n.setMembers(n.getMembers.filterNot(_ == constr)) - } - var superInvocation: Option[ExplicitConstructorInvocationStmt] = None - if (constr != null) { - if (!isEmpty(constr.getParameters) || !constr.getModifiers.isPublic) { - printConstructor(constr, arg, true) - } - superInvocation = constr.getBlock.getStmts - .collect({ case x: ExplicitConstructorInvocationStmt => x }) - .filter(!_.isThis).headOption - } - var superTypes = new ArrayList[ClassOrInterfaceType]() - if (n.getExtends != null) { - superTypes.addAll(n.getExtends) - } - if (n.getImplements != null) { - superTypes.addAll(n.getImplements) - } - if (settings.splitLongLines && printer.lineLength > 75) { - printer.printLn() - printer.print(" ") - } - if (!superTypes.isEmpty) { - printer.print(" extends ") - var i = superTypes.iterator() - i.next().accept(this, arg) - superInvocation.foreach { s => - constr.getBlock.remove(s) - printArguments(s.getArgs, arg) - } - while (i.hasNext) { - printer.print(" with ") - i.next().accept(this, arg) - } - } - - if (!isEmpty(n.getMembers)) { - printer.printLn(" {") - printer.indent() - printMembers(n.getMembers, arg) - printer.unindent() - printer.print("}") - } - } - - private def getFirstConstructor(members: List[BodyDeclaration]): ConstructorDeclaration = { - if (members == null) { - return null - } - members.collectFirst({ case c: ConstructorDeclaration => c }).getOrElse(null) - } - - def visit(n: EmptyTypeDeclaration, arg: Context) { - printJavadoc(n.getJavaDoc, arg) - } - - def visit(n: JavadocComment, arg: Context) { - printer.printLn("/**") - for (line <- StringUtils.split(n.getContent.trim, '\n')) { - printer.printLn(" " + line.trim) - } - printer.printLn(" */") - } - - def visit(n: ClassOrInterfaceType, arg: Context) { - if (n.getScope != null) { - n.getScope.accept(this, arg) - printer.print(".") - } else if (!arg.classOf && !arg.typeArg && PRIMITIVES.contains(n.getName)) { - // primitive types are favored for class literals and type arguments - printer.print("java.lang.") - } else if (JAVA_TYPES.contains(n.getName)) { - printer.print("java.lang.") - } - if (n.getName == "Object") { - printer.print(if (arg.inObjectEquals || arg.typeArg) "Any" else "AnyRef") - } else if (n.getScope == null && n.getName == "Array") { - // TODO : only if Array import is present - printer.print("_Array") -// } else if (PRIMITIVES.contains(n.getName) && (arg.classOf || arg.typeArg)) { -// printer.print(PRIMITIVES(n.getName)) - } else { - printer.print(n.getName) - } - if (isEmpty(n.getTypeArgs)) { - if (PARAMETRIZED.contains(n.getName)) { - printer.print("[_]") - } else if (UTIL_PARAMETRIZED.contains(n.getName) && - arg.imports.getOrElse(n.getName,"") == "java.util") { - printer.print(if (n.getName == "Map") "[_,_]" else "[_]") - } - } - printTypeArgs(n.getTypeArgs, arg) - } - - def visit(n: TypeParameter, arg: Context) { - printer.print(n.getName) - if (n.getTypeBound != null) { - printer.print(" <: ") - var i = n.getTypeBound.iterator() - while (i.hasNext) { - i.next().accept(this, arg) - if (i.hasNext) { - printer.print(" with ") - } - } - } - } - - def visit(n: PrimitiveType, arg: Context) { - printer.print(n.getType.name) - } - - def visit(n: ReferenceType, arg: Context) { - val typeArg = arg.typeArg - for (i <- 0 until n.getArrayCount) { - printer.print("Array[") - arg.typeArg = true - } - n.getType.accept(this, arg) - arg.typeArg = typeArg - for (i <- 0 until n.getArrayCount) { - printer.print("]") - } - } - - def visit(n: WildcardType, arg: Context) { - printer.print("_") - if (n.getExtends != null) { - printer.print(" <: ") - n.getExtends.accept(this, arg) - } - if (n.getSuper != null) { - printer.print(" >: ") - n.getSuper.accept(this, arg) - } - } - - def visit(n: FieldDeclaration, arg: Context) { - val oldType = arg.assignType - arg.assignType = n.getType - printJavadoc(n.getJavaDoc, arg) - val modifier = if (ModifierSet.isFinal(n.getModifiers)) "val " else "var " - val i = n.getVariables.iterator() - while (i.hasNext) { - var v = i.next() - printMemberAnnotations(n.getAnnotations, arg) - printModifiers(n.getModifiers) - printer.print(modifier) - - v.getId.accept(this, arg) - if (v.getInit == null || modifier != "val ") { - if (v.getId.getName.endsWith("_")) { - printer.print(" ") - } - printer.print(": ") - n.getType.accept(this, arg) - } - if (v.getInit == null) { - printer.print(" = _") - } else { - printer.print(" = ") - v.getInit.accept(this, arg) - } - - if (i.hasNext) { - printer.printLn() - printer.printLn() - } - } - arg.assignType = oldType - } - - def visit(n: VariableDeclarator, arg: Context) { - n.getId.accept(this, arg) - if (n.getInit != null) { - printer.print(" = ") - n.getInit.accept(this, arg) - } - } - - def visit(n: VariableDeclaratorId, arg: Context) { - visitName(n.getName) -// for (i <- 0 until n.getArrayCount) { -// printer.print("[]") -// } - } - - def visit(n: ArrayInitializerExpr, arg: Context) { - printer.print("Array(") - if (n.getValues != null) { - var i = n.getValues.iterator() - while (i.hasNext) { - i.next().accept(this, arg) - if (i.hasNext) { - printer.print(", ") - } - } - } - printer.print(")") - } - - def visit(n: VoidType, arg: Context) { - printer.print("Unit") - } - - def visit(n: ArrayAccessExpr, arg: Context) { - val arrayAccess = arg.arrayAccess - arg.arrayAccess = true - n.getName.accept(this, arg) - arg.arrayAccess = arrayAccess - printer.print("(") - n.getIndex.accept(this, arg) - printer.print(")") - } - - def visit(n: ArrayCreationExpr, arg: Context) { - if (n.getDimensions != null) { - - if (arg.assignType != null) { - printer.print("new ") - arg.assignType.accept(this, arg) - } else { - val max = n.getArrayCount + 1 - printer.print("Array.ofDim[") - for (i <- 0 until max) { - val typeArg = arg.typeArg - arg.typeArg = true - n.getType.accept(this, arg) - arg.typeArg = typeArg - if (i > 0) { - printer.print(",") - } - } - printer.print("]") - } - - printer.print(n.getDimensions.map(print(_,arg)).mkString("(",", ",")")) - } else { - n.getInitializer.accept(this, arg) - } - } - - def visit(n: AssignExpr, arg: Context) { - n.getTarget.accept(this, arg) - printer.print(" ") - import AssignExpr.{Operator => Op} - val symbol = n.getOperator match { - case Op.assign => "=" - case Op.and => "&=" - case Op.or => "|=" - case Op.xor => "^=" - case Op.plus => "+=" - case Op.minus => "-=" - case Op.rem => "%=" - case Op.slash => "/=" - case Op.star => "*=" - case Op.lShift => "<<=" - case Op.rSignedShift => ">>=" - case Op.rUnsignedShift => ">>>=" - } - printer.print(symbol) - printer.print(" ") - n.getValue.accept(this, arg) - } - - def visit(n: BinaryExpr, arg: Context) { - n.getLeft.accept(this, arg) - printer.print(" ") - import BinaryExpr.{Operator => Op} - val symbol = n.getOperator match { - case Op.or => "||" - case Op.and => "&&" - case Op.binOr => "|" - case Op.binAnd => "&" - case Op.xor => "^" - case Op.equals => "==" - case Op.notEquals => "!=" - case Op.less => "<" - case Op.greater => ">" - case Op.lessEquals => "<=" - case Op.greaterEquals => ">=" - case Op.lShift => "<<" - case Op.rSignedShift => ">>" - case Op.rUnsignedShift => ">>>" - case Op.plus => "+" - case Op.minus => "-" - case Op.times => "*" - case Op.divide => "/" - case Op.remainder => "%" - } - printer.print(symbol) - printer.print(" ") - if (settings.splitLongLines && (print(n.getLeft, arg).length > 50 || print(n.getRight, arg).length > 50)) { - printer.printLn() - printer.print(" ") - } - n.getRight.accept(this, arg) - } - - def visit(n: CastExpr, arg: Context) { - n.getExpr.accept(this, arg) - if (n.getType.isInstanceOf[PrimitiveType]) { - printer.print(".to") - n.getType.accept(this, arg) - } else { - printer.print(".asInstanceOf[") - n.getType.accept(this, arg) - printer.print("]") - } - } - - def visit(n: ClassExpr, arg: Context) { - printer.print("classOf[") - arg.classOf = true - n.getType.accept(this, arg) - arg.classOf = false - printer.print("]") - } - - def visit(n: ConditionalExpr, arg: Context) { - printer.print("if (") - n.getCondition.accept(this, arg) - printer.print(") ") - n.getThenExpr.accept(this, arg) - printer.print(" else ") - n.getElseExpr.accept(this, arg) - } - - def visit(n: EnclosedExpr, arg: Context) { - if (n.getInner.isInstanceOf[CastExpr]) { - n.getInner.accept(this, arg) - } else { - printer.print("(") - n.getInner.accept(this, arg) - printer.print(")") - } - } - - def visit(n: FieldAccessExpr, arg: Context) { - n.getScope.accept(this, arg) - printer.print(".") - visitName(n.getField) - } - - def visit(n: InstanceOfExpr, arg: Context) { - n.getExpr.accept(this, arg) - printer.print(".isInstanceOf[") - n.getType.accept(this, arg) - printer.print("]") - } - - def visit(n: CharLiteralExpr, arg: Context) { - printer.print("'") - printer.print(n.getValue) - printer.print("'") - } - - def visit(n: DoubleLiteralExpr, arg: Context) { - printer.print(removeUnderscores(n.getValue)) - } - - def visit(n: IntegerLiteralExpr, arg: Context) { - printer.print(numberValue(n.getValue, "Integer.parseInt")) - } - - def visit(n: LongLiteralExpr, arg: Context) { - printer.print(numberValue(n.getValue, "java.lang.Long.parseLong")) - } - - private def removeUnderscores(n: String) = n.replaceAllLiterally("_", "") - - private def numberValue(n: String, parseMethod: String) = { - var number = removeUnderscores(n) - if (number.startsWith("0b") || number.startsWith("0B")) { - number = number.drop(2) - if (number.endsWith("L") || number.endsWith("l")) { - number = number.dropRight(1) - } - parseMethod + "(\"" + number + "\", 2)" - } else { - number - } - } - - def visit(n: IntegerLiteralMinValueExpr, arg: Context) { - printer.print(n.getValue) - } - - def visit(n: LongLiteralMinValueExpr, arg: Context) { - printer.print(n.getValue) - } - - def visit(n: StringLiteralExpr, arg: Context) { - printer.print("\"") - printer.print(n.getValue) - printer.print("\"") - } - - def visit(n: BooleanLiteralExpr, arg: Context) { - printer.print(String.valueOf(n.getValue)) - } - - def visit(n: NullLiteralExpr, arg: Context) { - printer.print("null") - } - - def visit(n: ThisExpr, arg: Context) { - if (n.getClassExpr != null) { - n.getClassExpr.accept(this, arg) - printer.print(".") - } - printer.print("this") - } - - def visit(n: SuperExpr, arg: Context) { - if (n.getClassExpr != null) { - n.getClassExpr.accept(this, arg) - printer.print(".") - } - printer.print("super") - } - - def visit(n: MethodCallExpr, arg: Context) { - //val split = arg.split - var args = if (n.getArgs == null) 0 else n.getArgs.size - val shortForm = ((SHORT_FORM.contains(n.getName) && args < 2 && !n.getArgs.get(0).isInstanceOf[LiteralExpr]) - || (NO_ARGS_SHORT.contains(n.getName) && args == 0)) - if (n.getScope != null) { - val split = settings.splitLongLines && print(n.getScope, arg).length > 50 - n.getScope.accept(this, arg) - if (split) { - printer.printLn() - printer.print(" ") - } - printer.print(if ((shortForm && args == 1)) " " else ".") - } - if (METHOD_REPLACEMENTS.contains(n.getName)) { - printer.print(METHOD_REPLACEMENTS(n.getName)) - } else { - visitName(n.getName) - } - printTypeArgs(n.getTypeArgs, arg) - if (n.getName == "asList" && n.getScope != null && n.getScope.toString == "Arrays" && args == 1) { - // assume Arrays.asList is called with an array argument - printer.print("(") - n.getArgs().get(0).accept(this, arg) - printer.print(":_*)") - } else if (arg.arrayAccess) { - printArguments(n.getArgs, arg) - } else if (shortForm) { - if (args == 1) { - printer.print(" ") - n.getArgs.get(0).accept(this, arg) - } - } else if (!(n.getName.startsWith("get") || n.getName.startsWith("is")) || args > 0) { - printArguments(n.getArgs, arg) - } - //arg.split = split - } - - def visit(n: ObjectCreationExpr, arg: Context) { - if (n.getScope != null) { - n.getScope.accept(this, arg) - printer.print(".") - } - printer.print("new ") - printTypeArgs(n.getTypeArgs, arg) - n.getType.accept(this, arg) - printArguments(n.getArgs, arg) - if (n.getAnonymousClassBody != null) { - printer.printLn(" {") - printer.indent() - printMembers(n.getAnonymousClassBody, arg) - printer.unindent() - printer.print("}") - } - } - - def visit(n: UnaryExpr, arg: Context) { - import UnaryExpr.{Operator => Op} - - // !x.equals(y) into x != y - if (n.getOperator == Op.not && n.getExpr.isInstanceOf[MethodCallExpr] && - n.getExpr.asInstanceOf[MethodCallExpr].getName == "equals") { - val method = n.getExpr.asInstanceOf[MethodCallExpr] - new MethodCallExpr(method.getScope, "!=", method.getArgs).accept(this, arg) - return - } - - printer.print(n.getOperator match { - case Op.positive => "+" - case Op.negative => "-" - case Op.inverse => "~" - case Op.not => "!" -// case Op.preIncrement => "+= 1" -// case Op.preDecrement => "-= 1" - case _ => "" - }) - if (n.getOperator == Op.posIncrement || n.getOperator == Op.posDecrement) { - printer.print("{") - } - n.getExpr.accept(this, arg) - printer.print(n.getOperator match { - case Op.posIncrement => " += 1" - case Op.posDecrement => " -= 1" - case _ => "" - }) - if (n.getOperator == Op.posIncrement || n.getOperator == Op.posDecrement) { - printer.print("; ") - n.getExpr.accept(this, arg) - printer.print(n.getOperator match { - case Op.posIncrement => " - 1" - case Op.posDecrement => " + 1" - case _ => "" - }) - printer.print("}") - } - - } - - def visit(n: ConstructorDeclaration, arg: Context) { - printConstructor(n, arg, false) - } - - private def printConstructor(n: ConstructorDeclaration, arg: Context, first: Boolean) { - if (!first) { - printJavadoc(n.getJavaDoc, arg) - } - printMemberAnnotations(n.getAnnotations, arg) - if (first && (n.getModifiers.isPrivate || n.getModifiers.isProtected)) { - printer.print(" ") - } - printModifiers(n.getModifiers) - if (!first) { - printer.print("def this") - printTypeParameters(n.getTypeParameters, arg) - } - printer.print("(") - if (n.getParameters != null) { - val lineBreaks = settings.splitLongLines && n.getParameters.size > 3 - val i = n.getParameters.iterator() - while (i.hasNext) { - i.next().accept(this, arg) - if (i.hasNext) { - printer.print(", ") - if (lineBreaks) { - printer.printLn() - printer.print(" ") - } - } - } - } - printer.print(")") - if (!first) { - printer.print(" ") - n.getBlock.accept(this, arg) - } - } - - def visit(n: MethodDeclaration, arg: Context) { - arg.inObjectEquals = n.getName == "equals" && n.getParameters.size == 1 - printJavadoc(n.getJavaDoc, arg) - var hasOverride = printMemberAnnotations(n.getAnnotations, arg) - printMethodModifiers(n.getModifiers) - if (hasOverride || isHashCode(n) || isEquals(n) || isToString(n)) { - printer.print("override ") - } - printer.print("def ") - visitName(n.getName) - printTypeParameters(n.getTypeParameters, arg) - printer.print("(") - if (n.getParameters != null) { - val lineBreaks = settings.splitLongLines && n.getParameters.size > 3 - val i = n.getParameters.iterator() - while (i.hasNext) { - i.next().accept(this, arg) - if (i.hasNext) { - printer.print(", ") - if (lineBreaks) { - printer.printLn() - printer.print(" ") - } - } - } - } - printer.print(")") - if (!(n.getType.isInstanceOf[VoidType]) || n.getBody == null) { - printer.print(": ") - n.getType.accept(this, arg) - } - if (n.getBody != null) { - if (!(n.getType.isInstanceOf[VoidType])) { - printer.print(" = ") - if (n.getBody.getStmts.size == 1 && printer.lineLength < NL_THRESHOLD) { - val str = print(n.getBody.getStmts.get(0), arg) - if (str.length < 40) { - printer.print(str) - } else { - n.getBody.accept(this, arg) - } - } else { - n.getBody.accept(this, arg) - } - } else { - printer.print(" ") - val origUnwrap = arg.noUnwrap - arg.noUnwrap = arg.noUnwrap.+(n.getBody) - n.getBody.accept(this, arg) - arg.noUnwrap = origUnwrap - } - } - } - - def visit(n: Parameter, arg: Context) { - printAnnotations(n.getAnnotations, arg) - printModifiers(n.getModifiers) - if (n.getModifiers.isProperty) { - printer.print(if (n.getModifiers.isFinal) "val " else "var ") - } - n.getId.accept(this, arg) - printer.print(": ") - for (i <- 0 until n.getId.getArrayCount) { - printer.print("Array[") - } - n.getType.accept(this, arg) - for (i <- 0 until n.getId.getArrayCount) { - printer.print("]") - } - if (n.isVarArgs) { - printer.print("*") - } - } - - def visit(n: MultiTypeParameter, arg: Context) { - printAnnotations(n.getAnnotations, arg) - printModifiers(n.getModifiers) - if (n.getModifiers.isProperty) { - printer.print(if (n.getModifiers.isFinal) "val " else "var ") - } - n.getId.accept(this, arg) - - n.getTypes.toList match { - case tpe :: Nil => - printer.print(": ") - tpe.accept(this, arg) - case types => - printer.print(" @ (") - for ((tpe, i) <- types.zipWithIndex) { - val last = i == types.length - 1 - printer.print("_: ") - tpe.accept(this, arg) - if (!last) { - printer.print(" | ") - } - } - printer.print(")") - } - } - - def visit(n: ExplicitConstructorInvocationStmt, arg: Context) { - if (n.isThis) { - printTypeArgs(n.getTypeArgs, arg) - printer.print("this") - } else { - if (n.getExpr != null) { - n.getExpr.accept(this, arg) - printer.print(".") - } - printTypeArgs(n.getTypeArgs, arg) - printer.print("super") - } - printArguments(n.getArgs, arg) - } - - def isTypeInitMatch(n: VariableDeclarationExpr, v: VariableDeclarator) = { - import PrimitiveType.Primitive - val init = v.getInit - if (init.isInstanceOf[LiteralExpr]) { - n.getType match { - case ptype: PrimitiveType => { - ptype.getType match { - case Primitive.Boolean => init.isInstanceOf[BooleanLiteralExpr] - case Primitive.Byte => false - case Primitive.Char => init.isInstanceOf[CharLiteralExpr] - case Primitive.Double => init.isInstanceOf[DoubleLiteralExpr] - case Primitive.Float => false - case Primitive.Int => init.isInstanceOf[IntegerLiteralExpr] - case Primitive.Long => init.isInstanceOf[LongLiteralExpr] - case Primitive.Short => false - } - } - case _ => true - } - } else { - true - } - } - - def visit(n: VariableDeclarationExpr, arg: Context) { - val asParameter = n.getModifiers == -1 - var modifier = if (ModifierSet.isFinal(n.getModifiers)) "val " else "var " - var i = n.getVars.iterator() - while (i.hasNext) { - var v = i.next() - printAnnotations(n.getAnnotations, arg) - if (!asParameter) { - printer.print(modifier) - } - if (v.getInit == null || v.getInit.isInstanceOf[NullLiteralExpr] || !isTypeInitMatch(n, v)){ - v.getId.accept(this, arg) - printer.print(": ") - for (i <- 0 until v.getId.getArrayCount) { - printer.print("Array[") - } - n.getType.accept(this, arg) - for (i <- 0 until v.getId.getArrayCount) { - printer.print("]") - } - if (!asParameter) { - printer.print(" = ") - if (n.getType.isInstanceOf[PrimitiveType]) { - if (v.getInit != null) { - v.getInit.accept(this, arg) - } else { - val ptype = n.getType.asInstanceOf[PrimitiveType] - printer.print(DEFAULTS(ptype.getType)) - } - } else { - printer.print("null") - } - //printer.print(if (v.getInit() == null) "_" else "null") - } - } else { - v.getInit match { - case newObj: ObjectCreationExpr => - if (newObj.getType() != null && (newObj.getType.getTypeArgs() == null || newObj.getType.getTypeArgs.isEmpty)) { - n.getType match { - case ref: ReferenceType => ref.getType match { - case tpe: ClassOrInterfaceType => newObj.getType.setTypeArgs(tpe.getTypeArgs()) - case _ => - } - case _ => - } - } - case _ => - } - v.accept(this, arg) - } - if (i.hasNext) { - printer.printLn() - } - } - } - - def visit(n: TypeDeclarationStmt, arg: Context) { - n.getTypeDeclaration.accept(this, arg) - } - - def visit(n: AssertStmt, arg: Context) { - printer.print("assert(") - n.getCheck.accept(this, arg) - printer.print(")") - if (n.getMessage != null) { - printer.print(" : ") - n.getMessage.accept(this, arg) - } - } - - def visit(n: BlockStmt, arg: Context) { - if (!isEmpty(n.getStmts) - && !arg.noUnwrap.contains(n) - && n.getStmts.size == 1 - && n.getStmts.get(0).isInstanceOf[SwitchStmt]) { - n.getStmts.get(0).accept(this, arg) - return - } - printer.printLn("{") - if (n.getStmts != null) { - printer.indent() - val s = n.getStmts.iterator() - val returnOn = arg.returnOn - def print(stmt: Statement) { - stmt.accept(this,arg) - printer.printLn() - } - while (s.hasNext) { - val stmt = s.next() - arg.returnOn = returnOn || s.hasNext - stmt match { - case b: BlockStmt => b.getStmts.foreach(print) - case _ => print(stmt) - } - } - arg.returnOn = returnOn - printer.unindent() - } - printer.print("}") - } - - def visit(n: LabeledStmt, arg: Context) { - printer.print(n.getLabel) - printer.print(": ") - n.getStmt.accept(this, arg) - } - - def visit(n: EmptyStmt, arg: Context) { - } - - def visit(n: ExpressionStmt, arg: Context) { - n.getExpression.accept(this, arg) - } - - def visit(n: SwitchStmt, arg: Context) { - val oldSkip = arg.skip - arg.skip = false - n.getSelector.accept(this, arg) - printer.printLn(" match {") - if (n.getEntries != null) { - printer.indent() - for (e <- n.getEntries) { - e.accept(this, arg) - if (!arg.skip) { - printer.printLn() - } - } - printer.unindent() - } - printer.print("}") - arg.skip = oldSkip - } - - def visit(n: SwitchEntryStmt, arg: Context) { - if (arg.skip) { - printer.print(" | ") - if (n.getLabel != null) { - n.getLabel.accept(this, arg) - } - } else { - printer.print("case ") - if (n.getLabel != null) { - n.getLabel.accept(this, arg) - } else { - printer.print("_") - } - } - arg.skip = n.getStmts == null - if (n.getStmts != null) { - printer.print(" => ") - if (n.getStmts.size == 1) { - n.getStmts.get(0).accept(this, arg) - } else { - printer.printLn() - printer.indent() - for (s <- n.getStmts) { - s.accept(this, arg) - printer.printLn() - } - printer.unindent() - } - } - } - - def visit(n: BreakStmt, arg: Context) { - printer.print("//break") -// if (n.getId != null) { -// printer.print(" ") -// printer.print(n.getId) -// } - } - - def visit(n: ReturnStmt, arg: Context) { - if (n.getExpr != null) { - if (arg.returnOn) { - printer.print("return ") - } - n.getExpr.accept(this, arg) - } else { - printer.print("return") - } - } - - def visit(n: EnumDeclaration, arg: Context) { - // Java syntax - printJavadoc(n.getJavaDoc, arg) - printMemberAnnotations(n.getAnnotations, arg) - printModifiers(n.getModifiers) - printer.print("enum ") - printer.print(n.getName) - if (n.getImplements != null) { - printer.print(" implements ") - var i = n.getImplements.iterator() - while (i.hasNext) { - i.next().accept(this, arg) - if (i.hasNext) { - printer.print(", ") - } - } - } - printer.printLn(" {") - printer.indent() - if (n.getEntries != null) { - printer.printLn() - var i = n.getEntries.iterator() - while (i.hasNext) { - i.next().accept(this, arg) - if (i.hasNext) { - printer.print(", ") - } - } - } - if (n.getMembers != null) { - printer.printLn(";") - printMembers(n.getMembers, arg) - } else { - if (n.getEntries != null) { - printer.printLn() - } - } - printer.unindent() - printer.print("}") - } - - def visit(n: EnumConstantDeclaration, arg: Context) { - // Java syntax - printJavadoc(n.getJavaDoc, arg) - printMemberAnnotations(n.getAnnotations, arg) - printer.print(n.getName) - if (n.getArgs != null) { - printArguments(n.getArgs, arg) - } - if (n.getClassBody != null) { - printer.printLn(" {") - printer.indent() - printMembers(n.getClassBody, arg) - printer.unindent() - printer.printLn("}") - } - } - - def visit(n: EmptyMemberDeclaration, arg: Context) { - printJavadoc(n.getJavaDoc, arg) - } - - def visit(n: InitializerDeclaration, arg: Context) { - if (n.getBlock.getStmts != null) { - val i = n.getBlock.getStmts.iterator - while (i.hasNext) { - val stmt = i.next() - if (!stmt.isInstanceOf[ExplicitConstructorInvocationStmt]) { - stmt.accept(this, arg) - if (i.hasNext) { - printer.printLn() - printer.printLn() - } - } - } - } - } - - def visit(n: IfStmt, arg: Context) { - printer.print("if (") - n.getCondition.accept(this, arg) - printer.print(") ") - n.getThenStmt.accept(this, arg) - if (n.getElseStmt != null) { - printer.print(" else ") - n.getElseStmt.accept(this, arg) - } - } - - def visit(n: WhileStmt, arg: Context) { - printer.print("while (") - n.getCondition.accept(this, arg) - printer.print(") ") - n.getBody.accept(this, arg) - } - - def visit(n: ContinueStmt, arg: Context) { - printer.print("//continue") -// if (n.getId != null) { -// printer.print(" ") -// printer.print(n.getId) -// } -// printer.print(";") - } - - def visit(n: DoStmt, arg: Context) { - printer.print("do ") - n.getBody.accept(this, arg) - printer.print(" while (") - n.getCondition.accept(this, arg) - printer.print(");") - } - - def visit(n: ForeachStmt, arg: Context) { - printer.print("for (") - n.getVariable.getVars.get(0).accept(this, arg) - printer.print(" <- ") - n.getIterable.accept(this, arg) - - var body = n.getBody - while (isUnwrapped(body)) { - Types.extract(body) match { - case fe: ForeachStmt => { - printer.print("; ") - if (settings.splitLongLines && printer.lineLength > NL_THRESHOLD) { - printer.printLn() - printer.print(" ") - } - fe.getVariable.getVars.get(0).accept(this, arg) - printer.print(" <- ") - fe.getIterable.accept(this, arg) - body = fe.getBody - } - case ifStmt: IfStmt => { - if (settings.splitLongLines && printer.lineLength > NL_THRESHOLD) { - printer.printLn() - printer.print(" ") - } - printer.print(" if ") - ifStmt.getCondition.accept(this, arg) - body = ifStmt.getThenStmt - } - } - } - - printer.print(") ") - body.accept(this, arg) - - } - - private def isUnwrapped(stmt: Statement): Boolean = Types.extract(stmt) match { - case foreach: ForeachStmt => true - case ifStmt: IfStmt => ifStmt.getElseStmt() == null - case _ => false - } - - def visit(n: ForStmt, arg: Context) { - // init - if (n.getInit != null) { - n.getInit.foreach { i => - i.accept(this, arg) - printer.printLn() - } - } - - // comparison - printer.print("while (") - if (n.getCompare != null) { - n.getCompare.accept(this, arg) - } else { - printer.print("true") - } - printer.print(") ") - - if (n.getUpdate != null && n.getBody.isInstanceOf[BlockStmt]) { - // merge updates into block - val block = n.getBody.asInstanceOf[BlockStmt] - block.addAll(n.getUpdate.map(new ExpressionStmt(_))) - block.accept(this, arg) - - } else { - if (n.getUpdate != null) { - printer.print("{") - } - n.getBody.accept(this, arg) - - // update - if (n.getUpdate != null) { - n.getUpdate.foreach { u => - u.accept(this, arg) - printer.printLn() - } - printer.print("}") - } - } - } - - def visit(n: ThrowStmt, arg: Context) { - printer.print("throw ") - n.getExpr.accept(this, arg) - } - - def visit(n: SynchronizedStmt, arg: Context) { - if (n.getExpr != null) { - printer.print("synchronized (") - n.getExpr.accept(this, arg) - printer.print(") ") - } else { - printer.print("synchronized ") - } - n.getBlock.accept(this, arg) - } - - def visit(n: TryStmt, arg: Context) { - val wrapInTry = !isEmpty(n.getCatchs()) || n.getFinallyBlock() != null - if (wrapInTry) { - printer.print("try ") - } - def printResource(rd: VariableDeclarationExpr): Unit = { - for (resource <- rd.getVars()) { - resource.getId.accept(this, arg) - printer.print(" <- managed(") - resource.getInit.accept(this, arg) - printer.print(")") - } - } - - if (!n.getResources.isEmpty) { - if (wrapInTry) { - printer.printLn("{") - printer.indent() - } - printer.print("for ") - if (n.getResources.size == 1) { - printer.print("(") - val rd = n.getResources.get(0) - printResource(rd) - printer.print(")") - } else { - printer.printLn("{") - printer.indent() - for (rd <- n.getResources) { - printResource(rd) - printer.printLn() - } - printer.unindent() - printer.print("} ") - } - n.getTryBlock.accept(this, arg) - if (wrapInTry) { - printer.printLn() - printer.unindent() - printer.print("}") - } - } else { - n.getTryBlock.accept(this, arg) - } - - if (n.getCatchs != null) { - printer.printLn(" catch {") - printer.indent() - for (c <- n.getCatchs) { - c.accept(this, arg) - } - printer.unindent() - printer.print("}") - } - if (n.getFinallyBlock != null) { - printer.print(" finally ") - n.getFinallyBlock.accept(this, arg) - } - } - - def visit(n: CatchClause, arg: Context) { - printer.print("case ") - n.getExcept.accept(this, arg) - printer.print(" => ") - if (n.getCatchBlock.getStmts != null) { - if (n.getCatchBlock.getStmts.size == 1) { - n.getCatchBlock.getStmts.get(0).accept(this, arg); - } else { - n.getCatchBlock.accept(this, arg) - } - } - printer.printLn() - } - - def visit(n: AnnotationDeclaration, arg: Context) { - // Java syntax - printJavadoc(n.getJavaDoc, arg) - printMemberAnnotations(n.getAnnotations, arg) - printModifiers(n.getModifiers) - printer.print("@interface ") - printer.print(n.getName) - printer.printLn(" {") - printer.indent() - if (n.getMembers != null) { - printMembers(n.getMembers, arg) - } - printer.unindent() - printer.print("}") - } - - def visit(n: AnnotationMemberDeclaration, arg: Context) { - // Java syntax - printJavadoc(n.getJavaDoc, arg) - printMemberAnnotations(n.getAnnotations, arg) - printModifiers(n.getModifiers) - visitName(n.getName) - printer.print(": ") - n.getType.accept(this, arg) - if (n.getDefaultValue != null) { - printer.print("= ") - n.getDefaultValue.accept(this, arg) - } - } - - def visit(n: MarkerAnnotationExpr, arg: Context) { - printer.print("@") - n.getName.accept(this, arg) - } - - def visit(n: SingleMemberAnnotationExpr, arg: Context) { - printer.print("@") - n.getName.accept(this, arg) - printer.print("(") - n.getMemberValue.accept(this, arg) - printer.print(")") - } - - def visit(n: NormalAnnotationExpr, arg: Context) { - printer.print("@") - n.getName.accept(this, arg) - printer.print("(") - if (n.getPairs != null) { - var i = n.getPairs.iterator() - while (i.hasNext) { - i.next().accept(this, arg) - if (i.hasNext) { - printer.print(", ") - } - } - } - printer.print(")") - } - - def visit(n: MemberValuePair, arg: Context) { - visitName(n.getName) - printer.print(" = ") - n.getValue.accept(this, arg) - } - - def visit(n: LineComment, arg: Context) { - printer.print("//") - printer.printLn(n.getContent) - } - - def visit(n: BlockComment, arg: Context) { - printer.print("/*") - printer.print(n.getContent) - printer.printLn("*/") - } -} diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/ScalaVersion.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/ScalaVersion.scala deleted file mode 100644 index 8ee666f27..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/ScalaVersion.scala +++ /dev/null @@ -1,28 +0,0 @@ -package com.mysema.scalagen - -import scala.util.{Properties => ScalaProperties} - -sealed abstract class ScalaVersion(val sortOrder: Int) extends Ordered[ScalaVersion] { - def compare(that: ScalaVersion): Int = sortOrder.compare(that.sortOrder) -} - -case object Scala29 extends ScalaVersion(0) - -case object Scala210 extends ScalaVersion(1) - -case object Scala211 extends ScalaVersion(2) - -object ScalaVersion { - lazy val current = { - //we can't use ScalaProperties.scalaVersionNumber because it's new in 2.10 - val scalaVersionNumber = ScalaProperties.versionString.drop("version ".length) - getVersion(scalaVersionNumber) - } - - def getVersion(versionNumberString: String) = { - if (versionNumberString.startsWith("2.9.")) Scala29 - else if (versionNumberString.startsWith("2.10.")) Scala210 - else if (versionNumberString.startsWith("2.11.")) Scala211 - else throw new IllegalArgumentException("Unsupported scala version: " + versionNumberString) - } -} diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/SerialVersionUID.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/SerialVersionUID.scala deleted file mode 100644 index 654ce568e..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/SerialVersionUID.scala +++ /dev/null @@ -1,55 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import java.util.ArrayList -import japa.parser.ast.CompilationUnit -import UnitTransformer._ - -object SerialVersionUID extends SerialVersionUID - -/** - * SerialVersionUID turns serialVersionUID fields into annotations - */ -class SerialVersionUID extends UnitTransformerBase { - - def transform(cu: CompilationUnit): CompilationUnit = { - cu.accept(this, cu).asInstanceOf[CompilationUnit] - } - - override def visit(nn: ClassOrInterfaceDecl, cu: CompilationUnit): ClassOrInterfaceDecl = { - val n = super.visit(nn, cu).asInstanceOf[ClassOrInterfaceDecl] - if (n.getMembers == null) { - return n - } - - val varAndField = n.getMembers.collect { case f: Field => f } - .flatMap { f => f.getVariables.map( v => (v.getId.getName,v,f)) } - .find(_._1 == "serialVersionUID").map(t => (t._2,t._3)) - .getOrElse(null) - - if (varAndField != null) { - //varAndField._2.getVariables.remove(varAndField._1) - varAndField._2.setVariables(varAndField._2.getVariables.filterNot(_ == varAndField._1)) - if (varAndField._2.getVariables.isEmpty) { - //n.getMembers.remove(varAndField._2) - n.setMembers( n.getMembers.filterNot(_ == varAndField._2) ) - } - val value = varAndField._1.getInit - n.setAnnotations(new SingleMemberAnnotation("SerialVersionUID", value) :: n.getAnnotations) - } - n - } - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Setters.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Setters.scala deleted file mode 100644 index e52ee8aa7..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Setters.scala +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import japa.parser.ast.visitor._ -import java.util.ArrayList -import UnitTransformer._ -import com.mysema.scalagen.ast.BeginClosureExpr - -object Setters extends Setters - -class Setters extends UnitTransformerBase { - - private val thisExpr = new This() - - def setterToField(s: String) = { - val name = s.substring(3) - name.charAt(0).toLower + name.substring(1) - } - - def transform(cu: CompilationUnit): CompilationUnit = { - cu.accept(this, cu).asInstanceOf[CompilationUnit] - } - - override def visit(nn: MethodCall, arg: CompilationUnit): Node = { - // replaces setter invocations with field access - val n = super.visit(nn, arg).asInstanceOf[MethodCall] - if (n.getName.startsWith("set") && - (n.getScope == null || n.getScope.isInstanceOf[This]) && - n.getArgs.size == 1) { - val scope = if (n.getScope != null) n.getScope else thisExpr - new Assign( - new FieldAccess(scope, setterToField(n.getName)), - n.getArgs.get(0), - Assign.assign) - } else { - n - } - } - - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/SimpleEquals.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/SimpleEquals.scala deleted file mode 100644 index e24317043..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/SimpleEquals.scala +++ /dev/null @@ -1,108 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import japa.parser.ast.visitor.ModifierVisitorAdapter -import UnitTransformer._ -import java.util.ArrayList - -object SimpleEquals extends SimpleEquals - -/** - * SimpleEquals simplifies equals method implementations - */ -class SimpleEquals extends UnitTransformerBase { - - private val returnFalse: Statement = new Return(new BooleanLiteral(false)) - - private val replacer = new ModifierVisitor[(Name,Name)]() { - - override def visit(n: Block, arg: (Name,Name)) = { - val visited = super.visit(n, arg) - val matched = n match { - case Block(Stmt(VariableDeclaration(_, Variable(newName, init) :: Nil)) :: Nil) if init == arg._1 => newName - case _ => null - } - if (matched != null) { - //n.getStmts.remove(0) - n.setStmts(n.getStmts.drop(1)) - super.visit(n, (new Name(matched),arg._2)) - } else { - super.visit(n, arg) - } - } - - override def visit(n: Enclosed, arg: (Name,Name)) = { - super.visit(n, arg) match { - case Enclosed(n: Name) => n - case o => o - } - } - - override def visit(n: Name, arg: (Name,Name)) = { - if (n == arg._1) arg._2 else n - } - - override def visit(n: Cast, arg: (Name,Name)) = { - if (n.getExpr == arg._1) arg._2 else super.visit(n,arg) - } - } - - def transform(cu: CompilationUnit): CompilationUnit = { - cu.accept(this, cu).asInstanceOf[CompilationUnit] - } - - override def visit(n: Method, arg: CompilationUnit) = { - // transform - // if (obj == this) { true } - // else if (obj.isInstanceOf[Type]) { obj.asInstanceOf[Type].flag == flag } - // else { false } - // into - // obj match { - // case obj: JoinFlag => obj.flag == flag - // case _ => false - // } - n match { - case Method("equals", Type.Boolean, Parameter(name) :: Nil, stmt) => { - val converted = stmt match { - // skip obj == this check - case If(_ === This(_) | This(_) === _, Return(Literal(true)), - If(InstanceOf(_,t), action, Return(Literal(false)))) => createSwitch(name,t, action) - case If(InstanceOf(_,t), action, Return(Literal(false))) => createSwitch(name,t, action) - case Return(InstanceOf(_,t) and cond) => createSwitch(name, t, new Return(cond)) - case _ => null - } - if (converted != null) { - n.setBody(new Block(converted :: Nil)) - } - n - } - case _ => n - } - } - - private def createSwitch(name: String, t: Type, action: Statement): Statement = { - // obj match { - // case obj: JoinFlag => obj.flag == flag - // case _ => false - // } - val selector = new Name(name) - val simplified = action.accept(replacer, (selector,selector)).asInstanceOf[Statement] - val matches = new SwitchEntry(VariableDeclaration(-1,name,t), simplified :: Nil) - val doesnt = new SwitchEntry(null, returnFalse :: Nil) - new Switch(selector, matches :: doesnt :: Nil) - } - - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/SourcePrinter.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/SourcePrinter.scala deleted file mode 100644 index 3b5ac94d2..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/SourcePrinter.scala +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -/** - * @author tiwe - * - */ -class SourcePrinter { - - private var offset = 0 - - private var level = 0 - - private var indented = false - - private val buf = new StringBuilder() - - def indent() { - level += 1 - } - - def unindent() { - level -= 1 - } - - private def makeIndent() { - for (i <- 0 until level) { buf.append(" ") } - } - - def print(arg: String) { - if (!indented) { - makeIndent() - indented = true - } - buf.append(arg) - } - - def printLn(arg: String) { - print(arg) - printLn() - } - - def printLn() { - buf.append("\n") - offset = buf.length - indented = false - } - - def source: String = buf.toString - - def lineLength = buf.length - offset - - override def toString(): String = source - -} diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Synchronized.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Synchronized.scala deleted file mode 100644 index 4d805a5f5..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Synchronized.scala +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import java.util.ArrayList -import japa.parser.ast.CompilationUnit -import UnitTransformer._ -import defs._ -import japa.parser.ast.body.ModifierSet - -object Synchronized extends Synchronized - -/** - * - */ -class Synchronized extends ModifierVisitor[CompilationUnit] with UnitTransformer { - - def transform(cu: CompilationUnit): CompilationUnit = { - cu.accept(this, cu).asInstanceOf[CompilationUnit] - } - - override def visit(nn: Method, arg: CompilationUnit) = { - val n = super.visit(nn, arg).asInstanceOf[Method] - if (n.getModifiers.hasModifier(ModifierSet.SYNCHRONIZED)) { - n.removeModifier(ModifierSet.SYNCHRONIZED) - n.setBody(new SynchronizedStmt(null, n.getBody())) - } - n - } - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Types.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Types.scala deleted file mode 100644 index 0b19958f5..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Types.scala +++ /dev/null @@ -1,335 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import japa.parser.ast.Node -import japa.parser.ast.body._ -import japa.parser.ast.expr._ -import japa.parser.ast.stmt._ -import japa.parser.ast.`type`._ -import japa.parser.ast.visitor.ModifierVisitorAdapter -import japa.parser.ast.CompilationUnit -import japa.parser.ast.ImportDeclaration -import java.util.ArrayList - -object Types extends Types - -/** - * Types contains type aliases and extractor functionality - */ -trait Types { - - def extract(stmt: Statement): Statement = stmt match { - case b: Block => if (b.getStmts != null && b.getStmts.size == 1) b.getStmts.get(0) else b - case _ => stmt - } - - //private def safeToString(obj: AnyRef): String = if (obj != null) obj.toString else null - - private def handle(o: BinaryExpr.Operator, b: BinaryExpr) = { - if (b.getOperator == o) Some(b.getLeft, b.getRight) else None - } - - object str { - def unapply(n: Node) = if (n != null) Some(n.toString) else None - } - - object and { - def unapply(b: Binary) = handle(Binary.and, b) - } - - object or { - def unapply(b: Binary) = handle(Binary.or, b) - } - - object set { - def unapply(a: Assign) = if (a.getOperator == Assign.assign) Some(a.getTarget, a.getValue) else None - } - - object === { - def unapply(b: Binary) = handle(Binary.equals, b) - } - - object incr { - def unapply(u: Unary) = if (u.getOperator.toString.endsWith("Increment")) Some(u.getExpr) else None - } - - object lt { - def unapply(b: Binary) = handle(Binary.less, b) - } - - object field { - def unapply(f: Expression) = f match { - case FieldAccess(str("this"), field) => Some(field) - case Name(field) => Some(field) - case _ => None - } - } - - object isnull { - def unapply(b: Binary) = { - if (b.getOperator == Binary.equals && b.getRight.isInstanceOf[Null]) Some(b.getLeft) - else None - } - } - - object Assign { - val assign = AssignExpr.Operator.assign - def unapply(a: Assign) = Some(a.getOperator, a.getTarget, a.getValue) - } - - object Binary { - val or = BinaryExpr.Operator.or - val and = BinaryExpr.Operator.and - val equals = BinaryExpr.Operator.equals - val notEquals = BinaryExpr.Operator.notEquals - val less = BinaryExpr.Operator.less - val greater = BinaryExpr.Operator.greater - def unapply(b: Binary) = Some(b.getOperator, b.getLeft, b.getRight) - } - - object Block { - //def unapply(b: Block) = Some(if (b != null) toScalaList(b.getStmts) else Nil) - def unapply(s: Statement) = s match { - case b: Block => Some(if (b != null) toScalaList(b.getStmts) else Nil) - case _ => Some(List(s)) - } - } - - object Cast { - def unapply(c: Cast) = Some(c.getExpr, c.getType) - } - - object Catch { - def unapply(c: Catch) = Some(c.getExcept, extract(c.getCatchBlock)) - } - - object ClassOrInterface { - def unapply(c: ClassOrInterfaceDecl) = Some(c.getName, toScalaList(c.getMembers)) - } - - object Conditional { - def unapply(c: Conditional) = Some(c.getCondition, c.getThenExpr, c.getElseExpr) - } - - object Constructor { - def unapply(c: Constructor) = Some(toScalaList(c.getParameters), extract(c.getBlock)) - def unapply(c: ConstructorInvocation) = Some(c.isThis, toScalaList(c.getArgs)) - } - - object Enclosed { - def unapply(e: Enclosed) = Some(e.getInner) - } - - object FieldAccess { - def unapply(f: FieldAccess) = Some(f.getScope, f.getField) - } - - object For { - def unapply(f: For) = Some(toScalaList(f.getInit), f.getCompare, toScalaList(f.getUpdate), extract(f.getBody)) - } - - object Foreach { - def unapply(f: Foreach) = Some(f.getVariable, f.getIterable, extract(f.getBody)) - } - - object If { - def unapply(i: If) = Some(i.getCondition, extract(i.getThenStmt), extract(i.getElseStmt)) - } - - object InstanceOf { - def unapply(i: InstanceOf) = Some(i.getExpr, i.getType) - } - - object Initializer { - def unapply(i: Initializer) = Block.unapply(i.getBlock) - } - - object Literal { - def unapply(l: Literal) = l match { - case b: BooleanLiteral => Some(b.getValue) - } - } - - object Method { - def unapply(m: Method) = Some(m.getName, m.getType, toScalaList(m.getParameters), extract(m.getBody)) - } - - object MethodCall { - def unapply(m: MethodCall) = Some(m.getScope, m.getName, toScalaList(m.getArgs)) - } - - object Name { - def unapply(n: Name) = Some(n.getName) - } - - object Parameter { - def unapply(p: Parameter) = Some(p.getId.getName) - } - - object Return { - def unapply(r: Return) = Some(r.getExpr) - } - - object Stmt { - def unapply(s: ExpressionStmt) = Some(s.getExpression) - } - - object This { - def unapply(t: This) = Some(t.getClassExpr) - } - - object Type { - val Boolean = new PrimitiveType(PrimitiveType.Primitive.Boolean) - val Int = new PrimitiveType(PrimitiveType.Primitive.Int) - val Object = new ReferenceType(new ClassOrInterfaceType("Object")) - val String = new ReferenceType(new ClassOrInterfaceType("String")) - val Void = new VoidType() - } - - object Unary { - val positive = UnaryExpr.Operator.positive - val negative = UnaryExpr.Operator.negative - val preIncrement = UnaryExpr.Operator.preIncrement - val preDecrement = UnaryExpr.Operator.posDecrement - val not = UnaryExpr.Operator.not - val inverse = UnaryExpr.Operator.inverse - val posIncrement = UnaryExpr.Operator.posIncrement - val posDecrement = UnaryExpr.Operator.posDecrement - def unapply(u: Unary) = Some(u.getOperator, u.getExpr) - } - - object Variable { - def unapply(v: VariableDeclarator) = Some(v.getId.getName, v.getInit) - } - - object VariableDeclaration { - def apply(mod: Int, name: String, t: Type): VariableDeclaration = { - val variable = new VariableDeclarator(new VariableDeclaratorId(name)) - new VariableDeclaration(mod, t, variable :: Nil) - } - def unapply(v: VariableDeclaration) = Some(v.getType, toScalaList(v.getVars)) - } - - type Annotation = AnnotationExpr - - type AnnotationDecl = AnnotationDeclaration - - type AnnotationMember = AnnotationMemberDeclaration - - type Assign = AssignExpr - - type Binary = BinaryExpr - - type Block = BlockStmt - - type BodyDecl = BodyDeclaration - - type BooleanLiteral = BooleanLiteralExpr - - type Break = BreakStmt - - type Cast = CastExpr - - type Catch = CatchClause - - type ClassOrInterfaceDecl = ClassOrInterfaceDeclaration - - type ClassOrInterface = ClassOrInterfaceType - - type CompilationUnit = japa.parser.ast.CompilationUnit - - type Conditional = ConditionalExpr - - type Constructor = ConstructorDeclaration - - type ConstructorInvocation = ExplicitConstructorInvocationStmt - - type Enclosed = EnclosedExpr - - type EnumDecl = EnumDeclaration - - type Expression = japa.parser.ast.expr.Expression - - type ExpressionStmt = japa.parser.ast.stmt.ExpressionStmt - - type Field = FieldDeclaration - - type FieldAccess = FieldAccessExpr - - type For = ForStmt - - type Foreach = ForeachStmt - - type If = IfStmt - - type Import = ImportDeclaration - - type InstanceOf = InstanceOfExpr - - type Initializer = InitializerDeclaration - - type Literal = LiteralExpr - - type MarkerAnnotation = MarkerAnnotationExpr - - type Method = MethodDeclaration - - type MethodCall = MethodCallExpr - - type Name = NameExpr - - type Node = japa.parser.ast.Node - - type Null = NullLiteralExpr - - type ObjectCreation = ObjectCreationExpr - - type Parameter = japa.parser.ast.body.Parameter - - type Return = ReturnStmt - - type SingleMemberAnnotation = SingleMemberAnnotationExpr - - type Statement = japa.parser.ast.stmt.Statement - - type Switch = SwitchStmt - - type SwitchEntry = SwitchEntryStmt - - type SynchronizedStmt = japa.parser.ast.stmt.SynchronizedStmt - - type This = ThisExpr - - type Throw = ThrowStmt - - type Try = TryStmt - - type Type = japa.parser.ast.`type`.Type - - type TypeDecl = japa.parser.ast.body.TypeDeclaration - - type Unary = UnaryExpr - - type Variable = VariableDeclarator - - type VariableDeclaration = VariableDeclarationExpr - - //type VariableDeclarator = japa.parser.ast.body.VariableDeclarator - - type VariableDeclaratorId = japa.parser.ast.body.VariableDeclaratorId - - type VoidType = japa.parser.ast.`type`.VoidType - -} diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Underscores.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Underscores.scala deleted file mode 100644 index b3fb4f0bb..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/Underscores.scala +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import java.util.ArrayList -import japa.parser.ast.CompilationUnit -import UnitTransformer._ - -object Underscores extends Underscores - -/** - * Underscores strips off underscore prefixes from field names with related Bean properties - */ -class Underscores extends UnitTransformerBase with BeanHelpers { - - private val nameReplacer = new ModifierVisitor[Set[String]] { - - override def visitName(n: String, arg: Set[String]): String = { - if (arg.contains(n)) n.substring(1) else n - } - } - - def transform(cu: CompilationUnit): CompilationUnit = { - cu.accept(this, cu).asInstanceOf[CompilationUnit] - } - - override def visit(n: ClassOrInterfaceDecl, cu: CompilationUnit): Node = { - val getters = n.getMembers.collect { case m: Method => m } - .filter(m => isBeanGetter(m) || isBooleanBeanGetter(m)) - .map(getProperty) - - val variables = n.getMembers.collect { case f: Field => f } - .flatMap( _.getVariables) - .map(_.getId.getName) - .filter(n => n.startsWith("_") && getters.contains(n.substring(1))) - .toSet - - n.accept(nameReplacer, variables) - } - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/UnitTransformer.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/UnitTransformer.scala deleted file mode 100644 index 03a907480..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/UnitTransformer.scala +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import japa.parser.ast.Node -import japa.parser.ast.body._ -import japa.parser.ast.expr._ -import japa.parser.ast.stmt._ -import japa.parser.ast.`type`._ -import japa.parser.ast.visitor.ModifierVisitorAdapter -import japa.parser.ast.CompilationUnit -import japa.parser.ast.ImportDeclaration -import java.util.ArrayList - -object UnitTransformer extends Helpers with Types { - - @inline - implicit def toNameExpr(s: String) = new NameExpr(s) - - @inline - implicit def toVariableDeclaratorId(s: String) = new VariableDeclaratorId(s) - - @inline - implicit def toBlock(s: Statement) = new Block(s :: Nil) - - private def safeToString(obj: AnyRef): String = if (obj != null) obj.toString else null - - //val BOOLEAN_BEAN_PROPERTY_IMPORT = new Import("scala.reflect.BooleanBeanProperty", false, false) - - val BEAN_PROPERTY = new MarkerAnnotation("BeanProperty") - - val BOOLEAN_BEAN_PROPERTY = new MarkerAnnotation("BooleanBeanProperty") - - abstract class UnitTransformerBase extends ModifierVisitor[CompilationUnit] with UnitTransformer { - - override def visit(n: CompilationUnit, arg: CompilationUnit): Node = { - val rv = new CompilationUnit() - rv.setPackage(filter(n.getPackage, arg)) - rv.setImports(filter(n.getImports, arg)) - // arg is replaced with converted instance here - rv.setTypes(filter(n.getTypes, rv)) - rv - } - } - -} - -/** - * @author tiwe - * - */ -trait UnitTransformer { - - def transform(cu: CompilationUnit): CompilationUnit - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/VarToVal.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/VarToVal.scala deleted file mode 100644 index 68eee195f..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/VarToVal.scala +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import java.util.ArrayList -import japa.parser.ast.CompilationUnit -import UnitTransformer._ -import defs._ -import japa.parser.ast.body.ModifierSet - -object VarToVal extends VarToVal - -object defs { - type Vars = List[Map[String,VariableDeclaration]] -} - -/** - * VarToVal changes var to val if no reassignments are done - */ -class VarToVal extends ModifierVisitor[Vars] with UnitTransformer { - - private val operators = Set(Unary.posDecrement, Unary.posIncrement, - Unary.preDecrement, Unary.preIncrement) - - def transform(cu: CompilationUnit): CompilationUnit = { - cu.accept(this, Nil).asInstanceOf[CompilationUnit] - } - - override def visit(n: Block, arg: Vars): Node = { - if (n.getStmts == null) { - return n - } - val vars = n.getStmts.collect { case Stmt(v: VariableDeclaration) => v } - .flatMap(v => v.getVars.map(va => (va.getId.getName,v))) - .toMap - // set vars to final - vars.values.foreach(_.addModifier(ModifierSet.FINAL)) - super.visit(n, vars :: arg) - } - - override def visit(n: Assign, arg: Vars): Node = { - removeFinal(n.getTarget.toString, arg) - n - } - - override def visit(n: Unary, arg: Vars): Node = { - if (operators.contains(n.getOperator)) { - removeFinal(n.getExpr.toString, arg) - } - n - } - - // leave VariableDeclarations unchanged - override def visit(n: VariableDeclaration, arg: Vars): Node = n - - private def removeFinal(key: String, arg: Vars) { - arg.find(_.contains(key)) - .flatMap(_.get(key)) - .foreach(_.removeModifier(ModifierSet.FINAL)) - } - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/ast/BeginClosureExpr.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/ast/BeginClosureExpr.scala deleted file mode 100644 index 39c0a4b21..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/ast/BeginClosureExpr.scala +++ /dev/null @@ -1,7 +0,0 @@ -package com.mysema.scalagen.ast - -import japa.parser.ast.expr.NameExpr - -class BeginClosureExpr(params: String) extends NameExpr(params) { - def params = getName -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/package.scala b/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/package.scala deleted file mode 100644 index ba43360d0..000000000 --- a/jsonschema2pojo-scalagen/src/main/scala/com/mysema/scalagen/package.scala +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema - -import japa.parser.ast.body._ -import japa.parser.ast.expr._ -import japa.parser.ast.stmt._ -import _root_.scala.collection.JavaConversions -import _root_.scala.collection.Set - -/** - * scalagen provides common functionality for this package - */ -package object scalagen { - - type JavaCollection[T] = java.util.Collection[T] - - type JavaList[T] = java.util.List[T] - - type JavaSet[T] = java.util.Set[T] - - implicit def toJavaList[T](col: Seq[T]): JavaList[T] = JavaConversions.seqAsJavaList(col) - - implicit def toJavaSet[T](col: Set[T]): JavaSet[T] = JavaConversions.setAsJavaSet(col) - -// implicit def toScalaSeq[T](col: JavaList[T]): Seq[T] = { -// if (col != null) JavaConversions.asScalaBuffer(col) else Nil -// } - - implicit def toScalaList[T](col: JavaList[T]): List[T] = { - if (col != null) JavaConversions.asScalaBuffer(col).toList else Nil - } - - implicit def toScalaSet[T](col: JavaSet[T]): Set[T] = { - if (col != null) JavaConversions.asScalaSet(col) else Set[T]() - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/A.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/A.java deleted file mode 100644 index c1df275d9..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/A.java +++ /dev/null @@ -1,15 +0,0 @@ -package com.mysema.examples; - -public class A extends B { - public A() { - super("args"); - } -} - -class B { - - public B(String s) { - - } - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/AbstractClass.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/AbstractClass.java deleted file mode 100644 index d13007ffb..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/AbstractClass.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.mysema.examples; - -public abstract class AbstractClass { - - public static final String constant = "XXX"; - - public final String property = "XXX"; - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/AbstractCodeWriter.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/AbstractCodeWriter.java deleted file mode 100644 index d51a8cbeb..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/AbstractCodeWriter.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Copyright (c) 2010 Mysema Ltd. - * All rights reserved. - * - */ -package com.mysema.examples; - -import static com.mysema.codegen.Symbols.NEWLINE; - -import java.io.IOException; - -import org.apache.commons.lang3.StringUtils; - -/** - * @author tiwe - * - * @param - */ -public abstract class AbstractCodeWriter> implements Appendable { - - private final Appendable appendable; - - private final int spaces; - - private final String spacesString; - - private String indent = ""; - - @SuppressWarnings("unchecked") - private final T self = (T)this; - - public AbstractCodeWriter(Appendable appendable, int spaces){ - if (appendable == null){ - throw new IllegalArgumentException("appendable is null"); - } - this.appendable = appendable; - this.spaces = spaces; - this.spacesString = StringUtils.leftPad("", spaces); - } - - @Override - public T append(char c) throws IOException { - appendable.append(c); - return self; - } - - @Override - public T append(CharSequence csq) throws IOException { - appendable.append(csq); - return self; - } - - @Override - public T append(CharSequence csq, int start, int end) throws IOException { - appendable.append(csq, start, end); - return self; - } - - //@Override - public T beginLine(String... segments) throws IOException { - append(indent); - for (String segment : segments){ - append(segment); - } - return self; - } - - protected T goIn(){ - indent += spacesString; - return self; - } - - - protected T goOut(){ - if (indent.length() >= spaces){ - indent = indent.substring(0, indent.length() - spaces); - } - return self; - } - - //@Override - public T line(String... segments) throws IOException{ - append(indent); - for (String segment : segments){ - append(segment); - } - return nl(); - } - - //@Override - public T nl() throws IOException { - return append(NEWLINE); - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/AbstractDao.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/AbstractDao.java deleted file mode 100644 index 844470577..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/AbstractDao.java +++ /dev/null @@ -1,61 +0,0 @@ -package com.mysema.examples; - -import javax.annotation.Nullable; - -import com.mysema.query.types.EntityPath; -import com.mysema.query.types.OrderSpecifier; -import com.mysema.query.types.Predicate; - -public abstract class AbstractDao implements Dao { - - private HibernateSessionManager sessionManager; - - protected JPQLQuery query() { - return new HibernateQuery(getSession()); - } - - protected Session getSession() { - return sessionManager.getSession(); - } - - protected HibernateSessionManager getSessionManager() { - return sessionManager; - } - - protected GridDataSource createGridDataSource(final EntityPath path, - final OrderSpecifier order, final boolean caseSensitive, final Predicate filters) { - return new JPQLGridDataSource(getSessionManager(), path, order, caseSensitive, filters); - } - -} - -interface Dao { - - @Nullable - Entity getById( Id id ); - -} -class HibernateQuery implements JPQLQuery { - public HibernateQuery(Session session) { - - } -} - -interface HibernateSessionManager { - Session getSession(); -} - -interface Session { } - -interface JPQLQuery { } - -interface GridDataSource {} - -class JPQLGridDataSource implements GridDataSource { - - public JPQLGridDataSource(HibernateSessionManager sessionManager, - EntityPath path, OrderSpecifier order, boolean caseSensitive, - Predicate filters) { - } - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/AbstractModule.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/AbstractModule.java deleted file mode 100644 index 2ba0857f8..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/AbstractModule.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.examples; - -import java.lang.annotation.Annotation; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.util.HashMap; -import java.util.Map; - -import javax.inject.Inject; -import javax.inject.Named; - -/** - * @author tiwe - * - */ -public abstract class AbstractModule { - - private final Map, Object> instances = new HashMap<>(); - - private final Map, Class> bindings = new HashMap<>(); - - private final Map namedInstances = new HashMap<>(); - - private final Map> namedBindings = new HashMap<>(); - - public AbstractModule() { - configure(); - } - - public final AbstractModule bind(Class clazz){ - if (clazz.isInterface()) { - throw new IllegalArgumentException("Interfaces can't be instantiated"); - } - bind(clazz, clazz); - return this; - } - - public final AbstractModule bind(String name, Class implementation){ - namedBindings.put(name, implementation); - return this; - } - - public final AbstractModule bind(String name, T implementation){ - namedInstances.put(name, implementation); - return this; - } - - public final AbstractModule bind(Class iface, Class implementation){ - bindings.put(iface, implementation); - return this; - } - - public final AbstractModule bind(Class iface, T implementation){ - instances.put(iface, implementation); - return this; - } - - protected abstract void configure(); - - @SuppressWarnings("unchecked") - public final T get(Class iface){ - if (instances.containsKey(iface)) { - return (T)instances.get(iface); - } else if (bindings.containsKey(iface)) { - Class implementation = bindings.get(iface); - T instance = (T)createInstance(implementation); - instances.put(iface, instance); - return instance; - } else { - throw new IllegalArgumentException(iface.getName() + " is not registered"); - } - } - - @SuppressWarnings("unchecked") - public final T get(Class iface, String name){ - if (namedInstances.containsKey(name)) { - return (T)namedInstances.get(name); - } else if (namedBindings.containsKey(name)) { - Class implementation = namedBindings.get(name); - if (implementation != null) { - T instance = (T)createInstance(implementation); - namedInstances.put(name, instance); - return instance; - } else { - return (T)null; - } - } else { - throw new IllegalArgumentException(iface.getName() + " " + name + " is not registered"); - } - } - - @SuppressWarnings("unchecked") - private T createInstance(Class implementation) { - Constructor constructor = null; - for (Constructor c : implementation.getConstructors()) { - if (c.getAnnotation(Inject.class) != null) { - constructor = c; - break; - } - } - - // fallback to default constructor - if (constructor == null) { - try { - // FIXME - constructor = implementation.getConstructor(Object.class); - } catch (SecurityException | NoSuchMethodException e) { - throw new RuntimeException(e); - } - } - - if (constructor != null) { - Object[] args = new Object[constructor.getParameterTypes().length]; - for (int i = 0; i < constructor.getParameterTypes().length; i++) { - Named named = getNamedAnnotation(constructor.getParameterAnnotations()[i]); - if (named != null) { - args[i] = get(constructor.getParameterTypes()[i], named.value()); - } else { - args[i] = get(constructor.getParameterTypes()[i]); - } - } - try { - return (T) constructor.newInstance(args); - - } catch (InstantiationException | InvocationTargetException | IllegalAccessException e) { - throw new RuntimeException(e); - } - - } else { - throw new IllegalArgumentException("Got no annotated constructor for " + implementation.getName()); - } - - } - - private Named getNamedAnnotation(Annotation[] annotations) { - for (Annotation annotation : annotations) { - if (annotation.annotationType().equals(Named.class)) { - return (Named)annotation; - } - } - return null; - } - - - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/AbstractProperties.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/AbstractProperties.java deleted file mode 100644 index 20ef14955..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/AbstractProperties.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.mysema.examples; - -public abstract class AbstractProperties { - - private int capacity; - - protected abstract int capacity(); -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/AnnotatedElementAdapter.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/AnnotatedElementAdapter.java deleted file mode 100644 index f31c675db..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/AnnotatedElementAdapter.java +++ /dev/null @@ -1,58 +0,0 @@ -/* - * Copyright 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.examples; - -import java.lang.annotation.Annotation; -import java.lang.reflect.AnnotatedElement; -import java.util.HashMap; -import java.util.Map; - -/** - * @author tiwe - * - */ -public class AnnotatedElementAdapter implements AnnotatedElement{ - - private final Map,Annotation> annotations = new HashMap<>(); - - public AnnotatedElementAdapter(AnnotatedElement... elements) { - for (AnnotatedElement element : elements) { - for (Annotation annotation : element.getAnnotations()) { - annotations.put(annotation.annotationType(), annotation); - } - } - } - - @SuppressWarnings("unchecked") - @Override - public T getAnnotation(Class annotationClass) { - return (T) annotations.get(annotationClass); - } - - @Override - public Annotation[] getAnnotations() { - return annotations.values().toArray(new Annotation[annotations.values().size()]); - } - - @Override - public Annotation[] getDeclaredAnnotations() { - return getAnnotations(); - } - - @Override - public boolean isAnnotationPresent(Class annotationClass) { - return annotations.containsKey(annotationClass); - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Annotations.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Annotations.java deleted file mode 100644 index ab5eb58e3..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Annotations.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.examples; - -import java.lang.annotation.Annotation; -import java.lang.reflect.AnnotatedElement; -import java.util.HashMap; -import java.util.Map; - -import javax.annotation.Nullable; - -/** - * @author tiwe - * - */ -public class Annotations implements AnnotatedElement{ - - private final Map,Annotation> annotations = new HashMap<>(); - - public Annotations(AnnotatedElement... elements) { - for (AnnotatedElement element : elements) { - for (Annotation annotation : element.getAnnotations()) { - annotations.put(annotation.annotationType(), annotation); - } - } - } - - @SuppressWarnings("unchecked") - @Override - public T getAnnotation(Class annotationClass) { - return (T) annotations.get(annotationClass); - } - - @Override - public Annotation[] getAnnotations() { - return annotations.values().toArray(new Annotation[annotations.values().size()]); - } - - @Override - public Annotation[] getDeclaredAnnotations() { - return getAnnotations(); - } - - @Override - public boolean isAnnotationPresent(Class annotationClass) { - return annotations.containsKey(annotationClass); - } - - public void addAnnotation(@Nullable Annotation annotation) { - if (annotation != null) { - annotations.put(annotation.annotationType(), annotation); - } - - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ArrayConstructorExpression.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ArrayConstructorExpression.java deleted file mode 100644 index 8974c232f..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ArrayConstructorExpression.java +++ /dev/null @@ -1,85 +0,0 @@ -package com.mysema.examples; - -import java.util.Collections; -import java.util.List; - -import com.mysema.commons.lang.Assert; -import com.mysema.query.types.Expression; -import com.mysema.query.types.ExpressionBase; -import com.mysema.query.types.FactoryExpression; -import com.mysema.query.types.Visitor; - -/** - * ArrayConstructorExpression extends {@link ExpressionBase} to represent array initializers - * - * @author tiwe - * - * @param component type - */ -public class ArrayConstructorExpression extends ExpressionBase implements FactoryExpression { - - private static final long serialVersionUID = 8667880104290226505L; - - private final Class elementType; - - private final List> args; - -// @SuppressWarnings("unchecked") -// public ExampleArrayConstructorExpression(Expression... args) { -// this((Class)Object[].class, (Expression[])args); -// } - - @SuppressWarnings("unchecked") - public ArrayConstructorExpression(Class type, Expression... a) { - super(type); - this.elementType = (Class) Assert.notNull(type.getComponentType(),"componentType"); - // FIXME vargs - //this.args = Arrays.>asList(a); - this.args = Collections.>emptyList(); - } - - public final Class getElementType() { - return elementType; - } - - @Override - public R accept(Visitor v, C context) { - return v.visit(this, context); - } - - @SuppressWarnings("unchecked") - @Override - public T[] newInstance(Object... a){ - if (a.getClass().getComponentType().equals(elementType)){ - return (T[])a; - } else { - T[] rv = (T[]) java.lang.reflect.Array.newInstance(elementType, a.length); - System.arraycopy(a, 0, rv, 0, a.length); - return rv; - } - } - - - @Override - public List> getArgs() { - return args; - } - - @Override - public boolean equals(Object obj) { - if (obj == this){ - return true; - } else if (obj instanceof ArrayConstructorExpression) { - ArrayConstructorExpression c = (ArrayConstructorExpression)obj; - return args.equals(c.args) && getType().equals(c.getType()); - } else { - return false; - } - } - - @Override - public int hashCode(){ - return getType().hashCode(); - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ArrayTests.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ArrayTests.java deleted file mode 100644 index 6d1a8fc8c..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ArrayTests.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.mysema.examples; - -public class ArrayTests { - - int[] foo() { - return new int[2]; - } - - void bar() { -// var foo:Array[Object] = Array[Object](new Object()) -// var bar:Array[char] = Array('f', 'o', 'o') - Object[] foo = new Object[] { new Object() }; - char[] bar = new char[] { 'f', 'o', 'o' }; - } - - void bar2() { - String el1s[] = new String[]{"a","b"}; - String el2s[] = new String[]{"a","b","c"}; - } - - void bar3() { - final int SIZE = 3; - String strings1[]; - strings1 = new String[SIZE]; - } - - void bar4() { - final int SIZE = 3; - String[] strings2; - strings2 = new String[SIZE]; - } -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ArrayUtils.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ArrayUtils.java deleted file mode 100644 index 0a3e65efb..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ArrayUtils.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.examples; - -/** - * @author tiwe - * - */ -public final class ArrayUtils { - - public static Object[] combine(int size, Object[]... arrays) { - int offset = 0; - Object[] target = new Object[size]; - for (Object[] arr : arrays) { - System.arraycopy(arr, 0, target, offset, arr.length); - offset += arr.length; - } - return target; - } - - private ArrayUtils() {} - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Asserts.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Asserts.java deleted file mode 100644 index 96e99d777..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Asserts.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.mysema.examples; - -import com.mysema.commons.lang.Assert; - -public class Asserts { - - private final String firstName, lastName; - - public Asserts(String firstName, String lastName) { - this.firstName = Assert.notNull(firstName, "firstName"); - this.lastName = Assert.notNull(lastName, "lastName"); - } - - public String getFirstName() { - return firstName; - } - - public String getLastName() { - return lastName; - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Asserts2.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Asserts2.java deleted file mode 100644 index f42e9386c..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Asserts2.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.mysema.examples; - -public class Asserts2 { - - public Asserts2(boolean a, boolean b) { - assert a && b; - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Assignment.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Assignment.java deleted file mode 100644 index 9f9061902..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Assignment.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.mysema.examples; - - -public class Assignment { - -// def foo(j:Int):Unit = { -// var i:Int = j -// System.out.println({i = i + 1; i} > j) -// } - -// FIXME -// void foo(int j){ -// int i = j; -// System.out.println((i = i + 1) > j); -// } -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Bag2.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Bag2.java deleted file mode 100644 index 26c71927b..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Bag2.java +++ /dev/null @@ -1,31 +0,0 @@ - -package com.mysema.examples; - -import java.lang.reflect.Type; -import java.util.ArrayList; -import java.util.HashMap; - -public abstract class Bag2 { - - private HashMap nameTable; - - private ArrayList> itemTable; - - private int capacity; - - private int mass; - - private int levelIndex; - - private int currentLevel; - - private int currentCounter; - - private boolean showing; - - protected abstract int capacity(); - - protected abstract int forgetRate(); - - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/BagWindow.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/BagWindow.java deleted file mode 100644 index 4f996ef85..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/BagWindow.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.mysema.examples; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.AdjustmentEvent; -import java.awt.event.AdjustmentListener; - -public class BagWindow extends BagWindowSuper implements ActionListener, AdjustmentListener { - - private Bag bag; - - private String str; - - private int showLevel; - - public BagWindow(Bag b, String title) { - super(title); - bag = b; - str = "abc"; - adjustmentValueChanged(null); - } - - public int showLevel() { - return showLevel; - } - - @Override - public void adjustmentValueChanged(AdjustmentEvent e) { - - } - - @Override - public void actionPerformed(ActionEvent e) { - - } - -} - -class Bag { - -} - -class BagWindowSuper { - - public BagWindowSuper(String title) { - // do nothing - } -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Base.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Base.java deleted file mode 100644 index aaf407fdc..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Base.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.mysema.examples; - -class Base { - - Base() { - } - - Base(String s) { - } -} - -class Derived extends Base { - Derived(String s) { - super(s); - } -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Bean.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Bean.java deleted file mode 100644 index 34272d5a3..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Bean.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.mysema.examples; - -public class Bean { - - public static void main(String[] args) { - Bean bean = new Bean(); - bean.setFirstName("John"); - System.out.println(bean.getFirstName()); - } - - private int age; - - private String firstName, lastName, userName; - - private boolean male; - - public int getAge() { - return age; - } - - public void setAge(int age) { - this.age = age; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public String getUserName() { - return userName; - } - - public void setUserName(String userName) { - this.userName = userName; - } - - public boolean isMale() { - return male; - } - - public void setMale(boolean male) { - this.male = male; - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Bean2.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Bean2.java deleted file mode 100644 index e2f987e62..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Bean2.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.mysema.examples; - -public class Bean2 { - - public static void main(String[] args) { - Bean2 bean = new Bean2(); - bean.setFirstName("John"); - System.out.println(bean.getFirstName()); - } - - private int age; - - private String firstName; - - private String lastName; - - private String userName; - - public int getAge() { - return age; - } - - public void setAge(int age) { - this.age = age; - } - - public String getFirstName() { - return firstName; - } - - public void setFirstName(String firstName) { - this.firstName = firstName; - } - - public String getLastName() { - return lastName; - } - - public void setLastName(String lastName) { - this.lastName = lastName; - } - - public String getUserName() { - return userName; - } - - public void setUserName(String userName) { - this.userName = userName; - } - - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Bean3.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Bean3.java deleted file mode 100644 index bd0999c60..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Bean3.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.mysema.examples; - -import java.util.List; - -public class Bean3 extends Superclass{ - - private List names; - - public Bean3(List n) { - super(n.toString()); - this.names = n; - } - - public List getNames() { - return names; - } - - public void setNames(List names) { - this.names = names; - } - -} - - -class Superclass { - - public Superclass(String s) { - // TODO Auto-generated constructor stub - } -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Bean4.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Bean4.java deleted file mode 100644 index 2ed597d81..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Bean4.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.mysema.examples; - -public class Bean4 { - - public static class T1 {} - - public static class C { - private T1 prop; - - C(T1 prop) { - setProp(prop); - } - - public void setProp(T1 prop) { - this.prop = prop; - } - - public T1 getProp() { - return prop; - } - } - - public static class D { - private T1 prop; - - D(T1 prop) { - this.prop = prop; - } - - public void setProp(T1 prop) { - this.prop = prop; - } - - public T1 getProp() { - return prop; - } - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/BeanWithUnderscores.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/BeanWithUnderscores.java deleted file mode 100644 index b4c5fc510..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/BeanWithUnderscores.java +++ /dev/null @@ -1,49 +0,0 @@ -package com.mysema.examples; - -public class BeanWithUnderscores { - - private int _age; - - private String _firstName; - - private String _lastName; - - private String _userName; - - public int getAge() { - return _age; - } - - public void setAge(int age) { - this._age = age; - } - - public String getFirstName() { - return _firstName; - } - - public void setFirstName(String firstName) { - this._firstName = firstName; - } - - public String getLastName() { - return _lastName; - } - - public void setLastName(String lastName) { - this._lastName = lastName; - } - - public String getUserName() { - return _userName; - } - - public void setUserName(String userName) { - this._userName = userName; - } - - public String toString() { - return _firstName + " " + this._lastName; - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Casts.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Casts.java deleted file mode 100644 index 0baa4f10c..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Casts.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.mysema.examples; - -public class Casts { - - public static void main(String[] args){ - //System.out.println(args.length.toDouble) - System.out.println((double) args.length); - System.out.println((float) args.length); - System.out.println((long) args.length); - System.out.println((short) args.length); - System.out.println((byte) args.length); - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ClassPathUtils.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ClassPathUtils.java deleted file mode 100644 index 4ccf6999e..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ClassPathUtils.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.examples; - -import java.io.File; -import java.io.IOException; -import java.net.URISyntaxException; -import java.net.URL; -import java.util.ArrayDeque; -import java.util.Deque; -import java.util.Enumeration; -import java.util.HashSet; -import java.util.Set; -import java.util.jar.JarEntry; -import java.util.jar.JarFile; -import java.util.regex.Pattern; - -public final class ClassPathUtils { - - private static final Pattern JAR_URL_SEPARATOR = Pattern.compile("!"); - - public static Set> scanPackage(ClassLoader classLoader, Package pkg) throws IOException { - return scanPackage(classLoader, pkg.getName()); - } - - public static Set> scanPackage(ClassLoader classLoader, String pkg) throws IOException { - String packagePath = pkg.replace('.', '/'); - Enumeration urls = classLoader.getResources(packagePath); - Set> classes = new HashSet<>(); - while (urls.hasMoreElements()) { - URL url = urls.nextElement(); - if (url.getProtocol().equals("jar")) { - scanJar(classes, url, packagePath); - - } else if (url.getProtocol().equals("file")) { - scanDirectory(pkg, classes, url, pkg); - - } else { - throw new IllegalArgumentException("Illegal url : " + url); - } - } - return classes; - } - - private static void scanDirectory(String pkg, Set> classes, URL url, String packageName) throws IOException { - Deque files = new ArrayDeque<>(); - String packagePath = null; - try { - File packageAsFile = new File(url.toURI()); - packagePath = packageAsFile.getPath(); - files.add(packageAsFile); - } catch (URISyntaxException e) { - throw new IOException(e); - } - while (!files.isEmpty()) { - File file = files.pop(); - for (File child : file.listFiles()) { - if (child.getName().endsWith(".class")) { - String fileName = child.getPath().substring(packagePath.length()+1).replace(File.separatorChar, '.'); - String className = pkg + "." + fileName.substring(0, fileName.length()-6); - if (className.startsWith(packageName)) { - Class cl = safeClassForName(className); - if (cl != null) { - classes.add(cl); - } - } - } else if (child.isDirectory()) { - files.add(child); - } - } - } - } - - private static void scanJar(Set> classes, URL url, String packagePath) throws IOException { - String[] fileAndPath = JAR_URL_SEPARATOR.split(url.getFile().substring(5)); - JarFile jarFile = new JarFile(fileAndPath[0]); - Enumeration entries = jarFile.entries(); - while (entries.hasMoreElements()) { - JarEntry entry = entries.nextElement(); - if (entry.getName().endsWith(".class") && entry.getName().startsWith(packagePath) && entry.getName().startsWith(fileAndPath[1].substring(1))) { - String className = entry.getName().substring(0, entry.getName().length()-6).replace('/', '.'); - Class cl = safeClassForName(className); - if (cl != null) { - classes.add(cl); - } - } - } - } - - public static Class safeClassForName(String className){ - try { - if (className.startsWith("com.sun")) { - return null; - } else { - return Class.forName(className); - } - } catch (ClassNotFoundException | NoClassDefFoundError e) { - return null; - } - } - - private ClassPathUtils() {} - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Concatenation.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Concatenation.java deleted file mode 100644 index 17634f34c..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Concatenation.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.mysema.examples; - -public class Concatenation { - - public static String f(String arg1) { - return arg1; - } - - private static String f(String arg1, String arg2, String arg3) { - return arg1; - } - - public static void main(String[] args) { - String sep = ";"; - String title = "abc".toLowerCase() + ":" + f(sep) + ", fdsa=" - + ", ma " + f(sep) + - args[0] + f(args[0], sep, args[1]); - System.out.println(title); - } - - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Concept.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Concept.java deleted file mode 100644 index 902943268..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Concept.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.mysema.examples; - -public final class Concept extends Item { - - private Object term; - private Object memory; - - // XXX this signature fails - // public Concept(Object tm, Object memory) - public Concept(Object term, Object memory) { - super(term.toString()); - this.term = term; - this.memory = memory; - } - - public Object getTerm() { - return term; - } - - public void setTerm(Object term) { - this.term = term; - } - - public Object getMemory() { - return memory; - } - - public void setMemory(Object memory) { - this.memory = memory; - } - -} - -class Item { - - public Item(String str) { - // TODO Auto-generated constructor stub - } -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Config.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Config.java deleted file mode 100644 index e43d79067..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Config.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.examples; - -import static java.lang.annotation.ElementType.PACKAGE; -import static java.lang.annotation.ElementType.TYPE; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -/** - * Config defines serialization flags for annotated domain types and packages - * - * @author tiwe - * - */ -@Documented -@Target({PACKAGE,TYPE}) -@Retention(RUNTIME) -public @interface Config { - - /** - * Created entity field initialization accessors - * - * @return - */ - boolean entityAccessors() default false; - - /** - * Create accessors for indexed list access - * - * @return - */ - boolean listAccessors() default false; - - /** - * Create accessors for keyed map access - * - * @return - */ - boolean mapAccessors() default false; - - /** - * Create default variable in query type - * - * @return - */ - boolean createDefaultVariable() default true; - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ConstantImpl.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ConstantImpl.java deleted file mode 100644 index 45c3aefa5..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ConstantImpl.java +++ /dev/null @@ -1,151 +0,0 @@ -package com.mysema.examples; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import com.mysema.commons.lang.Assert; -import com.mysema.query.types.Constant; -import com.mysema.query.types.ExpressionBase; -import com.mysema.query.types.Visitor; - -/** - * ConstantImpl is the default implementation of the Constant interface - * - * @author tiwe - */ -public class ConstantImpl extends ExpressionBase implements Constant { - - private static final long serialVersionUID = -3898138057967814118L; - - private static final int CACHE_SIZE = 256; - - private static final Constant[] BYTES = new Constant[CACHE_SIZE]; - - private static final Constant[] INTEGERS = new Constant[CACHE_SIZE]; - - private static final Constant[] LONGS = new Constant[CACHE_SIZE]; - - private static final Constant[] SHORTS = new Constant[CACHE_SIZE]; - - private static final Map> STRINGS; - - private static final Constant FALSE = new ConstantImpl<>(Boolean.FALSE); - - private static final Constant TRUE = new ConstantImpl<>(Boolean.TRUE); - - static { - List strs = new ArrayList<>(Arrays.asList("", ".", ".*", "%")); - for (int i = 0; i < CACHE_SIZE; i++) { - strs.add(String.valueOf(i)); - } - - STRINGS = new HashMap<>(strs.size()); - for (String str : strs) { - STRINGS.put(str, new ConstantImpl<>(str)); - } - - for (int i = 0; i < CACHE_SIZE; i++) { - INTEGERS[i] = new ConstantImpl<>(Integer.class, Integer.valueOf(i)); - SHORTS[i] = new ConstantImpl<>(Short.class, Short.valueOf((short) i)); - BYTES[i] = new ConstantImpl<>(Byte.class, Byte.valueOf((byte) i)); - LONGS[i] = new ConstantImpl<>(Long.class, Long.valueOf(i)); - } - } - - public static Constant create(boolean b) { - return b ? TRUE : FALSE; - } - - public static Constant create(byte i) { - if (i >= 0 && i < CACHE_SIZE) { - return BYTES[i]; - } else { - return new ConstantImpl<>(Byte.class, Byte.valueOf(i)); - } - } - - public static Constant create(int i) { - if (i >= 0 && i < CACHE_SIZE) { - return INTEGERS[i]; - } else { - return new ConstantImpl<>(Integer.class, Integer.valueOf(i)); - } - } - - public static Constant create(long i) { - if (i >= 0 && i < CACHE_SIZE) { - return LONGS[(int)i]; - } else { - return new ConstantImpl<>(Long.class, Long.valueOf(i)); - } - } - - public static Constant create(short i) { - if (i >= 0 && i < CACHE_SIZE) { - return SHORTS[i]; - } else { - return new ConstantImpl<>(Short.class, Short.valueOf(i)); - } - } - - public static Constant create(String str) { - return create(str, false); - } - - public static Constant create(String str, boolean populateCache) { - if (STRINGS.containsKey(str)) { - return STRINGS.get(str); - } else { - Constant rv = new ConstantImpl<>(Assert.notNull(str, "str")); - if (populateCache) { - STRINGS.put(str, rv); - } - return rv; - } - } - - public static Constant> create(Class constant) { - return new ConstantImpl<>(constant); - } - - private final T constant; - - public ConstantImpl(T constant) { - this((Class)constant.getClass(), constant); - } - - public ConstantImpl(Class type, T constant) { - super(type); - this.constant = constant; - } - - @Override - public R accept(Visitor v, C context) { - return v.visit(this, context); - } - - @Override - public boolean equals(Object o) { - if (o == this) { - return true; - } else if (o instanceof Constant) { - return ((Constant)o).getConstant().equals(constant); - } else { - return false; - } - } - - @Override - public T getConstant() { - return constant; - } - - @Override - public int hashCode() { - return constant.hashCode(); - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ConstructorParams.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ConstructorParams.java deleted file mode 100644 index 6d1b8a89c..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ConstructorParams.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.mysema.examples; - -public class ConstructorParams { - - private int bar; - - public ConstructorParams(int bar) { - this.bar = bar * 2; // ok in Java - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Constructors.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Constructors.java deleted file mode 100644 index f3f93d693..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Constructors.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.mysema.examples; - -public class Constructors { - - /** - * skipped javadocs - */ - public Constructors() { - this("first", "last"); - } - - /** - * available javadocs - * - * @param first - * @param last - */ - public Constructors(String first, String last) { - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Constructors2.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Constructors2.java deleted file mode 100644 index db59d08b4..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Constructors2.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.mysema.examples; - -public class Constructors2 { - - class C { - private final int a; - public C(int a) { - this.a = a; - } - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Constructors3.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Constructors3.java deleted file mode 100644 index 19335dd36..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Constructors3.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.mysema.examples; - - -public class Constructors3 { - - class A { - public A(String str) { - } - } - - class B extends A { - public B() { - super("some value"); - } - - public B(String str) { - super(str); - } - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Control.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Control.java deleted file mode 100644 index 4d76cf388..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Control.java +++ /dev/null @@ -1,105 +0,0 @@ -package com.mysema.examples; - -import java.util.Arrays; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -public class Control { - - List integers = Arrays.asList(1,2,3,4,5); - - int[] ints = {1,2,3,4,5}; - - public void whileLoop() { - int i = 0; - while (i < integers.size()) { - System.err.println(integers.get(i)); - i++; - } - } - - public void whileLoop2() { - Iterator i = integers.iterator(); - while (i.hasNext()) { - System.err.println(i.next()); - } - } - - public void forLoop() { - for (int i = 0; i < integers.size(); i++) { - System.err.println(integers.get(i)); - } - } - - public void forLoop2() { - for (Integer i : integers) { - System.err.println(i); - } - } - - public void forLoop3() { - for (Iterator i = integers.iterator(); i.hasNext(); ) { - System.err.println(i.next()); - } - } - - public void forLoop4() { - for(int i = 0;; i++){ - if (i > 10) return; - } - } - - public void forLoopWithIf() { - for (Integer i : integers) { - if (i > 0) { - System.err.println(i); - } - } - } - - public void forLoopWithIfAndFor() { - for (Integer i : integers) { - if (i > 0) { - for (Integer j : integers) { - System.err.println(i + j); - } - } - } - } - - public void forLoopWithFor() { - for (Integer i : integers) { - for (Integer j : integers) { - System.err.println(i + j); - } - } - } - - public int transform(int i) { - for (int j : ints) { - if (j == i) { - return j; - } - } - return -1; - } - - public int transform2(int i) { - for (int j : ints) { - if (j == i) { - return 2 * j; - } - } - return -1; - } - - public void entrySetIterator() { - Map entries = Collections.emptyMap(); - for (Map.Entry entry : entries.entrySet()) { - System.out.println(entry.getKey()+ " " + entry.getValue()); - } - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/DateTimeExpression.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/DateTimeExpression.java deleted file mode 100644 index af5c2e023..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/DateTimeExpression.java +++ /dev/null @@ -1,332 +0,0 @@ -/* - * Copyright 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.examples; - -import java.util.Arrays; -import java.util.Date; -import java.util.List; - -import javax.annotation.Nullable; - -import com.mysema.query.types.Expression; -import com.mysema.query.types.Operation; -import com.mysema.query.types.OperationImpl; -import com.mysema.query.types.Operator; -import com.mysema.query.types.Ops; -import com.mysema.query.types.Visitor; -import com.mysema.query.types.expr.NumberExpression; -import com.mysema.query.types.expr.NumberOperation; -import com.mysema.query.types.expr.TemporalExpression; - -/** - * DateTimeExpression represents Date / Time expressions - * The date representation is compatible with the Gregorian calendar. - * - * @param expression type - * - * @author tiwe - * @see Gregorian calendar - */ -public abstract class DateTimeExpression> extends TemporalExpression { - - private static final DateTimeExpression CURRENT_DATE = currentDate(Date.class); - - private static final DateTimeExpression CURRENT_TIMESTAMP = currentTimestamp(Date.class); - - private static final long serialVersionUID = -6879277113694148047L; - - /** - * Get an expression representing the current date as a EDateTime instance - * - * @return - */ - public static DateTimeExpression currentDate() { - return CURRENT_DATE; - } - - /** - * Get an expression representing the current date as a EDateTime instance - * - * @return - */ - public static > DateTimeExpression currentDate(Class cl) { - return DateTimeOperation.create(cl, Ops.DateTimeOps.CURRENT_DATE); - } - - /** - * Get an expression representing the current time instant as a EDateTime instance - * - * @return - */ - public static DateTimeExpression currentTimestamp() { - return CURRENT_TIMESTAMP; - } - - /** - * Get an expression representing the current time instant as a EDateTime instance - * - * @return - */ - public static > DateTimeExpression currentTimestamp(Class cl) { - return DateTimeOperation.create(cl, Ops.DateTimeOps.CURRENT_TIMESTAMP); - } - - - @Nullable - private volatile NumberExpression dayOfMonth, dayOfWeek, dayOfYear; - - @Nullable - private volatile NumberExpression hour, minute, second, milliSecond; - - - @Nullable - private volatile DateTimeExpression min, max; - - @Nullable - private volatile NumberExpression week, month, year, yearMonth; - - public DateTimeExpression(Class type) { - super(type); - } - -// @Override -// public DateTimeExpression as(Path alias) { -// return DateTimeOperation.create((Class)getType(), Ops.ALIAS, this, alias); -// } - -// @Override -// public DateTimeExpression as(String alias) { -// return as(new PathImpl(getType(), alias)); -// } - - /** - * Get a day of month expression (range 1-31) - * - * @return - */ - public NumberExpression dayOfMonth(){ - if (dayOfMonth == null) { - dayOfMonth = NumberOperation.create(Integer.class, Ops.DateTimeOps.DAY_OF_MONTH, this); - } - return dayOfMonth; - } - - /** - * Get a day of week expression (range 1-7 / SUN-SAT) - *

NOT supported in JDOQL and not in Derby

- * - * @return - */ - public NumberExpression dayOfWeek() { - if (dayOfWeek == null) { - dayOfWeek = NumberOperation.create(Integer.class, Ops.DateTimeOps.DAY_OF_WEEK, this); - } - return dayOfWeek; - } - - /** - * Get a day of year expression (range 1-356) - *

NOT supported in JDOQL and not in Derby

- * - * @return - */ - public NumberExpression dayOfYear() { - if (dayOfYear == null){ - dayOfYear = NumberOperation.create(Integer.class, Ops.DateTimeOps.DAY_OF_YEAR, this); - } - return dayOfYear; - } - - /** - * Get a hours expression (range 0-23) - * - * @return - */ - public NumberExpression hour(){ - if (hour == null) { - hour = NumberOperation.create(Integer.class, Ops.DateTimeOps.HOUR, this); - } - return hour; - } - - /** - * Get the maximum value of this expression (aggregation) - * - * @return max(this) - */ - public DateTimeExpression max(){ - if (max == null) { - max = DateTimeOperation.create((Class)getType(), Ops.AggOps.MAX_AGG, this); - } - return max; - } - - /** - * Get a milliseconds expression (range 0-999) - *

Is always 0 in HQL and JDOQL modules

- * - * @return - */ - public NumberExpression milliSecond(){ - if (milliSecond == null) { - milliSecond = NumberOperation.create(Integer.class, Ops.DateTimeOps.MILLISECOND, this); - } - return milliSecond; - } - - /** - * Get the minimum value of this expression (aggregation) - * - * @return min(this) - */ - public DateTimeExpression min(){ - if (min == null) { - min = DateTimeOperation.create((Class)getType(), Ops.AggOps.MIN_AGG, this); - } - return min; - } - - /** - * Get a minutes expression (range 0-59) - * - * @return - */ - public NumberExpression minute(){ - if (minute == null) { - minute = NumberOperation.create(Integer.class, Ops.DateTimeOps.MINUTE, this); - } - return minute; - } - - /** - * Get a month expression (range 1-12 / JAN-DEC) - * - * @return - */ - public NumberExpression month(){ - if (month == null) { - month = NumberOperation.create(Integer.class, Ops.DateTimeOps.MONTH, this); - } - return month; - } - - /** - * Get a seconds expression (range 0-59) - * - * @return - */ - public NumberExpression second(){ - if (second == null) { - second = NumberOperation.create(Integer.class, Ops.DateTimeOps.SECOND, this); - } - return second; - } - - /** - * Get a week expression - * - * @return - */ - public NumberExpression week() { - if (week == null) { - week = NumberOperation.create(Integer.class, Ops.DateTimeOps.WEEK, this); - } - return week; - } - - /** - * Get a year expression - * - * @return - */ - public NumberExpression year(){ - if (year == null) { - year = NumberOperation.create(Integer.class, Ops.DateTimeOps.YEAR, this); - } - return year; - } - - /** - * Get a year / month expression - * - * @return - */ - public NumberExpression yearMonth(){ - if (yearMonth == null) { - yearMonth = NumberOperation.create(Integer.class, Ops.DateTimeOps.YEAR_MONTH, this); - } - return yearMonth; - } - -} - -class DateTimeOperation> extends DateTimeExpression implements Operation { - - private static final long serialVersionUID = 6523293814317168556L; - - /** - * Factory method - * - * @param - * @param type - * @param op - * @param args - * @return - */ - public static > DateTimeExpression create(Class type, Operator op, Expression... args) { - return new DateTimeOperation<>(type, op, Arrays.asList(args)); - } - - private final Operation opMixin; - -// protected DateTimeOperation(Class type, Operator op, Expression... args) { -// this(type, op, Arrays.asList(args)); -// } - - protected DateTimeOperation(Class type, Operator op, List> args) { - super(type); - this.opMixin = new OperationImpl<>(type, op, args); - } - - @Override - public R accept(Visitor v, C context) { - return v.visit(this, context); - } - - @Override - public Expression getArg(int index) { - return opMixin.getArg(index); - } - - @Override - public List> getArgs() { - return opMixin.getArgs(); - } - - @Override - public Operator getOperator() { - return opMixin.getOperator(); - } - - @Override - public boolean equals(Object o) { - return opMixin.equals(o); - } - - @Override - public int hashCode() { - return getType().hashCode(); - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Diamond.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Diamond.java deleted file mode 100644 index b43e62f7c..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Diamond.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.mysema.examples; - -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; - -public class Diamond { - Set set1 = new HashSet<>(); - void infer() { - Set set2 = new HashSet<>(); - Map map = new HashMap<>(); - } -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/EqualsHashCode.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/EqualsHashCode.java deleted file mode 100644 index f7b4aa0a5..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/EqualsHashCode.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.mysema.examples; - -public class EqualsHashCode { - - // NOTE: override should be added implicitly - - public boolean equals(Object o) { - return false; - } - - public int hashCode() { - return super.hashCode(); - } - - public String toString() { - return ""; - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Fields.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Fields.java deleted file mode 100644 index de6d5955b..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Fields.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.mysema.examples; - -import java.util.HashMap; -import java.util.Map; - -public class Fields { - - private Map properties = new HashMap<>(); - - public Fields() { - } - - public Fields(Map properties) { - this.properties = properties; - } - - public Map getProperties() { - return properties; - } - - - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/FileSystemRegistry.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/FileSystemRegistry.java deleted file mode 100644 index 4d3ce89f4..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/FileSystemRegistry.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright (c) 2010 Mysema Ltd. - * - * base on code from https://hickory.dev.java.net/ - * - */ - -package com.mysema.examples; - -import java.lang.ref.WeakReference; -import java.net.URL; -import java.util.Map; -import java.util.WeakHashMap; - -import javax.annotation.Nullable; -import javax.tools.JavaFileManager; - -/** - * @author tiwe - * - */ -public final class FileSystemRegistry { - - public static final FileSystemRegistry DEFAULT = new FileSystemRegistry(); - - private final Map jfm2prefix = new WeakHashMap<>(); - - private Map> prefix2jfm = new WeakHashMap<>(); - - private final String protocolName; - - private int sequence = 0; - - private FileSystemRegistry() { - String pkgName = FileSystemRegistry.class.getPackage().getName(); - protocolName = pkgName.substring(pkgName.lastIndexOf('.') + 1); - String pkgs = System.getProperty("java.protocol.handler.pkgs"); - String parentPackage = pkgName.substring(0,pkgName.lastIndexOf('.')); - pkgs = pkgs == null ? parentPackage : pkgs + "|" + parentPackage; - System.setProperty("java.protocol.handler.pkgs",pkgs); - } - - @Nullable - public JavaFileManager getFileSystem(URL url) { - String prefix = url.getProtocol() + "://" + url.getHost() + "/"; - if(prefix2jfm.containsKey(prefix)) { - return prefix2jfm.get(prefix).get(); - } else { - return null; - } - } - - public String getUrlPrefix(JavaFileManager jfm) { - if(jfm2prefix.containsKey(jfm)) { - return jfm2prefix.get(jfm); - } else { - String result = protocolName + "://jfm" + (sequence++) + "/"; - jfm2prefix.put(jfm,result); - prefix2jfm.put(result, new WeakReference<>(jfm)); - return result; - } - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Gender.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Gender.java deleted file mode 100644 index 0a88b65d4..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Gender.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.mysema.examples; - -public enum Gender { - MALE, - FEMALE -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/IDao.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/IDao.java deleted file mode 100644 index 6dc263b76..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/IDao.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.mysema.examples; - -import java.io.Serializable; - -import javax.annotation.Nullable; - -/** - * @author tiwe - * - * @param - * @param - */ -public interface IDao { - /** - * Get the persisted instance with the given id - * - * @param id - * @return - */ - @Nullable - Entity getById( Id id ); - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/IfElse.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/IfElse.java deleted file mode 100644 index 8f03a7709..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/IfElse.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.mysema.examples; - -import java.util.ArrayList; -import java.util.List; - -public class IfElse { - - public void ifElse() { - String property = "x"; - if (System.currentTimeMillis() > 0) { - property = "y"; - } else { - property = "z"; - } - System.out.println(property); - } - - public void ifElse2() { - boolean success; - List list = new ArrayList<>(); - list.add(1); - list.add(2); - if (list.size() == 2) { - success = true; - } else { - success = false; - } - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Immutable.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Immutable.java deleted file mode 100644 index 408373e92..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Immutable.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.mysema.examples; - -public class Immutable { - - public static void main(String[] args) { - Immutable immutable = new Immutable("John", "Doe"); - System.out.println(immutable.getFirstName()); - System.out.println(immutable.getLastName()); - } - - private final String firstName; - - private final String lastName; - - public Immutable(String firstName, String lastName) { - this.firstName = firstName; - this.lastName = lastName; - } - - public String getFirstName() { - return firstName; - } - - public String getLastName() { - return lastName; - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Immutable2.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Immutable2.java deleted file mode 100644 index 0c6be4237..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Immutable2.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.mysema.examples; - -public class Immutable2 { - - private final String firstName; - - private final String lastName; - - public Immutable2(String f, String l) { - firstName = f; - lastName = l; - } - - public String getFirstName() { - return firstName; - } - - public String getLastName() { - return lastName; - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Increment.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Increment.java deleted file mode 100644 index 0cefbca25..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Increment.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.mysema.examples; - -public class Increment { - - public void doSomething() { - int i = 0; - int[] ints = new int[10]; - while (i < 10) { - System.out.println(ints[i++]); - } - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Initializers.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Initializers.java deleted file mode 100644 index d840e118b..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Initializers.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.mysema.examples; - -public class Initializers { - - static final String staticValue; - - static { - staticValue = "xx"; - } - - final String value; - - { - value = "x"; - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/InnerClasses.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/InnerClasses.java deleted file mode 100644 index e1d13fc72..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/InnerClasses.java +++ /dev/null @@ -1,39 +0,0 @@ -package com.mysema.examples; - -@SuppressWarnings("unused") -public class InnerClasses { - - public static class StaticClass { - - } - - private static class PrivateStaticClass { - - } - - private class PrivateClass { - - } - - public class PublicClass { - - } - - private static final class LoopContext { - private String note; - private String text; - private String paragraphs; - private int counter; - private boolean inBib; - private boolean inA; - private String reference; - private String url; - - private LoopContext() { - note = null; - text = null; - counter = 0; - } - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/LazyInitBeanAccessor.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/LazyInitBeanAccessor.java deleted file mode 100644 index e28a3ddce..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/LazyInitBeanAccessor.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.mysema.examples; - -public class LazyInitBeanAccessor { - - private String value; - - public String getValue() { - if (value == null) { - value = "XXX"; - } - return value; - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Literal.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Literal.java deleted file mode 100644 index 300f7acb1..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Literal.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.mysema.examples; - - -public class Literal { - - public void doSomething() { - final String s = query(""); - System.out.println(s); - } - - public void doSomething2() { - System.out.println(query("")); - } - - private String query(String string) { - return null; - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Literals.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Literals.java deleted file mode 100644 index 44f6c7d83..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Literals.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.mysema.examples; - -public class Literals { - int a = 123_456; - int b = 0b101010; - long c = 123_456L; -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/LocationAndKind.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/LocationAndKind.java deleted file mode 100644 index f2af22c0a..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/LocationAndKind.java +++ /dev/null @@ -1,56 +0,0 @@ -/* - * Copyright (c) 2010 Mysema Ltd. - * - * base on code from https://hickory.dev.java.net/ - * - */ - -package com.mysema.examples; - -import javax.tools.JavaFileManager.Location; -import javax.tools.JavaFileObject.Kind; - -/** - * LocationAndKind defines a pair of Location and Kind - * - * @author tiwe - * - */ -public class LocationAndKind { - - private final Kind kind; - - private final Location location; - - public LocationAndKind(Location location, Kind kind) { - this.location = location; - this.kind = kind; - } - - @Override - public boolean equals(Object obj) { - if (obj == this){ - return true; - }else if (obj instanceof LocationAndKind){ - LocationAndKind other = (LocationAndKind)obj; - return location.equals(other.location) && kind.equals(other.kind); - }else{ - return false; - } - } - - @Override - public int hashCode() { - return kind.hashCode() * 31 + location.hashCode(); - } - - @Override - public String toString() { - return kind.toString() + "@" + location.toString(); - } - - - - - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/LongLinesIncludingAVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongClassName.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/LongLinesIncludingAVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongClassName.java deleted file mode 100644 index ddb0102dd..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/LongLinesIncludingAVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongClassName.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.mysema.examples; - -public class LongLinesIncludingAVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongClassName extends LongClassToExtendAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa { - LongLinesIncludingAVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongClassName x = new LongLinesIncludingAVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongClassName(444, 2, 3, 4, 5, 6, 7, 8, 9, 10); - - public LongLinesIncludingAVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongClassName(int... nums) { - } - - public LongLinesIncludingAVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongClassName(int a, int b, int c, int d, int e) { - this(a, b, c, d, e, 1, 2, 3, 4, 5); - } - - public void a(int... nums) { - if ("very long condition ........................".length() > 0 || "other long condition".length() > 0) { - a(555, 2, 3, 4, 5, 6, 7, 8, 9); - } - int[] aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa = nums; - for (int n : aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) { - if ("long condition goes here ........................".length() > 0) { - System.out.println(n); - } - } - } -} - -class LongClassToExtendAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa { - public LongClassToExtendAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa() { - } - - public LongClassToExtendAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(int... nums) { - } -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Loop.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Loop.java deleted file mode 100644 index ad2344413..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Loop.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.mysema.examples; - -public class Loop { - - boolean condition_and_early_return_dont_contain_b(String str) { - for (String b : java.util.Arrays.asList("a", "b")) { - if (str.startsWith("a")) { - return true; - } - } - return false; - } - - boolean condition_and_early_return_contain_b_once(String str) { - for (String b : java.util.Arrays.asList("a", "b")) { - if (str.startsWith(b)) { - return b.length() > 0; - } - } - return false; - } - - boolean condition_and_early_return_contain_b_multiple_times(String str) { - for (String b : java.util.Arrays.asList("a", "b")) { - if (str.startsWith(b) && b.length() < 10) { - return b.length() > 0 || b.length() < 15; - } - } - return false; - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/MathUtils.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/MathUtils.java deleted file mode 100644 index 72e47bddf..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/MathUtils.java +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.examples; - -import java.math.BigDecimal; -import java.math.BigInteger; - -public final class MathUtils { - - private MathUtils(){} - - @SuppressWarnings("unchecked") - public static > D sum(D num1, Number num2){ - BigDecimal res = new BigDecimal(num1.toString()).add(new BigDecimal(num2.toString())); - return MathUtils.cast(res, (Class)num1.getClass()); - } - - @SuppressWarnings("unchecked") - public static > D difference(D num1, Number num2){ - BigDecimal res = new BigDecimal(num1.toString()).subtract(new BigDecimal(num2.toString())); - return MathUtils.cast(res, (Class)num1.getClass()); - } - - @SuppressWarnings("unchecked") - public static > D cast(Number num, Class type){ - Number rv = null; - if (type.equals(Byte.class)) { - rv = num.byteValue(); - } else if (type.equals(Double.class)) { - rv = num.doubleValue(); - } else if (type.equals(Float.class)) { - rv = num.floatValue(); - } else if (type.equals(Integer.class)) { - rv = num.intValue(); - } else if (type.equals(Long.class)) { - rv = num.longValue(); - } else if (type.equals(Short.class)) { - rv = num.shortValue(); - } else if (type.equals(BigDecimal.class)) { - if (num instanceof BigDecimal) { - rv = num; - } else{ - rv = new BigDecimal(num.toString()); - } - } else if (type.equals(BigInteger.class)){ - if (num instanceof BigInteger) { - rv = num; - } else if (num instanceof BigDecimal) { - rv = ((BigDecimal)num).toBigInteger(); - } else { - rv = new BigInteger(num.toString()); - } - } else { - throw new IllegalArgumentException(String.format("Illegal type : %s", type.getSimpleName())); - } - return (D) rv; - } -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Methods.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Methods.java deleted file mode 100644 index 690e3ce95..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Methods.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.mysema.examples; - -public class Methods { - - public void pl(String s) { - System.out.println(s); - } - - public void doSmth(int i) { - switch (i) { - case 3: - return; - } - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Modifiers.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Modifiers.java deleted file mode 100644 index 0808dd172..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Modifiers.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.mysema.examples; - -public class Modifiers { - - private transient String foo = "foo"; - - private volatile String bar = "bar"; - - public synchronized void foobar() { - System.out.println("Hello World"); - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/MultiIterator.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/MultiIterator.java deleted file mode 100644 index d6be82087..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/MultiIterator.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.examples; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.NoSuchElementException; - -import javax.annotation.Nullable; - -/** - * MultiIterator provides a cartesian view on the given iterators - * - *
- * e.g. (1,2) and (100, 200, 300)
- * are expanded to (1, 100) (1, 200) (1, 300) (2, 100) (2, 200) (2, 300)
- * 
- * - * @author tiwe - */ -public class MultiIterator implements Iterator { - - @Nullable - private Boolean _hasNext; - - private int index = 0; - - private final List> iterables; - - private final List> iterators; - - private final boolean[] lastEntry; - - private final Object[] values; - - public MultiIterator(List> iterables){ - this.iterables = iterables; - this.iterators = new ArrayList<>(iterables.size()); - for (int i = 0; i < iterables.size(); i++) { - iterators.add(null); - } - this.lastEntry = new boolean[iterables.size()]; - this.values = new Object[iterables.size()]; - } - - @Override - public boolean hasNext() { - while (_hasNext == null) { - produceNext(); - } - return _hasNext.booleanValue(); - } - - @Override - public Object[] next() { - while (_hasNext == null) { - produceNext(); - } - if (_hasNext.booleanValue()) { - _hasNext = null; - return values.clone(); - } else { - throw new NoSuchElementException(); - } - } - - private void produceNext() { - for (int i = index; i < iterables.size(); i++) { - if (iterators.get(i) == null || (!iterators.get(i).hasNext() && i > 0)) { - iterators.set(i, iterables.get(i).iterator()); - } - if (!iterators.get(i).hasNext()) { - _hasNext = i == 0 ? Boolean.FALSE : null; - return; - } - values[i] = iterators.get(i).next(); - lastEntry[i] = !iterators.get(i).hasNext(); - _hasNext = Boolean.TRUE; - } - index = iterables.size() - 1; - while (lastEntry[index] && index > 0) { - index--; - } - } - - @Override - public void remove() { - // do nothing - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Operators.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Operators.java deleted file mode 100644 index 94f89ebd6..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Operators.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.mysema.examples; - -public class Operators { - -// def foo(j:Int):Int = { -// var i:Int = j -// return {val k = i; i = i + 1; k } -//} - -// FIXME -// int foo(int j){ -// int i = j; -// return i++; -// } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Ops.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Ops.java deleted file mode 100644 index 43896eba2..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Ops.java +++ /dev/null @@ -1,319 +0,0 @@ -/* - * Copyright 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.examples; - -import static java.util.Collections.unmodifiableList; - -import java.io.Serializable; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -/** - * Ops provides the operators for the fluent query grammar. - * - * @author tiwe - */ -public final class Ops { - - private static final List> BOOLEAN_X_2 = unmodifiableList(Arrays.> asList(Boolean.class, Boolean.class)); - - private static final List> COMPARABLE_X_2 = unmodifiableList(Arrays.> asList(Comparable.class, Comparable.class)); - - private static final List> COMPARABLE_X_3 = unmodifiableList(Arrays.> asList(Comparable.class, Comparable.class,Comparable.class)); - - private static final List> OBJECT_X_2 = unmodifiableList(Arrays.> asList(Object.class, Object.class)); - - private static final List> NUMBER_X_2 = unmodifiableList(Arrays.> asList(Number.class, Number.class)); - - private static final List> STRING_X_2 = unmodifiableList(Arrays.> asList(String.class, String.class)); - - // general - public static final Operator EQ_PRIMITIVE = new OperatorImpl<>("EQ_PRIMITIVE", OBJECT_X_2); - public static final Operator EQ_OBJECT = new OperatorImpl<>("EQ_OBJECT", OBJECT_X_2); - public static final Operator IS_NOT_NULL = new OperatorImpl<>("IS_NOT_NULL", Object.class); - public static final Operator IS_NULL = new OperatorImpl<>("IS_NULL", Object.class); - public static final Operator INSTANCE_OF = new OperatorImpl<>("INSTANCE_OF"); - public static final Operator NE_PRIMITIVE = new OperatorImpl<>("NE_PRIMITIVE", OBJECT_X_2); - public static final Operator NE_OBJECT = new OperatorImpl<>("NE_OBJECT", OBJECT_X_2); - public static final Operator NUMCAST = new OperatorImpl<>("NUMCAST"); - public static final Operator STRING_CAST = new OperatorImpl<>("STING_CAST", Object.class); - public static final Operator ALIAS = new OperatorImpl<>("ALIAS"); - public static final Operator LIST = new OperatorImpl<>("LIST"); - public static final Operator ORDINAL = new OperatorImpl<>("ORDINAL"); - public static final Operator DELEGATE = new OperatorImpl<>("DELEGATE"); - public static final Operator WRAPPED = new OperatorImpl<>("WRAPPED"); - - // collection - public static final Operator IN = new OperatorImpl<>("IN", OBJECT_X_2); // cmp. contains - public static final Operator COL_IS_EMPTY = new OperatorImpl<>("COL_IS_EMPTY", Object.class); - public static final Operator COL_SIZE = new OperatorImpl<>("COL_SIZE", Object.class); - - // array - public static final Operator ARRAY_SIZE = new OperatorImpl<>("ARRAY_SIZE", Object.class); - - // map - public static final Operator CONTAINS_KEY = new OperatorImpl<>("CONTAINS_KEY", OBJECT_X_2); - public static final Operator CONTAINS_VALUE = new OperatorImpl<>("CONTAINS_VALUE", OBJECT_X_2); - public static final Operator MAP_SIZE = new OperatorImpl<>("MAP_SIZE", Object.class); - public static final Operator MAP_IS_EMPTY = new OperatorImpl<>("MAP_IS_EMPTY", Object.class); - - // Boolean - public static final Operator AND = new OperatorImpl<>("AND", BOOLEAN_X_2); - public static final Operator NOT = new OperatorImpl<>("NOT", Boolean.class); - public static final Operator OR = new OperatorImpl<>("OR", BOOLEAN_X_2); - public static final Operator XNOR = new OperatorImpl<>("XNOR", BOOLEAN_X_2); - public static final Operator XOR = new OperatorImpl<>("XOR", BOOLEAN_X_2); - - // Comparable - public static final Operator BETWEEN = new OperatorImpl<>("BETWEEN", COMPARABLE_X_3); - public static final Operator GOE = new OperatorImpl<>("GOE", COMPARABLE_X_2); - public static final Operator GT = new OperatorImpl<>("GT", COMPARABLE_X_2); - public static final Operator LOE = new OperatorImpl<>("LOE", COMPARABLE_X_2); - public static final Operator LT = new OperatorImpl<>("LT", COMPARABLE_X_2); - - // Date / Comparable - public static final Operator AFTER = new OperatorImpl<>("AFTER", COMPARABLE_X_2); - public static final Operator BEFORE = new OperatorImpl<>("BEFORE", COMPARABLE_X_2); - public static final Operator AOE = new OperatorImpl<>("AOE", COMPARABLE_X_2); - public static final Operator BOE = new OperatorImpl<>("BOE", COMPARABLE_X_2); - - // Number - public static final Operator NEGATE = new OperatorImpl<>("NEGATE", Number.class); - public static final Operator ADD = new OperatorImpl<>("ADD", NUMBER_X_2); - public static final Operator DIV = new OperatorImpl<>("DIV", NUMBER_X_2); - public static final Operator MULT = new OperatorImpl<>("MULT", NUMBER_X_2); - public static final Operator SUB = new OperatorImpl<>("SUB", NUMBER_X_2); - public static final Operator MOD = new OperatorImpl<>("MOD", NUMBER_X_2); - - // String - public static final Operator CHAR_AT = new OperatorImpl<>("CHAR_AT"); - public static final Operator CONCAT = new OperatorImpl<>("CONCAT", STRING_X_2); - public static final Operator LOWER = new OperatorImpl<>("LOWER", String.class); - public static final Operator SUBSTR_1ARG = new OperatorImpl<>("SUBSTR"); - public static final Operator SUBSTR_2ARGS = new OperatorImpl<>("SUBSTR2"); - public static final Operator TRIM = new OperatorImpl<>("TRIM", String.class); - public static final Operator UPPER = new OperatorImpl<>("UPPER", String.class); - public static final Operator MATCHES = new OperatorImpl<>("MATCHES", STRING_X_2); - public static final Operator MATCHES_IC = new OperatorImpl<>("MATCHES_IC", STRING_X_2); - public static final Operator STRING_LENGTH = new OperatorImpl<>("STRING_LENGTH", String.class); - public static final Operator STRING_IS_EMPTY = new OperatorImpl<>("STRING_IS_EMPTY", String.class); - public static final Operator STARTS_WITH = new OperatorImpl<>("STARTS_WITH", STRING_X_2); - public static final Operator STARTS_WITH_IC = new OperatorImpl<>("STATS_WITH_IC", STRING_X_2); - public static final Operator INDEX_OF_2ARGS = new OperatorImpl<>("INDEX_OF2"); - public static final Operator INDEX_OF = new OperatorImpl<>("INDEX_OF"); - public static final Operator EQ_IGNORE_CASE = new OperatorImpl<>("EQ_IGNORE_CASE", STRING_X_2); - public static final Operator ENDS_WITH = new OperatorImpl<>("ENDS_WITH", STRING_X_2); - public static final Operator ENDS_WITH_IC = new OperatorImpl<>("ENDS_WITH_IC", STRING_X_2); - public static final Operator STRING_CONTAINS = new OperatorImpl<>("STRING_CONTAINS", STRING_X_2); - public static final Operator STRING_CONTAINS_IC = new OperatorImpl<>("STRING_CONTAINS_IC", STRING_X_2); - public static final Operator LIKE = new OperatorImpl<>("LIKE", STRING_X_2); - - // case - public static final Operator CASE = new OperatorImpl<>("CASE", Object.class); - public static final Operator CASE_WHEN = new OperatorImpl<>("CASE_WHEN"); - public static final Operator CASE_ELSE = new OperatorImpl<>("CASE_ELSE", Object.class); - - // case for eq - public static final Operator CASE_EQ = new OperatorImpl<>("CASE_EQ", Object.class); - public static final Operator CASE_EQ_WHEN = new OperatorImpl<>("CASE_EQ_WHEN"); - public static final Operator CASE_EQ_ELSE = new OperatorImpl<>("CASE_EQ_ELSE", Object.class); - - // coalesce - public static final Operator COALESCE = new OperatorImpl<>("COALESCE", Object.class); - - // subquery operations - public static final Operator EXISTS = new OperatorImpl<>("EXISTS", Object.class); - - public static final List> equalsOps = unmodifiableList(Arrays.> asList(EQ_OBJECT, EQ_PRIMITIVE)); - - public static final List> notEqualsOps = unmodifiableList(Arrays.> asList(NE_OBJECT, NE_PRIMITIVE)); - - public static final List> compareOps = unmodifiableList(Arrays.> asList(EQ_OBJECT, EQ_PRIMITIVE,LT, GT, GOE, LOE)); - - /** - * Aggreation operators - */ - @SuppressWarnings("unchecked") - public static final class AggOps{ - public static final Operator MAX_AGG = new OperatorImpl<>("MAX_AGG", Comparable.class); - public static final Operator MIN_AGG = new OperatorImpl<>("MIN_AGG", Comparable.class); - public static final Operator AVG_AGG = new OperatorImpl<>("AVG_AGG", Number.class); - public static final Operator SUM_AGG = new OperatorImpl<>("SUM_AGG", Number.class); - public static final Operator COUNT_AGG = new OperatorImpl<>("COUNT_AGG", Object.class); - public static final Operator COUNT_DISTINCT_AGG = new OperatorImpl<>("COUNT_DISTINCT_AGG", Object.class); - public static final Operator COUNT_ALL_AGG = new OperatorImpl<>("COUNT_ALL_AGG"); - private AggOps() {} - } - - /** - * Date and time operators - */ - @SuppressWarnings("unchecked") - public static final class DateTimeOps { - public static final Operator CURRENT_DATE = new OperatorImpl<>("CURRENT_DATE"); - public static final Operator CURRENT_TIME = new OperatorImpl<>("CURRENT_TIME"); - public static final Operator CURRENT_TIMESTAMP = new OperatorImpl<>("CURRENT_TIMESTAMP"); - public static final Operator HOUR = new OperatorImpl<>("HOUR", java.util.Date.class); - public static final Operator MINUTE = new OperatorImpl<>("MINUTE", java.util.Date.class); - public static final Operator MONTH = new OperatorImpl<>("MONTH", java.util.Date.class); - public static final Operator SECOND = new OperatorImpl<>("SECOND", java.util.Date.class); - public static final Operator MILLISECOND = new OperatorImpl<>("MILLISECOND", java.util.Date.class); - public static final Operator SYSDATE = new OperatorImpl<>("SYSDATE"); - public static final Operator YEAR = new OperatorImpl<>("YEAR", java.util.Date.class); - public static final Operator YEAR_MONTH = new OperatorImpl<>("YEAR_MONTH", java.util.Date.class); - public static final Operator WEEK = new OperatorImpl<>("WEEK", java.util.Date.class); - public static final Operator DAY_OF_WEEK = new OperatorImpl<>("DAY_OF_WEEK", java.util.Date.class); - public static final Operator DAY_OF_MONTH = new OperatorImpl<>("DAY_OF_MONTH", java.util.Date.class); - public static final Operator DAY_OF_YEAR = new OperatorImpl<>("DAY_OF_YEAR", java.util.Date.class); - private DateTimeOps() {} - } - - /** - * Math operators - * - */ - public static final class MathOps { - public static final Operator ABS = new OperatorImpl<>("ABS", Number.class); - public static final Operator ACOS = new OperatorImpl<>("ACOS", Number.class); - public static final Operator ASIN = new OperatorImpl<>("ASIN", Number.class); - public static final Operator ATAN = new OperatorImpl<>("ATAN", Number.class); - public static final Operator CEIL = new OperatorImpl<>("CEIL", Number.class); - public static final Operator COS = new OperatorImpl<>("COS", Number.class); - public static final Operator TAN = new OperatorImpl<>("TAN", Number.class); - public static final Operator SQRT = new OperatorImpl<>("SQRT", Number.class); - public static final Operator SIN = new OperatorImpl<>("SIN", Number.class); - public static final Operator ROUND = new OperatorImpl<>("ROUND", Number.class); - public static final Operator RANDOM = new OperatorImpl<>("RANDOM"); - public static final Operator POWER = new OperatorImpl<>("POWER", NUMBER_X_2); - public static final Operator MIN = new OperatorImpl<>("MIN", NUMBER_X_2); - public static final Operator MAX = new OperatorImpl<>("MAX", NUMBER_X_2); - public static final Operator LOG10 = new OperatorImpl<>("LOG10", Number.class); - public static final Operator LOG = new OperatorImpl<>("LOG", Number.class); - public static final Operator FLOOR = new OperatorImpl<>("FLOOR", Number.class); - public static final Operator EXP = new OperatorImpl<>("EXP", Number.class); - private MathOps() {} - } - - /** - * String operators - */ - public static final class StringOps { - public static final Operator LTRIM = new OperatorImpl<>("LTRIM", String.class); - public static final Operator RTRIM = new OperatorImpl<>("RTRIM", String.class); - public static final Operator SPACE = new OperatorImpl<>("SPACE", Integer.class); - public static final Operator SPLIT = new OperatorImpl<>("SPLIT", STRING_X_2); - public static final Operator LAST_INDEX_2ARGS = new OperatorImpl<>("LAST_INDEX2"); - public static final Operator LAST_INDEX = new OperatorImpl<>("LAST_INDEX", STRING_X_2); - private StringOps() {} - } - - /** - * Quantification operators - */ - @SuppressWarnings("unchecked") - public static final class QuantOps { - public static final Operator AVG_IN_COL = new OperatorImpl<>("AVG_IN_COL", Collection.class); - public static final Operator MAX_IN_COL = new OperatorImpl<>("MAX_IN_COL", Collection.class); - public static final Operator MIN_IN_COL = new OperatorImpl<>("MIN_IN_COL", Collection.class); - - // some / any = true for any - // all = true for all - // exists = true is subselect matches - // not exists = true if subselect doesn't match - public static final Operator ANY = new OperatorImpl<>("ANY", Object.class); - public static final Operator ALL = new OperatorImpl<>("ALL", Object.class); - private QuantOps() {} - } - - /** - * Operator represents operator symbols - * - * @author tiwe - * - * @param related expression type - */ - interface Operator extends Serializable{ - - /** - * Get the unique id for this Operator - * - * @return - */ - String getId(); - - /** - * Get the types related to this operator symbols - * - * @return - */ - List> getTypes(); - - } - - /** - * OperatorImpl is the default implementation of the {@link Operator} interface - */ - static class OperatorImpl implements Operator { - - private static final long serialVersionUID = -2435035383548549877L; - - private final String id; - - private final List> types; - - public OperatorImpl(String id, Class... types) { - this(id, Arrays.> asList(types)); - } - - public OperatorImpl(String id, List> types) { - this.id = id; - this.types = types; - } - - @Override - public String getId(){ - return id; - } - - @Override - public List> getTypes() { - return types; - } - - @Override - public boolean equals(Object o){ - if (o == this) { - return true; - } else if (o instanceof Operator) { - return ((Operator)o).getId().equals(id); - } else { - return false; - } - } - - @Override - public int hashCode(){ - return id.hashCode(); - } - - @Override - public String toString(){ - return id; - } - } - - private Ops() {} -} - diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ParameterDef.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ParameterDef.java deleted file mode 100644 index a0d6ff4ba..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ParameterDef.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.mysema.examples; - -public class ParameterDef { - - public static void main(String[] args) { - System.out.println(sum(3, 44)); - System.out.println(sum(4, 4, 5, 45, 45)); - } - - public static int sum(int ... values) { - int res = 0; - for (int i : values) { - res += i; - } - return res; - } -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Person.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Person.java deleted file mode 100644 index ec611f4a3..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Person.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.mysema.examples; - -public abstract class Person { - - private int age = 0; - - public abstract String firstName(); - - public final String lastName() { - return "Spiewak"; - } - - public synchronized void incrementAge() { - age += 1; - } - - //public native String hardDriveAge(); - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/PrimitiveInits.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/PrimitiveInits.java deleted file mode 100644 index f97f6e76f..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/PrimitiveInits.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.mysema.examples; - -public class PrimitiveInits { - - double a = 3; - - void doSomething() { - // byte - byte b = 0; - // char - char c = 0; - // int - int i = 2; - // long - long l1 = 1; - long l2 = 2l; - // float - float f1 = 3f; - float f2 = 3; - // double - double d1 = 2d; - double d2 = 2.0; - double d3 = 2; - System.out.println(a + d1); - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/PropertyType.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/PropertyType.java deleted file mode 100644 index 9624f12fa..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/PropertyType.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.examples; - -import javax.annotation.Nullable; - -import com.mysema.codegen.model.TypeCategory; - -/** - * PropertyType defines the Path type to be used for a Domain property - * - * @author tiwe - * - */ -public enum PropertyType { - /** - * - */ - COMPARABLE(TypeCategory.COMPARABLE), - - /** - * - */ - ENUM(TypeCategory.ENUM), - - /** - * - */ - DATE(TypeCategory.DATE), - - /** - * - */ - DATETIME(TypeCategory.DATETIME), - - /** - * - */ - NONE(null), - - /** - * - */ - NUMERIC(TypeCategory.NUMERIC), - - /** - * - */ - SIMPLE(TypeCategory.SIMPLE), - - /** - * - */ - STRING(TypeCategory.STRING), - - /** - * - */ - TIME(TypeCategory.TIME), - - /** - * - */ - ENTITY(TypeCategory.ENTITY); - - @Nullable - private final TypeCategory category; - - PropertyType(@Nullable TypeCategory category) { - this.category = category; - } - - @Nullable - public TypeCategory getCategory() { - return category; - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Protected.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Protected.java deleted file mode 100644 index 52733b8ba..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Protected.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.mysema.examples; - -public class Protected { - - protected Protected() { - - } -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/QueryDelegate.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/QueryDelegate.java deleted file mode 100644 index a0a6633ec..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/QueryDelegate.java +++ /dev/null @@ -1,39 +0,0 @@ -/* -* Copyright 2011, Mysema Ltd -* -* Licensed under the Apache License, Version 2.0 (the "License"); -* you may not use this file except in compliance with the License. -* You may obtain a copy of the License at -* http://www.apache.org/licenses/LICENSE-2.0 -* Unless required by applicable law or agreed to in writing, software -* distributed under the License is distributed on an "AS IS" BASIS, -* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -* See the License for the specific language governing permissions and -* limitations under the License. -*/ -package com.mysema.examples; - -import static java.lang.annotation.ElementType.METHOD; -import static java.lang.annotation.RetentionPolicy.RUNTIME; - -import java.lang.annotation.Documented; -import java.lang.annotation.Retention; -import java.lang.annotation.Target; - -/** -* Declaration of a static delegate method -* -* @author tiwe -* -*/ -@Documented -@Target({METHOD}) -@Retention(RUNTIME) -public @interface QueryDelegate { - - /** - * @return - */ - Class value(); - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ReflectionUtils.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ReflectionUtils.java deleted file mode 100644 index 96f5cb98d..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ReflectionUtils.java +++ /dev/null @@ -1,154 +0,0 @@ -/* - * Copyright 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.examples; - -import java.lang.reflect.AnnotatedElement; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.ParameterizedType; -import java.lang.reflect.TypeVariable; -import java.lang.reflect.WildcardType; -import java.util.ArrayDeque; -import java.util.Arrays; -import java.util.Deque; -import java.util.HashSet; -import java.util.Set; - -import javax.annotation.Nullable; - - -/** - * @author tiwe - * - */ -public final class ReflectionUtils { - -// private static final AnnotatedElement EMPTY = new Annotations(); - - private ReflectionUtils(){} - - public static AnnotatedElement getAnnotatedElement(Class beanClass, String propertyName, Class propertyClass) { - Field field = getFieldOrNull(beanClass, propertyName); - Method method = getGetterOrNull(beanClass, propertyName, propertyClass); - if (field == null || field.getAnnotations().length == 0) { - return (method != null && method.getAnnotations().length > 0) ? method : method; - } else if (method == null || method.getAnnotations().length == 0) { - return field; - } else { - //return new Annotations(field, method); - return null; - } - } - - @Nullable - private static Field getFieldOrNull(Class clazz, String propertyName) { - Class beanClass = clazz; - while (beanClass != null && !beanClass.equals(Object.class)) { - try { - return beanClass.getDeclaredField(propertyName); - } catch (SecurityException | NoSuchFieldException e) { - // skip - } - beanClass = beanClass.getSuperclass(); - } - return null; - } - - @Nullable - public static Method getGetterOrNull(Class clazz, String name, Class type){ - Class beanClass = clazz; - String methodName = ((type.equals(Boolean.class) || type.equals(boolean.class)) ? "is" : "get") + name; - while(beanClass != null && !beanClass.equals(Object.class)){ - try { - return beanClass.getDeclaredMethod(methodName); - } catch (SecurityException | NoSuchMethodException e) { // skip - } - beanClass = beanClass.getSuperclass(); - } - return null; - - } - - public static int getTypeParameterCount(java.lang.reflect.Type type){ - if (type instanceof ParameterizedType) { - return ((ParameterizedType) type).getActualTypeArguments().length; - }else{ - return 0; - } - } - - @Nullable - public static Class getTypeParameter(java.lang.reflect.Type type, int index) { - if (type instanceof ParameterizedType) { - ParameterizedType ptype = (ParameterizedType) type; - java.lang.reflect.Type[] targs = ptype.getActualTypeArguments(); - if (targs[index] instanceof WildcardType) { - WildcardType wildcardType = (WildcardType) targs[index]; - if (wildcardType.getUpperBounds()[0] instanceof Class){ - return (Class) wildcardType.getUpperBounds()[0]; - }else if (wildcardType.getUpperBounds()[0] instanceof ParameterizedType){ - return (Class) ((ParameterizedType) wildcardType.getUpperBounds()[0]).getRawType(); - }else{ - return Object.class; - } - - } else if (targs[index] instanceof TypeVariable) { - return (Class) ((TypeVariable) targs[index]).getGenericDeclaration(); - } else if (targs[index] instanceof ParameterizedType) { - return (Class) ((ParameterizedType) targs[index]).getRawType(); - } else { - return (Class) targs[index]; - } - } - return null; - } - - public static Set> getSuperClasses(Class cl) { - Set> classes = new HashSet<>(); - Class c = cl; - while (c != null) { - classes.add(c); - c = c.getSuperclass(); - } - return classes; - } - - public static Set getFields(Class cl) { - Set fields = new HashSet<>(); - Class c = cl; - while (c != null) { - for (Field field : c.getDeclaredFields()) { - fields.add(field); - } - c = c.getSuperclass(); - } - return fields; - } - - public static Set> getImplementedInterfaces(Class cl){ - Set> interfaces = new HashSet<>(); - Deque> classes = new ArrayDeque<>(); - classes.add(cl); - while (!classes.isEmpty()) { - Class c = classes.pop(); - interfaces.addAll(Arrays.asList(c.getInterfaces())); - if (c.getSuperclass() != null) { - classes.add(c.getSuperclass()); - } - classes.addAll(Arrays.asList(c.getInterfaces())); - } - return interfaces; - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Reserved.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Reserved.java deleted file mode 100644 index 50459c654..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Reserved.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.mysema.examples; - -public class Reserved { - - String type = "a"; - String var = "b"; - String val = "c"; - String object = "d"; - String def = "d"; - - public void reservedWords() { - String type = "a"; - String var = "b"; - String val = "c"; - String object = "d"; - String def = "d"; - System.err.println(type + var + val + object + def); - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Resource.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Resource.java deleted file mode 100644 index 822876cf2..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Resource.java +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (c) 2010 Mysema Ltd. - * All rights reserved. - * - */ -package com.mysema.examples; - - - -/** - * Resource provides - * - * @author tiwe - * @version $Id$ - */ -public class Resource { - - private final boolean forward; - - private final boolean l10n; - - private String path; - - public Resource(String path, boolean forward, boolean l10n) { - this.path = path; - this.forward = forward; - this.l10n = l10n; - } - - public boolean equals(Object o) { - return o instanceof Resource && ((Resource) o).path.equals(path); - } - - public int hashCode(){ - return path.hashCode(); - } - - public String getPath() { - return path; - } - - public void addPathPrefix(String basePath) { - this.path = basePath + path; - } - - public boolean isForward() { - return forward; - } - - public boolean isL10n() { - return l10n; - } - - @Override - public String toString(){ - return path; - } - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Returns.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Returns.java deleted file mode 100644 index 07112e1f8..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Returns.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.mysema.examples; - -public class Returns { - - public int shouldPrintReturns(int start, int n) { - for (int i = start; i < n; ++i) - if (i / 5 > 1) - return i; - return -1; - } - - public void shouldPrintReturns2(int start, int n) { - for (int i = start; i < n; ++i) - if (i / 5 > 1) { - doSomething(i); - return; - } - } - - public void doSomething(int n) { - - } - - public boolean shouldNotPrintReturns(boolean bool) { - return bool; - } -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/SelectedText.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/SelectedText.java deleted file mode 100644 index dcd670f49..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/SelectedText.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.mysema.examples; - -import org.apache.commons.lang3.StringUtils; - -public class SelectedText { - - private String selection; - - public SelectedText(){} - - public SelectedText(String selection) { - this.selection = selection; - } - - public String getSelection() { - return selection; - } - - public void setSelection(String selection) { - this.selection = selection; - } - - public String getFirstWord(){ - String[] words = StringUtils.split(selection); - return words[0]; - } - - public String getLastWord(){ - String[] words = StringUtils.split(selection); - return words[words.length-1]; - } - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/SimpleCompiler.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/SimpleCompiler.java deleted file mode 100644 index 3fbf74fa7..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/SimpleCompiler.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright (c) 2010 Mysema Ltd. - * All rights reserved. - * - */ -package com.mysema.examples; - -import java.io.File; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.UnsupportedEncodingException; -import java.io.Writer; -import java.net.URL; -import java.net.URLClassLoader; -import java.net.URLDecoder; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.List; -import java.util.Locale; -import java.util.Set; - -import javax.annotation.Nullable; -import javax.lang.model.SourceVersion; -import javax.tools.DiagnosticListener; -import javax.tools.JavaCompiler; -import javax.tools.JavaFileManager; -import javax.tools.JavaFileObject; -import javax.tools.StandardJavaFileManager; -import javax.tools.ToolProvider; - -/** - * SimpleCompiler provides a convenience wrapper of the JavaCompiler interface with automatic - * classpath generation - * - * @author tiwe - * - */ -public class SimpleCompiler implements JavaCompiler{ - - public static String getClassPath(URLClassLoader classLoader) { - try{ - StringBuilder path = new StringBuilder(); - for (URL url : ((URLClassLoader)classLoader).getURLs()){ - if (path.length() > 0){ - path.append(File.pathSeparator); - } - String decodedPath = URLDecoder.decode(url.getPath(),"UTF-8"); - path.append(new File(decodedPath).getAbsolutePath()); - } - return path.toString(); - }catch(UnsupportedEncodingException e){ - throw new RuntimeException(e); - } - } - - private final ClassLoader classLoader; - - @Nullable - private String classPath; - - private final JavaCompiler compiler; - - public SimpleCompiler(){ - this(ToolProvider.getSystemJavaCompiler(), Thread.currentThread().getContextClassLoader()); - } - - public SimpleCompiler(JavaCompiler compiler, ClassLoader classLoader){ - this.compiler = compiler; - this.classLoader = classLoader; - } - - private String getClasspath(){ - if (classPath == null){ - if (classLoader instanceof URLClassLoader){ - classPath = getClassPath((URLClassLoader)classLoader); - }else{ - throw new IllegalArgumentException("Unsupported ClassLoader " + classLoader); - } - } - return classPath; - } - - @Override - public Set getSourceVersions() { - return compiler.getSourceVersions(); - } - - @Override - public StandardJavaFileManager getStandardFileManager( - DiagnosticListener diagnosticListener, - Locale locale, Charset charset) { - return compiler.getStandardFileManager(diagnosticListener, locale, charset); - } - - @Override - public JavaCompiler.CompilationTask getTask(Writer out, JavaFileManager fileManager, - DiagnosticListener diagnosticListener, - Iterable options, Iterable classes, - Iterable compilationUnits) { - return compiler.getTask(out, fileManager, diagnosticListener, options, classes, compilationUnits); - } - - @Override - public int isSupportedOption(String option) { - return compiler.isSupportedOption(option); - } - - @Override - public int run(InputStream in, OutputStream out, OutputStream err, String... arguments) { - for (String a : arguments){ - if (a.equals("-classpath")){ - // FIXME varargs - //return compiler.run(in, out, err, arguments); - } - } - - // no classpath given - List args = new ArrayList<>(arguments.length + 2); - args.add("-classpath"); - args.add(getClasspath()); - for (String arg : arguments){ - args.add(arg); - } - - // FIXME varargs - //return compiler.run(in, out, err, args.toArray(new String[args.size()])); - return 0; - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/SimpleProjectableAdapter.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/SimpleProjectableAdapter.java deleted file mode 100644 index 852294c09..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/SimpleProjectableAdapter.java +++ /dev/null @@ -1,163 +0,0 @@ -/* - * Copyright 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.examples; - -import java.util.List; - -import com.mysema.commons.lang.CloseableIterator; -import com.mysema.query.Projectable; -import com.mysema.query.QueryModifiers; -import com.mysema.query.SearchResults; -import com.mysema.query.SimpleProjectable; -import com.mysema.query.SimpleQuery; -import com.mysema.query.types.Expression; -import com.mysema.query.types.OrderSpecifier; -import com.mysema.query.types.ParamExpression; -import com.mysema.query.types.Predicate; - -/** - * SimpleQueryAdapter is an apdater implementation for the SimpleQuery and SimpleProjectabl interfaces - * - * @author tiwe - * - * @param type of entity - */ -public class SimpleProjectableAdapter implements SimpleQuery>, SimpleProjectable{ - - private final Projectable projectable; - - private final Expression projection; - - private final SimpleQuery query; - -// @SuppressWarnings("BC_UNCONFIRMED_CAST") -// public & Projectable> SimpleProjectableAdapter(Q query, Expression projection) { -// // NOTE : this is a correct cast which is not handled properly by FindBugs -// this(query, query, projection); -// } - - public SimpleProjectableAdapter(SimpleQuery query, Projectable projectable, Expression projection) { - this.query = query; - this.projectable = projectable; - this.projection = projection; - } - - @Override - public boolean exists() { - return projectable.exists(); - } - - @Override - public boolean notExists() { - return projectable.notExists(); - } - - @Override - public long count() { - return projectable.count(); - } - - @Override - public long countDistinct() { - return projectable.countDistinct(); - } - - @Override - public SimpleProjectableAdapter distinct() { - query.distinct(); - return this; - } - - @Override - public SimpleProjectableAdapter limit(long limit) { - query.limit(limit); - return this; - } - - @Override - public CloseableIterator iterate() { - return projectable.iterate(projection); - } - - @Override - public CloseableIterator iterateDistinct() { - return projectable.iterateDistinct(projection); - } - - @Override - public List list() { - return projectable.list(projection); - } - - @Override - public List listDistinct() { - return projectable.listDistinct(projection); - } - - @Override - public SearchResults listDistinctResults() { - return projectable.listDistinctResults(projection); - } - - @Override - public SearchResults listResults() { - return projectable.listResults(projection); - } - - @Override - public SimpleProjectableAdapter offset(long offset) { - query.offset(offset); - return this; - } - - @Override - public SimpleProjectableAdapter orderBy(OrderSpecifier... o) { - //query.orderBy(o); FIXME vararggs - return this; - } - - @Override - public SimpleProjectableAdapter restrict(QueryModifiers modifiers) { - query.restrict(modifiers); - return this; - } - - @Override - public

SimpleProjectableAdapter set(ParamExpression

param, P value) { - query.set(param, value); - return this; - } - - @Override - public String toString() { - return query.toString(); - } - - @Override - public T singleResult() { - return projectable.singleResult(projection); - } - - @Override - public T uniqueResult() { - return projectable.uniqueResult(projection); - } - - @Override - public SimpleProjectableAdapter where(Predicate... e) { - //query.where(e); FIXME varargs - return this; - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/SourceFileObject.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/SourceFileObject.java deleted file mode 100644 index d74c72f3c..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/SourceFileObject.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Copyright (c) 2010 Mysema Ltd. - * - * base on code from https://hickory.dev.java.net/ - * - */ -package com.mysema.examples; - -import java.io.IOException; -import java.io.Writer; -import java.net.URI; - -import javax.tools.JavaFileObject; -import javax.tools.SimpleJavaFileObject; - -/** - * MemSourceFileObject defines a in-memory Java source file object - * - * @author tiwe - * - */ -public class SourceFileObject extends SimpleJavaFileObject { - - private static URI toUri(String fqname) { - return URI.create(fqname.replace(".","/") + ".java"); - } - - private final StringBuilder contents; - - public SourceFileObject(String fullName) { - super(toUri(fullName),JavaFileObject.Kind.SOURCE); - contents = new StringBuilder(1000); - } - - public SourceFileObject(String fullName, String content) { - this(fullName); - contents.append(content); - } - - @Override - public CharSequence getCharContent(boolean ignoreEncodingErrors) { - return contents; - } - - @Override - public Writer openWriter() { - return new Writer() { - @Override - public Writer append(CharSequence csq) throws IOException { - contents.append(csq); - return this; - } - - @Override - public void close(){} - - @Override - public void flush() {} - - @Override - public void write(char[] cbuf, int off, int len) throws IOException { - contents.append(cbuf,off,len); - } - }; - } -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Static.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Static.java deleted file mode 100644 index 28e0054ca..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Static.java +++ /dev/null @@ -1,13 +0,0 @@ -package com.mysema.examples; - -public class Static { - - public static void main(String[] args) { - // do nothing - } - - public static void main2(String args[]) { - // do nothing - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/StrikeLabel.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/StrikeLabel.java deleted file mode 100644 index 142071467..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/StrikeLabel.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.mysema.examples; - -import javax.swing.JLabel; - - -public class StrikeLabel extends JLabel { - public StrikeLabel(String text) { - super(text); - } - - public StrikeLabel() { - this(""); - } -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/SuperConstructors.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/SuperConstructors.java deleted file mode 100644 index 0931800fe..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/SuperConstructors.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.mysema.examples; - -public class SuperConstructors extends SuperConstructorsSuperClass { - - public SuperConstructors() { - this("first", "last"); - } - - public SuperConstructors(String first, String last) { - super(first); - } - -} - -class SuperConstructorsSuperClass { - - public SuperConstructorsSuperClass(String first) { - } -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Switch.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Switch.java deleted file mode 100644 index b582b9875..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Switch.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.mysema.examples; - -public class Switch { - - public static void method1() { - switch (42) { - default: System.out.println(42); - } - System.out.println("Hello World!"); - } - - public static void method2() { - System.out.println("Hello World!"); - switch (42) { - default: System.out.println(42); - } - } - - public static void method3() { - switch (42) { - default: System.out.println(42); - } - } - - public static void method4() { - System.out.println("Hello World!"); - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/SwitchCase.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/SwitchCase.java deleted file mode 100644 index b83c7339b..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/SwitchCase.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.mysema.examples; - -public class SwitchCase { - - public void run() { - int i = hashCode(); - switch (i) { - case 0: System.out.println(0); - case 1: System.out.println(1); - default: System.out.println(i); - } - } - - public void run2() { - int i = hashCode(); - switch (i) { - case 0: - case 1: System.out.println(1); - default: System.out.println(i); - } - } - - public void run3() { - int i = hashCode(); - switch (i) { - case 0: break; - case 1: System.out.println(1); break; - default: System.out.println(i); - } - } - - public void run4() { - String str = null; - int i = hashCode(); - switch (i) { - case 0: str = "0"; break; - case 1: str = "1"; break; - default: str = String.valueOf(i); - } - System.err.println(str); - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/SwitchCase2.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/SwitchCase2.java deleted file mode 100644 index 51790dc56..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/SwitchCase2.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.mysema.examples; - -public class SwitchCase2 { - - public void doSmth(int i) { - switch (i) { - case 3: - return; - } - } - - public String doSmthElse(int i) { - switch (i) { - case 3: - return "abc"; - default: - return null; - } - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/TryCatch.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/TryCatch.java deleted file mode 100644 index 954f7fff4..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/TryCatch.java +++ /dev/null @@ -1,102 +0,0 @@ -package com.mysema.examples; - -import java.io.ByteArrayInputStream; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.Arrays; - -public class TryCatch { - - public void run() { - try { - for (String str : Arrays.asList("a","b","c")) { - System.out.println(str); - } - } catch (IllegalArgumentException e) { - throw new RuntimeException(e); - } catch (NullPointerException e) { - System.err.println(e.getMessage()); - } catch (Exception e) { - System.err.println(e.getClass().getName()); - System.err.println(e.getMessage()); - } finally { - System.out.println("done"); - } - } - - void foo() { - try { - - } finally { - - } - } - - void bar() { - try { - } catch (Exception e) { - } - } - - void baz() { - try { - bar(); - } catch (Exception e) { - } finally { - foo(); - } - } - - void buzz() { - try { - - } finally { - baz(); - } - } - - void simplified() { - try { - System.getProperty("xxx").substring(1); - } catch (NullPointerException n) { - throw new RuntimeException(n); - } - } - - void simplified2() { - try { - System.getProperty("xxx").substring(1); - } catch (IllegalArgumentException | NullPointerException n) { - throw new RuntimeException(n); - } - } - - void multiCatch() { - try { - System.out.println("here"); - } catch (Error | Exception e) { - throw new RuntimeException(e); - } - } - - void tryWithResources() throws IOException { - try (InputStream in1 = makeInput(); - InputStream in2 = makeInput()) { - System.out.println(in1 + ", " + in2); - } catch (IOException e) { - - } finally { - System.out.println("done"); - } - - try (InputStream in = new ByteArrayInputStream(new byte[0])) { - System.out.println(in); - } - } - - FileInputStream makeInput() throws IOException { - return new FileInputStream("abc.txt"); - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/TryMe.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/TryMe.java deleted file mode 100644 index 5734ca35f..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/TryMe.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.mysema.examples; - -class TryMe { - - void someMethod(int num) {} - - void useIt() { - int n = 5; - someMethod(Integer.toString(n + 1).length() * 5); - } - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/TypeCategory.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/TypeCategory.java deleted file mode 100644 index f9b02d81e..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/TypeCategory.java +++ /dev/null @@ -1,144 +0,0 @@ -/* - * Copyright (c) 2010 Mysema Ltd. - * All rights reserved. - * - */ -package com.mysema.examples; - -import java.util.HashSet; -import java.util.Set; - -import javax.annotation.Nullable; - -/** - * TypeCategory defines the expression type used for a Field - * - * @author tiwe - * - */ -public enum TypeCategory { - /** - * - */ - SIMPLE(null), - /** - * - */ - MAP(null), - /** - * - */ - COLLECTION(null), - /** - * - */ - LIST(COLLECTION), - /** - * - */ - SET(COLLECTION), - /** - * - */ - ARRAY(null), - /** - * - */ - COMPARABLE(SIMPLE), - /** - * - */ - BOOLEAN(COMPARABLE, Boolean.class.getName()), - /** - * - */ - DATE(COMPARABLE, java.sql.Date.class.getName(), "org.joda.time.LocalDate"), - /** - * - */ - DATETIME(COMPARABLE, - java.util.Calendar.class.getName(), - java.util.Date.class.getName(), - java.sql.Timestamp.class.getName(), - "org.joda.time.LocalDateTime", - "org.joda.time.Instant", - "org.joda.time.DateTime", - "org.joda.time.DateMidnight"), - /** - * - */ - ENUM(COMPARABLE), - /** - * - */ - CUSTOM(null), - - /** - * - */ - ENTITY(null), - - /** - * - */ - NUMERIC(COMPARABLE), - /** - * - */ - STRING(COMPARABLE, String.class.getName()), - /** - * - */ - TIME(COMPARABLE, java.sql.Time.class.getName(), "org.joda.time.LocalTime"); - - @Nullable - private final TypeCategory superType; - - private final Set types; - - TypeCategory(@Nullable TypeCategory superType, String... t){ - this.superType = superType; - this.types = new HashSet<>(t.length); - for (String type : t){ - this.types.add(type); - } - } - - public TypeCategory getSuperType() { - return superType; - } - - public boolean supports(Class cl){ - return supports(cl.getName()); - } - - public boolean supports(String className){ - return types.contains(className); - } - - /** - * transitive and reflexive subCategoryOf check - * - * @param ancestor - * @return - */ - public boolean isSubCategoryOf(TypeCategory ancestor){ - if (this == ancestor){ - return true; - }else if (superType == null){ - return false; - }else{ - return superType == ancestor || superType.isSubCategoryOf(ancestor); - } - } - - public static TypeCategory get(String className){ - for (TypeCategory category : values()){ - if (category.supports(className)){ - return category; - } - } - return SIMPLE; - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Underscore.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Underscore.java deleted file mode 100644 index 300d17ccd..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Underscore.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.mysema.examples; - -public class Underscore { - - String prop_; - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/UserInfo.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/UserInfo.java deleted file mode 100644 index 2f436b7fe..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/UserInfo.java +++ /dev/null @@ -1,68 +0,0 @@ -package com.mysema.examples; - -public class UserInfo { - - private long id; - - private String username; - - public UserInfo() { - } - - public UserInfo(String username) { - this.username = username; - } - - public UserInfo(long id, String username) { - this(username); - this.id = id; - } - - public void setId(long id) { - this.id = id; - } - - public long getId() { - return id; - } - - public String getUsername() { - return username; - } - - public void setUsername(String username) { - this.username = username; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + (username == null ? 0 : username.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) { - return true; - } - if (obj == null) { - return false; - } - if (getClass() != obj.getClass()) { - return false; - } - UserInfo other = (UserInfo) obj; - if (username == null) { - if (other.username != null) { - return false; - } - } else if (!username.equals(other.username)) { - return false; - } - return true; - } - - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ValueOf.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ValueOf.java deleted file mode 100644 index 5f4f85b22..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/ValueOf.java +++ /dev/null @@ -1,9 +0,0 @@ -package com.mysema.examples; - -public class ValueOf { - - public void foo() { - double a = Double.valueOf("1.0"); - System.out.println(a - 3.0); - } -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Wildcard.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Wildcard.java deleted file mode 100644 index bd0285a01..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/Wildcard.java +++ /dev/null @@ -1,14 +0,0 @@ -package com.mysema.examples; - -import java.util.List; - -public class Wildcard { - - int foo(List list) { - return list.size(); - } - - int bar(List list) { - return list.size(); - } -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/WithComments.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/WithComments.java deleted file mode 100644 index 8945204e7..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/WithComments.java +++ /dev/null @@ -1,12 +0,0 @@ -package com.mysema.examples; - -public class WithComments { - - /** - * javadocs - */ - public void method() { - // comments inside - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/WithStatic.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/WithStatic.java deleted file mode 100644 index 09dd003c3..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/WithStatic.java +++ /dev/null @@ -1,8 +0,0 @@ -package com.mysema.examples; - -public final class WithStatic { - - public static final String CONSTANT = ""; - - private WithStatic() {} -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/WithStaticAndInstance.java b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/WithStaticAndInstance.java deleted file mode 100644 index e63e43e4a..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/examples/WithStaticAndInstance.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.mysema.examples; - -public final class WithStaticAndInstance { - - public static final String CONSTANT = ""; - - private String property; - - public String getProperty() { - return property; - } - - public void setProperty(String property) { - this.property = property; - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scala/CompileTestUtils.scala b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scala/CompileTestUtils.scala deleted file mode 100644 index f9280b216..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scala/CompileTestUtils.scala +++ /dev/null @@ -1,62 +0,0 @@ -package com.mysema.scala - -import com.mysema.scalagen.{ Scala210, ScalaVersion } -import scala.tools.nsc._ -import scala.io.Source.fromFile -import java.io.File - -object CompileTestUtils { - import java.io.File.pathSeparator - - val currentLibraries = (this.getClass.getClassLoader).asInstanceOf[java.net.URLClassLoader].getURLs().toList - val cp = (jarPathOfClass("scala.tools.nsc.Interpreter") :: - //scala.ScalaObject was a marker trait used up to 2.10 - (if (ScalaVersion.current <= Scala210) jarPathOfClass("scala.ScalaObject") else "") :: - currentLibraries) - val cpString = cp.mkString(pathSeparator) - - private def jarPathOfClass(className: String) = { - Class.forName(className).getProtectionDomain.getCodeSource.getLocation - } -} - -trait CompileTestUtils { - import CompileTestUtils._ - - def assertCompileSuccess(files: Traversable[File]): Unit = { - assertCompileSuccess(files - map (fromFile(_).mkString) - mkString ("\n")) - } - - def assertCompileSuccess(source: String): Unit = { - val out = new java.io.ByteArrayOutputStream - val interpreterWriter = new java.io.PrintWriter(out) - - val env = new Settings() - env.classpath.value = cpString - env.usejavacp.value = true - - val interpreter = new Interpreter(env, interpreterWriter) - try { - val result = interpreter.interpret(source.replaceAll("package ", "import ")) - //we have to compare as a string because of an incompatibility between 2.9 and 2.10: - //in 2.9, result is scala.tools.nsc.InterpreterResults - //in 2.10, result is scala.tools.nsc.interpreter.Results - if (result.toString != "Success") { - throw new AssertionError("Compile failed, interpreter output:\n" + out.toString("utf-8")) - } - } finally { - interpreterWriter.close - interpreter.close - } - } - - def recursiveFileList(file: File): Array[File] = { - if (file.isDirectory) { - file.listFiles.flatMap(recursiveFileList(_)) - } else { - Array(file) - } - } -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/BeanPropertiesTest.scala b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/BeanPropertiesTest.scala deleted file mode 100644 index 9946b80fc..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/BeanPropertiesTest.scala +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import org.junit.Assert.assertEquals -import japa.parser.ParseException -import japa.parser.ast.CompilationUnit -import japa.parser.ast.body.BodyDeclaration -import japa.parser.ast.body.FieldDeclaration -import java.io.FileNotFoundException -import org.junit.Test -import com.mysema.examples._ - -class BeanPropertiesTest extends AbstractParserTest { - - @Test - def Methods_Are_Removed1() { - var unit = getCompilationUnit(classOf[Bean]) - assertEquals(14, unit.getTypes.get(0).getMembers.size) - unit = new BeanProperties(Scala211).transform(unit) - assertEquals(4, unit.getTypes.get(0).getMembers.size) -// for (member <- unit.getTypes.get(1).getMembers) { -// assertEquals(classOf[FieldDeclaration], member.getClass) -// } - } - - @Test - def Methods_Are_Removed2() { - var unit = getCompilationUnit(classOf[Bean2]) - assertEquals(13, unit.getTypes.get(0).getMembers.size) - unit = new BeanProperties(Scala211).transform(unit) - assertEquals(5, unit.getTypes.get(0).getMembers.size) -// for (member <- unit.getTypes.get(0).getMembers) { -// assertEquals(classOf[FieldDeclaration], member.getClass) -// } - } -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/CompanionObjectTest.scala b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/CompanionObjectTest.scala deleted file mode 100644 index 96a914a13..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/CompanionObjectTest.scala +++ /dev/null @@ -1,59 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import org.junit.Assert._ -import java.io.FileNotFoundException -import japa.parser.ParseException -import japa.parser.ast.CompilationUnit -import org.junit.Test -import com.mysema.examples._ -import UnitTransformer._ - -class CompanionObjectTest extends AbstractParserTest { - - @Test - def Replace_Class() { - var unit = getCompilationUnit(classOf[WithStatic]) - assertEquals(1, unit.getTypes.size) - unit = CompanionObject.transform(unit) - assertEquals(1, unit.getTypes.size) - assertEquals(OBJECT, unit.getTypes.get(0).getModifiers) - assertEquals("WithStatic", unit.getTypes.get(0).getName) - } - - @Test - def Replace_Class_Imports() { - var unit = getCompilationUnit(classOf[WithStatic]) - assertEquals(0, if (unit.getImports == null) 0 else unit.getImports.size) - unit = CompanionObject.transform(unit) - assertEquals(0, if (unit.getImports == null) 0 else unit.getImports.size) - } - - @Test - def Split_Class() { - var unit = getCompilationUnit(classOf[WithStaticAndInstance]) - assertEquals(1, unit.getTypes.size) - unit = CompanionObject.transform(unit) - assertEquals(2, unit.getTypes.size) - } - - @Test - def Split_Class_Imports() { - var unit = getCompilationUnit(classOf[WithStaticAndInstance]) - assertEquals(0, if (unit.getImports == null) 0 else unit.getImports.size) - unit = CompanionObject.transform(unit) - assertEquals(1, if (unit.getImports == null) 0 else unit.getImports.size) - } -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/ConstructorsTest.scala b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/ConstructorsTest.scala deleted file mode 100644 index b9817434d..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/ConstructorsTest.scala +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import org.junit.Assert.assertEquals -import japa.parser.ParseException -import japa.parser.ast.CompilationUnit -import java.io.FileNotFoundException -import org.junit.Test -import com.mysema.examples._ - -class ConstructorsTest extends AbstractParserTest { - - @Test - def Empty_Constructor_Are_Ignored() { - var unit = getCompilationUnit(classOf[WithStatic]) - assertEquals(2, unit.getTypes.get(0).getMembers.size) - unit = Constructors.transform(unit) - assertEquals(2, unit.getTypes.get(0).getMembers.size) - } - - @Test - def Body_Is_Extracted() { - var unit = getCompilationUnit(classOf[Immutable]) - assertEquals(6, unit.getTypes.get(0).getMembers.size) - unit = Constructors.transform(unit) - assertEquals(4, unit.getTypes.get(0).getMembers.size) - } - - @Test - def Immutable2 { - var unit = getCompilationUnit(classOf[Immutable2]) - unit = Constructors.transform(unit) - // TODO - } - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/ConvertProjects.scala b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/ConvertProjects.scala deleted file mode 100644 index 78b04a211..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/ConvertProjects.scala +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import japa.parser.JavaParser -import japa.parser.ParseException -import japa.parser.ast.CompilationUnit -import java.io.File -import java.io.FileInputStream -import java.io.IOException -import java.util.ArrayList -import java.util.Arrays -import java.util.List -import org.apache.commons.io.FileUtils - -object ConvertProjects extends AbstractParserTest { - - def main(args: Array[String]) { - val start = System.currentTimeMillis() - //Converter.instance.convert(new File("../../quercus"), new File("target/quercus")) - Converter.instance.convert(new File("../../../querydsl"), new File("target/querydsl")) - Converter.instance.convert(new File("../../codegen"), new File("target/codegen")) - Converter.instance.convert(new File("../../webmin"), new File("target/webmin")) - Converter.instance.convert(new File("../../../rdfbean"), new File("target/rdfbean")) - val duration = System.currentTimeMillis() - start - println("took " + (duration/1000) + "s") - } - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/ConverterTest.scala b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/ConverterTest.scala deleted file mode 100644 index 44120cf9a..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/ConverterTest.scala +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import java.io.File -import org.junit.Test -import org.junit.Assert._ - -class ConverterTest extends AbstractParserTest { - - @Test - def Convert_Creates_Files { - Converter.instance.convert(new File("src/test/scala"), new File("target/test/scala")) - assertTrue(new File("target/test/scala/com/mysema/examples/Bean.scala").exists) - assertTrue(new File("target/test/scala/com/mysema/examples/Bean2.scala").exists) - } - - @Test - def Convert_Creates_File_with_Content { - Converter.instance.convert(new File("src/test/scala"), new File("target/test2/scala")) - assertTrue(new File("target/test2/scala/com/mysema/examples/Bean.scala").length > 0) - } - - @Test - def Convert_String_Has_Content { - assertTrue(Converter.instance.convert("class A {}").length > 0) - } - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/Enums.scala b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/Enums.scala deleted file mode 100644 index eb381f633..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/Enums.scala +++ /dev/null @@ -1,10 +0,0 @@ -package com.mysema.scalagen - -object Gender extends Enumeration { - val MALE = new Gender(0) - val FEMALE = new Gender(1) -} - -class Gender(val id: Int) extends Gender.Value { - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/HelpersTest.scala b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/HelpersTest.scala deleted file mode 100644 index 87dd8bab4..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/HelpersTest.scala +++ /dev/null @@ -1,32 +0,0 @@ -package com.mysema.scalagen - -//import japa.parser.ast.`type`._ -import org.junit.Test -import org.junit.Assert._ -import UnitTransformer._ -import java.util.Collections - -class HelpersTest { - - val helpers = new AnyRef with Helpers - - @Test - def IsHashCode { - val method = new Method(0, Type.Int, "hashCode", null) - assertTrue(helpers.isHashCode(method)) - } - - @Test - def IsEquals { - val method = new Method(0, Type.Boolean, "equals", Collections.singletonList[Parameter](new Parameter)) - assertTrue(helpers.isEquals(method)) - } - - @Test - def ToString { - val method = new Method(0, Type.String, "toString", null) - assertTrue(helpers.isToString(method)) - } - - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/ReturnsTest.scala b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/ReturnsTest.scala deleted file mode 100644 index 14b11ca22..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/ReturnsTest.scala +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import org.junit.Test -import org.junit.Assert._ - -class ReturnsTest { - - @Test - def test { - assertEquals(-1, printReturns()) - } - - def printReturns(): Int = { - for (i <- 0 until 10 if i > 2) i - -1 - } - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/ScalaDumpVisitorTest.scala b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/ScalaDumpVisitorTest.scala deleted file mode 100644 index 52b250b05..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/ScalaDumpVisitorTest.scala +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import japa.parser.JavaParser -import japa.parser.ParseException -import japa.parser.ast.CompilationUnit -import java.io.File -import java.io.FileInputStream -import java.io.IOException -import java.util.ArrayList -import java.util.Arrays -import java.util.List -import org.apache.commons.io.FileUtils -import org.junit.Test - -class ScalaDumpVisitorTest extends AbstractParserTest { - - @Test - def Dump { - val resources = new ArrayList[File]() - resources.addAll(Arrays.asList(new File("src/test/scala/com/mysema/examples").listFiles():_*)) - for (res <- resources if res.getName.endsWith(".java")) { - val out = new File("target/" + res.getName.substring(0, res.getName.length() - 5) + ".scala") - Converter.instance.convertFile(res, out) - } - } -} diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/ScalaVersionTest.scala b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/ScalaVersionTest.scala deleted file mode 100644 index 85075c178..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/ScalaVersionTest.scala +++ /dev/null @@ -1,15 +0,0 @@ -package com.mysema.scalagen - -import org.junit.Test -import org.junit.Assert._ -import java.util.Collections - -class ScalaVersionTest { - - @Test - def VersionOrdering { - assertTrue(Scala211 > Scala210) - assertTrue(Scala210 > Scala29) - } - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/SerializationTest.scala b/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/SerializationTest.scala deleted file mode 100644 index b78c17e60..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala/com/mysema/scalagen/SerializationTest.scala +++ /dev/null @@ -1,319 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import java.io.File -import java.io.FileInputStream -import java.io.IOException -import org.junit.{ Test, Ignore } -import org.junit.Assert._ -import japa.parser.JavaParser -import com.mysema.examples._ - -class SerializationTest extends AbstractParserTest { - - private def assertContains(str: String, strings: String*) { - strings.foreach { s => assertTrue(s + " was not found", str.contains(s)) } - } - - @Test - def AbstractCodeWriter { - val sources = toScala[AbstractCodeWriter[_]] - assertContains(sources, - "abstract class AbstractCodeWriter[T <: AbstractCodeWriter[T]]" + - "(private val appendable: Appendable, private val spaces: Int)\n extends Appendable {") - } - - @Test - def AbstractDao { - val sources = toScala[AbstractDao[_]] - assertContains(sources, "protected def query(): JPQLQuery = new HibernateQuery(getSession)") - } - - @Test - def AnnotatedElementAdapter { - val sources = toScala[AnnotatedElementAdapter] - assertContains(sources, "for (element <- elements; annotation <- element.getAnnotations) {") - } - - @Test - def ArrayConstructorExpression { - val sources = toScala[ArrayConstructorExpression[_]] - assertContains(sources, - "@SerialVersionUID(8667880104290226505L)", - "val elementType = `type`.getComponentType.asInstanceOf[Class[T]]", - "override def equals(obj: Any): Boolean =") - - } - - @Test - def ArrayTests { - val sources = toScala[ArrayTests] - assertContains(sources, "def foo(): Array[Int] = Array.ofDim[Int](2)") - } - - @Test - def Bean { - val sources = toScala[Bean] - assertContains(sources, "@BeanProperty") - } - - @Test - def Bean2 { - val sources = toScala[Bean2] - assertContains(sources, "@BeanProperty") - } - - @Test - def BeanWithUnderscores { - val sources = toScala[BeanWithUnderscores] - assertContains(sources, - "var firstName: String = _", - "override def toString(): String = firstName + \" \" + this.lastName") - } - - @Test - def Casts { - val sources = toScala[Casts] - assertContains(sources, "args.length.toDouble") - } - - @Test - def ConstantImpl { - val sources = toScala[ConstantImpl[_]] - assertContains(sources, "private val BYTES = new Array[Constant[Byte]](CACHE_SIZE)") - } - - @Test - def Constructors { - val sources = toScala[com.mysema.examples.Constructors] - assertContains(sources, "class Constructors(first: String, last: String) {") - } - - @Test - def Constructors2 { - val sources = toScala[com.mysema.examples.Constructors2] - assertContains(sources, "class C(private val a: Int)") - } - - @Test - def Control { - val sources = toScala[Control] - assertContains(sources, - "for (i <- 0 until integers.size) {", - "for (i <- integers) {", - "for (i <- integers if i > 0) {", - "ints.find(_ == i).getOrElse(-1)", - "ints.find(_ == i).map(2 * _).getOrElse(-1)", - "for ((key, value) <- entries) {", - "println(key + \" \" + value)") - } - - @Test - def Dao { - val sources = toScala[IDao[_,_]] - assertContains(sources, "trait IDao[Entity, Id <: Serializable] {") - } - - @Test - def DateTimeExpression { - val sources = toScala[DateTimeExpression[_]] - assertContains(sources, - "lazy val dayOfMonth = NumberOperation.create(classOf[Integer], Ops.DateTimeOps.DAY_OF_MONTH, this)", - "lazy val dayOfWeek = NumberOperation.create(classOf[Integer], Ops.DateTimeOps.DAY_OF_WEEK, this)", - "lazy val dayOfYear = NumberOperation.create(classOf[Integer], Ops.DateTimeOps.DAY_OF_YEAR, this)", - "lazy val hour = NumberOperation.create(classOf[Integer], Ops.DateTimeOps.HOUR, this)", - "lazy val minute = NumberOperation.create(classOf[Integer], Ops.DateTimeOps.MINUTE, this)", - "lazy val second = NumberOperation.create(classOf[Integer], Ops.DateTimeOps.SECOND, this)", - "lazy val milliSecond = NumberOperation.create(classOf[Integer], Ops.DateTimeOps.MILLISECOND, this)") - } - - @Test - def FileSystemRegistry { - val sources = toScala[FileSystemRegistry] - assertContains(sources, "class FileSystemRegistry private () {") - } - - @Test - def IfElse { - val sources = toScala[IfElse] - assertContains(sources, "property = if (System.currentTimeMillis() > 0) \"y\" else \"z\"") - } - - @Test - def Immutable { - val sources = toScala[Immutable] - assertContains(sources, - "class Immutable(@BeanProperty val firstName: String, @BeanProperty val lastName: String)", - "val immutable = new Immutable") - } - - @Test - def Immutable2 { - val sources = toScala[Immutable2] - assertContains(sources, - "class Immutable2(@BeanProperty val firstName: String, @BeanProperty val lastName: String)") - } - - @Test - def Initializers { - - } - - @Test - def InnerClasses { - val sources = toScala[InnerClasses] - assertContains(sources, "private class LoopContext private () {") - } - - @Test - def LongLines { - val sources = toScala[LongLinesIncludingAVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongClassName](ConversionSettings(splitLongLines = false)) - assertContains(sources, "class LongLinesIncludingAVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongClassName(nums: Int*) extends LongClassToExtendAaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa {") - assertContains(sources, "var x: LongLinesIncludingAVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongClassName = new LongLinesIncludingAVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongClassName(444, 2, 3, 4, 5, 6, 7, 8, 9, 10)") - assertContains(sources, "def this(a: Int, b: Int, c: Int, d: Int, e: Int)") - assertContains(sources, """if ("very long condition ........................".length > 0 || "other long condition".length > 0)""") - assertContains(sources, """for (n <- aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa if "long condition goes here ........................".length > 0)""") - } - - @Test - def LazyInitBeanAccessor { - val sources = toScala[LazyInitBeanAccessor] - assertContains(sources, "lazy val value = \"XXX\"") - } - - @Test - def Loop { - val sources = toScala[Loop] - assertContains(sources, """.find(_ => str.startsWith("a"))""") - assertContains(sources, ".map(_ => true)") - assertContains(sources, ".find(str.startsWith(_))") - assertContains(sources, ".map(_.length > 0)") - assertContains(sources, ".find(b => str.startsWith(b) && b.length < 10)") - assertContains(sources, ".map(b => b.length > 0 || b.length < 15)") - } - - @Test - def Modifiers { - val sources = toScala[Modifiers] - assertContains(sources, - "@transient private var foo: String = \"foo\"", - "@volatile private var bar: String = \"bar\"") - } - - @Test - def Ops { - val sources = toScala[Ops] - assertContains(sources, "object Ops {", "object AggOps {") - } - - @Test - def Protected { - val sources = toScala[Protected] - assertContains(sources, "class Protected protected ()") - } - - @Test - def Reserved { - val sources = toScala[Reserved] - assertContains(sources, "`object`","`type`","`var`","`val`") - } - - @Test - def Resource { - val sources = toScala[Resource] - assertContains(sources, "case o: Resource => o.path == path") - } - - @Test - def Returns { - val sources = toScala[Returns] - assertContains(sources,"(start until n).find(_ / 5 > 1).getOrElse(-1)") - //"for (i <- start until n if i / 5 > 1) return i",) - } - - @Test - def SimpleCompiler { - val sources = toScala[SimpleCompiler] - assertContains(sources, - "for (url <- classLoader.asInstanceOf[URLClassLoader].getURLs) {", - //"case e: UnsupportedEncodingException => throw new RuntimeException(e)", - "this(ToolProvider.getSystemJavaCompiler, Thread.currentThread().getContextClassLoader)") - } - - @Test - def SourceFileObject { - - } - - @Test - def SuperConstructors { - val sources = toScala[SuperConstructors] - assertContains(sources, - "class SuperConstructors(first: String, last: String) extends SuperConstructorsSuperClass(first) {") - } - - @Test - def SwitchCase { - val sources = toScala[SwitchCase] - assertContains(sources, - "case 0 => println(0)", - "case 1 => println(1)", - "case 0 | 1 => println(1)") - } - - @Test - def Static { - val sources = toScala[Static] - assertContains(sources, - "def main(args: Array[String])", - "def main2(args: Array[String])") - } - - @Test - def TryCatch { - val sources = toScala[TryCatch] - assertContains(sources, - "case e: IllegalArgumentException => throw new RuntimeException(e)", - "case e: NullPointerException => System.err.println(e.getMessage)") - - } - - @Test @Ignore // FIXME - def WithComments { - val sources = toScala[WithComments] - assertContains(sources, "javadocs", "// comments inside") - } - - @Test - def WithStatic { - val sources = toScala[WithStatic] - assertContains(sources, "object WithStatic {") - } - - @Test - def WithStaticAndInstance { - val sources = toScala[WithStaticAndInstance] - assertContains(sources, - "object WithStaticAndInstance {", - "class WithStaticAndInstance {") - } - - @Test - def Wildcard { - val sources = toScala[Wildcard] - assertContains(sources, "def bar(list: List[_ <: CharSequence]): Int = list.size") - } - -} \ No newline at end of file diff --git a/jsonschema2pojo-scalagen/src/test/scala210_and_up/scala/com/mysema/scalagen/AbstractParserTest.scala b/jsonschema2pojo-scalagen/src/test/scala210_and_up/scala/com/mysema/scalagen/AbstractParserTest.scala deleted file mode 100644 index ea151b0ef..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala210_and_up/scala/com/mysema/scalagen/AbstractParserTest.scala +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import japa.parser.JavaParser -import japa.parser.ParseException -import japa.parser.ast.{CompilationUnit, ImportDeclaration} -import java.io.File -import java.io.FileInputStream -import java.io.FileNotFoundException -import java.util.ArrayList -import scala.collection.JavaConversions._ -import scala.reflect.ClassTag - -abstract class AbstractParserTest { - - def getCompilationUnit(cl: Class[_]): CompilationUnit = { - var file = new File("src/test/scala/" + cl.getName.replace('.', '/') + ".java") - var in = new FileInputStream(file) - val unit = JavaParser.parse(in) - if (unit.getImports == null) { - unit.setImports(new ArrayList[ImportDeclaration]) - } - unit - } - - def toScala(obj: AnyRef): String = toScala(getCompilationUnit(obj.getClass)) - - def toScala[T](implicit ct: ClassTag[T]): String = toScala(getCompilationUnit(ct.runtimeClass)) - - def toScala[T](settings: ConversionSettings)(implicit ct: ClassTag[T]): String = - toScala(getCompilationUnit(ct.runtimeClass), settings) - - def toScala(unit: CompilationUnit): String = Converter.getInstance().toScala(unit) - - def toScala(unit: CompilationUnit, settings: ConversionSettings): String = Converter.getInstance().toScala(unit, settings) - -} diff --git a/jsonschema2pojo-scalagen/src/test/scala29/scala/com/mysema/scalagen/AbstractParserTest.scala b/jsonschema2pojo-scalagen/src/test/scala29/scala/com/mysema/scalagen/AbstractParserTest.scala deleted file mode 100644 index b8fa3bcb8..000000000 --- a/jsonschema2pojo-scalagen/src/test/scala29/scala/com/mysema/scalagen/AbstractParserTest.scala +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Copyright (C) 2011, Mysema Ltd - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.mysema.scalagen - -import japa.parser.JavaParser -import japa.parser.ParseException -import japa.parser.ast.{CompilationUnit, ImportDeclaration} -import java.io.File -import java.io.FileInputStream -import java.io.FileNotFoundException -import java.util.ArrayList -import scala.collection.JavaConversions._ - -abstract class AbstractParserTest { - - def getCompilationUnit(cl: Class[_]): CompilationUnit = { - var file = new File("src/test/scala/" + cl.getName.replace('.', '/') + ".java") - var in = new FileInputStream(file) - val unit = JavaParser.parse(in) - if (unit.getImports == null) { - unit.setImports(new ArrayList[ImportDeclaration]) - } - unit - } - - def toScala(obj: AnyRef): String = toScala(getCompilationUnit(obj.getClass)) - - def toScala[T](implicit mf: Manifest[T]): String = toScala(getCompilationUnit(mf.erasure)) - - def toScala[T](settings: ConversionSettings)(implicit mf: Manifest[T]): String = - toScala(getCompilationUnit(mf.erasure), settings) - - def toScala(unit: CompilationUnit): String = Converter.getInstance().toScala(unit) - - def toScala(unit: CompilationUnit, settings: ConversionSettings): String = Converter.getInstance().toScala(unit, settings) - -} diff --git a/pom.xml b/pom.xml index 4aaa2294e..4ad632b08 100644 --- a/pom.xml +++ b/pom.xml @@ -24,7 +24,6 @@ jsonschema2pojo-gradle-plugin jsonschema2pojo-integration-tests jsonschema2pojo-maven-plugin - jsonschema2pojo-scalagen @@ -56,7 +55,6 @@ 1.5.0 2.9.10 2.9.10.7 - 2.11.12 @@ -337,16 +335,6 @@ javaparser 1.0.10 - - org.scala-lang - scala-library - ${scala.version} - - - org.scala-lang - scala-compiler - ${scala.version} - com.sun.codemodel codemodel @@ -368,6 +356,11 @@ commons-lang 2.6 + + org.apache.commons + commons-lang3 + 3.11 + javax.validation validation-api