List of usage examples for org.eclipse.jdt.core.formatter CodeFormatter K_EXPRESSION
int K_EXPRESSION
To view the source code for org.eclipse.jdt.core.formatter CodeFormatter K_EXPRESSION.
Click Source Link
This kind is not applicable to module descriptions.
From source file:org.deved.antlride.integration.jdt.AntlrJavaTargetService.java
License:Open Source License
public String format(String source) { try {//ww w. java2 s . c o m @SuppressWarnings("unchecked") Map<Object, Object> options = DefaultCodeFormatterConstants.getEclipseDefaultSettings(); // initialize the compiler settings to be able to format 1.5 code options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5); options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5); options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5); final CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(options); final int[] K = { CodeFormatter.K_STATEMENTS, CodeFormatter.K_CLASS_BODY_DECLARATIONS, CodeFormatter.K_EXPRESSION }; TextEdit edit = null; for (int i = 0; i < K.length; i++) { edit = codeFormatter.format(K[i], source, 0, source.length(), 0, System.getProperty("line.separator")); if (edit != null) { // found break; } } if (edit != null) { IDocument document = new Document(source); edit.apply(document); return document.get(); } } catch (MalformedTreeException ex) { AntlrCore.error(ex); } catch (BadLocationException ex) { AntlrCore.error(ex); } return source; }
From source file:org.eclipse.jet.internal.taglib.java.JavaFormatTag.java
License:Open Source License
private int getSnippetKind(String snippetKindString, JET2Context context) { if (DEBUG)// ww w.ja v a 2s .c o m System.out.println("JavaFormatTag.getSnippetKind - value specified=" + snippetKindString); //$NON-NLS-1$ if ("K_COMPILATION_UNIT".equals(snippetKindString)) { //$NON-NLS-1$ return CodeFormatter.K_COMPILATION_UNIT + CodeFormatter.F_INCLUDE_COMMENTS; } else if ("K_CLASS_BODY_DECLARATIONS".equals(snippetKindString)) { //$NON-NLS-1$ return CodeFormatter.K_CLASS_BODY_DECLARATIONS; } else if ("K_EXPRESSION".equals(snippetKindString)) { //$NON-NLS-1$ return CodeFormatter.K_EXPRESSION; } else if ("K_STATEMENTS".equals(snippetKindString)) { //$NON-NLS-1$ return CodeFormatter.K_STATEMENTS; } if (DEBUG) System.out.println("JavaFormatTag.getSnippetKind - Falling back to K_UNKNOWN"); //$NON-NLS-1$ return CodeFormatter.K_UNKNOWN + CodeFormatter.F_INCLUDE_COMMENTS; }