/** * @return Returns the settings for the new eclipse profile. */ public static Map<String, String> getEclipseSettings() { return DefaultCodeFormatterConstants.getEclipseDefaultSettings(); }
/** * @return Returns the settings for the default profile. */ public static Map<String, String> getEclipse21Settings() { return DefaultCodeFormatterConstants.getEclipse21Settings(); }
/** * @return Returns the settings for the Java Conventions profile. */ public static Map<String, String> getJavaSettings() { return DefaultCodeFormatterConstants.getJavaConventionsSettings(); }
private void insertIntoMap(Map wrappingMap, Map indentMap, Map forceMap, Category category) { final String value= (String)fWorkingValues.get(category.key); Integer wrappingStyle; Integer indentStyle; Boolean forceWrapping; try { wrappingStyle= new Integer(DefaultCodeFormatterConstants.getWrappingStyle(value)); indentStyle= new Integer(DefaultCodeFormatterConstants.getIndentStyle(value)); forceWrapping= new Boolean(DefaultCodeFormatterConstants.getForceWrapping(value)); } catch (IllegalArgumentException e) { forceWrapping= new Boolean(false); indentStyle= new Integer(DefaultCodeFormatterConstants.INDENT_DEFAULT); wrappingStyle= new Integer(DefaultCodeFormatterConstants.WRAP_NO_SPLIT); } increaseMapEntry(wrappingMap, wrappingStyle); increaseMapEntry(indentMap, indentStyle); increaseMapEntry(forceMap, forceWrapping); }
@Override public String format(String string, int indentLevel, int[] positions, String lineSeparator) { Map newOptions = DefaultCodeFormatterConstants.getEclipse21Settings(); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_ARRAY_INITIALIZER, DefaultCodeFormatterConstants.END_OF_LINE); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION, "1");//$NON-NLS-1$ newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_PARAMETERS_IN_METHOD_DECLARATION, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_PARAMETERS_IN_CONSTRUCTOR_DECLARATION, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ALLOCATION_EXPRESSION, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_EXPLICIT_CONSTRUCTOR_CALL, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_QUALIFIED_ALLOCATION_EXPRESSION, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_THROWS_CLAUSE_IN_METHOD_DECLARATION, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_MULTIPLE_FIELDS, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_ARRAY_INITIALIZER, JavaCore.INSERT); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_OPENING_BRACE_IN_ARRAY_INITIALIZER, JavaCore.INSERT);
public ASTRewriteFormatter(NodeInfoStore placeholders, RewriteEventStore eventStore, Map options, String lineDelimiter) { this.placeholders= placeholders; this.eventStore= eventStore; this.options= options == null ? JavaCore.getOptions() : (Map) new HashMap(options); this.options.put( DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_RESOURCES_IN_TRY, DefaultCodeFormatterConstants.createAlignmentValue(true, DefaultCodeFormatterConstants.WRAP_NEXT_PER_LINE, DefaultCodeFormatterConstants.INDENT_DEFAULT)); this.lineDelimiter= lineDelimiter; this.tabWidth= IndentManipulation.getTabWidth(options); this.indentWidth= IndentManipulation.getIndentWidth(options); }
/** * Format java code for given input * * @param source source to format * @return formatted source code or original on error */ @SuppressWarnings({RAWTYPES, UNCHECKED}) public static String formatCode(final String source) { final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings(); options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_7); options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_7); options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_7); final String alignmentValue = DefaultCodeFormatterConstants.createAlignmentValue(true, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_ON_COLUMN); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUM_CONSTANTS, alignmentValue); final CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(options); final TextEdit edit = codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, source, 0, source.length(), 0, System.getProperty("line.separator")); final ASTParser parser = ASTParser.newParser(AST.JLS3); final IDocument document = new Document(source); parser.setSource(document.get().toCharArray()); try { edit.apply(document); return document.get(); } catch (BadLocationException e) { log.error("Error formatting java code", e); } return source; }
private boolean prefTernaryDeepAlign() { String option= getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_CONDITIONAL_EXPRESSION); try { return DefaultCodeFormatterConstants.getIndentStyle(option) == DefaultCodeFormatterConstants.INDENT_ON_COLUMN; } catch (IllegalArgumentException e) { // ignore and return default } return false; }
public String format(String string, int indentLevel, int[] positions, String lineSeparator) { Map newOptions = DefaultCodeFormatterConstants.getEclipse21Settings(); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_ARRAY_INITIALIZER, DefaultCodeFormatterConstants.END_OF_LINE); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION, "1");//$NON-NLS-1$ newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_PARAMETERS_IN_METHOD_DECLARATION, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_PARAMETERS_IN_CONSTRUCTOR_DECLARATION, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ALLOCATION_EXPRESSION, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_EXPLICIT_CONSTRUCTOR_CALL, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_QUALIFIED_ALLOCATION_EXPRESSION, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_THROWS_CLAUSE_IN_METHOD_DECLARATION, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_MULTIPLE_FIELDS, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_ARRAY_INITIALIZER, JavaCore.INSERT); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_OPENING_BRACE_IN_ARRAY_INITIALIZER, JavaCore.INSERT);
public ASTRewriteFormatter(NodeInfoStore placeholders, RewriteEventStore eventStore, Map options, String lineDelimiter) { this.placeholders= placeholders; this.eventStore= eventStore; this.options= options == null ? JavaCore.getOptions() : (Map) new HashMap(options); this.options.put( DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_RESOURCES_IN_TRY, DefaultCodeFormatterConstants.createAlignmentValue(true, DefaultCodeFormatterConstants.WRAP_NEXT_PER_LINE, DefaultCodeFormatterConstants.INDENT_DEFAULT)); this.lineDelimiter= lineDelimiter; this.tabWidth= IndentManipulation.getTabWidth(options); this.indentWidth= IndentManipulation.getIndentWidth(options); }
/** * Format java code for given input * * @param source source to format * @return formatted source code or original on error */ @SuppressWarnings({RAWTYPES, UNCHECKED}) public static String formatCode(final String source) { final Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings(); options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_7); options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_7); options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_7); final String alignmentValue = DefaultCodeFormatterConstants.createAlignmentValue(true, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_ON_COLUMN); options.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ENUM_CONSTANTS, alignmentValue); final CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(options); final TextEdit edit = codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, source, 0, source.length(), 0, System.getProperty("line.separator")); final ASTParser parser = ASTParser.newParser(AST.JLS3); final IDocument document = new Document(source); parser.setSource(document.get().toCharArray()); try { edit.apply(document); return document.get(); } catch (BadLocationException e) { log.error("Error formatting java code", e); } return source; }
private void insertIntoMap(Map<Object, Integer> wrappingMap, Map<Object, Integer> indentMap, Map<Object, Integer> forceMap, Category category) { final String value= fWorkingValues.get(category.key); Integer wrappingStyle; Integer indentStyle; Boolean forceWrapping; try { wrappingStyle= new Integer(DefaultCodeFormatterConstants.getWrappingStyle(value)); indentStyle= new Integer(DefaultCodeFormatterConstants.getIndentStyle(value)); forceWrapping= Boolean.valueOf(DefaultCodeFormatterConstants.getForceWrapping(value)); } catch (IllegalArgumentException e) { forceWrapping= Boolean.FALSE; indentStyle= new Integer(DefaultCodeFormatterConstants.INDENT_DEFAULT); wrappingStyle= new Integer(DefaultCodeFormatterConstants.WRAP_NO_SPLIT); } increaseMapEntry(wrappingMap, wrappingStyle); increaseMapEntry(indentMap, indentStyle); increaseMapEntry(forceMap, forceWrapping); }
private boolean prefMethodDeclDeepIndent() { String option= getCoreFormatterOption(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_PARAMETERS_IN_METHOD_DECLARATION); try { return DefaultCodeFormatterConstants.getIndentStyle(option) == DefaultCodeFormatterConstants.INDENT_ON_COLUMN; } catch (IllegalArgumentException e) { // ignore and return default } return true; }
public String format(String string, int indentLevel, int[] positions, String lineSeparator) { Map newOptions = DefaultCodeFormatterConstants.getEclipse21Settings(); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_BRACE_POSITION_FOR_ARRAY_INITIALIZER, DefaultCodeFormatterConstants.END_OF_LINE); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_CONTINUATION_INDENTATION, "1");//$NON-NLS-1$ newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_PARAMETERS_IN_METHOD_DECLARATION, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_PARAMETERS_IN_CONSTRUCTOR_DECLARATION, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_ALLOCATION_EXPRESSION, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_EXPLICIT_CONSTRUCTOR_CALL, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_METHOD_INVOCATION, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_ARGUMENTS_IN_QUALIFIED_ALLOCATION_EXPRESSION, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_THROWS_CLAUSE_IN_METHOD_DECLARATION, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_MULTIPLE_FIELDS, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION, DefaultCodeFormatterConstants.createAlignmentValue(false, DefaultCodeFormatterConstants.WRAP_ONE_PER_LINE, DefaultCodeFormatterConstants.INDENT_BY_ONE)); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_OPENING_BRACE_IN_ARRAY_INITIALIZER, JavaCore.INSERT); newOptions.put(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_AFTER_OPENING_BRACE_IN_ARRAY_INITIALIZER, JavaCore.INSERT);
public ASTRewriteFormatter(NodeInfoStore placeholders, RewriteEventStore eventStore, Map options, String lineDelimiter) { this.placeholders= placeholders; this.eventStore= eventStore; this.options= options == null ? JavaCore.getOptions() : (Map) new HashMap(options); this.options.put( DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_RESOURCES_IN_TRY, DefaultCodeFormatterConstants.createAlignmentValue(true, DefaultCodeFormatterConstants.WRAP_NEXT_PER_LINE, DefaultCodeFormatterConstants.INDENT_DEFAULT)); this.lineDelimiter= lineDelimiter; this.tabWidth= IndentManipulation.getTabWidth(options); this.indentWidth= IndentManipulation.getIndentWidth(options); }
/** * Return the options to be passed when creating {@link CodeFormatter} * instance. * * @return */ private Map<String, String> getFormattingOptions() { @SuppressWarnings("unchecked") Map<String, String> options = DefaultCodeFormatterConstants .getEclipseDefaultSettings(); options.put(JavaCore.COMPILER_SOURCE, JAVA_COMPILER_SOURCE_VERSION); options.put(JavaCore.COMPILER_COMPLIANCE, JAVA_COMPILER_COMPLIANCE_VERSION); options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JAVA_COMPILER_CODEGEN_TARGET_PLATFORM_VERSION); return options; }
/** * @return Returns the settings for the Java Conventions profile. */ public static Map getJavaSettings() { final Map options= DefaultCodeFormatterConstants.getJavaConventionsSettings(); ProfileVersioner.setLatestCompliance(options); return options; }
protected boolean valueMatches(StringMatcher matcher) { String value= getPreferences().get(getKey()); int wrappingStyle= DefaultCodeFormatterConstants.getWrappingStyle(value); MenuItem wrapStyleItem= updateMenuItem(fWrapStyleItems, wrappingStyle); if (matcher.match(wrapStyleItem.getText())) return true; if (wrappingStyle == DefaultCodeFormatterConstants.WRAP_NO_SPLIT) return false; boolean forceWrapping= DefaultCodeFormatterConstants.getForceWrapping(value); if (forceWrapping && matcher.match(fForceSplitItem.getToolTipText())) return true; MenuItem indentStyleItem= updateMenuItem(fIndentationItems, DefaultCodeFormatterConstants.getIndentStyle(value)); if (matcher.match(indentStyleItem.getText())) return true; if (fWrapBeforeKey != null) { int wrapBeforeAfterValue= WRAP_BEFORE_PREF_VALUES.indexOf(getPreferences().get(fWrapBeforeKey)); MenuItem wrapBeforeAfterItem= updateMenuItem(fWrapBeforeAfterItems, wrapBeforeAfterValue); if (matcher.match(wrapBeforeAfterItem.getText())) return true; } return false; }
/** * @return Returns the settings for the default profile. */ public static Map<String, String> getEclipse21Settings() { final Map<String, String> options= DefaultCodeFormatterConstants.getEclipse21Settings(); ProfileVersioner.setLatestCompliance(options); return options; }
private int getBinaryOperatorAlignmentStyle() { String binaryAlignmentValue= getCoreFormatterOption( DefaultCodeFormatterConstants.FORMATTER_ALIGNMENT_FOR_BINARY_EXPRESSION); return DefaultCodeFormatterConstants.getIndentStyle(binaryAlignmentValue); }