├── .gitignore ├── LICENSE ├── README.md ├── license_header.txt ├── nb-configuration.xml ├── nbactions.xml ├── pom.xml └── src ├── main └── java │ └── com │ └── speedment │ └── common │ └── codegen │ ├── DependencyManager.java │ ├── Generator.java │ ├── Meta.java │ ├── RenderStack.java │ ├── RenderTree.java │ ├── Transform.java │ ├── TransformFactory.java │ ├── constant │ ├── DefaultAnnotationUsage.java │ ├── DefaultJavadocTag.java │ ├── DefaultType.java │ ├── DefaultValue.java │ ├── SimpleParameterizedType.java │ ├── SimpleType.java │ └── SimpleTypeUtil.java │ ├── controller │ ├── AlignTabs.java │ ├── AutoEquals.java │ ├── AutoImports.java │ ├── AutoJavadoc.java │ ├── FinalParameters.java │ ├── SetGetAdd.java │ └── package-info.java │ ├── internal │ ├── BridgeTransform.java │ ├── DefaultDependencyManager.java │ ├── DefaultGenerator.java │ ├── DefaultRenderStack.java │ ├── DefaultRenderTree.java │ ├── DefaultTransformFactory.java │ ├── MetaImpl.java │ ├── java │ │ ├── JavaGenerator.java │ │ ├── JavaTransformFactory.java │ │ └── view │ │ │ ├── AnnotationUsageView.java │ │ │ ├── AnnotationView.java │ │ │ ├── ClassOrInterfaceView.java │ │ │ ├── ClassView.java │ │ │ ├── ConstructorView.java │ │ │ ├── EnumConstantView.java │ │ │ ├── EnumView.java │ │ │ ├── FieldView.java │ │ │ ├── FileView.java │ │ │ ├── GenericView.java │ │ │ ├── ImportView.java │ │ │ ├── InitalizerView.java │ │ │ ├── InterfaceFieldView.java │ │ │ ├── InterfaceMethodView.java │ │ │ ├── InterfaceView.java │ │ │ ├── JavadocTagView.java │ │ │ ├── JavadocView.java │ │ │ ├── MethodView.java │ │ │ ├── ModifierView.java │ │ │ ├── TypeView.java │ │ │ ├── trait │ │ │ ├── HasAnnotationUsageView.java │ │ │ ├── HasClassesView.java │ │ │ ├── HasCodeView.java │ │ │ ├── HasCommentView.java │ │ │ ├── HasFieldsView.java │ │ │ ├── HasGenericsView.java │ │ │ ├── HasImplementsView.java │ │ │ ├── HasImportsView.java │ │ │ ├── HasInitalizersView.java │ │ │ ├── HasInitializersView.java │ │ │ ├── HasJavadocTagsView.java │ │ │ ├── HasJavadocView.java │ │ │ ├── HasMethodsView.java │ │ │ ├── HasModifiersView.java │ │ │ ├── HasNameView.java │ │ │ ├── HasThrowsView.java │ │ │ ├── HasTypeView.java │ │ │ └── HasValueView.java │ │ │ └── value │ │ │ ├── ArrayValueView.java │ │ │ ├── BooleanValueView.java │ │ │ ├── EnumValueView.java │ │ │ ├── NullValueView.java │ │ │ ├── NumberValueView.java │ │ │ ├── ReferenceValueView.java │ │ │ └── TextValueView.java │ ├── model │ │ ├── AnnotationImpl.java │ │ ├── AnnotationUsageImpl.java │ │ ├── ClassImpl.java │ │ ├── ClassOrInterfaceImpl.java │ │ ├── ConstructorImpl.java │ │ ├── EnumConstantImpl.java │ │ ├── EnumImpl.java │ │ ├── FieldImpl.java │ │ ├── FileImpl.java │ │ ├── GenericImpl.java │ │ ├── ImportImpl.java │ │ ├── InitializerImpl.java │ │ ├── InterfaceFieldImpl.java │ │ ├── InterfaceImpl.java │ │ ├── InterfaceMethodImpl.java │ │ ├── JavadocImpl.java │ │ ├── JavadocTagImpl.java │ │ ├── MethodImpl.java │ │ ├── ValueImpl.java │ │ └── value │ │ │ ├── ArrayValueImpl.java │ │ │ ├── BooleanValueImpl.java │ │ │ ├── EnumValueImpl.java │ │ │ ├── NullValueImpl.java │ │ │ ├── NumberValueImpl.java │ │ │ ├── ReferenceValueImpl.java │ │ │ └── TextValueImpl.java │ └── util │ │ ├── CollectorUtil.java │ │ ├── Copier.java │ │ ├── NullUtil.java │ │ ├── StaticClassUtil.java │ │ └── TextUtil.java │ ├── model │ ├── Annotation.java │ ├── AnnotationUsage.java │ ├── Class.java │ ├── ClassOrInterface.java │ ├── Constructor.java │ ├── Enum.java │ ├── EnumConstant.java │ ├── Field.java │ ├── File.java │ ├── Generic.java │ ├── Import.java │ ├── Initializer.java │ ├── Interface.java │ ├── InterfaceField.java │ ├── InterfaceMethod.java │ ├── Javadoc.java │ ├── JavadocTag.java │ ├── Method.java │ ├── Value.java │ ├── modifier │ │ ├── AnnotationModifier.java │ │ ├── ClassModifier.java │ │ ├── ConstructorModifier.java │ │ ├── EnumModifier.java │ │ ├── FieldModifier.java │ │ ├── ImportModifier.java │ │ ├── InitalizerModifier.java │ │ ├── InterfaceFieldModifier.java │ │ ├── InterfaceMethodModifier.java │ │ ├── InterfaceModifier.java │ │ ├── Keyword.java │ │ ├── MethodModifier.java │ │ ├── Modifier.java │ │ └── package-info.java │ ├── package-info.java │ ├── trait │ │ ├── HasAnnotationUsage.java │ │ ├── HasCall.java │ │ ├── HasClasses.java │ │ ├── HasCode.java │ │ ├── HasComment.java │ │ ├── HasConstructors.java │ │ ├── HasCopy.java │ │ ├── HasFields.java │ │ ├── HasGenerics.java │ │ ├── HasImplements.java │ │ ├── HasImports.java │ │ ├── HasInitializers.java │ │ ├── HasJavadoc.java │ │ ├── HasJavadocTags.java │ │ ├── HasMethods.java │ │ ├── HasModifiers.java │ │ ├── HasName.java │ │ ├── HasSupertype.java │ │ ├── HasThrows.java │ │ ├── HasType.java │ │ ├── HasValue.java │ │ └── package-info.java │ └── value │ │ ├── ArrayValue.java │ │ ├── BooleanValue.java │ │ ├── EnumValue.java │ │ ├── NullValue.java │ │ ├── NumberValue.java │ │ ├── ReferenceValue.java │ │ └── TextValue.java │ ├── package-info.java │ └── util │ ├── Formatting.java │ └── package-info.java └── test └── java └── com ├── example └── PersonFactory.java └── speedment ├── common └── codegen │ ├── internal │ ├── DefaultRenderStackTest.java │ ├── TestGenericInterfaces.java │ └── java │ │ └── view │ │ ├── TypeViewTest.java │ │ └── trait │ │ └── HasImportsViewTest.java │ └── model │ └── AnnotationUsageTest.java └── example ├── Person.java └── PersonImpl.java /.gitignore: -------------------------------------------------------------------------------- 1 | .sonar 2 | sonar-project.properties 3 | /target/ 4 | /.idea/ 5 | nb-configuration.xml 6 | **.iml -------------------------------------------------------------------------------- /license_header.txt: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) 2006-${currentYear}, Speedment, Inc. All Rights Reserved. 3 | 4 | Licensed under the Apache License, Version 2.0 (the "License"); You may not 5 | use this file except in compliance with the License. You may obtain a copy of 6 | the License at: 7 | 8 | http://www.apache.org/licenses/LICENSE-2.0 9 | 10 | Unless required by applicable law or agreed to in writing, software 11 | distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 12 | WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 13 | License for the specific language governing permissions and limitations under 14 | the License. 15 | 16 | 17 | -------------------------------------------------------------------------------- /nbactions.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | CUSTOM-Deploy Snapshot 5 | Deploy Snapshot 6 | 7 | clean 8 | deploy 9 | 10 | 11 | 12 | CUSTOM-Deploy Release 13 | Deploy Release 14 | 15 | clean 16 | deploy 17 | -P 18 | release 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/RenderStack.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen; 18 | 19 | import java.util.stream.Stream; 20 | 21 | /** 22 | * Represents the stack of models currently processed by the generator. For an 23 | * example, if a Field is currently being transformed into a String, 24 | * the stack might look like this: 25 | *
26 |  *     File → Class → Method → Field
27 |  * 
28 | * 29 | * @author Emil Forslund 30 | * @see Generator 31 | * @since 2.0 32 | */ 33 | public interface RenderStack { 34 | 35 | /** 36 | * Returns a Stream of all models in the stack of a particular 37 | * type from bottom and up. 38 | * 39 | * @param the type of the models to return 40 | * @param type the type of the models to return 41 | * @return a stream of all models of that type 42 | */ 43 | Stream fromBottom(Class type); 44 | 45 | /** 46 | * Returns a Stream of all models in the stack of a particular 47 | * type from top to bottom. 48 | * 49 | * @param the type of the models to return 50 | * @param type the type of the models to return 51 | * @return a stream of all models of that type 52 | */ 53 | Stream fromTop(Class type); 54 | 55 | /** 56 | * Returns true if there are no models in the stack. 57 | * 58 | * @return true if the stack is empty 59 | */ 60 | boolean isEmpty(); 61 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/RenderTree.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen; 18 | 19 | import com.speedment.common.codegen.internal.DefaultRenderTree; 20 | import java.util.List; 21 | 22 | /** 23 | * 24 | * @author Emil Forslund 25 | */ 26 | public interface RenderTree { 27 | 28 | List> branches(); 29 | 30 | static Builder builder() { 31 | return new DefaultRenderTree.Builder(); 32 | } 33 | 34 | interface Builder { 35 | Builder withBranch(Meta meta); 36 | RenderTree build(); 37 | } 38 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/Transform.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen; 18 | 19 | import java.util.Optional; 20 | 21 | /** 22 | * Transforms must have a public constructor with no parameters so that it can 23 | * be instantiated dynamically. 24 | * 25 | * @author Emil Forslund 26 | * @param the model to generate from 27 | * @param the resulting model 28 | * @since 2.0 29 | */ 30 | public interface Transform { 31 | 32 | /** 33 | * Transforms a model from one type to another. A reference to the current 34 | * code generator is supplied so that intermediate generation processes can 35 | * be initiated to resolve dependencies. The transform can choose not to 36 | * accept a particular input and therefore return empty. 37 | *

38 | * This method is not meant to be called outside the code generator. If you 39 | * want to transform between different types, setup a {@link Generator}, 40 | * install the Transform in the factory and call one of the 41 | * on()-methods in Generator. 42 | * 43 | * @param gen a reference to the generator being used 44 | * @param model the model to transform 45 | * @return the transformed model or empty if the transformation could 46 | * not be done for that input 47 | */ 48 | Optional transform(Generator gen, F model); 49 | 50 | /** 51 | * Returns true if this transform is or contains the specified 52 | * transformer. This is used internally by the code generator to avoid 53 | * circular paths. 54 | * 55 | * @param transformer the type of the transformer to check 56 | * @return true if this transform is or contains the input 57 | */ 58 | default boolean is(Class> transformer) { 59 | return transformer.isAssignableFrom(getClass()); 60 | } 61 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/constant/DefaultValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.constant; 18 | 19 | import com.speedment.common.codegen.model.Value; 20 | 21 | import static java.util.Objects.requireNonNull; 22 | 23 | /** 24 | * Contains common default values used when generating java code. 25 | * 26 | * @author Emil Forslund 27 | */ 28 | public final class DefaultValue { 29 | 30 | /** 31 | * The class should never be instantiated. 32 | */ 33 | private DefaultValue() {} 34 | 35 | public final static Value 36 | NULL = Value.ofNull(), 37 | EMPTY_STRING = string(""); 38 | 39 | /** 40 | * Creates a 'string' value with the specified content. 41 | * 42 | * @param text the inner text 43 | * @return a value representing that string 44 | */ 45 | public static Value string(String text) { 46 | return Value.ofText(requireNonNull(text)); 47 | } 48 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/constant/SimpleType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.constant; 18 | 19 | import com.speedment.common.codegen.model.ClassOrInterface; 20 | import com.speedment.common.codegen.model.File; 21 | 22 | import java.lang.reflect.Type; 23 | import java.util.Objects; 24 | 25 | import static java.util.Objects.requireNonNull; 26 | 27 | /** 28 | * A very simple implementation of the java {@link Type} interface. 29 | * 30 | * @author Emil Forslund 31 | * @since 2.4.1 32 | */ 33 | public final class SimpleType implements Type { 34 | 35 | /** 36 | * Creates a new {@code SimpleType} with the specified absolute class name. 37 | * 38 | * @param typeName the absolute type name 39 | * @return the created simple type 40 | */ 41 | public static SimpleType create(String typeName) { 42 | return new SimpleType(typeName); 43 | } 44 | 45 | /** 46 | * Creates a new {@code SimpleType} referencing the specified class in the 47 | * specified file. These do not have to exist yet. 48 | * 49 | * @param file the file to reference 50 | * @param clazz the class to reference 51 | * @return the new simple type 52 | */ 53 | public static SimpleType create(File file, ClassOrInterface clazz) { 54 | return create(SimpleTypeUtil.nameOf(file, clazz)); 55 | } 56 | 57 | @Override 58 | public String getTypeName() { 59 | return typeName; 60 | } 61 | 62 | @Override 63 | public int hashCode() { 64 | return Objects.hashCode(this.typeName); 65 | } 66 | 67 | @Override 68 | public boolean equals(Object obj) { 69 | if (this == obj) { return true; } 70 | else if (obj == null) { return false; } 71 | else if (!(obj instanceof Type)) { return false; } 72 | 73 | final Type other = (Type) obj; 74 | return Objects.equals(typeName, other.getTypeName()); 75 | } 76 | 77 | @Override 78 | public String toString() { 79 | return getTypeName(); 80 | } 81 | 82 | private SimpleType(String typeName) { 83 | this.typeName = requireNonNull(typeName); 84 | } 85 | 86 | private final String typeName; 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/controller/FinalParameters.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.controller; 18 | 19 | import com.speedment.common.codegen.model.trait.HasMethods; 20 | 21 | import java.util.function.Consumer; 22 | 23 | import static java.util.Objects.requireNonNull; 24 | 25 | /** 26 | * This control makes sure all method parameters in the specified model is set 27 | * to final. 28 | * 29 | * @author Emil Forslund 30 | * @param The extending type 31 | */ 32 | public final class FinalParameters> implements Consumer { 33 | 34 | /** 35 | * Sets all method parameters in the specified model to final. 36 | * 37 | * @param model the model to operate on 38 | */ 39 | @Override 40 | public void accept(T model) { 41 | requireNonNull(model).getMethods() 42 | .forEach(m -> m.getFields() 43 | .forEach(f -> f.final_()) 44 | ); 45 | } 46 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/controller/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | /** 18 | * Controllers that automate certain tasks on the model hierarchy is located 19 | * here. These components are useful to keep the model initialization short 20 | * and consise. 21 | *

22 | * This package is part of the API. Modifications to classes here should only 23 | * (if ever) be done in major releases. 24 | */ 25 | package com.speedment.common.codegen.controller; -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/DefaultRenderTree.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal; 18 | 19 | import com.speedment.common.codegen.Meta; 20 | import com.speedment.common.codegen.RenderTree; 21 | import java.util.LinkedList; 22 | import java.util.List; 23 | import static java.util.Objects.requireNonNull; 24 | 25 | /** 26 | * 27 | * @author Emil Forslund 28 | */ 29 | public final class DefaultRenderTree implements RenderTree { 30 | 31 | private final List> branches; 32 | 33 | private DefaultRenderTree(List> branches) { 34 | this.branches = requireNonNull(branches); 35 | } 36 | 37 | @Override 38 | public List> branches() { 39 | return branches; 40 | } 41 | 42 | public static final class Builder implements RenderTree.Builder { 43 | 44 | private final List> branches; 45 | 46 | public Builder() { 47 | branches = new LinkedList<>(); 48 | } 49 | 50 | @Override 51 | public Builder withBranch(Meta meta) { 52 | branches.add(requireNonNull(meta)); 53 | return this; 54 | } 55 | 56 | @Override 57 | public RenderTree build() { 58 | return new DefaultRenderTree(branches); 59 | } 60 | } 61 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/JavaGenerator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java; 18 | 19 | import com.speedment.common.codegen.TransformFactory; 20 | import com.speedment.common.codegen.internal.DefaultDependencyManager; 21 | import com.speedment.common.codegen.internal.DefaultGenerator; 22 | 23 | import java.util.Set; 24 | import java.util.regex.Pattern; 25 | import java.util.stream.Collectors; 26 | import java.util.stream.Stream; 27 | 28 | /** 29 | * A hook to the generator that can be passed to various stages in the pipeline. 30 | * Contains multiple methods for generating model-to-model or model-to-text. 31 | *

32 | * The JavaGenerator comes with all the basic types 33 | * of the java language and the 'java.lang'-package ignored in imports and 34 | * has views of all the basic language concepts preinstalled. 35 | * 36 | * @author Emil Forslund 37 | */ 38 | public class JavaGenerator extends DefaultGenerator { 39 | 40 | private final static Pattern[] IGNORED = compileAll( 41 | "^void$", 42 | "^byte$", 43 | "^short$", 44 | "^char$", 45 | "^int$", 46 | "^long$", 47 | "^boolean$", 48 | "^float$", 49 | "^double$", 50 | "^java\\.lang\\." 51 | ); 52 | 53 | /** 54 | * Instantiates the JavaGenerator. 55 | */ 56 | public JavaGenerator() { 57 | this(new JavaTransformFactory()); 58 | } 59 | 60 | /** 61 | * Instantiates the JavaGenerator using an array of custom 62 | * {@link TransformFactory}. 63 | *

64 | * Warning! If you use this constructor, no transforms will be installed 65 | * by default! 66 | * 67 | * @param factory the transform factory to use 68 | */ 69 | public JavaGenerator(TransformFactory factory) { 70 | super(new DefaultDependencyManager(IGNORED), factory); 71 | } 72 | 73 | private static Pattern[] compileAll(String... regexp) { 74 | final Set patterns = Stream.of(regexp) 75 | .map(Pattern::compile) 76 | .collect(Collectors.toSet()); 77 | 78 | return patterns.toArray(new Pattern[patterns.size()]); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/AnnotationUsageView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.model.AnnotationUsage; 22 | 23 | import java.util.Optional; 24 | import java.util.stream.Stream; 25 | 26 | import static com.speedment.common.codegen.internal.util.CollectorUtil.joinIfNotEmpty; 27 | import static java.util.Objects.requireNonNull; 28 | 29 | /** 30 | * Transforms from an {@link AnnotationUsage} to java code. 31 | * 32 | * @author Emil Forslund 33 | */ 34 | public final class AnnotationUsageView implements Transform { 35 | 36 | @Override 37 | public Optional transform(Generator gen, AnnotationUsage model) { 38 | requireNonNull(gen); 39 | requireNonNull(model); 40 | 41 | final Optional value = gen.on(model.getValue()); 42 | final Stream valueStream = value.isPresent() 43 | ? Stream.of(value.get()) 44 | : Stream.empty(); 45 | 46 | return Optional.of( 47 | "@" + gen.on(model.getType()).get() 48 | + Stream.of( 49 | model.getValues().stream() 50 | .map(e -> e.getKey() + 51 | gen.on(e.getValue()) 52 | .map(s -> " = " + s) 53 | .orElse("") 54 | ), 55 | valueStream 56 | ).flatMap(s -> s).collect( 57 | joinIfNotEmpty(", ", "(", ")") 58 | ) 59 | ); 60 | } 61 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/AnnotationView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.internal.java.view.trait.HasAnnotationUsageView; 22 | import com.speedment.common.codegen.internal.java.view.trait.HasJavadocView; 23 | import com.speedment.common.codegen.internal.java.view.trait.HasNameView; 24 | import com.speedment.common.codegen.model.Annotation; 25 | 26 | import java.util.Optional; 27 | 28 | import static com.speedment.common.codegen.internal.util.NullUtil.requireNonNulls; 29 | import static com.speedment.common.codegen.util.Formatting.*; 30 | import static java.util.stream.Collectors.joining; 31 | 32 | /** 33 | * Transforms from an {@link Annotation} to java code. 34 | * 35 | * @author Emil Forslund 36 | */ 37 | public final class AnnotationView implements Transform, 38 | HasJavadocView, 39 | HasAnnotationUsageView, 40 | HasNameView { 41 | 42 | @Override 43 | public Optional transform(Generator gen, Annotation model) { 44 | requireNonNulls(gen, model); 45 | 46 | return Optional.of( 47 | renderAnnotations(gen, model) 48 | + renderAnnotations(gen, model) 49 | + "@interface " 50 | + renderName(gen, model) 51 | + block( 52 | model.getFields().stream().map(f 53 | -> // Field javadoc (optional) 54 | renderJavadoc(gen, model) 55 | + // Field declaration 56 | gen.on(f.getType()) + " " + f.getName() + "()" 57 | + // Default value (optional) 58 | ifelse(gen.on(f.getValue()), v -> " default " + v, "") 59 | + ";" 60 | ).collect(joining(dnl())) 61 | ) 62 | ); 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/ClassView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.model.Class; 21 | 22 | import static com.speedment.common.codegen.util.Formatting.dnl; 23 | import static java.util.Objects.requireNonNull; 24 | import static java.util.stream.Collectors.joining; 25 | 26 | /** 27 | * Transforms from a {@link Class} to java code. 28 | * 29 | * @author Emil Forslund 30 | */ 31 | public final class ClassView extends ClassOrInterfaceView { 32 | 33 | @Override 34 | protected String renderDeclarationType() { 35 | return CLASS_STRING; 36 | } 37 | 38 | @Override 39 | public String extendsOrImplementsInterfaces() { 40 | return IMPLEMENTS_STRING; 41 | } 42 | 43 | @Override 44 | protected String renderSupertype(Generator gen, Class model) { 45 | requireNonNull(gen); 46 | requireNonNull(model); 47 | 48 | if (model.getSupertype().isPresent()) { 49 | return EXTENDS_STRING + gen.on(model.getSupertype().get()).orElse("") + " "; 50 | } else { 51 | return ""; 52 | } 53 | } 54 | 55 | @Override 56 | protected String renderConstructors(Generator gen, Class model) { 57 | requireNonNull(gen); 58 | requireNonNull(model); 59 | 60 | return gen.onEach(model.getConstructors()) 61 | .collect(joining(dnl())); 62 | } 63 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/EnumView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import static com.speedment.common.codegen.internal.util.CollectorUtil.joinIfNotEmpty; 21 | import static com.speedment.common.codegen.internal.util.NullUtil.requireNonNulls; 22 | import com.speedment.common.codegen.model.Enum; 23 | import com.speedment.common.codegen.util.Formatting; 24 | import static com.speedment.common.codegen.util.Formatting.dnl; 25 | import static com.speedment.common.codegen.util.Formatting.nl; 26 | import java.util.List; 27 | import static java.util.stream.Collectors.joining; 28 | import static java.util.stream.Collectors.toList; 29 | 30 | /** 31 | * Transforms from an {@link Enum} to java code. 32 | * 33 | * @author Emil Forslund 34 | */ 35 | public final class EnumView extends ClassOrInterfaceView { 36 | 37 | @Override 38 | protected String renderDeclarationType() { 39 | return ENUM_STRING; 40 | } 41 | 42 | @Override 43 | public String extendsOrImplementsInterfaces() { 44 | return IMPLEMENTS_STRING; 45 | } 46 | 47 | @Override 48 | protected String renderSupertype(Generator gen, Enum model) { 49 | return ""; 50 | } 51 | 52 | @Override 53 | protected String onBeforeFields(Generator gen, Enum model) { 54 | requireNonNulls(gen, model); 55 | 56 | final List constants = model.getConstants().stream() 57 | .map(c -> gen.on(c).get()).collect(toList()); 58 | 59 | Formatting.alignTabs(constants); 60 | 61 | return constants.stream().collect( 62 | joinIfNotEmpty( 63 | (!model.getConstants().isEmpty() 64 | && !model.getConstants().get(0).getValues().isEmpty()) 65 | ? "," + nl() : ", ", 66 | "", 67 | ";" 68 | ) 69 | ); 70 | } 71 | 72 | @Override 73 | protected String renderConstructors(Generator gen, Enum model) { 74 | requireNonNulls(gen, model); 75 | 76 | return gen.onEach(model.getConstructors()) 77 | .collect(joining(dnl())); 78 | } 79 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/FieldView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.internal.java.view.trait.*; 22 | import com.speedment.common.codegen.model.Field; 23 | 24 | import java.util.Optional; 25 | 26 | import static com.speedment.common.codegen.internal.util.NullUtil.requireNonNulls; 27 | 28 | /** 29 | * Transforms from a {@link Field} to java code. 30 | * 31 | * @author Emil Forslund 32 | */ 33 | public final class FieldView implements Transform, HasNameView, 34 | HasJavadocView, HasModifiersView, HasTypeView, 35 | HasValueView, HasAnnotationUsageView { 36 | 37 | @Override 38 | public Optional transform(Generator gen, Field model) { 39 | requireNonNulls(gen, model); 40 | 41 | return Optional.of( 42 | renderJavadoc(gen, model) + 43 | renderModifiers(gen, model) + 44 | renderAnnotations(gen, model) + 45 | renderType(gen, model) + 46 | renderName(gen, model) + 47 | renderValue(gen, model) 48 | ); 49 | } 50 | 51 | @Override 52 | public String annotationSeparator() { 53 | return " "; 54 | } 55 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/GenericView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.model.Generic; 22 | 23 | import java.util.Optional; 24 | 25 | import static com.speedment.common.codegen.internal.util.CollectorUtil.joinIfNotEmpty; 26 | import static com.speedment.common.codegen.internal.util.NullUtil.requireNonNulls; 27 | 28 | /** 29 | * Transforms from a {@link Generic} to java code. 30 | * 31 | * @author Emil Forslund 32 | */ 33 | public final class GenericView implements Transform { 34 | 35 | @Override 36 | public Optional transform(Generator gen, Generic model) { 37 | requireNonNulls(gen, model); 38 | 39 | if (!model.getLowerBound().isPresent() 40 | && model.getUpperBounds().isEmpty()) { 41 | return Optional.empty(); 42 | } else { 43 | return Optional.of( 44 | model.getLowerBound().orElse("") + 45 | gen.onEach(model.getUpperBounds()).collect(joinIfNotEmpty("&", 46 | model.getLowerBound().isPresent() ? 47 | model.getBoundType() == Generic.BoundType.EXTENDS ? 48 | " extends " : " super " 49 | : "", 50 | "" 51 | ) 52 | ) 53 | ); 54 | } 55 | } 56 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/InitalizerView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.internal.java.view.trait.HasCodeView; 22 | import com.speedment.common.codegen.internal.java.view.trait.HasModifiersView; 23 | import com.speedment.common.codegen.model.Initializer; 24 | 25 | import java.util.Optional; 26 | 27 | import static java.util.Objects.requireNonNull; 28 | 29 | /** 30 | * Transforms from an {@link Initializer} to java code. 31 | * 32 | * @author Emil Forslund 33 | */ 34 | public final class InitalizerView implements Transform, 35 | HasModifiersView, 36 | HasCodeView { 37 | 38 | @Override 39 | public Optional transform(Generator gen, Initializer model) { 40 | requireNonNull(gen); 41 | requireNonNull(model); 42 | 43 | return Optional.of( 44 | renderModifiers(gen, model) + 45 | renderCode(gen, model) 46 | ); 47 | } 48 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/InterfaceFieldView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.internal.java.view.trait.*; 22 | import com.speedment.common.codegen.model.InterfaceField; 23 | 24 | import java.util.Optional; 25 | 26 | import static com.speedment.common.codegen.internal.util.NullUtil.requireNonNulls; 27 | import static com.speedment.common.codegen.model.modifier.Modifier.FINAL; 28 | 29 | /** 30 | * Transforms from an {@link InterfaceField} to java code. 31 | * 32 | * @author Emil Forslund 33 | */ 34 | public final class InterfaceFieldView implements Transform, 35 | HasJavadocView, 36 | HasModifiersView, 37 | HasAnnotationUsageView, 38 | HasTypeView, 39 | HasNameView { 40 | 41 | @Override 42 | public Optional transform(Generator gen, InterfaceField model) { 43 | requireNonNulls(gen, model); 44 | 45 | return Optional.of( 46 | renderJavadoc(gen, model) + 47 | renderModifiers(gen, model, FINAL) + 48 | renderAnnotations(gen, model) + 49 | renderType(gen, model) + 50 | renderName(gen, model) 51 | ); 52 | } 53 | 54 | @Override 55 | public String annotationSeparator() { 56 | return " "; 57 | } 58 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/InterfaceView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.internal.model.InterfaceMethodImpl; 21 | import com.speedment.common.codegen.model.Interface; 22 | import com.speedment.common.codegen.model.InterfaceMethod; 23 | import com.speedment.common.codegen.model.Method; 24 | 25 | /** 26 | * Transforms from an {@link Interface} to java code. 27 | * 28 | * @author Emil Forslund 29 | */ 30 | public final class InterfaceView extends ClassOrInterfaceView { 31 | 32 | @Override 33 | protected String renderDeclarationType() { 34 | return INTERFACE_STRING; 35 | } 36 | 37 | @Override 38 | public String extendsOrImplementsInterfaces() { 39 | return EXTENDS_STRING; 40 | } 41 | 42 | @Override 43 | protected String renderSupertype(Generator gen, Interface model) { 44 | return ""; 45 | } 46 | 47 | @Override 48 | public InterfaceMethod wrapMethod(Method method) { 49 | return new InterfaceMethodImpl(method); 50 | } 51 | 52 | @Override 53 | protected String renderConstructors(Generator gen, Interface model) { 54 | return ""; 55 | } 56 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/JavadocTagView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.model.JavadocTag; 22 | 23 | import java.util.Optional; 24 | 25 | import static com.speedment.common.codegen.util.Formatting.ifelse; 26 | import static java.util.Objects.requireNonNull; 27 | 28 | /** 29 | * Transforms from a {@link JavadocTag} to java code. 30 | * 31 | * @author Emil Forslund 32 | */ 33 | public final class JavadocTagView implements Transform { 34 | 35 | @Override 36 | public Optional transform(Generator gen, JavadocTag model) { 37 | requireNonNull(gen); 38 | requireNonNull(model); 39 | 40 | return Optional.of( 41 | "@" + model.getName() + 42 | ifelse(model.getValue(), s -> " " + s, "") + " " + 43 | model.getText().orElse("") 44 | ); 45 | } 46 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/MethodView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.internal.java.view.trait.*; 22 | import static com.speedment.common.codegen.internal.util.NullUtil.requireNonNulls; 23 | import com.speedment.common.codegen.model.Method; 24 | import static com.speedment.common.codegen.model.modifier.Modifier.ABSTRACT; 25 | import static com.speedment.common.codegen.util.Formatting.nl; 26 | import static com.speedment.common.codegen.util.Formatting.tab; 27 | import java.util.Optional; 28 | 29 | /** 30 | * Transforms from a {@link Method} to java code. 31 | * 32 | * @author Emil Forslund 33 | */ 34 | public final class MethodView implements Transform, 35 | HasNameView, 36 | HasTypeView, 37 | HasThrowsView, 38 | HasGenericsView, 39 | HasFieldsView, 40 | HasJavadocView, 41 | HasAnnotationUsageView, 42 | HasCodeView, 43 | HasModifiersView { 44 | 45 | @Override 46 | public Optional transform(Generator gen, Method model) { 47 | requireNonNulls(gen, model); 48 | 49 | return Optional.of( 50 | renderJavadoc(gen, model) + 51 | renderAnnotations(gen, model) + 52 | renderModifiers(gen, model) + 53 | renderGenerics(gen, model) + 54 | renderType(gen, model) + 55 | renderName(gen, model) + 56 | ((model.getFields().size() > 3) ? "(" + nl() + tab() + tab() : "(") + 57 | renderFields(gen, model) + ") " + 58 | renderThrows(gen, model) + 59 | renderCode(gen, model) 60 | ); 61 | } 62 | 63 | @Override 64 | public String fieldSeparator(Method model) { 65 | if (model.getFields().size() > 3) { 66 | return "," + nl() + tab() + tab(); 67 | } else return ", "; 68 | } 69 | 70 | @Override 71 | public String throwsSuffix(Method model) { 72 | return model.getModifiers().contains(ABSTRACT) ? "" : " "; 73 | } 74 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/ModifierView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.model.modifier.Modifier; 22 | 23 | import java.util.Optional; 24 | 25 | /** 26 | * Transforms from a {@link Modifier} to java code. 27 | * 28 | * @author Emil Forslund 29 | */ 30 | public final class ModifierView implements Transform { 31 | 32 | @Override 33 | public Optional transform(Generator gen, Modifier model) { 34 | return Optional.of(model.getName()); 35 | } 36 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/trait/HasAnnotationUsageView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view.trait; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.model.trait.HasAnnotationUsage; 22 | 23 | import static com.speedment.common.codegen.internal.util.CollectorUtil.joinIfNotEmpty; 24 | import static com.speedment.common.codegen.util.Formatting.nl; 25 | 26 | /** 27 | * A trait with the functionality to render models with the trait 28 | * {@link HasAnnotationUsage}. 29 | * 30 | * @author Emil Forslund 31 | * @param The model type 32 | * @see Transform 33 | */ 34 | public interface HasAnnotationUsageView> extends 35 | Transform { 36 | 37 | /** 38 | * The string separating different annotations. 39 | * 40 | * @return the annotation separator 41 | */ 42 | default String annotationSeparator() { 43 | return nl(); 44 | } 45 | 46 | /** 47 | * Renders all annotations in the specified model separated by new-line 48 | * characters. 49 | * 50 | * @param gen the generator 51 | * @param model the model with the annotations 52 | * @return the generated code 53 | */ 54 | default String renderAnnotations(Generator gen, M model) { 55 | return gen.onEach(model.getAnnotations()) 56 | .collect(joinIfNotEmpty( 57 | annotationSeparator(), 58 | "", 59 | annotationSeparator() 60 | )); 61 | } 62 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/trait/HasClassesView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view.trait; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.model.trait.HasClasses; 22 | 23 | import static com.speedment.common.codegen.util.Formatting.dnl; 24 | import static java.util.stream.Collectors.joining; 25 | 26 | /** 27 | * A trait with the functionality to render models with the trait 28 | * {@link HasClasses}. 29 | * 30 | * @author Emil Forslund 31 | * @param The model type 32 | * @see Transform 33 | */ 34 | public interface HasClassesView> extends Transform { 35 | 36 | /** 37 | * Render the classes-part of the model separated by two new-line characters. 38 | * 39 | * @param gen the generator 40 | * @param model the model 41 | * @return the generated code 42 | */ 43 | default String renderClasses(Generator gen, M model) { 44 | return gen.onEach(model.getClasses()) 45 | .collect(joining(dnl())); 46 | } 47 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/trait/HasCodeView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view.trait; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.model.trait.HasCode; 22 | 23 | import static com.speedment.common.codegen.util.Formatting.block; 24 | import static com.speedment.common.codegen.util.Formatting.nl; 25 | import static java.util.stream.Collectors.joining; 26 | 27 | /** 28 | * A trait with the functionality to render models with the trait 29 | * {@link HasCode}. 30 | * 31 | * @author Emil Forslund 32 | * @param The model type 33 | * @see Transform 34 | */ 35 | public interface HasCodeView> extends Transform { 36 | 37 | /** 38 | * Render the code-part of the model separated by new-line characters. 39 | * 40 | * @param gen the generator 41 | * @param model the model 42 | * @return the generated code 43 | */ 44 | default String renderCode(Generator gen, M model) { 45 | return block(model.getCode().stream() 46 | .collect(joining(nl())) 47 | ); 48 | } 49 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/trait/HasCommentView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view.trait; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.model.trait.HasComment; 22 | 23 | import java.util.stream.Stream; 24 | 25 | import static com.speedment.common.codegen.util.Formatting.nl; 26 | import static java.util.stream.Collectors.joining; 27 | 28 | /** 29 | * A trait with the functionality to render models with the trait 30 | * {@link HasComment}. 31 | * 32 | * @author Emil Forslund 33 | * @param The model type 34 | * @see Transform 35 | */ 36 | public interface HasCommentView> extends Transform { 37 | 38 | /** 39 | * Render the comment-part of the model, prepending each row with '//'. 40 | * 41 | * @param gen the generator 42 | * @param model the model 43 | * @return the generated code 44 | */ 45 | default String renderComment(Generator gen, M model) { 46 | return model.getComment().map(comment -> 47 | Stream.of(comment.split(nl())) 48 | .map(row -> "// " + row) 49 | .collect(joining(nl())) 50 | ).orElse(""); 51 | } 52 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/trait/HasFieldsView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view.trait; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import static com.speedment.common.codegen.internal.util.CollectorUtil.joinIfNotEmpty; 22 | import com.speedment.common.codegen.model.trait.HasFields; 23 | 24 | /** 25 | * A trait with the functionality to render models with the trait 26 | * {@link HasFields}. 27 | * 28 | * @author Emil Forslund 29 | * @param The model type 30 | * @see Transform 31 | */ 32 | public interface HasFieldsView> extends Transform { 33 | 34 | /** 35 | * Render the fields-part of the model using the 36 | * {@link #fieldSeparator(HasFields)} method to separate the fields and 37 | * the {@link #fieldPrefix()}- and {@link #fieldSuffix()}-methods on each 38 | * field. 39 | * 40 | * @param gen the generator 41 | * @param model the model 42 | * @return the generated code 43 | */ 44 | default String renderFields(Generator gen, M model) { 45 | return gen.onEach(model.getFields()) 46 | .collect(joinIfNotEmpty( 47 | fieldSuffix() + fieldSeparator(model) + fieldPrefix(), 48 | fieldPrefix(), 49 | fieldSuffix() 50 | )); 51 | } 52 | 53 | /** 54 | * The separator string used when joining fields. 55 | * 56 | * @param model the model that is being rendered 57 | * @return the field separator 58 | */ 59 | String fieldSeparator(M model); 60 | 61 | /** 62 | * A text to be inserted before each field. 63 | * 64 | * @return the field prefix 65 | */ 66 | default String fieldPrefix() { 67 | return ""; 68 | } 69 | 70 | /** 71 | * A text to be inserted after each field. 72 | * 73 | * @return the field suffix 74 | */ 75 | default String fieldSuffix() { 76 | return ""; 77 | } 78 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/trait/HasGenericsView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view.trait; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.model.trait.HasGenerics; 22 | 23 | import static com.speedment.common.codegen.internal.util.CollectorUtil.joinIfNotEmpty; 24 | 25 | /** 26 | * A trait with the functionality to render models with the trait 27 | * {@link HasGenerics}. 28 | * 29 | * @author Emil Forslund 30 | * @param The model type 31 | * @see Transform 32 | */ 33 | public interface HasGenericsView> extends 34 | Transform { 35 | 36 | /** 37 | * A trailing suffix that is to be appended to the generics if it is rendered. 38 | *

39 | * The default value is a single space (" "). 40 | * 41 | * @return the suffix 42 | */ 43 | default String genericsSuffix() { 44 | return " "; 45 | } 46 | 47 | /** 48 | * Render the generics-part of the model followed by a space character. 49 | * 50 | * @param gen the generator 51 | * @param model the model 52 | * @return the generated code 53 | */ 54 | default String renderGenerics(Generator gen, M model) { 55 | return gen.onEach(model.getGenerics()) 56 | .collect(joinIfNotEmpty(", ", "<", ">" + genericsSuffix())); 57 | } 58 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/trait/HasImplementsView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view.trait; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.model.trait.HasImplements; 22 | 23 | import static com.speedment.common.codegen.internal.util.CollectorUtil.joinIfNotEmpty; 24 | 25 | /** 26 | * A trait with the functionality to render models with the trait 27 | * {@link HasImplements}. 28 | * 29 | * @author Emil Forslund 30 | * @param The model type 31 | * @see Transform 32 | */ 33 | public interface HasImplementsView> extends 34 | Transform { 35 | 36 | /** 37 | * Returns the correct term to use when describing the supertype of this 38 | * component. In java, "extends" is used when an interface 39 | * has another interface as a supertype and "implements" when a 40 | * class and an enum uses it. 41 | * 42 | * @return "extends" or "implements". 43 | */ 44 | String extendsOrImplementsInterfaces(); 45 | 46 | /** 47 | * Render the supertype-part of the model. The 48 | * {@link #extendsOrImplementsInterfaces()}-method should be implemented to 49 | * answer which wording to use; 'implements' or 'extends'. 50 | * 51 | * @param gen the generator 52 | * @param model the model 53 | * @return the generated code 54 | */ 55 | default String renderInterfaces(Generator gen, M model) { 56 | return gen.onEach(model.getInterfaces()).collect( 57 | joinIfNotEmpty( 58 | ", ", 59 | extendsOrImplementsInterfaces(), 60 | " " 61 | ) 62 | ); 63 | } 64 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/trait/HasImportsView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view.trait; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.model.trait.HasImports; 22 | 23 | import static com.speedment.common.codegen.internal.util.CollectorUtil.joinIfNotEmpty; 24 | import static com.speedment.common.codegen.util.Formatting.dnl; 25 | import static com.speedment.common.codegen.util.Formatting.nl; 26 | 27 | /** 28 | * A trait with the functionality to render models with the trait 29 | * {@link HasImports}. 30 | * 31 | * @author Emil Forslund 32 | * @param The model type 33 | * @see Transform 34 | */ 35 | public interface HasImportsView> extends 36 | Transform { 37 | 38 | /** 39 | * Render the imports-part of the model separated by new-line characters and 40 | * appended by two new-line characters. 41 | * 42 | * @param gen the generator 43 | * @param model the model 44 | * @return the generated code 45 | */ 46 | default String renderImports(Generator gen, M model) { 47 | return gen.onEach(model.getImports()) 48 | .distinct().sorted() 49 | .collect(joinIfNotEmpty(nl(), "", dnl())); 50 | } 51 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/trait/HasInitalizersView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view.trait; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | 22 | import java.util.stream.Collectors; 23 | 24 | import static com.speedment.common.codegen.util.Formatting.dnl; 25 | import com.speedment.common.codegen.model.trait.HasInitializers; 26 | 27 | /** 28 | * A trait with the functionality to render models with the trait 29 | * {@link HasInitializers}. 30 | * 31 | * @author Emil Forslund 32 | * @param The model type 33 | * @see Transform 34 | */ 35 | public interface HasInitalizersView> extends 36 | Transform { 37 | 38 | /** 39 | * Render the initalizers-part of the model separated by two new-line 40 | * characters. 41 | * 42 | * @param gen the generator 43 | * @param model the model 44 | * @return the generated code 45 | */ 46 | default String renderInitalizers(Generator gen, M model) { 47 | return gen.onEach(model.getInitializers()) 48 | .collect(Collectors.joining(dnl())); 49 | } 50 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/trait/HasInitializersView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view.trait; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | 22 | import java.util.stream.Collectors; 23 | 24 | import static com.speedment.common.codegen.util.Formatting.dnl; 25 | import com.speedment.common.codegen.model.trait.HasInitializers; 26 | 27 | /** 28 | * A trait with the functionality to render models with the trait 29 | * {@link HasInitializers}. 30 | * 31 | * @author Emil Forslund 32 | * @param The model type 33 | * @see Transform 34 | */ 35 | public interface HasInitializersView> extends 36 | Transform { 37 | 38 | /** 39 | * Render the initalizers-part of the model separated by two new-line 40 | * characters. 41 | * 42 | * @param gen the generator 43 | * @param model the model 44 | * @return the generated code 45 | */ 46 | default String renderInitalizers(Generator gen, M model) { 47 | return gen.onEach(model.getInitializers()) 48 | .collect(Collectors.joining(dnl())); 49 | } 50 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/trait/HasJavadocTagsView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view.trait; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.model.trait.HasJavadoc; 22 | import com.speedment.common.codegen.model.trait.HasJavadocTags; 23 | 24 | import java.util.stream.Stream; 25 | 26 | /** 27 | * A trait with the functionality to render models with the trait 28 | * {@link HasJavadoc}. 29 | * 30 | * @author Emil Forslund 31 | * @param The model type 32 | * @see Transform 33 | */ 34 | public interface HasJavadocTagsView> { 35 | 36 | /** 37 | * Returns a stream of javadoc lines generated from the tags in the 38 | * specified model. If the stream is not empty it is prepended by an 39 | * empty line. 40 | * 41 | * @param gen the generator 42 | * @param model the model 43 | * @return the generated code 44 | */ 45 | default Stream renderJavadocTags(Generator gen, M model) { 46 | final Stream stream = gen.onEach(model.getTags()); 47 | 48 | if (model.getTags().isEmpty()) { 49 | return stream; 50 | } else { 51 | return Stream.concat( 52 | Stream.of(" "), // to get an empty line before the tags... 53 | stream 54 | ); 55 | } 56 | } 57 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/trait/HasJavadocView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view.trait; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.model.trait.HasJavadoc; 22 | 23 | import static com.speedment.common.codegen.util.Formatting.nl; 24 | 25 | /** 26 | * A trait with the functionality to render models with the trait 27 | * {@link HasJavadoc}. 28 | * 29 | * @author Emil Forslund 30 | * @param The model type 31 | * @see Transform 32 | */ 33 | public interface HasJavadocView> extends 34 | Transform { 35 | 36 | /** 37 | * Render the javadoc-part of the model with an extra new-line appended 38 | * afterwards. If no javadoc exists, an empty string is returned. 39 | * 40 | * @param gen the generator 41 | * @param model the model 42 | * @return the generated code 43 | */ 44 | default String renderJavadoc(Generator gen, M model) { 45 | return gen.on(model.getJavadoc()) 46 | .map(doc -> doc + nl()) 47 | .orElse(""); 48 | } 49 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/trait/HasMethodsView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view.trait; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.model.Method; 22 | import com.speedment.common.codegen.model.trait.HasMethods; 23 | 24 | import java.util.stream.Collectors; 25 | 26 | import static com.speedment.common.codegen.util.Formatting.dnl; 27 | 28 | /** 29 | * A trait with the functionality to render models with the trait 30 | * {@link HasMethods}. 31 | * 32 | * @author Emil Forslund 33 | * @param The model type 34 | * @see Transform 35 | */ 36 | public interface HasMethodsView> extends Transform { 37 | 38 | /** 39 | * Render the methods-part of the model separated with two new-line 40 | * characters. The {@link #wrapMethod(Method)}-method 41 | * can be overridden to change the implementation type of the methods before 42 | * rendering. 43 | * 44 | * @param gen the generator 45 | * @param model the model 46 | * @return the generated code 47 | */ 48 | default String renderMethods(Generator gen, M model) { 49 | return gen.onEach( 50 | model.getMethods().stream() 51 | .map(this::wrapMethod) 52 | .collect(Collectors.toList()) 53 | ).collect(Collectors.joining(dnl())); 54 | } 55 | 56 | /** 57 | * This method is called for every method being generated to give the 58 | * implementing class a chance to change the implementation before rendering. 59 | * There must be a {@link Transform} installed in the generator that can 60 | * handle the output of this method. 61 | *

62 | * The default behaviour of this method is to return the input without any 63 | * modifications. 64 | * 65 | * @param method the method to wrap 66 | * @return a model derived from the method 67 | */ 68 | default Object wrapMethod(Method method) { 69 | return method; 70 | } 71 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/trait/HasModifiersView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view.trait; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.model.modifier.Modifier; 22 | import com.speedment.common.codegen.model.trait.HasModifiers; 23 | 24 | import java.util.Set; 25 | import java.util.stream.Stream; 26 | 27 | import static com.speedment.common.codegen.internal.util.CollectorUtil.joinIfNotEmpty; 28 | import static java.util.stream.Collectors.toSet; 29 | 30 | /** 31 | * A trait with the functionality to render models with the trait 32 | * {@link HasModifiers}. 33 | * 34 | * @author Emil Forslund 35 | * @param The model type 36 | * @see Transform 37 | */ 38 | public interface HasModifiersView> extends 39 | Transform { 40 | 41 | /** 42 | * Render the modifiers-part of the model with an extra space appended 43 | * afterwards. If no modifiers exists, an empty string is returned. If an 44 | * non-empty array of allowed modifiers is provided, only those can 45 | * be visible in the result. 46 | * 47 | * @param gen the generator 48 | * @param model the model 49 | * @param allowed set of modifiers that can be visible 50 | * @return the generated code 51 | */ 52 | default String renderModifiers(Generator gen, M model, Modifier... allowed) { 53 | final Set modifiers; 54 | 55 | if (allowed.length == 0) { 56 | modifiers = model.getModifiers(); 57 | } else { 58 | modifiers = Stream.of(allowed).collect(toSet()); 59 | modifiers.retainAll(model.getModifiers()); 60 | } 61 | 62 | return gen.onEach(modifiers).collect(joinIfNotEmpty(" ", "", " ")); 63 | } 64 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/trait/HasNameView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view.trait; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.model.trait.HasName; 22 | 23 | /** 24 | * A trait with the functionality to render models with the trait 25 | * {@link HasName}. 26 | * 27 | * @author Emil Forslund 28 | * @param The model type 29 | * @see Transform 30 | */ 31 | public interface HasNameView> extends Transform { 32 | 33 | /** 34 | * Returns the trailing suffix that should be appended after the name if 35 | * one is rendered. 36 | *

37 | * The default value is an empty string (""). 38 | * 39 | * @return the trailing name suffix 40 | */ 41 | default String nameSuffix() { 42 | return ""; 43 | } 44 | 45 | /** 46 | * Render the name of the model. 47 | * 48 | * @param gen the generator 49 | * @param model the model 50 | * @return the generated code 51 | */ 52 | default String renderName(Generator gen, M model) { 53 | return model.getName() + nameSuffix(); 54 | } 55 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/trait/HasThrowsView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view.trait; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import static com.speedment.common.codegen.internal.util.CollectorUtil.joinIfNotEmpty; 22 | import com.speedment.common.codegen.model.trait.HasThrows; 23 | 24 | /** 25 | * A trait with the functionality to render models with the trait 26 | * {@link HasThrows}. 27 | * 28 | * @author Emil Forslund 29 | * @param The model type 30 | * @see Transform 31 | */ 32 | public interface HasThrowsView> extends 33 | Transform { 34 | 35 | /** 36 | * Render the throws-part of the model. 37 | * 38 | * @param gen the generator 39 | * @param model the model 40 | * @return the generated code 41 | */ 42 | default String renderThrows(Generator gen, M model) { 43 | return gen.onEach(model.getExceptions()) 44 | .collect(joinIfNotEmpty(", ", "throws ", throwsSuffix(model))); 45 | } 46 | 47 | /** 48 | * Returns any suffix to a throws statement. This will only be used if a 49 | * throws clause was specified. 50 | * 51 | * @param model the model being rendered 52 | * @return the throws suffix 53 | */ 54 | String throwsSuffix(M model); 55 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/trait/HasTypeView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view.trait; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.model.trait.HasType; 22 | 23 | /** 24 | * A trait with the functionality to render models with the trait 25 | * {@link HasType}. 26 | * 27 | * @author Emil Forslund 28 | * @param The model type 29 | * @see Transform 30 | */ 31 | public interface HasTypeView> extends Transform { 32 | 33 | /** 34 | * Render the type of the model appended by an extra space. 35 | * 36 | * @param gen the generator 37 | * @param model the model 38 | * @return the generated code 39 | */ 40 | default String renderType(Generator gen, M model) { 41 | return gen.on(model.getType()) 42 | .map(s -> s + " ") 43 | .orElse(""); 44 | } 45 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/trait/HasValueView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view.trait; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.model.trait.HasValue; 22 | 23 | import static com.speedment.common.codegen.util.Formatting.ifelse; 24 | 25 | /** 26 | * A trait with the functionality to render models with the trait 27 | * {@link HasValue}. 28 | * 29 | * @author Emil Forslund 30 | * @param The model type 31 | * @see Transform 32 | */ 33 | public interface HasValueView> extends Transform { 34 | 35 | /** 36 | * Render the value of the model if it exists, else an empty string. 37 | * 38 | * @param gen the generator 39 | * @param model the model 40 | * @return the generated code 41 | */ 42 | default String renderValue(Generator gen, M model) { 43 | return ifelse(model.getValue(), 44 | v -> " = " + gen.on(v).orElse(""), 45 | "" 46 | ); 47 | } 48 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/value/ArrayValueView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view.value; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.model.value.ArrayValue; 22 | 23 | import java.util.Optional; 24 | import java.util.stream.Collectors; 25 | 26 | import static com.speedment.common.codegen.internal.util.NullUtil.requireNonNulls; 27 | 28 | /** 29 | * Transforms from an {@link ArrayValue} to java code. 30 | * 31 | * @author Emil Forslund 32 | */ 33 | public final class ArrayValueView implements Transform { 34 | 35 | @Override 36 | public Optional transform(Generator gen, ArrayValue model) { 37 | requireNonNulls(gen, model); 38 | 39 | return Optional.of( 40 | gen.onEach(model.getValue()).collect( 41 | Collectors.joining(", ", "{", "}") 42 | ) 43 | ); 44 | } 45 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/value/BooleanValueView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view.value; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.model.value.BooleanValue; 22 | 23 | import java.util.Optional; 24 | 25 | import static java.util.Objects.requireNonNull; 26 | 27 | /** 28 | * Transforms from an {@link BooleanValue} to java code. 29 | * 30 | * @author Emil Forslund 31 | */ 32 | public final class BooleanValueView implements Transform { 33 | 34 | @Override 35 | public Optional transform(Generator gen, BooleanValue model) { 36 | requireNonNull(gen); 37 | requireNonNull(model); 38 | 39 | return Optional.of(model.getValue().toString()); 40 | } 41 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/value/EnumValueView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view.value; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.model.value.EnumValue; 22 | 23 | import java.util.Optional; 24 | 25 | import static com.speedment.common.codegen.internal.util.NullUtil.requireNonNulls; 26 | 27 | /** 28 | * Transforms from an {@link EnumValue} to java code. 29 | * 30 | * @author Emil Forslund 31 | */ 32 | public final class EnumValueView implements Transform { 33 | 34 | @Override 35 | public Optional transform(Generator gen, EnumValue model) { 36 | requireNonNulls(gen, model); 37 | 38 | return Optional.of( 39 | gen.on(model.getType()).orElse("") + "." + 40 | model.getValue() 41 | ); 42 | } 43 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/value/NullValueView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view.value; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.model.value.NullValue; 22 | 23 | import java.util.Optional; 24 | 25 | import static java.util.Objects.requireNonNull; 26 | 27 | /** 28 | * Transforms from an {@link NullValue} to java code. 29 | * 30 | * @author Emil Forslund 31 | */ 32 | public final class NullValueView implements Transform { 33 | 34 | private final static String NULL = "null"; 35 | 36 | @Override 37 | public Optional transform(Generator gen, NullValue model) { 38 | requireNonNull(gen); 39 | requireNonNull(model); 40 | 41 | return Optional.of(NULL); 42 | } 43 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/value/NumberValueView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view.value; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.model.value.NumberValue; 22 | 23 | import java.util.Optional; 24 | 25 | import static java.util.Objects.requireNonNull; 26 | 27 | /** 28 | * Transforms from an {@link NumberValue} to java code. 29 | * 30 | * @author Emil Forslund 31 | */ 32 | public final class NumberValueView implements Transform { 33 | 34 | @Override 35 | public Optional transform(Generator gen, NumberValue model) { 36 | requireNonNull(gen); 37 | requireNonNull(model); 38 | 39 | return Optional.of(model.getValue().toString()); 40 | } 41 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/value/ReferenceValueView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.java.view.value; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.Transform; 21 | import com.speedment.common.codegen.model.value.ReferenceValue; 22 | 23 | import java.util.Optional; 24 | 25 | import static java.util.Objects.requireNonNull; 26 | 27 | /** 28 | * Transforms from an {@link ReferenceValue} to java code. 29 | * 30 | * @author Emil Forslund 31 | */ 32 | public final class ReferenceValueView implements Transform { 33 | 34 | @Override 35 | public Optional transform(Generator gen, ReferenceValue model) { 36 | requireNonNull(gen); 37 | requireNonNull(model); 38 | 39 | return Optional.of(model.getValue()); 40 | } 41 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/java/view/value/TextValueView.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | /* 18 | * To change this license header, choose License Headers in Project Properties. 19 | * To change this template file, choose Tools | Templates 20 | * and open the template in the editor. 21 | */ 22 | package com.speedment.common.codegen.internal.java.view.value; 23 | 24 | import com.speedment.common.codegen.Generator; 25 | import com.speedment.common.codegen.Transform; 26 | import com.speedment.common.codegen.model.value.TextValue; 27 | 28 | import java.util.Optional; 29 | 30 | import static com.speedment.common.codegen.internal.util.NullUtil.requireNonNulls; 31 | 32 | /** 33 | * Transforms from an {@link TextValue} to java code. 34 | * 35 | * @author Emil Forslund 36 | */ 37 | public final class TextValueView implements Transform { 38 | 39 | @Override 40 | public Optional transform(Generator gen, TextValue model) { 41 | requireNonNulls(gen, model); 42 | 43 | return Optional.of("\"" + model.getValue() + "\""); 44 | } 45 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/model/InterfaceImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.model; 18 | 19 | import com.speedment.common.codegen.model.Interface; 20 | import com.speedment.common.codegen.model.Method; 21 | 22 | /** 23 | * The default implementation of the wrapper for the {@link Method} interface. 24 | * 25 | * @author Emil Forslund 26 | */ 27 | public final class InterfaceImpl extends ClassOrInterfaceImpl 28 | implements Interface { 29 | 30 | /** 31 | * Initializes this interface using a name. 32 | *

33 | * Warning! This class should not be instantiated directly but using 34 | * the {@link Interface#of(String)} method! 35 | * 36 | * @param name the name 37 | */ 38 | public InterfaceImpl(String name) { 39 | super (name); 40 | } 41 | 42 | /** 43 | * Copy constructor 44 | * 45 | * @param prototype the prototype 46 | */ 47 | protected InterfaceImpl(Interface prototype) { 48 | super (prototype); 49 | } 50 | 51 | @Override 52 | public InterfaceImpl copy() { 53 | return new InterfaceImpl(this); 54 | } 55 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/model/ValueImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | /* 18 | * To change this license header, choose License Headers in Project Properties. 19 | * To change this template file, choose Tools | Templates 20 | * and open the template in the editor. 21 | */ 22 | package com.speedment.common.codegen.internal.model; 23 | 24 | import com.speedment.common.codegen.model.Value; 25 | 26 | import java.util.Objects; 27 | 28 | /** 29 | * The default implementation of the {@link Value} interface. 30 | * 31 | * @author Emil Forslund 32 | * @param The extending type 33 | */ 34 | public abstract class ValueImpl implements Value { 35 | 36 | private V value; 37 | 38 | /** 39 | * Initializes this value. 40 | * 41 | * @param val the inner value 42 | */ 43 | public ValueImpl(V val) { 44 | value = val; 45 | } 46 | 47 | @Override 48 | public Value setValue(V value) { 49 | this.value = value; 50 | return this; 51 | } 52 | 53 | @Override 54 | public V getValue() { 55 | return value; 56 | } 57 | 58 | @Override 59 | public abstract ValueImpl copy(); 60 | 61 | @Override 62 | public int hashCode() { 63 | int hash = 7; 64 | hash = 31 * hash + Objects.hashCode(this.value); 65 | return hash; 66 | } 67 | 68 | @Override 69 | public boolean equals(Object obj) { 70 | if (this == obj) { 71 | return true; 72 | } 73 | if (obj == null) { 74 | return false; 75 | } 76 | if (getClass() != obj.getClass()) { 77 | return false; 78 | } 79 | final ValueImpl other = (ValueImpl) obj; 80 | return Objects.equals(this.value, other.value); 81 | } 82 | 83 | 84 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/model/value/ArrayValueImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.model.value; 18 | 19 | import com.speedment.common.codegen.internal.model.ValueImpl; 20 | import com.speedment.common.codegen.internal.util.Copier; 21 | import com.speedment.common.codegen.model.Value; 22 | import com.speedment.common.codegen.model.value.ArrayValue; 23 | 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | 27 | /** 28 | * 29 | * @author Emil Forslund 30 | */ 31 | public final class ArrayValueImpl extends ValueImpl>> implements ArrayValue { 32 | 33 | public ArrayValueImpl() { 34 | super(new ArrayList<>()); 35 | } 36 | 37 | public ArrayValueImpl(List> val) { 38 | super(val); 39 | } 40 | 41 | @Override 42 | public ArrayValueImpl copy() { 43 | return new ArrayValueImpl(Copier.copy(getValue(), s -> s.copy())); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/model/value/BooleanValueImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.model.value; 18 | 19 | import com.speedment.common.codegen.internal.model.ValueImpl; 20 | import com.speedment.common.codegen.model.value.BooleanValue; 21 | 22 | /** 23 | * 24 | * @author Emil Forslund 25 | */ 26 | public final class BooleanValueImpl extends ValueImpl implements BooleanValue { 27 | 28 | public BooleanValueImpl(Boolean num) { 29 | super(num); 30 | } 31 | 32 | @Override 33 | public BooleanValueImpl copy() { 34 | return new BooleanValueImpl(getValue()); 35 | } 36 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/model/value/EnumValueImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.model.value; 18 | 19 | import com.speedment.common.codegen.internal.model.ValueImpl; 20 | import com.speedment.common.codegen.model.value.EnumValue; 21 | 22 | import java.lang.reflect.Type; 23 | import java.util.Objects; 24 | 25 | /** 26 | * 27 | * @author Emil Forslund 28 | */ 29 | public final class EnumValueImpl extends ValueImpl implements EnumValue { 30 | 31 | private Type type; 32 | 33 | public EnumValueImpl(Type type, String value) { 34 | super (value); 35 | this.type = type; 36 | } 37 | 38 | protected EnumValueImpl(EnumValue prototype) { 39 | this (prototype.getType(), prototype.getValue()); 40 | } 41 | 42 | @Override 43 | public EnumValueImpl set(Type type) { 44 | this.type = type; 45 | return this; 46 | } 47 | 48 | @Override 49 | public Type getType() { 50 | return type; 51 | } 52 | 53 | @Override 54 | public EnumValueImpl copy() { 55 | return new EnumValueImpl(this); 56 | } 57 | 58 | @Override 59 | public int hashCode() { 60 | int hash = 7; 61 | hash = 79 * hash + Objects.hashCode(this.type); 62 | return hash; 63 | } 64 | 65 | @Override 66 | public boolean equals(Object obj) { 67 | if (this == obj) { 68 | return true; 69 | } 70 | if (obj == null) { 71 | return false; 72 | } 73 | if (getClass() != obj.getClass()) { 74 | return false; 75 | } 76 | final EnumValue other = (EnumValue) obj; 77 | return Objects.equals(this.type, other.getType()); 78 | } 79 | 80 | 81 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/model/value/NullValueImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.model.value; 18 | 19 | import com.speedment.common.codegen.internal.model.ValueImpl; 20 | import com.speedment.common.codegen.model.value.NullValue; 21 | 22 | /** 23 | * 24 | * @author Emil Forslund 25 | */ 26 | public final class NullValueImpl extends ValueImpl implements NullValue { 27 | 28 | public NullValueImpl() { 29 | super(0); 30 | } 31 | 32 | @Override 33 | public NullValueImpl copy() { 34 | return this; 35 | } 36 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/model/value/NumberValueImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.model.value; 18 | 19 | import com.speedment.common.codegen.internal.model.ValueImpl; 20 | import com.speedment.common.codegen.model.value.NumberValue; 21 | 22 | /** 23 | * 24 | * @author Emil Forslund 25 | */ 26 | public final class NumberValueImpl extends ValueImpl implements NumberValue { 27 | 28 | public NumberValueImpl(Number num) { 29 | super(num); 30 | } 31 | 32 | @Override 33 | public NumberValueImpl copy() { 34 | return new NumberValueImpl(getValue()); 35 | } 36 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/model/value/ReferenceValueImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.model.value; 18 | 19 | import com.speedment.common.codegen.internal.model.ValueImpl; 20 | import com.speedment.common.codegen.model.value.ReferenceValue; 21 | 22 | /** 23 | * 24 | * @author Emil Forslund 25 | */ 26 | public final class ReferenceValueImpl extends ValueImpl implements ReferenceValue { 27 | 28 | public ReferenceValueImpl(String value) { 29 | super(value); 30 | } 31 | 32 | @Override 33 | public ReferenceValueImpl copy() { 34 | return new ReferenceValueImpl(getValue()); 35 | } 36 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/model/value/TextValueImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.model.value; 18 | 19 | import com.speedment.common.codegen.internal.model.ValueImpl; 20 | import com.speedment.common.codegen.model.value.TextValue; 21 | 22 | /** 23 | * 24 | * @author Emil Forslund 25 | */ 26 | public final class TextValueImpl extends ValueImpl implements TextValue { 27 | 28 | public TextValueImpl(String num) { 29 | super(num); 30 | } 31 | 32 | @Override 33 | public TextValueImpl copy() { 34 | return new TextValueImpl(getValue()); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/util/Copier.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.util; 18 | 19 | import com.speedment.common.codegen.model.trait.HasCopy; 20 | 21 | import java.util.*; 22 | import java.util.function.Function; 23 | 24 | import static com.speedment.common.codegen.internal.util.StaticClassUtil.instanceNotAllowed; 25 | import static java.util.Objects.requireNonNull; 26 | 27 | /** 28 | * 29 | * @author Emil Forslund 30 | */ 31 | public final class Copier { 32 | 33 | public static > T copy(T prototype) { 34 | return prototype == null ? null : prototype.copy(); 35 | } 36 | 37 | public static > Optional copy(Optional prototype) { 38 | return Copier.copy(prototype, c -> c.copy()); 39 | } 40 | 41 | public static Optional copy(Optional prototype, Function copier) { 42 | if (prototype.isPresent()) { 43 | return Optional.of( 44 | requireNonNull(copier).apply(prototype.get()) 45 | ); 46 | } else { 47 | return Optional.empty(); 48 | } 49 | } 50 | 51 | public static > List copy(List prototype) { 52 | return Copier.copy(requireNonNull(prototype), c -> c.copy()); 53 | } 54 | 55 | public static List copy(List prototype, Function copier) { 56 | return copy(requireNonNull(prototype), copier, new ArrayList<>()); 57 | } 58 | 59 | public static > Set copy(Set prototype) { 60 | return Copier.copy(requireNonNull(prototype), c -> c.copy()); 61 | } 62 | 63 | public static Set copy(Set prototype, Function copier) { 64 | return copy(requireNonNull(prototype), copier, new HashSet<>()); 65 | } 66 | 67 | public static > L copy(Collection prototype, Function copier, L empty) { 68 | requireNonNull(prototype).forEach(e -> empty.add(copier.apply(e))); 69 | return empty; 70 | } 71 | 72 | /** 73 | * Utility classes should not be instantiated. 74 | */ 75 | private Copier() { instanceNotAllowed(getClass()); } 76 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/internal/util/StaticClassUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal.util; 18 | 19 | /** 20 | * Support class for classes that only contains static methods and fields. 21 | * This interface can for example be used for various "Util" classes. 22 | * 23 | * @author Per Minborg 24 | */ 25 | public final class StaticClassUtil { 26 | 27 | /** 28 | * Support method that can be used in constructors to throw an 29 | * {@code UnsupportedOperationException} if someone is trying to create an 30 | * instance of the class. 31 | * 32 | * @param caller the class of the instance that called this method 33 | */ 34 | public static void instanceNotAllowed(Class caller) throws UnsupportedOperationException { 35 | throw new UnsupportedOperationException( 36 | "It is not allowed to create instances of the " + 37 | caller.getName() + 38 | " class." 39 | ); 40 | } 41 | 42 | /** 43 | * Utility classes should not be instantiated. 44 | */ 45 | private StaticClassUtil() { instanceNotAllowed(getClass()); } 46 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/Annotation.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model; 18 | 19 | import com.speedment.common.codegen.internal.model.AnnotationImpl; 20 | import com.speedment.common.codegen.model.modifier.AnnotationModifier; 21 | import com.speedment.common.codegen.model.trait.*; 22 | 23 | /** 24 | * A model that represents an annotation in code. 25 | * 26 | * @author Emil Forslund 27 | * @see AnnotationUsage 28 | * @since 2.0 29 | */ 30 | public interface Annotation extends HasCopy, HasName, 31 | HasJavadoc, HasFields, HasImports, 32 | AnnotationModifier, HasAnnotationUsage { 33 | 34 | /** 35 | * Creates a new instance implementing this interface using the default 36 | * implementation. 37 | * 38 | * @param name the name 39 | * @return the new instance 40 | */ 41 | static Annotation of(String name) { 42 | return new AnnotationImpl(name); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/AnnotationUsage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model; 18 | 19 | import com.speedment.common.codegen.internal.model.AnnotationUsageImpl; 20 | import com.speedment.common.codegen.model.trait.HasCopy; 21 | import com.speedment.common.codegen.model.trait.HasType; 22 | import com.speedment.common.codegen.model.trait.HasValue; 23 | 24 | import java.lang.reflect.Type; 25 | import java.util.List; 26 | import java.util.Map; 27 | 28 | /** 29 | * A model that represents the usage of a particular annotation in code. 30 | * 31 | * @author Emil Forslund 32 | * @see Annotation 33 | * @since 2.0 34 | */ 35 | public interface AnnotationUsage extends HasCopy, 36 | HasType, HasValue { 37 | 38 | /** 39 | * Use the specified key-value pair when referencing the annotation. If you 40 | * only want to show a single value without any key, consider using the 41 | * {@link #put(String, Value)} method. 42 | * 43 | * @param key the key 44 | * @param val the value 45 | * @return a reference to this model 46 | */ 47 | AnnotationUsage put(String key, Value val); 48 | 49 | /** 50 | * Returns a list of all the key-value pairs in this model. 51 | * 52 | * @return all key-value pairs 53 | */ 54 | List>> getValues(); 55 | 56 | /** 57 | * Creates a new instance implementing this interface by using the default 58 | * implementation. 59 | * 60 | * @param type the type 61 | * @return the new instance 62 | */ 63 | static AnnotationUsage of(Type type) { 64 | return new AnnotationUsageImpl(type); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/Class.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model; 18 | 19 | import com.speedment.common.codegen.internal.model.ClassImpl; 20 | import com.speedment.common.codegen.model.modifier.ClassModifier; 21 | import com.speedment.common.codegen.model.trait.HasConstructors; 22 | import com.speedment.common.codegen.model.trait.HasSupertype; 23 | 24 | /** 25 | * A model that represents a class in code. 26 | * 27 | * @author Emil Forslund 28 | * @since 2.0 29 | */ 30 | public interface Class extends ClassOrInterface, HasConstructors, 31 | HasSupertype, ClassModifier { 32 | 33 | /** 34 | * Creates a new instance implementing this interface by using the default 35 | * implementation. 36 | * 37 | * @param name the name 38 | * @return the new instance 39 | */ 40 | static Class of(String name) { 41 | return new ClassImpl(name); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/ClassOrInterface.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model; 18 | 19 | import com.speedment.common.codegen.model.trait.*; 20 | 21 | /** 22 | * An abstract base class to share functionality between the models 23 | * {@link Class}, {@link Enum} and {@link Interface}. 24 | * 25 | * @author Emil Forslund 26 | * @param The extending type 27 | * @since 2.0 28 | */ 29 | public interface ClassOrInterface> extends 30 | HasCopy, HasCall, HasName, HasJavadoc, HasGenerics, 31 | HasImplements, HasClasses, HasMethods, HasFields, 32 | HasAnnotationUsage, HasModifiers, HasInitializers {} -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/Constructor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model; 18 | 19 | import com.speedment.common.codegen.internal.model.ConstructorImpl; 20 | import com.speedment.common.codegen.model.modifier.ConstructorModifier; 21 | import com.speedment.common.codegen.model.trait.*; 22 | 23 | /** 24 | * A model that represents a constructor in code. 25 | * 26 | * @author Emil Forslund 27 | * @since 2.0 28 | */ 29 | public interface Constructor extends HasCopy, HasCall, 30 | HasThrows, HasJavadoc, HasAnnotationUsage, 31 | HasFields, HasCode, ConstructorModifier { 32 | 33 | /** 34 | * Creates a new instance implementing this interface by using the default 35 | * implementation. 36 | 37 | * @return the new instance 38 | */ 39 | static Constructor of() { 40 | return new ConstructorImpl(); 41 | } 42 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/Enum.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model; 18 | 19 | import com.speedment.common.codegen.internal.model.EnumImpl; 20 | import com.speedment.common.codegen.model.modifier.EnumModifier; 21 | import com.speedment.common.codegen.model.trait.HasConstructors; 22 | 23 | import java.util.List; 24 | 25 | import static java.util.Objects.requireNonNull; 26 | 27 | /** 28 | * A model that represents an enumeration in code. 29 | * 30 | * @author Emil Forslund 31 | * @see EnumConstant 32 | * @since 2.0 33 | */ 34 | public interface Enum extends ClassOrInterface, EnumModifier, 35 | HasConstructors { 36 | 37 | /** 38 | * Adds the specified constant to this enum. The constant must not be null. 39 | * 40 | * @param constant the constant 41 | * @return a reference to this model 42 | */ 43 | default Enum add(EnumConstant constant) { 44 | getConstants().add(requireNonNull(constant)); 45 | return this; 46 | } 47 | 48 | /** 49 | * Returns a modifiable list of all the constants in this enum. 50 | * 51 | * @return a list of constants 52 | */ 53 | List getConstants(); 54 | 55 | /** 56 | * Creates a new instance implementing this interface by using the default 57 | * implementation. 58 | * 59 | * @param name the name 60 | * @return the new instance 61 | */ 62 | static Enum of(String name) { 63 | return new EnumImpl(name); 64 | } 65 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/EnumConstant.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model; 18 | 19 | import com.speedment.common.codegen.internal.model.EnumConstantImpl; 20 | import com.speedment.common.codegen.model.trait.HasClasses; 21 | import com.speedment.common.codegen.model.trait.HasCopy; 22 | import com.speedment.common.codegen.model.trait.HasFields; 23 | import com.speedment.common.codegen.model.trait.HasInitializers; 24 | import com.speedment.common.codegen.model.trait.HasJavadoc; 25 | import com.speedment.common.codegen.model.trait.HasMethods; 26 | import com.speedment.common.codegen.model.trait.HasName; 27 | import java.util.List; 28 | 29 | /** 30 | * A model that represents a constant in an enumeration. 31 | * 32 | * @author Emil Forslund 33 | * @see Enum 34 | * @since 2.0 35 | */ 36 | public interface EnumConstant 37 | extends HasCopy, 38 | HasName, 39 | HasJavadoc, 40 | HasClasses, 41 | HasInitializers, 42 | HasMethods, 43 | HasFields { 44 | 45 | /** 46 | * Adds the specified construction parameter to this constant. 47 | * 48 | * @param value the construction parameter 49 | * @return a reference to this model 50 | */ 51 | default EnumConstant add(Value value) { 52 | getValues().add(value); 53 | return this; 54 | } 55 | 56 | /** 57 | * Returns a modifiable list of all the construction parameters used when 58 | * instantiating this enum constant. 59 | * 60 | * @return all construction parameters 61 | */ 62 | List> getValues(); 63 | 64 | /** 65 | * Creates a new instance implementing this interface by using the default 66 | * implementation. 67 | * 68 | * @param name the name 69 | * @return the new instance 70 | */ 71 | static EnumConstant of(String name) { 72 | return new EnumConstantImpl(name); 73 | } 74 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/Field.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model; 18 | 19 | import com.speedment.common.codegen.internal.model.FieldImpl; 20 | import com.speedment.common.codegen.model.modifier.FieldModifier; 21 | import com.speedment.common.codegen.model.trait.*; 22 | 23 | import java.lang.reflect.Type; 24 | 25 | /** 26 | * A model that represents a field in code. This can be either as a method 27 | * parameter or as a class member. 28 | * 29 | * @author Emil Forslund 30 | * @since 2.0 31 | */ 32 | public interface Field extends 33 | HasCopy, 34 | HasCall, 35 | HasName, 36 | HasType, 37 | HasJavadoc, 38 | HasValue, 39 | HasAnnotationUsage, 40 | FieldModifier { 41 | 42 | /** 43 | * Creates a new instance implementing this interface by using the default 44 | * implementation. 45 | * 46 | * @param name the name 47 | * @param type the type 48 | * @return the new instance 49 | */ 50 | static Field of(String name, Type type) { 51 | return new FieldImpl(name, type); 52 | } 53 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/File.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model; 18 | 19 | import com.speedment.common.codegen.internal.model.FileImpl; 20 | import com.speedment.common.codegen.model.trait.*; 21 | 22 | /** 23 | * A model that represents an entire code file. 24 | * 25 | * @author Emil Forslund 26 | * @since 2.0 27 | */ 28 | public interface File extends 29 | HasCopy, 30 | HasName, 31 | HasJavadoc, 32 | HasImports, 33 | HasClasses, 34 | HasCall { 35 | 36 | /** 37 | * Creates a new instance implementing this interface by using the default 38 | * implementation. 39 | * 40 | * @param name the name 41 | * @return the new instance 42 | */ 43 | static File of(String name) { 44 | return new FileImpl(name); 45 | } 46 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/Import.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model; 18 | 19 | import com.speedment.common.codegen.internal.model.ImportImpl; 20 | import com.speedment.common.codegen.model.modifier.ImportModifier; 21 | import com.speedment.common.codegen.model.trait.HasCopy; 22 | import com.speedment.common.codegen.model.trait.HasType; 23 | 24 | import java.lang.reflect.Type; 25 | import java.util.Optional; 26 | 27 | /** 28 | * A model that represents the explicit import of an dependency in code. 29 | * 30 | * @author Emil Forslund 31 | * @since 2.0 32 | */ 33 | public interface Import extends HasCopy, HasType, 34 | ImportModifier { 35 | 36 | /** 37 | * Returns any static member referenced in this import. For non-static 38 | * imports, this value will be empty. 39 | * 40 | * @return the static member referenced 41 | */ 42 | Optional getStaticMember(); 43 | 44 | /** 45 | * Sets the static member referenced by this import. Remember to also set 46 | * the modifier to static using the {@link #static_()} method! 47 | * 48 | * @param member the new static member to reference 49 | * @return a reference to this model 50 | */ 51 | Import setStaticMember(String member); 52 | 53 | /** 54 | * Creates a new instance implementing this interface by using the default 55 | * implementation. 56 | * 57 | * @param type the type 58 | * @return the new instance 59 | */ 60 | static Import of(Type type) { 61 | return new ImportImpl(type); 62 | } 63 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/Initializer.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model; 18 | 19 | import com.speedment.common.codegen.internal.model.InitializerImpl; 20 | import com.speedment.common.codegen.model.modifier.InitalizerModifier; 21 | import com.speedment.common.codegen.model.trait.HasCall; 22 | import com.speedment.common.codegen.model.trait.HasCode; 23 | import com.speedment.common.codegen.model.trait.HasCopy; 24 | 25 | /** 26 | * A model that represents an initializer in code. 27 | * 28 | * @author Emil Forslund 29 | * @since 2.1 30 | */ 31 | public interface Initializer extends HasCopy, HasCall, 32 | HasCode, InitalizerModifier { 33 | 34 | /** 35 | * Creates a new instance implementing this interface by using the default 36 | * implementation. 37 | 38 | * @return the new instance 39 | */ 40 | static Initializer of() { 41 | return new InitializerImpl(); 42 | } 43 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/Interface.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model; 18 | 19 | import com.speedment.common.codegen.internal.model.InterfaceImpl; 20 | import com.speedment.common.codegen.model.modifier.InterfaceModifier; 21 | 22 | /** 23 | * A model that represents an interface in code. 24 | * 25 | * @author Emil Forslund 26 | * @see InterfaceField 27 | * @see InterfaceMethod 28 | * @since 2.0 29 | */ 30 | public interface Interface extends ClassOrInterface, InterfaceModifier { 31 | 32 | /** 33 | * Creates a new instance implementing this interface by using the default 34 | * implementation. 35 | * 36 | * @param name the name 37 | * @return the new instance 38 | */ 39 | static Interface of(String name) { 40 | return new InterfaceImpl(name); 41 | } 42 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/InterfaceField.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model; 18 | 19 | import com.speedment.common.codegen.internal.model.InterfaceFieldImpl; 20 | import com.speedment.common.codegen.model.modifier.InterfaceFieldModifier; 21 | import com.speedment.common.codegen.model.trait.*; 22 | 23 | /** 24 | * A model that represents a field of an interface in code. 25 | * 26 | * @author Emil Forslund 27 | * @see Interface 28 | * @since 2.0 29 | */ 30 | public interface InterfaceField extends HasName, 31 | HasType, InterfaceFieldModifier, 32 | HasJavadoc, HasValue, 33 | HasAnnotationUsage, HasCopy { 34 | 35 | /** 36 | * Creates a new instance implementing this interface by wrapping an existing 37 | * {@link Field} in an {@link InterfaceFieldImpl}. 38 | * 39 | * @param wrapped the wrapped field 40 | * @return the new instance 41 | */ 42 | static InterfaceField of(Field wrapped) { 43 | return new InterfaceFieldImpl(wrapped); 44 | } 45 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/InterfaceMethod.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model; 18 | 19 | import com.speedment.common.codegen.internal.model.InterfaceMethodImpl; 20 | import com.speedment.common.codegen.model.modifier.InterfaceMethodModifier; 21 | import com.speedment.common.codegen.model.trait.*; 22 | 23 | /** 24 | * A model that represents a method of an interface in code. 25 | * 26 | * @author Emil Forslund 27 | * @see Interface 28 | * @since 2.0 29 | */ 30 | public interface InterfaceMethod extends HasName, 31 | HasThrows, 32 | HasType, HasGenerics, 33 | HasFields, HasJavadoc, 34 | HasAnnotationUsage, HasCode, 35 | InterfaceMethodModifier, HasCopy { 36 | 37 | /** 38 | * Creates a new instance implementing this interface by wrapping an existing 39 | * {@link Method} in an {@link InterfaceMethodImpl}. 40 | * 41 | * @param wrapped the wrapped method 42 | * @return the new instance 43 | */ 44 | static InterfaceMethod of(Method wrapped) { 45 | return new InterfaceMethodImpl(wrapped); 46 | } 47 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/Javadoc.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model; 18 | 19 | import com.speedment.common.codegen.internal.model.JavadocImpl; 20 | import com.speedment.common.codegen.model.trait.HasCall; 21 | import com.speedment.common.codegen.model.trait.HasCopy; 22 | import com.speedment.common.codegen.model.trait.HasJavadocTags; 23 | 24 | /** 25 | * A model that represents a block of documentation in code. 26 | * 27 | * @author Emil Forslund 28 | * @see JavadocTag 29 | * @since 2.0 30 | */ 31 | public interface Javadoc extends HasCopy, HasCall, 32 | HasJavadocTags { 33 | 34 | /** 35 | * Sets the body text shown in the javadoc. 36 | * 37 | * @param text the text 38 | * @return a reference to this model 39 | */ 40 | Javadoc setText(String text); 41 | 42 | /** 43 | * Returns the body text shown in the javadoc. 44 | * 45 | * @return the body documentation text 46 | */ 47 | String getText(); 48 | 49 | /** 50 | * Creates a new instance implementing this interface by using the default 51 | * implementation. 52 | 53 | * @return the new instance 54 | */ 55 | static Javadoc of() { 56 | return new JavadocImpl(); 57 | } 58 | 59 | /** 60 | * Creates a new instance implementing this interface by using the default 61 | * implementation. 62 | * 63 | * @param text the documentation 64 | * @return the new instance 65 | */ 66 | static Javadoc of(String text) { 67 | return of().setText(text); 68 | } 69 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/Method.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model; 18 | 19 | import com.speedment.common.codegen.internal.model.MethodImpl; 20 | import com.speedment.common.codegen.model.modifier.MethodModifier; 21 | import com.speedment.common.codegen.model.trait.*; 22 | 23 | import java.lang.reflect.Type; 24 | 25 | /** 26 | * A model that represents a method declaration in code. 27 | * 28 | * @author Emil Forslund 29 | * @since 2.0 30 | */ 31 | public interface Method extends HasName, HasType, HasThrows, 32 | HasGenerics, HasFields, HasJavadoc, HasAnnotationUsage, 33 | HasCode, HasCall, MethodModifier, HasCopy { 34 | 35 | /** 36 | * Creates a new instance implementing this interface by using the default 37 | * implementation. 38 | * 39 | * @param name the name 40 | * @param type the type 41 | * @return the new instance 42 | */ 43 | static Method of(String name, Type type) { 44 | return new MethodImpl(name, type); 45 | } 46 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/Value.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model; 18 | 19 | 20 | import com.speedment.common.codegen.internal.model.value.*; 21 | import com.speedment.common.codegen.model.trait.HasCopy; 22 | import com.speedment.common.codegen.model.value.*; 23 | 24 | import java.lang.reflect.Type; 25 | import java.util.List; 26 | 27 | /** 28 | * A model that represents any kind of value declared in code. 29 | * 30 | * @author Emil Forslund 31 | * @param the value type 32 | * @since 2.0 33 | */ 34 | public interface Value extends HasCopy> { 35 | 36 | /** 37 | * Sets the inner value of this. 38 | * 39 | * @param value the new value 40 | * @return a reference to this model 41 | */ 42 | Value setValue(V value); 43 | 44 | /** 45 | * Returns the inner value of this model. 46 | * 47 | * @return the inner value 48 | */ 49 | V getValue(); 50 | 51 | static ArrayValue ofArray() { 52 | return new ArrayValueImpl(); 53 | } 54 | 55 | static ArrayValue ofArray(List> arrayValue) { 56 | return new ArrayValueImpl(arrayValue); 57 | } 58 | 59 | static BooleanValue ofBoolean(Boolean val) { 60 | return new BooleanValueImpl(val); 61 | } 62 | 63 | static EnumValue ofEnum(Type type, String value) { 64 | return new EnumValueImpl(type, value); 65 | } 66 | 67 | // static EnumValue ofEnum(EnumValue prototype) { 68 | // return new EnumValueImpl(prototype); 69 | // } 70 | 71 | static NullValue ofNull() { 72 | return new NullValueImpl(); 73 | } 74 | 75 | static NumberValue ofNumber(Number num) { 76 | return new NumberValueImpl(num); 77 | } 78 | 79 | static ReferenceValue ofReference(String reference) { 80 | return new ReferenceValueImpl(reference); 81 | } 82 | 83 | static TextValue ofText(String text) { 84 | return new TextValueImpl(text); 85 | } 86 | 87 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/modifier/AnnotationModifier.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.modifier; 18 | 19 | import com.speedment.common.codegen.model.modifier.Keyword.Public; 20 | 21 | /** 22 | * 23 | * @author Emil Forslund 24 | * @param The extending type 25 | * @since 2.0 26 | */ 27 | public interface AnnotationModifier> 28 | extends Public {} -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/modifier/ClassModifier.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.modifier; 18 | 19 | import com.speedment.common.codegen.model.modifier.Keyword.*; 20 | 21 | /** 22 | * 23 | * @author Emil Forslund 24 | * @param The extending type 25 | * @since 2.0 26 | */ 27 | public interface ClassModifier> extends Public, 28 | Protected, Private, Abstract, Static, Final, Strictfp {} -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/modifier/ConstructorModifier.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.modifier; 18 | 19 | import com.speedment.common.codegen.model.modifier.Keyword.Private; 20 | import com.speedment.common.codegen.model.modifier.Keyword.Protected; 21 | import com.speedment.common.codegen.model.modifier.Keyword.Public; 22 | 23 | /** 24 | * 25 | * @author Emil Forslund 26 | * @param The extending type 27 | * @since 2.0 28 | */ 29 | public interface ConstructorModifier> 30 | extends Public, Protected, Private {} -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/modifier/EnumModifier.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.modifier; 18 | 19 | import com.speedment.common.codegen.model.modifier.Keyword.Static; 20 | import com.speedment.common.codegen.model.modifier.Keyword.Private; 21 | import com.speedment.common.codegen.model.modifier.Keyword.Protected; 22 | import com.speedment.common.codegen.model.modifier.Keyword.Public; 23 | 24 | /** 25 | * 26 | * @author Emil Forslund 27 | * @param The extending type 28 | * @since 2.0 29 | */ 30 | public interface EnumModifier> 31 | extends Public, Protected, Private, Static {} -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/modifier/FieldModifier.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.modifier; 18 | 19 | import com.speedment.common.codegen.model.modifier.Keyword.*; 20 | 21 | /** 22 | * 23 | * @author Emil Forslund 24 | * @param The extending type 25 | * @since 2.0 26 | */ 27 | public interface FieldModifier> 28 | extends Public, Protected, Private, Static, Final, 29 | Synchronized, Transient, Volatile {} -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/modifier/ImportModifier.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.modifier; 18 | 19 | import com.speedment.common.codegen.model.modifier.Keyword.Static; 20 | 21 | /** 22 | * 23 | * @author Emil Forslund 24 | * @param The extending type 25 | * @since 2.0 26 | */ 27 | public interface ImportModifier> extends Static {} -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/modifier/InitalizerModifier.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.modifier; 18 | 19 | import com.speedment.common.codegen.model.modifier.Keyword.Static; 20 | 21 | /** 22 | * 23 | * @author Emil Forslund 24 | * @param The extending type 25 | * @since 2.0 26 | */ 27 | public interface InitalizerModifier> extends Static {} -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/modifier/InterfaceFieldModifier.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.modifier; 18 | 19 | import com.speedment.common.codegen.model.modifier.Keyword.Final; 20 | 21 | /** 22 | * 23 | * @author Emil Forslund 24 | * @param The extending type 25 | * @since 2.0 26 | */ 27 | public interface InterfaceFieldModifier> extends Final {} -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/modifier/InterfaceMethodModifier.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.modifier; 18 | 19 | import com.speedment.common.codegen.model.modifier.Keyword.Static; 20 | import com.speedment.common.codegen.model.modifier.Keyword.Default; 21 | 22 | /** 23 | * 24 | * @author Emil Forslund 25 | * @param The extending type 26 | * @since 2.0 27 | */ 28 | public interface InterfaceMethodModifier> 29 | extends Static, Default {} -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/modifier/InterfaceModifier.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.modifier; 18 | 19 | import com.speedment.common.codegen.model.modifier.Keyword.Public; 20 | 21 | /** 22 | * 23 | * @author Emil Forslund 24 | * @param The extending type 25 | * @since 2.0 26 | */ 27 | public interface InterfaceModifier> extends Public {} -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/modifier/MethodModifier.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.modifier; 18 | 19 | import com.speedment.common.codegen.model.modifier.Keyword.*; 20 | 21 | /** 22 | * 23 | * @author Emil Forslund 24 | * @param The extending type 25 | * @since 2.0 26 | */ 27 | public interface MethodModifier> extends Public, 28 | Protected, Private, Abstract, Static, Final, Strictfp, 29 | Synchronized, Native, Default {} -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/modifier/Modifier.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.modifier; 18 | 19 | import com.speedment.common.codegen.model.trait.HasCopy; 20 | 21 | /** 22 | * A modifier is a keyword that the programmer can put before a declaration 23 | * to configure things like accessibility and lifespan. 24 | * 25 | * @author Emil Forslund 26 | * @since 2.0 27 | */ 28 | public enum Modifier implements HasCopy { 29 | 30 | PUBLIC ("public"), 31 | PROTECTED ("protected"), 32 | PRIVATE ("private"), 33 | ABSTRACT ("abstract"), 34 | FINAL ("final"), 35 | STATIC ("static"), 36 | STRICTFP ("strictfp"), 37 | TRANSIENT ("transient"), 38 | VOLATILE ("volatile"), 39 | SYNCHRONIZED ("synchronized"), 40 | NATIVE ("native"), 41 | DEFAULT ("default"); 42 | 43 | private final String name; 44 | 45 | /** 46 | * Modifier constructor. 47 | * 48 | * @param name the name in lowercase 49 | */ 50 | Modifier(String name) { 51 | this.name = name; 52 | } 53 | 54 | /** 55 | * Returns the name of the modifier. 56 | * 57 | * @return the name 58 | */ 59 | public String getName() { 60 | return name; 61 | } 62 | 63 | @Override 64 | public Modifier copy() { 65 | return this; 66 | } 67 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/modifier/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | /** 18 | * Implementations of the 19 | * {@link com.speedment.common.codegen.model.modifier.Modifier} interface that 20 | * represent the modifier keywords of the java language is located in this 21 | * package. 22 | *

23 | * This package is part of the API. Modifications to classes here should only 24 | * (if ever) be done in major releases. 25 | */ 26 | package com.speedment.common.codegen.model.modifier; -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | /** 18 | * Models for typical object-oriented language building blocks are located in 19 | * this package. The ambition of codegen is to separate model, view and 20 | * controller logic into different classes. This package represents the model 21 | * part of that trio. 22 | *

23 | * The interfaces in this package does not share a common ancestor. The reason 24 | * for this is that any class should qualify as a model as long as a 25 | * corresponding view is installed in the active 26 | * {@link com.speedment.common.codegen.Generator}. 27 | *

28 | * This package is part of the API. Modifications to classes here should only 29 | * (if ever) be done in major releases. 30 | */ 31 | package com.speedment.common.codegen.model; -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/trait/HasAnnotationUsage.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.trait; 18 | 19 | import com.speedment.common.codegen.model.AnnotationUsage; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * A trait for models that contains {@link AnnotationUsage} components. 25 | * 26 | * @author Emil Forslund 27 | * @param The extending type 28 | */ 29 | public interface HasAnnotationUsage> { 30 | 31 | /** 32 | * Adds the specified {@link AnnotationUsage} to this model. 33 | * 34 | * @param annotation the new child 35 | * @return a reference to this 36 | */ 37 | @SuppressWarnings("unchecked") 38 | default T add(final AnnotationUsage annotation) { 39 | getAnnotations().add(annotation); 40 | return (T) this; 41 | } 42 | 43 | /** 44 | * Returns a list of all the annotation usages in this model. 45 | *

46 | * The list returned must be mutable for changes! 47 | * 48 | * @return the annotations. 49 | */ 50 | List getAnnotations(); 51 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/trait/HasCall.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.trait; 18 | 19 | import java.util.function.Consumer; 20 | 21 | /** 22 | * Trait for code generator models that can be called. 23 | * 24 | * @param The extending type 25 | * 26 | * @author Emil Forslund 27 | * @since 2.0 28 | */ 29 | public interface HasCall { 30 | 31 | /** 32 | * Calls the specified {@link Consumer} with this object as the parameter. 33 | * This method exists so that methods can operate on an object without 34 | * breaking the flow. 35 | * 36 | * @param procedure the procedure to call 37 | * @return a reference to this 38 | */ 39 | @SuppressWarnings("unchecked") 40 | default T call(Consumer procedure) { 41 | procedure.accept((T) this); 42 | return (T) this; 43 | } 44 | 45 | /** 46 | * Calls the specified {@link Runnable}. This method exists so that methods 47 | * can operate on an object without breaking the flow. 48 | * 49 | * @param procedure the procedure to call 50 | * @return a reference to this 51 | */ 52 | @SuppressWarnings("unchecked") 53 | default T call(Runnable procedure) { 54 | procedure.run(); 55 | return (T) this; 56 | } 57 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/trait/HasClasses.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.trait; 18 | 19 | import com.speedment.common.codegen.model.ClassOrInterface; 20 | 21 | import java.util.Collection; 22 | import java.util.List; 23 | 24 | /** 25 | * A trait for models that contain {@link ClassOrInterface} components. 26 | * 27 | * @author Emil Forslund 28 | * @param The extending type 29 | * @since 2.0 30 | */ 31 | public interface HasClasses> { 32 | 33 | /** 34 | * Adds the specified {@link ClassOrInterface} to this model. 35 | * 36 | * @param member the new child 37 | * @return a reference to this 38 | */ 39 | @SuppressWarnings("unchecked") 40 | default T add(ClassOrInterface member) { 41 | getClasses().add(member); 42 | return (T) this; 43 | } 44 | 45 | /** 46 | * Adds all the specified {@link ClassOrInterface} members to this model. 47 | * 48 | * @param members the new children 49 | * @return a reference to this 50 | */ 51 | @SuppressWarnings("unchecked") 52 | default T addAllClasses(Collection> members) { 53 | getClasses().addAll(members); 54 | return (T) this; 55 | } 56 | 57 | /** 58 | * Returns a list of all the classes, interfaces and enumerations in this 59 | * model. 60 | *

61 | * The list returned must be mutable for changes! 62 | * 63 | * @return all the classes 64 | */ 65 | List> getClasses(); 66 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/trait/HasCode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.trait; 18 | 19 | import java.util.Collections; 20 | import java.util.List; 21 | 22 | import static com.speedment.common.codegen.internal.util.NullUtil.requireNonNullElements; 23 | import static com.speedment.common.codegen.util.Formatting.nl; 24 | 25 | /** 26 | * A trait for models that contains code. 27 | * 28 | * @author Emil Forslund 29 | * @param The extending type 30 | * @since 2.0 31 | */ 32 | public interface HasCode> { 33 | 34 | /** 35 | * Adds the specified row of code to this model. If the row contains 36 | * new-line characters, the line will be broken apart on those characters 37 | * and added using the {@link #add(String...)}-method. 38 | * 39 | * @param row the row 40 | * @return a reference to this 41 | */ 42 | @SuppressWarnings("unchecked") 43 | default T add(String row) { 44 | return add(row.split(nl())); 45 | } 46 | 47 | /** 48 | * Adds all the specified rows to this model. If any of the specified rows 49 | * contains a new-line character it will be broken apart on that character 50 | * so that every row is in fact added as a separate string. 51 | * 52 | * @param rows the rows 53 | * @return a reference to this 54 | */ 55 | @SuppressWarnings("unchecked") 56 | default T add(String... rows) { 57 | requireNonNullElements(rows); 58 | for (final String row : rows) { 59 | Collections.addAll(getCode(), row.split(nl())); 60 | } 61 | return (T) this; 62 | } 63 | 64 | /** 65 | * Returns a list of the code rows of this model. 66 | *

67 | * The list returned must be mutable for changes! 68 | * 69 | * @return the code rows 70 | */ 71 | List getCode(); 72 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/trait/HasComment.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.trait; 18 | 19 | import java.util.Optional; 20 | 21 | /** 22 | * A trait for models that can have a comment. 23 | * 24 | * @author Emil Forslund 25 | * @param The extending type 26 | * @since 2.0 27 | */ 28 | public interface HasComment> { 29 | 30 | /** 31 | * If a comment is attached to this model, return it. Else empty. 32 | * 33 | * @return the comment or empty 34 | */ 35 | Optional getComment(); 36 | 37 | /** 38 | * Sets the comment of this model. The comment may have multiple rows. 39 | * 40 | * @param comment the comment 41 | * @return a reference to this 42 | */ 43 | T setComment(String comment); 44 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/trait/HasConstructors.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.trait; 18 | 19 | import com.speedment.common.codegen.model.Constructor; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * A trait for models that contain {@link Constructor} components. 25 | * 26 | * @author Emil Forslund 27 | * @param The extending type 28 | * @since 2.0 29 | */ 30 | public interface HasConstructors> { 31 | 32 | /** 33 | * Adds the specified {@link Constructor} to this model. 34 | * 35 | * @param constr the new child 36 | * @return a reference to this 37 | */ 38 | @SuppressWarnings("unchecked") 39 | default T add(final Constructor constr) { 40 | getConstructors().add(constr); 41 | return (T) this; 42 | } 43 | 44 | /** 45 | * Returns a list of all the constructors of this model. 46 | *

47 | * The list returned must be mutable for changes! 48 | * 49 | * @return the constructors 50 | */ 51 | List getConstructors(); 52 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/trait/HasCopy.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.trait; 18 | 19 | /** 20 | * Trait for code generator models that can be deep-copied. 21 | * 22 | * @author Emil Forslund 23 | * @param The extending type 24 | * @since 2.0 25 | */ 26 | public interface HasCopy> { 27 | 28 | /** 29 | * Create a deep copy of this model. 30 | * 31 | * @return the copy 32 | */ 33 | T copy(); 34 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/trait/HasFields.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.trait; 18 | 19 | import com.speedment.common.codegen.model.Field; 20 | 21 | import java.util.Collection; 22 | import java.util.List; 23 | 24 | /** 25 | * A trait for models that contain {@link Field} components. 26 | * 27 | * @author Emil Forslund 28 | * @param The extending type 29 | * @since 2.0 30 | */ 31 | public interface HasFields> { 32 | 33 | /** 34 | * Adds the specified {@link Field} to this model. 35 | * 36 | * @param field the new child 37 | * @return a reference to this 38 | */ 39 | @SuppressWarnings("unchecked") 40 | default T add(final Field field) { 41 | getFields().add(field); 42 | return (T) this; 43 | } 44 | 45 | /** 46 | * Adds all the specified {@link Field} members to this model. 47 | * 48 | * @param fields the new children 49 | * @return a reference to this 50 | */ 51 | @SuppressWarnings("unchecked") 52 | default T addAllFields(final Collection fields) { 53 | getFields().addAll(fields); 54 | return (T) this; 55 | } 56 | 57 | /** 58 | * Returns a list of all the fields in this model. 59 | *

60 | * The list returned must be mutable for changes! 61 | * 62 | * @return all the fields 63 | */ 64 | List getFields(); 65 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/trait/HasGenerics.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.trait; 18 | 19 | import com.speedment.common.codegen.model.Generic; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * A trait for models that contain {@link Generic} components. 25 | * 26 | * @author Emil Forslund 27 | * @param The extending type 28 | * @since 2.0 29 | */ 30 | public interface HasGenerics> { 31 | 32 | /** 33 | * Adds the specified {@link Generic} to this model. 34 | * 35 | * @param generic the new child 36 | * @return a reference to this 37 | */ 38 | @SuppressWarnings("unchecked") 39 | default T add(final Generic generic) { 40 | getGenerics().add(generic); 41 | return (T) this; 42 | } 43 | 44 | /** 45 | * Returns a list of all the generics in this model. 46 | *

47 | * The list returned must be mutable for changes! 48 | * 49 | * @return the generics 50 | */ 51 | List getGenerics(); 52 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/trait/HasImplements.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.trait; 18 | 19 | import java.lang.reflect.Type; 20 | import java.util.List; 21 | 22 | /** 23 | * A trait for models that have interfaces as supertypes. 24 | * 25 | * @author Emil Forslund 26 | * @param The extending type 27 | * @since 2.0 28 | */ 29 | public interface HasImplements> { 30 | 31 | /** 32 | * Adds the specified supertype to this model. The type should represent 33 | * an interface. 34 | * 35 | * @param interf the new child 36 | * @return a reference to this 37 | */ 38 | @SuppressWarnings("unchecked") 39 | default T add(final Type interf) { 40 | getInterfaces().add(interf); 41 | return (T) this; 42 | } 43 | 44 | /** 45 | * Returns a list of all the interfaces implemented by this model. 46 | *

47 | * The list returned must be mutable for changes! 48 | * 49 | * @return the interfaces 50 | */ 51 | List getInterfaces(); 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/trait/HasImports.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.trait; 18 | 19 | import com.speedment.common.codegen.model.Import; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * A trait for models that contain {@link Import} components. 25 | * 26 | * @author Emil Forslund 27 | * @param The extending type 28 | * @since 2.0 29 | */ 30 | public interface HasImports> { 31 | 32 | /** 33 | * Adds the specified {@link Import} to this model. 34 | * 35 | * @param dep the new child 36 | * @return a reference to this 37 | */ 38 | @SuppressWarnings("unchecked") 39 | default T add(final Import dep) { 40 | getImports().add(dep); 41 | return (T) this; 42 | } 43 | 44 | /** 45 | * Returns a list of all imports in this model. 46 | *

47 | * The list returned must be mutable for changes! 48 | * 49 | * @return the imports 50 | */ 51 | List getImports(); 52 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/trait/HasInitializers.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.trait; 18 | 19 | import com.speedment.common.codegen.model.Initializer; 20 | import java.util.List; 21 | 22 | /** 23 | * A trait for models that contain {@link Initializer} components. 24 | * 25 | * @param the extending type 26 | * 27 | * @author Emil Forslund 28 | * @since 2.0.0 29 | */ 30 | public interface HasInitializers> { 31 | 32 | /** 33 | * Adds the specified {@link Initializer} to this model. 34 | * 35 | * @param init the new child 36 | * @return a reference to this 37 | */ 38 | @SuppressWarnings("unchecked") 39 | default T add(final Initializer init) { 40 | getInitializers().add(init); 41 | return (T) this; 42 | } 43 | 44 | /** 45 | * Returns a list of all intializers in this model. 46 | *

47 | * The list returned must be mutable for changes! 48 | * 49 | * @return the initalizers 50 | */ 51 | List getInitializers(); 52 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/trait/HasJavadoc.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.trait; 18 | 19 | import com.speedment.common.codegen.model.Javadoc; 20 | 21 | import java.util.Optional; 22 | 23 | /** 24 | * A trait for models that contain {@link Javadoc} components. 25 | * 26 | * @author Emil Forslund 27 | * @param The extending type 28 | * @since 2.0 29 | */ 30 | public interface HasJavadoc> { 31 | 32 | /** 33 | * Sets the {@link Javadoc} of this model. 34 | * 35 | * @param doc the javadoc 36 | * @return a reference to this 37 | */ 38 | T set(final Javadoc doc); 39 | 40 | /** 41 | * Returns the documentation of this model if such exists, else 42 | * empty. 43 | * 44 | * @return the documentation or empty 45 | */ 46 | Optional getJavadoc(); 47 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/trait/HasJavadocTags.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.trait; 18 | 19 | import com.speedment.common.codegen.model.JavadocTag; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * A trait for models that contain {@link JavadocTag} components. 25 | * 26 | * @author Emil Forslund 27 | * @param The extending type 28 | * @since 2.0 29 | */ 30 | public interface HasJavadocTags> { 31 | 32 | /** 33 | * Adds the specified {@link JavadocTag} to this model. 34 | * 35 | * @param tag the new child 36 | * @return a reference to this 37 | */ 38 | @SuppressWarnings("unchecked") 39 | default T add(final JavadocTag tag) { 40 | getTags().add(tag); 41 | return (T) this; 42 | } 43 | 44 | /** 45 | * Returns a list of all documentation tags of this model. 46 | *

47 | * The list returned must be mutable for changes! 48 | * 49 | * @return the javadoc tags 50 | */ 51 | List getTags(); 52 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/trait/HasMethods.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.trait; 18 | 19 | import com.speedment.common.codegen.model.Method; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * A trait for models that contain {@link Method} components. 25 | * 26 | * @author Emil Forslund 27 | * @param The extending type 28 | * @since 2.0 29 | */ 30 | public interface HasMethods> { 31 | 32 | /** 33 | * Adds the specified {@link Method} to this model. 34 | * 35 | * @param meth the new child 36 | * @return a reference to this 37 | */ 38 | @SuppressWarnings("unchecked") 39 | default T add(final Method meth) { 40 | getMethods().add(meth); 41 | return (T) this; 42 | } 43 | 44 | /** 45 | * Returns a list of all methods in this model. 46 | *

47 | * The list returned must be mutable for changes! 48 | * 49 | * @return the methods 50 | */ 51 | List getMethods(); 52 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/trait/HasModifiers.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.trait; 18 | 19 | import com.speedment.common.codegen.model.modifier.Modifier; 20 | 21 | import java.util.Set; 22 | 23 | /** 24 | * A trait for models that contain {@link Modifier} components. 25 | * 26 | * @author Emil Forslund 27 | * @param The extending type 28 | * @since 2.0 29 | */ 30 | public interface HasModifiers> { 31 | 32 | /** 33 | * Returns a Set with all modifiers of this model. 34 | *

35 | * The set returned must be mutable for changes! 36 | * 37 | * @return the modifiers 38 | */ 39 | Set getModifiers(); 40 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/trait/HasName.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.trait; 18 | 19 | /** 20 | * A trait for models that have a name. 21 | * 22 | * @author Emil Forslund 23 | * @param The extending type 24 | * @since 2.0 25 | */ 26 | public interface HasName> { 27 | 28 | /** 29 | * Sets the name of this model. 30 | *

31 | * This must not be null! 32 | * 33 | * @param name the new name 34 | * @return a reference to this 35 | */ 36 | T setName(final String name); 37 | 38 | /** 39 | * Returns the name of this model. 40 | *

41 | * This should never be null! 42 | * 43 | * @return the name 44 | */ 45 | String getName(); 46 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/trait/HasSupertype.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.trait; 18 | 19 | import java.lang.reflect.Type; 20 | import java.util.Optional; 21 | 22 | /** 23 | * A trait for models that has a super type. 24 | * 25 | * @author Emil Forslund 26 | * @param The extending type 27 | * @since 2.0 28 | */ 29 | public interface HasSupertype> { 30 | 31 | /** 32 | * Sets the super type of this model. 33 | * 34 | * @param type the super type 35 | * @return a reference to this 36 | */ 37 | T setSupertype(Type type); 38 | 39 | /** 40 | * Returns the super type if such exists, else empty. 41 | * 42 | * @return the super type or empty 43 | */ 44 | Optional getSupertype(); 45 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/trait/HasThrows.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.trait; 18 | 19 | import java.lang.reflect.Type; 20 | import java.util.Set; 21 | 22 | /** 23 | * A trait for models that can throw exceptions. 24 | * 25 | * @author Emil Forslund 26 | * @param The extending type 27 | * @since 2.0 28 | */ 29 | public interface HasThrows> { 30 | 31 | /** 32 | * Adds the specified exception reference to the throws-clause 33 | * of this model. 34 | * 35 | * @param exception the new exception 36 | * @return a reference to this 37 | */ 38 | @SuppressWarnings("unchecked") 39 | default T add(final Type exception) { 40 | getExceptions().add(exception); 41 | return (T) this; 42 | } 43 | 44 | /** 45 | * Returns a Set with all the exceptions that can be throwed by 46 | * this model. 47 | *

48 | * The set returned must be mutable for changes! 49 | * 50 | * @return all exceptions 51 | */ 52 | Set getExceptions(); 53 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/trait/HasType.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.trait; 18 | 19 | import java.lang.reflect.Type; 20 | 21 | /** 22 | * A trait for models that has a {@link Type}. 23 | * 24 | * @author Emil Forslund 25 | * @param The extending type 26 | * @since 2.0 27 | */ 28 | public interface HasType> { 29 | 30 | /** 31 | * Sets the type of this model. 32 | * 33 | * @param type the new type 34 | * @return a reference to this 35 | */ 36 | T set(final Type type); 37 | 38 | /** 39 | * Returns the type of this model. 40 | * 41 | * @return the type 42 | */ 43 | Type getType(); 44 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/trait/HasValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.trait; 18 | 19 | import com.speedment.common.codegen.model.Value; 20 | 21 | import java.util.Optional; 22 | 23 | /** 24 | * A trait for models that has a {@link Value}. 25 | * 26 | * @author Emil Forslund 27 | * @param The extending type 28 | * @since 2.0 29 | */ 30 | public interface HasValue> { 31 | 32 | /** 33 | * Sets the value of this model. 34 | * 35 | * @param val the new value 36 | * @return a reference to this 37 | */ 38 | T set(final Value val); 39 | 40 | /** 41 | * Returns the value of this model. 42 | * 43 | * @return the value 44 | */ 45 | Optional> getValue(); 46 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/trait/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | /** 18 | * Common traits used by the codegen models located in the 19 | * {@code com.speedment.codegen.lang.model} package. 20 | *

21 | * This package is part of the API. Modifications to classes here should only 22 | * (if ever) be done in major releases. 23 | */ 24 | package com.speedment.common.codegen.model.trait; 25 | -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/value/ArrayValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.value; 18 | 19 | import com.speedment.common.codegen.model.Value; 20 | 21 | import java.util.List; 22 | 23 | /** 24 | * 25 | * @author Emil Forslund 26 | */ 27 | public interface ArrayValue extends Value>> { 28 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/value/BooleanValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.value; 18 | 19 | import com.speedment.common.codegen.model.Value; 20 | 21 | /** 22 | * 23 | * @author Emil Forslund 24 | */ 25 | public interface BooleanValue extends Value { 26 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/value/EnumValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.value; 18 | 19 | import com.speedment.common.codegen.model.Value; 20 | import com.speedment.common.codegen.model.trait.HasType; 21 | 22 | /** 23 | * 24 | * @author Emil Forslund 25 | */ 26 | public interface EnumValue extends Value, HasType { 27 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/value/NullValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.value; 18 | 19 | import com.speedment.common.codegen.model.Value; 20 | 21 | 22 | /** 23 | * 24 | * @author Emil Forslund 25 | */ 26 | public interface NullValue extends Value { 27 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/value/NumberValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.value; 18 | 19 | import com.speedment.common.codegen.model.Value; 20 | 21 | /** 22 | * 23 | * @author Emil Forslund 24 | */ 25 | public interface NumberValue extends Value { 26 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/value/ReferenceValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.value; 18 | 19 | import com.speedment.common.codegen.model.Value; 20 | 21 | /** 22 | * 23 | * @author Emil Forslund 24 | */ 25 | public interface ReferenceValue extends Value { 26 | 27 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/model/value/TextValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.model.value; 18 | 19 | import com.speedment.common.codegen.model.Value; 20 | 21 | /** 22 | * 23 | * @author Emil Forslund 24 | */ 25 | public interface TextValue extends Value { 26 | } -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | /** 18 | * The main interfaces of the codegen library are located in this package. 19 | *

20 | * This package is part of the API. Modifications to classes here should only 21 | * (if ever) be done in major releases. 22 | */ 23 | package com.speedment.common.codegen; -------------------------------------------------------------------------------- /src/main/java/com/speedment/common/codegen/util/package-info.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | /** 18 | * Utility methods for the codegen library are located in this package. 19 | *

20 | * This package is part of the API. Modifications to classes here should only 21 | * (if ever) be done in major releases. 22 | */ 23 | package com.speedment.common.codegen.util; -------------------------------------------------------------------------------- /src/test/java/com/example/PersonFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.example; 18 | 19 | import com.speedment.example.PersonImpl; 20 | 21 | public final class PersonFactory { 22 | 23 | private final com.speedment.example.Person.Builder builder; 24 | 25 | public PersonFactory() { 26 | this.builder = new PersonImpl.Builder(); 27 | } 28 | 29 | public com.speedment.example.Person create(long id, String firstname, String lastname) { 30 | return builder 31 | .withId(id) 32 | .withFirstname(firstname) 33 | .withLastname(lastname) 34 | .build(); 35 | } 36 | } -------------------------------------------------------------------------------- /src/test/java/com/speedment/common/codegen/internal/TestGenericInterfaces.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.common.codegen.internal; 18 | 19 | import com.speedment.common.codegen.Generator; 20 | import com.speedment.common.codegen.constant.SimpleType; 21 | import com.speedment.common.codegen.internal.java.JavaGenerator; 22 | import com.speedment.common.codegen.model.Field; 23 | import com.speedment.common.codegen.model.Generic; 24 | import com.speedment.common.codegen.model.Interface; 25 | import com.speedment.common.codegen.model.Method; 26 | import org.junit.After; 27 | import org.junit.AfterClass; 28 | import org.junit.Before; 29 | import org.junit.Test; 30 | 31 | /** 32 | * 33 | * @author Emil Forslund 34 | */ 35 | public class TestGenericInterfaces { 36 | 37 | private Generator cg; 38 | private Interface model; 39 | 40 | @AfterClass 41 | public static void tearDownClass() {} 42 | 43 | @Before 44 | public void setUp() { 45 | 46 | model = Interface.of("Nameable") 47 | .add(Generic.of("T")) 48 | .add(Method.of("getName", String.class)) 49 | .add(Method.of("setName", SimpleType.create("T")) 50 | .add(Field.of("name", String.class)) 51 | ); 52 | 53 | cg = new JavaGenerator(); 54 | } 55 | 56 | @After 57 | public void tearDown() {} 58 | 59 | @Test 60 | public void testRender() { 61 | System.out.println("*** Begin TestGenericInterfaces: testRender() ***"); 62 | System.out.println(cg.on(model).get()); 63 | System.out.println("*** End TestGenericInterfaces: testRender() ***"); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/test/java/com/speedment/example/Person.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.example; 18 | 19 | /** 20 | * 21 | * @author Emil Forslund 22 | * @since 1.0.0 23 | */ 24 | public interface Person { 25 | 26 | long getId(); 27 | 28 | String getFirstname(); 29 | 30 | String getLastname(); 31 | 32 | interface Builder { 33 | 34 | Builder withId(long id); 35 | 36 | Builder withFirstname(String firstname); 37 | 38 | Builder withLastname(String lastname); 39 | 40 | Person build(); 41 | 42 | } 43 | 44 | } -------------------------------------------------------------------------------- /src/test/java/com/speedment/example/PersonImpl.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | * Copyright (c) 2006-2017, Speedment, Inc. All Rights Reserved. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); You may not 6 | * use this file except in compliance with the License. You may obtain a copy of 7 | * the License at: 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 13 | * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 14 | * License for the specific language governing permissions and limitations under 15 | * the License. 16 | */ 17 | package com.speedment.example; 18 | 19 | /** 20 | * 21 | * @author Emil Forslund 22 | * @since 1.0.0 23 | */ 24 | public final class PersonImpl implements Person { 25 | 26 | private final long id; 27 | private final String firstname; 28 | private final String lastname; 29 | 30 | private PersonImpl(long id, String firstname, String lastname) { 31 | this.id = id; 32 | this.firstname = firstname; 33 | this.lastname = lastname; 34 | } 35 | 36 | @Override 37 | public long getId() { 38 | return id; 39 | } 40 | 41 | @Override 42 | public String getFirstname() { 43 | return firstname; 44 | } 45 | 46 | @Override 47 | public String getLastname() { 48 | return lastname; 49 | } 50 | 51 | public final static class Builder implements Person.Builder { 52 | 53 | private long id; 54 | private String firstname; 55 | private String lastname; 56 | 57 | @Override 58 | public Builder withId(long id) { 59 | this.id = id; 60 | return this; 61 | } 62 | 63 | @Override 64 | public Builder withFirstname(String firstname) { 65 | this.firstname = firstname; 66 | return this; 67 | } 68 | 69 | @Override 70 | public Builder withLastname(String lastname) { 71 | this.lastname = lastname; 72 | return this; 73 | } 74 | 75 | @Override 76 | public Person build() { 77 | return new PersonImpl(id, firstname, lastname); 78 | } 79 | } 80 | } --------------------------------------------------------------------------------