diff --git a/README.md b/README.md
index d82419d..150f14f 100644
--- a/README.md
+++ b/README.md
@@ -5,5 +5,5 @@ Java/Scala Code generation tool
[![Build Status](https://travis-ci.org/querydsl/codegen.svg?branch=master)](https://travis-ci.org/querydsl/codegen)
-See this test for examples https://github.com/querydsl/codegen/blob/master/src/test/java/com/mysema/codegen/JavaWriterTest.java
+See this test for examples https://github.com/querydsl/codegen/blob/master/src/test/java/com/querydsl/codegen/utils/JavaWriterTest.java
diff --git a/pom.xml b/pom.xml
index 21c638f..d9d71ac 100644
--- a/pom.xml
+++ b/pom.xml
@@ -2,16 +2,16 @@
4.0.0
- com.mysema.codegen
- codegen
- 0.6.9.BUILD-SNAPSHOT
+ com.querydsl
+ codegen-utils
+ 1.0.0-SNAPSHOT
Codegen
Code generation and compilation for Java
-
+
- com.mysema.home
- mysema-source
- 0.3.1
+ com.querydsl
+ querydsl-parent
+ 0.1.0
jar
@@ -33,17 +33,10 @@
4.01
3.0.1
- 11.0.2
- 4.3.1
+ 4.6.1
-
- com.google.guava
- guava
- 18.0
-
-
org.eclipse.jdt.core.compiler
ecj
@@ -54,14 +47,8 @@
junit
junit
- 4.8.1
+ 4.13.1
test
-
-
- javax.servlet
- servlet-api
-
-
javax.validation
@@ -69,53 +56,45 @@
1.0.CR3
test
-
-
-
- org.apache.maven.plugins
- maven-jar-plugin
-
- true
-
-
-
- com.springsource.bundlor
- com.springsource.bundlor.maven
- 1.0.0.RELEASE
-
-
- bundlor
-
- bundlor
-
-
-
-
- true
-
-
+
+ org.apache.maven.plugins
+ maven-jar-plugin
+ 2.6
+
+ true
+
+
+
+ com.springsource.bundlor
+ com.springsource.bundlor.maven
+ 1.0.0.RELEASE
+
+
+ bundlor
+
+ bundlor
+
+
+
+
+ true
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+ 1.8
+
+
-
-
-
+
com.springsource.repository.bundles.release
@@ -123,4 +102,25 @@
+
+
+
+ tiwe
+ Timo Westkämper
+ timo.westkamper@mysema.com
+ Mysema Ltd
+
+ Architect
+
+
+
+ laim
+ Lassi Immonen
+ lassi.immonen@mysema.com
+ Mysema Ltd
+
+ Consultant
+
+
+
diff --git a/src/main/java/com/mysema/codegen/AbstractCodeWriter.java b/src/main/java/com/querydsl/codegen/utils/AbstractCodeWriter.java
similarity index 94%
rename from src/main/java/com/mysema/codegen/AbstractCodeWriter.java
rename to src/main/java/com/querydsl/codegen/utils/AbstractCodeWriter.java
index 88adb83..4d1d819 100644
--- a/src/main/java/com/mysema/codegen/AbstractCodeWriter.java
+++ b/src/main/java/com/querydsl/codegen/utils/AbstractCodeWriter.java
@@ -11,12 +11,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.mysema.codegen;
+package com.querydsl.codegen.utils;
import java.io.IOException;
-import com.google.common.base.Strings;
-
/**
* @author tiwe
*
@@ -42,7 +40,7 @@ public AbstractCodeWriter(Appendable appendable, int spaces) {
}
this.appendable = appendable;
this.spaces = spaces;
- this.spacesString = Strings.repeat(" ", spaces);
+ this.spacesString = StringUtils.repeat(' ', spaces);
}
@Override
diff --git a/src/main/java/com/mysema/codegen/AbstractEvaluatorFactory.java b/src/main/java/com/querydsl/codegen/utils/AbstractEvaluatorFactory.java
similarity index 94%
rename from src/main/java/com/mysema/codegen/AbstractEvaluatorFactory.java
rename to src/main/java/com/querydsl/codegen/utils/AbstractEvaluatorFactory.java
index 1cd5cc0..f54357a 100644
--- a/src/main/java/com/mysema/codegen/AbstractEvaluatorFactory.java
+++ b/src/main/java/com/querydsl/codegen/utils/AbstractEvaluatorFactory.java
@@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.mysema.codegen;
+package com.querydsl.codegen.utils;
import java.io.IOException;
import java.io.StringWriter;
@@ -20,12 +20,12 @@
import java.util.Map;
import java.util.WeakHashMap;
-import com.mysema.codegen.model.ClassType;
-import com.mysema.codegen.model.Parameter;
-import com.mysema.codegen.model.SimpleType;
-import com.mysema.codegen.model.Type;
-import com.mysema.codegen.model.TypeCategory;
-import com.mysema.codegen.support.ClassUtils;
+import com.querydsl.codegen.utils.model.ClassType;
+import com.querydsl.codegen.utils.model.Parameter;
+import com.querydsl.codegen.utils.model.SimpleType;
+import com.querydsl.codegen.utils.model.Type;
+import com.querydsl.codegen.utils.model.TypeCategory;
+import com.querydsl.codegen.utils.support.ClassUtils;
/**
* @author tiwe
diff --git a/src/main/java/com/mysema/codegen/CodeWriter.java b/src/main/java/com/querydsl/codegen/utils/CodeWriter.java
similarity index 93%
rename from src/main/java/com/mysema/codegen/CodeWriter.java
rename to src/main/java/com/querydsl/codegen/utils/CodeWriter.java
index d06ba71..555c2f5 100644
--- a/src/main/java/com/mysema/codegen/CodeWriter.java
+++ b/src/main/java/com/querydsl/codegen/utils/CodeWriter.java
@@ -1,114 +1,114 @@
-/*
- * Copyright 2010, 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.codegen;
-
-import java.io.IOException;
-import java.lang.annotation.Annotation;
-import java.util.Collection;
-
-import com.google.common.base.Function;
-import com.mysema.codegen.model.Parameter;
-import com.mysema.codegen.model.Type;
-
-/**
- * CodeWriter defines an interface for serializing Java source code
- *
- * @author tiwe
- *
- */
-public interface CodeWriter extends Appendable {
-
- String getRawName(Type type);
-
- String getGenericName(boolean asArgType, Type type);
-
- String getClassConstant(String className);
-
- CodeWriter annotation(Annotation annotation) throws IOException;
-
- CodeWriter annotation(Class extends Annotation> annotation) throws IOException;
-
- CodeWriter beginClass(Type type) throws IOException;
-
- CodeWriter beginClass(Type type, Type superClass, Type... interfaces) throws IOException;
-
- CodeWriter beginConstructor(Collection params, Function transformer) throws IOException;
-
- CodeWriter beginConstructor(Parameter... params) throws IOException;
-
- CodeWriter beginInterface(Type type, Type... interfaces) throws IOException;
-
- CodeWriter beginLine(String... segments) throws IOException;
-
- CodeWriter beginPublicMethod(Type returnType, String methodName, Collection parameters,
- Function transformer) throws IOException;
-
- CodeWriter beginPublicMethod(Type returnType, String methodName, Parameter... args) throws IOException;
-
- CodeWriter beginStaticMethod(Type type, String name, Collection params,
- Function transformer) throws IOException;
-
- CodeWriter beginStaticMethod(Type returnType, String methodName, Parameter... args) throws IOException;
-
- CodeWriter end() throws IOException;
-
- CodeWriter field(Type type, String name) throws IOException;
-
- CodeWriter imports(Class>... imports) throws IOException;
-
- CodeWriter imports(Package... imports) throws IOException;
-
- CodeWriter importClasses(String... classes) throws IOException;
-
- CodeWriter importPackages(String... packages) throws IOException;
-
- CodeWriter javadoc(String... lines) throws IOException;
-
- CodeWriter line(String... segments) throws IOException;
-
- CodeWriter nl() throws IOException;
-
- CodeWriter packageDecl(String packageName) throws IOException;
-
- CodeWriter privateField(Type type, String name) throws IOException;
-
- CodeWriter privateFinal(Type type, String name) throws IOException;
-
- CodeWriter privateFinal(Type type, String name, String value) throws IOException;
-
- CodeWriter privateStaticFinal(Type type, String name, String value) throws IOException;
-
- CodeWriter protectedField(Type type, String name) throws IOException;
-
- CodeWriter protectedFinal(Type type, String name) throws IOException;
-
- CodeWriter protectedFinal(Type type, String name, String value) throws IOException;
-
- CodeWriter publicField(Type type, String name) throws IOException;
-
- CodeWriter publicField(Type type, String name, String value) throws IOException;
-
- CodeWriter publicFinal(Type type, String name) throws IOException;
-
- CodeWriter publicFinal(Type type, String name, String value) throws IOException;
-
- CodeWriter publicStaticFinal(Type type, String name, String value) throws IOException;
-
- CodeWriter staticimports(Class>... imports) throws IOException;
-
- CodeWriter suppressWarnings(String type) throws IOException;
-
- CodeWriter suppressWarnings(String... types) throws IOException;
-
+/*
+ * Copyright 2010, 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.querydsl.codegen.utils;
+
+import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.util.Collection;
+import java.util.function.Function;
+
+import com.querydsl.codegen.utils.model.Parameter;
+import com.querydsl.codegen.utils.model.Type;
+
+/**
+ * CodeWriter defines an interface for serializing Java source code
+ *
+ * @author tiwe
+ *
+ */
+public interface CodeWriter extends Appendable {
+
+ String getRawName(Type type);
+
+ String getGenericName(boolean asArgType, Type type);
+
+ String getClassConstant(String className);
+
+ CodeWriter annotation(Annotation annotation) throws IOException;
+
+ CodeWriter annotation(Class extends Annotation> annotation) throws IOException;
+
+ CodeWriter beginClass(Type type) throws IOException;
+
+ CodeWriter beginClass(Type type, Type superClass, Type... interfaces) throws IOException;
+
+ CodeWriter beginConstructor(Collection params, Function transformer) throws IOException;
+
+ CodeWriter beginConstructor(Parameter... params) throws IOException;
+
+ CodeWriter beginInterface(Type type, Type... interfaces) throws IOException;
+
+ CodeWriter beginLine(String... segments) throws IOException;
+
+ CodeWriter beginPublicMethod(Type returnType, String methodName, Collection parameters,
+ Function transformer) throws IOException;
+
+ CodeWriter beginPublicMethod(Type returnType, String methodName, Parameter... args) throws IOException;
+
+ CodeWriter beginStaticMethod(Type type, String name, Collection params,
+ Function transformer) throws IOException;
+
+ CodeWriter beginStaticMethod(Type returnType, String methodName, Parameter... args) throws IOException;
+
+ CodeWriter end() throws IOException;
+
+ CodeWriter field(Type type, String name) throws IOException;
+
+ CodeWriter imports(Class>... imports) throws IOException;
+
+ CodeWriter imports(Package... imports) throws IOException;
+
+ CodeWriter importClasses(String... classes) throws IOException;
+
+ CodeWriter importPackages(String... packages) throws IOException;
+
+ CodeWriter javadoc(String... lines) throws IOException;
+
+ CodeWriter line(String... segments) throws IOException;
+
+ CodeWriter nl() throws IOException;
+
+ CodeWriter packageDecl(String packageName) throws IOException;
+
+ CodeWriter privateField(Type type, String name) throws IOException;
+
+ CodeWriter privateFinal(Type type, String name) throws IOException;
+
+ CodeWriter privateFinal(Type type, String name, String value) throws IOException;
+
+ CodeWriter privateStaticFinal(Type type, String name, String value) throws IOException;
+
+ CodeWriter protectedField(Type type, String name) throws IOException;
+
+ CodeWriter protectedFinal(Type type, String name) throws IOException;
+
+ CodeWriter protectedFinal(Type type, String name, String value) throws IOException;
+
+ CodeWriter publicField(Type type, String name) throws IOException;
+
+ CodeWriter publicField(Type type, String name, String value) throws IOException;
+
+ CodeWriter publicFinal(Type type, String name) throws IOException;
+
+ CodeWriter publicFinal(Type type, String name, String value) throws IOException;
+
+ CodeWriter publicStaticFinal(Type type, String name, String value) throws IOException;
+
+ CodeWriter staticimports(Class>... imports) throws IOException;
+
+ CodeWriter suppressWarnings(String type) throws IOException;
+
+ CodeWriter suppressWarnings(String... types) throws IOException;
+
}
\ No newline at end of file
diff --git a/src/main/java/com/mysema/codegen/CodegenException.java b/src/main/java/com/querydsl/codegen/utils/CodegenException.java
similarity index 96%
rename from src/main/java/com/mysema/codegen/CodegenException.java
rename to src/main/java/com/querydsl/codegen/utils/CodegenException.java
index d76847a..52d34c9 100644
--- a/src/main/java/com/mysema/codegen/CodegenException.java
+++ b/src/main/java/com/querydsl/codegen/utils/CodegenException.java
@@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.mysema.codegen;
+package com.querydsl.codegen.utils;
/**
* @author tiwe
diff --git a/src/main/java/com/mysema/codegen/ECJEvaluatorFactory.java b/src/main/java/com/querydsl/codegen/utils/ECJEvaluatorFactory.java
similarity index 89%
rename from src/main/java/com/mysema/codegen/ECJEvaluatorFactory.java
rename to src/main/java/com/querydsl/codegen/utils/ECJEvaluatorFactory.java
index b2ba4ed..6edc162 100644
--- a/src/main/java/com/mysema/codegen/ECJEvaluatorFactory.java
+++ b/src/main/java/com/querydsl/codegen/utils/ECJEvaluatorFactory.java
@@ -1,301 +1,304 @@
-/*
- * Copyright 2010, 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.codegen;
-
-import javax.tools.JavaFileObject;
-import javax.tools.StandardLocation;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.nio.charset.Charset;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-import java.util.StringTokenizer;
-
-import com.google.common.base.Joiner;
-import com.google.common.base.Strings;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-import com.google.common.io.ByteStreams;
-import com.mysema.codegen.model.ClassType;
-import com.mysema.codegen.model.Type;
-import org.eclipse.jdt.core.compiler.CategorizedProblem;
-import org.eclipse.jdt.core.compiler.CharOperation;
-import org.eclipse.jdt.internal.compiler.*;
-import org.eclipse.jdt.internal.compiler.Compiler;
-import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
-import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
-import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
-import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
-import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
-import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
-import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
-import org.eclipse.jdt.internal.compiler.tool.EclipseFileManager;
-
-/**
- * EvaluatorFactory is a factory implementation for creating Evaluator instances
- *
- * @author tiwe
- *
- */
-public class ECJEvaluatorFactory extends AbstractEvaluatorFactory {
-
- private final MemFileManager fileManager;
-
- private final ClassLoader parentClassLoader;
-
- private final List problemList = Lists.newArrayList();
-
- private final CompilerOptions compilerOptions;
-
- public static CompilerOptions getDefaultCompilerOptions() {
- String javaSpecVersion = System.getProperty("java.specification.version");
- if (javaSpecVersion.equals("1.8")) {
- javaSpecVersion = "1.7";
- }
- Map settings = Maps.newHashMap();
- settings.put(CompilerOptions.OPTION_Source, javaSpecVersion);
- settings.put(CompilerOptions.OPTION_TargetPlatform, javaSpecVersion);
- settings.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE);
- return new CompilerOptions(settings);
- }
-
- public ECJEvaluatorFactory(ClassLoader parent) {
- this(parent, getDefaultCompilerOptions());
- }
-
- public ECJEvaluatorFactory(ClassLoader parent, CompilerOptions compilerOptions) {
- this.parentClassLoader = parent;
- this.fileManager = new MemFileManager(parent, new EclipseFileManager(Locale.getDefault(), Charset.defaultCharset()));
- this.loader = fileManager.getClassLoader(StandardLocation.CLASS_OUTPUT);
- this.compilerOptions = compilerOptions;
- }
-
- protected void compile(String source, ClassType projectionType, String[] names, Type[] types,
- String id, Map constants) throws IOException {
- // create source
- source = createSource(source, projectionType, names, types, id, constants);
-
- // compile
- final char[] targetContents = source.toCharArray();
- final String targetName = id;
- final ICompilationUnit[] targetCompilationUnits = new ICompilationUnit[] { new ICompilationUnit() {
- @Override
- public char[] getContents() {
- return targetContents;
- }
-
- @Override
- public char[] getMainTypeName() {
- int dot = targetName.lastIndexOf('.');
- if (dot > 0)
- return targetName.substring(dot + 1).toCharArray();
- else
- return targetName.toCharArray();
- }
-
- @Override
- public char[][] getPackageName() {
- StringTokenizer tok = new StringTokenizer(targetName, ".");
- char[][] result = new char[tok.countTokens() - 1][];
- for (int j = 0; j < result.length; j++) {
- result[j] = tok.nextToken().toCharArray();
- }
- return result;
- }
-
- @Override
- public char[] getFileName() {
- return CharOperation.concat(targetName.toCharArray(), ".java".toCharArray());
- }
-
- @Override
- public boolean ignoreOptionalProblems() {
- return true;
- }
- } };
-
- INameEnvironment env = new INameEnvironment() {
-
- private String join(char[][] compoundName, char separator) {
- if (compoundName == null) {
- return "";
- } else {
- List parts = Lists.newArrayListWithCapacity(compoundName.length);
- for (char[] part: compoundName) {
- parts.add(new String(part));
- }
- return Joiner.on(separator).join(parts);
- }
- }
-
- @Override
- public NameEnvironmentAnswer findType(char[][] compoundTypeName) {
- return findType(join(compoundTypeName, '.'));
- }
-
- @Override
- public NameEnvironmentAnswer findType(char[] typeName, char[][] packageName) {
- return findType(CharOperation.arrayConcat(packageName, typeName));
- }
-
- private boolean isClass(String result) {
- if (Strings.isNullOrEmpty(result)) {
- return false;
- }
-
- // if it's the class we're compiling, then of course it's a class
- if (result.equals(targetName)) {
- return true;
- }
- InputStream is = null;
- try {
- // if this is a class we've already compiled, it's a class
- is = loader.getResourceAsStream(result);
- if (is == null) {
- // use our normal class loader now...
- String resourceName = result.replace('.', '/') + ".class";
- is = parentClassLoader.getResourceAsStream(resourceName);
- if (is == null && !result.contains(".")) {
- // we couldn't find the class, and it has no package; is it a core class?
- is = parentClassLoader.getResourceAsStream("java/lang/" + resourceName);
- }
- }
- return is != null;
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (IOException ex) {}
- }
- }
- }
-
- @Override
- public boolean isPackage(char[][] parentPackageName, char[] packageName) {
- // if the parent is a class, the child can't be a package
- String parent = join(parentPackageName, '.');
- if (isClass(parent))
- return false;
-
- // if the child is a class, it's not a package
- String qualifiedName = (parent.isEmpty() ? "" : parent + ".") + new String(packageName);
- return !isClass(qualifiedName);
- }
-
- @Override
- public void cleanup() {
- }
-
- private NameEnvironmentAnswer findType(String className) {
- String resourceName = className.replace('.', '/') + ".class";
- InputStream is = null;
- try {
- // we're only asking ECJ to compile a single class; we shouldn't need this
- if (className.equals(targetName)) {
- return new NameEnvironmentAnswer(targetCompilationUnits[0], null);
- }
-
- is = loader.getResourceAsStream(resourceName);
- if (is == null) {
- is = parentClassLoader.getResourceAsStream(resourceName);
- }
-
- if (is != null) {
- ClassFileReader cfr = new ClassFileReader(ByteStreams.toByteArray(is), className.toCharArray(), true);
- return new NameEnvironmentAnswer(cfr, null);
- } else {
- return null;
- }
- } catch (ClassFormatException ex) {
- throw new RuntimeException(ex);
- } catch (IOException e) {
- throw new RuntimeException(e);
- } finally {
- if (is != null) {
- try {
- is.close();
- } catch (IOException e) {}
- }
- }
-
- }
- };
-
- ICompilerRequestor requestor = new ICompilerRequestor() {
-
- @Override
- public void acceptResult(CompilationResult result) {
- if (result.hasErrors()) {
- for (CategorizedProblem problem: result.getProblems()) {
- if (problem.isError()) {
- problemList.add(problem.getMessage());
- }
- }
- } else {
- for (ClassFile clazz: result.getClassFiles()) {
- try {
- MemJavaFileObject jfo = (MemJavaFileObject) fileManager
- .getJavaFileForOutput(StandardLocation.CLASS_OUTPUT,
- new String(clazz.fileName()), JavaFileObject.Kind.CLASS, null);
- OutputStream os = jfo.openOutputStream();
- os.write(clazz.getBytes());
- } catch (IOException ex) {
- throw new RuntimeException(ex);
- }
- }
- }
- }
- };
-
- problemList.clear();
-
- IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.exitAfterAllProblems();
- IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault());
-
- try {
- //Compiler compiler = new Compiler(env, policy, getCompilerOptions(), requestor, problemFactory, true);
- Compiler compiler = new Compiler(env, policy, compilerOptions, requestor, problemFactory);
- compiler.compile(targetCompilationUnits);
- if (!problemList.isEmpty()) {
- StringBuilder sb = new StringBuilder();
- for (String problem: problemList) {
- sb.append("\t").append(problem).append("\n");
- }
- throw new CodegenException("Compilation of " + id + " failed:\n" + source + "\n" + sb.toString());
- }
- } catch (RuntimeException ex) {
- // if we encountered an IOException, unbox and throw it;
- // if we encountered a ClassFormatException, box it as an IOException and throw it
- // otherwise, it's a legit RuntimeException,
- // not one of our checked exceptions boxed as unchecked; just rethrow
- Throwable cause = ex.getCause();
- if (cause != null) {
- if (cause instanceof IOException) {
- throw (IOException)cause;
- } else if (cause instanceof ClassFormatException) {
- throw new IOException(cause);
- }
- }
- throw ex;
- }
- }
-
- public CompilerOptions getCompilerOptions() {
- return compilerOptions;
- }
-
-
-}
+/*
+ * Copyright 2010, 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.querydsl.codegen.utils;
+
+import javax.tools.JavaFileObject;
+import javax.tools.StandardLocation;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.StringTokenizer;
+import java.util.stream.Collectors;
+
+import com.querydsl.codegen.utils.model.ClassType;
+import com.querydsl.codegen.utils.model.Type;
+import org.eclipse.jdt.core.compiler.CategorizedProblem;
+import org.eclipse.jdt.core.compiler.CharOperation;
+import org.eclipse.jdt.internal.compiler.*;
+import org.eclipse.jdt.internal.compiler.Compiler;
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFileReader;
+import org.eclipse.jdt.internal.compiler.classfmt.ClassFormatException;
+import org.eclipse.jdt.internal.compiler.env.ICompilationUnit;
+import org.eclipse.jdt.internal.compiler.env.INameEnvironment;
+import org.eclipse.jdt.internal.compiler.env.NameEnvironmentAnswer;
+import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
+import org.eclipse.jdt.internal.compiler.problem.DefaultProblemFactory;
+import org.eclipse.jdt.internal.compiler.tool.EclipseFileManager;
+
+/**
+ * EvaluatorFactory is a factory implementation for creating Evaluator instances
+ *
+ * @author tiwe
+ *
+ */
+public class ECJEvaluatorFactory extends AbstractEvaluatorFactory {
+
+ private final MemFileManager fileManager;
+
+ private final ClassLoader parentClassLoader;
+
+ private final List problemList = new ArrayList<>();
+
+ private final CompilerOptions compilerOptions;
+
+ public static CompilerOptions getDefaultCompilerOptions() {
+ String javaSpecVersion = System.getProperty("java.specification.version");
+ Map settings = new HashMap<>();
+ settings.put(CompilerOptions.OPTION_Source, javaSpecVersion);
+ settings.put(CompilerOptions.OPTION_TargetPlatform, javaSpecVersion);
+ settings.put(CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.IGNORE);
+ return new CompilerOptions(settings);
+ }
+
+ public ECJEvaluatorFactory(ClassLoader parent) {
+ this(parent, getDefaultCompilerOptions());
+ }
+
+ public ECJEvaluatorFactory(ClassLoader parent, CompilerOptions compilerOptions) {
+ this.parentClassLoader = parent;
+ this.fileManager = new MemFileManager(parent, new EclipseFileManager(Locale.getDefault(), Charset.defaultCharset()));
+ this.loader = fileManager.getClassLoader(StandardLocation.CLASS_OUTPUT);
+ this.compilerOptions = compilerOptions;
+ }
+
+ protected void compile(String source, ClassType projectionType, String[] names, Type[] types,
+ String id, Map constants) throws IOException {
+ // create source
+ source = createSource(source, projectionType, names, types, id, constants);
+
+ // compile
+ final char[] targetContents = source.toCharArray();
+ final String targetName = id;
+ final ICompilationUnit[] targetCompilationUnits = new ICompilationUnit[] { new ICompilationUnit() {
+ @Override
+ public char[] getContents() {
+ return targetContents;
+ }
+
+ @Override
+ public char[] getMainTypeName() {
+ int dot = targetName.lastIndexOf('.');
+ if (dot > 0)
+ return targetName.substring(dot + 1).toCharArray();
+ else
+ return targetName.toCharArray();
+ }
+
+ @Override
+ public char[][] getPackageName() {
+ StringTokenizer tok = new StringTokenizer(targetName, ".");
+ char[][] result = new char[tok.countTokens() - 1][];
+ for (int j = 0; j < result.length; j++) {
+ result[j] = tok.nextToken().toCharArray();
+ }
+ return result;
+ }
+
+ @Override
+ public char[] getFileName() {
+ return CharOperation.concat(targetName.toCharArray(), ".java".toCharArray());
+ }
+
+ @Override
+ public boolean ignoreOptionalProblems() {
+ return true;
+ }
+ } };
+
+ INameEnvironment env = new INameEnvironment() {
+
+ private String join(char[][] compoundName, char separator) {
+ if (compoundName == null) {
+ return "";
+ } else {
+ List parts = new ArrayList<>(compoundName.length);
+ for (char[] part: compoundName) {
+ parts.add(new String(part));
+ }
+ return parts.stream().collect(Collectors.joining(new String(new char[] { separator })));
+ }
+ }
+
+ @Override
+ public NameEnvironmentAnswer findType(char[][] compoundTypeName) {
+ return findType(join(compoundTypeName, '.'));
+ }
+
+ @Override
+ public NameEnvironmentAnswer findType(char[] typeName, char[][] packageName) {
+ return findType(CharOperation.arrayConcat(packageName, typeName));
+ }
+
+ private boolean isClass(String result) {
+ if (result == null || result.isEmpty()) {
+ return false;
+ }
+
+ // if it's the class we're compiling, then of course it's a class
+ if (result.equals(targetName)) {
+ return true;
+ }
+ InputStream is = null;
+ try {
+ // if this is a class we've already compiled, it's a class
+ is = loader.getResourceAsStream(result);
+ if (is == null) {
+ // use our normal class loader now...
+ String resourceName = result.replace('.', '/') + ".class";
+ is = parentClassLoader.getResourceAsStream(resourceName);
+ if (is == null && !result.contains(".")) {
+ // we couldn't find the class, and it has no package; is it a core class?
+ is = parentClassLoader.getResourceAsStream("java/lang/" + resourceName);
+ }
+ }
+ return is != null;
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException ex) {}
+ }
+ }
+ }
+
+ @Override
+ public boolean isPackage(char[][] parentPackageName, char[] packageName) {
+ // if the parent is a class, the child can't be a package
+ String parent = join(parentPackageName, '.');
+ if (isClass(parent))
+ return false;
+
+ // if the child is a class, it's not a package
+ String qualifiedName = (parent.isEmpty() ? "" : parent + ".") + new String(packageName);
+ return !isClass(qualifiedName);
+ }
+
+ @Override
+ public void cleanup() {
+ }
+
+ private NameEnvironmentAnswer findType(String className) {
+ String resourceName = className.replace('.', '/') + ".class";
+ InputStream is = null;
+ try {
+ // we're only asking ECJ to compile a single class; we shouldn't need this
+ if (className.equals(targetName)) {
+ return new NameEnvironmentAnswer(targetCompilationUnits[0], null);
+ }
+
+ is = loader.getResourceAsStream(resourceName);
+ if (is == null) {
+ is = parentClassLoader.getResourceAsStream(resourceName);
+ }
+
+ if (is != null) {
+
+ ByteArrayOutputStream buffer = new ByteArrayOutputStream();
+ int nRead;
+ byte[] data = new byte[1024];
+ while ((nRead = is.read(data, 0, data.length)) != -1) {
+ buffer.write(data, 0, nRead);
+ }
+ buffer.flush();
+
+ ClassFileReader cfr = new ClassFileReader(buffer.toByteArray(), className.toCharArray(), true);
+ return new NameEnvironmentAnswer(cfr, null);
+ } else {
+ return null;
+ }
+ } catch (ClassFormatException | IOException ex) {
+ throw new RuntimeException(ex);
+ } finally {
+ if (is != null) {
+ try {
+ is.close();
+ } catch (IOException e) {}
+ }
+ }
+
+ }
+ };
+
+ ICompilerRequestor requestor = new ICompilerRequestor() {
+
+ @Override
+ public void acceptResult(CompilationResult result) {
+ if (result.hasErrors()) {
+ for (CategorizedProblem problem: result.getProblems()) {
+ if (problem.isError()) {
+ problemList.add(problem.getMessage());
+ }
+ }
+ } else {
+ for (ClassFile clazz: result.getClassFiles()) {
+ try {
+ MemJavaFileObject jfo = (MemJavaFileObject) fileManager
+ .getJavaFileForOutput(StandardLocation.CLASS_OUTPUT,
+ new String(clazz.fileName()), JavaFileObject.Kind.CLASS, null);
+ OutputStream os = jfo.openOutputStream();
+ os.write(clazz.getBytes());
+ } catch (IOException ex) {
+ throw new RuntimeException(ex);
+ }
+ }
+ }
+ }
+ };
+
+ problemList.clear();
+
+ IErrorHandlingPolicy policy = DefaultErrorHandlingPolicies.exitAfterAllProblems();
+ IProblemFactory problemFactory = new DefaultProblemFactory(Locale.getDefault());
+
+ try {
+ //Compiler compiler = new Compiler(env, policy, getCompilerOptions(), requestor, problemFactory, true);
+ Compiler compiler = new Compiler(env, policy, compilerOptions, requestor, problemFactory);
+ compiler.compile(targetCompilationUnits);
+ if (!problemList.isEmpty()) {
+ StringBuilder sb = new StringBuilder();
+ for (String problem: problemList) {
+ sb.append("\t").append(problem).append("\n");
+ }
+ throw new CodegenException("Compilation of " + id + " failed:\n" + source + "\n" + sb.toString());
+ }
+ } catch (RuntimeException ex) {
+ // if we encountered an IOException, unbox and throw it;
+ // if we encountered a ClassFormatException, box it as an IOException and throw it
+ // otherwise, it's a legit RuntimeException,
+ // not one of our checked exceptions boxed as unchecked; just rethrow
+ Throwable cause = ex.getCause();
+ if (cause != null) {
+ if (cause instanceof IOException) {
+ throw (IOException)cause;
+ } else if (cause instanceof ClassFormatException) {
+ throw new IOException(cause);
+ }
+ }
+ throw ex;
+ }
+ }
+
+ public CompilerOptions getCompilerOptions() {
+ return compilerOptions;
+ }
+
+
+}
diff --git a/src/main/java/com/mysema/codegen/Evaluator.java b/src/main/java/com/querydsl/codegen/utils/Evaluator.java
similarity index 93%
rename from src/main/java/com/mysema/codegen/Evaluator.java
rename to src/main/java/com/querydsl/codegen/utils/Evaluator.java
index 6e9977a..d49d5dd 100644
--- a/src/main/java/com/mysema/codegen/Evaluator.java
+++ b/src/main/java/com/querydsl/codegen/utils/Evaluator.java
@@ -1,36 +1,36 @@
-/*
- * Copyright 2010, 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.codegen;
-
-/**
- * Evaluator defines an interface for returning a value as a result of
- * evaluating an expression using the given argument array
- *
- * @author tiwe
- *
- */
-public interface Evaluator {
-
- /**
- * @param args
- * @return
- */
- T evaluate(Object... args);
-
- /**
- * @return
- */
- Class extends T> getType();
-
-}
+/*
+ * Copyright 2010, 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.querydsl.codegen.utils;
+
+/**
+ * Evaluator defines an interface for returning a value as a result of
+ * evaluating an expression using the given argument array
+ *
+ * @author tiwe
+ *
+ */
+public interface Evaluator {
+
+ /**
+ * @param args
+ * @return
+ */
+ T evaluate(Object... args);
+
+ /**
+ * @return
+ */
+ Class extends T> getType();
+
+}
diff --git a/src/main/java/com/mysema/codegen/EvaluatorFactory.java b/src/main/java/com/querydsl/codegen/utils/EvaluatorFactory.java
similarity index 84%
rename from src/main/java/com/mysema/codegen/EvaluatorFactory.java
rename to src/main/java/com/querydsl/codegen/utils/EvaluatorFactory.java
index 58c2d30..4d6e8dd 100644
--- a/src/main/java/com/mysema/codegen/EvaluatorFactory.java
+++ b/src/main/java/com/querydsl/codegen/utils/EvaluatorFactory.java
@@ -1,56 +1,57 @@
-/*
- * Copyright 2010, 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.codegen;
-
-import com.mysema.codegen.model.ClassType;
-import com.mysema.codegen.model.Type;
-import java.util.Map;
-
-/**
- *
- * @author pgrant
- */
-public interface EvaluatorFactory {
-
- /**
- * @param source
- * @param projectionType
- * @param names
- * @param classes
- * @param constants
- * @return
- */
- Evaluator createEvaluator(String source, Class extends T> projectionType,
- String[] names, Class>[] classes, Map constants);
-
- /**
- * Create a new Evaluator instance
- *
- * @param
- * projection type
- * @param source
- * expression in Java source code form
- * @param projection
- * type of the source expression
- * @param names
- * names of the arguments
- * @param types
- * types of the arguments
- * @param constants
- * @return
- */
- Evaluator createEvaluator(String source, ClassType projection, String[] names,
- Type[] types, Class>[] classes, Map constants);
-
-}
+/*
+ * Copyright 2010, 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.querydsl.codegen.utils;
+
+import com.querydsl.codegen.utils.model.ClassType;
+import com.querydsl.codegen.utils.model.Type;
+
+import java.util.Map;
+
+/**
+ *
+ * @author pgrant
+ */
+public interface EvaluatorFactory {
+
+ /**
+ * @param source
+ * @param projectionType
+ * @param names
+ * @param classes
+ * @param constants
+ * @return
+ */
+ Evaluator createEvaluator(String source, Class extends T> projectionType,
+ String[] names, Class>[] classes, Map constants);
+
+ /**
+ * Create a new Evaluator instance
+ *
+ * @param
+ * projection type
+ * @param source
+ * expression in Java source code form
+ * @param projection
+ * type of the source expression
+ * @param names
+ * names of the arguments
+ * @param types
+ * types of the arguments
+ * @param constants
+ * @return
+ */
+ Evaluator createEvaluator(String source, ClassType projection, String[] names,
+ Type[] types, Class>[] classes, Map constants);
+
+}
diff --git a/src/main/java/com/mysema/codegen/JDKEvaluatorFactory.java b/src/main/java/com/querydsl/codegen/utils/JDKEvaluatorFactory.java
similarity index 90%
rename from src/main/java/com/mysema/codegen/JDKEvaluatorFactory.java
rename to src/main/java/com/querydsl/codegen/utils/JDKEvaluatorFactory.java
index e4f099b..2c5b731 100644
--- a/src/main/java/com/mysema/codegen/JDKEvaluatorFactory.java
+++ b/src/main/java/com/querydsl/codegen/utils/JDKEvaluatorFactory.java
@@ -1,78 +1,78 @@
-/*
- * Copyright 2010, 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.codegen;
-
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.Writer;
-import java.net.URLClassLoader;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-
-import javax.tools.JavaCompiler;
-import javax.tools.JavaCompiler.CompilationTask;
-import javax.tools.SimpleJavaFileObject;
-import javax.tools.StandardLocation;
-import javax.tools.ToolProvider;
-
-import com.mysema.codegen.model.ClassType;
-import com.mysema.codegen.model.Type;
-
-/**
- * JDKEvaluatorFactory is a factory implementation for creating Evaluator instances
- *
- * @author tiwe
- *
- */
-public class JDKEvaluatorFactory extends AbstractEvaluatorFactory {
-
- private final MemFileManager fileManager;
-
- private final String classpath;
-
- private final List compilationOptions;
-
- private final JavaCompiler compiler;
-
- public JDKEvaluatorFactory(URLClassLoader parent) {
- this(parent, ToolProvider.getSystemJavaCompiler());
- }
-
- public JDKEvaluatorFactory(URLClassLoader parent, JavaCompiler compiler) {
- this.fileManager = new MemFileManager(parent, compiler.getStandardFileManager(null, null, null));
- this.compiler = compiler;
- this.classpath = SimpleCompiler.getClassPath(parent);
- this.loader = fileManager.getClassLoader(StandardLocation.CLASS_OUTPUT);
- this.compilationOptions = Arrays.asList("-classpath", classpath, "-g:none");
- }
-
- protected void compile(String source, ClassType projectionType, String[] names, Type[] types,
- String id, Map constants) throws IOException {
- // create source
- source = createSource(source, projectionType, names, types, id, constants);
-
- // compile
- SimpleJavaFileObject javaFileObject = new MemSourceFileObject(id, source);
- Writer out = new StringWriter();
-
- CompilationTask task = compiler.getTask(out, fileManager, null, compilationOptions, null,
- Collections.singletonList(javaFileObject));
- if (!task.call().booleanValue()) {
- throw new CodegenException("Compilation of " + source + " failed.\n" + out.toString());
- }
- }
-
-}
+/*
+ * Copyright 2010, 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.querydsl.codegen.utils;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.net.URLClassLoader;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import javax.tools.JavaCompiler;
+import javax.tools.JavaCompiler.CompilationTask;
+import javax.tools.SimpleJavaFileObject;
+import javax.tools.StandardLocation;
+import javax.tools.ToolProvider;
+
+import com.querydsl.codegen.utils.model.ClassType;
+import com.querydsl.codegen.utils.model.Type;
+
+/**
+ * JDKEvaluatorFactory is a factory implementation for creating Evaluator instances
+ *
+ * @author tiwe
+ *
+ */
+public class JDKEvaluatorFactory extends AbstractEvaluatorFactory {
+
+ private final MemFileManager fileManager;
+
+ private final String classpath;
+
+ private final List compilationOptions;
+
+ private final JavaCompiler compiler;
+
+ public JDKEvaluatorFactory(URLClassLoader parent) {
+ this(parent, ToolProvider.getSystemJavaCompiler());
+ }
+
+ public JDKEvaluatorFactory(URLClassLoader parent, JavaCompiler compiler) {
+ this.fileManager = new MemFileManager(parent, compiler.getStandardFileManager(null, null, null));
+ this.compiler = compiler;
+ this.classpath = SimpleCompiler.getClassPath(parent);
+ this.loader = fileManager.getClassLoader(StandardLocation.CLASS_OUTPUT);
+ this.compilationOptions = Arrays.asList("-classpath", classpath, "-g:none");
+ }
+
+ protected void compile(String source, ClassType projectionType, String[] names, Type[] types,
+ String id, Map constants) throws IOException {
+ // create source
+ source = createSource(source, projectionType, names, types, id, constants);
+
+ // compile
+ SimpleJavaFileObject javaFileObject = new MemSourceFileObject(id, source);
+ Writer out = new StringWriter();
+
+ CompilationTask task = compiler.getTask(out, fileManager, null, compilationOptions, null,
+ Collections.singletonList(javaFileObject));
+ if (!task.call().booleanValue()) {
+ throw new CodegenException("Compilation of " + source + " failed.\n" + out.toString());
+ }
+ }
+
+}
diff --git a/src/main/java/com/mysema/codegen/JavaWriter.java b/src/main/java/com/querydsl/codegen/utils/JavaWriter.java
similarity index 91%
rename from src/main/java/com/mysema/codegen/JavaWriter.java
rename to src/main/java/com/querydsl/codegen/utils/JavaWriter.java
index 3645829..f39959f 100644
--- a/src/main/java/com/mysema/codegen/JavaWriter.java
+++ b/src/main/java/com/querydsl/codegen/utils/JavaWriter.java
@@ -1,499 +1,492 @@
-/*
- * Copyright 2010, 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.codegen;
-
-import static com.mysema.codegen.Symbols.ASSIGN;
-import static com.mysema.codegen.Symbols.COMMA;
-import static com.mysema.codegen.Symbols.DOT;
-import static com.mysema.codegen.Symbols.QUOTE;
-import static com.mysema.codegen.Symbols.SEMICOLON;
-import static com.mysema.codegen.Symbols.SPACE;
-
-import java.io.IOException;
-import java.lang.annotation.Annotation;
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashSet;
-import java.util.Set;
-import java.util.Stack;
-
-import com.google.common.base.Function;
-import com.mysema.codegen.model.Parameter;
-import com.mysema.codegen.model.Type;
-
-/**
- * JavaWriter is the default implementation of the CodeWriter interface
- *
- * @author tiwe
- *
- */
-public final class JavaWriter extends AbstractCodeWriter {
-
- private static final String EXTENDS = " extends ";
-
- private static final String IMPLEMENTS = " implements ";
-
- private static final String IMPORT = "import ";
-
- private static final String IMPORT_STATIC = "import static ";
-
- private static final String PACKAGE = "package ";
-
- private static final String PRIVATE = "private ";
-
- private static final String PRIVATE_FINAL = "private final ";
-
- private static final String PRIVATE_STATIC_FINAL = "private static final ";
-
- private static final String PROTECTED = "protected ";
-
- private static final String PROTECTED_FINAL = "protected final ";
-
- private static final String PUBLIC = "public ";
-
- private static final String PUBLIC_CLASS = "public class ";
-
- private static final String PUBLIC_FINAL = "public final ";
-
- private static final String PUBLIC_INTERFACE = "public interface ";
-
- private static final String PUBLIC_STATIC = "public static ";
-
- private static final String PUBLIC_STATIC_FINAL = "public static final ";
-
- private final Set classes = new HashSet();
-
- private final Set packages = new HashSet();
-
- private final Stack types = new Stack();
-
- public JavaWriter(Appendable appendable) {
- super(appendable, 4);
- this.packages.add("java.lang");
- }
-
- @Override
- public JavaWriter annotation(Annotation annotation) throws IOException {
- beginLine().append("@").appendType(annotation.annotationType());
- Method[] methods = annotation.annotationType().getDeclaredMethods();
- if (methods.length == 1 && methods[0].getName().equals("value")) {
- try {
- Object value = methods[0].invoke(annotation);
- append("(");
- annotationConstant(value);
- append(")");
- } catch (IllegalArgumentException e) {
- throw new CodegenException(e);
- } catch (IllegalAccessException e) {
- throw new CodegenException(e);
- } catch (InvocationTargetException e) {
- throw new CodegenException(e);
- }
- } else {
- boolean first = true;
- for (Method method : methods) {
- try {
- Object value = method.invoke(annotation);
- if (value == null || value.equals(method.getDefaultValue())) {
- continue;
- } else if (value.getClass().isArray()
- && Arrays.equals((Object[]) value, (Object[]) method.getDefaultValue())) {
- continue;
- } else if (!first) {
- append(COMMA);
- } else {
- append("(");
- }
- append(method.getName()).append("=");
- annotationConstant(value);
- } catch (IllegalArgumentException e) {
- throw new CodegenException(e);
- } catch (IllegalAccessException e) {
- throw new CodegenException(e);
- } catch (InvocationTargetException e) {
- throw new CodegenException(e);
- }
- first = false;
- }
- if (!first) {
- append(")");
- }
- }
- return nl();
- }
-
- @Override
- public JavaWriter annotation(Class extends Annotation> annotation) throws IOException {
- return beginLine().append("@").appendType(annotation).nl();
- }
-
- @SuppressWarnings("unchecked")
- private void annotationConstant(Object value) throws IOException {
- if (value.getClass().isArray()) {
- append("{");
- boolean first = true;
- for (Object o : (Object[]) value) {
- if (!first) {
- append(", ");
- }
- annotationConstant(o);
- first = false;
- }
- append("}");
- } else if (value instanceof Class) {
- appendType((Class) value).append(".class");
- } else if (value instanceof Number || value instanceof Boolean) {
- append(value.toString());
- } else if (value instanceof Enum) {
- Enum> enumValue = (Enum>) value;
- if (classes.contains(enumValue.getClass().getName())
- || packages.contains(enumValue.getClass().getPackage().getName())) {
- append(enumValue.name());
- } else {
- append(enumValue.getDeclaringClass().getName()).append(DOT).append(enumValue.name());
- }
- } else if (value instanceof String) {
- String escaped = StringUtils.escapeJava(value.toString());
- append(QUOTE).append(escaped.replace("\\/", "/")).append(QUOTE);
- } else {
- throw new IllegalArgumentException("Unsupported annotation value : " + value);
- }
- }
-
- private JavaWriter appendType(Class> type) throws IOException {
- if (classes.contains(type.getName()) || packages.contains(type.getPackage().getName())) {
- append(type.getSimpleName());
- } else {
- append(type.getName());
- }
- return this;
- }
-
- @Override
- public JavaWriter beginClass(Type type) throws IOException {
- return beginClass(type, null);
- }
-
- @Override
- public JavaWriter beginClass(Type type, Type superClass, Type... interfaces) throws IOException {
- packages.add(type.getPackageName());
- beginLine(PUBLIC_CLASS, type.getGenericName(false, packages, classes));
- if (superClass != null) {
- append(EXTENDS).append(superClass.getGenericName(false, packages, classes));
- }
- if (interfaces.length > 0) {
- append(IMPLEMENTS);
- for (int i = 0; i < interfaces.length; i++) {
- if (i > 0) {
- append(COMMA);
- }
- append(interfaces[i].getGenericName(false, packages, classes));
- }
- }
- append(" {").nl().nl();
- goIn();
- types.push(type);
- return this;
- }
-
- @Override
- public JavaWriter beginConstructor(Collection parameters,
- Function transformer) throws IOException {
- types.push(types.peek());
- beginLine(PUBLIC, types.peek().getSimpleName()).params(parameters, transformer)
- .append(" {").nl();
- return goIn();
- }
-
- @Override
- public JavaWriter beginConstructor(Parameter... parameters) throws IOException {
- types.push(types.peek());
- beginLine(PUBLIC, types.peek().getSimpleName()).params(parameters).append(" {").nl();
- return goIn();
- }
-
- @Override
- public JavaWriter beginInterface(Type type, Type... interfaces) throws IOException {
- packages.add(type.getPackageName());
- beginLine(PUBLIC_INTERFACE, type.getGenericName(false, packages, classes));
- if (interfaces.length > 0) {
- append(EXTENDS);
- for (int i = 0; i < interfaces.length; i++) {
- if (i > 0) {
- append(COMMA);
- }
- append(interfaces[i].getGenericName(false, packages, classes));
- }
- }
- append(" {").nl().nl();
- goIn();
- types.push(type);
- return this;
- }
-
- private JavaWriter beginMethod(String modifiers, Type returnType, String methodName,
- Parameter... args) throws IOException {
- types.push(types.peek());
- beginLine(
- modifiers, returnType.getGenericName(true, packages, classes), SPACE, methodName)
- .params(args).append(" {").nl();
- return goIn();
- }
-
- @Override
- public JavaWriter beginPublicMethod(Type returnType, String methodName,
- Collection parameters, Function transformer) throws IOException {
- return beginMethod(PUBLIC, returnType, methodName, transform(parameters, transformer));
- }
-
- @Override
- public JavaWriter beginPublicMethod(Type returnType, String methodName, Parameter... args)
- throws IOException {
- return beginMethod(PUBLIC, returnType, methodName, args);
- }
-
- @Override
- public JavaWriter beginStaticMethod(Type returnType, String methodName,
- Collection parameters, Function transformer) throws IOException {
- return beginMethod(PUBLIC_STATIC, returnType, methodName,
- transform(parameters, transformer));
- }
-
- @Override
- public JavaWriter beginStaticMethod(Type returnType, String methodName, Parameter... args)
- throws IOException {
- return beginMethod(PUBLIC_STATIC, returnType, methodName, args);
- }
-
- @Override
- public JavaWriter end() throws IOException {
- types.pop();
- goOut();
- return line("}").nl();
- }
-
- @Override
- public JavaWriter field(Type type, String name) throws IOException {
- return line(type.getGenericName(true, packages, classes), SPACE, name, SEMICOLON).nl();
- }
-
- private JavaWriter field(String modifier, Type type, String name) throws IOException {
- return line(
- modifier, type.getGenericName(true, packages, classes), SPACE, name, SEMICOLON)
- .nl();
- }
-
- private JavaWriter field(String modifier, Type type, String name, String value)
- throws IOException {
- return line(
- modifier, type.getGenericName(true, packages, classes), SPACE, name,
- ASSIGN , value, SEMICOLON).nl();
- }
-
-
- @Override
- public String getClassConstant(String className) {
- return className + ".class";
- }
-
- @Override
- public String getGenericName(boolean asArgType, Type type) {
- return type.getGenericName(asArgType, packages, classes);
- }
-
- @Override
- public String getRawName(Type type) {
- return type.getRawName(packages, classes);
- }
-
- @Override
- public JavaWriter imports(Class>... imports) throws IOException {
- for (Class> cl : imports) {
- classes.add(cl.getName());
- line(IMPORT, cl.getName(), SEMICOLON);
- }
- nl();
- return this;
- }
-
- @Override
- public JavaWriter imports(Package... imports) throws IOException {
- for (Package p : imports) {
- packages.add(p.getName());
- line(IMPORT, p.getName(), ".*;");
- }
- nl();
- return this;
- }
-
- @Override
- public JavaWriter importClasses(String... imports) throws IOException {
- for (String cl : imports) {
- classes.add(cl);
- line(IMPORT, cl, SEMICOLON);
- }
- nl();
- return this;
- }
-
- @Override
- public JavaWriter importPackages(String... imports) throws IOException {
- for (String p : imports) {
- packages.add(p);
- line(IMPORT, p, ".*;");
- }
- nl();
- return this;
- }
-
- @Override
- public JavaWriter javadoc(String... lines) throws IOException {
- line("/**");
- for (String line : lines) {
- line(" * ", line);
- }
- return line(" */");
- }
-
- @Override
- public JavaWriter packageDecl(String packageName) throws IOException {
- packages.add(packageName);
- return line(PACKAGE, packageName, SEMICOLON).nl();
- }
-
- private JavaWriter params(Collection parameters, Function transformer)
- throws IOException {
- append("(");
- boolean first = true;
- for (T param : parameters) {
- if (!first) {
- append(COMMA);
- }
- param(transformer.apply(param));
- first = false;
- }
- append(")");
- return this;
- }
-
- private JavaWriter params(Parameter... params) throws IOException {
- append("(");
- for (int i = 0; i < params.length; i++) {
- if (i > 0) {
- append(COMMA);
- }
- param(params[i]);
- }
- append(")");
- return this;
- }
-
- private JavaWriter param(Parameter parameter) throws IOException {
- append(parameter.getType().getGenericName(true, packages, classes));
- append(" ");
- append(parameter.getName());
- return this;
- }
-
- @Override
- public JavaWriter privateField(Type type, String name) throws IOException {
- return field(PRIVATE, type, name);
- }
-
- @Override
- public JavaWriter privateFinal(Type type, String name) throws IOException {
- return field(PRIVATE_FINAL, type, name);
- }
-
- @Override
- public JavaWriter privateFinal(Type type, String name, String value) throws IOException {
- return field(PRIVATE_FINAL, type, name, value);
- }
-
- @Override
- public JavaWriter privateStaticFinal(Type type, String name, String value) throws IOException {
- return field(PRIVATE_STATIC_FINAL, type, name, value);
- }
-
- @Override
- public JavaWriter protectedField(Type type, String name) throws IOException {
- return field(PROTECTED, type, name);
- }
-
- @Override
- public JavaWriter protectedFinal(Type type, String name) throws IOException {
- return field(PROTECTED_FINAL, type, name);
- }
-
- @Override
- public JavaWriter protectedFinal(Type type, String name, String value) throws IOException {
- return field(PROTECTED_FINAL, type, name, value);
- }
-
- @Override
- public JavaWriter publicField(Type type, String name) throws IOException {
- return field(PUBLIC, type, name);
- }
-
- @Override
- public JavaWriter publicField(Type type, String name, String value) throws IOException {
- return field(PUBLIC, type, name, value);
- }
-
- @Override
- public JavaWriter publicFinal(Type type, String name) throws IOException {
- return field(PUBLIC_FINAL, type, name);
- }
-
- @Override
- public JavaWriter publicFinal(Type type, String name, String value) throws IOException {
- return field(PUBLIC_FINAL, type, name, value);
- }
-
- @Override
- public JavaWriter publicStaticFinal(Type type, String name, String value) throws IOException {
- return field(PUBLIC_STATIC_FINAL, type, name, value);
- }
-
- @Override
- public JavaWriter staticimports(Class>... imports) throws IOException {
- for (Class> cl : imports) {
- line(IMPORT_STATIC, cl.getName(), ".*;");
- }
- return this;
- }
-
- @Override
- public JavaWriter suppressWarnings(String type) throws IOException {
- return line("@SuppressWarnings(\"", type, "\")");
- }
-
- @Override
- public CodeWriter suppressWarnings(String... types) throws IOException {
- return annotation(new MultiSuppressWarnings(types));
- }
-
- private Parameter[] transform(Collection parameters,
- Function transformer) {
- Parameter[] rv = new Parameter[parameters.size()];
- int i = 0;
- for (T value : parameters) {
- rv[i++] = transformer.apply(value);
- }
- return rv;
- }
-
-}
+/*
+ * Copyright 2010, 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.querydsl.codegen.utils;
+
+import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.Stack;
+import java.util.function.Function;
+
+import com.querydsl.codegen.utils.model.Parameter;
+import com.querydsl.codegen.utils.model.Type;
+
+/**
+ * JavaWriter is the default implementation of the CodeWriter interface
+ *
+ * @author tiwe
+ *
+ */
+public final class JavaWriter extends AbstractCodeWriter {
+
+ private static final String EXTENDS = " extends ";
+
+ private static final String IMPLEMENTS = " implements ";
+
+ private static final String IMPORT = "import ";
+
+ private static final String IMPORT_STATIC = "import static ";
+
+ private static final String PACKAGE = "package ";
+
+ private static final String PRIVATE = "private ";
+
+ private static final String PRIVATE_FINAL = "private final ";
+
+ private static final String PRIVATE_STATIC_FINAL = "private static final ";
+
+ private static final String PROTECTED = "protected ";
+
+ private static final String PROTECTED_FINAL = "protected final ";
+
+ private static final String PUBLIC = "public ";
+
+ private static final String PUBLIC_CLASS = "public class ";
+
+ private static final String PUBLIC_FINAL = "public final ";
+
+ private static final String PUBLIC_INTERFACE = "public interface ";
+
+ private static final String PUBLIC_STATIC = "public static ";
+
+ private static final String PUBLIC_STATIC_FINAL = "public static final ";
+
+ private final Set classes = new HashSet();
+
+ private final Set packages = new HashSet();
+
+ private final Stack types = new Stack();
+
+ public JavaWriter(Appendable appendable) {
+ super(appendable, 4);
+ this.packages.add("java.lang");
+ }
+
+ @Override
+ public JavaWriter annotation(Annotation annotation) throws IOException {
+ beginLine().append("@").appendType(annotation.annotationType());
+ Method[] methods = annotation.annotationType().getDeclaredMethods();
+ if (methods.length == 1 && methods[0].getName().equals("value")) {
+ try {
+ Object value = methods[0].invoke(annotation);
+ append("(");
+ annotationConstant(value);
+ append(")");
+ } catch (IllegalArgumentException e) {
+ throw new CodegenException(e);
+ } catch (IllegalAccessException e) {
+ throw new CodegenException(e);
+ } catch (InvocationTargetException e) {
+ throw new CodegenException(e);
+ }
+ } else {
+ boolean first = true;
+ for (Method method : methods) {
+ try {
+ Object value = method.invoke(annotation);
+ if (value == null || value.equals(method.getDefaultValue())) {
+ continue;
+ } else if (value.getClass().isArray()
+ && Arrays.equals((Object[]) value, (Object[]) method.getDefaultValue())) {
+ continue;
+ } else if (!first) {
+ append(Symbols.COMMA);
+ } else {
+ append("(");
+ }
+ append(method.getName()).append("=");
+ annotationConstant(value);
+ } catch (IllegalArgumentException e) {
+ throw new CodegenException(e);
+ } catch (IllegalAccessException e) {
+ throw new CodegenException(e);
+ } catch (InvocationTargetException e) {
+ throw new CodegenException(e);
+ }
+ first = false;
+ }
+ if (!first) {
+ append(")");
+ }
+ }
+ return nl();
+ }
+
+ @Override
+ public JavaWriter annotation(Class extends Annotation> annotation) throws IOException {
+ return beginLine().append("@").appendType(annotation).nl();
+ }
+
+ @SuppressWarnings("unchecked")
+ private void annotationConstant(Object value) throws IOException {
+ if (value.getClass().isArray()) {
+ append("{");
+ boolean first = true;
+ for (Object o : (Object[]) value) {
+ if (!first) {
+ append(", ");
+ }
+ annotationConstant(o);
+ first = false;
+ }
+ append("}");
+ } else if (value instanceof Class) {
+ appendType((Class) value).append(".class");
+ } else if (value instanceof Number || value instanceof Boolean) {
+ append(value.toString());
+ } else if (value instanceof Enum) {
+ Enum> enumValue = (Enum>) value;
+ if (classes.contains(enumValue.getClass().getName())
+ || packages.contains(enumValue.getClass().getPackage().getName())) {
+ append(enumValue.name());
+ } else {
+ append(enumValue.getDeclaringClass().getName()).append(Symbols.DOT).append(enumValue.name());
+ }
+ } else if (value instanceof String) {
+ String escaped = StringUtils.escapeJava(value.toString());
+ append(Symbols.QUOTE).append(escaped.replace("\\/", "/")).append(Symbols.QUOTE);
+ } else {
+ throw new IllegalArgumentException("Unsupported annotation value : " + value);
+ }
+ }
+
+ private JavaWriter appendType(Class> type) throws IOException {
+ if (classes.contains(type.getName()) || packages.contains(type.getPackage().getName())) {
+ append(type.getSimpleName());
+ } else {
+ append(type.getName());
+ }
+ return this;
+ }
+
+ @Override
+ public JavaWriter beginClass(Type type) throws IOException {
+ return beginClass(type, null);
+ }
+
+ @Override
+ public JavaWriter beginClass(Type type, Type superClass, Type... interfaces) throws IOException {
+ packages.add(type.getPackageName());
+ beginLine(PUBLIC_CLASS, type.getGenericName(false, packages, classes));
+ if (superClass != null) {
+ append(EXTENDS).append(superClass.getGenericName(false, packages, classes));
+ }
+ if (interfaces.length > 0) {
+ append(IMPLEMENTS);
+ for (int i = 0; i < interfaces.length; i++) {
+ if (i > 0) {
+ append(Symbols.COMMA);
+ }
+ append(interfaces[i].getGenericName(false, packages, classes));
+ }
+ }
+ append(" {").nl().nl();
+ goIn();
+ types.push(type);
+ return this;
+ }
+
+ @Override
+ public JavaWriter beginConstructor(Collection parameters,
+ Function transformer) throws IOException {
+ types.push(types.peek());
+ beginLine(PUBLIC, types.peek().getSimpleName()).params(parameters, transformer)
+ .append(" {").nl();
+ return goIn();
+ }
+
+ @Override
+ public JavaWriter beginConstructor(Parameter... parameters) throws IOException {
+ types.push(types.peek());
+ beginLine(PUBLIC, types.peek().getSimpleName()).params(parameters).append(" {").nl();
+ return goIn();
+ }
+
+ @Override
+ public JavaWriter beginInterface(Type type, Type... interfaces) throws IOException {
+ packages.add(type.getPackageName());
+ beginLine(PUBLIC_INTERFACE, type.getGenericName(false, packages, classes));
+ if (interfaces.length > 0) {
+ append(EXTENDS);
+ for (int i = 0; i < interfaces.length; i++) {
+ if (i > 0) {
+ append(Symbols.COMMA);
+ }
+ append(interfaces[i].getGenericName(false, packages, classes));
+ }
+ }
+ append(" {").nl().nl();
+ goIn();
+ types.push(type);
+ return this;
+ }
+
+ private JavaWriter beginMethod(String modifiers, Type returnType, String methodName,
+ Parameter... args) throws IOException {
+ types.push(types.peek());
+ beginLine(
+ modifiers, returnType.getGenericName(true, packages, classes), Symbols.SPACE, methodName)
+ .params(args).append(" {").nl();
+ return goIn();
+ }
+
+ @Override
+ public JavaWriter beginPublicMethod(Type returnType, String methodName,
+ Collection parameters, Function transformer) throws IOException {
+ return beginMethod(PUBLIC, returnType, methodName, transform(parameters, transformer));
+ }
+
+ @Override
+ public JavaWriter beginPublicMethod(Type returnType, String methodName, Parameter... args)
+ throws IOException {
+ return beginMethod(PUBLIC, returnType, methodName, args);
+ }
+
+ @Override
+ public JavaWriter beginStaticMethod(Type returnType, String methodName,
+ Collection parameters, Function transformer) throws IOException {
+ return beginMethod(PUBLIC_STATIC, returnType, methodName,
+ transform(parameters, transformer));
+ }
+
+ @Override
+ public JavaWriter beginStaticMethod(Type returnType, String methodName, Parameter... args)
+ throws IOException {
+ return beginMethod(PUBLIC_STATIC, returnType, methodName, args);
+ }
+
+ @Override
+ public JavaWriter end() throws IOException {
+ types.pop();
+ goOut();
+ return line("}").nl();
+ }
+
+ @Override
+ public JavaWriter field(Type type, String name) throws IOException {
+ return line(type.getGenericName(true, packages, classes), Symbols.SPACE, name, Symbols.SEMICOLON).nl();
+ }
+
+ private JavaWriter field(String modifier, Type type, String name) throws IOException {
+ return line(
+ modifier, type.getGenericName(true, packages, classes), Symbols.SPACE, name, Symbols.SEMICOLON)
+ .nl();
+ }
+
+ private JavaWriter field(String modifier, Type type, String name, String value)
+ throws IOException {
+ return line(
+ modifier, type.getGenericName(true, packages, classes), Symbols.SPACE, name,
+ Symbols.ASSIGN , value, Symbols.SEMICOLON).nl();
+ }
+
+
+ @Override
+ public String getClassConstant(String className) {
+ return className + ".class";
+ }
+
+ @Override
+ public String getGenericName(boolean asArgType, Type type) {
+ return type.getGenericName(asArgType, packages, classes);
+ }
+
+ @Override
+ public String getRawName(Type type) {
+ return type.getRawName(packages, classes);
+ }
+
+ @Override
+ public JavaWriter imports(Class>... imports) throws IOException {
+ for (Class> cl : imports) {
+ classes.add(cl.getName());
+ line(IMPORT, cl.getName(), Symbols.SEMICOLON);
+ }
+ nl();
+ return this;
+ }
+
+ @Override
+ public JavaWriter imports(Package... imports) throws IOException {
+ for (Package p : imports) {
+ packages.add(p.getName());
+ line(IMPORT, p.getName(), ".*;");
+ }
+ nl();
+ return this;
+ }
+
+ @Override
+ public JavaWriter importClasses(String... imports) throws IOException {
+ for (String cl : imports) {
+ classes.add(cl);
+ line(IMPORT, cl, Symbols.SEMICOLON);
+ }
+ nl();
+ return this;
+ }
+
+ @Override
+ public JavaWriter importPackages(String... imports) throws IOException {
+ for (String p : imports) {
+ packages.add(p);
+ line(IMPORT, p, ".*;");
+ }
+ nl();
+ return this;
+ }
+
+ @Override
+ public JavaWriter javadoc(String... lines) throws IOException {
+ line("/**");
+ for (String line : lines) {
+ line(" * ", line);
+ }
+ return line(" */");
+ }
+
+ @Override
+ public JavaWriter packageDecl(String packageName) throws IOException {
+ packages.add(packageName);
+ return line(PACKAGE, packageName, Symbols.SEMICOLON).nl();
+ }
+
+ private JavaWriter params(Collection parameters, Function transformer)
+ throws IOException {
+ append("(");
+ boolean first = true;
+ for (T param : parameters) {
+ if (!first) {
+ append(Symbols.COMMA);
+ }
+ param(transformer.apply(param));
+ first = false;
+ }
+ append(")");
+ return this;
+ }
+
+ private JavaWriter params(Parameter... params) throws IOException {
+ append("(");
+ for (int i = 0; i < params.length; i++) {
+ if (i > 0) {
+ append(Symbols.COMMA);
+ }
+ param(params[i]);
+ }
+ append(")");
+ return this;
+ }
+
+ private JavaWriter param(Parameter parameter) throws IOException {
+ append(parameter.getType().getGenericName(true, packages, classes));
+ append(" ");
+ append(parameter.getName());
+ return this;
+ }
+
+ @Override
+ public JavaWriter privateField(Type type, String name) throws IOException {
+ return field(PRIVATE, type, name);
+ }
+
+ @Override
+ public JavaWriter privateFinal(Type type, String name) throws IOException {
+ return field(PRIVATE_FINAL, type, name);
+ }
+
+ @Override
+ public JavaWriter privateFinal(Type type, String name, String value) throws IOException {
+ return field(PRIVATE_FINAL, type, name, value);
+ }
+
+ @Override
+ public JavaWriter privateStaticFinal(Type type, String name, String value) throws IOException {
+ return field(PRIVATE_STATIC_FINAL, type, name, value);
+ }
+
+ @Override
+ public JavaWriter protectedField(Type type, String name) throws IOException {
+ return field(PROTECTED, type, name);
+ }
+
+ @Override
+ public JavaWriter protectedFinal(Type type, String name) throws IOException {
+ return field(PROTECTED_FINAL, type, name);
+ }
+
+ @Override
+ public JavaWriter protectedFinal(Type type, String name, String value) throws IOException {
+ return field(PROTECTED_FINAL, type, name, value);
+ }
+
+ @Override
+ public JavaWriter publicField(Type type, String name) throws IOException {
+ return field(PUBLIC, type, name);
+ }
+
+ @Override
+ public JavaWriter publicField(Type type, String name, String value) throws IOException {
+ return field(PUBLIC, type, name, value);
+ }
+
+ @Override
+ public JavaWriter publicFinal(Type type, String name) throws IOException {
+ return field(PUBLIC_FINAL, type, name);
+ }
+
+ @Override
+ public JavaWriter publicFinal(Type type, String name, String value) throws IOException {
+ return field(PUBLIC_FINAL, type, name, value);
+ }
+
+ @Override
+ public JavaWriter publicStaticFinal(Type type, String name, String value) throws IOException {
+ return field(PUBLIC_STATIC_FINAL, type, name, value);
+ }
+
+ @Override
+ public JavaWriter staticimports(Class>... imports) throws IOException {
+ for (Class> cl : imports) {
+ line(IMPORT_STATIC, cl.getName(), ".*;");
+ }
+ return this;
+ }
+
+ @Override
+ public JavaWriter suppressWarnings(String type) throws IOException {
+ return line("@SuppressWarnings(\"", type, "\")");
+ }
+
+ @Override
+ public CodeWriter suppressWarnings(String... types) throws IOException {
+ return annotation(new MultiSuppressWarnings(types));
+ }
+
+ private Parameter[] transform(Collection parameters,
+ Function transformer) {
+ Parameter[] rv = new Parameter[parameters.size()];
+ int i = 0;
+ for (T value : parameters) {
+ rv[i++] = transformer.apply(value);
+ }
+ return rv;
+ }
+
+}
diff --git a/src/main/java/com/mysema/codegen/LocationAndKind.java b/src/main/java/com/querydsl/codegen/utils/LocationAndKind.java
similarity index 94%
rename from src/main/java/com/mysema/codegen/LocationAndKind.java
rename to src/main/java/com/querydsl/codegen/utils/LocationAndKind.java
index 869d69a..1aef471 100644
--- a/src/main/java/com/mysema/codegen/LocationAndKind.java
+++ b/src/main/java/com/querydsl/codegen/utils/LocationAndKind.java
@@ -1,58 +1,58 @@
-/*
- * Copyright 2010, 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.codegen;
-
-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();
- }
-
-}
+/*
+ * Copyright 2010, 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.querydsl.codegen.utils;
+
+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/src/main/java/com/mysema/codegen/MemClassLoader.java b/src/main/java/com/querydsl/codegen/utils/MemClassLoader.java
similarity index 96%
rename from src/main/java/com/mysema/codegen/MemClassLoader.java
rename to src/main/java/com/querydsl/codegen/utils/MemClassLoader.java
index d7e999b..90bcd12 100644
--- a/src/main/java/com/mysema/codegen/MemClassLoader.java
+++ b/src/main/java/com/querydsl/codegen/utils/MemClassLoader.java
@@ -1,126 +1,126 @@
-/*
- * Copyright 2010, 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.codegen;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.Collections;
-import java.util.Enumeration;
-import java.util.List;
-import java.util.Map;
-
-import javax.tools.JavaFileObject;
-import javax.tools.JavaFileObject.Kind;
-import javax.tools.StandardLocation;
-
-/**
- * MemClassLoader is a mmemory based implementation of the ClassLoader interface
- *
- * @author tiwe
- *
- */
-public final class MemClassLoader extends ClassLoader {
-
- private static final LocationAndKind CLASS_KEY = new LocationAndKind(
- StandardLocation.CLASS_OUTPUT, Kind.CLASS);
-
- private static final LocationAndKind OTHER_KEY = new LocationAndKind(
- StandardLocation.CLASS_OUTPUT, Kind.OTHER);
-
- private static final LocationAndKind SOURCE_KEY = new LocationAndKind(
- StandardLocation.CLASS_OUTPUT, Kind.SOURCE);
-
- private final Map> memFileSystem;
-
- public MemClassLoader(ClassLoader parent,
- Map> ramFileSystem) {
- super(parent);
- this.memFileSystem = ramFileSystem;
- }
-
- @Override
- protected Class> findClass(String name) throws ClassNotFoundException {
- JavaFileObject jfo = memFileSystem.get(CLASS_KEY).get(name);
- if (jfo != null) {
- byte[] bytes = ((MemJavaFileObject) jfo).getByteArray();
- return defineClass(name, bytes, 0, bytes.length);
- } else {
- return super.findClass(name);
- }
- }
-
- @Override
- protected URL findResource(String name) {
- URL retValue = super.findResource(name);
- if (retValue != null) {
- return retValue;
- } else {
- JavaFileObject jfo = getFileObject(name);
- if (jfo != null) {
- try {
- return jfo.toUri().toURL();
- } catch (MalformedURLException ex) {
- return null;
- }
- } else {
- return null;
- }
- }
- }
-
- private JavaFileObject getFileObject(String n) {
- LocationAndKind key;
- String name;
- if (n.endsWith(Kind.CLASS.extension)) {
- name = n.replace('.', '/') + Kind.CLASS.extension;
- key = CLASS_KEY;
- } else if (n.endsWith(Kind.SOURCE.extension)) {
- name = n.replace('.', '/') + Kind.SOURCE.extension;
- key = SOURCE_KEY;
- } else {
- name = n;
- key = OTHER_KEY;
- }
- if (memFileSystem.containsKey(key)) {
- return memFileSystem.get(key).get(name);
- } else {
- return null;
- }
- }
-
- @Override
- public InputStream getResourceAsStream(String name) {
- JavaFileObject jfo = getFileObject(name);
- if (jfo != null) {
- byte[] bytes = ((MemJavaFileObject) jfo).getByteArray();
- return new ByteArrayInputStream(bytes);
- } else {
- return null;
- }
- }
-
- @Override
- public Enumeration getResources(String name) throws IOException {
- List retValue;
- retValue = Collections.list(super.getResources(name));
- JavaFileObject jfo = getFileObject(name);
- if (jfo != null) {
- retValue.add(jfo.toUri().toURL());
- }
- return Collections.enumeration(retValue);
- }
-}
+/*
+ * Copyright 2010, 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.querydsl.codegen.utils;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Map;
+
+import javax.tools.JavaFileObject;
+import javax.tools.JavaFileObject.Kind;
+import javax.tools.StandardLocation;
+
+/**
+ * MemClassLoader is a mmemory based implementation of the ClassLoader interface
+ *
+ * @author tiwe
+ *
+ */
+public final class MemClassLoader extends ClassLoader {
+
+ private static final LocationAndKind CLASS_KEY = new LocationAndKind(
+ StandardLocation.CLASS_OUTPUT, Kind.CLASS);
+
+ private static final LocationAndKind OTHER_KEY = new LocationAndKind(
+ StandardLocation.CLASS_OUTPUT, Kind.OTHER);
+
+ private static final LocationAndKind SOURCE_KEY = new LocationAndKind(
+ StandardLocation.CLASS_OUTPUT, Kind.SOURCE);
+
+ private final Map> memFileSystem;
+
+ public MemClassLoader(ClassLoader parent,
+ Map> ramFileSystem) {
+ super(parent);
+ this.memFileSystem = ramFileSystem;
+ }
+
+ @Override
+ protected Class> findClass(String name) throws ClassNotFoundException {
+ JavaFileObject jfo = memFileSystem.get(CLASS_KEY).get(name);
+ if (jfo != null) {
+ byte[] bytes = ((MemJavaFileObject) jfo).getByteArray();
+ return defineClass(name, bytes, 0, bytes.length);
+ } else {
+ return super.findClass(name);
+ }
+ }
+
+ @Override
+ protected URL findResource(String name) {
+ URL retValue = super.findResource(name);
+ if (retValue != null) {
+ return retValue;
+ } else {
+ JavaFileObject jfo = getFileObject(name);
+ if (jfo != null) {
+ try {
+ return jfo.toUri().toURL();
+ } catch (MalformedURLException ex) {
+ return null;
+ }
+ } else {
+ return null;
+ }
+ }
+ }
+
+ private JavaFileObject getFileObject(String n) {
+ LocationAndKind key;
+ String name;
+ if (n.endsWith(Kind.CLASS.extension)) {
+ name = n.replace('.', '/') + Kind.CLASS.extension;
+ key = CLASS_KEY;
+ } else if (n.endsWith(Kind.SOURCE.extension)) {
+ name = n.replace('.', '/') + Kind.SOURCE.extension;
+ key = SOURCE_KEY;
+ } else {
+ name = n;
+ key = OTHER_KEY;
+ }
+ if (memFileSystem.containsKey(key)) {
+ return memFileSystem.get(key).get(name);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public InputStream getResourceAsStream(String name) {
+ JavaFileObject jfo = getFileObject(name);
+ if (jfo != null) {
+ byte[] bytes = ((MemJavaFileObject) jfo).getByteArray();
+ return new ByteArrayInputStream(bytes);
+ } else {
+ return null;
+ }
+ }
+
+ @Override
+ public Enumeration getResources(String name) throws IOException {
+ List retValue;
+ retValue = Collections.list(super.getResources(name));
+ JavaFileObject jfo = getFileObject(name);
+ if (jfo != null) {
+ retValue.add(jfo.toUri().toURL());
+ }
+ return Collections.enumeration(retValue);
+ }
+}
diff --git a/src/main/java/com/mysema/codegen/MemFileManager.java b/src/main/java/com/querydsl/codegen/utils/MemFileManager.java
similarity index 96%
rename from src/main/java/com/mysema/codegen/MemFileManager.java
rename to src/main/java/com/querydsl/codegen/utils/MemFileManager.java
index a4ca488..7e69dbe 100644
--- a/src/main/java/com/mysema/codegen/MemFileManager.java
+++ b/src/main/java/com/querydsl/codegen/utils/MemFileManager.java
@@ -1,172 +1,172 @@
-/*
- * Copyright 2010, 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.codegen;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-import javax.tools.FileObject;
-import javax.tools.ForwardingJavaFileManager;
-import javax.tools.JavaFileManager;
-import javax.tools.JavaFileObject;
-import javax.tools.StandardJavaFileManager;
-import javax.tools.StandardLocation;
-import javax.tools.JavaFileObject.Kind;
-
-/**
- * MemFileManager is a memory based implementation of the JavaFileManager
- * interface
- *
- * @author tiwe
- *
- */
-public class MemFileManager extends ForwardingJavaFileManager {
-
- private final ClassLoader classLoader;
-
- private final Map> ramFileSystem;
-
- private final String urlPrefix;
-
- public MemFileManager(ClassLoader parent, StandardJavaFileManager sjfm) {
- super(sjfm);
- ramFileSystem = new HashMap>();
- Map classLoaderContent = new HashMap();
- ramFileSystem.put(new LocationAndKind(StandardLocation.CLASS_OUTPUT, Kind.CLASS),
- classLoaderContent);
- classLoader = new MemClassLoader(parent, ramFileSystem);
- urlPrefix = MemFileSystemRegistry.DEFAULT.getUrlPrefix(this);
- }
-
- @Override
- public ClassLoader getClassLoader(JavaFileManager.Location location) {
- return classLoader;
- }
-
- @Override
- public FileObject getFileForInput(JavaFileManager.Location location, String packageName,
- String relativeName) throws IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public FileObject getFileForOutput(JavaFileManager.Location location, String packageName,
- String relativeName, FileObject sibling) throws IOException {
- String name = null;
- if ("".equals(packageName)) {
- name = relativeName;
- } else {
- name = packageName.replace('.', '/') + "/" + relativeName;
- }
- LocationAndKind key = new LocationAndKind(location, Kind.OTHER);
- if (ramFileSystem.containsKey(key)) {
- JavaFileObject jfo = ramFileSystem.get(key).get(name);
- if (jfo != null) {
- return jfo;
- }
- }
- JavaFileObject jfo = new MemJavaFileObject(urlPrefix, name, Kind.OTHER);
- register(key, jfo);
- return jfo;
- }
-
- @Override
- public JavaFileObject getJavaFileForInput(JavaFileManager.Location location, String className,
- JavaFileObject.Kind kind) throws IOException {
- throw new UnsupportedOperationException();
- }
-
- @Override
- public JavaFileObject getJavaFileForOutput(Location location, String name, Kind kind,
- FileObject sibling) throws IOException {
- JavaFileObject javaFileObject = null;
- LocationAndKind key = new LocationAndKind(location, kind);
-
- if (ramFileSystem.containsKey(key)) {
- javaFileObject = ramFileSystem.get(key).get(name);
- if (javaFileObject != null) {
- return javaFileObject;
- }
- }
- if (kind == Kind.SOURCE) {
- javaFileObject = new MemSourceFileObject(name);
- } else {
- javaFileObject = new MemJavaFileObject(urlPrefix, name, kind);
- }
- register(key, javaFileObject);
- return javaFileObject;
- }
-
- @Override
- public String inferBinaryName(Location loc, JavaFileObject javaFileObject) {
- String result;
- if (loc == StandardLocation.CLASS_PATH && javaFileObject instanceof MemJavaFileObject) {
- result = javaFileObject.getName();
- } else {
- result = super.inferBinaryName(loc, javaFileObject);
- }
- return result;
- }
-
- @Override
- public boolean isSameFile(FileObject a, FileObject b) {
- return a.equals(b);
- }
-
- @Override
- public Iterable list(Location location, String pkg, Set kinds,
- boolean recurse) throws IOException {
-
- List result = new ArrayList();
- for (JavaFileObject f : super.list(location, pkg, kinds, recurse)) {
- result.add(f);
- }
- if (location == StandardLocation.CLASS_PATH) {
- location = StandardLocation.CLASS_OUTPUT;
- }
-
- for (Kind kind : kinds) {
- LocationAndKind key = new LocationAndKind(location, kind);
- if (ramFileSystem.containsKey(key)) {
- Map locatedFiles = ramFileSystem.get(key);
- for (Map.Entry entry : locatedFiles.entrySet()) {
- String name = entry.getKey();
- String packageName = "";
- if (name.indexOf('.') > -1) {
- packageName = name.substring(0, name.lastIndexOf('.'));
- }
- if (recurse ? packageName.startsWith(pkg) : packageName.equals(pkg)) {
- JavaFileObject candidate = entry.getValue();
- if (kinds.contains(candidate.getKind())) {
- result.add(candidate);
- }
- }
- }
- }
- }
- return result;
- }
-
- private void register(LocationAndKind key, JavaFileObject javaFileObject) {
- if (!ramFileSystem.containsKey(key)) {
- ramFileSystem.put(key, new HashMap());
- }
- ramFileSystem.get(key).put(javaFileObject.getName(), javaFileObject);
- }
-
-}
+/*
+ * Copyright 2010, 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.querydsl.codegen.utils;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.tools.FileObject;
+import javax.tools.ForwardingJavaFileManager;
+import javax.tools.JavaFileManager;
+import javax.tools.JavaFileObject;
+import javax.tools.StandardJavaFileManager;
+import javax.tools.StandardLocation;
+import javax.tools.JavaFileObject.Kind;
+
+/**
+ * MemFileManager is a memory based implementation of the JavaFileManager
+ * interface
+ *
+ * @author tiwe
+ *
+ */
+public class MemFileManager extends ForwardingJavaFileManager {
+
+ private final ClassLoader classLoader;
+
+ private final Map> ramFileSystem;
+
+ private final String urlPrefix;
+
+ public MemFileManager(ClassLoader parent, StandardJavaFileManager sjfm) {
+ super(sjfm);
+ ramFileSystem = new HashMap>();
+ Map classLoaderContent = new HashMap();
+ ramFileSystem.put(new LocationAndKind(StandardLocation.CLASS_OUTPUT, Kind.CLASS),
+ classLoaderContent);
+ classLoader = new MemClassLoader(parent, ramFileSystem);
+ urlPrefix = MemFileSystemRegistry.DEFAULT.getUrlPrefix(this);
+ }
+
+ @Override
+ public ClassLoader getClassLoader(JavaFileManager.Location location) {
+ return classLoader;
+ }
+
+ @Override
+ public FileObject getFileForInput(JavaFileManager.Location location, String packageName,
+ String relativeName) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public FileObject getFileForOutput(JavaFileManager.Location location, String packageName,
+ String relativeName, FileObject sibling) throws IOException {
+ String name = null;
+ if ("".equals(packageName)) {
+ name = relativeName;
+ } else {
+ name = packageName.replace('.', '/') + "/" + relativeName;
+ }
+ LocationAndKind key = new LocationAndKind(location, Kind.OTHER);
+ if (ramFileSystem.containsKey(key)) {
+ JavaFileObject jfo = ramFileSystem.get(key).get(name);
+ if (jfo != null) {
+ return jfo;
+ }
+ }
+ JavaFileObject jfo = new MemJavaFileObject(urlPrefix, name, Kind.OTHER);
+ register(key, jfo);
+ return jfo;
+ }
+
+ @Override
+ public JavaFileObject getJavaFileForInput(JavaFileManager.Location location, String className,
+ JavaFileObject.Kind kind) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public JavaFileObject getJavaFileForOutput(Location location, String name, Kind kind,
+ FileObject sibling) throws IOException {
+ JavaFileObject javaFileObject = null;
+ LocationAndKind key = new LocationAndKind(location, kind);
+
+ if (ramFileSystem.containsKey(key)) {
+ javaFileObject = ramFileSystem.get(key).get(name);
+ if (javaFileObject != null) {
+ return javaFileObject;
+ }
+ }
+ if (kind == Kind.SOURCE) {
+ javaFileObject = new MemSourceFileObject(name);
+ } else {
+ javaFileObject = new MemJavaFileObject(urlPrefix, name, kind);
+ }
+ register(key, javaFileObject);
+ return javaFileObject;
+ }
+
+ @Override
+ public String inferBinaryName(Location loc, JavaFileObject javaFileObject) {
+ String result;
+ if (loc == StandardLocation.CLASS_PATH && javaFileObject instanceof MemJavaFileObject) {
+ result = javaFileObject.getName();
+ } else {
+ result = super.inferBinaryName(loc, javaFileObject);
+ }
+ return result;
+ }
+
+ @Override
+ public boolean isSameFile(FileObject a, FileObject b) {
+ return a.equals(b);
+ }
+
+ @Override
+ public Iterable list(Location location, String pkg, Set kinds,
+ boolean recurse) throws IOException {
+
+ List result = new ArrayList();
+ for (JavaFileObject f : super.list(location, pkg, kinds, recurse)) {
+ result.add(f);
+ }
+ if (location == StandardLocation.CLASS_PATH) {
+ location = StandardLocation.CLASS_OUTPUT;
+ }
+
+ for (Kind kind : kinds) {
+ LocationAndKind key = new LocationAndKind(location, kind);
+ if (ramFileSystem.containsKey(key)) {
+ Map locatedFiles = ramFileSystem.get(key);
+ for (Map.Entry entry : locatedFiles.entrySet()) {
+ String name = entry.getKey();
+ String packageName = "";
+ if (name.indexOf('.') > -1) {
+ packageName = name.substring(0, name.lastIndexOf('.'));
+ }
+ if (recurse ? packageName.startsWith(pkg) : packageName.equals(pkg)) {
+ JavaFileObject candidate = entry.getValue();
+ if (kinds.contains(candidate.getKind())) {
+ result.add(candidate);
+ }
+ }
+ }
+ }
+ }
+ return result;
+ }
+
+ private void register(LocationAndKind key, JavaFileObject javaFileObject) {
+ if (!ramFileSystem.containsKey(key)) {
+ ramFileSystem.put(key, new HashMap());
+ }
+ ramFileSystem.get(key).put(javaFileObject.getName(), javaFileObject);
+ }
+
+}
diff --git a/src/main/java/com/mysema/codegen/MemFileSystemRegistry.java b/src/main/java/com/querydsl/codegen/utils/MemFileSystemRegistry.java
similarity index 96%
rename from src/main/java/com/mysema/codegen/MemFileSystemRegistry.java
rename to src/main/java/com/querydsl/codegen/utils/MemFileSystemRegistry.java
index 696c27f..85e4f1d 100644
--- a/src/main/java/com/mysema/codegen/MemFileSystemRegistry.java
+++ b/src/main/java/com/querydsl/codegen/utils/MemFileSystemRegistry.java
@@ -1,68 +1,68 @@
-/*
- * Copyright 2010, 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.codegen;
-
-import java.lang.ref.WeakReference;
-import java.net.URL;
-import java.util.Map;
-import java.util.WeakHashMap;
-
-import javax.tools.JavaFileManager;
-
-/**
- * @author tiwe
- *
- */
-public final class MemFileSystemRegistry {
-
- public static final MemFileSystemRegistry DEFAULT = new MemFileSystemRegistry();
-
- private final Map jfm2prefix = new WeakHashMap();
-
- private Map> prefix2jfm = new WeakHashMap>();
-
- private final String protocolName;
-
- private int sequence = 0;
-
- private MemFileSystemRegistry() {
- String pkgName = MemFileSystemRegistry.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);
- }
-
- 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;
- }
- }
-
-}
+/*
+ * Copyright 2010, 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.querydsl.codegen.utils;
+
+import java.lang.ref.WeakReference;
+import java.net.URL;
+import java.util.Map;
+import java.util.WeakHashMap;
+
+import javax.tools.JavaFileManager;
+
+/**
+ * @author tiwe
+ *
+ */
+public final class MemFileSystemRegistry {
+
+ public static final MemFileSystemRegistry DEFAULT = new MemFileSystemRegistry();
+
+ private final Map jfm2prefix = new WeakHashMap();
+
+ private Map> prefix2jfm = new WeakHashMap>();
+
+ private final String protocolName;
+
+ private int sequence = 0;
+
+ private MemFileSystemRegistry() {
+ String pkgName = MemFileSystemRegistry.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);
+ }
+
+ 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/src/main/java/com/mysema/codegen/MemJavaFileObject.java b/src/main/java/com/querydsl/codegen/utils/MemJavaFileObject.java
similarity index 90%
rename from src/main/java/com/mysema/codegen/MemJavaFileObject.java
rename to src/main/java/com/querydsl/codegen/utils/MemJavaFileObject.java
index da58b60..f762e4c 100644
--- a/src/main/java/com/mysema/codegen/MemJavaFileObject.java
+++ b/src/main/java/com/querydsl/codegen/utils/MemJavaFileObject.java
@@ -1,78 +1,77 @@
-/*
- * Copyright 2010, 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.codegen;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.net.URI;
-
-import javax.tools.SimpleJavaFileObject;
-
-import com.google.common.base.Charsets;
-
-/**
- * MemJavaFileObject defines an in memory compiled Java file
- *
- * @author tiwe
- *
- */
-public class MemJavaFileObject extends SimpleJavaFileObject {
-
- private ByteArrayOutputStream baos;
-
- private final String name;
-
- public MemJavaFileObject(String urlPrefix, String name, Kind kind) {
- super(URI.create(urlPrefix + name + kind.extension), kind);
- this.name = name;
- }
-
- @Override
- public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
- if (baos == null) {
- throw new FileNotFoundException(name);
- }
- return new String(baos.toByteArray(), Charsets.UTF_8);
- }
-
- @Override
- public String getName() {
- return name;
- }
-
- public byte[] getByteArray() {
- return baos.toByteArray();
- }
-
- @Override
- public InputStream openInputStream() throws IOException {
- if (baos == null) {
- throw new FileNotFoundException(name);
- }
- return new ByteArrayInputStream(baos.toByteArray());
- }
-
- @Override
- public OutputStream openOutputStream() throws IOException {
- if (baos == null) {
- baos = new ByteArrayOutputStream();
- }
- return baos;
- }
-
-}
+/*
+ * Copyright 2010, 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.querydsl.codegen.utils;
+
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.URI;
+import java.nio.charset.StandardCharsets;
+
+import javax.tools.SimpleJavaFileObject;
+
+/**
+ * MemJavaFileObject defines an in memory compiled Java file
+ *
+ * @author tiwe
+ *
+ */
+public class MemJavaFileObject extends SimpleJavaFileObject {
+
+ private ByteArrayOutputStream baos;
+
+ private final String name;
+
+ public MemJavaFileObject(String urlPrefix, String name, Kind kind) {
+ super(URI.create(urlPrefix + name + kind.extension), kind);
+ this.name = name;
+ }
+
+ @Override
+ public CharSequence getCharContent(boolean ignoreEncodingErrors) throws IOException {
+ if (baos == null) {
+ throw new FileNotFoundException(name);
+ }
+ return new String(baos.toByteArray(), StandardCharsets.UTF_8);
+ }
+
+ @Override
+ public String getName() {
+ return name;
+ }
+
+ public byte[] getByteArray() {
+ return baos.toByteArray();
+ }
+
+ @Override
+ public InputStream openInputStream() throws IOException {
+ if (baos == null) {
+ throw new FileNotFoundException(name);
+ }
+ return new ByteArrayInputStream(baos.toByteArray());
+ }
+
+ @Override
+ public OutputStream openOutputStream() throws IOException {
+ if (baos == null) {
+ baos = new ByteArrayOutputStream();
+ }
+ return baos;
+ }
+
+}
diff --git a/src/main/java/com/mysema/codegen/MemSourceFileObject.java b/src/main/java/com/querydsl/codegen/utils/MemSourceFileObject.java
similarity index 95%
rename from src/main/java/com/mysema/codegen/MemSourceFileObject.java
rename to src/main/java/com/querydsl/codegen/utils/MemSourceFileObject.java
index b712c2b..931b3e3 100644
--- a/src/main/java/com/mysema/codegen/MemSourceFileObject.java
+++ b/src/main/java/com/querydsl/codegen/utils/MemSourceFileObject.java
@@ -1,75 +1,75 @@
-/*
- * Copyright 2010, 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.codegen;
-
-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 MemSourceFileObject extends SimpleJavaFileObject {
-
- private static URI toUri(String fqname) {
- return URI.create("file:///" + fqname.replace(".", "/") + ".java");
- }
-
- private final StringBuilder contents;
-
- public MemSourceFileObject(String fullName) {
- super(toUri(fullName), JavaFileObject.Kind.SOURCE);
- contents = new StringBuilder(1000);
- }
-
- public MemSourceFileObject(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);
- }
- };
- }
-}
+/*
+ * Copyright 2010, 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.querydsl.codegen.utils;
+
+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 MemSourceFileObject extends SimpleJavaFileObject {
+
+ private static URI toUri(String fqname) {
+ return URI.create("file:///" + fqname.replace(".", "/") + ".java");
+ }
+
+ private final StringBuilder contents;
+
+ public MemSourceFileObject(String fullName) {
+ super(toUri(fullName), JavaFileObject.Kind.SOURCE);
+ contents = new StringBuilder(1000);
+ }
+
+ public MemSourceFileObject(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/src/main/java/com/mysema/codegen/MethodEvaluator.java b/src/main/java/com/querydsl/codegen/utils/MethodEvaluator.java
similarity index 98%
rename from src/main/java/com/mysema/codegen/MethodEvaluator.java
rename to src/main/java/com/querydsl/codegen/utils/MethodEvaluator.java
index 5fe1f29..6109b67 100644
--- a/src/main/java/com/mysema/codegen/MethodEvaluator.java
+++ b/src/main/java/com/querydsl/codegen/utils/MethodEvaluator.java
@@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.mysema.codegen;
+package com.querydsl.codegen.utils;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
diff --git a/src/main/java/com/mysema/codegen/MultiSuppressWarnings.java b/src/main/java/com/querydsl/codegen/utils/MultiSuppressWarnings.java
similarity index 97%
rename from src/main/java/com/mysema/codegen/MultiSuppressWarnings.java
rename to src/main/java/com/querydsl/codegen/utils/MultiSuppressWarnings.java
index 046ea31..3f8566f 100644
--- a/src/main/java/com/mysema/codegen/MultiSuppressWarnings.java
+++ b/src/main/java/com/querydsl/codegen/utils/MultiSuppressWarnings.java
@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.mysema.codegen;
+package com.querydsl.codegen.utils;
import java.lang.annotation.Annotation;
import java.util.Arrays;
diff --git a/src/main/java/com/mysema/codegen/ScalaWriter.java b/src/main/java/com/querydsl/codegen/utils/ScalaWriter.java
similarity index 97%
rename from src/main/java/com/mysema/codegen/ScalaWriter.java
rename to src/main/java/com/querydsl/codegen/utils/ScalaWriter.java
index bcf468a..d5ef5a3 100644
--- a/src/main/java/com/mysema/codegen/ScalaWriter.java
+++ b/src/main/java/com/querydsl/codegen/utils/ScalaWriter.java
@@ -11,12 +11,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.mysema.codegen;
+package com.querydsl.codegen.utils;
-import static com.mysema.codegen.Symbols.ASSIGN;
-import static com.mysema.codegen.Symbols.COMMA;
-import static com.mysema.codegen.Symbols.DOT;
-import static com.mysema.codegen.Symbols.QUOTE;
+import static com.querydsl.codegen.utils.Symbols.ASSIGN;
+import static com.querydsl.codegen.utils.Symbols.COMMA;
+import static com.querydsl.codegen.utils.Symbols.DOT;
+import static com.querydsl.codegen.utils.Symbols.QUOTE;
import java.io.IOException;
import java.lang.annotation.Annotation;
@@ -26,12 +26,12 @@
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
+import java.util.function.Function;
-import com.google.common.base.Function;
-import com.mysema.codegen.model.Parameter;
-import com.mysema.codegen.model.Type;
-import com.mysema.codegen.model.Types;
-import com.mysema.codegen.support.ScalaSyntaxUtils;
+import com.querydsl.codegen.utils.model.Parameter;
+import com.querydsl.codegen.utils.model.Type;
+import com.querydsl.codegen.utils.model.Types;
+import com.querydsl.codegen.utils.support.ScalaSyntaxUtils;
/**
* @author tiwe
diff --git a/src/main/java/com/mysema/codegen/SimpleCompiler.java b/src/main/java/com/querydsl/codegen/utils/SimpleCompiler.java
similarity index 93%
rename from src/main/java/com/mysema/codegen/SimpleCompiler.java
rename to src/main/java/com/querydsl/codegen/utils/SimpleCompiler.java
index ae207e4..5d11800 100644
--- a/src/main/java/com/mysema/codegen/SimpleCompiler.java
+++ b/src/main/java/com/querydsl/codegen/utils/SimpleCompiler.java
@@ -1,155 +1,152 @@
-/*
- * Copyright 2010, 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.codegen;
-
-import java.io.*;
-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 java.util.jar.Manifest;
-
-import javax.lang.model.SourceVersion;
-import javax.tools.*;
-
-import com.google.common.base.Joiner;
-
-/**
- * SimpleCompiler provides a convenience wrapper of the JavaCompiler interface
- * with automatic classpath generation
- *
- * @author tiwe
- *
- */
-public class SimpleCompiler implements JavaCompiler {
-
- private static final Joiner pathJoiner = Joiner.on(File.pathSeparator);
-
- protected static boolean isSureFireBooter(URLClassLoader cl) {
- for (URL url : cl.getURLs()) {
- if (url.getPath().contains("surefirebooter")) {
- return true;
- }
- }
-
- return false;
- }
-
- public static String getClassPath(URLClassLoader cl) {
- try {
- List paths = new ArrayList();
- if (isSureFireBooter(cl)) {
- // extract MANIFEST.MF Class-Path entry, since the Java Compiler doesn't handle
- // manifest only jars in the classpath correctly
- URL url = cl.findResource("META-INF/MANIFEST.MF");
- Manifest manifest = new Manifest(url.openStream());
- String classpath = manifest.getMainAttributes().getValue("Class-Path");
- for (String entry : classpath.split(" ")) {
- URL entryUrl = new URL(entry);
- String decodedPath = URLDecoder.decode(entryUrl.getPath(), "UTF-8");
- paths.add(new File(decodedPath).getAbsolutePath());
- }
- } else {
- ClassLoader c = cl;
- while (c instanceof URLClassLoader) {
- for (URL url : ((URLClassLoader)c).getURLs()) {
- String decodedPath = URLDecoder.decode(url.getPath(), "UTF-8");
- paths.add(new File(decodedPath).getAbsolutePath());
- }
- c = c.getParent();
- }
- }
- return pathJoiner.join(paths);
- } catch (UnsupportedEncodingException e) {
- throw new CodegenException(e);
- } catch (IOException e) {
- throw new CodegenException(e);
- }
- }
-
- private final ClassLoader classLoader;
-
- 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 super JavaFileObject> diagnosticListener, Locale locale,
- Charset charset) {
- return compiler.getStandardFileManager(diagnosticListener, locale, charset);
- }
-
- @Override
- public CompilationTask getTask(Writer out, JavaFileManager fileManager,
- DiagnosticListener super JavaFileObject> diagnosticListener,
- Iterable options, Iterable classes,
- Iterable extends JavaFileObject> 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")) {
- 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);
- }
- return compiler.run(in, out, err, args.toArray(new String[args.size()]));
- }
-
-}
+/*
+ * Copyright 2010, 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.querydsl.codegen.utils;
+
+import java.io.*;
+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 java.util.jar.Manifest;
+import java.util.stream.Collectors;
+
+import javax.lang.model.SourceVersion;
+import javax.tools.*;
+
+/**
+ * SimpleCompiler provides a convenience wrapper of the JavaCompiler interface
+ * with automatic classpath generation
+ *
+ * @author tiwe
+ *
+ */
+public class SimpleCompiler implements JavaCompiler {
+
+ protected static boolean isSureFireBooter(URLClassLoader cl) {
+ for (URL url : cl.getURLs()) {
+ if (url.getPath().contains("surefirebooter")) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ public static String getClassPath(URLClassLoader cl) {
+ try {
+ List paths = new ArrayList();
+ if (isSureFireBooter(cl)) {
+ // extract MANIFEST.MF Class-Path entry, since the Java Compiler doesn't handle
+ // manifest only jars in the classpath correctly
+ URL url = cl.findResource("META-INF/MANIFEST.MF");
+ Manifest manifest = new Manifest(url.openStream());
+ String classpath = manifest.getMainAttributes().getValue("Class-Path");
+ for (String entry : classpath.split(" ")) {
+ URL entryUrl = new URL(entry);
+ String decodedPath = URLDecoder.decode(entryUrl.getPath(), "UTF-8");
+ paths.add(new File(decodedPath).getAbsolutePath());
+ }
+ } else {
+ ClassLoader c = cl;
+ while (c instanceof URLClassLoader) {
+ for (URL url : ((URLClassLoader)c).getURLs()) {
+ String decodedPath = URLDecoder.decode(url.getPath(), "UTF-8");
+ paths.add(new File(decodedPath).getAbsolutePath());
+ }
+ c = c.getParent();
+ }
+ }
+ return paths.stream().collect(Collectors.joining(File.pathSeparator));
+ } catch (UnsupportedEncodingException e) {
+ throw new CodegenException(e);
+ } catch (IOException e) {
+ throw new CodegenException(e);
+ }
+ }
+
+ private final ClassLoader classLoader;
+
+ 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 super JavaFileObject> diagnosticListener, Locale locale,
+ Charset charset) {
+ return compiler.getStandardFileManager(diagnosticListener, locale, charset);
+ }
+
+ @Override
+ public CompilationTask getTask(Writer out, JavaFileManager fileManager,
+ DiagnosticListener super JavaFileObject> diagnosticListener,
+ Iterable options, Iterable classes,
+ Iterable extends JavaFileObject> 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")) {
+ 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);
+ }
+ return compiler.run(in, out, err, args.toArray(new String[args.size()]));
+ }
+
+}
diff --git a/src/main/java/com/mysema/codegen/StringUtils.java b/src/main/java/com/querydsl/codegen/utils/StringUtils.java
similarity index 74%
rename from src/main/java/com/mysema/codegen/StringUtils.java
rename to src/main/java/com/querydsl/codegen/utils/StringUtils.java
index 9756089..ec07634 100644
--- a/src/main/java/com/mysema/codegen/StringUtils.java
+++ b/src/main/java/com/querydsl/codegen/utils/StringUtils.java
@@ -11,18 +11,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.mysema.codegen;
+package com.querydsl.codegen.utils;
-import com.google.common.base.CaseFormat;
+import java.util.Arrays;
public final class StringUtils {
public static String capitalize(String str) {
- return CaseFormat.LOWER_CAMEL.to(CaseFormat.UPPER_CAMEL, str);
+ return str.substring(0, 1).toUpperCase() + str.substring(1);
}
public static String uncapitalize(String str) {
- return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_CAMEL, str);
+ return str.substring(0, 1).toLowerCase() + str.substring(1);
}
public static String escapeJava(String str) {
@@ -33,6 +33,12 @@ public static String escapeJava(String str) {
str = str.replace("\n", "\\\n");
return str;
}
+
+ public static String repeat(char value, int times) {
+ char[] chars = new char[times];
+ Arrays.fill(chars, value);
+ return new String(chars);
+ }
private StringUtils() {}
diff --git a/src/main/java/com/mysema/codegen/Symbols.java b/src/main/java/com/querydsl/codegen/utils/Symbols.java
similarity index 94%
rename from src/main/java/com/mysema/codegen/Symbols.java
rename to src/main/java/com/querydsl/codegen/utils/Symbols.java
index 79135ae..61b08bc 100644
--- a/src/main/java/com/mysema/codegen/Symbols.java
+++ b/src/main/java/com/querydsl/codegen/utils/Symbols.java
@@ -1,58 +1,58 @@
-/*
- * Copyright 2010, 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.codegen;
-
-/**
- * Defines general String constants
- *
- * @author tiwe
- *
- */
-public final class Symbols {
-
- public static final String ASSIGN = " = ";
-
- public static final String COMMA = ", ";
-
- public static final String DOT = ".";
-
- public static final String DOT_CLASS = ".class";
-
- public static final String EMPTY = "";
-
- public static final String NEW = "new ";
-
- public static final String NEWLINE = "\n";
-
- public static final String QUOTE = "\"";
-
- public static final String RETURN = "return ";
-
- public static final String SEMICOLON = ";";
-
- public static final String SERIAL = "serial";
-
- public static final String SPACE = " ";
-
- public static final String STAR = "*";
-
- public static final String SUPER = "super";
-
- public static final String THIS = "this";
-
- public static final String UNCHECKED = "unchecked";
-
- private Symbols() {
- }
-}
+/*
+ * Copyright 2010, 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.querydsl.codegen.utils;
+
+/**
+ * Defines general String constants
+ *
+ * @author tiwe
+ *
+ */
+public final class Symbols {
+
+ public static final String ASSIGN = " = ";
+
+ public static final String COMMA = ", ";
+
+ public static final String DOT = ".";
+
+ public static final String DOT_CLASS = ".class";
+
+ public static final String EMPTY = "";
+
+ public static final String NEW = "new ";
+
+ public static final String NEWLINE = "\n";
+
+ public static final String QUOTE = "\"";
+
+ public static final String RETURN = "return ";
+
+ public static final String SEMICOLON = ";";
+
+ public static final String SERIAL = "serial";
+
+ public static final String SPACE = " ";
+
+ public static final String STAR = "*";
+
+ public static final String SUPER = "super";
+
+ public static final String THIS = "this";
+
+ public static final String UNCHECKED = "unchecked";
+
+ private Symbols() {
+ }
+}
diff --git a/src/main/java/com/mysema/codegen/model/ClassType.java b/src/main/java/com/querydsl/codegen/utils/model/ClassType.java
similarity index 98%
rename from src/main/java/com/mysema/codegen/model/ClassType.java
rename to src/main/java/com/querydsl/codegen/utils/model/ClassType.java
index 3d0c08d..d582cee 100644
--- a/src/main/java/com/mysema/codegen/model/ClassType.java
+++ b/src/main/java/com/querydsl/codegen/utils/model/ClassType.java
@@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.mysema.codegen.model;
+package com.querydsl.codegen.utils.model;
import java.lang.reflect.Modifier;
import java.util.Arrays;
@@ -19,7 +19,7 @@
import java.util.List;
import java.util.Set;
-import com.mysema.codegen.support.ClassUtils;
+import com.querydsl.codegen.utils.support.ClassUtils;
/**
* @author tiwe
diff --git a/src/main/java/com/mysema/codegen/model/Constructor.java b/src/main/java/com/querydsl/codegen/utils/model/Constructor.java
similarity index 96%
rename from src/main/java/com/mysema/codegen/model/Constructor.java
rename to src/main/java/com/querydsl/codegen/utils/model/Constructor.java
index 5c6e7c1..6afc52b 100644
--- a/src/main/java/com/mysema/codegen/model/Constructor.java
+++ b/src/main/java/com/querydsl/codegen/utils/model/Constructor.java
@@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.mysema.codegen.model;
+package com.querydsl.codegen.utils.model;
import java.util.Collection;
diff --git a/src/main/java/com/mysema/codegen/model/Parameter.java b/src/main/java/com/querydsl/codegen/utils/model/Parameter.java
similarity index 97%
rename from src/main/java/com/mysema/codegen/model/Parameter.java
rename to src/main/java/com/querydsl/codegen/utils/model/Parameter.java
index cf73779..241ed73 100644
--- a/src/main/java/com/mysema/codegen/model/Parameter.java
+++ b/src/main/java/com/querydsl/codegen/utils/model/Parameter.java
@@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.mysema.codegen.model;
+package com.querydsl.codegen.utils.model;
/**
* Parameter represents a parameter in a Constructor
diff --git a/src/main/java/com/mysema/codegen/model/SimpleType.java b/src/main/java/com/querydsl/codegen/utils/model/SimpleType.java
similarity index 99%
rename from src/main/java/com/mysema/codegen/model/SimpleType.java
rename to src/main/java/com/querydsl/codegen/utils/model/SimpleType.java
index a482ceb..b69af1b 100644
--- a/src/main/java/com/mysema/codegen/model/SimpleType.java
+++ b/src/main/java/com/querydsl/codegen/utils/model/SimpleType.java
@@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.mysema.codegen.model;
+package com.querydsl.codegen.utils.model;
import java.lang.reflect.Array;
import java.util.Arrays;
diff --git a/src/main/java/com/mysema/codegen/model/Type.java b/src/main/java/com/querydsl/codegen/utils/model/Type.java
similarity index 96%
rename from src/main/java/com/mysema/codegen/model/Type.java
rename to src/main/java/com/querydsl/codegen/utils/model/Type.java
index 2ae8613..568d6b3 100644
--- a/src/main/java/com/mysema/codegen/model/Type.java
+++ b/src/main/java/com/querydsl/codegen/utils/model/Type.java
@@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.mysema.codegen.model;
+package com.querydsl.codegen.utils.model;
import java.util.List;
import java.util.Set;
diff --git a/src/main/java/com/mysema/codegen/model/TypeAdapter.java b/src/main/java/com/querydsl/codegen/utils/model/TypeAdapter.java
similarity index 98%
rename from src/main/java/com/mysema/codegen/model/TypeAdapter.java
rename to src/main/java/com/querydsl/codegen/utils/model/TypeAdapter.java
index ee348b8..158359b 100644
--- a/src/main/java/com/mysema/codegen/model/TypeAdapter.java
+++ b/src/main/java/com/querydsl/codegen/utils/model/TypeAdapter.java
@@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.mysema.codegen.model;
+package com.querydsl.codegen.utils.model;
import java.util.List;
import java.util.Set;
diff --git a/src/main/java/com/mysema/codegen/model/TypeCategory.java b/src/main/java/com/querydsl/codegen/utils/model/TypeCategory.java
similarity index 98%
rename from src/main/java/com/mysema/codegen/model/TypeCategory.java
rename to src/main/java/com/querydsl/codegen/utils/model/TypeCategory.java
index 4443256..80e31cf 100644
--- a/src/main/java/com/mysema/codegen/model/TypeCategory.java
+++ b/src/main/java/com/querydsl/codegen/utils/model/TypeCategory.java
@@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.mysema.codegen.model;
+package com.querydsl.codegen.utils.model;
import java.util.HashSet;
import java.util.Set;
diff --git a/src/main/java/com/mysema/codegen/model/TypeExtends.java b/src/main/java/com/querydsl/codegen/utils/model/TypeExtends.java
similarity index 87%
rename from src/main/java/com/mysema/codegen/model/TypeExtends.java
rename to src/main/java/com/querydsl/codegen/utils/model/TypeExtends.java
index 5e83a0a..c0bd393 100644
--- a/src/main/java/com/mysema/codegen/model/TypeExtends.java
+++ b/src/main/java/com/querydsl/codegen/utils/model/TypeExtends.java
@@ -11,14 +11,12 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.mysema.codegen.model;
+package com.querydsl.codegen.utils.model;
import java.util.Collections;
+import java.util.Objects;
import java.util.Set;
-import com.google.common.base.Objects;
-import com.google.common.base.Strings;
-
/**
* @author tiwe
*
@@ -50,7 +48,7 @@ public String getGenericName(boolean asArgType, Set packages, Set JAVA_LANG = Collections.singleton("java.lang");
-
- public static String getName(Class> cl) {
- return getName(cl, JAVA_LANG, Collections. emptySet());
- }
-
- public static String getFullName(Class> cl) {
- if (cl.isArray()) {
- return getFullName(cl.getComponentType()) + "[]";
- }
- final String name = cl.getName();
- if (name.indexOf('$') > 0) {
- return getFullName(cl.getDeclaringClass()) + "." + cl.getSimpleName();
- }
- return name;
- }
-
- public static String getPackageName(Class> cl) {
- while (cl.isArray()) {
- cl = cl.getComponentType();
- }
- final String name = cl.getName();
- final int i = name.lastIndexOf('.');
- if (i > 0) {
- return name.substring(0, i);
- } else {
- return "";
- }
- }
-
- public static String getName(Class> cl, Set packages, Set classes) {
- if (cl.isArray()) {
- return getName(cl.getComponentType(), packages, classes) + "[]";
- }
- final String canonicalName = cl.getName().replace('$', '.');
- final int i = cl.getName().lastIndexOf('.');
- if (classes.contains(canonicalName)) {
- return cl.getSimpleName();
- } else if (cl.getEnclosingClass() != null) {
- return getName(cl.getEnclosingClass(), packages, classes) + "." + cl.getSimpleName();
- } else if (i == -1) {
- return canonicalName;
- } else if (packages.contains(canonicalName.substring(0, i))) {
- return canonicalName.substring(i + 1);
- } else {
- return canonicalName;
- }
- }
-
- public static Class> normalize(Class> clazz) {
- if (List.class.isAssignableFrom(clazz)) {
- return List.class;
- } else if (Set.class.isAssignableFrom(clazz)) {
- return Set.class;
- } else if (Collection.class.isAssignableFrom(clazz)) {
- return Collection.class;
- } else if (Map.class.isAssignableFrom(clazz)) {
- return Map.class;
- // check for CGLIB generated classes
- } else if (clazz.getName().contains("$$")) {
- Class> zuper = clazz.getSuperclass();
- if (zuper != null && !Object.class.equals(zuper)) {
- return zuper;
- }
- } else if (!Modifier.isPublic(clazz.getModifiers())) {
- return normalize(clazz.getSuperclass());
- }
- return clazz;
- }
-
- private ClassUtils() {
- }
-
-}
+/*
+ * Copyright 2010, 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.querydsl.codegen.utils.support;
+
+import java.lang.reflect.Modifier;
+import java.util.*;
+
+/**
+ * @author tiwe
+ *
+ */
+public final class ClassUtils {
+
+ private static final Set JAVA_LANG = Collections.singleton("java.lang");
+
+ public static String getName(Class> cl) {
+ return getName(cl, JAVA_LANG, Collections. emptySet());
+ }
+
+ public static String getFullName(Class> cl) {
+ if (cl.isArray()) {
+ return getFullName(cl.getComponentType()) + "[]";
+ }
+ final String name = cl.getName();
+ if (name.indexOf('$') > 0) {
+ return getFullName(cl.getDeclaringClass()) + "." + cl.getSimpleName();
+ }
+ return name;
+ }
+
+ public static String getPackageName(Class> cl) {
+ while (cl.isArray()) {
+ cl = cl.getComponentType();
+ }
+ final String name = cl.getName();
+ final int i = name.lastIndexOf('.');
+ if (i > 0) {
+ return name.substring(0, i);
+ } else {
+ return "";
+ }
+ }
+
+ public static String getName(Class> cl, Set packages, Set classes) {
+ if (cl.isArray()) {
+ return getName(cl.getComponentType(), packages, classes) + "[]";
+ }
+ final String canonicalName = cl.getName().replace('$', '.');
+ final int i = cl.getName().lastIndexOf('.');
+ if (classes.contains(canonicalName)) {
+ return cl.getSimpleName();
+ } else if (cl.getEnclosingClass() != null) {
+ return getName(cl.getEnclosingClass(), packages, classes) + "." + cl.getSimpleName();
+ } else if (i == -1) {
+ return canonicalName;
+ } else if (packages.contains(canonicalName.substring(0, i))) {
+ return canonicalName.substring(i + 1);
+ } else {
+ return canonicalName;
+ }
+ }
+
+ public static Class> normalize(Class> clazz) {
+ if (List.class.isAssignableFrom(clazz)) {
+ return List.class;
+ } else if (Set.class.isAssignableFrom(clazz)) {
+ return Set.class;
+ } else if (Collection.class.isAssignableFrom(clazz)) {
+ return Collection.class;
+ } else if (Map.class.isAssignableFrom(clazz)) {
+ return Map.class;
+ // check for CGLIB generated classes
+ } else if (clazz.getName().contains("$$")) {
+ Class> zuper = clazz.getSuperclass();
+ if (zuper != null && !Object.class.equals(zuper)) {
+ return zuper;
+ }
+ } else if (!Modifier.isPublic(clazz.getModifiers())) {
+ return normalize(clazz.getSuperclass());
+ }
+ return clazz;
+ }
+
+ private ClassUtils() {
+ }
+
+}
diff --git a/src/main/java/com/mysema/codegen/support/ScalaSyntaxUtils.java b/src/main/java/com/querydsl/codegen/utils/support/ScalaSyntaxUtils.java
similarity index 96%
rename from src/main/java/com/mysema/codegen/support/ScalaSyntaxUtils.java
rename to src/main/java/com/querydsl/codegen/utils/support/ScalaSyntaxUtils.java
index 2c287f8..54aece8 100644
--- a/src/main/java/com/mysema/codegen/support/ScalaSyntaxUtils.java
+++ b/src/main/java/com/querydsl/codegen/utils/support/ScalaSyntaxUtils.java
@@ -11,7 +11,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package com.mysema.codegen.support;
+package com.querydsl.codegen.utils.support;
import java.util.Arrays;
import java.util.HashSet;
diff --git a/src/main/java/com/mysema/codegen/support/package-info.java b/src/main/java/com/querydsl/codegen/utils/support/package-info.java
similarity index 61%
rename from src/main/java/com/mysema/codegen/support/package-info.java
rename to src/main/java/com/querydsl/codegen/utils/support/package-info.java
index fbd9125..3b18ad6 100644
--- a/src/main/java/com/mysema/codegen/support/package-info.java
+++ b/src/main/java/com/querydsl/codegen/utils/support/package-info.java
@@ -4,5 +4,5 @@
*
*/
-package com.mysema.codegen.support;
+package com.querydsl.codegen.utils.support;
diff --git a/src/test/java/NestedTest.java b/src/test/java/NestedTest.java
index 9a240e2..75b7c36 100644
--- a/src/test/java/NestedTest.java
+++ b/src/test/java/NestedTest.java
@@ -2,8 +2,8 @@
import org.junit.Test;
-import com.mysema.codegen.model.ClassType;
-import com.mysema.codegen.support.ClassUtils;
+import com.querydsl.codegen.utils.model.ClassType;
+import com.querydsl.codegen.utils.support.ClassUtils;
public class NestedTest {
diff --git a/src/test/java/com/mysema/codegen/Annotation.java b/src/test/java/com/querydsl/codegen/utils/Annotation.java
similarity index 91%
rename from src/test/java/com/mysema/codegen/Annotation.java
rename to src/test/java/com/querydsl/codegen/utils/Annotation.java
index 3a98acb..7218a81 100644
--- a/src/test/java/com/mysema/codegen/Annotation.java
+++ b/src/test/java/com/querydsl/codegen/utils/Annotation.java
@@ -3,7 +3,7 @@
* All rights reserved.
*
*/
-package com.mysema.codegen;
+package com.querydsl.codegen.utils;
import static java.lang.annotation.ElementType.TYPE;
diff --git a/src/test/java/com/mysema/codegen/Annotation2.java b/src/test/java/com/querydsl/codegen/utils/Annotation2.java
similarity index 89%
rename from src/test/java/com/mysema/codegen/Annotation2.java
rename to src/test/java/com/querydsl/codegen/utils/Annotation2.java
index 3317363..49bb20c 100644
--- a/src/test/java/com/mysema/codegen/Annotation2.java
+++ b/src/test/java/com/querydsl/codegen/utils/Annotation2.java
@@ -1,7 +1,7 @@
/**
*
*/
-package com.mysema.codegen;
+package com.querydsl.codegen.utils;
import static java.lang.annotation.ElementType.TYPE;
diff --git a/src/test/java/com/mysema/codegen/Annotation2Impl.java b/src/test/java/com/querydsl/codegen/utils/Annotation2Impl.java
similarity index 92%
rename from src/test/java/com/mysema/codegen/Annotation2Impl.java
rename to src/test/java/com/querydsl/codegen/utils/Annotation2Impl.java
index f61fd01..52b9ac0 100644
--- a/src/test/java/com/mysema/codegen/Annotation2Impl.java
+++ b/src/test/java/com/querydsl/codegen/utils/Annotation2Impl.java
@@ -1,4 +1,4 @@
-package com.mysema.codegen;
+package com.querydsl.codegen.utils;
import java.lang.annotation.Annotation;
diff --git a/src/test/java/com/mysema/codegen/Annotation3.java b/src/test/java/com/querydsl/codegen/utils/Annotation3.java
similarity index 91%
rename from src/test/java/com/mysema/codegen/Annotation3.java
rename to src/test/java/com/querydsl/codegen/utils/Annotation3.java
index 9a7b83c..4981b1c 100644
--- a/src/test/java/com/mysema/codegen/Annotation3.java
+++ b/src/test/java/com/querydsl/codegen/utils/Annotation3.java
@@ -3,7 +3,7 @@
* All rights reserved.
*
*/
-package com.mysema.codegen;
+package com.querydsl.codegen.utils;
import static java.lang.annotation.ElementType.TYPE;
diff --git a/src/test/java/com/mysema/codegen/AnnotationTest.java b/src/test/java/com/querydsl/codegen/utils/AnnotationTest.java
similarity index 77%
rename from src/test/java/com/mysema/codegen/AnnotationTest.java
rename to src/test/java/com/querydsl/codegen/utils/AnnotationTest.java
index 96a763a..8d29b0e 100644
--- a/src/test/java/com/mysema/codegen/AnnotationTest.java
+++ b/src/test/java/com/querydsl/codegen/utils/AnnotationTest.java
@@ -3,7 +3,7 @@
* All rights reserved.
*
*/
-package com.mysema.codegen;
+package com.querydsl.codegen.utils;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
@@ -25,8 +25,8 @@ public class AnnotationTest {
@Test
public void ClassAnnotation() throws IOException {
writer.annotation(getClass().getAnnotation(Annotation.class));
- String option1 = "@com.mysema.codegen.Annotation(clazz=com.mysema.codegen.AnnotationTest.class, prop2=false)";
- String option2 = "@com.mysema.codegen.Annotation(prop2=false, clazz=com.mysema.codegen.AnnotationTest.class)";
+ String option1 = "@com.querydsl.codegen.utils.Annotation(clazz=com.querydsl.codegen.utils.AnnotationTest.class, prop2=false)";
+ String option2 = "@com.querydsl.codegen.utils.Annotation(prop2=false, clazz=com.querydsl.codegen.utils.AnnotationTest.class)";
String serialized = w.toString().trim();
assertTrue(serialized.equals(option1) || serialized.equals(option2));
}
@@ -34,14 +34,14 @@ public void ClassAnnotation() throws IOException {
@Test
public void ClassAnnotation2() throws IOException {
writer.annotation(getClass().getAnnotation(Annotation2.class));
- assertEquals("@com.mysema.codegen.Annotation2(\"Hello\")", w.toString().trim());
+ assertEquals("@com.querydsl.codegen.utils.Annotation2(\"Hello\")", w.toString().trim());
}
@Test
public void ClassAnnotation3() throws IOException {
writer.annotation(getClass().getAnnotation(Annotation3.class));
assertEquals(
- "@com.mysema.codegen.Annotation3(type=java.lang.annotation.ElementType.ANNOTATION_TYPE)",
+ "@com.querydsl.codegen.utils.Annotation3(type=java.lang.annotation.ElementType.ANNOTATION_TYPE)",
w.toString().trim());
}
@@ -72,7 +72,7 @@ public void NotNull() throws IOException {
@Test
public void Uri_Value() throws IOException {
writer.annotation(new Annotation2Impl("http://www.example.com#"));
- assertEquals("@com.mysema.codegen.Annotation2(\"http://www.example.com#\")", w.toString()
+ assertEquals("@com.querydsl.codegen.utils.Annotation2(\"http://www.example.com#\")", w.toString()
.trim());
}
diff --git a/src/test/java/com/mysema/codegen/ComplexEvaluationTest.java b/src/test/java/com/querydsl/codegen/utils/ComplexEvaluationTest.java
similarity index 90%
rename from src/test/java/com/mysema/codegen/ComplexEvaluationTest.java
rename to src/test/java/com/querydsl/codegen/utils/ComplexEvaluationTest.java
index 537f920..fedf570 100644
--- a/src/test/java/com/mysema/codegen/ComplexEvaluationTest.java
+++ b/src/test/java/com/querydsl/codegen/utils/ComplexEvaluationTest.java
@@ -3,7 +3,7 @@
* All rights reserved.
*
*/
-package com.mysema.codegen;
+package com.querydsl.codegen.utils;
import static org.junit.Assert.*;
@@ -11,13 +11,13 @@
import java.util.Collections;
import java.util.List;
+import com.querydsl.codegen.utils.model.ClassType;
+import com.querydsl.codegen.utils.model.Type;
+import com.querydsl.codegen.utils.model.TypeCategory;
+import com.querydsl.codegen.utils.model.Types;
import org.junit.Test;
-import com.mysema.codegen.model.ClassType;
-import com.mysema.codegen.model.Type;
-import com.mysema.codegen.model.TypeCategory;
-import com.mysema.codegen.model.Types;
-import com.mysema.codegen.support.Cat;
+import com.querydsl.codegen.utils.support.Cat;
public class ComplexEvaluationTest {
@@ -55,8 +55,8 @@ public void ComplexClassLoading() {
ClassType resultType = new ClassType(TypeCategory.LIST, List.class, Types.OBJECTS);
StringBuilder source = new StringBuilder();
source.append("java.util.List