@Override public String toString() { DefaultJavaPrettyPrinter printer = new DefaultJavaPrettyPrinter(getFactory().getEnvironment()); String errorMessage = ""; try { // we do not want to compute imports of for CtImport and CtReference // as it may change the print of a reference if (!(this instanceof CtImport) && !(this instanceof CtReference)) { printer.getImportsContext().computeImports(this); } printer.scan(this); } catch (ParentNotInitializedException ignore) { LOGGER.error(ERROR_MESSAGE_TO_STRING, ignore); errorMessage = ERROR_MESSAGE_TO_STRING; } // in line-preservation mode, newlines are added at the beginning to matches the lines // removing them from the toString() representation return printer.toString().replaceFirst("^\\s+", "") + errorMessage; }
@Override public String toString() { DefaultJavaPrettyPrinter printer = new DefaultJavaPrettyPrinter( getFactory().getEnvironment()); printer.scan(this); return printer.toString(); }
protected synchronized String sourceForModelledClass(CtType<?> modelledClass) { prettyPrinter = new DefaultJavaPrettyPrinter(this.getFactory().getEnvironment()); prettyPrinter.scan(modelledClass); String sourceCode = "package " + modelledClass.getPackage().toString() + ";" + System.getProperty("line.separator") + prettyPrinter.toString(); prettyPrinter = new DefaultJavaPrettyPrinter(this.getFactory().getEnvironment()); return sourceCode; }
@Override public String toString() { DefaultJavaPrettyPrinter printer = new DefaultJavaPrettyPrinter(getFactory().getEnvironment()); String errorMessage = ""; try { printer.computeImports(this); printer.scan(this); } catch (ParentNotInitializedException ignore) { errorMessage = ERROR_MESSAGE_TO_STRING; } return printer.toString() + errorMessage; }
protected synchronized String sourceForModelledClass(CtType<?> modelledClass) { //logDebug(logger(), format("[Scanning source code of %s]", modelledClass.getQualifiedName())); prettyPrinter().scan(modelledClass); String packageDeclaration = ""; if (!modelledClass.getPackage().isUnnamedPackage()) { packageDeclaration = "package " + modelledClass.getPackage().getQualifiedName() + ";"; } String sourceCode = packageDeclaration + JavaLibrary.lineSeparator() + prettyPrinter().toString(); prettyPrinter = new DefaultJavaPrettyPrinter(spoonEnvironment()); return sourceCode; }