com.speedment.common.codegen.Transform Maven / Gradle / Ivy
Show all versions of codegen Show documentation
/**
*
* Copyright (c) 2006-2019, Speedment, Inc. All Rights Reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License"); You may not
* use this file except in compliance with the License. You may obtain a copy of
* the License at:
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations under
* the License.
*/
package com.speedment.common.codegen;
import java.util.Optional;
/**
* Transforms must have a public constructor with no parameters so that it can
* be instantiated dynamically.
*
* @author Emil Forslund
* @param the model to generate from
* @param the resulting model
* @since 2.0
*/
public interface Transform {
/**
* Transforms a model from one type to another. A reference to the current
* code generator is supplied so that intermediate generation processes can
* be initiated to resolve dependencies. The transform can choose not to
* accept a particular input and therefore return empty
.
*
* This method is not meant to be called outside the code generator. If you
* want to transform between different types, setup a {@link Generator},
* install the Transform
in the factory and call one of the
* on()
-methods in Generator
.
*
* @param gen a reference to the generator being used
* @param model the model to transform
* @return the transformed model or empty if the transformation could
* not be done for that input
*/
Optional transform(Generator gen, F model);
/**
* Returns true if this transform is or contains the specified
* transformer. This is used internally by the code generator to avoid
* circular paths.
*
* @param transformer the type of the transformer to check
* @return true if this transform is or contains the input
*/
default boolean is(Class extends Transform, ?>> transformer) {
return transformer.isAssignableFrom(getClass());
}
}