Skip to content

Commit

Permalink
[JavaGenerator] Adds Utils.ln(), IGenerate now uses that method
Browse files Browse the repository at this point in the history
  • Loading branch information
joaobispo committed Jan 2, 2025
1 parent cc92875 commit 4ebb2f9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 35 deletions.
15 changes: 8 additions & 7 deletions JavaGenerator/src/org/specs/generators/java/IGenerate.java
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
/*
* Copyright 2013 SPeCS.
*
*
* 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. under the License.
*/
/**
*
*
*/
package org.specs.generators.java;

import pt.up.fe.specs.util.SpecsIo;
import org.specs.generators.java.utils.Utils;

/**
* @author Tiago
*
*
*/
public interface IGenerate {
public StringBuilder generateCode(int indentation);

default String ln() {
return SpecsIo.getNewline();
return Utils.ln();
//return SpecsIo.getNewline();
}
}
51 changes: 23 additions & 28 deletions JavaGenerator/src/org/specs/generators/java/utils/Utils.java
Original file line number Diff line number Diff line change
@@ -1,24 +1,23 @@
/*
* Copyright 2013 SPeCS.
*
*
* 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. under the License.
*/
package org.specs.generators.java.utils;

import java.io.File;

import org.specs.generators.java.IGenerate;
import org.specs.generators.java.classtypes.ClassType;

import pt.up.fe.specs.util.SpecsIo;

import java.io.File;

public class Utils {

private static final String INDENTER = " ";
Expand All @@ -27,9 +26,8 @@ public class Utils {

/**
* Returns a {@link StringBuilder} containing the desired indentation
*
* @param indentation
* the level of indentation
*
* @param indentation the level of indentation
* @return {@link StringBuilder} with indentation
*/
public static StringBuilder indent(int indentation) {
Expand All @@ -42,12 +40,10 @@ public static StringBuilder indent(int indentation) {

/**
* Generates the java class/enum/interface into the requested folder, according to the class' package
*
*
* @param outputDir
* @param java
* the class to generate and write in the output folder
* @param replace
* replace existing file?
* @param java the class to generate and write in the output folder
* @param replace replace existing file?
*/

public static boolean generateToFile(File outputDir, ClassType java, boolean replace) {
Expand All @@ -59,13 +55,10 @@ public static boolean generateToFile(File outputDir, ClassType java, boolean rep

/**
* Create the file path according to the package of the class/interface
*
* @param outputDir
* the output directory
* @param pack
* the class/interface package
* @param name
* the class/interface name
*
* @param outputDir the output directory
* @param pack the class/interface package
* @param name the class/interface name
* @return {@link File} containing the new file path
*/
private static File getFilePath(File outputDir, String pack, String name) {
Expand All @@ -83,13 +76,10 @@ private static File getFilePath(File outputDir, String pack, String name) {

/**
* Write the java code in an output file
*
* @param outputFile
* the file destiny of the code
* @param java
* the code to generate and write;
* @param replace
* replace existing file?
*
* @param outputFile the file destiny of the code
* @param java the code to generate and write;
* @param replace replace existing file?
*/
private static boolean writeToFile(File outputFile, IGenerate java, boolean replace) {
final StringBuilder generatedJava = java.generateCode(0);
Expand All @@ -110,4 +100,9 @@ public static String firstCharToUpper(String string) {
return string.substring(0, 1).toUpperCase() + string.substring(1);
}

public static String ln() {
return "\n";
//return SpecsIo.getNewline();
}

}

0 comments on commit 4ebb2f9

Please sign in to comment.