
br.com.objectos.way.code.CodeCanvasWriter Maven / Gradle / Ivy
The newest version!
/*
* Copyright 2014 Objectos, Fábrica de Software LTDA.
*
* 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 br.com.objectos.way.code;
import java.util.List;
import br.com.objectos.way.core.tmpl.mustache.MustacheObject;
import br.com.objectos.way.core.tmpl.mustache.MustacheWriter;
import com.google.common.base.Joiner;
import com.squareup.javapoet.ClassName;
import com.squareup.javapoet.JavaFile;
/**
* @author [email protected] (Marcio Endo)
*/
public abstract class CodeCanvasWriter {
protected String name;
public static CodeCanvasWriter forJavaFile(JavaFile javaFile) {
return new CodeCanvasWriterJavaPoet(javaFile);
}
public static CodeCanvasWriter forTemplate(String template) {
return new CodeCanvasWriterMustache(template);
}
public CodeCanvasArtifact toCodeCanvasArtifact() {
throw new UnsupportedOperationException();
}
public CodeCanvasArtifact toCodeCanvasArtifact(MustacheWriter writer, MustacheObject context) {
throw new UnsupportedOperationException();
}
public CodeCanvasWriter name(String name) {
this.name = name;
return this;
}
public CodeCanvasWriter named(ClassName className) {
List simpleNames = className.simpleNames();
String first = simpleNames.get(0);
Object[] rest = simpleNames.subList(1, simpleNames.size()).toArray();
name = Joiner.on('.').join(className.packageName(), first, rest);
return this;
}
public CodeCanvasWriter namedAfter(ClassInfo classInfo, String suffix) {
return classInfo.writeQualifiedNameTo(this, suffix);
}
public CodeCanvasWriter namedAfter(InterfaceInfo ifaceInfo, String suffix) {
return ifaceInfo.writeQualifiedNameTo(this, suffix);
}
public CodeCanvasWriter namedAfter(TypeInfo typeInfo, String suffix) {
return typeInfo.writeQualifiedNameTo(this, suffix);
}
public CodeCanvasWriter namedAfter(String prefix, TypeInfo typeInfo) {
return typeInfo.writeQualifiedNameTo(prefix, this);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy