/** * Creates a full name for the specified class in the specified file, * suitable to be used as a TypeName. * * @param file the file to reference * @param clazz the class to reference * @return the full name of the class */ public static String nameOf(File file, ClassOrInterface<?> clazz) { String name = Formatting.fileToClassName(file.getName()) .flatMap(Formatting::packageName) .orElseThrow( () -> new RuntimeException( "File did not have appropriate name." ) ) + "." + pathTo(file, clazz.getName()); return name; }
/** * Renders the 'package'-part of the file. In java, the package should only * be present if the file is located in a directory in the sources folder. * If the file is in the global package, an empty string will be returned. * <p> * The package part will be suffixed by two new line characters if a package * was outputted. * <p> * Example: <pre>"package com.speedment.example;\n\n"</pre> * * @param file the file * @return the package part or an empty string */ private String renderPackage(File file) { final Optional<String> name = fileToClassName(file.getName()); if (name.isPresent()) { final Optional<String> pack = packageName(name.get()); if (pack.isPresent()) { return "package " + pack.get() + ";" + dnl(); } } return ""; } }
/** * Copy constructor. * * @param prototype the prototype */ protected FileImpl(File prototype) { this.name = requireNonNull(prototype).getName(); this.doc = prototype.getJavadoc().map(Copier::copy).orElse(null); this.imports = Copier.copy(prototype.getImports()); this.classes = Copier.copy(prototype.getClasses(), c -> c.copy()); }
public void writeToFile(TranslatorManager delegator, Project project, Meta<File, String> meta, boolean overwriteExisting) { events.notify(new FileGenerated(project, meta)); delegator.writeToFile(project, meta.getModel().getName(), meta.getResult(), overwriteExisting); }
@Override public Optional<String> transform(Generator gen, File model) { requireNonNulls(gen, model); final DependencyManager mgr = gen.getDependencyMgr(); mgr.clearDependencies(); final String pack = fileToClassName(model.getName()) .flatMap(Formatting::packageName) .orElse(""); mgr.setCurrentPackage(pack); final Optional<String> view = Optional.of( renderJavadoc(gen, model) + renderPackage(model) + renderImports(gen, model) + renderClasses(gen, model) ); mgr.unsetCurrentPackage(pack); return view; }
@Override public Label createNode() { final Label label = new Label(""); events.on(BeforeGenerate.class, bg -> runLater(() -> label.setText("Generating..."))); events.on(FileGenerated.class, fg -> runLater(() -> label.setText(fg.meta().getModel().getName()))); events.on(AfterGenerate.class, ag -> runLater(() -> label.setText(""))); return label; }
/** * Creates a full name for the specified class in the specified file, * suitable to be used as a TypeName. * * @param file the file to reference * @param clazz the class to reference * @return the full name of the class */ public static String nameOf(File file, ClassOrInterface<?> clazz) { String name = Formatting.fileToClassName(file.getName()) .flatMap(Formatting::packageName) .orElseThrow( () -> new RuntimeException( "File did not have appropriate name." ) ) + "." + pathTo(file, clazz.getName()); return name; }
/** * Creates a full name for the specified class in the specified file, * suitable to be used as a TypeName. * * @param file the file to reference * @param clazz the class to reference * @return the full name of the class */ public static String nameOf(File file, ClassOrInterface<?> clazz) { String name = Formatting.fileToClassName(file.getName()) .flatMap(Formatting::packageName) .orElseThrow( () -> new RuntimeException( "File did not have appropriate name." ) ) + "." + pathTo(file, clazz.getName()); return name; }
/** * Renders the 'package'-part of the file. In java, the package should only * be present if the file is located in a directory in the sources folder. * If the file is in the global package, an empty string will be returned. * <p> * The package part will be suffixed by two new line characters if a package * was outputted. * <p> * Example: <pre>"package com.speedment.example;\n\n"</pre> * * @param file the file * @return the package part or an empty string */ private String renderPackage(File file) { final Optional<String> name = fileToClassName(file.getName()); if (name.isPresent()) { final Optional<String> pack = packageName(name.get()); if (pack.isPresent()) { return "package " + pack.get() + ";" + dnl(); } } return ""; } }
/** * Renders the 'package'-part of the file. In java, the package should only * be present if the file is located in a directory in the sources folder. * If the file is in the global package, an empty string will be returned. * <p> * The package part will be suffixed by two new line characters if a package * was outputted. * <p> * Example: <pre>"package com.speedment.example;\n\n"</pre> * * @param file the file * @return the package part or an empty string */ private String renderPackage(File file) { final Optional<String> name = fileToClassName(file.getName()); if (name.isPresent()) { final Optional<String> pack = packageName(name.get()); if (pack.isPresent()) { return "package " + pack.get() + ";" + dnl(); } } return ""; } }
/** * Copy constructor. * * @param prototype the prototype */ protected FileImpl(File prototype) { this.name = requireNonNull(prototype).getName(); this.doc = prototype.getJavadoc().map(Copier::copy).orElse(null); this.imports = Copier.copy(prototype.getImports()); this.classes = Copier.copy(prototype.getClasses(), c -> c.copy()); }
/** * Copy constructor. * * @param prototype the prototype */ protected FileImpl(File prototype) { this.name = requireNonNull(prototype).getName(); this.doc = prototype.getJavadoc().map(Copier::copy).orElse(null); this.imports = Copier.copy(prototype.getImports()); this.classes = Copier.copy(prototype.getClasses(), c -> c.copy()); }
public void writeToFile(TranslatorManager delegator, Project project, Meta<File, String> meta, boolean overwriteExisting) { events.notify(new FileGenerated(project, meta)); delegator.writeToFile(project, meta.getModel().getName(), meta.getResult(), overwriteExisting); }
@Override public Optional<String> transform(Generator gen, File model) { requireNonNulls(gen, model); final DependencyManager mgr = gen.getDependencyMgr(); mgr.clearDependencies(); final String pack = fileToClassName(model.getName()) .flatMap(Formatting::packageName) .orElse(""); mgr.setCurrentPackage(pack); final Optional<String> view = Optional.of( renderJavadoc(gen, model) + renderPackage(model) + renderImports(gen, model) + renderClasses(gen, model) ); mgr.unsetCurrentPackage(pack); return view; }
@Override public Optional<String> transform(Generator gen, File model) { requireNonNulls(gen, model); final DependencyManager mgr = gen.getDependencyMgr(); mgr.clearDependencies(); final String pack = fileToClassName(model.getName()) .flatMap(Formatting::packageName) .orElse(""); mgr.setCurrentPackage(pack); final Optional<String> view = Optional.of( renderJavadoc(gen, model) + renderPackage(model) + renderImports(gen, model) + renderClasses(gen, model) ); mgr.unsetCurrentPackage(pack); return view; }