diff options
| author | Jesper S Moller | 2013-03-20 01:18:21 +0000 |
|---|---|---|
| committer | ssankaran | 2013-03-20 01:18:21 +0000 |
| commit | 9617178877607b049b1a7c4f92c93a8d11facd28 (patch) | |
| tree | 171d7515ba7ffbaf65d806327fa80073b67f37e2 | |
| parent | cf072eeff121940a541295553114f490c9a9bb69 (diff) | |
| download | eclipse.jdt.core-9617178877607b049b1a7c4f92c93a8d11facd28.tar.gz eclipse.jdt.core-9617178877607b049b1a7c4f92c93a8d11facd28.tar.xz eclipse.jdt.core-9617178877607b049b1a7c4f92c93a8d11facd28.zip | |
Fixed Bug 402892 - [1.8][formatter] Code formatter should understand
type annotations
9 files changed, 695 insertions, 208 deletions
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava8Tests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava8Tests.java index cd1112eb44..3bd54f6e8c 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava8Tests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunAllJava8Tests.java @@ -44,6 +44,7 @@ import org.eclipse.jdt.core.tests.dom.ASTConverterBugsTestJLS8; import org.eclipse.jdt.core.tests.dom.ASTConverterTestAST8_2; import org.eclipse.jdt.core.tests.dom.ConverterTestSetup; import org.eclipse.jdt.core.tests.dom.TypeAnnotationsConverterTest; +import org.eclipse.jdt.core.tests.formatter.FormatterJSR308Tests; import org.eclipse.jdt.core.tests.formatter.FormatterJSR335Tests; import org.eclipse.jdt.core.tests.rewrite.describing.ASTRewritingTest; @@ -67,6 +68,7 @@ public class RunAllJava8Tests extends TestCase { ExpressionContextTests.class, FlowAnalysisTest8.class, FormatterJSR335Tests.class, + FormatterJSR308Tests.class, }; } diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunFormatterTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunFormatterTests.java index 20da4d9149..e8e6aba074 100644 --- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunFormatterTests.java +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunFormatterTests.java @@ -12,6 +12,7 @@ * Contributors: * IBM Corporation - initial API and implementation * Jesper S Moller - Contribution for bug 402173 + * Contribution for bug 402892 *******************************************************************************/ package org.eclipse.jdt.core.tests; @@ -37,6 +38,7 @@ public class RunFormatterTests extends junit.framework.TestCase { TEST_SUITES.add(FormatterCommentsBugsTest.class); TEST_SUITES.add(FormatterCommentsTests.class); TEST_SUITES.add(FormatterJSR335Tests.class); + TEST_SUITES.add(FormatterJSR308Tests.class); TEST_SUITES.add(FormatterCommentsClearBlankLinesTests.class); TEST_SUITES.add(FormatterJavadocDontIndentTagsTests.class); TEST_SUITES.add(FormatterJavadocDontIndentTagsDescriptionTests.class); diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterJSR308Tests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterJSR308Tests.java new file mode 100644 index 0000000000..fda1a6fdde --- /dev/null +++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterJSR308Tests.java @@ -0,0 +1,351 @@ +/******************************************************************************* + * Copyright (c) 2013 Jesper Steen Moller and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * + * Contributors: + * Jesper Steen Moller - initial API and implementation */ + +package org.eclipse.jdt.core.tests.formatter; + +import java.util.Map; + +import junit.framework.Test; + +import org.eclipse.core.resources.IWorkspaceDescription; +import org.eclipse.jdt.core.ICompilationUnit; +import org.eclipse.jdt.core.IJavaProject; +import org.eclipse.jdt.core.JavaModelException; +import org.eclipse.jdt.core.formatter.CodeFormatter; +import org.eclipse.jdt.core.tests.model.AbstractJavaModelTests; +import org.eclipse.jdt.core.tests.util.Util; +import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; +import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter; +import org.eclipse.jdt.internal.formatter.DefaultCodeFormatterOptions; +import org.eclipse.text.edits.TextEdit; + +public class FormatterJSR308Tests extends AbstractJavaModelTests { + + protected static IJavaProject JAVA_PROJECT; + + public static final int UNKNOWN_KIND = 0; + public static final String IN = "_in"; + public static final String OUT = "_out"; + public static final boolean DEBUG = false; + static final String LINE_SEPARATOR = System.getProperty("line.separator"); + private static final String PROJECT_NAME = "FormatterJSR308"; + private long time; + + DefaultCodeFormatterOptions formatterPrefs; + Map formatterOptions; + + static { +// TESTS_NUMBERS = new int[] { 783 }; +// TESTS_RANGE = new int[] { 734, -1 }; +// TESTS_NAMES = new String [] { "test015" }; + } + public static Test suite() { + return buildModelTestSuite(FormatterJSR308Tests.class); + } + + public FormatterJSR308Tests(String name) { + super(name); + } + + String runFormatter(CodeFormatter codeFormatter, String source, int kind, int indentationLevel, int offset, int length, String lineSeparator, boolean repeat) { +// long time = System.currentTimeMillis(); + TextEdit edit = codeFormatter.format(kind, source, offset, length, indentationLevel, lineSeparator);//$NON-NLS-1$ +// System.out.println((System.currentTimeMillis() - time) + " ms"); + if (edit == null) return null; +// System.out.println(edit.getChildrenSize() + " edits"); + String result = org.eclipse.jdt.internal.core.util.Util.editedString(source, edit); + + if (repeat && length == source.length()) { +// time = System.currentTimeMillis(); + edit = codeFormatter.format(kind, result, 0, result.length(), indentationLevel, lineSeparator);//$NON-NLS-1$ +// System.out.println((System.currentTimeMillis() - time) + " ms"); + if (edit == null) return null; +// assertEquals("Should not have edits", 0, edit.getChildren().length); + final String result2 = org.eclipse.jdt.internal.core.util.Util.editedString(result, edit); + if (!result.equals(result2)) { + assertSourceEquals("Second formatting is different from first one!", Util.convertToIndependantLineDelimiter(result), Util.convertToIndependantLineDelimiter(result2)); + } + } + return result; + } + + /** + * Init formatter preferences with Eclipse default settings. + */ + protected void setUp() throws Exception { + super.setUp(); + this.formatterPrefs = DefaultCodeFormatterOptions.getEclipseDefaultSettings(); + if (JAVA_PROJECT != null) { + this.formatterOptions = JAVA_PROJECT.getOptions(true); + } + this.formatterOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_8); + this.formatterOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_8); + this.formatterOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_8); + } + + /** + * Create project and set the jar placeholder. + */ + public void setUpSuite() throws Exception { + // ensure autobuilding is turned off + IWorkspaceDescription description = getWorkspace().getDescription(); + if (description.isAutoBuilding()) { + description.setAutoBuilding(false); + getWorkspace().setDescription(description); + } + + if (JAVA_PROJECT == null) { + JAVA_PROJECT = setUpJavaProject(PROJECT_NAME, "1.8"); //$NON-NLS-1$ + } + + if (DEBUG) { + this.time = System.currentTimeMillis(); + } + } + + /** + * Reset the jar placeholder and delete project. + */ + public void tearDownSuite() throws Exception { + deleteProject(JAVA_PROJECT); //$NON-NLS-1$ + JAVA_PROJECT = null; + if (DEBUG) { + System.out.println("Time spent = " + (System.currentTimeMillis() - this.time));//$NON-NLS-1$ + } + super.tearDownSuite(); + } + + private String getIn(String compilationUnitName) { + assertNotNull(compilationUnitName); + int dotIndex = compilationUnitName.indexOf('.'); + assertTrue(dotIndex != -1); + return compilationUnitName.substring(0, dotIndex) + IN + compilationUnitName.substring(dotIndex); + } + + private String getOut(String compilationUnitName) { + assertNotNull(compilationUnitName); + int dotIndex = compilationUnitName.indexOf('.'); + assertTrue(dotIndex != -1); + return compilationUnitName.substring(0, dotIndex) + OUT + compilationUnitName.substring(dotIndex); + } + + void assertLineEquals(String actualContents, String originalSource, String expectedContents, boolean checkNull) { + if (actualContents == null) { + assertTrue("actualContents is null", checkNull); + assertEquals(expectedContents, originalSource); + return; + } + assertSourceEquals("Different number of length", Util.convertToIndependantLineDelimiter(expectedContents), actualContents); + } + + private void runTest(String packageName, String compilationUnitName) { + DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(this.formatterPrefs, this.formatterOptions); + runTest(codeFormatter, packageName, compilationUnitName, CodeFormatter.K_COMPILATION_UNIT, 0); + } + + private void runTest(CodeFormatter codeFormatter, String packageName, String compilationUnitName, int kind, int indentationLevel) { + runTest(codeFormatter, packageName, compilationUnitName, kind, indentationLevel, false, 0, -1); + } + private void runTest(CodeFormatter codeFormatter, String packageName, String compilationUnitName, int kind, int indentationLevel, boolean checkNull, int offset, int length) { + runTest(codeFormatter, packageName, compilationUnitName, kind, indentationLevel, checkNull, offset, length, null); + } + + private void runTest(CodeFormatter codeFormatter, String packageName, String compilationUnitName, int kind, int indentationLevel, boolean checkNull, int offset, int length, String lineSeparator) { + try { + ICompilationUnit sourceUnit = getCompilationUnit(PROJECT_NAME , "", packageName, getIn(compilationUnitName)); //$NON-NLS-1$ //$NON-NLS-2$ + String source = sourceUnit.getSource(); + assertNotNull(source); + ICompilationUnit outputUnit = getCompilationUnit(PROJECT_NAME , "", packageName, getOut(compilationUnitName)); //$NON-NLS-1$ //$NON-NLS-2$ + assertNotNull(outputUnit); + String result; + if (length == -1) { + result = runFormatter(codeFormatter, source, kind, indentationLevel, offset, source.length(), lineSeparator, true); + } else { + result = runFormatter(codeFormatter, source, kind, indentationLevel, offset, length, lineSeparator, true); + } + assertLineEquals(result, source, outputUnit.getSource(), checkNull); + } catch (JavaModelException e) { + e.printStackTrace(); + assertTrue(false); + } + } + + public void testLambda() { + runTest("testLambda", "A.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void testReferenceExpression() { + runTest("testReferenceExpression", "A.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test000() { + runTest("test000", "I.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test001() { + runTest("test001", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test002() { + runTest("test002", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test003() { + runTest("test003", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test004() { + runTest("test004", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test005() { + runTest("test005", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test006() { + runTest("test006", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test007() { + runTest("test007", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test008() { + runTest("test008", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test009() { + runTest("test009", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test010() { + runTest("test010", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test011() { + runTest("test011", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test012() { + runTest("test012", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test013() { + runTest("test013", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test014() { + runTest("test014", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test015() { + runTest("test015", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test016() { + runTest("test016", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test017() { + runTest("test017", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test018() { + runTest("test018", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test019() { + runTest("test019", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test020() { + runTest("test020", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test021() { + runTest("test021", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test022() { + runTest("test022", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test023() { + runTest("test023", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test024() { + runTest("test024", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test025() { + runTest("test025", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test026() { + runTest("test026", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test027() { + runTest("test027", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test028() { + runTest("test028", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test029() { + runTest("test029", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test030() { + runTest("test030", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test031() { + runTest("test031", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test032() { + runTest("test032", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test033() { + runTest("test033", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test034() { + runTest("test034", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test035() { + runTest("test035", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test036() { + runTest("test036", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test037() { + runTest("test037", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test038() { + runTest("test038", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } + + public void test039() { + runTest("test039", "X.java");//$NON-NLS-1$ //$NON-NLS-2$ + } +}
\ No newline at end of file diff --git a/org.eclipse.jdt.core.tests.model/workspace/FormatterJSR308/testLambda/A_in.java b/org.eclipse.jdt.core.tests.model/workspace/FormatterJSR308/testLambda/A_in.java new file mode 100644 index 0000000000..39744d7a62 --- /dev/null +++ b/org.eclipse.jdt.core.tests.model/workspace/FormatterJSR308/testLambda/A_in.java @@ -0,0 +1,44 @@ +/** + * Test + * + */ +package p1.p2.test; + +import java.io.Serializable; +import java.io.IOException; + +public abstract class A extends java.lang.Object implements Runnable, Cloneable, Serializable { + public void run() { + } + + public void lambdas() { + Runnable a = () -> { + thisIsCrazy(); + iJustMet(you); + here.number.callMe(); + }; + + Func idA = x -> x; + + Func idB = x -> { return x; }; + + Func idC = x -> x; + + Func id2 = x -> { + if (x == null) + { + return null; + } + else + return x; + }; + + ImaginableFunction<String, Integer> f = + (String input) -> input.length(); + + ImaginableFunction<String, Integer> f2 = (String input) -> { return input.length() + new LetsPretend() { int howMany() { return 42; } } + +.howMany(); }; + } + +}
\ No newline at end of file diff --git a/org.eclipse.jdt.core.tests.model/workspace/FormatterJSR308/testLambda/A_out.java b/org.eclipse.jdt.core.tests.model/workspace/FormatterJSR308/testLambda/A_out.java new file mode 100644 index 0000000000..1bcd7c3422 --- /dev/null +++ b/org.eclipse.jdt.core.tests.model/workspace/FormatterJSR308/testLambda/A_out.java @@ -0,0 +1,51 @@ +/** + * Test + * + */ +package p1.p2.test; + +import java.io.Serializable; +import java.io.IOException; + +public abstract class A extends java.lang.Object implements Runnable, + Cloneable, Serializable { + public void run() { + } + + public void lambdas() { + Runnable a = () -> { + thisIsCrazy(); + iJustMet(you); + here.number.callMe(); + }; + + Func idA = x -> x; + + Func idB = x -> { + return x; + }; + + Func idC = x -> x; + + Func id2 = x -> { + if (x == null) { + return null; + } else + return x; + }; + + ImaginableFunction<String, Integer> f = (String input) -> input + .length(); + + ImaginableFunction<String, Integer> f2 = (String input) -> { + return input.length() + new LetsPretend() { + int howMany() { + return 42; + } + } + + .howMany(); + }; + } + +}
\ No newline at end of file diff --git a/org.eclipse.jdt.core.tests.model/workspace/FormatterJSR308/testReferenceExpression/A_in.java b/org.eclipse.jdt.core.tests.model/workspace/FormatterJSR308/testReferenceExpression/A_in.java new file mode 100644 index 0000000000..4499467645 --- /dev/null +++ b/org.eclipse.jdt.core.tests.model/workspace/FormatterJSR308/testReferenceExpression/A_in.java @@ -0,0 +1,21 @@ +/** + * Test + * + */ +package p1.p2.test; + +import java.io.Serializable; +import java.io.IOException; + +public abstract class A extends java.lang.Object implements Runnable, Cloneable, Serializable { + public void run() { + } + + private static final Functionalish<List<Integer>, Integer> WHATEVER = List< Integer > :: size ; + + public void referenceExpression() { + ImaginableFunction<String, Integer> func = Klazz + :: method; + } + +}
\ No newline at end of file diff --git a/org.eclipse.jdt.core.tests.model/workspace/FormatterJSR308/testReferenceExpression/A_out.java b/org.eclipse.jdt.core.tests.model/workspace/FormatterJSR308/testReferenceExpression/A_out.java new file mode 100644 index 0000000000..2652404a61 --- /dev/null +++ b/org.eclipse.jdt.core.tests.model/workspace/FormatterJSR308/testReferenceExpression/A_out.java @@ -0,0 +1,21 @@ +/** + * Test + * + */ +package p1.p2.test; + +import java.io.Serializable; +import java.io.IOException; + +public abstract class A extends java.lang.Object implements Runnable, + Cloneable, Serializable { + public void run() { + } + + private static final Functionalish<List<Integer>, Integer> WHATEVER = List<Integer>::size; + + public void referenceExpression() { + ImaginableFunction<String, Integer> func = Klazz::method; + } + +}
\ No newline at end of file diff --git a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java index f79cafcaed..5c0433e17d 100644 --- a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java +++ b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/CodeFormatterVisitor.java @@ -15,6 +15,7 @@ * Nanda Firdausi - Contribution for bug 298844 * Jesper S Moller - Contribution for bug 402173 * Contribution for bug 402174 + * Contribution for bug 402892 *******************************************************************************/ package org.eclipse.jdt.internal.formatter; @@ -32,6 +33,7 @@ import org.eclipse.jdt.internal.compiler.ast.ASTNode; import org.eclipse.jdt.internal.compiler.ast.AbstractMethodDeclaration; import org.eclipse.jdt.internal.compiler.ast.AbstractVariableDeclaration; import org.eclipse.jdt.internal.compiler.ast.AllocationExpression; +import org.eclipse.jdt.internal.compiler.ast.Annotation; import org.eclipse.jdt.internal.compiler.ast.AnnotationMethodDeclaration; import org.eclipse.jdt.internal.compiler.ast.Argument; import org.eclipse.jdt.internal.compiler.ast.ArrayAllocationExpression; @@ -634,16 +636,7 @@ public class CodeFormatterVisitor extends ASTVisitor { this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier, true); - /* - * Check for extra dimensions - */ - int extraDimensions = getDimensions(); - if (extraDimensions != 0) { - for (int i = 0; i < extraDimensions; i++) { - this.scribe.printNextToken(TerminalTokens.TokenNameLBRACKET); - this.scribe.printNextToken(TerminalTokens.TokenNameRBRACKET); - } - } + formatExtraDimensions(fieldDeclaration.type); /* * Field initialization @@ -686,6 +679,43 @@ public class CodeFormatterVisitor extends ASTVisitor { } } + private void formatExtraDimensions(TypeReference typeReference) { + /* + * Check for extra dimensions + */ + int extraDimensions = getDimensions(); + if (extraDimensions != 0) { + int anchor = typeReference != null ? (typeReference.dimensions() - extraDimensions) : 0; + formatDimensions(typeReference, anchor, extraDimensions, true); + } + } + + private void formatLeadingDimensions(TypeReference typeReference, boolean spaceBeforeAnnotation) { + int leadingDimensions = Math.min(getDimensions(), typeReference != null ? typeReference.dimensions() : 0); + if (leadingDimensions != 0) formatDimensions(typeReference, 0, leadingDimensions, spaceBeforeAnnotation); + } + + private void formatDimensions(TypeReference typeReference, int anchor, int count, boolean spaceBeforeAnnotation) { + if (count != 0) { + if (this.preferences.insert_space_before_opening_bracket_in_array_type_reference) { + this.scribe.space(); + } + Annotation[][] annotationsOnDimensions = typeReference != null ? typeReference.getAnnotationsOnDimensions() : null; + for (int i = 0; i < count; i++) { + int dimensionIndex = anchor + i; + if (annotationsOnDimensions != null && annotationsOnDimensions.length > dimensionIndex) { + boolean hadAnnotations = formatInlineAnnotations(annotationsOnDimensions[dimensionIndex], spaceBeforeAnnotation && i == 0); + if (hadAnnotations && this.preferences.insert_space_before_opening_bracket_in_array_type_reference) this.scribe.space(); + } + this.scribe.printNextToken(TerminalTokens.TokenNameLBRACKET); + if (this.preferences.insert_space_between_brackets_in_array_type_reference) { + this.scribe.space(); + } + this.scribe.printNextToken(TerminalTokens.TokenNameRBRACKET); + } + } + } + private void format(ImportReference importRef, boolean isLast) { this.scribe.printNextToken(TerminalTokens.TokenNameimport); if (!isLast) this.scribe.blank_lines_between_import_groups = this.preferences.blank_lines_between_import_groups; @@ -763,16 +793,7 @@ public class CodeFormatterVisitor extends ASTVisitor { this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier, false); } - /* - * Check for extra dimensions - */ - int extraDimensions = getDimensions(); - if (extraDimensions != 0) { - for (int index = 0; index < extraDimensions; index++) { - this.scribe.printNextToken(TerminalTokens.TokenNameLBRACKET); - this.scribe.printNextToken(TerminalTokens.TokenNameRBRACKET); - } - } + formatExtraDimensions(fieldDeclaration.type); /* * Field initialization @@ -1677,16 +1698,7 @@ public class CodeFormatterVisitor extends ASTVisitor { */ this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier, false); } - /* - * Check for extra dimensions - */ - int extraDimensions = getDimensions(); - if (extraDimensions != 0) { - for (int index = 0; index < extraDimensions; index++) { - this.scribe.printNextToken(TerminalTokens.TokenNameLBRACKET); - this.scribe.printNextToken(TerminalTokens.TokenNameRBRACKET); - } - } + formatExtraDimensions(localDeclaration.type); final Expression initialization = localDeclaration.initialization; if (initialization != null) { @@ -2348,6 +2360,9 @@ public class CodeFormatterVisitor extends ASTVisitor { dimensions++; balance--; break; + case TerminalTokens.TokenNameAT : + skipPastTypeAnnotations(); + break; case TerminalTokens.TokenNameCOMMENT_BLOCK : case TerminalTokens.TokenNameCOMMENT_JAVADOC : case TerminalTokens.TokenNameCOMMENT_LINE : @@ -2368,6 +2383,40 @@ public class CodeFormatterVisitor extends ASTVisitor { return 0; } + private void skipPastTypeAnnotations() { // we get here having seen @ + int balance = 0; + int currentTokenStartPosition = this.localScanner.currentPosition; + try { + loop: while (true) { + currentTokenStartPosition = this.localScanner.currentPosition; + int token = this.localScanner.getNextToken(); + switch(token) { + case TerminalTokens.TokenNameEOF: + break loop; + case TerminalTokens.TokenNameIdentifier : + case TerminalTokens.TokenNameDOT : + case TerminalTokens.TokenNameCOMMENT_BLOCK : + case TerminalTokens.TokenNameCOMMENT_JAVADOC : + case TerminalTokens.TokenNameCOMMENT_LINE : + break; + case TerminalTokens.TokenNameLPAREN: + balance++; + break; + case TerminalTokens.TokenNameRPAREN: + --balance; + break; + default: + if (balance <= 0) + break loop; + } + } + } catch(InvalidInputException e) { + // ignore + } finally { + this.localScanner.resetTo(currentTokenStartPosition, this.scribe.scannerEndPosition - 1); + } + } + private boolean hasComments() { this.localScanner.resetTo(this.scribe.scanner.startPosition, this.scribe.scannerEndPosition - 1); @@ -2406,6 +2455,17 @@ public class CodeFormatterVisitor extends ASTVisitor { return false; } + private boolean isNextTokenPunctuation() { + this.localScanner.resetTo(this.scribe.scanner.currentPosition, this.scribe.scannerEndPosition - 1); + try { + int token = this.localScanner.getNextToken(); + return !(Scanner.isLiteral(token) || Scanner.isKeyword(token) || Scanner.isIdentifier(token)); + } catch(InvalidInputException e) { + // ignore + } + return false; + } + private boolean isClosingGenericToken() { this.localScanner.resetTo(this.scribe.scanner.currentPosition, this.scribe.scannerEndPosition - 1); try { @@ -2624,8 +2684,14 @@ public class CodeFormatterVisitor extends ASTVisitor { */ int extraDimensions = annotationTypeMemberDeclaration.extendedDimensions; if (extraDimensions != 0) { + if (this.preferences.insert_space_before_opening_bracket_in_array_type_reference) { + this.scribe.space(); + } for (int i = 0; i < extraDimensions; i++) { this.scribe.printNextToken(TerminalTokens.TokenNameLBRACKET); + if (this.preferences.insert_space_between_brackets_in_array_type_reference) { + this.scribe.space(); + } this.scribe.printNextToken(TerminalTokens.TokenNameRBRACKET); } } @@ -2655,8 +2721,9 @@ public class CodeFormatterVisitor extends ASTVisitor { /* * Argument type */ - if (argument.type != null) { - if (argument.type instanceof UnionTypeReference) { + TypeReference argumentType = argument.type; + if (argumentType != null) { + if (argumentType instanceof UnionTypeReference) { formatMultiCatchArguments( argument, this.preferences.insert_space_before_binary_operator, @@ -2664,11 +2731,18 @@ public class CodeFormatterVisitor extends ASTVisitor { this.preferences.alignment_for_union_type_in_multicatch, scope); } else { - argument.type.traverse(this, scope); + argumentType.traverse(this, scope); } } if (argument.isVarArgs()) { + Annotation [][] annotationsOnDimensions = argumentType.getAnnotationsOnDimensions(); + if (annotationsOnDimensions != null) { + Annotation [] varargAnnotations = annotationsOnDimensions[annotationsOnDimensions.length - 1]; + if (varargAnnotations != null) { + formatInlineAnnotations(varargAnnotations, true); + } + } this.scribe.printNextToken(TerminalTokens.TokenNameELLIPSIS, this.preferences.insert_space_before_ellipsis); if (this.preferences.insert_space_after_ellipsis) { this.scribe.space(); @@ -2681,18 +2755,7 @@ public class CodeFormatterVisitor extends ASTVisitor { this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier, argument.type != null); } - - /* - * Check for extra dimensions - */ - int extraDimensions = getDimensions(); - if (extraDimensions != 0) { - for (int i = 0; i < extraDimensions; i++) { - this.scribe.printNextToken(TerminalTokens.TokenNameLBRACKET); - this.scribe.printNextToken(TerminalTokens.TokenNameRBRACKET); - } - } - + formatExtraDimensions(argumentType); return false; } @@ -2714,6 +2777,9 @@ public class CodeFormatterVisitor extends ASTVisitor { final Expression[] dimensions = arrayAllocationExpression.dimensions; int dimensionsLength = dimensions.length; for (int i = 0; i < dimensionsLength; i++) { + if (arrayAllocationExpression.annotationsOnDimensions != null) { + formatInlineAnnotations(arrayAllocationExpression.annotationsOnDimensions[i], i == 0); + } if (this.preferences.insert_space_before_opening_bracket_in_array_allocation_expression) { this.scribe.space(); } @@ -2896,6 +2962,18 @@ public class CodeFormatterVisitor extends ASTVisitor { return false; } + private void formatArrayQualifiedTypeReference(ArrayQualifiedTypeReference arrayQualifiedTypeReference) { + final int numberOfParens = (arrayQualifiedTypeReference.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT; + if (numberOfParens > 0) { + manageOpeningParenthesizedExpression(arrayQualifiedTypeReference, numberOfParens); + } + formatQualifiedTypeReference(arrayQualifiedTypeReference); + formatLeadingDimensions(arrayQualifiedTypeReference, true); + if (numberOfParens > 0) { + manageClosingParenthesizedExpression(arrayQualifiedTypeReference, numberOfParens); + } + } + /** * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.ArrayQualifiedTypeReference, org.eclipse.jdt.internal.compiler.lookup.BlockScope) */ @@ -2903,21 +2981,7 @@ public class CodeFormatterVisitor extends ASTVisitor { ArrayQualifiedTypeReference arrayQualifiedTypeReference, BlockScope scope) { - final int numberOfParens = (arrayQualifiedTypeReference.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT; - if (numberOfParens > 0) { - manageOpeningParenthesizedExpression(arrayQualifiedTypeReference, numberOfParens); - } - this.scribe.printArrayQualifiedReference(arrayQualifiedTypeReference.tokens.length, arrayQualifiedTypeReference.sourceEnd); - int dimensions = getDimensions(); - if (dimensions != 0) { - for (int i = 0; i < dimensions; i++) { - this.scribe.printNextToken(TerminalTokens.TokenNameLBRACKET); - this.scribe.printNextToken(TerminalTokens.TokenNameRBRACKET); - } - } - if (numberOfParens > 0) { - manageClosingParenthesizedExpression(arrayQualifiedTypeReference, numberOfParens); - } + formatArrayQualifiedTypeReference(arrayQualifiedTypeReference); return false; } @@ -2928,21 +2992,7 @@ public class CodeFormatterVisitor extends ASTVisitor { ArrayQualifiedTypeReference arrayQualifiedTypeReference, ClassScope scope) { - final int numberOfParens = (arrayQualifiedTypeReference.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT; - if (numberOfParens > 0) { - manageOpeningParenthesizedExpression(arrayQualifiedTypeReference, numberOfParens); - } - this.scribe.printArrayQualifiedReference(arrayQualifiedTypeReference.tokens.length, arrayQualifiedTypeReference.sourceEnd); - int dimensions = getDimensions(); - if (dimensions != 0) { - for (int i = 0; i < dimensions; i++) { - this.scribe.printNextToken(TerminalTokens.TokenNameLBRACKET); - this.scribe.printNextToken(TerminalTokens.TokenNameRBRACKET); - } - } - if (numberOfParens > 0) { - manageClosingParenthesizedExpression(arrayQualifiedTypeReference, numberOfParens); - } + formatArrayQualifiedTypeReference(arrayQualifiedTypeReference); return false; } @@ -2981,20 +3031,14 @@ public class CodeFormatterVisitor extends ASTVisitor { if (numberOfParens > 0) { manageOpeningParenthesizedExpression(arrayTypeReference, numberOfParens); } + if (arrayTypeReference.annotations != null) { + formatInlineAnnotations(arrayTypeReference.annotations[0], false); + } this.scribe.printNextToken(SINGLETYPEREFERENCE_EXPECTEDTOKENS); int dimensions = getDimensions(); if (dimensions != 0) { - if (this.preferences.insert_space_before_opening_bracket_in_array_type_reference) { - this.scribe.space(); - } - for (int i = 0; i < dimensions; i++) { - this.scribe.printNextToken(TerminalTokens.TokenNameLBRACKET); - if (this.preferences.insert_space_between_brackets_in_array_type_reference) { - this.scribe.space(); - } - this.scribe.printNextToken(TerminalTokens.TokenNameRBRACKET); - } + formatDimensions(arrayTypeReference, 0, dimensions, true); } if (numberOfParens > 0) { manageClosingParenthesizedExpression(arrayTypeReference, numberOfParens); @@ -3013,19 +3057,13 @@ public class CodeFormatterVisitor extends ASTVisitor { if (numberOfParens > 0) { manageOpeningParenthesizedExpression(arrayTypeReference, numberOfParens); } + if (arrayTypeReference.annotations != null) { + formatInlineAnnotations(arrayTypeReference.annotations[0], false); + } this.scribe.printNextToken(SINGLETYPEREFERENCE_EXPECTEDTOKENS); int dimensions = getDimensions(); if (dimensions != 0) { - if (this.preferences.insert_space_before_opening_bracket_in_array_type_reference) { - this.scribe.space(); - } - for (int i = 0; i < dimensions; i++) { - this.scribe.printNextToken(TerminalTokens.TokenNameLBRACKET); - if (this.preferences.insert_space_between_brackets_in_array_type_reference) { - this.scribe.space(); - } - this.scribe.printNextToken(TerminalTokens.TokenNameRBRACKET); - } + formatDimensions(arrayTypeReference, 0, dimensions, true); } if (numberOfParens > 0) { manageClosingParenthesizedExpression(arrayTypeReference, numberOfParens); @@ -4520,16 +4558,7 @@ public class CodeFormatterVisitor extends ASTVisitor { this.preferences.insert_space_after_comma_in_method_declaration_parameters, this.preferences.alignment_for_parameters_in_method_declaration); - /* - * Check for extra dimensions - */ - int extraDimensions = getDimensions(); - if (extraDimensions != 0) { - for (int i = 0; i < extraDimensions; i++) { - this.scribe.printNextToken(TerminalTokens.TokenNameLBRACKET); - this.scribe.printNextToken(TerminalTokens.TokenNameRBRACKET); - } - } + formatExtraDimensions(methodDeclaration.returnType); // Format throws formatThrowsClause( @@ -4668,6 +4697,9 @@ public class CodeFormatterVisitor extends ASTVisitor { TypeReference[][] typeArguments = parameterizedQualifiedTypeReference.typeArguments; int length = typeArguments.length; for (int i = 0; i < length; i++) { + if (parameterizedQualifiedTypeReference.annotations != null) { + formatInlineAnnotations(parameterizedQualifiedTypeReference.annotations[i], false); + } this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier); TypeReference[] typeArgument = typeArguments[i]; if (typeArgument != null) { @@ -4697,19 +4729,7 @@ public class CodeFormatterVisitor extends ASTVisitor { this.scribe.printNextToken(TerminalTokens.TokenNameDOT); } } - int dimensions = getDimensions(); - if (dimensions != 0 && dimensions <= parameterizedQualifiedTypeReference.dimensions()) { - if (this.preferences.insert_space_before_opening_bracket_in_array_type_reference) { - this.scribe.space(); - } - for (int i = 0; i < dimensions; i++) { - this.scribe.printNextToken(TerminalTokens.TokenNameLBRACKET); - if (this.preferences.insert_space_between_brackets_in_array_type_reference) { - this.scribe.space(); - } - this.scribe.printNextToken(TerminalTokens.TokenNameRBRACKET); - } - } + formatLeadingDimensions(parameterizedQualifiedTypeReference, true); if (numberOfParens > 0) { manageClosingParenthesizedExpression(parameterizedQualifiedTypeReference, numberOfParens); } @@ -4725,6 +4745,9 @@ public class CodeFormatterVisitor extends ASTVisitor { TypeReference[][] typeArguments = parameterizedQualifiedTypeReference.typeArguments; int length = typeArguments.length; for (int i = 0; i < length; i++) { + if (parameterizedQualifiedTypeReference.annotations != null) { + formatInlineAnnotations(parameterizedQualifiedTypeReference.annotations[i], false); + } this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier); TypeReference[] typeArgument = typeArguments[i]; if (typeArgument != null) { @@ -4754,19 +4777,7 @@ public class CodeFormatterVisitor extends ASTVisitor { this.scribe.printNextToken(TerminalTokens.TokenNameDOT); } } - int dimensions = getDimensions(); - if (dimensions != 0 && dimensions <= parameterizedQualifiedTypeReference.dimensions()) { - if (this.preferences.insert_space_before_opening_bracket_in_array_type_reference) { - this.scribe.space(); - } - for (int i = 0; i < dimensions; i++) { - this.scribe.printNextToken(TerminalTokens.TokenNameLBRACKET); - if (this.preferences.insert_space_between_brackets_in_array_type_reference) { - this.scribe.space(); - } - this.scribe.printNextToken(TerminalTokens.TokenNameRBRACKET); - } - } + formatLeadingDimensions(parameterizedQualifiedTypeReference, true); if (numberOfParens > 0) { manageClosingParenthesizedExpression(parameterizedQualifiedTypeReference, numberOfParens); } @@ -4779,6 +4790,9 @@ public class CodeFormatterVisitor extends ASTVisitor { if (numberOfParens > 0) { manageOpeningParenthesizedExpression(parameterizedSingleTypeReference, numberOfParens); } + if (parameterizedSingleTypeReference.annotations != null) { + formatInlineAnnotations(parameterizedSingleTypeReference.annotations[0], false); + } this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier); TypeReference[] typeArguments = parameterizedSingleTypeReference.typeArguments; @@ -4803,20 +4817,7 @@ public class CodeFormatterVisitor extends ASTVisitor { this.scribe.printNextToken(TerminalTokens.TokenNameLESS, this.preferences.insert_space_before_opening_angle_bracket_in_parameterized_type_reference); this.scribe.printNextToken(CLOSING_GENERICS_EXPECTEDTOKENS); } - - int dimensions = getDimensions(); - if (dimensions != 0 && dimensions <= parameterizedSingleTypeReference.dimensions()) { - if (this.preferences.insert_space_before_opening_bracket_in_array_type_reference) { - this.scribe.space(); - } - for (int i = 0; i < dimensions; i++) { - this.scribe.printNextToken(TerminalTokens.TokenNameLBRACKET); - if (this.preferences.insert_space_between_brackets_in_array_type_reference) { - this.scribe.space(); - } - this.scribe.printNextToken(TerminalTokens.TokenNameRBRACKET); - } - } + formatLeadingDimensions(parameterizedSingleTypeReference, true); if (numberOfParens > 0) { manageClosingParenthesizedExpression(parameterizedSingleTypeReference, numberOfParens); } @@ -4829,6 +4830,9 @@ public class CodeFormatterVisitor extends ASTVisitor { if (numberOfParens > 0) { manageOpeningParenthesizedExpression(parameterizedSingleTypeReference, numberOfParens); } + if (parameterizedSingleTypeReference.annotations != null) { + formatInlineAnnotations(parameterizedSingleTypeReference.annotations[0], false); + } this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier); TypeReference[] typeArguments = parameterizedSingleTypeReference.typeArguments; @@ -4854,19 +4858,7 @@ public class CodeFormatterVisitor extends ASTVisitor { this.scribe.printNextToken(CLOSING_GENERICS_EXPECTEDTOKENS); } - int dimensions = getDimensions(); - if (dimensions != 0 && dimensions <= parameterizedSingleTypeReference.dimensions()) { - if (this.preferences.insert_space_before_opening_bracket_in_array_type_reference) { - this.scribe.space(); - } - for (int i = 0; i < dimensions; i++) { - this.scribe.printNextToken(TerminalTokens.TokenNameLBRACKET); - if (this.preferences.insert_space_between_brackets_in_array_type_reference) { - this.scribe.space(); - } - this.scribe.printNextToken(TerminalTokens.TokenNameRBRACKET); - } - } + formatLeadingDimensions(parameterizedSingleTypeReference, true); if (numberOfParens > 0) { manageClosingParenthesizedExpression(parameterizedSingleTypeReference, numberOfParens); } @@ -5087,14 +5079,25 @@ public class CodeFormatterVisitor extends ASTVisitor { if (numberOfParens > 0) { manageOpeningParenthesizedExpression(qualifiedTypeReference, numberOfParens); } - this.scribe.printQualifiedReference(qualifiedTypeReference.sourceEnd, numberOfParens>=0/*expect parenthesis*/); - + formatQualifiedTypeReference(qualifiedTypeReference); if (numberOfParens > 0) { manageClosingParenthesizedExpression(qualifiedTypeReference, numberOfParens); } return false; } + private void formatQualifiedTypeReference(QualifiedTypeReference qualifiedTypeReference) { + for (int i = 0, length = qualifiedTypeReference.tokens.length; i < length; ++i) { + if (i != 0) this.scribe.printNextToken(TerminalTokens.TokenNameDOT, false); + if (qualifiedTypeReference.annotations != null) { + formatInlineAnnotations(qualifiedTypeReference.annotations[i], false); + this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier, true); + } else { + this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier, false); + } + } + } + /** * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.QualifiedTypeReference, org.eclipse.jdt.internal.compiler.lookup.ClassScope) */ @@ -5106,7 +5109,7 @@ public class CodeFormatterVisitor extends ASTVisitor { if (numberOfParens > 0) { manageOpeningParenthesizedExpression(qualifiedTypeReference, numberOfParens); } - this.scribe.printQualifiedReference(qualifiedTypeReference.sourceEnd, numberOfParens>=0/*expect parenthesis*/); + formatQualifiedTypeReference(qualifiedTypeReference); if (numberOfParens > 0) { manageClosingParenthesizedExpression(qualifiedTypeReference, numberOfParens); @@ -5212,6 +5215,9 @@ public class CodeFormatterVisitor extends ASTVisitor { if (numberOfParens > 0) { manageOpeningParenthesizedExpression(singleTypeReference, numberOfParens); } + if (singleTypeReference.annotations != null) { + formatInlineAnnotations(singleTypeReference.annotations[0], false); + } this.scribe.printNextToken(SINGLETYPEREFERENCE_EXPECTEDTOKENS); if (numberOfParens > 0) { @@ -5220,6 +5226,22 @@ public class CodeFormatterVisitor extends ASTVisitor { return false; } + private boolean formatInlineAnnotations(final Annotation[] annotations, boolean spaceBefore) { + if (annotations != null ) { + if (spaceBefore) this.scribe.space(); + int length = annotations.length; + for (int i = 0; i < length; ++i) { + if (i != 0) this.scribe.space(); + annotations[i].traverse(this, (BlockScope)null); + } + if (length > 0 && !this.isNextTokenPunctuation()) { + this.scribe.space(); + } + return true; + } + return false; + } + /** * @see org.eclipse.jdt.internal.compiler.ASTVisitor#visit(org.eclipse.jdt.internal.compiler.ast.SingleTypeReference, org.eclipse.jdt.internal.compiler.lookup.ClassScope) */ @@ -5231,6 +5253,9 @@ public class CodeFormatterVisitor extends ASTVisitor { if (numberOfParens > 0) { manageOpeningParenthesizedExpression(singleTypeReference, numberOfParens); } + if (singleTypeReference.annotations != null) { + formatInlineAnnotations(singleTypeReference.annotations[0], false); + } this.scribe.printNextToken(SINGLETYPEREFERENCE_EXPECTEDTOKENS); if (numberOfParens > 0) { @@ -5688,6 +5713,9 @@ public class CodeFormatterVisitor extends ASTVisitor { return false; } public boolean visit(TypeParameter typeParameter, BlockScope scope) { + if (typeParameter.annotations != null) { + formatInlineAnnotations(typeParameter.annotations, false); + } this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier); if (typeParameter.type != null) { this.scribe.space(); @@ -5714,6 +5742,9 @@ public class CodeFormatterVisitor extends ASTVisitor { return false; } public boolean visit(TypeParameter typeParameter, ClassScope scope) { + if (typeParameter.annotations != null) { + formatInlineAnnotations(typeParameter.annotations, false); + } this.scribe.printNextToken(TerminalTokens.TokenNameIdentifier); if (typeParameter.type != null) { this.scribe.space(); @@ -5900,6 +5931,9 @@ public class CodeFormatterVisitor extends ASTVisitor { return false; } public boolean visit(Wildcard wildcard, BlockScope scope) { + if (wildcard.annotations != null) { + if (formatInlineAnnotations(wildcard.annotations[0], false)) this.scribe.space(); + } this.scribe.printNextToken(TerminalTokens.TokenNameQUESTION, this.preferences.insert_space_before_question_in_wilcard); switch(wildcard.kind) { case Wildcard.SUPER : @@ -5920,6 +5954,9 @@ public class CodeFormatterVisitor extends ASTVisitor { return false; } public boolean visit(Wildcard wildcard, ClassScope scope) { + if (wildcard.annotations != null) { + if (formatInlineAnnotations(wildcard.annotations[0], false)) this.scribe.space(); + } this.scribe.printNextToken(TerminalTokens.TokenNameQUESTION, this.preferences.insert_space_before_question_in_wilcard); switch(wildcard.kind) { case Wildcard.SUPER : diff --git a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/Scribe.java b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/Scribe.java index ced5686af3..38ac389fc9 100644 --- a/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/Scribe.java +++ b/org.eclipse.jdt.core/formatter/org/eclipse/jdt/internal/formatter/Scribe.java @@ -5,9 +5,14 @@ * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * + * This is an implementation of an early-draft specification developed under the Java + * Community Process (JCP) and is made available for testing and evaluation purposes + * only. The code is not compatible with any specification of the JCP. + * * Contributors: * IBM Corporation - initial API and implementation * Ray V. (voidstar@gmail.com) - Contribution for bug 282988 + * Jesper S Moller - Contribution for bug 402892 *******************************************************************************/ package org.eclipse.jdt.internal.formatter; @@ -4927,53 +4932,6 @@ public class Scribe implements IJavaDocTagConstants { } } - public void printArrayQualifiedReference(int numberOfTokens, int sourceEnd) { - int currentTokenStartPosition = this.scanner.currentPosition; - int numberOfIdentifiers = 0; - try { - do { - printComment(CodeFormatter.K_UNKNOWN, NO_TRAILING_COMMENT); - switch(this.currentToken = this.scanner.getNextToken()) { - case TerminalTokens.TokenNameEOF : - return; - case TerminalTokens.TokenNameWHITESPACE : - addDeleteEdit(this.scanner.getCurrentTokenStartPosition(), this.scanner.getCurrentTokenEndPosition()); - currentTokenStartPosition = this.scanner.currentPosition; - break; - case TerminalTokens.TokenNameCOMMENT_BLOCK : - case TerminalTokens.TokenNameCOMMENT_JAVADOC : - printBlockComment(false); - currentTokenStartPosition = this.scanner.currentPosition; - break; - case TerminalTokens.TokenNameCOMMENT_LINE : - printLineComment(); - currentTokenStartPosition = this.scanner.currentPosition; - break; - case TerminalTokens.TokenNameIdentifier : - print(this.scanner.currentPosition - this.scanner.startPosition, false); - currentTokenStartPosition = this.scanner.currentPosition; - if (++ numberOfIdentifiers == numberOfTokens) { - this.scanner.resetTo(currentTokenStartPosition, this.scannerEndPosition - 1); - return; - } - break; - case TerminalTokens.TokenNameDOT : - print(this.scanner.currentPosition - this.scanner.startPosition, false); - currentTokenStartPosition = this.scanner.currentPosition; - break; - case TerminalTokens.TokenNameRPAREN: - currentTokenStartPosition = this.scanner.startPosition; - // $FALL-THROUGH$ - fall through default case... - default: - this.scanner.resetTo(currentTokenStartPosition, this.scannerEndPosition - 1); - return; - } - } while (this.scanner.currentPosition <= sourceEnd); - } catch(InvalidInputException e) { - throw new AbortFormatting(e); - } - } - public void printQualifiedReference(int sourceEnd, boolean expectParenthesis) { int currentTokenStartPosition = this.scanner.currentPosition; try { |
