update jdt.core tests to v_A39 using patch from the corresponding update in old svn (for 1.4.0)
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceElementParserTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceElementParserTest.java
index 25d7a6d..33d948a 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceElementParserTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceElementParserTest.java
@@ -12,9 +12,11 @@
package org.eclipse.jdt.core.tests.compiler.parser;
import java.util.Locale;
+import java.util.Map;
import junit.framework.Test;
+import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.compiler.CategorizedProblem;
import org.eclipse.jdt.core.compiler.CharOperation;
import org.eclipse.jdt.core.tests.util.AbstractCompilerTest;
@@ -45,7 +47,7 @@
this.source = source;
}
static {
-// TESTS_NUMBERS = new int[] { 99662 };
+// TESTS_NUMBERS = new int[] { 81 };
}
public static Test suite() {
return buildAllCompliancesTestSuite(SourceElementParserTest.class);
@@ -228,7 +230,7 @@
if (typeInfo.typeParameters != null) {
for (int i = 0, length = typeInfo.typeParameters.length; i < length; i++) {
TypeParameterInfo typeParameterInfo = typeInfo.typeParameters[i];
- addTypeParameter(typeParameterInfo);
+ addTypeParameterToType(typeParameterInfo);
}
}
}
@@ -280,11 +282,11 @@
if (methodInfo.typeParameters != null) {
for (int i = 0, length = methodInfo.typeParameters.length; i < length; i++) {
TypeParameterInfo typeParameterInfo = methodInfo.typeParameters[i];
- addTypeParameter(typeParameterInfo);
+ addTypeParameterToMethod(typeParameterInfo);
}
}
}
-public void addTypeParameter(TypeParameterInfo typeParameterInfo) {
+public void addTypeParameterToMethod(TypeParameterInfo typeParameterInfo) {
if (this.currentMethod.typeParameterNames == null) {
this.currentMethod.typeParameterNames = new char[][] {typeParameterInfo.name};
this.currentMethod.typeParameterBounds = new char[][][] {typeParameterInfo.bounds};
@@ -296,6 +298,18 @@
this.currentMethod.typeParameterBounds[length] = typeParameterInfo.bounds;
}
}
+public void addTypeParameterToType(TypeParameterInfo typeParameterInfo) {
+ if (this.currentType.typeParameterNames == null) {
+ this.currentType.typeParameterNames = new char[][] {typeParameterInfo.name};
+ this.currentType.typeParameterBounds = new char[][][] {typeParameterInfo.bounds};
+ } else {
+ int length = this.currentType.typeParameterNames.length;
+ System.arraycopy(this.currentType.typeParameterNames, 0, this.currentType.typeParameterNames = new char[length+1][],0, length);
+ this.currentMethod.typeParameterNames[length] = typeParameterInfo.name;
+ System.arraycopy(this.currentType.typeParameterBounds, 0, this.currentType.typeParameterBounds = new char[length+1][][],0, length);
+ this.currentType.typeParameterBounds[length] = typeParameterInfo.bounds;
+ }
+}
public void exitType(int declarationEnd) {
this.currentType.setDeclarationSourceEnd(declarationEnd);
if (this.currentType.parent != null) {
@@ -318,13 +332,16 @@
public void fullParse(String s, String testName) {
this.fullParse(s, testName, false);
}
-public void fullParse(String s, String testName, boolean recordLocalDeclaration) {
+public void fullParse(String s, String testName, Map options) {
+ this.fullParse(s, testName, false, options);
+}
+public void fullParse(String s, String testName, boolean recordLocalDeclaration, Map options) {
this.source = s.toCharArray();
reset();
SourceElementParser parser =
new SourceElementParser(
this, new DefaultProblemFactory(Locale.getDefault()),
- new CompilerOptions(getCompilerOptions()),
+ new CompilerOptions(options),
recordLocalDeclaration/*don't record local declarations*/,
true/*optimize string literals*/);
@@ -332,6 +349,9 @@
parser.parseCompilationUnit(sourceUnit, true, null);
}
+public void fullParse(String s, String testName, boolean recordLocalDeclaration) {
+ this.fullParse(s, testName, recordLocalDeclaration, getCompilerOptions());
+}
public void reset() {
this.currentType = null;
this.currentMethod = null;
@@ -5277,6 +5297,83 @@
expectedUnitToString,
this.currentType.toString());
}
+public void test81() {
+
+ Map options = getCompilerOptions();
+ options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
+ options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_5);
+ options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
+
+ String s =
+ "import java.util.Collection;\n" +
+ "\n" +
+ "public class X {\n" +
+ " public abstract class AbstractData {}\n" +
+ " \n" +
+ " public interface IScalarData<T extends AbstractData> {}\n" +
+ "\n" +
+ " private static interface ValueObjectPropertyIterator {\n" +
+ " public <T extends AbstractData> void iterateOnValueObjectProperty(IScalarData<T> scalarObject, T valueObject, Class<?> valueObjectType, final String name, final Class<?> scalarType) throws Exception;\n" +
+ " }\n" +
+ "\n" +
+ " private static <T extends AbstractData> void iterateOnValueObjectProperties(IScalarData<T> scalarObject, T valueObject, ValueObjectPropertyIterator valueObjectPropertyIterator) {}\n" +
+ " \n" +
+ " public static <T extends AbstractData> void loadScalarFromValueObject(IScalarData<T> scalarObject, T valueObject) {\n" +
+ " iterateOnValueObjectProperties(scalarObject, valueObject, new ValueObjectPropertyIterator() {\n" +
+ " public <T extends AbstractData> void iterateOnValueObjectProperty(IScalarData<T> scalarObject, T valueObject, Class<?> valueObjectType, String name, Class<?> scalarType) throws Exception {\n" +
+ " if (true) {\n" +
+ " if (true) {\n" +
+ " if (true) {\n" +
+ " final Collection<IScalarData<AbstractData>> lazyCollection = createLazyCollection(\n" +
+ " name, scalarType, null, null,\n" +
+ " new CollectionProviderForTargetCollection<IScalarData<AbstractData>>() {\n" +
+ " @Override\n" +
+ " public Collection<IScalarData<AbstractData>> provideCollection(\n" +
+ " final Collection<IScalarData<AbstractData> targetCollection, final Class<IScalarData<AbstractData>> scalarCollectionType) {\n" +
+ " return null;\n" +
+ " }\n" +
+ " });\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ "\n" +
+ " abstract class CollectionProviderForTargetCollection<S> {\n" +
+ " abstract public Collection<S> provideCollection(Collection<S> targetCollection, Class<S> scalarCollectionType);\n" +
+ " }\n" +
+ "\n" +
+ " private <S> Collection<S> createLazyCollection(String name,\n" +
+ " Class<?> scalarType, final Collection<AbstractData> valueObjectCollection,\n" +
+ " final Class<S> scalarCollectionType, CollectionProviderForTargetCollection<S> collectionProvider) {\n" +
+ " return null;\n" +
+ " }\n" +
+ " });\n" +
+ " }\n" +
+ "}";
+
+ String expectedUnitToString =
+ "import java.util.Collection;\n" +
+ "public class X {\n" +
+ " public abstract class AbstractData {\n" +
+ " java.lang.Object(0)\n" +
+ " }\n" +
+ " public interface IScalarData {\n" +
+ " }\n" +
+ " private static interface ValueObjectPropertyIterator {\n" +
+ " public void iterateOnValueObjectProperty(IScalarData<T> scalarObject, T valueObject, Class<?> valueObjectType, String name, Class<?> scalarType, ) throws Exception, {}\n" +
+ " }\n" +
+ " java.lang.Object(0)\n" +
+ " private static void iterateOnValueObjectProperties(IScalarData<T> scalarObject, T valueObject, ValueObjectPropertyIterator valueObjectPropertyIterator, ) {}\n" +
+ " public static void loadScalarFromValueObject(IScalarData<T> scalarObject, T valueObject, ) {}\n" +
+ "}";
+
+ String testName = "test81: full parse";
+ fullParse(s,testName, options);
+ assertEquals(
+ "Invalid source " + testName,
+ expectedUnitToString,
+ this.currentType.toString());
+}
//{ObjectTeams: add OT-specific methods (should these be implemented??):
public void acceptBaseReference(char[][] typeName, int sourceStart,
int sourceEnd) {
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceType.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceType.java
index c549bce..2ee2409 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceType.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/parser/SourceType.java
@@ -33,6 +33,8 @@
private int numberOfFields;
private char[] source;
SourceType parent;
+ char[][] typeParameterNames;
+ char[][][] typeParameterBounds;
// Buffering.
private char[] qualifiedName;
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
index 0da80b2..90e19f5 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AbstractRegressionTest.java
@@ -1170,7 +1170,7 @@
protected void runConformTest(String[] testFiles, String expectedOutputString) {
runTest(
- // test directory preparation
+ // test directory preparation
true /* flush output directory */,
testFiles /* test files */,
// compiler options
@@ -1871,6 +1871,39 @@
JavacTestOptions.DEFAULT /* default javac test options */);
}
protected void runNegativeTest(
+ String[] testFiles,
+ String expectedCompilerLog,
+ String[] classLibraries,
+ boolean shouldFlushOutputDirectory,
+ Map customOptions,
+ String expectedErrorString) {
+ runTest(
+ // test directory preparation
+ shouldFlushOutputDirectory /* should flush output directory */,
+ testFiles /* test files */,
+ // compiler options
+ classLibraries /* class libraries */,
+ customOptions /* custom options */,
+ false /* do not perform statements recovery */,
+ new Requestor( /* custom requestor */
+ false,
+ null /* no custom requestor */,
+ false,
+ false),
+ // compiler results
+ expectedCompilerLog == null || /* expecting compiler errors */
+ expectedCompilerLog.indexOf("ERROR") != -1,
+ expectedCompilerLog /* expected compiler log */,
+ // runtime options
+ false /* do not force execution */,
+ null /* no vm arguments */,
+ // runtime results
+ null /* do not check output string */,
+ expectedErrorString /* do not check error string */,
+ // javac options
+ JavacTestOptions.DEFAULT /* default javac test options */);
+ }
+ protected void runNegativeTest(
String[] testFiles,
String expectedProblemLog,
String[] classLibraries,
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java
index a832066..9fc65ea 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AmbiguousMethodTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation 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
@@ -2913,7 +2913,7 @@
"interface C extends B, A {}\n" +
"interface D extends A, B {}\n" +
"public class X<T> {\n" +
- " public static void main(String[] args) {\n" +
+ " public void bar() {\n" +
" C c = null;\n" +
" X<? extends B> c_b = c.foo();\n" +
" D d = null;\n" +
@@ -3528,4 +3528,322 @@
},
"SUCCESS");
}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=302358
+public void test081() {
+ this.runConformTest(
+ new String[] {
+ "C.java",
+ "class A<ModelType extends D, ValueType> implements I<ModelType, ValueType> {\n" +
+ " public void doSet(ModelType valueGetter) {\n" +
+ " this.set((ValueType) valueGetter.getObject());\n" +
+ " }\n" +
+ " public void set(Object object) {\n" +
+ " System.out.println(\"In A.set(Object)\");\n" +
+ " }\n" +
+ "}\n" +
+ "class B extends A<E, CharSequence> {\n" +
+ " public void set(CharSequence string) {\n" +
+ " System.out.println(\"In B.set(CharSequence)\");\n" +
+ " }\n" +
+ "}\n" +
+ "public class C extends B {\n" +
+ " static public void main(String[] args) {\n" +
+ " C c = new C();\n" +
+ " c.run();\n" +
+ " }\n" +
+ " public void run() {\n" +
+ " E e = new E<String>(String.class);\n" +
+ " this.doSet(e);\n" +
+ " }\n" +
+ "}\n" +
+ "class D {\n" +
+ " public Object getObject() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n" +
+ "class E<Type extends CharSequence> extends D {\n" +
+ " private Class<Type> typeClass;\n" +
+ " public E(Class<Type> typeClass) {\n" +
+ " this.typeClass = typeClass;\n" +
+ " }\n" +
+ " public Type getObject() {\n" +
+ " try {\n" +
+ " return (Type) typeClass.newInstance();\n" +
+ " } catch (Exception e) {\n" +
+ " throw new RuntimeException(e);\n" +
+ " }\n" +
+ " }\n" +
+ "}\n" +
+ "interface I<ModelType, ValueType> {\n" +
+ " public void doSet(ModelType model);\n" +
+ " public void set(ValueType value);\n" +
+ "}\n"
+
+ },
+ "In B.set(CharSequence)");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=302358
+public void test082() {
+ this.runConformTest(
+ new String[] {
+ "C.java",
+ "class A<ModelType extends D, ValueType> extends I<ModelType, ValueType> {\n" +
+ " public void doSet(ModelType valueGetter) {\n" +
+ " this.set((ValueType) valueGetter.getObject());\n" +
+ " }\n" +
+ " public void set(Object object) {\n" +
+ " System.out.println(\"In A.set(Object)\");\n" +
+ " }\n" +
+ "}\n" +
+ "class B extends A<E, CharSequence> {\n" +
+ " public void set(CharSequence string) {\n" +
+ " System.out.println(\"In B.set(CharSequence)\");\n" +
+ " }\n" +
+ "}\n" +
+ "public class C extends B {\n" +
+ " static public void main(String[] args) {\n" +
+ " C c = new C();\n" +
+ " c.run();\n" +
+ " }\n" +
+ " public void run() {\n" +
+ " E e = new E<String>(String.class);\n" +
+ " this.doSet(e);\n" +
+ " }\n" +
+ "}\n" +
+ "class D {\n" +
+ " public Object getObject() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n" +
+ "class E<Type extends CharSequence> extends D {\n" +
+ " private Class<Type> typeClass;\n" +
+ " public E(Class<Type> typeClass) {\n" +
+ " this.typeClass = typeClass;\n" +
+ " }\n" +
+ " public Type getObject() {\n" +
+ " try {\n" +
+ " return (Type) typeClass.newInstance();\n" +
+ " } catch (Exception e) {\n" +
+ " throw new RuntimeException(e);\n" +
+ " }\n" +
+ " }\n" +
+ "}\n" +
+ "abstract class I<ModelType, ValueType> {\n" +
+ " public abstract void doSet(ModelType model);\n" +
+ " public abstract void set(ValueType value);\n" +
+ "}\n"
+
+ },
+ "In B.set(CharSequence)");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=302358
+public void test083() {
+ this.runConformTest(
+ new String[] {
+ "C.java",
+ "class A<ModelType extends D, ValueType> implements I<ModelType, ValueType> {\n" +
+ " public void doSet(ModelType valueGetter) {\n" +
+ " this.set((ValueType) valueGetter.getObject());\n" +
+ " }\n" +
+ " public void set(Object object) {\n" +
+ " System.out.println(\"In A.set(Object)\");\n" +
+ " }\n" +
+ "}\n" +
+ "class B extends A<E, CharSequence> implements I<E, CharSequence> {\n" +
+ " public void set(CharSequence string) {\n" +
+ " System.out.println(\"In B.set(CharSequence)\");\n" +
+ " }\n" +
+ "}\n" +
+ "public class C extends B {\n" +
+ " static public void main(String[] args) {\n" +
+ " C c = new C();\n" +
+ " c.run();\n" +
+ " }\n" +
+ " public void run() {\n" +
+ " E e = new E<String>(String.class);\n" +
+ " this.doSet(e);\n" +
+ " }\n" +
+ "}\n" +
+ "class D {\n" +
+ " public Object getObject() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n" +
+ "class E<Type extends CharSequence> extends D {\n" +
+ " private Class<Type> typeClass;\n" +
+ " public E(Class<Type> typeClass) {\n" +
+ " this.typeClass = typeClass;\n" +
+ " }\n" +
+ " public Type getObject() {\n" +
+ " try {\n" +
+ " return (Type) typeClass.newInstance();\n" +
+ " } catch (Exception e) {\n" +
+ " throw new RuntimeException(e);\n" +
+ " }\n" +
+ " }\n" +
+ "}\n" +
+ "interface I<ModelType, ValueType> {\n" +
+ " public void doSet(ModelType model);\n" +
+ " public void set(ValueType value);\n" +
+ "}\n"
+
+ },
+ "In B.set(CharSequence)");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=302358
+public void test084() {
+ this.runConformTest(
+ new String[] {
+ "C.java",
+ "abstract class A<ModelType extends D, ValueType> implements I<ModelType, ValueType> {\n" +
+ " public void doSet(ModelType valueGetter) {\n" +
+ " this.set((ValueType) valueGetter.getObject());\n" +
+ " }\n" +
+ " public void set(Object object) {\n" +
+ " System.out.println(\"In A.set(Object)\");\n" +
+ " }\n" +
+ "}\n" +
+ "class B extends A<E, CharSequence> {\n" +
+ "}\n" +
+ "public class C extends B {\n" +
+ " static public void main(String[] args) {\n" +
+ " C c = new C();\n" +
+ " c.run();\n" +
+ " }\n" +
+ " public void run() {\n" +
+ " E e = new E<String>(String.class);\n" +
+ " this.doSet(e);\n" +
+ " }\n" +
+ "}\n" +
+ "class D {\n" +
+ " public Object getObject() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n" +
+ "class E<Type extends CharSequence> extends D {\n" +
+ " private Class<Type> typeClass;\n" +
+ " public E(Class<Type> typeClass) {\n" +
+ " this.typeClass = typeClass;\n" +
+ " }\n" +
+ " public Type getObject() {\n" +
+ " try {\n" +
+ " return (Type) typeClass.newInstance();\n" +
+ " } catch (Exception e) {\n" +
+ " throw new RuntimeException(e);\n" +
+ " }\n" +
+ " }\n" +
+ "}\n" +
+ "interface I<ModelType, ValueType> {\n" +
+ " public void doSet(ModelType model);\n" +
+ " public void set(ValueType value);\n" +
+ "}\n"
+
+ },
+ "In A.set(Object)");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=302358
+public void test085() {
+ this.runConformTest(
+ new String[] {
+ "C.java",
+ "class A<ModelType extends D, ValueType> implements I<ModelType, ValueType> {\n" +
+ " public void doSet(ModelType valueGetter) {\n" +
+ " this.set((ValueType) valueGetter.getObject());\n" +
+ " }\n" +
+ " public void set(Object object) {\n" +
+ " System.out.println(\"In A.set(Object)\");\n" +
+ " }\n" +
+ "}\n" +
+ "class B extends A<E, CharSequence> {\n" +
+ "}\n" +
+ "public class C extends B {\n" +
+ " static public void main(String[] args) {\n" +
+ " C c = new C();\n" +
+ " c.run();\n" +
+ " }\n" +
+ " public void run() {\n" +
+ " E e = new E<String>(String.class);\n" +
+ " this.doSet(e);\n" +
+ " }\n" +
+ "}\n" +
+ "class D {\n" +
+ " public Object getObject() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n" +
+ "class E<Type extends CharSequence> extends D {\n" +
+ " private Class<Type> typeClass;\n" +
+ " public E(Class<Type> typeClass) {\n" +
+ " this.typeClass = typeClass;\n" +
+ " }\n" +
+ " public Type getObject() {\n" +
+ " try {\n" +
+ " return (Type) typeClass.newInstance();\n" +
+ " } catch (Exception e) {\n" +
+ " throw new RuntimeException(e);\n" +
+ " }\n" +
+ " }\n" +
+ "}\n" +
+ "interface I<ModelType, ValueType> {\n" +
+ " public void doSet(ModelType model);\n" +
+ " public void set(ValueType value);\n" +
+ "}\n"
+
+ },
+ "In A.set(Object)");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=302358
+public void test086() {
+ this.runConformTest(
+ new String[] {
+ "C.java",
+ "class A<ModelType extends D, ValueType> {\n" +
+ " public void doSet(ModelType valueGetter) {\n" +
+ " this.set((ValueType) valueGetter.getObject());\n" +
+ " }\n" +
+ " public void set(Object object) {\n" +
+ " System.out.println(\"In A.set(Object)\");\n" +
+ " }\n" +
+ "}\n" +
+ "class B extends A<E, CharSequence> {\n" +
+ " public void set(CharSequence string) {\n" +
+ " System.out.println(\"In B.set(CharSequence)\");\n" +
+ " }\n" +
+ "}\n" +
+ "public class C extends B {\n" +
+ " static public void main(String[] args) {\n" +
+ " C c = new C();\n" +
+ " c.run();\n" +
+ " }\n" +
+ " public void run() {\n" +
+ " E e = new E<String>(String.class);\n" +
+ " this.doSet(e);\n" +
+ " }\n" +
+ "}\n" +
+ "class D {\n" +
+ " public Object getObject() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n" +
+ "class E<Type extends CharSequence> extends D {\n" +
+ " private Class<Type> typeClass;\n" +
+ " public E(Class<Type> typeClass) {\n" +
+ " this.typeClass = typeClass;\n" +
+ " }\n" +
+ " public Type getObject() {\n" +
+ " try {\n" +
+ " return (Type) typeClass.newInstance();\n" +
+ " } catch (Exception e) {\n" +
+ " throw new RuntimeException(e);\n" +
+ " }\n" +
+ " }\n" +
+ "}\n" +
+ "interface I<ModelType, ValueType> {\n" +
+ " public void doSet(ModelType model);\n" +
+ " public void set(ValueType value);\n" +
+ "}\n"
+
+ },
+ "In A.set(Object)");
+}
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java
index 14f2036..3d98bcf 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/AnnotationTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation 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
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Stephan Herrmann - Contribution for bug 295551
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
@@ -44,7 +45,7 @@
// All specified tests which do not belong to the class are skipped...
static {
// TESTS_NAMES = new String[] { "test127" };
-// TESTS_NUMBERS = new int[] { 278 };
+// TESTS_NUMBERS = new int[] { 286 };
// TESTS_RANGE = new int[] { 249, -1 };
}
@@ -997,7 +998,7 @@
this.runConformTest(
new String[] {
"X.java",
- "@Foo(type=String.class) public class X {\r\n" +
+ "@Foo(type=String.class) public class X {\n" +
"}"
},
"",
@@ -1246,8 +1247,8 @@
"}\n"
},
"----------\n" +
- "1. ERROR in X.java (at line 12)\r\n" +
- " public @MyAnn void something() { } \r\n" +
+ "1. ERROR in X.java (at line 12)\n" +
+ " public @MyAnn void something() { } \n" +
" ^^^^^^\n" +
"The annotation @MyAnn is disallowed for this location\n" +
"----------\n");
@@ -2723,8 +2724,8 @@
"}\n"
},
"----------\n" +
- "1. ERROR in X.java (at line 4)\r\n" +
- " @Inherited\r\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " @Inherited\n" +
" ^^^^^^^^^^\n" +
"The annotation @Inherited is disallowed for this location\n" +
"----------\n");
@@ -2958,8 +2959,8 @@
"}\n",
},
"----------\n" +
- "1. ERROR in X.java (at line 3)\r\n" +
- " @Target(Element)\r\n" +
+ "1. ERROR in X.java (at line 3)\n" +
+ " @Target(Element)\n" +
" ^^^^^^^\n" +
"Element cannot be resolved to a variable\n" +
"----------\n");
@@ -4064,7 +4065,11 @@
" class S implements Serializable {\n" +
" ^\n" +
"The serializable class S does not declare a static final serialVersionUID field of type long\n" +
- "----------\n");
+ "----------\n",
+ null,
+ true,
+ null,
+ "java.lang.Error");
}
// check @SuppressWarning support
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=89436
@@ -4368,8 +4373,8 @@
public void test140() {
String expectedOutput = new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6
? "----------\n" +
- "1. ERROR in X.java (at line 6)\r\n" +
- " static void foo(){} \r\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " static void foo(){} \n" +
" ^^^^^\n" +
"The method foo() of type Bar must override a superclass method\n" +
"----------\n"
@@ -4503,6 +4508,8 @@
true,
raiseInvalidJavadocSeverity);
}
+// check that @SuppressWarning is reported as unused when corresponding warning is moved from
+// warning to error
public void test142c() {
Map raiseDeprecationReduceInvalidJavadocSeverity =
new HashMap(2);
@@ -4534,16 +4541,21 @@
},
null,
raiseDeprecationReduceInvalidJavadocSeverity,
- "----------\n" +
- "1. ERROR in X.java (at line 2)\n" +
- " public class X extends p.OldStuff {\n" +
- " ^^^^^^^^^^\n" +
- "The type OldStuff is deprecated\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 8)\n" +
- " super.foo();\n" +
- " ^^^^^^^^^^^\n" +
- "The method foo() from the type OldStuff is deprecated\n" +
+ "----------\n" +
+ "1. WARNING in X.java (at line 1)\n" +
+ " @SuppressWarnings(\"deprecation\")\n" +
+ " ^^^^^^^^^^^^^\n" +
+ "Unnecessary @SuppressWarnings(\"deprecation\")\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 2)\n" +
+ " public class X extends p.OldStuff {\n" +
+ " ^^^^^^^^^^\n" +
+ "The type OldStuff is deprecated\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 8)\n" +
+ " super.foo();\n" +
+ " ^^^^^^^^^^^\n" +
+ "The method foo() from the type OldStuff is deprecated\n" +
"----------\n",
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
}
@@ -5831,10 +5843,10 @@
"import static java.lang.annotation.RetentionPolicy.*;\n" +
"import java.lang.annotation.Retention;\n" +
"import java.lang.annotation.Target;\n" +
- "@Target({TYPE, FIELD, METHOD,\r\n" +
- " PARAMETER, CONSTRUCTOR,\r\n" +
- " LOCAL_VARIABLE, PACKAGE,})\r\n" +
- "@Retention(CLASS)\r\n" +
+ "@Target({TYPE, FIELD, METHOD,\n" +
+ " PARAMETER, CONSTRUCTOR,\n" +
+ " LOCAL_VARIABLE, PACKAGE,})\n" +
+ "@Retention(CLASS)\n" +
"public @interface X {}"
},
"",
@@ -6327,8 +6339,8 @@
"}"
},
"----------\n" +
- "1. ERROR in A.java (at line 2)\r\n" +
- " A circular1();\r\n" +
+ "1. ERROR in A.java (at line 2)\n" +
+ " A circular1();\n" +
" ^\n" +
"Cycle detected: the annotation type A cannot contain attributes of the annotation type itself\n" +
"----------\n"
@@ -6345,18 +6357,18 @@
"}"
},
"----------\n" +
- "1. ERROR in A.java (at line 2)\r\n" +
- " B circular2();\r\n" +
+ "1. ERROR in A.java (at line 2)\n" +
+ " B circular2();\n" +
" ^\n" +
"Cycle detected: a cycle exists between annotation attributes of A and B\n" +
"----------\n" +
- "2. ERROR in A.java (at line 3)\r\n" +
- " A circular1();\r\n" +
+ "2. ERROR in A.java (at line 3)\n" +
+ " A circular1();\n" +
" ^\n" +
"Cycle detected: the annotation type A cannot contain attributes of the annotation type itself\n" +
"----------\n" +
- "3. ERROR in A.java (at line 6)\r\n" +
- " A circular();\r\n" +
+ "3. ERROR in A.java (at line 6)\n" +
+ " A circular();\n" +
" ^\n" +
"Cycle detected: a cycle exists between annotation attributes of B and A\n" +
"----------\n"
@@ -6373,18 +6385,18 @@
"}"
},
"----------\n" +
- "1. ERROR in A.java (at line 2)\r\n" +
- " A circular1();\r\n" +
+ "1. ERROR in A.java (at line 2)\n" +
+ " A circular1();\n" +
" ^\n" +
"Cycle detected: the annotation type A cannot contain attributes of the annotation type itself\n" +
"----------\n" +
- "2. ERROR in A.java (at line 3)\r\n" +
- " B circular2();\r\n" +
+ "2. ERROR in A.java (at line 3)\n" +
+ " B circular2();\n" +
" ^\n" +
"Cycle detected: a cycle exists between annotation attributes of A and B\n" +
"----------\n" +
- "3. ERROR in A.java (at line 6)\r\n" +
- " A circular();\r\n" +
+ "3. ERROR in A.java (at line 6)\n" +
+ " A circular();\n" +
" ^\n" +
"Cycle detected: a cycle exists between annotation attributes of B and A\n" +
"----------\n"
@@ -7091,8 +7103,8 @@
if (new CompilerOptions(getCompilerOptions()).sourceLevel < ClassFileConstants.JDK1_6) {
this.runNegativeTest(sources,
"----------\n" +
- "1. ERROR in Y.java (at line 3)\r\n" +
- " public void foo() {}\r\n" +
+ "1. ERROR in Y.java (at line 3)\n" +
+ " public void foo() {}\n" +
" ^^^^^\n" +
"The method foo() of type Y must override a superclass method\n" +
"----------\n");
@@ -8147,8 +8159,8 @@
"}"
},
"----------\n" +
- "1. ERROR in TestAnnotation.java (at line 2)\r\n" +
- " String targetItem() default void.class;\r\n" +
+ "1. ERROR in TestAnnotation.java (at line 2)\n" +
+ " String targetItem() default void.class;\n" +
" ^^^^^^^^^^\n" +
"Type mismatch: cannot convert from Class<Void> to String\n" +
"----------\n");
@@ -9279,4 +9291,231 @@
expectedOutput,
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=301683
+public void test279() {
+ String testString [] = new String[] {
+ "A.java",
+ "public class A {\n" +
+ " public @interface Inline {\n" +
+ " String value();\n" +
+ " }\n" +
+ " @Inline(\"foo\")\n" +
+ " public Zork test;\n" +
+ " public native void method();\n" +
+ "}"
+ };
+ String expectedOutput =
+ "----------\n" +
+ "1. ERROR in A.java (at line 6)\n" +
+ " public Zork test;\n" +
+ " ^^^^\n" +
+ "Zork cannot be resolved to a type\n" +
+ "----------\n";
+ this.runNegativeTest(
+ testString,
+ expectedOutput,
+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551
+public void test280() {
+ Map customOptions = getCompilerOptions();
+ customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
+ customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED);
+ String testFiles [] = new String[] {
+ "A.java",
+ "public class A {\n" +
+ " @SuppressWarnings(\"unused\")\n" +
+ " private int i;\n" + // problem configured as warning but still suppressed
+ "}\n"
+ };
+ runConformTest(
+ testFiles,
+ null,
+ null,
+ true,
+ null,
+ customOptions,
+ null);
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551
+public void test281() {
+ Map customOptions = getCompilerOptions();
+ customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
+ customOptions.put(CompilerOptions.OPTION_SuppressWarnings, CompilerOptions.DISABLED); // this option overrides the next
+ customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED);
+ String testFiles [] = new String[] {
+ "A.java",
+ "public class A {\n" +
+ " @SuppressWarnings(\"unused\")\n" +
+ " private int i;\n" +
+ "}\n"
+ };
+ String expectedErrorString =
+ "----------\n" +
+ "1. ERROR in A.java (at line 3)\n" +
+ " private int i;\n" +
+ " ^\n" +
+ "The field A.i is never read locally\n" +
+ "----------\n";
+ runNegativeTest(
+ true,
+ testFiles,
+ null,
+ customOptions,
+ expectedErrorString,
+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551
+public void test282() {
+ Map customOptions = getCompilerOptions();
+ customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
+ customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED);
+ String testFiles [] = new String[] {
+ "A.java",
+ "import java.util.Map;\n" +
+ "public class A {\n" +
+ " @SuppressWarnings({\"rawtypes\", \"unused\"})\n" + //suppress a warning and an error
+ " private Map i;\n" +
+ "}\n"
+ };
+ runConformTest(
+ testFiles,
+ null,
+ null,
+ true,
+ null,
+ customOptions,
+ null);
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551
+public void test283() {
+ Map customOptions = getCompilerOptions();
+ customOptions.put(CompilerOptions.OPTION_ReportUnusedPrivateMember, CompilerOptions.ERROR);
+ customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED);
+ String testFiles [] = new String[] {
+ "A.java",
+ "public class A {\n" +
+ " @SuppressWarnings(\"all\")\n" +
+ " private void i;\n" + // cannot suppress mandatory error
+ "}\n"
+ };
+ String expectedErrorString =
+ "----------\n" +
+ "1. ERROR in A.java (at line 3)\n" +
+ " private void i;\n" +
+ " ^\n" +
+ "void is an invalid type for the variable i\n" +
+ "----------\n";
+ runNegativeTest(
+ true,
+ testFiles,
+ null,
+ customOptions,
+ expectedErrorString,
+ JavacTestOptions.SKIP);
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=304031
+public void test284() {
+ Map customOptions = getCompilerOptions();
+ customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.WARNING);
+ customOptions.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR);
+ customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED);
+ String testFiles [] = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " void m() {\n" +
+ " @SuppressWarnings(\"cast\")\n" +
+ " int i= (int) 0;\n" +
+ " @SuppressWarnings(\"cast\")\n" +
+ " byte b= (byte) i;\n" +
+ " System.out.println(b);\n" +
+ " }\n" +
+ "}"
+ };
+ String expectedErrorString =
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " @SuppressWarnings(\"cast\")\n" +
+ " ^^^^^^\n" +
+ "Unnecessary @SuppressWarnings(\"cast\")\n" +
+ "----------\n";
+ runNegativeTest(
+ true,
+ testFiles,
+ null,
+ customOptions,
+ expectedErrorString,
+ JavacTestOptions.SKIP);
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=304031
+public void test285() {
+ Map customOptions = getCompilerOptions();
+ customOptions.put(CompilerOptions.OPTION_ReportUnnecessaryTypeCheck, CompilerOptions.ERROR);
+ customOptions.put(CompilerOptions.OPTION_ReportUnusedWarningToken, CompilerOptions.ERROR);
+ customOptions.put(CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED);
+ String testFiles [] = new String[] {
+ "X.java",
+ "public class X {\n" +
+ " void m() {\n" +
+ " @SuppressWarnings(\"cast\")\n" +
+ " int i= (int) 0;\n" +
+ " @SuppressWarnings(\"cast\")\n" +
+ " byte b= (byte) i;\n" +
+ " System.out.println(b);\n" +
+ " }\n" +
+ "}"
+ };
+ String expectedErrorString =
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " @SuppressWarnings(\"cast\")\n" +
+ " ^^^^^^\n" +
+ "Unnecessary @SuppressWarnings(\"cast\")\n" +
+ "----------\n";
+ runNegativeTest(
+ true,
+ testFiles,
+ null,
+ customOptions,
+ expectedErrorString,
+ JavacTestOptions.SKIP);
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=304031
+public void test286() {
+ Map raiseDeprecationReduceInvalidJavadocSeverity =
+ new HashMap(2);
+ raiseDeprecationReduceInvalidJavadocSeverity.put(
+ CompilerOptions.OPTION_ReportDeprecation, CompilerOptions.ERROR);
+ raiseDeprecationReduceInvalidJavadocSeverity.put(
+ CompilerOptions.OPTION_SuppressOptionalErrors, CompilerOptions.ENABLED);
+ raiseDeprecationReduceInvalidJavadocSeverity.put(
+ CompilerOptions.OPTION_ReportInvalidJavadoc, CompilerOptions.WARNING);
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "@SuppressWarnings(\"deprecation\")\n" +
+ "public class X extends p.OldStuff {\n" +
+ " /**\n" +
+ " * @see p.OldStuff#foo()\n" +
+ " */\n" +
+ " @Override\n" +
+ " public void foo() {\n" +
+ " super.foo();\n" +
+ " }\n" +
+ "}\n",
+ "p/OldStuff.java",
+ "package p;\n" +
+ "@Deprecated\n" +
+ "public class OldStuff {\n" +
+ " public void foo() {\n" +
+ " } \n" +
+ "}\n",
+ },
+ "",
+ null,
+ true,
+ null,
+ raiseDeprecationReduceInvalidJavadocSeverity,
+ null);
+}
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
index 43bcf84..a1a34b5 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/BatchCompilerTest.java
@@ -9,6 +9,7 @@
* IBM Corporation - initial API and implementation
* Benjamin Muskalla - Contribution for bug 239066
* Stephan Herrmann - Contribution for bug 236385
+ * Stephan Herrmann - Contribution for bug 295551
* Technical University Berlin - adapted for Object Teams
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
@@ -48,8 +49,8 @@
static {
// TESTS_NAMES = new String[] { "test292_warn_options" };
-// TESTS_NUMBERS = new int[] { 295 };
-// TESTS_RANGE = new int[] { 107, -1 };
+// TESTS_NUMBERS = new int[] { 298 };
+// TESTS_RANGE = new int[] { 298, -1 };
}
public BatchCompilerTest(String name) {
super(name);
@@ -1735,7 +1736,9 @@
" static-access macro for indirectStatic and staticReceiver\n" +
" staticReceiver + non-static reference to static member\n" +
" super overriding a method without making a super invocation\n" +
- " suppress + enable @SuppressWarnings\n" +
+ " suppress + enable @SuppressWarnings\n" +
+ " When used with -err:, it can also silent optional\n" +
+ " errors and warnings\n" +
" syncOverride missing synchronized in synchr. method override\n" +
" syntheticAccess synthetic access for innerclass\n" +
" tasks(<tags separated by |>) tasks identified by tags inside comments\n" +
@@ -1883,6 +1886,7 @@
" <option key=\"org.eclipse.jdt.core.compiler.problem.redundantSuperinterface\" value=\"ignore\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.specialParameterHidingField\" value=\"disabled\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.staticAccessReceiver\" value=\"warning\"/>\n" +
+ " <option key=\"org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors\" value=\"disabled\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.suppressWarnings\" value=\"enabled\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation\" value=\"ignore\"/>\n" +
" <option key=\"org.eclipse.jdt.core.compiler.problem.tasks\" value=\"warning\"/>\n" +
@@ -11269,4 +11273,163 @@
"invalid error configuration: \'-err\'\n",
true);
}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551
+public void test298(){
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " @SuppressWarnings(\"unused\")\n" +
+ " private int i;\n" +
+ "}",
+ },
+ "\"" + OUTPUT_DIR + File.separator + "X.java\""
+ + " -1.5 -g -preserveAllLocals"
+ + " -proceedOnError -err:+unused,suppress -d \"" + OUTPUT_DIR + "\"",
+ "",
+ "",
+ true);
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551
+public void test299(){
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " @SuppressWarnings(\"unused\")\n" +
+ " private int i;\n" +
+ "}",
+ },
+ "\"" + OUTPUT_DIR + File.separator + "X.java\""
+ + " -1.5 -g -preserveAllLocals"
+ + " -proceedOnError -err:+unused -d \"" + OUTPUT_DIR + "\"",
+ "",
+ "----------\n" +
+ "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 2)\n" +
+ " @SuppressWarnings(\"unused\")\n" +
+ " ^^^^^^^^\n" +
+ "Unnecessary @SuppressWarnings(\"unused\")\n" +
+ "----------\n" +
+ "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
+ " private int i;\n" +
+ " ^\n" +
+ "The field X.i is never read locally\n" +
+ "----------\n" +
+ "2 problems (1 error, 1 warning)",
+ true);
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551
+public void test300(){
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " @SuppressWarnings(\"unused\")\n" +
+ " private int i;\n" +
+ "}",
+ },
+ "\"" + OUTPUT_DIR + File.separator + "X.java\""
+ + " -1.5 -g -preserveAllLocals"
+ + " -proceedOnError -warn:-suppress -err:+suppress,unused -d \"" + OUTPUT_DIR + "\"",
+ "",
+ "",
+ true);
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551
+public void test301(){
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " @SuppressWarnings(\"unused\")\n" +
+ " private int i;\n" +
+ "}",
+ },
+ "\"" + OUTPUT_DIR + File.separator + "X.java\""
+ + " -1.5 -g -preserveAllLocals"
+ + " -proceedOnError -warn:-suppress -err:+unused -d \"" + OUTPUT_DIR + "\"",
+ "",
+ "----------\n" +
+ "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
+ " private int i;\n" +
+ " ^\n" +
+ "The field X.i is never read locally\n" +
+ "----------\n" +
+ "1 problem (1 error)",
+ true);
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551
+public void test302(){
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " @SuppressWarnings(\"unused\")\n" +
+ " private int i;\n" +
+ "}",
+ },
+ "\"" + OUTPUT_DIR + File.separator + "X.java\""
+ + " -1.5 -g -preserveAllLocals"
+ + " -proceedOnError -warn:-suppress -err:+suppress,unused -warn:-suppress -d \"" + OUTPUT_DIR + "\"",
+ "",
+ "----------\n" +
+ "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
+ " private int i;\n" +
+ " ^\n" +
+ "The field X.i is never read locally\n" +
+ "----------\n" +
+ "1 problem (1 error)",
+ true);
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551
+public void test303(){
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " @SuppressWarnings(\"unused\")\n" +
+ " private int i;\n" +
+ "}",
+ },
+ "\"" + OUTPUT_DIR + File.separator + "X.java\""
+ + " -1.5 -g -preserveAllLocals"
+ + " -proceedOnError -warn:-suppress -err:+suppress,unused -warn:+suppress -d \"" + OUTPUT_DIR + "\"",
+ "",
+ "----------\n" +
+ "1. WARNING in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 2)\n" +
+ " @SuppressWarnings(\"unused\")\n" +
+ " ^^^^^^^^\n" +
+ "Unnecessary @SuppressWarnings(\"unused\")\n" +
+ "----------\n" +
+ "2. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
+ " private int i;\n" +
+ " ^\n" +
+ "The field X.i is never read locally\n" +
+ "----------\n" +
+ "2 problems (1 error, 1 warning)",
+ true);
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=295551
+public void test304(){
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " @SuppressWarnings(\"unused\")\n" +
+ " private int i;\n" +
+ "}",
+ },
+ "\"" + OUTPUT_DIR + File.separator + "X.java\""
+ + " -1.5 -g -preserveAllLocals"
+ + " -proceedOnError -err:+suppress,unused -warn:-suppress -d \"" + OUTPUT_DIR + "\"",
+ "",
+ "----------\n" +
+ "1. ERROR in ---OUTPUT_DIR_PLACEHOLDER---/X.java (at line 3)\n" +
+ " private int i;\n" +
+ " ^\n" +
+ "The field X.i is never read locally\n" +
+ "----------\n" +
+ "1 problem (1 error)",
+ true);
+}
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java
index 6e9c60a..fb65fd2 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CastTest.java
@@ -1782,6 +1782,93 @@
"----------\n"
);
}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=302919
+public void test048() {
+ CompilerOptions options = new CompilerOptions(getCompilerOptions());
+ if (options.sourceLevel < ClassFileConstants.JDK1_5) return;
+ this.runNegativeTest(
+ new String[] {
+ "A.java",
+ "public class A<T> extends D<T> {\n" +
+ " public class A1 extends D1 {\n" +
+ " }\n" +
+ " void m1(A<T> tree) {\n" +
+ " A.A1 v = ((A.A1) tree.root);\n" +
+ " }\n" +
+ " Zork z;\n" +
+ "}\n" +
+ "class D<T> {\n" +
+ " protected D1 root;\n" +
+ " protected class D1 {\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in A.java (at line 7)\n" +
+ " Zork z;\n" +
+ " ^^^^\n" +
+ "Zork cannot be resolved to a type\n" +
+ "----------\n"
+ );
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=302919
+public void test049() {
+ CompilerOptions options = new CompilerOptions(getCompilerOptions());
+ if (options.sourceLevel < ClassFileConstants.JDK1_5) return;
+ this.runNegativeTest(
+ new String[] {
+ "A.java",
+ "public class A {\n" +
+ " void foo(Other2<?>.Member2<?> om2) {\n" +
+ " Other<?>.Member m = (Other<?>.Member) om2;\n" +
+ " m = om2;\n" +
+ " }\n" +
+ "}\n" +
+ "class Other<T> {\n" +
+ " class Member {}\n" +
+ "}\n" +
+ "class Other2<T> extends Other<T> {\n" +
+ " class Member2<U> extends Other<U>.Member {\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. WARNING in A.java (at line 3)\n" +
+ " Other<?>.Member m = (Other<?>.Member) om2;\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Unnecessary cast from Other2<?>.Member2<capture#1-of ?> to Other<?>.Member\n" +
+ "----------\n"
+ );
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=302919
+public void test050() {
+ CompilerOptions options = new CompilerOptions(getCompilerOptions());
+ if (options.sourceLevel < ClassFileConstants.JDK1_5) return;
+ this.runNegativeTest(
+ new String[] {
+ "A.java",
+ "public class A<T> extends D<T> {\n" +
+ " public class A1 extends D.D1 {\n" +
+ " }\n" +
+ " void m1(A<T> tree) {\n" +
+ " A.A1 v = ((A.A1) tree.root);\n" +
+ " }\n" +
+ " Zork z;\n" +
+ "}\n" +
+ "class D<T> {\n" +
+ " protected D1 root;\n" +
+ " protected class D1 {\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. ERROR in A.java (at line 7)\n" +
+ " Zork z;\n" +
+ " ^^^^\n" +
+ "Zork cannot be resolved to a type\n" +
+ "----------\n"
+ );
+}
public static Class testClass() {
return CastTest.class;
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
index 4e20231..cebf4a2 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/CompilerInvocationTests.java
@@ -190,9 +190,9 @@
" }\n" +
"}\n"},
null,
- "[FIXME,message contents,HIGH]\n" +
- "[TODO,message contents,NORMAL]\n" +
- "[XXX,message contents,NORMAL]\n");
+ "[FIXME, message contents,HIGH]\n" +
+ "[TODO, message contents,NORMAL]\n" +
+ "[XXX, message contents,NORMAL]\n");
}
// effect of cancelling priorities
// reactivate when bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=143402 is fixed
@@ -208,9 +208,9 @@
" }\n" +
"}\n"},
customOptions,
- "[FIXME,message contents,NORMAL]\n" +
- "[TODO,message contents,NORMAL]\n" +
- "[XXX,message contents,NORMAL]\n");
+ "[FIXME, message contents,NORMAL]\n" +
+ "[TODO, message contents,NORMAL]\n" +
+ "[XXX, message contents,NORMAL]\n");
}
// effect of cancelling priorities
// reactivate when bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=143402 is fixed
@@ -263,9 +263,9 @@
" }\n" +
"}\n"},
customOptions,
- "[FIXME,message contents,NORMAL]\n" +
- "[TODO,message contents,NORMAL]\n" +
- "[XXX,message contents,NORMAL]\n");
+ "[FIXME, message contents,NORMAL]\n" +
+ "[TODO, message contents,NORMAL]\n" +
+ "[XXX, message contents,NORMAL]\n");
}
// effect of changing priorities
// reactivate when bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=143402 is fixed
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_3.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_3.java
index 2e03682..896383b 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_3.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_3.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation 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
@@ -1222,7 +1222,8 @@
"----------\n",
null,
true,
- customOptions);
+ customOptions,
+ "java.lang.ClassNotFoundException");
}
/*
@@ -3194,7 +3195,11 @@
" Object bar(I i) throws CloneNotSupportedException { return i.clone(); }\n" +
" ^^^^^^^^^\n" +
"Access to enclosing method clone() from the type Object is emulated by a synthetic accessor method\n" +
- "----------\n"
+ "----------\n",
+ null,
+ true,
+ null,
+ "java.lang.ClassFormatError"
// no compile errors but generates ClassFormatError if run
);
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java
index 7be85c0..5edd701 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_4.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation 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
@@ -1214,7 +1214,8 @@
"----------\n",
null,
true,
- customOptions);
+ customOptions,
+ "java.lang.ClassNotFoundException");
}
/*
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java
index e32145a..d2f1c7b 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/Compliance_1_5.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation 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
@@ -1245,7 +1245,7 @@
"----------\n",
// runtime results
null /* do not check output string */,
- null /* do not check error string */,
+ "java.lang.ClassNotFoundException" /* do not check error string */,
// javac options
JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings /* javac test options */);
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ExternalizeStringLiterals15Test.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ExternalizeStringLiterals15Test.java
index 87f86d6..6da24bd 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ExternalizeStringLiterals15Test.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ExternalizeStringLiterals15Test.java
@@ -68,8 +68,8 @@
"class X {\n" +
" String s2 = \"test1\"; //$NON-NLS-1$\n" +
" String s3 = \"test2\"; //$NON-NLS-1$//$NON-NLS-2$\n" +
- " \n" +
- " @SuppressWarnings(\"nls\")\n" +
+ "\n" +
+ "\n" +
" void foo() {\n" +
" String s4 = null;\n" +
" String s5 = \"test3\";\n" +
@@ -112,8 +112,8 @@
"class X {\n" +
" String s2 = \"test1\"; //$NON-NLS-1$\n" +
" String s3 = \"test2\"; //$NON-NLS-1$//$NON-NLS-2$\n" +
- " \n" +
- " @SuppressWarnings(\"nls\")\n" +
+ "\n" +
+ "\n" +
" void foo() {\n" +
" String s4 = null;\n" +
" String s5 = null;//$NON-NLS-1$\n" +
@@ -184,7 +184,7 @@
new String[] {
"X.java",
"class X {\n" +
- " @SuppressWarnings(\"nls\")\n" +
+ "\n" +
" void foo() {\n" +
" String s6 = \"SUCCESS\";\n" +
" System.out.println(s6);\n" +
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FieldAccessTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FieldAccessTest.java
index eebfc9e..29e3315 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FieldAccessTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/FieldAccessTest.java
@@ -19,7 +19,7 @@
public class FieldAccessTest extends AbstractRegressionTest {
static {
// TESTS_NAMES = new String[] { "test000" };
-// TESTS_NUMBERS = new int[] { 5, 6 };
+// TESTS_NUMBERS = new int[] { 21 };
// TESTS_RANGE = new int[] { 21, 50 };
}
@@ -623,6 +623,32 @@
true,
options);
}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=303830
+public void test021() {
+ Map options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE);
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "import java.util.ArrayList;\n" +
+ "\n" +
+ "public class X {\n" +
+ " public void bar() {\n" +
+ " ArrayList myList = new ArrayList();\n" +
+ " int len = myList.length;\n" +
+ " }\n" +
+ "}"
+ },
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " int len = myList.length;\n" +
+ " ^^^^^^\n" +
+ "length cannot be resolved or is not a field\n" +
+ "----------\n",
+ null,
+ true,
+ options);
+}
public static Class testClass() {
return FieldAccessTest.class;
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java
index 1888942..df86df5 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/GenericTypeTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation 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
@@ -32,7 +32,7 @@
// All specified tests which does not belong to the class are skipped...
static {
// TESTS_NAMES = new String[] { "test0788" };
-// TESTS_NUMBERS = new int[] { 1459 };
+// TESTS_NUMBERS = new int[] { 1455 };
// TESTS_RANGE = new int[] { 1097, -1 };
}
public static Test suite() {
@@ -2125,8 +2125,8 @@
"----------\n" +
"1. ERROR in X.java (at line 9)\n" +
" super(xt.t);\n" +
- " ^^^^\n" +
- "xt.t cannot be resolved or is not a field\n" +
+ " ^\n" +
+ "t cannot be resolved or is not a field\n" +
"----------\n" +
"2. WARNING in X.java (at line 12)\n" +
" X x = new X();\n" +
@@ -6468,7 +6468,7 @@
"----------\n",
// runtime results
null /* do not check output string */,
- null /* do not check error string */,
+ "java.lang.IndexOutOfBoundsException" /* do not check error string */,
// javac options
JavacTestOptions.Excuse.EclipseHasSomeMoreWarnings /* javac test options */);
}
@@ -14398,52 +14398,57 @@
" } \n" +
"}\n"
},
- "----------\n" +
- "1. WARNING in test\\Foo.java (at line 4)\n" +
- " private R dosomething(){ return s; } \n" +
- " ^^^^^^^^^^^^^\n" +
- "The method dosomething() from the type Foo<R> is never used locally\n" +
- "----------\n" +
- "2. WARNING in test\\Foo.java (at line 5)\n" +
- " private class Bar {} \n" +
- " ^^^\n" +
- "The type Foo<R>.Bar is never used locally\n" +
- "----------\n" +
- "----------\n" +
- "1. ERROR in test02\\FooBar.java (at line 6)\n" +
- " f.s = \"foo\"; \n" +
- " ^\n" +
- "The field Foo<String>.s is not visible\n" +
- "----------\n" +
- "2. ERROR in test02\\FooBar.java (at line 7)\n" +
- " this.s = \"foo\";\n" +
- " ^\n" +
- "The field Foo<R>.s is not visible\n" +
- "----------\n" +
- "3. ERROR in test02\\FooBar.java (at line 8)\n" +
- " f.dosomething(); \n" +
- " ^^^^^^^^^^^\n" +
- "The method dosomething() from the type Foo<String> is not visible\n" +
- "----------\n" +
- "4. ERROR in test02\\FooBar.java (at line 9)\n" +
- " this.dosomething(); \n" +
- " ^^^^^^^^^^^\n" +
- "The method dosomething() from the type Foo<R> is not visible\n" +
- "----------\n" +
- "5. ERROR in test02\\FooBar.java (at line 10)\n" +
- " Bar b1; \n" +
- " ^^^\n" +
- "The type Bar is not visible\n" +
- "----------\n" +
- "6. ERROR in test02\\FooBar.java (at line 11)\n" +
- " FooBar<String>.Bar b2; \n" +
- " ^^^^^^^^^^^^^^^^^^\n" +
- "The type FooBar.Bar is not visible\n" +
- "----------\n" +
- "7. ERROR in test02\\FooBar.java (at line 12)\n" +
- " Foo<String>.Bar b3; \n" +
- " ^^^^^^^^^^^^^^^\n" +
- "The type Foo.Bar is not visible\n" +
+ "----------\n" +
+ "1. WARNING in test\\Foo.java (at line 4)\n" +
+ " private R dosomething(){ return s; } \n" +
+ " ^^^^^^^^^^^^^\n" +
+ "The method dosomething() from the type Foo<R> is never used locally\n" +
+ "----------\n" +
+ "2. WARNING in test\\Foo.java (at line 5)\n" +
+ " private class Bar {} \n" +
+ " ^^^\n" +
+ "The type Foo<R>.Bar is never used locally\n" +
+ "----------\n" +
+ "----------\n" +
+ "1. ERROR in test02\\FooBar.java (at line 6)\n" +
+ " f.s = \"foo\"; \n" +
+ " ^\n" +
+ "The field Foo<String>.s is not visible\n" +
+ "----------\n" +
+ "2. ERROR in test02\\FooBar.java (at line 7)\n" +
+ " this.s = \"foo\";\n" +
+ " ^\n" +
+ "The field Foo<R>.s is not visible\n" +
+ "----------\n" +
+ "3. ERROR in test02\\FooBar.java (at line 7)\n" +
+ " this.s = \"foo\";\n" +
+ " ^^^^^\n" +
+ "Type mismatch: cannot convert from String to R\n" +
+ "----------\n" +
+ "4. ERROR in test02\\FooBar.java (at line 8)\n" +
+ " f.dosomething(); \n" +
+ " ^^^^^^^^^^^\n" +
+ "The method dosomething() from the type Foo<String> is not visible\n" +
+ "----------\n" +
+ "5. ERROR in test02\\FooBar.java (at line 9)\n" +
+ " this.dosomething(); \n" +
+ " ^^^^^^^^^^^\n" +
+ "The method dosomething() from the type Foo<R> is not visible\n" +
+ "----------\n" +
+ "6. ERROR in test02\\FooBar.java (at line 10)\n" +
+ " Bar b1; \n" +
+ " ^^^\n" +
+ "The type Bar is not visible\n" +
+ "----------\n" +
+ "7. ERROR in test02\\FooBar.java (at line 11)\n" +
+ " FooBar<String>.Bar b2; \n" +
+ " ^^^^^^^^^^^^^^^^^^\n" +
+ "The type FooBar.Bar is not visible\n" +
+ "----------\n" +
+ "8. ERROR in test02\\FooBar.java (at line 12)\n" +
+ " Foo<String>.Bar b3; \n" +
+ " ^^^^^^^^^^^^^^^\n" +
+ "The type Foo.Bar is not visible\n" +
"----------\n");
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=81594
@@ -36688,8 +36693,8 @@
"----------\n" +
"7. ERROR in Y.java (at line 9)\n" +
" E e2 = e2.e;\n" +
- " ^^^^\n" +
- "e2.e cannot be resolved or is not a field\n" +
+ " ^\n" +
+ "e cannot be resolved or is not a field\n" +
"----------\n");
}
@@ -45578,11 +45583,11 @@
" }\n" +
"}\n", // =================
},
- "----------\n" +
- "1. ERROR in X.java (at line 3)\n" +
- " Other<String>.Member m = (Other<String>.Member) om2;\n" +
- " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Cannot cast from Other2<?>.Member2<capture#1-of ?> to Other<String>.Member\n" +
+ "----------\n" +
+ "1. WARNING in X.java (at line 3)\n" +
+ " Other<String>.Member m = (Other<String>.Member) om2;\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Type safety: Unchecked cast from Other2<?>.Member2<capture#1-of ?> to Other<String>.Member\n" +
"----------\n");
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=233800 - variation
@@ -45603,11 +45608,11 @@
" }\n" +
"}\n", // =================
},
- "----------\n" +
- "1. ERROR in X.java (at line 3)\n" +
- " Other<String>.Member m = (Other<String>.Member) om2;\n" +
- " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
- "Cannot cast from Other2.Member2<capture#1-of ?> to Other<String>.Member\n" +
+ "----------\n" +
+ "1. WARNING in X.java (at line 3)\n" +
+ " Other<String>.Member m = (Other<String>.Member) om2;\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Type safety: Unchecked cast from Other2.Member2<capture#1-of ?> to Other<String>.Member\n" +
"----------\n");
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=234619
@@ -45667,10 +45672,11 @@
new String[] {
"Derived_A.java", // =================
"import java.util.Map;\n" +
+ "import java.util.HashMap;\n" +
"class Base_A {}\n" +
"public class Derived_A extends Base_A {\n" +
" public Map<Object, Base_B> getMap() {\n" +
- " return null;\n" +
+ " return new HashMap<Object, Base_B>();\n" +
" }\n" +
"}\n", // =================
"Derived_B.java", // =================
@@ -49797,8 +49803,8 @@
public void test1455() {
this.runNegativeTest(
new String[] {
- "X.java",
- "class Outer<E> {\n" +
+ "Outer.java",
+ "public class Outer<E> {\n" +
" Inner inner;\n" +
" class Inner {\n" +
" E e;\n" +
@@ -49821,7 +49827,7 @@
"}"
},
"----------\n" +
- "1. WARNING in X.java (at line 8)\n" +
+ "1. WARNING in Outer.java (at line 8)\n" +
" Inner that = (Inner) other;\n" +
" ^^^^^^^^^^^^^\n" +
"Type safety: Unchecked cast from Object to Outer<E>.Inner\n" +
@@ -50089,4 +50095,64 @@
"Type safety: The expression of type Set needs unchecked conversion to conform to Set<SimpleExample.Data>\n" +
"----------\n");
}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=268798
+public void test268798() {
+ this.runNegativeTest(
+ new String[] {
+ "GenericDemo.java",
+ "import java.util.Collections;\n" +
+ "import java.util.List;\n" +
+ "public class GenericDemo {\n" +
+ " static class A implements Comparable {\n" +
+ " public int compareTo(Object o) {\n" +
+ " return 0;\n" +
+ " }\n" +
+ " }\n" +
+ " void someCode(List<A> list) {\n" +
+ " A min = Collections.min(list); \n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. WARNING in GenericDemo.java (at line 4)\n" +
+ " static class A implements Comparable {\n" +
+ " ^^^^^^^^^^\n" +
+ "Comparable is a raw type. References to generic type Comparable<T> should be parameterized\n" +
+ "----------\n" +
+ "2. WARNING in GenericDemo.java (at line 10)\n" +
+ " A min = Collections.min(list); \n" +
+ " ^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Type safety: Unchecked invocation min(List<GenericDemo.A>) of the generic method min(Collection<? extends T>) of type Collections\n" +
+ "----------\n");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=268798
+public void test268798a() {
+ this.runNegativeTest(
+ new String[] {
+ "Bug268798.java",
+ "public class Bug268798 {\n" +
+ " interface SomeInterface<T> {\n" +
+ " }\n" +
+ " class A implements SomeInterface {\n" +
+ " }\n" +
+ " <T extends SomeInterface<? super T>> T someMethod() {\n" +
+ " return null;\n" +
+ " }\n" +
+ " void someCode() {\n" +
+ " A a = someMethod();\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. WARNING in Bug268798.java (at line 4)\n" +
+ " class A implements SomeInterface {\n" +
+ " ^^^^^^^^^^^^^\n" +
+ "Bug268798.SomeInterface is a raw type. References to generic type Bug268798.SomeInterface<T> should be parameterized\n" +
+ "----------\n" +
+ "2. WARNING in Bug268798.java (at line 10)\n" +
+ " A a = someMethod();\n" +
+ " ^^^^^^^^^^^^\n" +
+ "Type safety: Unchecked invocation someMethod() of the generic method someMethod() of type Bug268798\n" +
+ "----------\n");
+}
}
\ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InnerEmulationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InnerEmulationTest.java
index 761c748..a8adfa0 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InnerEmulationTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/InnerEmulationTest.java
@@ -25,7 +25,7 @@
public class InnerEmulationTest extends AbstractRegressionTest {
static {
// TESTS_NAMES = new String[] { "Bug58069" };
-// TESTS_NUMBERS = new int[] { 155 };
+// TESTS_NUMBERS = new int[] { 23, 24 };
// TESTS_RANGE = new int[] { 144, -1 };
}
public InnerEmulationTest(String name) {
@@ -1001,10 +1001,11 @@
* No need for protected access emulation
*/
public void test023() {
- this.runNegativeTest(
+ this.runConformTest(
new String[] {
/* X.java */
"p/X.java",
+ "package p; \n" +
"public class X extends q.Y { \n" +
" void bar(){ Object o = someObject; } \n"+
" public static void main(String[] argv){ \n" +
@@ -1019,14 +1020,14 @@
" protected Object someObject; \n" +
"}\n"
},
- "" // no problem log: not even a synthetic access emulation one
+ "SUCCESS"
);
}
/**
* No need for protected access emulation
*/
public void test024() {
- this.runNegativeTest(
+ this.runConformTest(
new String[] {
/* X.java */
"p/X.java",
@@ -1045,7 +1046,7 @@
" protected Object foo(){ return null;} \n" +
"}\n"
},
- "" // no problem log: not even a synthetic access emulation one
+ "SUCCESS"
);
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocBugsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocBugsTest.java
index 0607e81..6234f5a 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocBugsTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocBugsTest.java
@@ -6408,7 +6408,7 @@
this.reportMissingJavadocTags = CompilerOptions.ERROR;
runConformTest(
new String[] {
- "src/JavaDocTest.java",
+ "JavaDocTest.java",
"public interface JavaDocTest\n" +
"{\n" +
" /**\n" +
@@ -7174,7 +7174,7 @@
this.runConformTest(
true,
new String[] {
- "pkg/X.java",
+ "X.java",
"public class X {\n" +
"private int unused1;\n" +
"\n" +
@@ -7187,12 +7187,12 @@
null,
customOptions,
"----------\n" +
- "1. WARNING in pkg\\X.java (at line 2)\n" +
+ "1. WARNING in X.java (at line 2)\n" +
" private int unused1;\n" +
" ^^^^^^^\n" +
"The field X.unused1 is never read locally\n" +
"----------\n" +
- "2. WARNING in pkg\\X.java (at line 7)\n" +
+ "2. WARNING in X.java (at line 7)\n" +
" private int unused2;\n" +
" ^^^^^^^\n" +
"The field X.unused2 is never read locally\n" +
@@ -7949,7 +7949,7 @@
public void testBug237937() {
runConformTest(
new String[] {
- "src/Link.java",
+ "Link.java",
"/**\n" +
" * @see <a href=\"http://www.eclipse.org/\">http://www.eclipse.org</a>\n" +
" * @see <a href=\"http://www.eclipse.org/\">//</a>\n" +
@@ -7968,7 +7968,7 @@
this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS;
runConformTest(
new String[] {
- "src/X.java",
+ "X.java",
"public class X {\n" +
"\n" +
" /**\n" +
@@ -7981,7 +7981,7 @@
" return \"X\";\n" +
" }\n" +
"}\n",
- "src/Y.java",
+ "Y.java",
"public class Y extends X {\n" +
"\n" +
" /**\n" +
@@ -8003,7 +8003,7 @@
this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS;
runConformTest(
new String[] {
- "src/X.java",
+ "X.java",
"/**\n" +
" * @author {@link String}\n" +
" * @since {@link String}\n" +
@@ -8033,7 +8033,7 @@
this.reportMissingJavadocDescription = CompilerOptions.ALL_STANDARD_TAGS;
runConformTest(
new String[] {
- "src/X.java",
+ "X.java",
"public class X {\n" +
"\n" +
" final static int WAIT_YES = 0;\n" +
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java
index 703a2bf..73537bd 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/JavadocTest.java
@@ -458,7 +458,6 @@
boolean shouldFlushOutputDirectory) {
String testName = null;
Process compileProcess = null;
- Process execProcess = null;
try {
// Init test name
testName = testName();
@@ -589,7 +588,6 @@
}
catch (InterruptedException e1) {
if (compileProcess != null) compileProcess.destroy();
- if (execProcess != null) execProcess.destroy();
System.out.println(testName+": Sun javadoc compilation was aborted!");
javacFullLog.println("JAVAC_WARNING: Sun javadoc compilation was aborted!");
e1.printStackTrace(javacFullLog);
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java
index c48bdff..5ff18a8 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/LookupTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation 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
@@ -216,15 +216,15 @@
"}"
},
"----------\n" +
- "1. WARNING in p1\\A.java (at line 3)\n" +
- " private static String success = \"SUCCESS\"; \n" +
- " ^^^^^^^\n" +
- "The field A.success is never read locally\n" +
- "----------\n" +
- "2. ERROR in p1\\A.java (at line 7)\n" +
+ "1. ERROR in p1\\A.java (at line 7)\n" +
" public void aTask() {System.out.println(this.success);}\n" +
" ^^^^^^^\n" +
"The field A.success is not visible\n" +
+ "----------\n" +
+ "2. WARNING in p1\\A.java (at line 7)\n" +
+ " public void aTask() {System.out.println(this.success);}\n" +
+ " ^^^^^^^\n" +
+ "The static field A.success should be accessed in a static way\n" +
"----------\n");
}
/**
@@ -308,12 +308,7 @@
"}"
},
"----------\n" +
- "1. WARNING in p1\\A.java (at line 3)\n" +
- " private String success = \"SUCCESS\"; \n" +
- " ^^^^^^^\n" +
- "The field A.success is never read locally\n" +
- "----------\n" +
- "2. ERROR in p1\\A.java (at line 7)\n" +
+ "1. ERROR in p1\\A.java (at line 7)\n" +
" public void aTask() {System.out.println(this.success);}\n" +
" ^^^^^^^\n" +
"The field A.success is not visible\n" +
@@ -656,8 +651,8 @@
"----------\n" +
"1. ERROR in p1\\A.java (at line 17)\n" +
" System.out.println(foo.rating + bar.other); \n" +
- " ^^^^^^^^^\n" +
- "bar.other cannot be resolved or is not a field\n" +
+ " ^^^^^\n" +
+ "other cannot be resolved or is not a field\n" +
"----------\n"
);
}
@@ -693,8 +688,8 @@
"----------\n" +
"2. ERROR in p1\\A.java (at line 13)\n" +
" System.out.println(foo.rating + bar.other); \n" +
- " ^^^^^^^^^\n" +
- "bar.other cannot be resolved or is not a field\n" +
+ " ^^^^^\n" +
+ "other cannot be resolved or is not a field\n" +
"----------\n");
}
/**
@@ -2891,8 +2886,8 @@
"----------\n" +
"1. ERROR in X.java (at line 5)\n" +
" System.out.println(y.length);\n" +
- " ^^^^^^^^\n" +
- "y.length cannot be resolved or is not a field\n" +
+ " ^^^^^^\n" +
+ "length cannot be resolved or is not a field\n" +
"----------\n");
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=185422 - variation
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java
index 7ef848e..08116c5 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/MethodVerifyTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation 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
@@ -27,7 +27,7 @@
public class MethodVerifyTest extends AbstractComparableTest {
static {
// TESTS_NAMES = new String[] { "test000" };
-// TESTS_NUMBERS = new int[] { 121 };
+// TESTS_NUMBERS = new int[] { 184 };
// TESTS_RANGE = new int[] { 190, -1};
}
@@ -8088,7 +8088,11 @@
" Enum<?> foo() {\n" +
" ^^^^\n" +
"Type safety: The return type Enum<?> for foo() from the type X.B needs unchecked conversion to conform to U from the type X.A<T>\n" +
- "----------\n");
+ "----------\n",
+ null,
+ true,
+ null,
+ "java.lang.ClassCastException");
}
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=180789
public void test128() {
@@ -8275,7 +8279,7 @@
public void test134() {
this.runNegativeTest(
new String[] {
- "X.java",
+ "A.java",
"interface I {\n" +
" <T extends Exception & Cloneable> T foo(Number n);\n" +
"}\n" +
@@ -8287,7 +8291,7 @@
"}"
},
"----------\n" +
- "1. WARNING in X.java (at line 5)\n" +
+ "1. WARNING in A.java (at line 5)\n" +
" A foo(Number n);\n" +
" ^\n" +
"Type safety: The return type A for foo(Number) from the type J needs unchecked conversion to conform to T from the type I\n" +
@@ -10015,7 +10019,7 @@
public void test184() {
this.runNegativeTest(
new String[] {
- "X.java",
+ "A.java",
"class A<U extends Number> {\n" +
" <T extends A<Number>> T a() { return null; }\n" +
" <T extends Number> U num() { return null; }\n" +
@@ -10047,42 +10051,42 @@
"}"
},
"----------\n" +
- "1. WARNING in X.java (at line 6)\n" +
+ "1. WARNING in A.java (at line 6)\n" +
" <T extends Integer> T z() { return null; }\n" +
" ^^^^^^^\n" +
"The type parameter T should not be bounded by the final type Integer. Final types cannot be further extended\n" +
"----------\n" +
- "2. WARNING in X.java (at line 9)\n" +
+ "2. WARNING in A.java (at line 9)\n" +
" @Override A a() { return null; }\n" +
" ^\n" +
"A is a raw type. References to generic type A<U> should be parameterized\n" +
"----------\n" +
- "3. WARNING in X.java (at line 9)\n" +
+ "3. WARNING in A.java (at line 9)\n" +
" @Override A a() { return null; }\n" +
" ^\n" +
"Type safety: The return type A for a() from the type B needs unchecked conversion to conform to T from the type A<U>\n" +
"----------\n" +
- "4. WARNING in X.java (at line 11)\n" +
+ "4. WARNING in A.java (at line 11)\n" +
" @Override Integer x() { return 1; }\n" +
" ^^^^^^^\n" +
"Type safety: The return type Integer for x() from the type B needs unchecked conversion to conform to T from the type A<U>\n" +
"----------\n" +
- "5. WARNING in X.java (at line 12)\n" +
+ "5. WARNING in A.java (at line 12)\n" +
" @Override Integer y() { return 1; }\n" +
" ^^^^^^^\n" +
"Type safety: The return type Integer for y() from the type B needs unchecked conversion to conform to T from the type A<U>\n" +
"----------\n" +
- "6. WARNING in X.java (at line 13)\n" +
+ "6. WARNING in A.java (at line 13)\n" +
" @Override Integer z() { return 1; }\n" +
" ^^^^^^^\n" +
"Type safety: The return type Integer for z() from the type B needs unchecked conversion to conform to T from the type A<U>\n" +
"----------\n" +
- "7. WARNING in X.java (at line 15)\n" +
+ "7. WARNING in A.java (at line 15)\n" +
" class C extends A {\n" +
" ^\n" +
"A is a raw type. References to generic type A<U> should be parameterized\n" +
"----------\n" +
- "8. WARNING in X.java (at line 16)\n" +
+ "8. WARNING in A.java (at line 16)\n" +
" @Override A a() { return null; }\n" +
" ^\n" +
"A is a raw type. References to generic type A<U> should be parameterized\n" +
@@ -10731,4 +10735,101 @@
"Name clash: The method put(K, V) of type OverrideBug<K,V> has the same erasure as put(K, V) of type Map<K,V> but does not override it\n" +
"----------\n");
}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=298362
+public void test205() {
+ this.runConformTest(
+ new String[] {
+ "Tester.java",
+ "import java.lang.reflect.Method;\n" +
+ "\n" +
+ "public class Tester {\n" +
+ "\n" +
+ " public static interface Converter<T> {\n" +
+ " T convert(String input);\n" +
+ " }\n" +
+ "\n" +
+ " public static abstract class EnumConverter<T extends Enum<T>> implements Converter<Enum<T>> {\n" +
+ " public final T convert(String input) {\n" +
+ " return null;\n" +
+ " }\n" +
+ " }\n" +
+ "\n" +
+ " public static class SomeEnumConverter extends EnumConverter<Thread.State> {\n" +
+ " }\n" +
+ "\n" +
+ " public static void main(String[] args) throws Exception {\n" +
+ " Method m = SomeEnumConverter.class.getMethod(\"convert\", String.class);\n" +
+ " System.out.println(m.getGenericReturnType());\n" +
+ " }\n" +
+ "\n" +
+ "}\n"
+
+ },
+ "T");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=298362 (variation)
+public void test206() {
+ this.runConformTest(
+ new String[] {
+ "Tester.java",
+ "import java.lang.reflect.Method;\n" +
+ "\n" +
+ "public class Tester {\n" +
+ "\n" +
+ " public static interface Converter<T> {\n" +
+ " T convert(String input);\n" +
+ " }\n" +
+ "\n" +
+ " public static abstract class EnumConverter<T extends Enum<T>> implements Converter<T> {\n" +
+ " public final T convert(String input) {\n" +
+ " return null;\n" +
+ " }\n" +
+ " }\n" +
+ "\n" +
+ " public static class SomeEnumConverter extends EnumConverter<Thread.State> {\n" +
+ " }\n" +
+ "\n" +
+ " public static void main(String[] args) throws Exception {\n" +
+ " Method m = SomeEnumConverter.class.getMethod(\"convert\", String.class);\n" +
+ " System.out.println(m.getGenericReturnType());\n" +
+ " }\n" +
+ "\n" +
+ "}\n"
+
+ },
+ "T");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=298362 (variation)
+// Note that this test prints "T" with javac5 and "class java.lang.Object with javac 6,7
+public void test207() {
+ this.runConformTest(
+ new String[] {
+ "Tester.java",
+ "import java.lang.reflect.Method;\n" +
+ "\n" +
+ "public class Tester {\n" +
+ "\n" +
+ " public static interface Converter<T> {\n" +
+ " T convert(String input);\n" +
+ " }\n" +
+ "\n" +
+ " public static abstract class EnumConverter<T extends Enum<T>, K> implements Converter<T> {\n" +
+ " public final T convert(K input) {\n" +
+ " return null;\n" +
+ " }\n" +
+ " }\n" +
+ "\n" +
+ " public static class SomeEnumConverter extends EnumConverter<Thread.State, String> {\n" +
+ " }\n" +
+ "\n" +
+ " public static void main(String[] args) throws Exception {\n" +
+ " Method m = SomeEnumConverter.class.getMethod(\"convert\", String.class);\n" +
+ " System.out.println(m.getGenericReturnType());\n" +
+ " }\n" +
+ "\n" +
+ "}\n"
+
+ },
+ "class java.lang.Object");
+}
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java
index ddd34e0..33247b2 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/NullReferenceTest.java
@@ -10,10 +10,14 @@
*******************************************************************************/
package org.eclipse.jdt.core.tests.compiler.regression;
+import java.io.File;
import java.util.Map;
import junit.framework.Test;
+import org.eclipse.jdt.core.ToolFactory;
+import org.eclipse.jdt.core.tests.util.Util;
+import org.eclipse.jdt.core.util.ClassFileBytesDisassembler;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
@@ -22,29 +26,25 @@
public class NullReferenceTest extends AbstractRegressionTest {
public NullReferenceTest(String name) {
- super(name);
+ super(name);
}
// Static initializer to specify tests subset using TESTS_* static variables
- // All specified tests which does not belong to the class are skipped...
- // Only the highest compliance level is run; add the VM argument
- // -Dcompliance=1.4 (for example) to lower it if needed
- static {
-// TESTS_NAMES = new String[] { "test011" };
-// TESTS_NUMBERS = new int[] { 561 };
-// TESTS_NUMBERS = new int[] { 2999 };
-// TESTS_RANGE = new int[] { 2050, -1 };
-// TESTS_RANGE = new int[] { 1, 2049 };
-// TESTS_RANGE = new int[] { 449, 451 };
-// TESTS_RANGE = new int[] { 900, 999 };
- }
+// All specified tests which does not belong to the class are skipped...
+// Only the highest compliance level is run; add the VM argument
+// -Dcompliance=1.4 (for example) to lower it if needed
+static {
+// TESTS_NAMES = new String[] { "testBug304416" };
+// TESTS_NUMBERS = new int[] { 561 };
+// TESTS_RANGE = new int[] { 1, 2049 };
+}
public static Test suite() {
- return buildAllCompliancesTestSuite(testClass());
+ return buildAllCompliancesTestSuite(testClass());
}
public static Class testClass() {
- return NullReferenceTest.class;
+ return NullReferenceTest.class;
}
// Conditionally augment problem detection settings
@@ -4133,8 +4133,8 @@
" }\n" +
"}\n"},
"----------\n" +
- "1. ERROR in X.java (at line 11)\r\n" +
- " while (o == null) {\r\n" +
+ "1. ERROR in X.java (at line 11)\n" +
+ " while (o == null) {\n" +
" ^\n" +
"Null comparison always yields false: The variable o cannot be null at this location\n" +
"----------\n",
@@ -5177,8 +5177,8 @@
" }\n" +
"}"},
"----------\n" +
- "1. ERROR in X.java (at line 13)\r\n" +
- " o.toString();\r\n" +
+ "1. ERROR in X.java (at line 13)\n" +
+ " o.toString();\n" +
" ^\n" +
"Potential null pointer access: The variable o may be null at this location\n" +
"----------\n",
@@ -6054,7 +6054,157 @@
},
"");
}
-
+// null analysis -- try/catch
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=302446
+public void test0569_try_catch() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " void foo() {\n" +
+ " Object o = null;\n" +
+ " int i;\n" +
+ " if (o == null)\n" + // redundant check
+ " i = 0;\n" +
+ " try {\n" +
+ " System.out.println(i);\n" + // might throw a runtime exception
+ " o = new Object();\n" +
+ " throw new Exception(\"Exception thrown from try block\");\n" +
+ " }\n" +
+ " catch (Throwable t) {\n" + // catches everything
+ " return;\n" + // gets out
+ " }\n" +
+ " }\n" +
+ "}\n"},
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " if (o == null)\n" +
+ " ^\n" +
+ "Redundant null check: The variable o can only be null at this location\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 8)\n" +
+ " System.out.println(i);\n" +
+ " ^\n" +
+ "The local variable i may not have been initialized\n" +
+ "----------\n");
+}
+// null analysis -- try/catch
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=302446
+public void test0570_try_catch() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " void foo() {\n" +
+ " Object o = null;\n" +
+ " int i;\n" +
+ " if (o == null)\n" + // redundant check
+ " i = 0;\n" +
+ " try {\n" +
+ " System.out.println();\n" + // might throw a runtime exception
+ " o = new Object();\n" +
+ " if (o != null)\n" + // redundant check
+ " i = 1\n;" +
+ " throw new Exception(\"Exception thrown from try block\");\n" +
+ " }\n" +
+ " catch (Exception e) {\n" +
+ " if(i == 0)\n" +
+ " System.out.println(\"o was initialised\");\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"},
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " if (o == null)\n" +
+ " ^\n" +
+ "Redundant null check: The variable o can only be null at this location\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 10)\n" +
+ " if (o != null)\n" +
+ " ^\n" +
+ "Redundant null check: The variable o cannot be null at this location\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 15)\n" +
+ " if(i == 0)\n" +
+ " ^\n" +
+ "The local variable i may not have been initialized\n" +
+ "----------\n");
+}
+//null analysis -- try/catch
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=302446
+public void test0571_try_catch_finally() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " void foo() {\n" +
+ " Object o = null;\n" +
+ " int i;\n" +
+ " if (o == null)\n" + // redundant check
+ " i = 0;\n" +
+ " try {\n" +
+ " o = new Object();\n" +
+ " i = 1\n;" +
+ " throw new Exception(\"Exception thrown from try block\");\n" +
+ " }\n" +
+ " catch (Exception e) {\n" +
+ " if(o == null)\n" +
+ " o = new Object();\n" +
+ " i = 1;\n" +
+ " }\n" +
+ " finally {\n" +
+ " if (i==1) {\n" +
+ " System.out.println(\"Method ended with o being initialised\");\n" +
+ " System.out.println(o.toString());\n" + // may be null
+ " } \n" +
+ " }\n" +
+ " }\n" +
+ "}\n"},
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " if (o == null)\n" +
+ " ^\n" +
+ "Redundant null check: The variable o can only be null at this location\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 18)\n" +
+ " if (i==1) {\n" +
+ " ^\n" +
+ "The local variable i may not have been initialized\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 20)\n" +
+ " System.out.println(o.toString());\n" +
+ " ^\n" +
+ "Potential null pointer access: The variable o may be null at this location\n" +
+ "----------\n");
+}
+//null analysis -- if statement
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=302446
+public void test0572_if_statement() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " void foo() {\n" +
+ " Object o = null;\n" +
+ " int i;\n" +
+ " if (o == null) // redundant check\n" +
+ " i = 0;\n" +
+ " System.out.println(i);\n" +
+ " }\n" +
+ "}\n" +
+ ""},
+ "----------\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " if (o == null) // redundant check\n" +
+ " ^\n" +
+ "Redundant null check: The variable o can only be null at this location\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 7)\n" +
+ " System.out.println(i);\n" +
+ " ^\n" +
+ "The local variable i may not have been initialized\n" +
+ "----------\n");
+}
// null analysis - throw
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=201182
public void test0595_throw() {
@@ -8082,12 +8232,7 @@
" ^^\n" +
"Null comparison always yields false: The variable o1 cannot be null at this location\n" +
"----------\n" +
- "2. WARNING in X.java (at line 4)\n" +
- " if (o1 == null) { };\n" +
- " ^^^\n" +
- "Dead code\n" +
- "----------\n" +
- "3. ERROR in X.java (at line 5)\n" +
+ "2. ERROR in X.java (at line 5)\n" +
" if (o2 == null) { };\n" +
" ^^\n" +
"Redundant null check: The variable o2 can only be null at this location\n" +
@@ -8136,11 +8281,6 @@
" if (o == null) { };\n" +
" ^\n" +
"Null comparison always yields false: The variable o cannot be null at this location\n" +
- "----------\n" +
- "2. WARNING in X.java (at line 4)\n" +
- " if (o == null) { };\n" +
- " ^^^\n" +
- "Dead code\n" +
"----------\n",
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
}
@@ -8156,25 +8296,258 @@
"public class X {\n" +
" void foo() {\n" +
" Object o = null;\n" +
- " assert(o != null);\n" + // complain
+ " assert(o != null);\n" + // don't complain
" if (o == null) { };\n" + // complain
" }\n" +
"}\n"},
"----------\n" +
- "1. ERROR in X.java (at line 4)\n" +
- " assert(o != null);\n" +
- " ^\n" +
- "Null comparison always yields false: The variable o can only be null at this location\n" +
- "----------\n" +
- "2. ERROR in X.java (at line 5)\n" +
+ "1. ERROR in X.java (at line 5)\n" +
" if (o == null) { };\n" +
" ^\n" +
"Null comparison always yields false: The variable o cannot be null at this location\n" +
+ "----------\n",
+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
+ }
+}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=250056
+// Test to verify that asserts are exempted from null comparison warnings,
+// but this doesn't affect the downstream info.
+public void test0957_assert() {
+ if (this.complianceLevel >= ClassFileConstants.JDK1_4) {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " void m() {\n" +
+ " X foo = new X();\n" +
+ " assert (foo != null);\n" + //don't warn
+ " if (foo == null) {}\n" +
+ " X foo2 = new X();\n" +
+ " assert (foo2 == null);\n" + //don't warn
+ " if (foo2 == null) {}\n" +
+ " X bar = null;\n" +
+ " assert (bar == null);\n" + //don't warn
+ " if (bar == null) {}\n" +
+ " X bar2 = null;\n" +
+ " assert (bar2 != null);\n" + //don't warn
+ " if (bar2 == null) {}\n" +
+ " }\n" +
+ "}\n"},
"----------\n" +
- "3. WARNING in X.java (at line 5)\n" +
- " if (o == null) { };\n" +
- " ^^^\n" +
- "Dead code\n" +
+ "1. ERROR in X.java (at line 5)\n" +
+ " if (foo == null) {}\n" +
+ " ^^^\n" +
+ "Null comparison always yields false: The variable foo cannot be null at this location\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 8)\n" +
+ " if (foo2 == null) {}\n" +
+ " ^^^^\n" +
+ "Redundant null check: The variable foo2 can only be null at this location\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 11)\n" +
+ " if (bar == null) {}\n" +
+ " ^^^\n" +
+ "Redundant null check: The variable bar can only be null at this location\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 14)\n" +
+ " if (bar2 == null) {}\n" +
+ " ^^^^\n" +
+ "Null comparison always yields false: The variable bar2 cannot be null at this location\n" +
+ "----------\n",
+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
+ }
+}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=250056
+// Test to verify that asserts are exempted from null comparison warnings,
+// but this doesn't affect the downstream info.
+public void test0958_assert() {
+ if (this.complianceLevel >= ClassFileConstants.JDK1_5) {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "import java.util.HashMap;\n" +
+ "public class X {\n" +
+ " void m() {\n" +
+ " HashMap<Integer,X> map = new HashMap<Integer,X>();\n" +
+ " X bar = null;\n" +
+ " X foo = map.get(1);\n" +
+ " if (foo == null) {\n" +
+ " foo = new X();\n" +
+ " map.put(1, foo);\n" +
+ " }\n" +
+ " assert (foo != null && bar == null);\n" + // don't warn but do the null analysis
+ " if (foo != null) {}\n" + // warn
+ " if (bar == null) {}\n" + // warn
+ " }\n" +
+ "}\n"},
+ "----------\n" +
+ "1. ERROR in X.java (at line 12)\n" +
+ " if (foo != null) {}\n" +
+ " ^^^\n" +
+ "Redundant null check: The variable foo cannot be null at this location\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 13)\n" +
+ " if (bar == null) {}\n" +
+ " ^^^\n" +
+ "Redundant null check: The variable bar can only be null at this location\n" +
+ "----------\n",
+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
+ }
+}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=250056
+// Test to verify that asserts are exempted from null comparison warnings in a looping context,
+// but this doesn't affect the downstream info.
+public void test0959a_assert_loop() {
+ if (this.complianceLevel >= ClassFileConstants.JDK1_4) {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " void m() {\n" +
+ " X foo = new X();\n" +
+ " X foo2 = new X();\n" +
+ " X bar = null;\n" +
+ " X bar2 = null;\n" +
+ " while (true) {\n" +
+ " assert (foo != null);\n" + //don't warn
+ " if (foo == null) {}\n" +
+ " assert (foo2 == null);\n" + //don't warn
+ " if (foo2 == null) {}\n" +
+ " assert (bar == null);\n" + //don't warn
+ " if (bar == null) {}\n" +
+ " assert (bar2 != null);\n" + //don't warn
+ " if (bar2 == null) {}\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"},
+ "----------\n" +
+ "1. ERROR in X.java (at line 9)\n" +
+ " if (foo == null) {}\n" +
+ " ^^^\n" +
+ "Null comparison always yields false: The variable foo cannot be null at this location\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 11)\n" +
+ " if (foo2 == null) {}\n" +
+ " ^^^^\n" +
+ "Redundant null check: The variable foo2 can only be null at this location\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 13)\n" +
+ " if (bar == null) {}\n" +
+ " ^^^\n" +
+ "Redundant null check: The variable bar can only be null at this location\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 15)\n" +
+ " if (bar2 == null) {}\n" +
+ " ^^^^\n" +
+ "Null comparison always yields false: The variable bar2 cannot be null at this location\n" +
+ "----------\n",
+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
+ }
+}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=250056
+// Test to verify that asserts are exempted from null comparison warnings in a looping context,
+// but this doesn't affect the downstream info.
+public void test0959b_assert_loop() {
+ if (this.complianceLevel >= ClassFileConstants.JDK1_4) {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " void m() {\n" +
+ " while (true) {\n" +
+ " X foo = new X();\n" +
+ " assert (foo != null);\n" + //don't warn
+ " if (foo == null) {}\n" +
+ " X foo2 = new X();\n" +
+ " assert (foo2 == null);\n" + //don't warn
+ " if (foo2 == null) {}\n" +
+ " X bar = null;\n" +
+ " assert (bar == null);\n" + //don't warn
+ " if (bar == null) {}\n" +
+ " X bar2 = null;\n" +
+ " assert (bar2 != null);\n" + //don't warn
+ " if (bar2 == null) {}\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"},
+ "----------\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " if (foo == null) {}\n" +
+ " ^^^\n" +
+ "Null comparison always yields false: The variable foo cannot be null at this location\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 9)\n" +
+ " if (foo2 == null) {}\n" +
+ " ^^^^\n" +
+ "Redundant null check: The variable foo2 can only be null at this location\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 12)\n" +
+ " if (bar == null) {}\n" +
+ " ^^^\n" +
+ "Redundant null check: The variable bar can only be null at this location\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 15)\n" +
+ " if (bar2 == null) {}\n" +
+ " ^^^^\n" +
+ "Null comparison always yields false: The variable bar2 cannot be null at this location\n" +
+ "----------\n",
+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
+ }
+}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=250056
+// Test to verify that asserts are exempted from null comparison warnings in a finally context,
+// but this doesn't affect the downstream info.
+public void test0960_assert_finally() {
+ if (this.complianceLevel >= ClassFileConstants.JDK1_4) {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " void m() {\n" +
+ " X foo = new X();\n" +
+ " X foo2 = new X();\n" +
+ " X bar = null;\n" +
+ " X bar2 = null;\n" +
+ " try {\n" +
+ " System.out.println(\"Inside try\");\n" +
+ " }\n" +
+ " finally {\n" +
+ " assert (foo != null);\n" + //don't warn
+ " if (foo == null) {}\n" +
+ " assert (foo2 == null);\n" + //don't warn
+ " if (foo2 == null) {}\n" +
+ " assert (bar == null);\n" + //don't warn
+ " if (bar == null) {}\n" +
+ " assert (bar2 != null);\n" + //don't warn
+ " if (bar2 == null) {}\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"},
+ "----------\n" +
+ "1. ERROR in X.java (at line 12)\n" +
+ " if (foo == null) {}\n" +
+ " ^^^\n" +
+ "Null comparison always yields false: The variable foo cannot be null at this location\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 14)\n" +
+ " if (foo2 == null) {}\n" +
+ " ^^^^\n" +
+ "Redundant null check: The variable foo2 can only be null at this location\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 16)\n" +
+ " if (bar == null) {}\n" +
+ " ^^^\n" +
+ "Redundant null check: The variable bar can only be null at this location\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 18)\n" +
+ " if (bar2 == null) {}\n" +
+ " ^^^^\n" +
+ "Null comparison always yields false: The variable bar2 cannot be null at this location\n" +
"----------\n",
JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
}
@@ -8697,17 +9070,17 @@
" }\n" +
"}"},
"----------\n" +
- "1. ERROR in X.java (at line 6)\r\n" +
- " if (o != null) return;\r\n" +
+ "1. ERROR in X.java (at line 6)\n" +
+ " if (o != null) return;\n" +
" ^\n" +
"Null comparison always yields false: The variable o can only be null at this location\n" +
"----------\n" +
- "2. ERROR in X.java (at line 7)\r\n" +
- " o = null;\r\n" +
+ "2. ERROR in X.java (at line 7)\n" +
+ " o = null;\n" +
" ^\n" +
"Redundant assignment: The variable o can only be null at this location\n" +
"----------\n",
- JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
+ JavacTestOptions.Excuse.EclipseWarningConfiguredAsError);
}
public void test1019() {
@@ -10753,4 +11126,514 @@
"Potential null pointer access: The variable bar may be null at this location\n" +
"----------\n");
}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=253896
+// Test whether Null pointer access warnings are being reported correctly when auto-unboxing
+public void testBug253896a() {
+ if (this.complianceLevel >= ClassFileConstants.JDK1_5) {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public void foo() {\n" +
+ " Integer f1 = null;\n" +
+ " if(f1 == 1)\n" +
+ " System.out.println(\"f1 is 1\");\n" +
+ " Integer f2 = null;\n" +
+ " int abc = (f2 != 1)? 1 : 0;\n" +
+ " Float f3 = null;\n" +
+ " if(f3 == null)\n" +
+ " System.out.println(\"f3 is null\");\n" +
+ " Byte f4 = null;\n" +
+ " if(f4 != null)\n" +
+ " System.out.println(\"f4 is not null\");\n" +
+ " }\n" +
+ "}"},
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " if(f1 == 1)\n" +
+ " ^^\n" +
+ "Null pointer access: The variable f1 can only be null at this location\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 7)\n" +
+ " int abc = (f2 != 1)? 1 : 0;\n" +
+ " ^^\n" +
+ "Null pointer access: The variable f2 can only be null at this location\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 9)\n" +
+ " if(f3 == null)\n" +
+ " ^^\n" +
+ "Redundant null check: The variable f3 can only be null at this location\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 12)\n" +
+ " if(f4 != null)\n" +
+ " ^^\n" +
+ "Null comparison always yields false: The variable f4 can only be null at this location\n" +
+ "----------\n" +
+ "5. WARNING in X.java (at line 13)\n" +
+ " System.out.println(\"f4 is not null\");\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Dead code\n" +
+ "----------\n");
+ }
+}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=253896
+// To test whether null pointer access and potential null pointer access warnings are correctly reported when auto-unboxing
+public void testBug253896b() {
+ if (this.complianceLevel >= ClassFileConstants.JDK1_5) {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public void foo(Integer i1, Integer i2) {\n" +
+ " if(i1 == null && i2 == null){\n" +
+ " if(i1 == 1)\n" +
+ " System.out.println(i1);}\n" + //i1 is definitely null here
+ " else {\n" +
+ " if(i1 == 0) {}\n" + //i1 may be null here.
+ " }\n" +
+ " }\n" +
+ "}"},
+ "----------\n" +
+ "1. ERROR in X.java (at line 4)\n" +
+ " if(i1 == 1)\n" +
+ " ^^\n" +
+ "Null pointer access: The variable i1 can only be null at this location\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 7)\n" +
+ " if(i1 == 0) {}\n" +
+ " ^^\n" +
+ "Potential null pointer access: The variable i1 may be null at this location\n" +
+ "----------\n");
+ }
+}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=253896
+// Test whether Null pointer access warnings are being reported correctly when auto-unboxing inside loops
+public void testBug253896c() {
+ if (this.complianceLevel >= ClassFileConstants.JDK1_5) {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public void foo() {\n" +
+ " Integer a = null;\n" +
+ " Integer outer2 = null;\n" +
+ " while (true) {\n" +
+ " Integer f1 = null;\n" +
+ " if(f1 == 1)\n" +
+ " System.out.println(\"f1 is 1\");\n" +
+ " Integer f2 = null;\n" +
+ " int abc = (f2 != 1)? 1 : 0;\n" +
+ " Float f3 = null;\n" +
+ " if(f3 == null)\n" +
+ " System.out.println(\"f3 is null\");\n" +
+ " Byte f4 = null;\n" +
+ " if(f4 != null)\n" +
+ " System.out.println(\"f4 is not null\");\n" +
+ " if(a == 1) {}\n" + // warn null reference in deferred check case
+ " if(outer2 == 1) {}\n" + // warn potential null reference in deferred check case
+ " outer2 = 1;\n" +
+ " }\n" +
+ " }\n" +
+ "}"},
+ "----------\n" +
+ "1. ERROR in X.java (at line 7)\n" +
+ " if(f1 == 1)\n" +
+ " ^^\n" +
+ "Null pointer access: The variable f1 can only be null at this location\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 10)\n" +
+ " int abc = (f2 != 1)? 1 : 0;\n" +
+ " ^^\n" +
+ "Null pointer access: The variable f2 can only be null at this location\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 12)\n" +
+ " if(f3 == null)\n" +
+ " ^^\n" +
+ "Redundant null check: The variable f3 can only be null at this location\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 15)\n" +
+ " if(f4 != null)\n" +
+ " ^^\n" +
+ "Null comparison always yields false: The variable f4 can only be null at this location\n" +
+ "----------\n" +
+ "5. WARNING in X.java (at line 16)\n" +
+ " System.out.println(\"f4 is not null\");\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Dead code\n" +
+ "----------\n" +
+ "6. ERROR in X.java (at line 17)\n" +
+ " if(a == 1) {}\n" +
+ " ^\n" +
+ "Null pointer access: The variable a can only be null at this location\n" +
+ "----------\n" +
+ "7. ERROR in X.java (at line 18)\n" +
+ " if(outer2 == 1) {}\n" +
+ " ^^^^^^\n" +
+ "Potential null pointer access: The variable outer2 may be null at this location\n" +
+ "----------\n");
+ }
+}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=253896
+// Test whether Null pointer access warnings are being reported correctly when auto-unboxing inside finally contexts
+public void testBug253896d() {
+ if (this.complianceLevel >= ClassFileConstants.JDK1_5) {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public void foo(Integer param) {\n" +
+ " Integer outer = null;\n" +
+ " if (param == null) {}\n" + //tainting param
+ " try {}\n" +
+ " finally {\n" +
+ " Integer f1 = null;\n" +
+ " if(f1 == 1)\n" +
+ " System.out.println(\"f1 is 1\");\n" +
+ " Integer f2 = null;\n" +
+ " int abc = (f2 != 1)? 1 : 0;\n" +
+ " Float f3 = null;\n" +
+ " if(f3 == null)\n" +
+ " System.out.println(\"f3 is null\");\n" +
+ " Byte f4 = null;\n" +
+ " if(f4 != null)\n" +
+ " System.out.println(\"f4 is not null\");\n" +
+ " if(outer == 1) {}\n" + // warn null reference in deferred check case
+ " if(param == 1) {}\n" +
+ " }\n" +
+ " }\n" +
+ "}"},
+ "----------\n" +
+ "1. ERROR in X.java (at line 8)\n" +
+ " if(f1 == 1)\n" +
+ " ^^\n" +
+ "Null pointer access: The variable f1 can only be null at this location\n" +
+ "----------\n" +
+ "2. ERROR in X.java (at line 11)\n" +
+ " int abc = (f2 != 1)? 1 : 0;\n" +
+ " ^^\n" +
+ "Null pointer access: The variable f2 can only be null at this location\n" +
+ "----------\n" +
+ "3. ERROR in X.java (at line 13)\n" +
+ " if(f3 == null)\n" +
+ " ^^\n" +
+ "Redundant null check: The variable f3 can only be null at this location\n" +
+ "----------\n" +
+ "4. ERROR in X.java (at line 16)\n" +
+ " if(f4 != null)\n" +
+ " ^^\n" +
+ "Null comparison always yields false: The variable f4 can only be null at this location\n" +
+ "----------\n" +
+ "5. WARNING in X.java (at line 17)\n" +
+ " System.out.println(\"f4 is not null\");\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Dead code\n" +
+ "----------\n" +
+ "6. ERROR in X.java (at line 18)\n" +
+ " if(outer == 1) {}\n" +
+ " ^^^^^\n" +
+ "Null pointer access: The variable outer can only be null at this location\n" +
+ "----------\n" +
+ "7. ERROR in X.java (at line 19)\n" +
+ " if(param == 1) {}\n" +
+ " ^^^^^\n" +
+ "Potential null pointer access: The variable param may be null at this location\n" +
+ "----------\n");
+ }
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=303448
+//To check that code gen is not optimized for an if statement
+//where a local variable's definite nullness or otherwise is known because of
+//an earlier assert expression (inside finally context)
+public void testBug303448a() throws Exception {
+ Map options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.IGNORE);
+ options.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.IGNORE);
+ options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.IGNORE);
+ options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE);
+ if (this.complianceLevel >= ClassFileConstants.JDK1_4) {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public void foo() {\n" +
+ " Object foo = null;\n" +
+ " Object foo2 = null;\n" +
+ " try {} \n" +
+ " finally {\n" +
+ " assert (foo != null && foo2 != null);\n" +
+ " if (foo != null) {\n" +
+ " System.out.println(\"foo is not null\");\n" +
+ " } else {\n" +
+ " System.out.println(\"foo is null\");\n" +
+ " }\n" +
+ " if (foo2 != null) {\n" +
+ " System.out.println(\"foo2 is not null\");\n" +
+ " } else {\n" +
+ " System.out.println(\"foo2 is null\");\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ "}\n",
+ },
+ "",
+ null,
+ true,
+ null,
+ options,
+ null); // custom requestor
+
+ String expectedOutput = this.complianceLevel < ClassFileConstants.JDK1_5?
+ " // Method descriptor #11 ()V\n" +
+ " // Stack: 2, Locals: 3\n" +
+ " public void foo();\n" +
+ " 0 aconst_null\n" +
+ " 1 astore_1 [foo]\n" +
+ " 2 aconst_null\n" +
+ " 3 astore_2 [foo2]\n" +
+ " 4 getstatic X.$assertionsDisabled : boolean [38]\n" +
+ " 7 ifne 26\n" +
+ " 10 aload_1 [foo]\n" +
+ " 11 ifnull 18\n" +
+ " 14 aload_2 [foo2]\n" +
+ " 15 ifnonnull 26\n" +
+ " 18 new java.lang.AssertionError [49]\n" +
+ " 21 dup\n" +
+ " 22 invokespecial java.lang.AssertionError() [51]\n" +
+ " 25 athrow\n" +
+ " 26 aload_1 [foo]\n" +
+ " 27 ifnull 41\n" +
+ " 30 getstatic java.lang.System.out : java.io.PrintStream [52]\n" +
+ " 33 ldc <String \"foo is not null\"> [58]\n" +
+ " 35 invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" +
+ " 38 goto 49\n" +
+ " 41 getstatic java.lang.System.out : java.io.PrintStream [52]\n" +
+ " 44 ldc <String \"foo is null\"> [65]\n" +
+ " 46 invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" +
+ " 49 aload_2 [foo2]\n" +
+ " 50 ifnull 64\n" +
+ " 53 getstatic java.lang.System.out : java.io.PrintStream [52]\n" +
+ " 56 ldc <String \"foo2 is not null\"> [67]\n" +
+ " 58 invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" +
+ " 61 goto 72\n" +
+ " 64 getstatic java.lang.System.out : java.io.PrintStream [52]\n" +
+ " 67 ldc <String \"foo2 is null\"> [69]\n" +
+ " 69 invokevirtual java.io.PrintStream.println(java.lang.String) : void [60]\n" +
+ " 72 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 3]\n" +
+ " [pc: 2, line: 4]\n" +
+ " [pc: 4, line: 7]\n" +
+ " [pc: 26, line: 8]\n" +
+ " [pc: 30, line: 9]\n" +
+ " [pc: 41, line: 11]\n" +
+ " [pc: 49, line: 13]\n" +
+ " [pc: 53, line: 14]\n" +
+ " [pc: 64, line: 16]\n" +
+ " [pc: 72, line: 19]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 73] local: this index: 0 type: X\n" +
+ " [pc: 2, pc: 73] local: foo index: 1 type: java.lang.Object\n" +
+ " [pc: 4, pc: 73] local: foo2 index: 2 type: java.lang.Object\n"
+ : this.complianceLevel < ClassFileConstants.JDK1_6?
+ " // Method descriptor #8 ()V\n" +
+ " // Stack: 2, Locals: 3\n" +
+ " public void foo();\n" +
+ " 0 aconst_null\n" +
+ " 1 astore_1 [foo]\n" +
+ " 2 aconst_null\n" +
+ " 3 astore_2 [foo2]\n" +
+ " 4 getstatic X.$assertionsDisabled : boolean [16]\n" +
+ " 7 ifne 26\n" +
+ " 10 aload_1 [foo]\n" +
+ " 11 ifnull 18\n" +
+ " 14 aload_2 [foo2]\n" +
+ " 15 ifnonnull 26\n" +
+ " 18 new java.lang.AssertionError [26]\n" +
+ " 21 dup\n" +
+ " 22 invokespecial java.lang.AssertionError() [28]\n" +
+ " 25 athrow\n" +
+ " 26 aload_1 [foo]\n" +
+ " 27 ifnull 41\n" +
+ " 30 getstatic java.lang.System.out : java.io.PrintStream [29]\n" +
+ " 33 ldc <String \"foo is not null\"> [35]\n" +
+ " 35 invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" +
+ " 38 goto 49\n" +
+ " 41 getstatic java.lang.System.out : java.io.PrintStream [29]\n" +
+ " 44 ldc <String \"foo is null\"> [43]\n" +
+ " 46 invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" +
+ " 49 aload_2 [foo2]\n" +
+ " 50 ifnull 64\n" +
+ " 53 getstatic java.lang.System.out : java.io.PrintStream [29]\n" +
+ " 56 ldc <String \"foo2 is not null\"> [45]\n" +
+ " 58 invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" +
+ " 61 goto 72\n" +
+ " 64 getstatic java.lang.System.out : java.io.PrintStream [29]\n" +
+ " 67 ldc <String \"foo2 is null\"> [47]\n" +
+ " 69 invokevirtual java.io.PrintStream.println(java.lang.String) : void [37]\n" +
+ " 72 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 3]\n" +
+ " [pc: 2, line: 4]\n" +
+ " [pc: 4, line: 7]\n" +
+ " [pc: 26, line: 8]\n" +
+ " [pc: 30, line: 9]\n" +
+ " [pc: 41, line: 11]\n" +
+ " [pc: 49, line: 13]\n" +
+ " [pc: 53, line: 14]\n" +
+ " [pc: 64, line: 16]\n" +
+ " [pc: 72, line: 19]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 73] local: this index: 0 type: X\n" +
+ " [pc: 2, pc: 73] local: foo index: 1 type: java.lang.Object\n" +
+ " [pc: 4, pc: 73] local: foo2 index: 2 type: java.lang.Object\n"
+ : " // Method descriptor #8 ()V\n" +
+ " // Stack: 2, Locals: 3\n" +
+ " public void foo();\n" +
+ " 0 aconst_null\n" +
+ " 1 astore_1 [foo]\n" +
+ " 2 aconst_null\n" +
+ " 3 astore_2 [foo2]\n" +
+ " 4 getstatic X.$assertionsDisabled : boolean [16]\n" +
+ " 7 ifne 26\n" +
+ " 10 aload_1 [foo]\n" +
+ " 11 ifnull 18\n" +
+ " 14 aload_2 [foo2]\n" +
+ " 15 ifnonnull 26\n" +
+ " 18 new java.lang.AssertionError [27]\n" +
+ " 21 dup\n" +
+ " 22 invokespecial java.lang.AssertionError() [29]\n" +
+ " 25 athrow\n" +
+ " 26 aload_1 [foo]\n" +
+ " 27 ifnull 41\n" +
+ " 30 getstatic java.lang.System.out : java.io.PrintStream [30]\n" +
+ " 33 ldc <String \"foo is not null\"> [36]\n" +
+ " 35 invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" +
+ " 38 goto 49\n" +
+ " 41 getstatic java.lang.System.out : java.io.PrintStream [30]\n" +
+ " 44 ldc <String \"foo is null\"> [44]\n" +
+ " 46 invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" +
+ " 49 aload_2 [foo2]\n" +
+ " 50 ifnull 64\n" +
+ " 53 getstatic java.lang.System.out : java.io.PrintStream [30]\n" +
+ " 56 ldc <String \"foo2 is not null\"> [46]\n" +
+ " 58 invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" +
+ " 61 goto 72\n" +
+ " 64 getstatic java.lang.System.out : java.io.PrintStream [30]\n" +
+ " 67 ldc <String \"foo2 is null\"> [48]\n" +
+ " 69 invokevirtual java.io.PrintStream.println(java.lang.String) : void [38]\n" +
+ " 72 return\n" +
+ " Line numbers:\n" +
+ " [pc: 0, line: 3]\n" +
+ " [pc: 2, line: 4]\n" +
+ " [pc: 4, line: 7]\n" +
+ " [pc: 26, line: 8]\n" +
+ " [pc: 30, line: 9]\n" +
+ " [pc: 41, line: 11]\n" +
+ " [pc: 49, line: 13]\n" +
+ " [pc: 53, line: 14]\n" +
+ " [pc: 64, line: 16]\n" +
+ " [pc: 72, line: 19]\n" +
+ " Local variable table:\n" +
+ " [pc: 0, pc: 73] local: this index: 0 type: X\n" +
+ " [pc: 2, pc: 73] local: foo index: 1 type: java.lang.Object\n" +
+ " [pc: 4, pc: 73] local: foo2 index: 2 type: java.lang.Object\n" +
+ " Stack map table: number of frames 6\n" +
+ " [pc: 18, append: {java.lang.Object, java.lang.Object}]\n" +
+ " [pc: 26, same]\n" +
+ " [pc: 41, same]\n" +
+ " [pc: 49, same]\n" +
+ " [pc: 64, same]\n" +
+ " [pc: 72, same]\n";
+
+ File f = new File(OUTPUT_DIR + File.separator + "X.class");
+ byte[] classFileBytes = org.eclipse.jdt.internal.compiler.util.Util.getFileByteContent(f);
+ ClassFileBytesDisassembler disassembler = ToolFactory.createDefaultClassFileBytesDisassembler();
+ String result = disassembler.disassemble(classFileBytes, "\n", ClassFileBytesDisassembler.DETAILED);
+ int index = result.indexOf(expectedOutput);
+ if (index == -1 || expectedOutput.length() == 0) {
+ System.out.println(Util.displayString(result, 3));
+ }
+ if (index == -1) {
+ assertEquals("Wrong contents", expectedOutput, result);
+ }
+ }
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=303448
+//To check that code gen is not optimized for an if statement
+//where a local variable's definite nullness or otherwise is known because of
+//an earlier assert expression (inside finally context)
+public void testBug303448b() throws Exception {
+ Map options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.IGNORE);
+ options.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.IGNORE);
+ options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.IGNORE);
+ options.put(CompilerOptions.OPTION_ReportRawTypeReference, CompilerOptions.IGNORE);
+ if (this.complianceLevel >= ClassFileConstants.JDK1_4) {
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.print(\"start\");\n" +
+ " Object foo = null;\n" +
+ " assert (foo != null);\n" +
+ " if (foo != null) {\n" +
+ " System.out.println(\"foo is not null\");\n" +
+ " }\n" +
+ " System.out.print(\"end\");\n" +
+ " }\n" +
+ "}\n",
+ },
+ "startend",
+ null,
+ true,
+ null,
+ options,
+ null);
+ }
+}
+//https://bugs.eclipse.org/bugs/show_bug.cgi?id=304416
+public void testBug304416() throws Exception {
+ Map options = getCompilerOptions();
+ options.put(CompilerOptions.OPTION_ReportNullReference, CompilerOptions.WARNING);
+ options.put(CompilerOptions.OPTION_ReportPotentialNullReference, CompilerOptions.WARNING);
+ options.put(CompilerOptions.OPTION_ReportRedundantNullCheck, CompilerOptions.WARNING);
+ options.put(CompilerOptions.OPTION_PreserveUnusedLocal, CompilerOptions.OPTIMIZE_OUT);
+ this.runConformTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " String s = null;\n" +
+ " String s2 = null;\n" +
+ " if (s != null && s2 != null) {\n" +
+ " System.out.println(s);\n" +
+ " System.out.println(s2);\n" +
+ " }\n" +
+ " }\n" +
+ "}",
+ },
+ "",
+ null,
+ true,
+ null,
+ options,
+ null);
+ String expectedOutput =
+ " public static void main(java.lang.String[] args);\n" +
+ " 0 aconst_null\n" +
+ " 1 astore_1 [s]\n" +
+ " 2 aconst_null\n" +
+ " 3 astore_2 [s2]\n" +
+ " 4 aload_1 [s]\n" +
+ " 5 ifnull 12\n" +
+ " 8 aload_2 [s2]\n" +
+ " 9 ifnull 12\n" +
+ " 12 return\n";
+ checkDisassembledClassFile(OUTPUT_DIR + File.separator + "X.class", "X", expectedOutput);
+}
}
\ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java
index 2421301..5e56546 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/ProgrammingProblemsTest.java
@@ -1559,4 +1559,65 @@
"Zork cannot be resolved to a type\n" +
"----------\n");
}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=251227
+public void test0041() {
+ this.runNegativeTest(
+ new String[] {
+ "X.java",
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(1.0 == 1.0);\n" +
+ " System.out.println(1.0f == 1.0f);\n" +
+ " }\n" +
+ "}\n"
+ },
+ "----------\n" +
+ "1. WARNING in X.java (at line 3)\n" +
+ " System.out.println(1.0 == 1.0);\n" +
+ " ^^^^^^^^^^\n" +
+ "Comparing identical expressions\n" +
+ "----------\n" +
+ "2. WARNING in X.java (at line 4)\n" +
+ " System.out.println(1.0f == 1.0f);\n" +
+ " ^^^^^^^^^^^^\n" +
+ "Comparing identical expressions\n" +
+ "----------\n");
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=248897
+public void test0042() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_5) {
+ return;
+ }
+ runTest(
+ new String[] {
+ "Test.java",
+ "public class Test {\n" +
+ " public static void main(String[] args) {\n" +
+ " final String var = \"Hello\";\n" +
+ " final int local = 10;\n" +
+ " @ZAnn(var + local)\n" +
+ " class X {}\n" +
+ " new X();\n" +
+ " }\n" +
+ "}\n" +
+ "@interface ZAnn {\n" +
+ " String value();\n" +
+ "}\n"
+ },
+ null /* errorOptions */,
+ new String[] {
+ CompilerOptions.OPTION_ReportUnusedLocal
+ } /* warningOptions */,
+ null /* ignoreOptions */,
+ false /* expectingCompilerErrors */,
+ "" /* expectedCompilerLog */,
+ "" /* expectedOutputString */,
+ false /* forceExecution */,
+ null /* classLib */,
+ true /* shouldFlushOutputDirectory */,
+ null /* vmArguments */,
+ null /* customOptions */,
+ null /* clientRequestor */,
+ true /* skipJavac */);
+}
}
\ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java
index 8bd47ad..0b4c1d5 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/StaticImportTest.java
@@ -2485,8 +2485,8 @@
"----------\n" +
"1. ERROR in p1\\A.java (at line 7)\n" +
" int v2 = b.fooC;\n" +
- " ^^^^^^\n" +
- "b.fooC cannot be resolved or is not a field\n" +
+ " ^^^^\n" +
+ "fooC cannot be resolved or is not a field\n" +
"----------\n");
}
//https://bugs.eclipse.org/bugs/show_bug.cgi?id=256375
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java
index 73c6195..e9b779d 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/TestAll.java
@@ -16,6 +16,7 @@
import junit.framework.Test;
import junit.framework.TestSuite;
+import org.eclipse.jdt.core.tests.dom.StandAloneASTParserTest;
import org.eclipse.jdt.core.tests.junit.extension.TestCase;
import org.eclipse.jdt.core.tests.util.AbstractCompilerTest;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
@@ -106,6 +107,7 @@
// Build final test suite
TestSuite all = new TestSuite(TestAll.class.getName());
+ all.addTest(new TestSuite(StandAloneASTParserTest.class));
int possibleComplianceLevels = AbstractCompilerTest.getPossibleComplianceLevels();
if ((possibleComplianceLevels & AbstractCompilerTest.F_1_3) != 0) {
ArrayList tests_1_3 = (ArrayList)standardTests.clone();
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/DebugEvaluationTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/DebugEvaluationTest.java
index 049c13e..ea958f9 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/DebugEvaluationTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/DebugEvaluationTest.java
@@ -21,6 +21,7 @@
import junit.framework.Test;
import org.eclipse.jdt.core.compiler.CategorizedProblem;
+import org.eclipse.jdt.core.compiler.IProblem;
import org.eclipse.jdt.core.compiler.batch.BatchCompiler;
import org.eclipse.jdt.core.tests.runtime.LocalVMLauncher;
import org.eclipse.jdt.core.tests.runtime.TargetInterface;
@@ -772,7 +773,7 @@
* Access to super reference
*/
// disabled since result has problem: Pb(422) super cannot be used in the code snippet code
-public void _test019() throws Exception {
+public void test019() throws Exception {
try {
String sourceA019 =
"public class A019 {\n" +
@@ -798,10 +799,10 @@
evaluate(stackFrame, requestor, snippet);
assertTrue("Should get one result but got " + requestor.resultIndex+1, requestor.resultIndex == 0);
EvaluationResult result = requestor.results[0];
- assertTrue("Code snippet should not have problems", !result.hasProblems());
- assertTrue("Result should have a value", result.hasValue());
- assertEquals("Value", "true".toCharArray(), result.getValueDisplayString());
- assertEquals("Type", "boolean".toCharArray(), result.getValueTypeName());
+ assertTrue("Code snippet should have problems", result.hasProblems());
+ assertTrue("Code snippet should have problems", result.hasProblems());
+ assertEquals("Wrong size", 1, result.getProblems().length);
+ assertEquals("Wrong pb", 422, result.getProblems()[0].getID() & IProblem.IgnoreCategoriesMask);
} finally {
removeTempClass("A019");
}
@@ -2939,6 +2940,121 @@
removeTempClass("A67");
}
}
+public void test068() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_5) return;
+ try {
+ String sourceSuperA68 =
+ "public class SuperA68 {\n"
+ + "\tprivate int i;\n"
+ + "\tpublic SuperA68() {\n"
+ + "\t}\n"
+ + "\tpublic <U> int foo(int i) {;\n"
+ + "\t\treturn i;\n"
+ + "\t}\n"
+ + "}";
+ compileAndDeploy15(sourceSuperA68, "SuperA68");
+ String sourceA68 =
+ "public class A68 extends SuperA68 {\n"
+ + "\tprivate int i;\n"
+ + "\tpublic A68() {\n"
+ + "\t}\n"
+ + "\tpublic <U> int foo(int i) {\n"
+ + "\t\treturn i;\n"
+ + "\t}\n"
+ + "\tpublic void bar() {\n"
+ + "\t}\n"
+ + "}";
+ compileAndDeploy15(sourceA68, "A68");
+
+ String userCode = "new A68().bar();";
+ JDIStackFrame stackFrame =
+ new JDIStackFrame(this.jdiVM, this, userCode, "A68", "bar", -1);
+
+ DebugRequestor requestor = new DebugRequestor();
+ char[] snippet = "return super.<Object>foo(3);".toCharArray();
+ try {
+ this.context.evaluate(
+ snippet,
+ stackFrame.localVariableTypeNames(),
+ stackFrame.localVariableNames(),
+ stackFrame.localVariableModifiers(),
+ stackFrame.declaringTypeName(),
+ stackFrame.isStatic(),
+ stackFrame.isConstructorCall(),
+ getEnv(),
+ getCompilerOptions(),
+ requestor,
+ getProblemFactory());
+ } catch (InstallException e) {
+ assertTrue("No targetException " + e.getMessage(), false);
+ }
+ assertTrue(
+ "Should get one result but got " + (requestor.resultIndex + 1),
+ requestor.resultIndex == 0);
+ EvaluationResult result = requestor.results[0];
+ assertTrue("Code snippet should have problems", result.hasProblems());
+ assertEquals("Wrong size", 1, result.getProblems().length);
+ assertEquals("Wrong pb", 422, result.getProblems()[0].getID() & IProblem.IgnoreCategoriesMask);
+ } finally {
+ removeTempClass("A68");
+ removeTempClass("SuperA68");
+ }
+}
+public void test069() {
+ if (this.complianceLevel < ClassFileConstants.JDK1_5) return;
+ try {
+ String sourceA69 =
+ "public enum A69 {\n"
+ + "\tA(2), B(1);\n"
+ + "\tprivate int i;\n"
+ + "\tprivate A69(int i) {\n"
+ + "\t\tthis.i = i;\n"
+ + "\t}\n"
+ + "\tpublic String toString() {\n"
+ + "\t\treturn String.valueOf(this.i);\n"
+ + "\t}\n"
+ + "\tpublic static void bar() {\n"
+ + "\t}\n"
+ + "}";
+ compileAndDeploy15(sourceA69, "A69");
+
+ String userCode = "A69.bar();";
+ JDIStackFrame stackFrame =
+ new JDIStackFrame(this.jdiVM, this, userCode, "A69", "bar", -1);
+
+ DebugRequestor requestor = new DebugRequestor();
+ char[] snippet = "enum E { C }; return String.toString(E.C.getName());".toCharArray();
+ try {
+ this.context.evaluate(
+ snippet,
+ stackFrame.localVariableTypeNames(),
+ stackFrame.localVariableNames(),
+ stackFrame.localVariableModifiers(),
+ stackFrame.declaringTypeName(),
+ stackFrame.isStatic(),
+ stackFrame.isConstructorCall(),
+ getEnv(),
+ getCompilerOptions(),
+ requestor,
+ getProblemFactory());
+ } catch (InstallException e) {
+ assertTrue("No targetException " + e.getMessage(), false);
+ }
+ assertTrue(
+ "Should get two results but got " + (requestor.resultIndex + 1),
+ requestor.resultIndex == 1);
+ EvaluationResult result = requestor.results[0];
+ assertTrue("Code snippet should not have problems", result.hasProblems());
+ assertEquals("Wrong size", 1, result.getProblems().length);
+ assertEquals("Wrong pb", 31, result.getProblems()[0].getID() & IProblem.IgnoreCategoriesMask);
+ result = requestor.results[1];
+ assertTrue("Code snippet should not have problems", result.hasProblems());
+ assertEquals("Wrong size", 1, result.getProblems().length);
+ assertEquals("Wrong pb", 50, result.getProblems()[0].getID() & IProblem.IgnoreCategoriesMask);
+ } finally {
+ removeTempClass("A69");
+ }
+}
/**
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=178861
*/
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/NegativeCodeSnippetTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/NegativeCodeSnippetTest.java
index 098b23f..7886745 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/NegativeCodeSnippetTest.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/eval/NegativeCodeSnippetTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation 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
@@ -130,7 +130,7 @@
evaluateWithExpectedProblem(
("String s = \"\";\n" +
"s.length").toCharArray(),
- "s.length cannot be resolved or is not a field\n");
+ "length cannot be resolved or is not a field\n");
}
/**
* Test a code snippet which is valid but the evaluation context imports have problems.
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/TestCase.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/TestCase.java
index 38b3920..e46b212 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/TestCase.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/junit/extension/TestCase.java
@@ -647,31 +647,32 @@
}
// Get file (create if necessary)
File logFile = new File(MEM_LOG_DIR, STORE_MEMORY+".log");
+ PrintStream stream = null;
try {
boolean fileExist = logFile.exists();
- PrintStream stream = new PrintStream(new FileOutputStream(logFile, true));
- if (stream != null) {
- if (fileExist) {
- stream.println();
- }
- // Log date and time
- Date date = new Date(System.currentTimeMillis());
- stream.println("Tests:\t" + STORE_MEMORY);
- stream.println("Date:\t" + DateFormat.getDateInstance(3).format(date));
- stream.println("Time:\t" + DateFormat.getTimeInstance(3).format(date));
- // Log columns title
- stream.print("Class");
- if (ALL_TESTS_LOG) stream.print("\tTest");
- stream.print("\tUsed\tTotal\tMax");
+ stream = new PrintStream(new FileOutputStream(logFile, true));
+ if (fileExist) {
stream.println();
- stream.close();
- System.out.println("Log file " + logFile.getPath() + " opened.");
- return logFile;
- } else {
- System.err.println("Cannot open file " + logFile.getPath());
}
+ // Log date and time
+ Date date = new Date(System.currentTimeMillis());
+ stream.println("Tests:\t" + STORE_MEMORY);
+ stream.println("Date:\t" + DateFormat.getDateInstance(3).format(date));
+ stream.println("Time:\t" + DateFormat.getTimeInstance(3).format(date));
+ // Log columns title
+ stream.print("Class");
+ if (ALL_TESTS_LOG) stream.print("\tTest");
+ stream.print("\tUsed\tTotal\tMax");
+ stream.println();
+ System.out.println("Log file " + logFile.getPath() + " opened.");
+ return logFile;
} catch (FileNotFoundException e) {
// no log available for this statistic
+ System.err.println("Cannot open file " + logFile.getPath());
+ } finally {
+ if (stream != null) {
+ stream.close();
+ }
}
return null;
}
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/TestVerifier.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/TestVerifier.java
index 246af06..8c38c58 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/TestVerifier.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/TestVerifier.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation 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
@@ -49,8 +49,9 @@
didMatchExpectation = false;
}
}
+ String trimmedErrorString = errorString.trim();
if (expectedErrorStringStart != null) {
- platformIndependantString = Util.convertToIndependantLineDelimiter(errorString.trim());
+ platformIndependantString = Util.convertToIndependantLineDelimiter(trimmedErrorString);
if (expectedErrorStringStart.length() == 0 && platformIndependantString.length() > 0 ||
!platformIndependantString.startsWith(Util.convertToIndependantLineDelimiter(expectedErrorStringStart))) {
/*
@@ -71,6 +72,17 @@
+ "---[END]---\n";
didMatchExpectation = false;
}
+ } else if (trimmedErrorString.length() != 0){
+ platformIndependantString = Util.convertToIndependantLineDelimiter(trimmedErrorString);
+ System.out.println(Util.displayString(platformIndependantString, 2));
+ this.failureReason =
+ "Unexpected error running resulting class file for "
+ + sourceFileName
+ + ":\n"
+ + "--[START]--\n"
+ + errorString
+ + "---[END]---\n";
+ didMatchExpectation = false;
}
return didMatchExpectation;
}
@@ -387,7 +399,7 @@
TestVerifier.this.outputBuffer.append((char) c);
c = input.read();
}
- } catch(IOException ioEx) {
+ } catch(IOException e) {
}
}
});
@@ -400,7 +412,7 @@
TestVerifier.this.errorBuffer.append((char) c);
c = errorStream.read();
}
- } catch(IOException ioEx) {
+ } catch(IOException e) {
}
}
});
diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/VerifyTests.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/VerifyTests.java
index 569c47b..5a65937 100644
--- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/VerifyTests.java
+++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/util/VerifyTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation 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
@@ -213,9 +213,14 @@
System.out.println(VerifyTests.class.getName());
out.writeBoolean(false);
} catch (IOException e1) {
- // ignore
+ e1.printStackTrace();
}
}
+ try {
+ out.flush();
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
}
};
thread.start();
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java
index 45021b9..90b92ba 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation 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
@@ -47,7 +47,7 @@
}
static {
-// TESTS_NUMBERS = new int[] { 340 };
+// TESTS_NUMBERS = new int[] { 342, 343 };
// TESTS_RANGE = new int[] { 325, -1 };
// TESTS_NAMES = new String[] {"test0204"};
}
@@ -10915,4 +10915,81 @@
assertEquals("Wrong size", "@goto", ((TagElement) tags.get(1)).getTagName());
checkSourceRange((TagElement) tags.get(1), "@goto new position", contents);
}
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=300734
+ public void test341() throws JavaModelException {
+ String contents =
+ "public class Bug300734 {\n" +
+ " public void foo(String x) {\n" +
+ " x.getClass();\n" +
+ " x.getClass();\n" +
+ " }\n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/Bug300734.java", true/*resolve*/);
+ CompilationUnit unit= (CompilationUnit) buildAST(
+ contents,
+ this.workingCopy,
+ true,
+ false,
+ true);
+ MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
+ IMethodBinding methodBinding1 = ((MethodInvocation) ((ExpressionStatement) methodDeclaration.getBody().statements().get(0)).getExpression()).resolveMethodBinding();
+ IMethodBinding methodBinding2 = ((MethodInvocation) ((ExpressionStatement) methodDeclaration.getBody().statements().get(1)).getExpression()).resolveMethodBinding();
+ assertTrue("Bindings differ", methodBinding1 == methodBinding2);
+ }
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=304122
+ public void test342() throws JavaModelException {
+ String contents =
+ "@Deprecated\n" +
+ "public class X<T> {\n" +
+ " X<String> field;\n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ CompilationUnit unit= (CompilationUnit) buildAST(
+ contents,
+ this.workingCopy,
+ true,
+ true,
+ true);
+ TypeDeclaration typeDeclaration = (TypeDeclaration) getASTNode(unit, 0);
+ ITypeBinding binding = typeDeclaration.resolveBinding();
+ IAnnotationBinding[] annotations = binding.getAnnotations();
+ assertEquals("Wrong size", 1, annotations.length);
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) getASTNode(unit, 0, 0);
+ binding = fieldDeclaration.getType().resolveBinding();
+ annotations = binding.getAnnotations();
+ assertEquals("Wrong size", 1, annotations.length);
+ }
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=304122
+ public void test343() throws JavaModelException {
+ String contents =
+ "public class X {\n" +
+ " @Deprecated\n" +
+ " <T> Object foo(T t) {\n" +
+ " return t;\n" +
+ " }\n" +
+ " public static Object bar() {\n" +
+ " return new X().<String>foo(\"Hello\");\n" +
+ " }\n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ CompilationUnit unit= (CompilationUnit) buildAST(
+ contents,
+ this.workingCopy,
+ true,
+ true,
+ true);
+ MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
+ IMethodBinding binding = methodDeclaration.resolveBinding();
+ IAnnotationBinding[] annotations = binding.getAnnotations();
+ assertEquals("Wrong size", 1, annotations.length);
+ methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 1);
+ ReturnStatement statement = (ReturnStatement) methodDeclaration.getBody().statements().get(0);
+ MethodInvocation expression = (MethodInvocation) statement.getExpression();
+ binding = expression.resolveMethodBinding();
+ annotations = binding.getAnnotations();
+ assertEquals("Wrong size", 1, annotations.length);
+ binding = binding.getMethodDeclaration();
+ annotations = binding.getAnnotations();
+ assertEquals("Wrong size", 1, annotations.length);
+ }
}
\ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java
index 9237c91..a4a823d 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java
@@ -122,7 +122,7 @@
static {
// TESTS_NAMES = new String[] {"test0602"};
// TESTS_RANGE = new int[] { 713, -1 };
-// TESTS_NUMBERS = new int[] { 718 };
+// TESTS_NUMBERS = new int[] { 653 };
}
public static Test suite() {
return buildModelTestSuite(ASTConverterTestAST3_2.class);
@@ -5287,7 +5287,7 @@
String source = "public class A {public boolean foo() {}}";
parser.setSource(source.toCharArray());
parser.setProject(getJavaProject("Converter"));
- parser.setUnitName("A");
+ parser.setUnitName("A.java");
parser.setResolveBindings(true);
ASTNode node = parser.createAST(null);
assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); //$NON-NLS-1$
@@ -8067,6 +8067,8 @@
FieldAccess fieldAccess = (FieldAccess) expression;
IVariableBinding variableBinding = fieldAccess.resolveFieldBinding();
assertNotNull("No variable binding", variableBinding);
+ IMethodBinding resolveMethodBinding = invocation.resolveMethodBinding();
+ assertNotNull("No binding", resolveMethodBinding);
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/BatchASTCreationTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/BatchASTCreationTests.java
index 69c8da0..7b39f37 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/BatchASTCreationTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/BatchASTCreationTests.java
@@ -32,8 +32,11 @@
import org.eclipse.jdt.core.dom.IMethodBinding;
import org.eclipse.jdt.core.dom.ITypeBinding;
import org.eclipse.jdt.core.dom.IVariableBinding;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.Type;
import org.eclipse.jdt.core.dom.TypeDeclaration;
+import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
import org.eclipse.jdt.core.tests.util.Util;
public class BatchASTCreationTests extends AbstractASTTests {
@@ -104,10 +107,10 @@
// All specified tests which do not belong to the class are skipped...
static {
// TESTS_PREFIX = "testBug86380";
-// TESTS_NAMES = new String[] { "test056" };
-// TESTS_NUMBERS = new int[] { 78, 79, 80 };
+// TESTS_NAMES = new String[] { "test072a" };
+// TESTS_NUMBERS = new int[] { 72 };
// TESTS_RANGE = new int[] { 83304, -1 };
- }
+ }
public void setUpSuite() throws Exception {
super.setUpSuite();
@@ -1692,7 +1695,7 @@
* is not null
* (regression test for bug 129804 Local variable bindings from ASTParser#createASTs(.., String[], .., ..) have no declaring method)
*/
- public void _test072() throws CoreException {
+ public void test072() throws CoreException {
IVariableBinding[] bindings = createVariableBindings(
new String[] {
"/P/X.java",
@@ -1710,6 +1713,49 @@
"LX;.m()V",
bindings[0].getDeclaringMethod());
}
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=152060
+ public void test072a() throws CoreException, IOException {
+ try {
+ IJavaProject project = createJavaProject("P072a", new String[] {"src"}, Util.getJavaClassLibs(), "bin", "1.5");
+ createFile("/P072a/src/X.java",
+ "public class X {\n" +
+ " void m() {\n" +
+ " Object o;\n" +
+ " }\n" +
+ "}");
+ final ICompilationUnit compilationUnits[] = new ICompilationUnit[1];
+ compilationUnits[0] = getCompilationUnit("P072a", "src", "", "X.java");
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setResolveBindings(true);
+ parser.setProject(project);
+ final String[] keys = new String[] { "LX;.m()V#o" };
+ final ASTNode[] nodes = new ASTNode[1];
+ BindingRequestor bindingRequestor = new BindingRequestor() {
+ public void acceptAST(ICompilationUnit source, CompilationUnit ast) {
+ if (compilationUnits[0].equals(source)) {
+ nodes[0] = ast;
+ }
+ }
+ };
+ parser.createASTs(
+ compilationUnits,
+ keys,
+ bindingRequestor,
+ null);
+ IBinding[] bindings = bindingRequestor.getBindings(keys);
+ IBinding binding = bindings[0];
+ assertNotNull("Should not be null", binding);
+ assertEquals("Not a type binding", IBinding.VARIABLE, binding.getKind());
+ MethodDeclaration declaration = ((TypeDeclaration)((CompilationUnit) nodes[0]).types().get(0)).getMethods()[0];
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) ((VariableDeclarationStatement) declaration.getBody().statements().get(0)).fragments().get(0);
+ IVariableBinding resolveBinding = fragment.resolveBinding();
+ assertTrue("Not equals", binding.isEqualTo(resolveBinding));
+ assertNotNull("No java element", resolveBinding.getJavaElement());
+ assertNotNull("No java element", binding.getJavaElement());
+ } finally {
+ deleteProject("P072a");
+ }
+ }
// https://bugs.eclipse.org/bugs/show_bug.cgi?id=159631
public void test073() throws CoreException, IOException {
@@ -1936,30 +1982,30 @@
" }\n" +
" public void extra() {\n" +
" }\n" +
- "}");
+ "}");
ICompilationUnit compilationUnits[] = new ICompilationUnit[1];
compilationUnits[0] = getCompilationUnit("P079", "src", "test", "Test.java");
ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setResolveBindings(true);
parser.setProject(project);
- final IBinding[] bindings = new IBinding[1];
+ final IBinding[] bindings = new IBinding[1];
final String key = "Ltest/Test~ExtraIterator<>;";
parser.createASTs(
- compilationUnits,
- new String[] {
- key
- },
- new ASTRequestor() {
- public void acceptAST(ICompilationUnit source, CompilationUnit localAst) {
- // do nothing
- }
- public void acceptBinding(String bindingKey, IBinding binding) {
- if (key.equals(bindingKey)) {
- bindings[0] = binding;
- }
- }
- },
- null);
+ compilationUnits,
+ new String[] {
+ key
+ },
+ new ASTRequestor() {
+ public void acceptAST(ICompilationUnit source, CompilationUnit localAst) {
+ // do nothing
+ }
+ public void acceptBinding(String bindingKey, IBinding binding) {
+ if (key.equals(bindingKey)) {
+ bindings[0] = binding;
+ }
+ }
+ },
+ null);
IBinding binding = bindings[0];
assertNotNull("Should not be null", binding);
assertEquals("Not a type binding", IBinding.TYPE, binding.getKind());
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java
index ab05872..678bc40 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterBugsTests.java
@@ -15,10 +15,12 @@
import junit.framework.Test;
import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.formatter.CodeFormatter;
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
import org.eclipse.jdt.core.formatter.IndentManipulation;
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter;
import org.eclipse.jdt.internal.formatter.DefaultCodeFormatterOptions;
+import org.eclipse.jdt.internal.formatter.align.Alignment;
public class FormatterBugsTests extends FormatterRegressionTests {
@@ -65,6 +67,573 @@
}
/**
+ * @bug 27079: [formatter] Tags for disabling/enabling code formatter (feature)
+ * @test Ensure that the formatter does not format code between specific javadoc comments
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=27079"
+ */
+public void testBug027079a() throws JavaModelException {
+ String source =
+ "public class X01 {\n" +
+ "\n" +
+ "/* disable-formatter */\n" +
+ "void foo( ) { \n" +
+ " // unformatted comment\n" +
+ "}\n" +
+ "/* enable-formatter */\n" +
+ "void bar( ) { \n" +
+ " // formatted comment\n" +
+ "}\n" +
+ "}\n";
+ formatSource(source,
+ "public class X01 {\n" +
+ "\n" +
+ " /* disable-formatter */\n" +
+ " void foo() {\n" +
+ " // unformatted comment\n" +
+ " }\n" +
+ "\n" +
+ " /* enable-formatter */\n" +
+ " void bar() {\n" +
+ " // formatted comment\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug027079a1() throws JavaModelException {
+ this.formatterPrefs.disabling_tag = "disable-formatter".toCharArray();
+ this.formatterPrefs.enabling_tag = "enable-formatter".toCharArray();
+ String source =
+ "public class X01 {\n" +
+ "\n" +
+ "/* disable-formatter */\n" +
+ "void foo( ) { \n" +
+ " // unformatted comment\n" +
+ "}\n" +
+ "/* enable-formatter */\n" +
+ "void bar( ) { \n" +
+ " // formatted comment\n" +
+ "}\n" +
+ "}\n";
+ formatSource(source,
+ "public class X01 {\n" +
+ "\n" +
+ "/* disable-formatter */\n" +
+ "void foo( ) { \n" +
+ " // unformatted comment\n" +
+ "}\n" +
+ "/* enable-formatter */\n" +
+ " void bar() {\n" +
+ " // formatted comment\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug027079a2() throws JavaModelException {
+ this.formatterPrefs.disabling_tag = "disable-formatter".toCharArray();
+ this.formatterPrefs.enabling_tag = "enable-formatter".toCharArray();
+ String source =
+ "public class X01 {\n" +
+ "\n" +
+ "/** disable-formatter */\n" +
+ "void foo( ) { \n" +
+ " // unformatted comment\n" +
+ "}\n" +
+ "/** enable-formatter */\n" +
+ "void bar( ) { \n" +
+ " // formatted comment\n" +
+ "}\n" +
+ "}\n";
+ formatSource(source,
+ "public class X01 {\n" +
+ "\n" +
+ "/** disable-formatter */\n" +
+ "void foo( ) { \n" +
+ " // unformatted comment\n" +
+ "}\n" +
+ "/** enable-formatter */\n" +
+ " void bar() {\n" +
+ " // formatted comment\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug027079a3() throws JavaModelException {
+ this.formatterPrefs.disabling_tag = "disable-formatter".toCharArray();
+ this.formatterPrefs.enabling_tag = "enable-formatter".toCharArray();
+ String source =
+ "public class X01 {\n" +
+ "\n" +
+ "// disable-formatter\n" +
+ "void foo( ) { \n" +
+ " // unformatted comment\n" +
+ "}\n" +
+ "// enable-formatter\n" +
+ "void bar( ) { \n" +
+ " // formatted comment\n" +
+ "}\n" +
+ "}\n";
+ formatSource(source,
+ "public class X01 {\n" +
+ "\n" +
+ "// disable-formatter\n" +
+ "void foo( ) { \n" +
+ " // unformatted comment\n" +
+ "}\n" +
+ "// enable-formatter\n" +
+ " void bar() {\n" +
+ " // formatted comment\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug027079a4() throws JavaModelException {
+ this.formatterPrefs.disabling_tag = "disable-formatter".toCharArray();
+ this.formatterPrefs.enabling_tag = "enable-formatter".toCharArray();
+ String source =
+ "public class X01 {\n" +
+ "\n" +
+ "// disable-formatter\n" +
+ "void foo( ) { \n" +
+ " // unformatted comment \n" +
+ "}\n" +
+ "// enable-formatter \n" +
+ "void bar( ) { \n" +
+ " // formatted comment \n" +
+ " /* disable-formatter *//* unformatted comment *//* enable-formatter */\n" +
+ "}\n" + "}\n";
+ formatSource(source,
+ "public class X01 {\n" +
+ "\n" +
+ "// disable-formatter\n" +
+ "void foo( ) { \n" +
+ " // unformatted comment \n" +
+ "}\n" +
+ "// enable-formatter \n" +
+ " void bar() {\n" +
+ " // formatted comment\n" +
+ " /* disable-formatter *//* unformatted comment *//* enable-formatter */\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug027079b() throws JavaModelException {
+ this.formatterPrefs.disabling_tag = "disable-formatter".toCharArray();
+ this.formatterPrefs.enabling_tag = "enable-formatter".toCharArray();
+ String source =
+ "public class X02 {\n" +
+ "void foo() {\n" +
+ "/* disable-formatter */\n" +
+ " /* unformatted comment */\n" +
+ " String test1= \"this\"+\n" +
+ " \"is\"+\n" +
+ " \"a specific\"+\n" +
+ " \"line wrapping \";\n" +
+ "\n" +
+ "/* enable-formatter */\n" +
+ " /* formatted comment */\n" +
+ " String test2= \"this\"+\n" +
+ " \"is\"+\n" +
+ " \"a specific\"+\n" +
+ " \"line wrapping \";\n" +
+ "}\n" +
+ "}\n";
+ formatSource(source,
+ "public class X02 {\n" +
+ " void foo() {\n" +
+ "/* disable-formatter */\n" +
+ " /* unformatted comment */\n" +
+ " String test1= \"this\"+\n" +
+ " \"is\"+\n" +
+ " \"a specific\"+\n" +
+ " \"line wrapping \";\n" +
+ "\n" +
+ "/* enable-formatter */\n" +
+ " /* formatted comment */\n" +
+ " String test2 = \"this\" + \"is\" + \"a specific\" + \"line wrapping \";\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug027079c() throws JavaModelException {
+ this.formatterPrefs.disabling_tag = "disable-formatter".toCharArray();
+ this.formatterPrefs.enabling_tag = "enable-formatter".toCharArray();
+ String source =
+ "public class X03 {\n" +
+ "void foo() {\n" +
+ "/* disable-formatter */\n" +
+ " bar(\n" +
+ " /** unformatted comment */\n" +
+ " \"this\" ,\n" +
+ " \"is\",\n" +
+ " \"a specific\",\n" +
+ " \"line wrapping \"\n" +
+ " );\n" +
+ "\n" +
+ "/* enable-formatter */\n" +
+ " bar(\n" +
+ " /** formatted comment */\n" +
+ " \"this\" ,\n" +
+ " \"is\",\n" +
+ " \"a specific\",\n" +
+ " \"line wrapping \"\n" +
+ " );\n" +
+ "}\n" +
+ "void bar(String... str) {}\n" +
+ "}\n";
+ formatSource(source,
+ "public class X03 {\n" +
+ " void foo() {\n" +
+ "/* disable-formatter */\n" +
+ " bar(\n" +
+ " /** unformatted comment */\n" +
+ " \"this\" ,\n" +
+ " \"is\",\n" +
+ " \"a specific\",\n" +
+ " \"line wrapping \"\n" +
+ " );\n" +
+ "\n" +
+ "/* enable-formatter */\n" +
+ " bar(\n" +
+ " /** formatted comment */\n" +
+ " \"this\", \"is\", \"a specific\", \"line wrapping \");\n" +
+ " }\n" +
+ "\n" +
+ " void bar(String... str) {\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug027079c2() throws JavaModelException {
+ this.formatterPrefs.disabling_tag = "disable-formatter".toCharArray();
+ this.formatterPrefs.enabling_tag = "enable-formatter".toCharArray();
+ String source =
+ "public class X03b {\n" +
+ "void foo() {\n" +
+ " bar(\n" +
+ "// disable-formatter\n" +
+ " /** unformatted comment */\n" +
+ " \"this\" ,\n" +
+ " \"is\",\n" +
+ " \"a specific\",\n" +
+ " \"line wrapping \"\n" +
+ "// enable-formatter\n" +
+ " );\n" +
+ " bar(\n" +
+ " /** formatted comment */\n" +
+ " \"this\" ,\n" +
+ " \"is\",\n" +
+ " \"a specific\",\n" +
+ " \"line wrapping \"\n" +
+ " );\n" +
+ "}\n" +
+ "void bar(String... str) {}\n" +
+ "}\n";
+ formatSource(source,
+ "public class X03b {\n" +
+ " void foo() {\n" +
+ " bar(\n" +
+ "// disable-formatter\n" +
+ " /** unformatted comment */\n" +
+ " \"this\" ,\n" +
+ " \"is\",\n" +
+ " \"a specific\",\n" +
+ " \"line wrapping \"\n" +
+ "// enable-formatter\n" +
+ " );\n" +
+ " bar(\n" +
+ " /** formatted comment */\n" +
+ " \"this\", \"is\", \"a specific\", \"line wrapping \");\n" +
+ " }\n" +
+ "\n" +
+ " void bar(String... str) {\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug027079d() throws JavaModelException {
+ this.formatterPrefs.disabling_tag = "disable-formatter".toCharArray();
+ this.formatterPrefs.enabling_tag = "enable-formatter".toCharArray();
+ String source =
+ "public class X04 {\r\n" +
+ "\r\n" +
+ "/* disable-formatter */\r\n" +
+ "void foo( ) { \r\n" +
+ " // unformatted comment \r\n" +
+ "}\r\n" +
+ "/* enable-formatter */\r\n" +
+ "void bar( ) { \r\n" +
+ " // formatted comment \r\n" +
+ "}\r\n" +
+ "}\r\n";
+ formatSource(source,
+ "public class X04 {\n" +
+ "\n" +
+ "/* disable-formatter */\n" +
+ "void foo( ) { \n" +
+ " // unformatted comment \n" +
+ "}\n" +
+ "/* enable-formatter */\n" +
+ " void bar() {\n" +
+ " // formatted comment\n" +
+ " }\n" +
+ "}\n",
+ CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS,
+ 0 /* indentation level */,
+ 0 /* offset */,
+ -1 /* length (all) */,
+ "\n",
+ true/*repeat*/);
+}
+public void testBug027079d2() throws JavaModelException {
+ this.formatterPrefs.disabling_tag = "disable-formatter".toCharArray();
+ this.formatterPrefs.enabling_tag = "enable-formatter".toCharArray();
+ String source =
+ "public class X04b {\n" +
+ "\n" +
+ "/* disable-formatter */\n" +
+ "void foo( ) { \n" +
+ " // unformatted comment \n" +
+ "}\n" +
+ "/* enable-formatter */\n" +
+ "void bar( ) { \n" +
+ " // formatted comment \n" +
+ "}\n" +
+ "}\n";
+ formatSource(source,
+ "public class X04b {\r\n" +
+ "\r\n" +
+ "/* disable-formatter */\r\n" +
+ "void foo( ) { \r\n" +
+ " // unformatted comment \r\n" +
+ "}\r\n" +
+ "/* enable-formatter */\r\n" +
+ " void bar() {\r\n" +
+ " // formatted comment\r\n" +
+ " }\r\n" +
+ "}\r\n",
+ CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS,
+ 0 /* indentation level */,
+ 0 /* offset */,
+ -1 /* length (all) */,
+ "\r\n",
+ true/*repeat*/);
+}
+public void testBug027079d3() throws JavaModelException {
+ this.formatterPrefs.disabling_tag = "disable-formatter".toCharArray();
+ this.formatterPrefs.enabling_tag = "enable-formatter".toCharArray();
+ String source =
+ "public class X04c {\r\n" +
+ "\r\n" +
+ "/* disable-formatter */\r\n" +
+ "void foo( ) { \r\n" +
+ " // unformatted comment \r\n" +
+ "}\r\n" +
+ "/* enable-formatter */\r\n" +
+ "void bar( ) { \r\n" +
+ " // formatted comment \r\n" +
+ "}\r\n" +
+ "}\r\n";
+ formatSource(source,
+ "public class X04c {\r\n" +
+ "\r\n" +
+ "/* disable-formatter */\r\n" +
+ "void foo( ) { \r\n" +
+ " // unformatted comment \r\n" +
+ "}\r\n" +
+ "/* enable-formatter */\r\n" +
+ " void bar() {\r\n" +
+ " // formatted comment\r\n" +
+ " }\r\n" +
+ "}\r\n",
+ CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS,
+ 0 /* indentation level */,
+ 0 /* offset */,
+ -1 /* length (all) */,
+ "\r\n",
+ true/*repeat*/);
+}
+public void testBug027079d4() throws JavaModelException {
+ this.formatterPrefs.disabling_tag = "disable-formatter".toCharArray();
+ this.formatterPrefs.enabling_tag = "enable-formatter".toCharArray();
+ String source =
+ "public class X04d {\n" +
+ "\n" +
+ "/* disable-formatter */\n" +
+ "void foo( ) { \n" +
+ " // unformatted comment \n" +
+ "}\n" +
+ "/* enable-formatter */\n" +
+ "void bar( ) { \n" +
+ " // formatted comment \n" +
+ "}\n" +
+ "}\n";
+ formatSource(source,
+ "public class X04d {\n" +
+ "\n" +
+ "/* disable-formatter */\n" +
+ "void foo( ) { \n" +
+ " // unformatted comment \n" +
+ "}\n" +
+ "/* enable-formatter */\n" +
+ " void bar() {\n" +
+ " // formatted comment\n" +
+ " }\n" +
+ "}\n",
+ CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS,
+ 0 /* indentation level */,
+ 0 /* offset */,
+ -1 /* length (all) */,
+ "\n",
+ true/*repeat*/);
+}
+public void testBug027079e() throws JavaModelException {
+ this.formatterPrefs.disabling_tag = "format: off".toCharArray();
+ this.formatterPrefs.enabling_tag = "format: on".toCharArray();
+ String source =
+ "public class X05 {\n" +
+ "\n" +
+ "/* format: off */\n" +
+ "void foo( ) { \n" +
+ " // unformatted comment\n" +
+ "}\n" +
+ "/* format: on */\n" +
+ "void bar( ) { \n" +
+ " // formatted comment\n" +
+ "}\n" +
+ "}\n";
+ formatSource(source,
+ "public class X05 {\n" +
+ "\n" +
+ "/* format: off */\n" +
+ "void foo( ) { \n" +
+ " // unformatted comment\n" +
+ "}\n" +
+ "/* format: on */\n" +
+ " void bar() {\n" +
+ " // formatted comment\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug027079f() throws JavaModelException {
+ this.formatterPrefs.disabling_tag = "format: off".toCharArray();
+ this.formatterPrefs.enabling_tag = "format: on".toCharArray();
+ String source =
+ "public class X06 {\n" +
+ "\n" +
+ "// format: off\n" +
+ "void foo( ) { \n" +
+ " // unformatted comment\n" +
+ "}\n" +
+ "// format: on\n" +
+ "void bar( ) { \n" +
+ " // formatted comment\n" +
+ "}\n" +
+ "}\n";
+ formatSource(source,
+ "public class X06 {\n" +
+ "\n" +
+ "// format: off\n" +
+ "void foo( ) { \n" +
+ " // unformatted comment\n" +
+ "}\n" +
+ "// format: on\n" +
+ " void bar() {\n" +
+ " // formatted comment\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug027079f2() throws JavaModelException {
+ this.formatterPrefs.disabling_tag = "format: off".toCharArray();
+ this.formatterPrefs.enabling_tag = "format: on".toCharArray();
+ String source =
+ "public class X06b {\n" +
+ "\n" +
+ "/** format: off */\n" +
+ "void foo( ) { \n" +
+ " // unformatted comment\n" +
+ "}\n" +
+ "/** format: on */\n" +
+ "void bar( ) { \n" +
+ " // formatted comment\n" +
+ "}\n" +
+ "}\n";
+ formatSource(source,
+ "public class X06b {\n" +
+ "\n" +
+ "/** format: off */\n" +
+ "void foo( ) { \n" +
+ " // unformatted comment\n" +
+ "}\n" +
+ "/** format: on */\n" +
+ " void bar() {\n" +
+ " // formatted comment\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug027079f3() throws JavaModelException {
+ this.formatterPrefs.disabling_tag = " format: off ".toCharArray();
+ this.formatterPrefs.enabling_tag = " format: on ".toCharArray();
+ String source =
+ "public class X06c {\n" +
+ "\n" +
+ "/* format: off */\n" +
+ "void foo( ) { \n" +
+ " // unformatted comment\n" +
+ "}\n" +
+ "// format: on \n" +
+ "void bar( ) { \n" +
+ " // formatted comment\n" +
+ "}\n" +
+ "}\n";
+ formatSource(source,
+ "public class X06c {\n" +
+ "\n" +
+ "/* format: off */\n" +
+ "void foo( ) { \n" +
+ " // unformatted comment\n" +
+ "}\n" +
+ "// format: on \n" +
+ " void bar() {\n" +
+ " // formatted comment\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug027079f4() throws JavaModelException {
+ this.formatterPrefs.disabling_tag = " format: off ".toCharArray();
+ this.formatterPrefs.enabling_tag = " format: on ".toCharArray();
+ String source =
+ "public class X06d {\n" +
+ "\n" +
+ "/* format: off */\n" +
+ "void foo( ) { \n" +
+ " // formatted comment\n" +
+ "}\n" +
+ "/* format: on */\n" +
+ "void bar( ) { \n" +
+ " // formatted comment\n" +
+ "}\n" +
+ "}\n";
+ formatSource(source,
+ "public class X06d {\n" +
+ "\n" +
+ " /* format: off */\n" +
+ " void foo() {\n" +
+ " // formatted comment\n" +
+ " }\n" +
+ "\n" +
+ " /* format: on */\n" +
+ " void bar() {\n" +
+ " // formatted comment\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+
+/**
* @bug 198074: [formatter] the code formatter doesn't respect my new lines
* @test Ensure that the formatter keep line breaks wrapping set by users in the code
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=198074"
@@ -581,6 +1150,360 @@
}
/**
+ * @bug 281655: [formatter] "Never join lines" does not work for annotations.
+ * @test Verify that "Never join lines" now works for annotations and also that
+ * element-value pairs are well wrapped using the new formatter option
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=281655"
+ */
+public void testBug281655() throws JavaModelException {
+ this.formatterPrefs.join_wrapped_lines = false;
+ String source =
+ "@MessageDriven(mappedName = \"filiality/SchedulerMQService\", \n" +
+ " activationConfig = { \n" +
+ " @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" +
+ "propertyValue = \"0/10 * * * * ?\") \n" +
+ " })\n" +
+ "@RunAs(\"admin\")\n" +
+ "@ResourceAdapter(\"quartz-ra.rar\")\n" +
+ "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" +
+ "public class X {\n" +
+ "}\n";
+ formatSource(source,
+ "@MessageDriven(mappedName = \"filiality/SchedulerMQService\",\n" +
+ " activationConfig = {\n" +
+ " @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" +
+ " propertyValue = \"0/10 * * * * ?\")\n" +
+ " })\n" +
+ "@RunAs(\"admin\")\n" +
+ "@ResourceAdapter(\"quartz-ra.rar\")\n" +
+ "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" +
+ "public class X {\n" +
+ "}\n"
+ );
+}
+public void testBug281655a() throws JavaModelException {
+ this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_NO_ALIGNMENT;
+ String source =
+ "@MessageDriven(mappedName = \"filiality/SchedulerMQService\", \n" +
+ " activationConfig = { \n" +
+ " @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" +
+ "propertyValue = \"0/10 * * * * ?\") \n" +
+ " })\n" +
+ "@RunAs(\"admin\")\n" +
+ "@ResourceAdapter(\"quartz-ra.rar\")\n" +
+ "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" +
+ "public class X {\n" +
+ "}\n";
+ formatSource(source,
+ "@MessageDriven(mappedName = \"filiality/SchedulerMQService\", activationConfig = { @ActivationConfigProperty(propertyName = \"cronTrigger\", propertyValue = \"0/10 * * * * ?\") })\n" +
+ "@RunAs(\"admin\")\n" +
+ "@ResourceAdapter(\"quartz-ra.rar\")\n" +
+ "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" +
+ "public class X {\n" +
+ "}\n"
+ );
+}
+public void testBug281655b() throws JavaModelException {
+ this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_COMPACT_SPLIT;
+ String source =
+ "@MessageDriven(mappedName = \"filiality/SchedulerMQService\", \n" +
+ " activationConfig = { \n" +
+ " @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" +
+ "propertyValue = \"0/10 * * * * ?\") \n" +
+ " })\n" +
+ "@RunAs(\"admin\")\n" +
+ "@ResourceAdapter(\"quartz-ra.rar\")\n" +
+ "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" +
+ "public class X {\n" +
+ "}\n";
+ formatSource(source,
+ "@MessageDriven(\n" +
+ " mappedName = \"filiality/SchedulerMQService\",\n" +
+ " activationConfig = { @ActivationConfigProperty(\n" +
+ " propertyName = \"cronTrigger\", propertyValue = \"0/10 * * * * ?\") })\n" +
+ "@RunAs(\"admin\")\n" +
+ "@ResourceAdapter(\"quartz-ra.rar\")\n" +
+ "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" +
+ "public class X {\n" +
+ "}\n"
+ );
+}
+public void testBug281655c() throws JavaModelException {
+ this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_COMPACT_FIRST_BREAK_SPLIT;
+ String source =
+ "@MessageDriven(mappedName = \"filiality/SchedulerMQService\", \n" +
+ " activationConfig = { \n" +
+ " @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" +
+ "propertyValue = \"0/10 * * * * ?\") \n" +
+ " })\n" +
+ "@RunAs(\"admin\")\n" +
+ "@ResourceAdapter(\"quartz-ra.rar\")\n" +
+ "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" +
+ "public class X {\n" +
+ "}\n";
+ formatSource(source,
+ "@MessageDriven(\n" +
+ " mappedName = \"filiality/SchedulerMQService\",\n" +
+ " activationConfig = { @ActivationConfigProperty(\n" +
+ " propertyName = \"cronTrigger\", propertyValue = \"0/10 * * * * ?\") })\n" +
+ "@RunAs(\"admin\")\n" +
+ "@ResourceAdapter(\"quartz-ra.rar\")\n" +
+ "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" +
+ "public class X {\n" +
+ "}\n"
+ );
+}
+public void testBug281655d() throws JavaModelException {
+ this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_ONE_PER_LINE_SPLIT;
+ String source =
+ "@MessageDriven(mappedName = \"filiality/SchedulerMQService\", \n" +
+ " activationConfig = { \n" +
+ " @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" +
+ "propertyValue = \"0/10 * * * * ?\") \n" +
+ " })\n" +
+ "@RunAs(\"admin\")\n" +
+ "@ResourceAdapter(\"quartz-ra.rar\")\n" +
+ "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" +
+ "public class X {\n" +
+ "}\n";
+ formatSource(source,
+ "@MessageDriven(\n" +
+ " mappedName = \"filiality/SchedulerMQService\",\n" +
+ " activationConfig = { @ActivationConfigProperty(\n" +
+ " propertyName = \"cronTrigger\",\n" +
+ " propertyValue = \"0/10 * * * * ?\") })\n" +
+ "@RunAs(\"admin\")\n" +
+ "@ResourceAdapter(\"quartz-ra.rar\")\n" +
+ "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" +
+ "public class X {\n" +
+ "}\n"
+ );
+}
+public void testBug281655e() throws JavaModelException {
+ this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_NEXT_SHIFTED_SPLIT;
+ String source =
+ "@MessageDriven(mappedName = \"filiality/SchedulerMQService\", \n" +
+ " activationConfig = { \n" +
+ " @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" +
+ "propertyValue = \"0/10 * * * * ?\") \n" +
+ " })\n" +
+ "@RunAs(\"admin\")\n" +
+ "@ResourceAdapter(\"quartz-ra.rar\")\n" +
+ "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" +
+ "public class X {\n" +
+ "}\n";
+ formatSource(source,
+ "@MessageDriven(\n" +
+ " mappedName = \"filiality/SchedulerMQService\",\n" +
+ " activationConfig = { @ActivationConfigProperty(\n" +
+ " propertyName = \"cronTrigger\",\n" +
+ " propertyValue = \"0/10 * * * * ?\") })\n" +
+ "@RunAs(\"admin\")\n" +
+ "@ResourceAdapter(\"quartz-ra.rar\")\n" +
+ "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" +
+ "public class X {\n" +
+ "}\n"
+ );
+}
+public void testBug281655f() throws JavaModelException {
+ this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_NEXT_PER_LINE_SPLIT;
+ String source =
+ "@MessageDriven(mappedName = \"filiality/SchedulerMQService\", \n" +
+ " activationConfig = { \n" +
+ " @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" +
+ "propertyValue = \"0/10 * * * * ?\") \n" +
+ " })\n" +
+ "@RunAs(\"admin\")\n" +
+ "@ResourceAdapter(\"quartz-ra.rar\")\n" +
+ "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" +
+ "public class X {\n" +
+ "}\n";
+ formatSource(source,
+ "@MessageDriven(mappedName = \"filiality/SchedulerMQService\",\n" +
+ " activationConfig = { @ActivationConfigProperty(propertyName = \"cronTrigger\",\n" +
+ " propertyValue = \"0/10 * * * * ?\") })\n" +
+ "@RunAs(\"admin\")\n" +
+ "@ResourceAdapter(\"quartz-ra.rar\")\n" +
+ "@TransactionAttribute(TransactionAttributeType.NOT_SUPPORTED)\n" +
+ "public class X {\n" +
+ "}\n"
+ );
+}
+
+/**
+ * @bug 282030: [formatter] Java annotation formatting
+ * @test Verify that element-value pairs are well wrapped using the new formatter option
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=282030"
+ */
+public void testBug282030() throws JavaModelException {
+ this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_COMPACT_SPLIT;
+ String source =
+ "@DeclareParents(value =\n" +
+ "\"com.apress.springrecipes.calculator.ArithmeticCalculatorImpl\", defaultImpl =\n" +
+ "MaxCalculatorImpl.class) \n" +
+ "public class X {\n" +
+ "}\n";
+ formatSource(source,
+ "@DeclareParents(\n" +
+ " value = \"com.apress.springrecipes.calculator.ArithmeticCalculatorImpl\",\n" +
+ " defaultImpl = MaxCalculatorImpl.class)\n" +
+ "public class X {\n" +
+ "}\n"
+ );
+}
+public void testBug282030a() throws JavaModelException {
+ String source =
+ "@MyAnnot(value1 = \"this is an example\", value2 = \"of an annotation\", value3 = \"with several arguments\", value4 = \"which may need to be wrapped\")\n" +
+ "public class Test {\n" +
+ "}\n";
+ formatSource(source,
+ "@MyAnnot(value1 = \"this is an example\", value2 = \"of an annotation\", value3 = \"with several arguments\", value4 = \"which may need to be wrapped\")\n" +
+ "public class Test {\n" +
+ "}\n"
+ );
+}
+public void testBug282030b() throws JavaModelException {
+ this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_COMPACT_SPLIT;
+ String source =
+ "@MyAnnot(value1 = \"this is an example\", value2 = \"of an annotation\", value3 = \"with several arguments\", value4 = \"which may need to be wrapped\")\n" +
+ "public class Test {\n" +
+ "}\n";
+ formatSource(source,
+ "@MyAnnot(value1 = \"this is an example\", value2 = \"of an annotation\",\n" +
+ " value3 = \"with several arguments\",\n" +
+ " value4 = \"which may need to be wrapped\")\n" +
+ "public class Test {\n" +
+ "}\n"
+ );
+}
+public void testBug282030c() throws JavaModelException {
+ this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_COMPACT_FIRST_BREAK_SPLIT;
+ String source =
+ "@MyAnnot(value1 = \"this is an example\", value2 = \"of an annotation\", value3 = \"with several arguments\", value4 = \"which may need to be wrapped\")\n" +
+ "public class Test {\n" +
+ "}\n";
+ formatSource(source,
+ "@MyAnnot(\n" +
+ " value1 = \"this is an example\", value2 = \"of an annotation\",\n" +
+ " value3 = \"with several arguments\",\n" +
+ " value4 = \"which may need to be wrapped\")\n" +
+ "public class Test {\n" +
+ "}\n"
+ );
+}
+public void testBug282030d() throws JavaModelException {
+ this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_ONE_PER_LINE_SPLIT;
+ String source =
+ "@MyAnnot(value1 = \"this is an example\", value2 = \"of an annotation\", value3 = \"with several arguments\", value4 = \"which may need to be wrapped\")\n" +
+ "public class Test {\n" +
+ "}\n";
+ formatSource(source,
+ "@MyAnnot(\n" +
+ " value1 = \"this is an example\",\n" +
+ " value2 = \"of an annotation\",\n" +
+ " value3 = \"with several arguments\",\n" +
+ " value4 = \"which may need to be wrapped\")\n" +
+ "public class Test {\n" +
+ "}\n"
+ );
+}
+public void testBug282030e() throws JavaModelException {
+ this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_NEXT_SHIFTED_SPLIT;
+ String source =
+ "@MyAnnot(value1 = \"this is an example\", value2 = \"of an annotation\", value3 = \"with several arguments\", value4 = \"which may need to be wrapped\")\n" +
+ "public class Test {\n" +
+ "}\n";
+ formatSource(source,
+ "@MyAnnot(\n" +
+ " value1 = \"this is an example\",\n" +
+ " value2 = \"of an annotation\",\n" +
+ " value3 = \"with several arguments\",\n" +
+ " value4 = \"which may need to be wrapped\")\n" +
+ "public class Test {\n" +
+ "}\n"
+ );
+}
+public void testBug282030f() throws JavaModelException {
+ this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_NEXT_PER_LINE_SPLIT;
+ String source =
+ "@MyAnnot(value1 = \"this is an example\", value2 = \"of an annotation\", value3 = \"with several arguments\", value4 = \"which may need to be wrapped\")\n" +
+ "public class Test {\n" +
+ "}\n";
+ formatSource(source,
+ "@MyAnnot(value1 = \"this is an example\",\n" +
+ " value2 = \"of an annotation\",\n" +
+ " value3 = \"with several arguments\",\n" +
+ " value4 = \"which may need to be wrapped\")\n" +
+ "public class Test {\n" +
+ "}\n"
+ );
+}
+public void testBug282030g1() throws JavaModelException {
+ this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_ONE_PER_LINE_SPLIT;
+ String source =
+ "@MyAnnot1(member1 = \"sample1\", member2 = \"sample2\")\n" +
+ "public class X {\n" +
+ "}\n";
+ formatSource(source,
+ "@MyAnnot1(member1 = \"sample1\", member2 = \"sample2\")\n" +
+ "public class X {\n" +
+ "}\n"
+ );
+}
+public void testBug282030g2() throws JavaModelException {
+ this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_ONE_PER_LINE_SPLIT | Alignment.M_FORCE;
+ String source =
+ "@MyAnnot1(member1 = \"sample1\", member2 = \"sample2\")\n" +
+ "public class X {\n" +
+ "}\n";
+ formatSource(source,
+ "@MyAnnot1(\n" +
+ " member1 = \"sample1\",\n" +
+ " member2 = \"sample2\")\n" +
+ "public class X {\n" +
+ "}\n"
+ );
+}
+public void testBug282030h1() throws JavaModelException {
+ this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_ONE_PER_LINE_SPLIT;
+ String source =
+ "@MyAnnot1(name = \"sample1\", \n" +
+ " value = { \n" +
+ " @MyAnnot2(name = \"sample2\",\n" +
+ "value = \"demo\") \n" +
+ " })\n" +
+ "public class X {\n" +
+ "}\n";
+ formatSource(source,
+ "@MyAnnot1(name = \"sample1\", value = { @MyAnnot2(\n" +
+ " name = \"sample2\",\n" +
+ " value = \"demo\") })\n" +
+ "public class X {\n" +
+ "}\n"
+ );
+}
+public void testBug282030h2() throws JavaModelException {
+ this.formatterPrefs.alignment_for_arguments_in_annotation = Alignment.M_ONE_PER_LINE_SPLIT | Alignment.M_FORCE;
+ String source =
+ "@MyAnnot1(name = \"sample1\", \n" +
+ " value = { \n" +
+ " @MyAnnot2(name = \"sample2\",\n" +
+ "value = \"demo\") \n" +
+ " })\n" +
+ "public class X {\n" +
+ "}\n";
+ formatSource(source,
+ "@MyAnnot1(\n" +
+ " name = \"sample1\",\n" +
+ " value = { @MyAnnot2(\n" +
+ " name = \"sample2\",\n" +
+ " value = \"demo\") })\n" +
+ "public class X {\n" +
+ "}\n"
+ );
+}
+
+/**
* @bug 283467: [formatter] wrong indentation with 'Never join lines' selected
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=283467"
*/
@@ -622,6 +1545,252 @@
}
/**
+ * @bug 284789: [formatter] Does not line-break method declaration exception with parameters
+ * @test Verify that the new preference to split method declaration works properly
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=284789"
+ */
+public void testBug284789() throws JavaModelException {
+ this.formatterPrefs.alignment_for_method_declaration = Alignment.M_COMPACT_SPLIT;
+ String source =
+ "public class Test {\n" +
+ "public synchronized List<FantasticallyWonderfulContainer<FantasticallyWonderfulClass>> getMeTheFantasticContainer() {\n" +
+ " return null;\n" +
+ "}\n" +
+ "}\n";
+ formatSource(source,
+ "public class Test {\n" +
+ " public synchronized\n" +
+ " List<FantasticallyWonderfulContainer<FantasticallyWonderfulClass>>\n" +
+ " getMeTheFantasticContainer() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug284789_01a() throws JavaModelException {
+ // default is no wrapping for method declaration
+ String source =
+ "class X01 {\n" +
+ " public final synchronized java.lang.String a_method_which_have_a_very_long_name() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n";
+ formatSource(source,
+ "class X01 {\n" +
+ " public final synchronized java.lang.String a_method_which_have_a_very_long_name() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug284789_01b() throws JavaModelException {
+ this.formatterPrefs.alignment_for_method_declaration = Alignment.M_COMPACT_SPLIT;
+ String source =
+ "class X01 {\n" +
+ " public final synchronized java.lang.String a_method_which_have_a_very_long_name() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n";
+ formatSource(source,
+ "class X01 {\n" +
+ " public final synchronized java.lang.String\n" +
+ " a_method_which_have_a_very_long_name() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug284789_01c() throws JavaModelException {
+ this.formatterPrefs.alignment_for_method_declaration = Alignment.M_COMPACT_FIRST_BREAK_SPLIT;
+ String source =
+ "class X01 {\n" +
+ " public final synchronized java.lang.String a_method_which_have_a_very_long_name() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n";
+ formatSource(source,
+ "class X01 {\n" +
+ " public final synchronized\n" +
+ " java.lang.String a_method_which_have_a_very_long_name() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug284789_01d() throws JavaModelException {
+ this.formatterPrefs.alignment_for_method_declaration = Alignment.M_ONE_PER_LINE_SPLIT;
+ String source =
+ "class X01 {\n" +
+ " public final synchronized java.lang.String a_method_which_have_a_very_long_name() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n";
+ formatSource(source,
+ "class X01 {\n" +
+ " public final synchronized\n" +
+ " java.lang.String\n" +
+ " a_method_which_have_a_very_long_name() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug284789_01e() throws JavaModelException {
+ this.formatterPrefs.alignment_for_method_declaration = Alignment.M_NEXT_SHIFTED_SPLIT;
+ String source =
+ "class X01 {\n" +
+ " public final synchronized java.lang.String a_method_which_have_a_very_long_name() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n";
+ formatSource(source,
+ "class X01 {\n" +
+ " public final synchronized\n" +
+ " java.lang.String\n" +
+ " a_method_which_have_a_very_long_name() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug284789_01f() throws JavaModelException {
+ this.formatterPrefs.alignment_for_method_declaration = Alignment.M_NEXT_PER_LINE_SPLIT;
+ String source =
+ "class X01 {\n" +
+ " public final synchronized java.lang.String a_method_which_have_a_very_long_name() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n";
+ formatSource(source,
+ "class X01 {\n" +
+ " public final synchronized java.lang.String\n" +
+ " a_method_which_have_a_very_long_name() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug284789_02a() throws JavaModelException {
+ // default is no wrapping for method declaration
+ String source =
+ "class X02 {\n" +
+ " public final synchronized java.lang.String a_method_which_have_a_very_long_name(String first, String second, String third) {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n";
+ formatSource(source,
+ "class X02 {\n" +
+ " public final synchronized java.lang.String a_method_which_have_a_very_long_name(\n" +
+ " String first, String second, String third) {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug284789_02b() throws JavaModelException {
+ this.formatterPrefs.alignment_for_method_declaration = Alignment.M_COMPACT_SPLIT;
+ this.formatterPrefs.alignment_for_parameters_in_method_declaration = Alignment.M_COMPACT_SPLIT;
+ String source =
+ "class X02 {\n" +
+ " public final synchronized java.lang.String a_method_which_have_a_very_long_name(String first, String second, String third) {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n";
+ formatSource(source,
+ "class X02 {\n" +
+ " public final synchronized java.lang.String\n" +
+ " a_method_which_have_a_very_long_name(String first, String second,\n" +
+ " String third) {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug284789_02c() throws JavaModelException {
+ this.formatterPrefs.alignment_for_method_declaration = Alignment.M_COMPACT_FIRST_BREAK_SPLIT;
+ this.formatterPrefs.alignment_for_parameters_in_method_declaration = Alignment.M_COMPACT_FIRST_BREAK_SPLIT;
+ String source =
+ "class X02 {\n" +
+ " public final synchronized java.lang.String a_method_which_have_a_very_long_name(String first, String second, String third) {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n";
+ formatSource(source,
+ "class X02 {\n" +
+ " public final synchronized\n" +
+ " java.lang.String a_method_which_have_a_very_long_name(\n" +
+ " String first, String second, String third) {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug284789_02d() throws JavaModelException {
+ this.formatterPrefs.alignment_for_method_declaration = Alignment.M_ONE_PER_LINE_SPLIT;
+ this.formatterPrefs.alignment_for_parameters_in_method_declaration = Alignment.M_ONE_PER_LINE_SPLIT;
+ String source =
+ "class X02 {\n" +
+ " public final synchronized java.lang.String a_method_which_have_a_very_long_name(String first, String second, String third) {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n";
+ formatSource(source,
+ "class X02 {\n" +
+ " public final synchronized\n" +
+ " java.lang.String\n" +
+ " a_method_which_have_a_very_long_name(\n" +
+ " String first,\n" +
+ " String second,\n" +
+ " String third) {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug284789_02e() throws JavaModelException {
+ this.formatterPrefs.alignment_for_method_declaration = Alignment.M_NEXT_SHIFTED_SPLIT;
+ this.formatterPrefs.alignment_for_parameters_in_method_declaration = Alignment.M_NEXT_SHIFTED_SPLIT;
+ String source =
+ "class X02 {\n" +
+ " public final synchronized java.lang.String a_method_which_have_a_very_long_name(String first, String second, String third) {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n";
+ formatSource(source,
+ "class X02 {\n" +
+ " public final synchronized\n" +
+ " java.lang.String\n" +
+ " a_method_which_have_a_very_long_name(\n" +
+ " String first,\n" +
+ " String second,\n" +
+ " String third) {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug284789_02f() throws JavaModelException {
+ this.formatterPrefs.alignment_for_method_declaration = Alignment.M_NEXT_PER_LINE_SPLIT;
+ this.formatterPrefs.alignment_for_parameters_in_method_declaration = Alignment.M_NEXT_PER_LINE_SPLIT;
+ String source =
+ "class X02 {\n" +
+ " public final synchronized java.lang.String a_method_which_have_a_very_long_name(String first, String second, String third) {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n";
+ formatSource(source,
+ "class X02 {\n" +
+ " public final synchronized java.lang.String\n" +
+ " a_method_which_have_a_very_long_name(String first,\n" +
+ " String second,\n" +
+ " String third) {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+
+/**
* @bug 285565: [formatter] wrong indentation with 'Never join lines' selected
* @test Test to make sure that use either formatter or {@link IndentManipulation}
* API methods an indentation set to zero does not thrown any exception.
@@ -3928,4 +5097,280 @@
"}\n";
formatSource(source);
}
+
+/**
+ * @bug 302123: [formatter] AssertionFailedException occurs while formatting a source containing the specific javadoc comment...
+ * @test Verify that no exception occurs while formatting source including the specific comment
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=302123"
+ */
+public void testBug302123() {
+ String source =
+ "package test;\n" +
+ "public class Test {\n" +
+ " public static void main(String[] args) {\n" +
+ " String s=\"X\"+/** ***/\"Y\";\n" +
+ " }\n" +
+ "\n" +
+ "}\n";
+ formatSource(source,
+ "package test;\n" +
+ "\n" +
+ "public class Test {\n" +
+ " public static void main(String[] args) {\n" +
+ " String s = \"X\" + /** ***/\n" +
+ " \"Y\";\n" +
+ " }\n" +
+ "\n" +
+ "}\n"
+ );
+}
+public void testBug302123b() {
+ String source =
+ "package test;\n" +
+ "public class Test {\n" +
+ " public static void main(String[] args) {\n" +
+ " String s=\"X\"+/** XXX ***/\"Y\";\n" +
+ " }\n" +
+ "\n" +
+ "}\n";
+ formatSource(source,
+ "package test;\n" +
+ "\n" +
+ "public class Test {\n" +
+ " public static void main(String[] args) {\n" +
+ " String s = \"X\" + /** XXX ***/\n" +
+ " \"Y\";\n" +
+ " }\n" +
+ "\n" +
+ "}\n"
+ );
+}
+public void testBug302123c() {
+ String source =
+ "package test;\n" +
+ "public class Test {\n" +
+ " public static void main(String[] args) {\n" +
+ " String s=\"X\"+/** ** XXX ** ***/\"Y\";\n" +
+ " }\n" +
+ "\n" +
+ "}\n";
+ formatSource(source,
+ "package test;\n" +
+ "\n" +
+ "public class Test {\n" +
+ " public static void main(String[] args) {\n" +
+ " String s = \"X\" + /** ** XXX ** ***/\n" +
+ " \"Y\";\n" +
+ " }\n" +
+ "\n" +
+ "}\n"
+ );
+}
+public void testBug302123d() {
+ String source =
+ "package test;\n" +
+ "public class Test {\n" +
+ " public static void main(String[] args) {\n" +
+ " String s=\"X\"+/**AAA *** BBB *** CCC***/\"Y\";\n" +
+ " }\n" +
+ "\n" +
+ "}\n";
+ formatSource(source,
+ "package test;\n" +
+ "\n" +
+ "public class Test {\n" +
+ " public static void main(String[] args) {\n" +
+ " String s = \"X\" + /** AAA *** BBB *** CCC ***/\n" +
+ " \"Y\";\n" +
+ " }\n" +
+ "\n" +
+ "}\n"
+ );
+}
+
+/**
+ * @bug 302552: [formatter] Formatting qualified invocations can be broken when the Line Wrapping policy forces element to be on a new line
+ * @test Verify that wrapping policies forcing the first element to be on a new line are working again...
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=302552"
+ */
+public void testBug302552_LW0() {
+ this.formatterPrefs.page_width = 20;
+ this.formatterPrefs.alignment_for_selector_in_method_invocation = Alignment.M_NO_ALIGNMENT;
+ String source =
+ "class Sample2 {int foo(Some a) {return a.getFirst();}}\n";
+ formatSource(source,
+ "class Sample2 {\n" +
+ " int foo(Some a) {\n" +
+ " return a.getFirst();\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug302552_LW1() {
+ this.formatterPrefs.page_width = 20;
+ this.formatterPrefs.alignment_for_selector_in_method_invocation = Alignment.M_COMPACT_SPLIT;
+ String source =
+ "class Sample2 {int foo(Some a) {return a.getFirst();}}\n";
+ formatSource(source,
+ "class Sample2 {\n" +
+ " int foo(Some a) {\n" +
+ " return a.getFirst();\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug302552_LW2() {
+ this.formatterPrefs.page_width = 20;
+ this.formatterPrefs.alignment_for_selector_in_method_invocation = Alignment.M_COMPACT_FIRST_BREAK_SPLIT;
+ String source =
+ "class Sample2 {int foo(Some a) {return a.getFirst();}}\n";
+ formatSource(source,
+ "class Sample2 {\n" +
+ " int foo(Some a) {\n" +
+ " return a\n" +
+ " .getFirst();\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug302552_LW3() {
+ this.formatterPrefs.page_width = 20;
+ this.formatterPrefs.alignment_for_selector_in_method_invocation = Alignment.M_ONE_PER_LINE_SPLIT;
+ String source =
+ "class Sample2 {int foo(Some a) {return a.getFirst();}}\n";
+ formatSource(source,
+ "class Sample2 {\n" +
+ " int foo(Some a) {\n" +
+ " return a\n" +
+ " .getFirst();\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug302552_LW4() {
+ this.formatterPrefs.page_width = 20;
+ this.formatterPrefs.alignment_for_selector_in_method_invocation = Alignment.M_NEXT_SHIFTED_SPLIT;
+ String source =
+ "class Sample2 {int foo(Some a) {return a.getFirst();}}\n";
+ formatSource(source,
+ "class Sample2 {\n" +
+ " int foo(Some a) {\n" +
+ " return a\n" +
+ " .getFirst();\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug302552_LW5() {
+ this.formatterPrefs.page_width = 20;
+ this.formatterPrefs.alignment_for_selector_in_method_invocation = Alignment.M_NEXT_PER_LINE_SPLIT;
+ String source =
+ "class Sample2 {int foo(Some a) {return a.getFirst();}}\n";
+ formatSource(source,
+ "class Sample2 {\n" +
+ " int foo(Some a) {\n" +
+ " return a.getFirst();\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+
+/**
+ * @bug 304529: [formatter] NPE when either the disabling or the enabling tag is not defined
+ * @test Verify that having an empty disabling or enabling is now accepted by the formatter
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=304529"
+ */
+public void testBug304529() {
+ this.formatterPrefs.disabling_tag = "off".toCharArray();
+ this.formatterPrefs.enabling_tag = null;
+ String source =
+ "/* off */\n" +
+ "public class X01 {\n" +
+ "void foo( ) { \n" +
+ " // unformatted area\n" +
+ "}\n" +
+ "}\n";
+ formatSource(source);
+}
+public void testBug304529b() {
+ this.formatterPrefs.disabling_tag = null;
+ this.formatterPrefs.enabling_tag = "on".toCharArray();
+ String source =
+ "/* on */\n" +
+ "public class X01 {\n" +
+ "void foo( ) { \n" +
+ " // formatted area\n" +
+ "}\n" +
+ "}\n";
+ formatSource(source,
+ "/* on */\n" +
+ "public class X01 {\n" +
+ " void foo() {\n" +
+ " // formatted area\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug304529c() {
+ this.formatterPrefs = null;
+ this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_DISABLING_TAG, "off");
+ this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_ENABLING_TAG, "");
+ String source =
+ "/* off */\n" +
+ "public class X01 {\n" +
+ "void foo( ) { \n" +
+ " // unformatted area\n" +
+ "}\n" +
+ "}\n";
+ formatSource(source);
+}
+public void testBug304529d() {
+ this.formatterPrefs = null;
+ this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_DISABLING_TAG, "");
+ this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_ENABLING_TAG, "on");
+ String source =
+ "/* on */\n" +
+ "public class X01 {\n" +
+ "void foo( ) { \n" +
+ " // formatted area\n" +
+ "}\n" +
+ "}\n";
+ formatSource(source,
+ "/* on */\n" +
+ "public class X01 {\n" +
+ " void foo() {\n" +
+ " // formatted area\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+public void testBug304529e() {
+ this.formatterPrefs = null;
+ this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_DISABLING_TAG, "off");
+ this.formatterOptions.put(DefaultCodeFormatterConstants.FORMATTER_ENABLING_TAG, "on");
+ String source =
+ "public class X01 {\n" +
+ "/* off */\n" +
+ "void foo( ) { \n" +
+ " // unformatted area\n" +
+ "}\n" +
+ "/* on */\n" +
+ "void bar( ) { \n" +
+ " // formatted area\n" +
+ "}\n" +
+ "}\n";
+ formatSource(source,
+ "public class X01 {\n" +
+ "/* off */\n" +
+ "void foo( ) { \n" +
+ " // unformatted area\n" +
+ "}\n" +
+ "/* on */\n" +
+ " void bar() {\n" +
+ " // formatted area\n" +
+ " }\n" +
+ "}\n"
+ );
+}
+
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java
index fa6a3ad..6e1542e 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsBugsTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation 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
@@ -2200,8 +2200,6 @@
" return null;\n" +
" }\n" +
"}\n";
- // TODO (frederic) line comment should be formatted when F_INCLUDE_COMMENTS
- // flag will work for all snippet kinds
formatSource(source,
"/**\n" +
" * Need a javadoc comment before to get the exception.\n" +
@@ -2213,7 +2211,7 @@
" * If there is an authority, it is:\n" +
" * \n" +
" * <pre>\n" +
- " * //class body snippet\n" +
+ " * // class body snippet\n" +
" * public class X {\n" +
" * }\n" +
" * </pre>\n" +
@@ -2265,6 +2263,142 @@
}
/**
+ * @bug 236406: [formatter] Formatting qualified invocations can be broken when the Line Wrapping policy forces element to be on a new line
+ * @test Verify that wrapping policies forcing the first element to be on a new line are working again...
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=236406"
+ */
+public void testBug236406_CDB1() {
+ String source =
+ "/** Javadoc comment */void foo1() {System.out.println();}\n" +
+ "// Line comment \n" +
+ "void foo2() {System.out.println();}\n" +
+ "/* Block comment */\n" +
+ "void foo3() {\n" +
+ "/* statement Block comment */\n" +
+ "System.out.println();}\n";
+ formatSource(source,
+ "/** Javadoc comment */\n" +
+ "void foo1() {\n" +
+ " System.out.println();\n" +
+ "}\n" +
+ "\n" +
+ "// Line comment \n" +
+ "void foo2() {\n" +
+ " System.out.println();\n" +
+ "}\n" +
+ "\n" +
+ "/* Block comment */\n" +
+ "void foo3() {\n" +
+ " /* statement Block comment */\n" +
+ " System.out.println();\n" +
+ "}",
+ CodeFormatter.K_CLASS_BODY_DECLARATIONS
+ );
+}
+public void testBug236406_CDB2() {
+ String source =
+ "/** Javadoc comment */void foo1() {System.out.println();}\n" +
+ "// Line comment \n" +
+ "void foo2() {System.out.println();}\n" +
+ "/* Block comment */\n" +
+ "void foo3() {\n" +
+ "/* statement Block comment */\n" +
+ "System.out.println();}\n";
+ formatSource(source,
+ "/** Javadoc comment */\n" +
+ "void foo1() {\n" +
+ " System.out.println();\n" +
+ "}\n" +
+ "\n" +
+ "// Line comment\n" +
+ "void foo2() {\n" +
+ " System.out.println();\n" +
+ "}\n" +
+ "\n" +
+ "/* Block comment */\n" +
+ "void foo3() {\n" +
+ " /* statement Block comment */\n" +
+ " System.out.println();\n" +
+ "}",
+ CodeFormatter.K_CLASS_BODY_DECLARATIONS | CodeFormatter.F_INCLUDE_COMMENTS
+ );
+}
+public void testBug236406_EX1() {
+ String source =
+ "// Line comment \n" +
+ "i = \n" +
+ "/** Javadoc comment */\n" +
+ "1 + (/* Block comment*/++a)\n";
+ formatSource(source,
+ "// Line comment \n" +
+ "i =\n" +
+ "/** Javadoc comment */\n" +
+ "1 + (/* Block comment*/++a)",
+ CodeFormatter.K_EXPRESSION
+ );
+}
+public void testBug236406_EX2() {
+ String source =
+ "// Line comment \n" +
+ "i = \n" +
+ "/** Javadoc comment */\n" +
+ "1 + (/* Block comment*/++a)\n";
+ formatSource(source,
+ "// Line comment\n" +
+ "i =\n" +
+ "/** Javadoc comment */\n" +
+ "1 + (/* Block comment */++a)",
+ CodeFormatter.K_EXPRESSION | CodeFormatter.F_INCLUDE_COMMENTS
+ );
+}
+public void testBug236406_ST1() {
+ String source =
+ "/** Javadoc comment */foo1();\n" +
+ "// Line comment \n" +
+ "foo2();\n" +
+ "/* Block comment */\n" +
+ "foo3(); {\n" +
+ "/* indented Block comment */\n" +
+ "System.out.println();}\n";
+ formatSource(source,
+ "/** Javadoc comment */\n" +
+ "foo1();\n" +
+ "// Line comment \n" +
+ "foo2();\n" +
+ "/* Block comment */\n" +
+ "foo3();\n" +
+ "{\n" +
+ " /* indented Block comment */\n" +
+ " System.out.println();\n" +
+ "}",
+ CodeFormatter.K_STATEMENTS
+ );
+}
+public void testBug236406_ST2() {
+ String source =
+ "/** Javadoc comment */foo1();\n" +
+ "// Line comment \n" +
+ "foo2();\n" +
+ "/* Block comment */\n" +
+ "foo3(); {\n" +
+ "/* indented Block comment */\n" +
+ "System.out.println();}\n";
+ formatSource(source,
+ "/** Javadoc comment */\n" +
+ "foo1();\n" +
+ "// Line comment\n" +
+ "foo2();\n" +
+ "/* Block comment */\n" +
+ "foo3();\n" +
+ "{\n" +
+ " /* indented Block comment */\n" +
+ " System.out.println();\n" +
+ "}",
+ CodeFormatter.K_STATEMENTS | CodeFormatter.F_INCLUDE_COMMENTS
+ );
+}
+
+/**
* @bug 237051: [formatter] Formatter insert blank lines after javadoc if javadoc contains Commons Attributes @@ annotations
* @test Ensure that Commons Attributes @@ annotations do not screw up the comment formatter
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=237051"
@@ -3487,6 +3621,125 @@
}
/**
+ * @bug 251133: [formatter] Automatic formatting single line comments is incoherent among tools
+ * @test Test the new formatter capability to completely ignore line comments starting at first column
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=251133"
+ */
+public void testBug251133() throws JavaModelException {
+ String source =
+ "public class X01 {\n" +
+ "// int a = 1;\n" +
+ "// int b = 2;\n" +
+ "}";
+ formatSource(source,
+ "public class X01 {\n" +
+ " // int a = 1;\n" +
+ " // int b = 2;\n" +
+ "}"
+ );
+}
+public void testBug251133a() throws JavaModelException {
+ this.formatterPrefs.comment_format_line_comment = true;
+ this.formatterPrefs.comment_format_line_comment_starting_on_first_column = true;
+ this.formatterPrefs.never_indent_line_comments_on_first_column = false;
+ String source =
+ "public class X {\n" +
+ "// first column comment \n" +
+ "}";
+ formatSource(source,
+ "public class X {\n" +
+ " // first column comment\n" +
+ "}"
+ );
+}
+public void testBug251133b() throws JavaModelException {
+ this.formatterPrefs.comment_format_line_comment = true;
+ this.formatterPrefs.comment_format_line_comment_starting_on_first_column = true;
+ this.formatterPrefs.never_indent_line_comments_on_first_column = true;
+ String source =
+ "public class X {\n" +
+ "// first column comment \n" +
+ "}";
+ formatSource(source,
+ "public class X {\n" +
+ "// first column comment\n" +
+ "}"
+ );
+}
+public void testBug251133c() throws JavaModelException {
+ this.formatterPrefs.comment_format_line_comment = true;
+ this.formatterPrefs.comment_format_line_comment_starting_on_first_column = false;
+ this.formatterPrefs.never_indent_line_comments_on_first_column = false;
+ String source =
+ "public class X {\n" +
+ "// first column comment \n" +
+ "}";
+ formatSource(source);
+}
+public void testBug251133d() throws JavaModelException {
+ this.formatterPrefs.comment_format_line_comment = true;
+ this.formatterPrefs.comment_format_line_comment_starting_on_first_column = false;
+ this.formatterPrefs.never_indent_line_comments_on_first_column = true;
+ String source =
+ "public class X {\n" +
+ "// first column comment \n" +
+ "}";
+ formatSource(source);
+}
+public void testBug251133e() throws JavaModelException {
+ this.formatterPrefs.comment_format_line_comment = false;
+ this.formatterPrefs.comment_format_line_comment_starting_on_first_column = true;
+ this.formatterPrefs.never_indent_line_comments_on_first_column = false;
+ String source =
+ "public class X {\n" +
+ "// first column comment \n" +
+ "}";
+ formatSource(source,
+ "public class X {\n" +
+ " // first column comment \n" +
+ "}"
+ );
+}
+public void testBug251133f() throws JavaModelException {
+ this.formatterPrefs.comment_format_line_comment = false;
+ this.formatterPrefs.comment_format_line_comment_starting_on_first_column = true;
+ this.formatterPrefs.never_indent_line_comments_on_first_column = true;
+ String source =
+ "public class X {\n" +
+ "// first column comment \n" +
+ "}";
+ formatSource(source,
+ "public class X {\n" +
+ "// first column comment \n" +
+ "}"
+ );
+}
+public void testBug251133g() throws JavaModelException {
+ this.formatterPrefs.comment_format_line_comment = false;
+ this.formatterPrefs.comment_format_line_comment_starting_on_first_column = false;
+ this.formatterPrefs.never_indent_line_comments_on_first_column = false;
+ String source =
+ "public class X {\n" +
+ "// first column comment \n" +
+ "}";
+ formatSource(source,
+ "public class X {\n" +
+ " // first column comment \n" +
+ "}"
+ );
+}
+public void testBug251133h() throws JavaModelException {
+ this.formatterPrefs.comment_format_line_comment = false;
+ this.formatterPrefs.comment_format_line_comment_starting_on_first_column = false;
+ this.formatterPrefs.never_indent_line_comments_on_first_column = true;
+ String source =
+ "public class X {\n" +
+ "// first column comment \n" +
+ "}";
+ formatSource(source);
+}
+
+/**
* @bug 256799: [formatter] Formatter wrongly adds space to //$FALL-THROUGH$
* @test Ensure that the comment formatter preserve $FALL-THROUGH$ tag leading spaces
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=256799"
@@ -4071,8 +4324,7 @@
"\n" +
" /**\n" +
" * Returns the change directly associated with this change element or <code\n" +
- " * null</code>\n" +
- " * if the element isn\'t associated with a change.\n" +
+ " * null</code> if the element isn\'t associated with a change.\n" +
" * \n" +
" * @return the change or <code>null</code>\n" +
" */\n" +
@@ -4398,6 +4650,837 @@
}
/**
+ * @bug 260381: [formatter] Javadoc formatter breaks {@code ...} tags.
+ * @test Ensure that the @code tag is similar to <code> HTML tag
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=260381"
+ */
+public void testBug260381() throws JavaModelException {
+ String source =
+ "/**\n" +
+ " * Comments that can be formated in several lines...\n" +
+ " * \n" +
+ " * @author Myself\n" +
+ " * @version {@code The text here should not be formatted.... }\n" +
+ " */\n" +
+ "public class X01 {\n" +
+ "}\n";
+ formatSource(source);
+}
+public void testBug260381a() throws JavaModelException {
+ String source =
+ "/**\n" +
+ " * Comments that can be formated in several lines...\n" +
+ " * \n" +
+ " * @author Myself\n" +
+ " * @version {@code " +
+ " * The text here should not be formatted.... }\n" +
+ " */\n" +
+ "public class X01a {\n" +
+ "}\n";
+ formatSource(source);
+}
+public void testBug260381b() throws JavaModelException {
+ String source =
+ "/**\n" +
+ " * Comments that can be formated in several lines...\n" +
+ " * \n" +
+ " * @author Myself\n" +
+ " * @version {@code\n" +
+ " * The text here should not be formatted.... }\n" +
+ " */\n" +
+ "public class X01b {\n" +
+ "}\n";
+ formatSource(source,
+ "/**\n" +
+ " * Comments that can be formated in several lines...\n" +
+ " * \n" +
+ " * @author Myself\n" +
+ " * @version {@code The text here should not be formatted.... }\n" +
+ " */\n" +
+ "public class X01b {\n" +
+ "}\n"
+ );
+}
+public void testBug260381c() throws JavaModelException {
+ String source =
+ "/**\n" +
+ " * Comments that can be formated in several lines...\n" +
+ " * \n" +
+ " * @author Myself\n" +
+ " * @version {@code \n" +
+ " * \n" +
+ " \n" +
+ " * The text here should not be formatted.... }\n" +
+ " */\n" +
+ "public class X01c {\n" +
+ "}\n";
+ formatSource(source,
+ "/**\n" +
+ " * Comments that can be formated in several lines...\n" +
+ " * \n" +
+ " * @author Myself\n" +
+ " * @version {@code \n" +
+ " * \n" +
+ " * \n" +
+ " * The text here should not be formatted.... }\n" +
+ " */\n" +
+ "public class X01c {\n" +
+ "}\n"
+ );
+}
+public void testBug260381d() throws JavaModelException {
+ String source =
+ "/**\n" +
+ " * Comments that can be formated in several lines...\n" +
+ " * \n" +
+ " * @author Myself\n" +
+ " * @version <code> The text here should not be formatted.... </code>\n" +
+ " */\n" +
+ "public class X02 {\n" +
+ "}\n";
+ formatSource(source);
+}
+public void testBug260381e() throws JavaModelException {
+ String source =
+ "/**\n" +
+ " * Comments that can be formated in several lines...\n" +
+ " * \n" +
+ " * @author Myself\n" +
+ " * @version\n" +
+ " * <code> The text here should not be formatted.... </code>\n" +
+ " */\n" +
+ "public class X02b {\n" +
+ "}\n";
+ formatSource(source,
+ "/**\n" +
+ " * Comments that can be formated in several lines...\n" +
+ " * \n" +
+ " * @author Myself\n" +
+ " * @version <code> The text here should not be formatted.... </code>\n" +
+ " */\n" +
+ "public class X02b {\n" +
+ "}\n"
+ );
+}
+public void testBug260381f() throws JavaModelException {
+ String source =
+ "/**\n" +
+ " * Comments that can be formated in several lines...\n" +
+ " * \n" +
+ " * @author Myself\n" +
+ " * @see Object <code> The text here should not be formatted.... </code>\n" +
+ " */\n" +
+ "public class X02c {\n" +
+ "}\n";
+ formatSource(source,
+ "/**\n" +
+ " * Comments that can be formated in several lines...\n" +
+ " * \n" +
+ " * @author Myself\n" +
+ " * @see Object\n" +
+ " * <code> The text here should not be formatted.... </code>\n" +
+ " */\n" +
+ "public class X02c {\n" +
+ "}\n"
+ );
+}
+public void testBug260381g() throws JavaModelException {
+ String source =
+ "/**\n" +
+ " * Comments that can be formated in several lines...\n" +
+ " * \n" +
+ " * {@code The text here should not be formatted.... }\n" +
+ " */\n" +
+ "public class X03 {\n" +
+ "}\n";
+ formatSource(source);
+}
+public void testBug260381h() throws JavaModelException {
+ String source =
+ "/**\n" +
+ " * Comments that can be formated in several lines...\n" +
+ " * \n" +
+ " * <code> The text here should \n" +
+ " * not be formatted.... </code>\n" +
+ " */\n" +
+ "public class X03b {\n" +
+ "}\n";
+ formatSource(source);
+}
+public void testBug260381i() throws JavaModelException {
+ String source =
+ "/**\n" +
+ " * Comments that can be formated in several lines...\n" +
+ " * \n" +
+ " * {@code The text here should\n" +
+ " * not be formatted.... }\n" +
+ " */\n" +
+ "public class X03c {\n" +
+ "}\n";
+ formatSource(source,
+ "/**\n" +
+ " * Comments that can be formated in several lines...\n" +
+ " * \n" +
+ " * {@code The text here should\n" +
+ " * not be formatted.... }\n" +
+ " */\n" +
+ "public class X03c {\n" +
+ "}\n"
+ );
+}
+public void testBug260381j() throws JavaModelException {
+ String source =
+ "/**\n" +
+ " * Comments that can be formated in several lines...\n" +
+ " * \n" +
+ " * {@code \n" +
+ " * The text here should\n" +
+ " * not \n" +
+ " * be formatted.... }\n" +
+ " */\n" +
+ "public class X03d {\n" +
+ "}\n";
+ formatSource(source,
+ "/**\n" +
+ " * Comments that can be formated in several lines...\n" +
+ " * \n" +
+ " * {@code \n" +
+ " * The text here should\n" +
+ " * not \n" +
+ " * be formatted.... }\n" +
+ " */\n" +
+ "public class X03d {\n" +
+ "}\n"
+ );
+}
+public void testBug260381k() throws JavaModelException {
+ String source =
+ "/**\n" +
+ " * Literal inline tag should also be untouched by the formatter\n" +
+ " * \n" +
+ " * @version {@literal The text here should not be formatted.... }\n" +
+ " */\n" +
+ "public class X04 {\n" +
+ "\n" +
+ "}\n";
+ formatSource(source);
+}
+public void testBug260381_wksp1_01() throws JavaModelException {
+ String source =
+ "package wksp1;\n" +
+ "\n" +
+ "public interface I01 {\n" +
+ "\n" +
+ " /**\n" +
+ " * Returns all configured content types for the given source viewer. This list\n" +
+ " * tells the caller which content types must be configured for the given source \n" +
+ " * viewer, i.e. for which content types the given source viewer\'s functionalities\n" +
+ " * must be specified. This implementation always returns <code>\n" +
+ " * new String[] { IDocument.DEFAULT_CONTENT_TYPE }</code>.\n" +
+ " *\n" +
+ " * @param source the source viewer to be configured by this configuration\n" +
+ " * @return the configured content types for the given viewer\n" +
+ " */\n" +
+ " public String[] getConfiguredContentTypes(String source);\n" +
+ "}\n";
+ formatSource(source,
+ "package wksp1;\n" +
+ "\n" +
+ "public interface I01 {\n" +
+ "\n" +
+ " /**\n" +
+ " * Returns all configured content types for the given source viewer. This\n" +
+ " * list tells the caller which content types must be configured for the\n" +
+ " * given source viewer, i.e. for which content types the given source\n" +
+ " * viewer\'s functionalities must be specified. This implementation always\n" +
+ " * returns <code>\n" +
+ " * new String[] { IDocument.DEFAULT_CONTENT_TYPE }</code>.\n" +
+ " * \n" +
+ " * @param source\n" +
+ " * the source viewer to be configured by this configuration\n" +
+ " * @return the configured content types for the given viewer\n" +
+ " */\n" +
+ " public String[] getConfiguredContentTypes(String source);\n" +
+ "}\n"
+ );
+}
+public void testBug260381_wksp2_01() throws JavaModelException {
+ String source =
+ "package wksp2;\n" +
+ "public interface I01 {\n" +
+ " /**\n" +
+ " * Returns the composition of two functions. For {@code f: A->B} and\n" +
+ " * {@code g: B->C}, composition is defined as the function h such that\n" +
+ " * {@code h(a) == g(f(a))} for each {@code a}.\n" +
+ " *\n" +
+ " * @see <a href=\"//en.wikipedia.org/wiki/Function_composition\">\n" +
+ " * function composition</a>\n" +
+ " *\n" +
+ " * @param g the second function to apply\n" +
+ " * @param f the first function to apply\n" +
+ " * @return the composition of {@code f} and {@code g}\n" +
+ " */\n" +
+ " void foo();\n" +
+ "}\n";
+ formatSource(source,
+ "package wksp2;\n" +
+ "\n" +
+ "public interface I01 {\n" +
+ " /**\n" +
+ " * Returns the composition of two functions. For {@code f: A->B} and\n" +
+ " * {@code g: B->C}, composition is defined as the function h such that\n" +
+ " * {@code h(a) == g(f(a))} for each {@code a}.\n" +
+ " * \n" +
+ " * @see <a href=\"//en.wikipedia.org/wiki/Function_composition\"> function\n" +
+ " * composition</a>\n" +
+ " * \n" +
+ " * @param g\n" +
+ " * the second function to apply\n" +
+ " * @param f\n" +
+ " * the first function to apply\n" +
+ " * @return the composition of {@code f} and {@code g}\n" +
+ " */\n" +
+ " void foo();\n" +
+ "}\n"
+ );
+}
+public void testBug260381_wksp2_01b() throws JavaModelException {
+ String source =
+ "package wksp2;\n" +
+ "public interface I01b {\n" +
+ " /**\n" +
+ " * Returns the composition of two functions. For <code> f: A->B</code> and\n" +
+ " * <code> g: B->C</code>, composition is defined as the function h such that\n" +
+ " * <code> h(a) == g(f(a))</code> for each <code> a</code>.\n" +
+ " *\n" +
+ " * @see <a href=\"//en.wikipedia.org/wiki/Function_composition\">\n" +
+ " * function composition</a>\n" +
+ " *\n" +
+ " * @param g the second function to apply\n" +
+ " * @param f the first function to apply\n" +
+ " * @return the composition of <code> f</code> and <code> g</code>\n" +
+ " */\n" +
+ " void foo();\n" +
+ "}\n";
+ formatSource(source,
+ "package wksp2;\n" +
+ "\n" +
+ "public interface I01b {\n" +
+ " /**\n" +
+ " * Returns the composition of two functions. For <code> f: A->B</code> and\n" +
+ " * <code> g: B->C</code>, composition is defined as the function h such that\n" +
+ " * <code> h(a) == g(f(a))</code> for each <code> a</code>.\n" +
+ " * \n" +
+ " * @see <a href=\"//en.wikipedia.org/wiki/Function_composition\"> function\n" +
+ " * composition</a>\n" +
+ " * \n" +
+ " * @param g\n" +
+ " * the second function to apply\n" +
+ " * @param f\n" +
+ " * the first function to apply\n" +
+ " * @return the composition of <code> f</code> and <code> g</code>\n" +
+ " */\n" +
+ " void foo();\n" +
+ "}\n"
+ );
+}
+public void testBug260381_wksp2_01c() throws JavaModelException {
+ String source =
+ "package wksp2;\n" +
+ "public interface I01c {\n" +
+ " /**\n" +
+ " * Returns the composition of two functions. For <code> f: A->B</code> and\n" +
+ " * <code>\n" +
+ " * g: B->C\n" +
+ " * </code>,\n" +
+ " * composition is defined as the function h such that\n" +
+ " * <code>\n" +
+ " * h(a) == g(f(a))\n" +
+ " * </code>\n" +
+ " * for each\n" +
+ " * <code>\n" +
+ " * a\n" +
+ " * </code>.\n" +
+ " *\n" +
+ " * @see <a href=\"//en.wikipedia.org/wiki/Function_composition\">\n" +
+ " * function composition</a>\n" +
+ " *\n" +
+ " * @param g the second function to apply\n" +
+ " * @param f the first function to apply\n" +
+ " * @return the composition of <code> f</code> and <code> g</code>\n" +
+ " */\n" +
+ " void foo();\n" +
+ "}\n";
+ formatSource(source,
+ "package wksp2;\n" +
+ "\n" +
+ "public interface I01c {\n" +
+ " /**\n" +
+ " * Returns the composition of two functions. For <code> f: A->B</code> and\n" +
+ " * <code>\n" +
+ " * g: B->C\n" +
+ " * </code>, composition is defined as the function h such that <code>\n" +
+ " * h(a) == g(f(a))\n" +
+ " * </code> for each <code>\n" +
+ " * a\n" +
+ " * </code>.\n" +
+ " * \n" +
+ " * @see <a href=\"//en.wikipedia.org/wiki/Function_composition\"> function\n" +
+ " * composition</a>\n" +
+ " * \n" +
+ " * @param g\n" +
+ " * the second function to apply\n" +
+ " * @param f\n" +
+ " * the first function to apply\n" +
+ " * @return the composition of <code> f</code> and <code> g</code>\n" +
+ " */\n" +
+ " void foo();\n" +
+ "}\n"
+ );
+}
+public void testBug260381_wksp2_02() throws JavaModelException {
+ String source =
+ "package wksp2;\n" +
+ "\n" +
+ "public interface I02 {\n" +
+ "\n" +
+ " /**\n" +
+ " * Implementations of {@code computeNext} <b>must</b> invoke this method when\n" +
+ " * there are no elements left in the iteration.\n" +
+ " *\n" +
+ " * @return {@code null}; a convenience so your {@link #computeNext}\n" +
+ " * implementation can use the simple statement {@code return endOfData();}\n" +
+ " */\n" +
+ " void foo();\n" +
+ "}\n";
+ formatSource(source,
+ "package wksp2;\n" +
+ "\n" +
+ "public interface I02 {\n" +
+ "\n" +
+ " /**\n" +
+ " * Implementations of {@code computeNext} <b>must</b> invoke this method\n" +
+ " * when there are no elements left in the iteration.\n" +
+ " * \n" +
+ " * @return {@code null}; a convenience so your {@link #computeNext}\n" +
+ " * implementation can use the simple statement\n" +
+ " * {@code return endOfData();}\n" +
+ " */\n" +
+ " void foo();\n" +
+ "}\n"
+ );
+}
+public void testBug260381_wksp2_03() throws JavaModelException {
+ String source =
+ "package wksp2;\n" +
+ "\n" +
+ "public interface I03 {\n" +
+ " /**\n" +
+ " * A builder for creating immutable bimap instances, especially {@code public\n" +
+ " * static final} bimaps (\"constant bimaps\"). Example: <pre> {@code\n" +
+ " *\n" +
+ " * static final ImmutableBiMap<String, Integer> WORD_TO_INT =\n" +
+ " * new ImmutableBiMap.Builder<String, Integer>()\n" +
+ " * .put(\"one\", 1)\n" +
+ " * .put(\"two\", 2)\n" +
+ " * .put(\"three\", 3)\n" +
+ " * .build();}</pre>\n" +
+ " *\n" +
+ " * For <i>small</i> immutable bimaps, the {@code ImmutableBiMap.of()} methods\n" +
+ " * are even more convenient.\n" +
+ " *\n" +
+ " * <p>Builder instances can be reused - it is safe to call {@link #build}\n" +
+ " * multiple times to build multiple bimaps in series. Each bimap is a superset\n" +
+ " * of the bimaps created before it.\n" +
+ " */\n" +
+ " void foo();\n" +
+ "}\n";
+ formatSource(source,
+ "package wksp2;\n" +
+ "\n" +
+ "public interface I03 {\n" +
+ " /**\n" +
+ " * A builder for creating immutable bimap instances, especially\n" +
+ " * {@code public\n" +
+ " * static final} bimaps (\"constant bimaps\"). Example:\n" +
+ " * \n" +
+ " * <pre>\n" +
+ " * {\n" +
+ " * @code\n" +
+ " * static final ImmutableBiMap<String, Integer> WORD_TO_INT = new ImmutableBiMap.Builder<String, Integer>()\n" +
+ " * .put("one", 1).put("two", 2).put("three", 3).build();\n" +
+ " * }\n" +
+ " * </pre>\n" +
+ " * \n" +
+ " * For <i>small</i> immutable bimaps, the {@code ImmutableBiMap.of()}\n" +
+ " * methods are even more convenient.\n" +
+ " * \n" +
+ " * <p>\n" +
+ " * Builder instances can be reused - it is safe to call {@link #build}\n" +
+ " * multiple times to build multiple bimaps in series. Each bimap is a\n" +
+ " * superset of the bimaps created before it.\n" +
+ " */\n" +
+ " void foo();\n" +
+ "}\n"
+ );
+}
+public void testBug260381_wksp2_03b() throws JavaModelException {
+ String source =
+ "package wksp2;\n" +
+ "\n" +
+ "public interface I03b {\n" +
+ " /**\n" +
+ " * A builder for creating immutable bimap instances, xxxxxxxx {@code public\n" +
+ " * static final} bimaps (\"constant bimaps\").\n" +
+ " */\n" +
+ " void foo();\n" +
+ "}\n";
+ formatSource(source,
+ "package wksp2;\n" +
+ "\n" +
+ "public interface I03b {\n" +
+ " /**\n" +
+ " * A builder for creating immutable bimap instances, xxxxxxxx {@code public\n" +
+ " * static final} bimaps (\"constant bimaps\").\n" +
+ " */\n" +
+ " void foo();\n" +
+ "}\n"
+ );
+}
+public void testBug260381_wksp2_04() throws JavaModelException {
+ String source =
+ "package wksp2;\n" +
+ "\n" +
+ "public interface I04 {\n" +
+ "\n" +
+ " /**\n" +
+ " * Returns an immutable multiset containing the given elements.\n" +
+ " * \n" +
+ " * <p>The multiset is ordered by the first occurrence of each element. For\n" +
+ " * example, {@code ImmutableMultiset.copyOf(Arrays.asList(2, 3, 1, 3))} yields\n" +
+ " * a multiset with elements in the order {@code 2, 3, 3, 1}.\n" +
+ " *\n" +
+ " * <p>Note that if {@code c} is a {@code Collection<String>}, then {@code\n" +
+ " * ImmutableMultiset.copyOf(c)} returns an {@code ImmutableMultiset<String>}\n" +
+ " * containing each of the strings in {@code c}, while\n" +
+ " * {@code ImmutableMultiset.of(c)} returns an\n" +
+ " * {@code ImmutableMultiset<Collection<String>>} containing one element\n" +
+ " * (the given collection itself).\n" +
+ " *\n" +
+ " * <p><b>Note:</b> Despite what the method name suggests, if {@code elements}\n" +
+ " * is an {@code ImmutableMultiset}, no copy will actually be performed, and\n" +
+ " * the given multiset itself will be returned.\n" +
+ " *\n" +
+ " * @throws NullPointerException if any of {@code elements} is null\n" +
+ " */\n" +
+ " void foo();\n" +
+ "}\n";
+ formatSource(source,
+ "package wksp2;\n" +
+ "\n" +
+ "public interface I04 {\n" +
+ "\n" +
+ " /**\n" +
+ " * Returns an immutable multiset containing the given elements.\n" +
+ " * \n" +
+ " * <p>\n" +
+ " * The multiset is ordered by the first occurrence of each element. For\n" +
+ " * example, {@code ImmutableMultiset.copyOf(Arrays.asList(2, 3, 1, 3))}\n" +
+ " * yields a multiset with elements in the order {@code 2, 3, 3, 1}.\n" +
+ " * \n" +
+ " * <p>\n" +
+ " * Note that if {@code c} is a {@code Collection<String>}, then\n" +
+ " * {@code ImmutableMultiset.copyOf(c)} returns an\n" +
+ " * {@code ImmutableMultiset<String>} containing each of the strings in\n" +
+ " * {@code c}, while {@code ImmutableMultiset.of(c)} returns an\n" +
+ " * {@code ImmutableMultiset<Collection<String>>} containing one element (the\n" +
+ " * given collection itself).\n" +
+ " * \n" +
+ " * <p>\n" +
+ " * <b>Note:</b> Despite what the method name suggests, if {@code elements}\n" +
+ " * is an {@code ImmutableMultiset}, no copy will actually be performed, and\n" +
+ " * the given multiset itself will be returned.\n" +
+ " * \n" +
+ " * @throws NullPointerException\n" +
+ " * if any of {@code elements} is null\n" +
+ " */\n" +
+ " void foo();\n" +
+ "}\n"
+ );
+}
+public void testBug260381_wksp2_05() throws JavaModelException {
+ String source =
+ "package wksp2;\n" +
+ "\n" +
+ "public interface I05 {\n" +
+ "\n" +
+ " /**\n" +
+ " * Indexes the specified values into a {@code Multimap} by applying a\n" +
+ " * specified function to each item in an {@code Iterable} of values. Each\n" +
+ " * value will be stored as a value in the specified multimap. The key used to\n" +
+ " * store that value in the multimap will be the result of calling the function\n" +
+ " * on that value. Depending on the multimap implementation, duplicate entries\n" +
+ " * (equal keys and equal values) may be collapsed.\n" +
+ " *\n" +
+ " * <p>For example,\n" +
+ " *\n" +
+ " * <pre class=\"code\">\n" +
+ " * List<String> badGuys =\n" +
+ " * Arrays.asList(\"Inky\", \"Blinky\", \"Pinky\", \"Pinky\", \"Clyde\");\n" +
+ " * Function<String, Integer> stringLengthFunction = ...;\n" +
+ " * Multimap<Integer, String> index = Multimaps.newHashMultimap();\n" +
+ " * Multimaps.index(badGuys, stringLengthFunction, index);\n" +
+ " * System.out.println(index); </pre>\n" +
+ " *\n" +
+ " * prints\n" +
+ " *\n" +
+ " * <pre class=\"code\">\n" +
+ " * {4=[Inky], 5=[Pinky, Clyde], 6=[Blinky]} </pre>\n" +
+ " *\n" +
+ " * The {@link HashMultimap} collapses the duplicate occurrence of\n" +
+ " * {@code (5, \"Pinky\")}.\n" +
+ " *\n" +
+ " * @param values the values to add to the multimap\n" +
+ " * @param keyFunction the function used to produce the key for each value\n" +
+ " * @param multimap the multimap to store the key value pairs\n" +
+ " */\n" +
+ " void foo();\n" +
+ "}\n";
+ formatSource(source,
+ "package wksp2;\n" +
+ "\n" +
+ "public interface I05 {\n" +
+ "\n" +
+ " /**\n" +
+ " * Indexes the specified values into a {@code Multimap} by applying a\n" +
+ " * specified function to each item in an {@code Iterable} of values. Each\n" +
+ " * value will be stored as a value in the specified multimap. The key used\n" +
+ " * to store that value in the multimap will be the result of calling the\n" +
+ " * function on that value. Depending on the multimap implementation,\n" +
+ " * duplicate entries (equal keys and equal values) may be collapsed.\n" +
+ " * \n" +
+ " * <p>\n" +
+ " * For example,\n" +
+ " * \n" +
+ " * <pre class=\"code\">\n" +
+ " * List<String> badGuys =\n" +
+ " * Arrays.asList(\"Inky\", \"Blinky\", \"Pinky\", \"Pinky\", \"Clyde\");\n" +
+ " * Function<String, Integer> stringLengthFunction = ...;\n" +
+ " * Multimap<Integer, String> index = Multimaps.newHashMultimap();\n" +
+ " * Multimaps.index(badGuys, stringLengthFunction, index);\n" +
+ " * System.out.println(index);\n" +
+ " * </pre>\n" +
+ " * \n" +
+ " * prints\n" +
+ " * \n" +
+ " * <pre class=\"code\">\n" +
+ " * {4=[Inky], 5=[Pinky, Clyde], 6=[Blinky]}\n" +
+ " * </pre>\n" +
+ " * \n" +
+ " * The {@link HashMultimap} collapses the duplicate occurrence of\n" +
+ " * {@code (5, \"Pinky\")}.\n" +
+ " * \n" +
+ " * @param values\n" +
+ " * the values to add to the multimap\n" +
+ " * @param keyFunction\n" +
+ " * the function used to produce the key for each value\n" +
+ " * @param multimap\n" +
+ " * the multimap to store the key value pairs\n" +
+ " */\n" +
+ " void foo();\n" +
+ "}\n"
+ );
+}
+public void testBug260381_wksp2_06() throws JavaModelException {
+ String source =
+ "package wksp2;\n" +
+ "\n" +
+ "public interface I06 {\n" +
+ "\n" +
+ " /**\n" +
+ " * Adds a number of occurrences of an element to this multiset. Note that if\n" +
+ " * {@code occurrences == 1}, this method has the identical effect to {@link\n" +
+ " * #add(Object)}. This method is functionally equivalent (except in the case\n" +
+ " * of overflow) to the call {@code addAll(Collections.nCopies(element,\n" +
+ " * occurrences))}, which would presumably perform much more poorly.\n" +
+ " *\n" +
+ " * @param element the element to add occurrences of; may be {@code null} only\n" +
+ " * if explicitly allowed by the implementation\n" +
+ " * @param occurrences the number of occurrences of this element to add. May\n" +
+ " * be zero, in which case no change will be made.\n" +
+ " * @return the previous count of this element before the operation; possibly\n" +
+ " * zero - TODO: make this the actual behavior!\n" +
+ " * @throws IllegalArgumentException if {@code occurrences} is negative, or if\n" +
+ " * this operation would result in more than {@link Integer#MAX_VALUE}\n" +
+ " * occurrences of the element \n" +
+ " * @throws NullPointerException if {@code element} is null and this\n" +
+ " * implementation does not permit null elements. Note that if {@code\n" +
+ " * occurrences} is zero, the implementation may opt to return normally.\n" +
+ " */\n" +
+ " boolean /*int*/ add(E element, int occurrences);\n" +
+ "}\n";
+ formatSource(source,
+ "package wksp2;\n" +
+ "\n" +
+ "public interface I06 {\n" +
+ "\n" +
+ " /**\n" +
+ " * Adds a number of occurrences of an element to this multiset. Note that if\n" +
+ " * {@code occurrences == 1}, this method has the identical effect to\n" +
+ " * {@link #add(Object)}. This method is functionally equivalent (except in\n" +
+ " * the case of overflow) to the call\n" +
+ " * {@code addAll(Collections.nCopies(element,\n" +
+ " * occurrences))}, which would presumably perform much more poorly.\n" +
+ " * \n" +
+ " * @param element\n" +
+ " * the element to add occurrences of; may be {@code null} only if\n" +
+ " * explicitly allowed by the implementation\n" +
+ " * @param occurrences\n" +
+ " * the number of occurrences of this element to add. May be zero,\n" +
+ " * in which case no change will be made.\n" +
+ " * @return the previous count of this element before the operation; possibly\n" +
+ " * zero - TODO: make this the actual behavior!\n" +
+ " * @throws IllegalArgumentException\n" +
+ " * if {@code occurrences} is negative, or if this operation\n" +
+ " * would result in more than {@link Integer#MAX_VALUE}\n" +
+ " * occurrences of the element\n" +
+ " * @throws NullPointerException\n" +
+ " * if {@code element} is null and this implementation does not\n" +
+ " * permit null elements. Note that if {@code occurrences} is\n" +
+ " * zero, the implementation may opt to return normally.\n" +
+ " */\n" +
+ " boolean /* int */add(E element, int occurrences);\n" +
+ "}\n"
+ );
+}
+public void testBug260381_wksp2_07() throws JavaModelException {
+ String source =
+ "package wksp2;\n" +
+ "\n" +
+ "public interface I07 {\n" +
+ "\n" +
+ " /**\n" +
+ " * Constructs a new, empty multiset, sorted according to the specified\n" +
+ " * comparator. All elements inserted into the multiset must be <i>mutually\n" +
+ " * comparable</i> by the specified comparator: {@code comparator.compare(e1,\n" +
+ " * e2)} must not throw a {@code ClassCastException} for any elements {@code\n" +
+ " * e1} and {@code e2} in the multiset. If the user attempts to add an element\n" +
+ " * to the multiset that violates this constraint, the {@code add(Object)} call\n" +
+ " * will throw a {@code ClassCastException}.\n" +
+ " *\n" +
+ " * @param comparator the comparator that will be used to sort this multiset. A\n" +
+ " * null value indicates that the elements\' <i>natural ordering</i> should\n" +
+ " * be used.\n" +
+ " */\n" +
+ " void foo();\n" +
+ "}\n";
+ formatSource(source,
+ "package wksp2;\n" +
+ "\n" +
+ "public interface I07 {\n" +
+ "\n" +
+ " /**\n" +
+ " * Constructs a new, empty multiset, sorted according to the specified\n" +
+ " * comparator. All elements inserted into the multiset must be <i>mutually\n" +
+ " * comparable</i> by the specified comparator: {@code comparator.compare(e1,\n" +
+ " * e2)} must not throw a {@code ClassCastException} for any elements\n" +
+ " * {@code e1} and {@code e2} in the multiset. If the user attempts to add an\n" +
+ " * element to the multiset that violates this constraint, the\n" +
+ " * {@code add(Object)} call will throw a {@code ClassCastException}.\n" +
+ " * \n" +
+ " * @param comparator\n" +
+ " * the comparator that will be used to sort this multiset. A null\n" +
+ " * value indicates that the elements\' <i>natural ordering</i>\n" +
+ " * should be used.\n" +
+ " */\n" +
+ " void foo();\n" +
+ "}\n"
+ );
+}
+public void testBug260381_wksp2_08() throws JavaModelException {
+ String source =
+ "package wksp2;\n" +
+ "\n" +
+ "public interface I08 {\n" +
+ "\n" +
+ " /**\n" +
+ " * Returns the composition of a function and a predicate. For every {@code x},\n" +
+ " * the generated predicate returns {@code predicate(function(x))}.\n" +
+ " *\n" +
+ " * @return the composition of the provided function and predicate\n" +
+ " */\n" +
+ " void foo();\n" +
+ "}\n";
+ formatSource(source,
+ "package wksp2;\n" +
+ "\n" +
+ "public interface I08 {\n" +
+ "\n" +
+ " /**\n" +
+ " * Returns the composition of a function and a predicate. For every\n" +
+ " * {@code x}, the generated predicate returns {@code predicate(function(x))}\n" +
+ " * .\n" +
+ " * \n" +
+ " * @return the composition of the provided function and predicate\n" +
+ " */\n" +
+ " void foo();\n" +
+ "}\n"
+ );
+}
+public void testBug260381_wksp2_09() throws JavaModelException {
+ String source =
+ "package wksp2;\n" +
+ "\n" +
+ "/**\n" +
+ " A Conditional represents an if/then/else block.\n" +
+ " When this is created the code will already have\n" +
+ " the conditional check code. The code is optimized for branch\n" +
+ " offsets that fit in 2 bytes, though will handle 4 byte offsets.\n" +
+ "<code>\n" +
+ " if condition\n" +
+ " then code\n" +
+ " else code\n" +
+ "</code>\n" +
+ " what actually gets built is\n" +
+ "<code>\n" +
+ " if !condition branch to eb:\n" +
+ " then code\n" +
+ " goto end: // skip else\n" +
+ " eb:\n" +
+ " else code\n" +
+ " end:\n" +
+ "</code>\n" +
+ "*/\n" +
+ "public class X09 {\n" +
+ "\n" +
+ "}\n";
+ formatSource(source,
+ "package wksp2;\n" +
+ "\n" +
+ "/**\n" +
+ " * A Conditional represents an if/then/else block. When this is created the code\n" +
+ " * will already have the conditional check code. The code is optimized for\n" +
+ " * branch offsets that fit in 2 bytes, though will handle 4 byte offsets. <code>\n" +
+ " if condition\n" +
+ " then code\n" +
+ " else code\n" +
+ "</code>\n" +
+ " * what actually gets built is <code>\n" +
+ " if !condition branch to eb:\n" +
+ " then code\n" +
+ " goto end: // skip else\n" +
+ " eb:\n" +
+ " else code\n" +
+ " end:\n" +
+ "</code>\n" +
+ " */\n" +
+ "public class X09 {\n" +
+ "\n" +
+ "}\n"
+ );
+}
+
+/**
* @bug 260798: [formatter] Strange behavior of never join lines
* @test Ensure that the formatter indents lines correctly when never join lines pref is activated
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=260798"
@@ -4594,6 +5677,133 @@
}
/**
+ * @bug 270209: [format] Condensed block comment formatting
+ * @test Verify that block and javadoc comments are formatted in condensed
+ * mode when the corresponding preferences is set
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=270209"
+ */
+public void testBug270209_Block01() throws JavaModelException {
+ this.formatterPrefs.comment_new_lines_at_block_boundaries = false;
+ String source =
+ "public interface X01 {\n" +
+ "\n" +
+ "/* Instead of like this. I use these a lot and\n" +
+ " * this can take up a lot of space. */\n" +
+ "void foo();\n" +
+ "}\n";
+ formatSource(source,
+ "public interface X01 {\n" +
+ "\n" +
+ " /* Instead of like this. I use these a lot and this can take up a lot of\n" +
+ " * space. */\n" +
+ " void foo();\n" +
+ "}\n"
+ );
+}
+public void testBug270209_Block02() throws JavaModelException {
+ this.formatterPrefs.comment_new_lines_at_block_boundaries = false;
+ String source =
+ "public interface X02 {\n" +
+ "\n" +
+ "/*\n" +
+ " * Instead of like this. I use these a lot and\n" +
+ " * this can take up a lot of space.\n" +
+ " */\n" +
+ "void foo();\n" +
+ "}\n";
+ formatSource(source,
+ "public interface X02 {\n" +
+ "\n" +
+ " /* Instead of like this. I use these a lot and this can take up a lot of\n" +
+ " * space. */\n" +
+ " void foo();\n" +
+ "}\n"
+ );
+}
+public void testBug270209_Block03() throws JavaModelException {
+ this.formatterPrefs.comment_new_lines_at_block_boundaries = false;
+ String source =
+ "public interface X03 {\n" +
+ "\n" +
+ "/*\n" +
+ " * \n" +
+ " * Instead of like this. I use these a lot and\n" +
+ " * this can take up a lot of space.\n" +
+ " * \n" +
+ " */\n" +
+ "void foo();\n" +
+ "}\n";
+ formatSource(source,
+ "public interface X03 {\n" +
+ "\n" +
+ " /* Instead of like this. I use these a lot and this can take up a lot of\n" +
+ " * space. */\n" +
+ " void foo();\n" +
+ "}\n"
+ );
+}
+public void testBug270209_Javadoc01() throws JavaModelException {
+ this.formatterPrefs.comment_new_lines_at_javadoc_boundaries = false;
+ String source =
+ "public interface X01 {\n" +
+ "\n" +
+ "/** Instead of like this. I use these a lot and\n" +
+ " * this can take up a lot of space. */\n" +
+ "void foo();\n" +
+ "}\n";
+ formatSource(source,
+ "public interface X01 {\n" +
+ "\n" +
+ " /** Instead of like this. I use these a lot and this can take up a lot of\n" +
+ " * space. */\n" +
+ " void foo();\n" +
+ "}\n"
+ );
+}
+public void testBug270209_Javadoc02() throws JavaModelException {
+ this.formatterPrefs.comment_new_lines_at_javadoc_boundaries = false;
+ String source =
+ "public interface X02 {\n" +
+ "\n" +
+ "/**\n" +
+ " * Instead of like this. I use these a lot and\n" +
+ " * this can take up a lot of space.\n" +
+ " */\n" +
+ "void foo();\n" +
+ "}\n";
+ formatSource(source,
+ "public interface X02 {\n" +
+ "\n" +
+ " /** Instead of like this. I use these a lot and this can take up a lot of\n" +
+ " * space. */\n" +
+ " void foo();\n" +
+ "}\n"
+ );
+}
+public void testBug270209_Javadoc03() throws JavaModelException {
+ this.formatterPrefs.comment_new_lines_at_javadoc_boundaries = false;
+ String source =
+ "public interface X03 {\n" +
+ "\n" +
+ "/**\n" +
+ " * \n" +
+ " * Instead of like this. I use these a lot and\n" +
+ " * this can take up a lot of space.\n" +
+ " * \n" +
+ " */\n" +
+ "void foo();\n" +
+ "}\n";
+ formatSource(source,
+ "public interface X03 {\n" +
+ "\n" +
+ " /** Instead of like this. I use these a lot and this can take up a lot of\n" +
+ " * space. */\n" +
+ " void foo();\n" +
+ "}\n"
+ );
+}
+
+/**
* @bug 273619: [formatter] Formatting repeats *} in javadoc
* @test Ensure that *} is not repeated while formatting
* @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=273619"
@@ -4934,4 +6144,99 @@
"}\n");
}
+/**
+ * @bug 300379: [formatter] Fup of bug 287833
+ * @test Verify that the leading '{' is not deleted while formatting
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=300379"
+ */
+public void testBug300379() {
+ String source =
+ "public class X {\n" +
+ " /**\n" +
+ " * <pre> {@code\n" +
+ " * \n" +
+ " * public class X {\n" +
+ " * }}</pre>\n" +
+ " */\n" +
+ " public void foo() {}\n" +
+ "}\n";
+
+ formatSource(source,
+ "public class X {\n" +
+ " /**\n" +
+ " * <pre>\n" +
+ " * {\n" +
+ " * @code\n" +
+ " * public class X {\n" +
+ " * }\n" +
+ " * }\n" +
+ " * </pre>\n" +
+ " */\n" +
+ " public void foo() {\n" +
+ " }\n" +
+ "}\n");
+}
+public void testBug300379b() {
+ String source =
+ "public class X {\n" +
+ " /**\n" +
+ " * <pre> {@code\n" +
+ " * \n" +
+ " * public class X {}}</pre>\n" +
+ " */\n" +
+ " public void foo() {}\n" +
+ "}\n";
+
+ formatSource(source,
+ "public class X {\n" +
+ " /**\n" +
+ " * <pre>\n" +
+ " * {\n" +
+ " * @code\n" +
+ " * public class X {\n" +
+ " * }\n" +
+ " * }\n" +
+ " * </pre>\n" +
+ " */\n" +
+ " public void foo() {\n" +
+ " }\n" +
+ "}\n");
+}
+
+/**
+ * @bug 304705: [formatter] Unexpected indentation of wrapped line comments when 'Never indent line comment on first column' preference is checked
+ * @test Verify that wrapped line comments are also put at first column
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=304705"
+ */
+public void testBug304705() {
+ this.formatterPrefs.never_indent_line_comments_on_first_column = true;
+ String source =
+ "public interface Example {\n" +
+ "// This is a long comment with whitespace that should be split in multiple line comments in case the line comment formatting is enabled\n" +
+ " int foo();\n" +
+ "}\n";
+ formatSource(source,
+ "public interface Example {\n" +
+ "// This is a long comment with whitespace that should be split in multiple line\n" +
+ "// comments in case the line comment formatting is enabled\n" +
+ " int foo();\n" +
+ "}\n");
+}
+public void testBug304705b() {
+ this.formatterPrefs.never_indent_block_comments_on_first_column = true;
+ String source =
+ "public interface Example {\n" +
+ "/* This is a long comment with whitespace that should be split in multiple line comments in case the line comment formatting is enabled */\n" +
+ " int foo();\n" +
+ "}\n";
+ formatSource(source,
+ "public interface Example {\n" +
+ "/*\n" +
+ " * This is a long comment with whitespace that should be split in multiple line\n" +
+ " * comments in case the line comment formatting is enabled\n" +
+ " */\n" +
+ " int foo();\n" +
+ "}\n");
+}
+
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsTests.java
index 38e8455..e58ca31 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterCommentsTests.java
@@ -258,7 +258,7 @@
this.workingCopies = new ICompilationUnit[1];
this.workingCopies[0] = getCompilationUnit(JAVA_PROJECT.getElementName() , "", "test."+packageName, unitName); //$NON-NLS-1$ //$NON-NLS-2$
String outputSource = getOutputSource(this.workingCopies[0]);
- formatSource(this.workingCopies[0].getSource(), outputSource, kind, indentationLevel, checkNull, offset, length, lineSeparator, true);
+ formatSource(this.workingCopies[0].getSource(), outputSource, kind, indentationLevel, offset, length, lineSeparator, true);
}
/**
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterMassiveRegressionTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterMassiveRegressionTests.java
index 486b650..90911f1 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterMassiveRegressionTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterMassiveRegressionTests.java
@@ -206,7 +206,7 @@
private final int testIndex;
// Cleaning
- private static int MAX_FILES, MAX_DIGITS;
+ private final static Map MAX_FILES = new HashMap();
// Formatting behavior
final static int FORMAT_REPEAT = Integer.parseInt(System.getProperty("repeat", "2"));
@@ -361,7 +361,7 @@
int profiles = initProfiles(profile);
// Init directories
- initDirectories(inputDir, profiles);
+ initDirectories(inputDir, profiles, true);
// Get files from input dir
FileFilter filter = new FileFilter() {
@@ -398,8 +398,10 @@
directories.put(inputDir, allFiles);
System.out.println("done");
}
- MAX_FILES = allFiles.length;
- MAX_DIGITS = (int) (Math.log(MAX_FILES)/Math.log(10));
+ int[] maxFiles = new int[2];
+ maxFiles[0] = allFiles.length;
+ maxFiles[1] = (int) (Math.log(maxFiles[0])/Math.log(10));
+ MAX_FILES.put(inputDir, maxFiles);
// Add tests to clean the output directory and rebuild the references
// if (CLEAN) {
@@ -407,7 +409,7 @@
// }
// Add one test per found file
- for (int i=0; i<MAX_FILES; i++) {
+ for (int i=0; i<maxFiles[0]; i++) {
if (CLEAN) {
suite.addTest(new FormatterMassiveRegressionTests(inputDir, allFiles[i], i, profiles, false/*do not compare while cleaning*/));
} else {
@@ -513,7 +515,7 @@
return profiles;
}
-private static void initDirectories(File inputDir, int profiles) {
+private static void initDirectories(File inputDir, int profiles, boolean verify) {
// Verify input directory
if (!inputDir.exists() && !inputDir.isDirectory()) {
@@ -557,7 +559,7 @@
// Get log dir
try {
- setLogDir(inputDir, profiles);
+ setLogDir(inputDir, profiles, verify);
} catch (CoreException e) {
e.printStackTrace();
}
@@ -573,7 +575,7 @@
}
}
-private static void setLogDir(File inputDir, int profiles) throws CoreException {
+private static void setLogDir(File inputDir, int profiles, boolean verify) throws CoreException {
// Compute log dir
File logDir = new File(System.getProperty("logDir"));
@@ -612,7 +614,7 @@
String filePrefix = inputDir.getName().replaceAll("\\.", "");
String logFileName = filePrefix+".txt";
LOG_FILE = new File(logDir, logFileName);
- if (LOG_FILE.exists()) {
+ if (verify && LOG_FILE.exists()) {
File saveDir = new File(logDir, "save");
saveDir.mkdir();
int i=0;
@@ -729,6 +731,9 @@
buffer.append(lines);
first = false;
}
+ if (first) {
+ buffer.append("none!");
+ }
}
private static void setOutputDir(File inputDir, String dir, int profiles) {
@@ -883,7 +888,8 @@
StringBuffer name = new StringBuffer(super.getName());
if (this.testIndex >= 0) {
int n = this.testIndex == 0 ? 0 : (int) (Math.log(this.testIndex)/Math.log(10));
- for (int i=n; i<MAX_DIGITS; i++) {
+ int max = ((int[])MAX_FILES.get(this.inputDir))[1];
+ for (int i=n; i<max; i++) {
name.append('0');
}
name.append(this.testIndex);
@@ -902,35 +908,70 @@
*/
public void setUp() throws Exception {
super.setUp();
+
+ // Setup preferences
this.preferences = DefaultCodeFormatterOptions.getEclipseDefaultSettings();
- if (NO_COMMENTS) {
+
+ // Setup no comments profile
+ if ((this.profiles & PROFILE_NO_COMMENTS) != 0) {
this.preferences.comment_format_javadoc_comment = false;
this.preferences.comment_format_block_comment = false;
this.preferences.comment_format_line_comment = false;
}
- if (JOIN_LINES != null) {
- if (!JOIN_LINES.equals("only_comments")) {
+
+ // Setup join lines profile
+ String joinLines = null;
+ switch (this.profiles & PROFILE_JOIN_LINES_MASK) {
+ case PROFILE_NEVER_JOIN_LINES:
+ joinLines = "never";
+ break;
+ case PROFILE_JOIN_LINES_ONLY_COMMENTS:
+ joinLines = "only_comments";
+ break;
+ case PROFILE_JOIN_LINES_ONLY_CODE:
+ joinLines = "only_code";
+ break;
+ }
+ if (joinLines != null) {
+ if (!joinLines.equals("only_comments")) {
this.preferences.join_lines_in_comments = false;
}
- if (!JOIN_LINES.equals("only_code")) {
+ if (!joinLines.equals("only_code")) {
this.preferences.join_wrapped_lines = false;
}
}
- if (BRACES != null) {
- this.preferences.brace_position_for_annotation_type_declaration = BRACES;
- this.preferences.brace_position_for_anonymous_type_declaration = BRACES;
- this.preferences.brace_position_for_array_initializer = BRACES;
- this.preferences.brace_position_for_block = BRACES;
- this.preferences.brace_position_for_block_in_case = BRACES;
- this.preferences.brace_position_for_constructor_declaration = BRACES;
- this.preferences.brace_position_for_enum_constant = BRACES;
- this.preferences.brace_position_for_enum_declaration = BRACES;
- this.preferences.brace_position_for_method_declaration = BRACES;
- this.preferences.brace_position_for_switch = BRACES;
- this.preferences.brace_position_for_type_declaration = BRACES;
+
+ // Setup braces profile
+ String braces = null;
+ switch (this.profiles & PROFILE_BRACES_MASK) {
+ case PROFILE_BRACES_NEXT_LINE:
+ braces = DefaultCodeFormatterConstants.NEXT_LINE;
+ break;
+ case PROFILE_BRACES_NEXT_LINE_ON_WRAP:
+ braces = DefaultCodeFormatterConstants.NEXT_LINE_ON_WRAP;
+ break;
+ case PROFILE_BRACES_NEXT_LINE_SHIFTED:
+ braces = DefaultCodeFormatterConstants.NEXT_LINE_SHIFTED;
+ break;
}
- if (PRESERVED_LINES != -1) {
- this.preferences.number_of_empty_lines_to_preserve = PRESERVED_LINES;
+ if (braces != null) {
+ this.preferences.brace_position_for_annotation_type_declaration = braces;
+ this.preferences.brace_position_for_anonymous_type_declaration = braces;
+ this.preferences.brace_position_for_array_initializer = braces;
+ this.preferences.brace_position_for_block = braces;
+ this.preferences.brace_position_for_block_in_case = braces;
+ this.preferences.brace_position_for_constructor_declaration = braces;
+ this.preferences.brace_position_for_enum_constant = braces;
+ this.preferences.brace_position_for_enum_declaration = braces;
+ this.preferences.brace_position_for_method_declaration = braces;
+ this.preferences.brace_position_for_switch = braces;
+ this.preferences.brace_position_for_type_declaration = braces;
+ }
+
+ // Setup preserved lines profile
+ if ((this.profiles & PROFILE_PRESERVED_LINES_MASK) != 0) {
+ int lines = (this.profiles & PROFILE_PRESERVED_LINES_MASK) >> 5;
+ this.preferences.number_of_empty_lines_to_preserve = lines;
}
}
@@ -940,7 +981,7 @@
public void setUpSuite() throws Exception {
// Init directories
- initDirectories(this.inputDir, this.profiles);
+ initDirectories(this.inputDir, this.profiles, false);
// Delete output dir before compute reference
if (CLEAN) {
@@ -1000,6 +1041,13 @@
// Input dir
buffer.append("Input dir : ");
buffer.append(this.inputDir);
+ buffer.append(LINE_SEPARATOR);
+
+ // Files
+ buffer.append(" ");
+ int[] maxFiles = (int[]) MAX_FILES.get(this.inputDir);
+ buffer.append(maxFiles[0]);
+ buffer.append(" java files to format...");
// Flush to console to show startup
String firstBuffer = buffer.toString();
@@ -1048,11 +1096,6 @@
} else {
buffer.append("Compare vs: none");
}
-
- // Files
- buffer.append(" ");
- buffer.append(MAX_FILES);
- buffer.append(" java files found");
buffer.append(LINE_SEPARATOR);
// Write logs
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java
index 814ebad..26601f6 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/FormatterRegressionTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation 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
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Brock Janiczak - Contribution for bug 150741
*******************************************************************************/
package org.eclipse.jdt.core.tests.formatter;
@@ -40,6 +41,7 @@
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.jdt.internal.formatter.align.Alignment;
import org.eclipse.jface.text.IRegion;
import org.eclipse.jface.text.Region;
import org.eclipse.text.edits.TextEdit;
@@ -218,6 +220,11 @@
assertSourceEquals("Different number of length", Util.convertToIndependantLineDelimiter(expectedContents), actualContents);
}
+ void assertLineEquals(String actualContents, String originalSource, String expectedContents) {
+ String outputSource = expectedContents == null ? originalSource : expectedContents;
+ assertLineEquals(actualContents, originalSource, outputSource, false /* do not check null */);
+ }
+
DefaultCodeFormatter codeFormatter() {
if (this.formatterOptions == null) {
this.formatterOptions = JAVA_PROJECT.getOptions(true);
@@ -225,11 +232,6 @@
DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(this.formatterPrefs, this.formatterOptions);
return codeFormatter;
}
-
- void assertLineEquals(String actualContents, String originalSource, String expectedContents) {
- String outputSource = expectedContents == null ? originalSource : expectedContents;
- assertLineEquals(actualContents, originalSource, outputSource, false /* do not check null */);
- }
void formatSource(String source) {
// expect unchanged source after formatting
@@ -239,6 +241,10 @@
void formatSource(String source, String formattedOutput) {
formatSource(source, formattedOutput, CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS, 0, true /*repeat formatting twice*/);
}
+
+ void formatSource(String source, String formattedOutput, int kind) {
+ formatSource(source, formattedOutput, kind, 0, true /*repeat formatting twice*/);
+ }
void formatSource(String source, String formattedOutput, boolean repeat) {
formatSource(source, formattedOutput, CodeFormatter.K_COMPILATION_UNIT | CodeFormatter.F_INCLUDE_COMMENTS, 0, repeat);
@@ -273,11 +279,11 @@
}
assertLineEquals(result, newSource, formattedOutput);
} else {
- formatSource(source, formattedOutput, kind, indentationLevel, false, 0, -1, null, repeat);
+ formatSource(source, formattedOutput, kind, indentationLevel, 0, -1, null, repeat);
}
}
- void formatSource(String source, String formattedOutput, int kind, int indentationLevel, boolean checkNull, int offset, int length, String lineSeparator, boolean repeat) {
+ void formatSource(String source, String formattedOutput, int kind, int indentationLevel, int offset, int length, String lineSeparator, boolean repeat) {
DefaultCodeFormatter codeFormatter = codeFormatter();
String result;
if (length == -1) {
@@ -285,7 +291,14 @@
} else {
result = runFormatter(codeFormatter, source, kind, indentationLevel, offset, length, lineSeparator, repeat);
}
- assertLineEquals(result, source, formattedOutput);
+ if (lineSeparator == null) {
+ assertLineEquals(result, source, formattedOutput);
+ } else {
+ // Do not convert line delimiter while comparing result when a specific one is specified
+ assertNotNull("Error(s) occured while formatting", result);
+ String outputSource = formattedOutput == null ? source : formattedOutput;
+ assertSourceEquals("Different number of length", outputSource, result, false/*do not convert line delimiter*/);
+ }
}
@@ -7310,6 +7323,30 @@
JavaCore.setOptions(javaCoreOptions);
}
}
+ public void test527b() {
+ Map options = DefaultCodeFormatterConstants.getJavaConventionsSettings();
+ DefaultCodeFormatterOptions preferences = new DefaultCodeFormatterOptions(options);
+ preferences.tab_char = DefaultCodeFormatterOptions.TAB;
+ preferences.tab_size = 4;
+ preferences.alignment_for_arguments_in_annotation = Alignment.M_COMPACT_SPLIT;
+ Hashtable javaCoreOptions = JavaCore.getOptions();
+ try {
+ Hashtable newJavaCoreOptions = JavaCore.getOptions();
+ newJavaCoreOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
+ newJavaCoreOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
+ newJavaCoreOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
+ JavaCore.setOptions(newJavaCoreOptions);
+
+ Map compilerOptions = new HashMap();
+ compilerOptions.put(CompilerOptions.OPTION_Compliance, CompilerOptions.VERSION_1_5);
+ compilerOptions.put(CompilerOptions.OPTION_TargetPlatform, CompilerOptions.VERSION_1_5);
+ compilerOptions.put(CompilerOptions.OPTION_Source, CompilerOptions.VERSION_1_5);
+ DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences, compilerOptions);
+ runTest(codeFormatter, "test527b", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$
+ } finally {
+ JavaCore.setOptions(javaCoreOptions);
+ }
+ }
/**
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=79779
@@ -8737,9 +8774,9 @@
"/**\r\n" +
" * Mensagens SMTP tem o seguinte formato:\r\n" +
" * <pre>\r\n" +
- " * resposta de uma linha só:\r\n" +
+ " * resposta de uma linha s�:\r\n" +
" * nnn [SP] lalalal [CR] [LF]\r\n" +
- " * resposta de várias linhas:\r\n" +
+ " * resposta de v�rias linhas:\r\n" +
" * nnn [-] lalalalal [CR] [LF]\r\n" +
" * nnn [-] lalalalal [CR] [LF]\r\n" +
" * ...\r\n" +
@@ -8751,9 +8788,9 @@
" * Mensagens SMTP tem o seguinte formato:\n" +
" * \n" +
" * <pre>\n" +
- " * resposta de uma linha só:\n" +
+ " * resposta de uma linha s�:\n" +
" * nnn [SP] lalalal [CR] [LF]\n" +
- " * resposta de várias linhas:\n" +
+ " * resposta de v�rias linhas:\n" +
" * nnn [-] lalalalal [CR] [LF]\n" +
" * nnn [-] lalalalal [CR] [LF]\n" +
" * ...\n" +
@@ -10622,4 +10659,27 @@
DefaultCodeFormatter codeFormatter = new DefaultCodeFormatter(preferences, compilerOptions);
runTest(codeFormatter, "test723", "A.java", CodeFormatter.K_COMPILATION_UNIT, false);//$NON-NLS-1$ //$NON-NLS-2$
}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=150741
+public void test724() {
+ this.formatterPrefs.insert_new_line_after_label = true;
+ String source =
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " LABEL:for (int i = 0; i < 10; i++) {\n" +
+ " }\n" +
+ " }\n" +
+ "\n" +
+ "}\n" +
+ "";
+ formatSource(source,
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " LABEL:\n" +
+ " for (int i = 0; i < 10; i++) {\n" +
+ " }\n" +
+ " }\n" +
+ "\n" +
+ "}\n"
+ );
+}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/RunFormatterMassiveTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/RunFormatterMassiveTests.java
index f763e0b..3c3c77a 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/RunFormatterMassiveTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/RunFormatterMassiveTests.java
@@ -29,7 +29,7 @@
private final static File INPUT_DIR = new File(System.getProperty("inputDir"));
private final static String PROFILE = System.getProperty("profiles");
private final static String[] SUPPORTED_WORKSPACES = {
- "full-src-3.0",
+ "full-src-30",
"galileo",
"JDKs",
};
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/comment/CommentTestCase.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/comment/CommentTestCase.java
index c55fecf..199ebad 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/comment/CommentTestCase.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/comment/CommentTestCase.java
@@ -24,6 +24,7 @@
import org.eclipse.jdt.core.tests.model.SuiteOfTestCases;
public abstract class CommentTestCase extends SuiteOfTestCases {
+
public static Test buildTestSuite(Class evaluationTestClass) {
return buildTestSuite(evaluationTestClass, null); //$NON-NLS-1$
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/comment/JavaDocTestCase.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/comment/JavaDocTestCase.java
index ba564ca..da589d7 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/comment/JavaDocTestCase.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/comment/JavaDocTestCase.java
@@ -19,23 +19,14 @@
import org.eclipse.jdt.core.formatter.CodeFormatter;
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
-import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter;
-import org.eclipse.jdt.internal.formatter.comment.JavaDocLine;
-import org.eclipse.jdt.internal.formatter.comment.MultiCommentLine;
import org.eclipse.text.edits.TextEdit;
-public class JavaDocTestCase extends CommentTestCase {
+public class JavaDocTestCase extends MultiLineTestCase {
static {
// TESTS_NAMES = new String[] { "test109636_2" } ;
}
- protected static final String INFIX= MultiCommentLine.MULTI_COMMENT_CONTENT_PREFIX;
-
- protected static final String POSTFIX= MultiCommentLine.MULTI_COMMENT_END_PREFIX;
-
- protected static final String PREFIX= JavaDocLine.JAVADOC_START_PREFIX;
-
public static Test suite() {
return buildTestSuite(JavaDocTestCase.class);
}
@@ -698,7 +689,7 @@
String expected = "/**" + DELIMITER +
" * <pre>" + DELIMITER +
- (DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT ? " * " + DELIMITER : "") +
+ " * " + DELIMITER +
" * </pre>" + DELIMITER +
" * " + DELIMITER +
" * " + DELIMITER +
@@ -876,23 +867,8 @@
" * </code>" + DELIMITER +
" */";
- String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
- ? input // do not change as <code> is an immutable tag
- : "/**" + DELIMITER +
- " * <code>" + DELIMITER +
- " * <pre>" + DELIMITER +
- " * setLeadingComment("/* traditional comment */"); // correct" + DELIMITER +
- " * setLeadingComment("missing comment delimiters"); // wrong" + DELIMITER +
- " * setLeadingComment("/* unterminated traditional comment "); // wrong" + DELIMITER +
- " * setLeadingComment("/* broken\\n traditional comment */"); // correct" + DELIMITER +
- " * setLeadingComment("// end-of-line comment\\n"); // correct" + DELIMITER +
- " * setLeadingComment("// end-of-line comment without line terminator"); // correct" + DELIMITER +
- " * setLeadingComment("// broken\\n end-of-line comment\\n"); // wrong" + DELIMITER +
- " * </pre>" + DELIMITER +
- " * </code>" + DELIMITER +
- " */";
String result=testFormat(input, options);
- assertEquals(expected, result);
+ assertEquals(input, result);
}
public void test109636_2() {
@@ -940,37 +916,35 @@
}
public void test109636_4() {
- if (DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT) {
- Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
+ Map options = DefaultCodeFormatterConstants.getEclipseDefaultSettings();
- String input =
- "/**" + DELIMITER +
- " * <pre>" + DELIMITER +
- " * setLeadingComment(\"/* traditional comment */\"); // correct" + DELIMITER +
- " * setLeadingComment(\"missing comment delimiters\"); // wrong" + DELIMITER +
- " * setLeadingComment(\"/* unterminated traditional comment \"); // wrong" + DELIMITER +
- " * setLeadingComment(\"/* broken\\n traditional comment */\"); // correct" + DELIMITER +
- " * setLeadingComment(\"// end-of-line comment\\n\"); // correct" + DELIMITER +
- " * setLeadingComment(\"// end-of-line comment without line terminator\"); // correct" + DELIMITER +
- " * setLeadingComment(\"// broken\\n end-of-line comment\\n\"); // wrong" + DELIMITER +
- " * </pre>" + DELIMITER +
- " */";
+ String input =
+ "/**" + DELIMITER +
+ " * <pre>" + DELIMITER +
+ " * setLeadingComment(\"/* traditional comment */\"); // correct" + DELIMITER +
+ " * setLeadingComment(\"missing comment delimiters\"); // wrong" + DELIMITER +
+ " * setLeadingComment(\"/* unterminated traditional comment \"); // wrong" + DELIMITER +
+ " * setLeadingComment(\"/* broken\\n traditional comment */\"); // correct" + DELIMITER +
+ " * setLeadingComment(\"// end-of-line comment\\n\"); // correct" + DELIMITER +
+ " * setLeadingComment(\"// end-of-line comment without line terminator\"); // correct" + DELIMITER +
+ " * setLeadingComment(\"// broken\\n end-of-line comment\\n\"); // wrong" + DELIMITER +
+ " * </pre>" + DELIMITER +
+ " */";
- String expected =
- "/**" + DELIMITER +
- " * <pre>" + DELIMITER +
- " * setLeadingComment("/* traditional comment */"); // correct" + DELIMITER +
- " * setLeadingComment("missing comment delimiters"); // wrong" + DELIMITER +
- " * setLeadingComment("/* unterminated traditional comment "); // wrong" + DELIMITER +
- " * setLeadingComment("/* broken\\n traditional comment */"); // correct" + DELIMITER +
- " * setLeadingComment("// end-of-line comment\\n"); // correct" + DELIMITER +
- " * setLeadingComment("// end-of-line comment without line terminator"); // correct" + DELIMITER +
- " * setLeadingComment("// broken\\n end-of-line comment\\n"); // wrong" + DELIMITER +
- " * </pre>" + DELIMITER +
- " */";
- String result=testFormat(input, options);
- assertEquals(expected, result);
- }
+ String expected =
+ "/**" + DELIMITER +
+ " * <pre>" + DELIMITER +
+ " * setLeadingComment("/* traditional comment */"); // correct" + DELIMITER +
+ " * setLeadingComment("missing comment delimiters"); // wrong" + DELIMITER +
+ " * setLeadingComment("/* unterminated traditional comment "); // wrong" + DELIMITER +
+ " * setLeadingComment("/* broken\\n traditional comment */"); // correct" + DELIMITER +
+ " * setLeadingComment("// end-of-line comment\\n"); // correct" + DELIMITER +
+ " * setLeadingComment("// end-of-line comment without line terminator"); // correct" + DELIMITER +
+ " * setLeadingComment("// broken\\n end-of-line comment\\n"); // wrong" + DELIMITER +
+ " * </pre>" + DELIMITER +
+ " */";
+ String result=testFormat(input, options);
+ assertEquals(expected, result);
}
/**
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/comment/MultiLineTestCase.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/comment/MultiLineTestCase.java
index 76d6e05..2d436d3 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/comment/MultiLineTestCase.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/comment/MultiLineTestCase.java
@@ -17,18 +17,14 @@
import junit.framework.Test;
-import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter;
-import org.eclipse.jdt.internal.formatter.comment.MultiCommentLine;
-
public class MultiLineTestCase extends CommentTestCase {
static {
// TESTS_NAMES = new String[] { "test170580" } ;
}
- protected static final String INFIX= MultiCommentLine.MULTI_COMMENT_CONTENT_PREFIX;
- protected static final String POSTFIX= MultiCommentLine.MULTI_COMMENT_END_PREFIX;
-
- protected static final String PREFIX= MultiCommentLine.MULTI_COMMENT_START_PREFIX;
+ protected static final String INFIX= " * "; //$NON-NLS-1$
+ protected static final String POSTFIX= " */"; //$NON-NLS-1$
+ protected static final String PREFIX= "/* "; //$NON-NLS-1$
public static Test suite() {
return buildTestSuite(MultiLineTestCase.class);
@@ -116,13 +112,9 @@
" * Member comment\n" +//$NON-NLS-1$
" */";//$NON-NLS-1$
String result= testFormat(input, 0, input.length(), CodeFormatter.K_MULTI_LINE_COMMENT , 2);
- String expectedOutput = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
- ? "/**\n" +
- " * Member comment\n" +
- " */"
- : "/***********************************************************************\n" +
- " * Member comment\n" +
- " */";
+ String expectedOutput = "/**\n" +
+ " * Member comment\n" +
+ " */";
assertEquals("Different output", expectedOutput, result);
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/comment/SingleLineTestCase.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/comment/SingleLineTestCase.java
index 32ce3f8..463c7e2 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/comment/SingleLineTestCase.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/formatter/comment/SingleLineTestCase.java
@@ -16,11 +16,9 @@
import org.eclipse.jdt.core.formatter.CodeFormatter;
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
-import org.eclipse.jdt.internal.formatter.DefaultCodeFormatter;
-import org.eclipse.jdt.internal.formatter.comment.SingleCommentLine;
-
public class SingleLineTestCase extends CommentTestCase {
- protected static final String PREFIX= SingleCommentLine.SINGLE_COMMENT_PREFIX;
+
+ protected static final String PREFIX= "// "; //$NON-NLS-1$
static {
// TESTS_NAMES = new String[] { "test109581" } ;
@@ -42,9 +40,7 @@
setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "5"); //$NON-NLS-1$
setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_BLOCK_COMMENT, DefaultCodeFormatterConstants.FALSE);
setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT, DefaultCodeFormatterConstants.FALSE);
- String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
- ? PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + "//"+ DELIMITER + PREFIX + "test"
- : PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER;
+ String expected = PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + "//"+ DELIMITER + PREFIX + "test";
assertEquals(expected, testFormat("//test\ttest" + DELIMITER + "//" + DELIMITER + "//\t\ttest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
}
@@ -52,9 +48,7 @@
setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "5"); //$NON-NLS-1$
setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_BLOCK_COMMENT, DefaultCodeFormatterConstants.FALSE);
setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT, DefaultCodeFormatterConstants.FALSE);
- String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
- ? PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + DELIMITER + PREFIX + "test"
- : PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER;
+ String expected = PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + "//" + DELIMITER + PREFIX + "test";
assertEquals(expected, testFormat("//test\t\ttest" + DELIMITER + PREFIX + DELIMITER + "//\t\ttest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
}
@@ -62,23 +56,17 @@
setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "5"); //$NON-NLS-1$
setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_BLOCK_COMMENT, DefaultCodeFormatterConstants.FALSE);
setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_CLEAR_BLANK_LINES_IN_JAVADOC_COMMENT, DefaultCodeFormatterConstants.FALSE);
- String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
- ? PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + "//"+ DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test"
- : PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER;
+ String expected = PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + "//"+ DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test";
assertEquals(expected, testFormat("//test\ttest" + DELIMITER + "//" + DELIMITER + PREFIX + "test\ttest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$
}
public void testCommentBegin1() {
- String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
- ? PREFIX + "test"
- : PREFIX + "test" + DELIMITER;
+ String expected = PREFIX + "test";
assertEquals(expected, testFormat("//test")); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testCommentBegin2() {
- String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
- ? PREFIX + "test"
- : PREFIX + "test" + DELIMITER;
+ String expected = PREFIX + "test";
assertEquals(expected, testFormat(PREFIX + "test")); //$NON-NLS-1$ //$NON-NLS-2$
}
@@ -87,14 +75,12 @@
}
public void testCommentDelimiter1() {
- String expected = PREFIX + "test" + DELIMITER;
- if (DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT) expected += DELIMITER;
+ String expected = PREFIX + "test" + DELIMITER + DELIMITER;
assertEquals(expected, testFormat("//\t\ttest " + DELIMITER + DELIMITER)); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testCommentDelimiter2() {
- String expected = PREFIX + "test" + DELIMITER;
- if (DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT) expected += DELIMITER ;
+ String expected = PREFIX + "test" + DELIMITER + DELIMITER ;
assertEquals(expected, testFormat(PREFIX + "test " + DELIMITER + DELIMITER + DELIMITER)); //$NON-NLS-1$ //$NON-NLS-2$
}
@@ -123,47 +109,35 @@
}
public void testCommentSpace1() {
- String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
- ? PREFIX + "test test"
- : PREFIX + "test test" + DELIMITER;
+ String expected = PREFIX + "test test";
assertEquals(expected, testFormat("//test\t \t test")); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testCommentSpace2() {
- String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
- ? PREFIX + "test test"
- : PREFIX + "test test" + DELIMITER;
+ String expected = PREFIX + "test test";
assertEquals(expected, testFormat("//test test")); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testCommentSpace3() {
- String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
- ? PREFIX + "test test"
- : PREFIX + "test test" + DELIMITER;
+ String expected = PREFIX + "test test";
assertEquals(expected, testFormat(PREFIX + "test \t \t test")); //$NON-NLS-1$ //$NON-NLS-2$
}
public void testCommentWrapping1() {
setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "5"); //$NON-NLS-1$
- String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
- ? PREFIX + "test" + DELIMITER + PREFIX + "test"
- : PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER;
+ String expected = PREFIX + "test" + DELIMITER + PREFIX + "test";
assertEquals(expected, testFormat("//test\ttest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
public void testCommentWrapping2() {
setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "1"); //$NON-NLS-1$
- String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
- ? PREFIX + "test" + DELIMITER + PREFIX + "test"
- : PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER;
+ String expected = PREFIX + "test" + DELIMITER + PREFIX + "test";
assertEquals(expected, testFormat("//test\ttest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
public void testCommentWrapping3() {
setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "32"); //$NON-NLS-1$
- String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
- ? PREFIX + "test test"
- : PREFIX + "test test" + DELIMITER;
+ String expected = PREFIX + "test test";
assertEquals(expected, testFormat("//test\ttest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
@@ -186,58 +160,48 @@
public void testHeaderComment1() {
setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_HEADER, DefaultCodeFormatterConstants.FALSE);
setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "12"); //$NON-NLS-1$
- String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
- ? PREFIX + "test test" + DELIMITER + PREFIX + "test test" + DELIMITER + PREFIX + "test test"
- : PREFIX + "test test" + DELIMITER + PREFIX + "test test" + DELIMITER + PREFIX + "test test" + DELIMITER;
+ String expected = PREFIX + "test test" + DELIMITER + PREFIX + "test test" + DELIMITER + PREFIX + "test test";
assertEquals(expected, testFormat("//test\t\t\t\ttest" + DELIMITER + PREFIX + "test test test test")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
}
public void testHeaderComment2() {
setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_FORMAT_HEADER, DefaultCodeFormatterConstants.FALSE);
setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "24"); //$NON-NLS-1$
- String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
- ? "// test" + DELIMITER + PREFIX + "test test test test" + DELIMITER
- : PREFIX + "test test test test" + DELIMITER + PREFIX + "test" + DELIMITER;
+ String expected = "// test" + DELIMITER + PREFIX + "test test test test" + DELIMITER;
assertEquals(expected, testFormat("//test\t\t\t" + DELIMITER + PREFIX + "test test test test" + DELIMITER)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
public void testIllegalLineLength1() {
setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "1"); //$NON-NLS-1$
- String expected =PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER;
- if (DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT) expected = expected.substring(0, expected.length()-DELIMITER.length());
+ String expected = PREFIX + "test" + DELIMITER + PREFIX + "test";
assertEquals(expected, testFormat("//test\ttest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
public void testIllegalLineLength2() {
setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "-16"); //$NON-NLS-1$
- String expected = PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER;
- if (DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT) expected = expected.substring(0, expected.length()-DELIMITER.length());
+ String expected = PREFIX + "test" + DELIMITER + PREFIX + "test";
assertEquals(expected, testFormat(PREFIX + "\t\t test\ttest")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
public void testMultipleComments1() {
setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "5"); //$NON-NLS-1$
- String expected = PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER;
- if (DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT) expected = expected.substring(0, expected.length()-DELIMITER.length());
+ String expected = PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test";
assertEquals(expected, testFormat("//test test" + DELIMITER + PREFIX + "test test test test")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$
}
public void testMultipleComments2() {
setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "12"); //$NON-NLS-1$
- String expected = DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT
- ? "// test test" + DELIMITER +
+ String expected = "// test test" + DELIMITER +
"// test" + DELIMITER +
- "// " + DELIMITER +
+ "//" + DELIMITER +
"// test test" + DELIMITER +
- "// test test"
- : PREFIX + "test test" + DELIMITER + PREFIX + "test test" + DELIMITER + PREFIX + "test test" + DELIMITER + PREFIX + "test" + DELIMITER;
+ "// test test";
assertEquals(expected, testFormat("//test test\ttest" + DELIMITER + PREFIX + DELIMITER + PREFIX + "test test test test")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
}
public void testMultipleComments3() {
setUserOption(DefaultCodeFormatterConstants.FORMATTER_COMMENT_LINE_LENGTH, "11"); //$NON-NLS-1$
- String expected = PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER;
- if (DefaultCodeFormatter.ENABLE_NEW_COMMENTS_FORMAT) expected = expected.substring(0, expected.length()-DELIMITER.length());
+ String expected = PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test" + DELIMITER + PREFIX + "test";
assertEquals(expected, testFormat("// test\t\t\ttest\ttest" + DELIMITER + PREFIX + "test test test test")); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$ //$NON-NLS-7$ //$NON-NLS-8$ //$NON-NLS-9$
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java
index 4ae8bab..1238664 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AbstractJavaModelTests.java
@@ -725,11 +725,21 @@
* The line separators in 'actual' are converted to '\n' before the comparison.
*/
protected void assertSourceEquals(String message, String expected, String actual) {
+ assertSourceEquals(message, expected, actual, true/*convert line delimiter*/);
+ }
+ /*
+ * Asserts that the given actual source is equal to the expected one.
+ * Note that if the line separators in 'actual' are converted to '\n' before the comparison,
+ * 'expected' is assumed to have the same '\n' line separator.
+ */
+ protected void assertSourceEquals(String message, String expected, String actual, boolean convert) {
if (actual == null) {
assertEquals(message, expected, null);
return;
}
- actual = org.eclipse.jdt.core.tests.util.Util.convertToIndependantLineDelimiter(actual);
+ if (convert) {
+ actual = org.eclipse.jdt.core.tests.util.Util.convertToIndependantLineDelimiter(actual);
+ }
if (!actual.equals(expected)) {
System.out.println("Expected source in "+getName()+" should be:");
System.out.print(org.eclipse.jdt.core.tests.util.Util.displayString(actual.toString(), 2));
@@ -2818,13 +2828,23 @@
return result;
}
protected void touch(File f) {
- int time = 1000;
+ final int time = 1000;
long lastModified = f.lastModified();
f.setLastModified(lastModified + time);
org.eclipse.jdt.core.tests.util.Util.waitAtLeast(time);
- // Assertion to track the reason of unexpected failures with tests on external resources
+ // Loop until the last modified time has really changed on the file
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=295619
- assertEquals("The file "+f.getAbsolutePath()+" was not touched!", lastModified+time, f.lastModified());
+ int n = 1;
+ while (n < 10) { // retry 9 times more if necessary
+ if (f.lastModified() != lastModified) {
+ // We can leave the loop as the file has been really touched
+ return;
+ }
+ f.setLastModified(lastModified + n*time);
+ org.eclipse.jdt.core.tests.util.Util.waitAtLeast(time);
+ n++;
+ }
+ assertFalse("The file "+f.getAbsolutePath()+" was not touched!", lastModified == f.lastModified());
}
protected String toString(String[] strings) {
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java
index 2d51faf..0fa79d8 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AllJavaModelTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation 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
@@ -180,6 +180,9 @@
// Creation of imports
CreateImportsTests.class,
+
+ // Util tests
+ UtilTests.class,
};
Class[] deprecatedClasses = getDeprecatedJDOMTestClasses();
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java
index cedc883..dd50eb1 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/AttachedJavadocTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation 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
@@ -547,4 +547,37 @@
String javadoc = field.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
assertNull("Should have no javadoc", javadoc); //$NON-NLS-1$
}
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=304316
+ public void test025() throws JavaModelException {
+ IClasspathEntry[] savedEntries = null;
+ try {
+ IClasspathEntry[] entries = this.project.getRawClasspath();
+ savedEntries = (IClasspathEntry[]) entries.clone();
+ final String path = "http:/java.sun.com/javaee/5/docs/api/"; //$NON-NLS-1$
+ IClasspathAttribute attribute = JavaCore.newClasspathAttribute(IClasspathAttribute.JAVADOC_LOCATION_ATTRIBUTE_NAME, path);
+ for (int i = 0, max = entries.length; i < max; i++) {
+ final IClasspathEntry entry = entries[i];
+ if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
+ && entry.getContentKind() == IPackageFragmentRoot.K_BINARY
+ && "/AttachedJavadocProject/lib/test6.jar".equals(entry.getPath().toString())) { //$NON-NLS-1$
+ entries[i] = JavaCore.newLibraryEntry(entry.getPath(), entry.getSourceAttachmentPath(), entry.getSourceAttachmentRootPath(), entry.getAccessRules(), new IClasspathAttribute[] { attribute }, entry.isExported());
+ }
+ }
+ this.project.setRawClasspath(entries, null);
+ IPackageFragment packageFragment = this.root.getPackageFragment("p1.p2"); //$NON-NLS-1$
+ assertNotNull("Should not be null", packageFragment); //$NON-NLS-1$
+ IClassFile classFile = packageFragment.getClassFile("X.class"); //$NON-NLS-1$
+ assertNotNull(classFile);
+ IType type = classFile.getType();
+ IField field = type.getField("f"); //$NON-NLS-1$
+ assertNotNull(field);
+ String javadoc = field.getAttachedJavadoc(new NullProgressMonitor()); //$NON-NLS-1$
+ assertNull("Should not have a javadoc", javadoc); //$NON-NLS-1$
+ } finally {
+ // restore classpath
+ if (savedEntries != null) {
+ this.project.setRawClasspath(savedEntries, null);
+ }
+ }
+ }
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClassFileTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClassFileTests.java
index a495d1f..f2afc82 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClassFileTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClassFileTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation 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
@@ -60,7 +60,7 @@
" <U extends Exception> X<T> foo(X<T> x) throws RuntimeException, U {\n" +
" return null;\n" +
" }\n" +
- " <K, V> V foo(K key, V value) throws Exception {\n" +
+ " <K, V extends T> V foo(K key, V value) throws Exception {\n" +
" return value;\n" +
" }\n" +
"}",
@@ -1094,7 +1094,7 @@
assertStringsEqual(
"Unexpected type parameters",
"K:Ljava.lang.Object;\n" +
- "V:Ljava.lang.Object;\n",
+ "V:TT;\n",
method.getTypeParameterSignatures());
}
@@ -1523,4 +1523,25 @@
"Ljava.util.Collection<Ljava.lang.String;>;",
field.getTypeSignature());
}
+
+ public void testBug246594() throws JavaModelException {
+ IType type = this.jarRoot.getPackageFragment("generic").getClassFile(
+ "Z.class").getType();
+ ITypeParameter typeParam = type.getTypeParameter("T");
+ assertNotNull(typeParam);
+ assertStringsEqual("Type parameter bounds signatures",
+ "Ljava.lang.Object;\n" +
+ "Lgeneric.I<-TT;>;\n",
+ typeParam.getBoundsSignatures());
+ }
+
+ public void testBug246594a() throws JavaModelException {
+ IType type = this.jarRoot.getPackageFragment("generic").getClassFile(
+ "X.class").getType();
+ IMethod method = type.getMethod("foo", new String[] { "TK;", "TV;" });
+ ITypeParameter typeParam = method.getTypeParameter("V");
+ assertStringsEqual("Type parameter bounds signatures",
+ "TT;\n", typeParam.getBoundsSignatures());
+ }
+
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClassNameTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClassNameTests.java
index d0c31c0..30f9e46 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClassNameTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClassNameTests.java
@@ -16,6 +16,8 @@
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.jdt.core.IClasspathEntry;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaProject;
@@ -1244,4 +1246,47 @@
deleteProject("P");
}
}
+
+/**
+ * @bug 302455: java.lang.ClassCastException in secondary types removal
+ * @test Ensure that no invalid entries are put in the secondary types caches
+ * when a file extension spec is removed from the workspace as the CCE
+ * does no longer occur...
+ * Also verify that secondary types from the removed file extension are not
+ * kept in the projects caches as the secondary type is no longer in the
+ * cache at the end of the test...
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=302455"
+ */
+public void testBug302455() throws CoreException, InterruptedException {
+ IContentType javaContentType = Platform.getContentTypeManager().getContentType(JavaCore.JAVA_SOURCE_CONTENT_TYPE);
+ try {
+ // Create project and file
+ assertNotNull("We should have got a Java Source content type!", javaContentType);
+ javaContentType.addFileSpec("b302455", IContentType.FILE_EXTENSION_SPEC);
+ IJavaProject javaProject = createJavaProject("P");
+ createFolder("/P/p");
+ String filePath = "/P/p/Bug.b302455";
+ createFile(
+ filePath,
+ "package p;\n" +
+ "public class Bug {}\n" +
+ "class Secondary {}\n" +
+ ""
+ );
+ waitUntilIndexesReady();
+
+ // Get the secondary type
+ IType type = javaProject.findType("p.Secondary", new NullProgressMonitor());
+ assertNotNull("We should have found the secondary type!", type);
+
+ // Remove file extension
+ javaContentType.removeFileSpec("b302455", IContentType.FILE_EXTENSION_SPEC);
+
+ // As there's no specific event fo
+ type = javaProject.findType("p.Secondary", new NullProgressMonitor());
+ assertNull("We should have not found the secondary type!", type);
+ } finally {
+ deleteProject("P");
+ }
+}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java
index 971310e..67e351f 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ClasspathTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation 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
@@ -5971,5 +5971,613 @@
this.deleteProject("P");
}
}
+/**
+ * @bug 300136:classpathentry OPTIONAL attribute not honored for var entries
+ *
+ * Test that classpath entries (CPE_LIB, CPE_CONTAINER and CPE_VARIABLE) that are marked as optional
+ * in the .classpath file are not reported for errors.
+ *
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=300136"
+ */
+public void testBug300136() throws Exception {
+ boolean autoBuild = getWorkspace().isAutoBuilding();
+ IWorkspaceDescription preferences = getWorkspace().getDescription();
+ try {
+ preferences.setAutoBuilding(false);
+ IJavaProject project = createJavaProject("P");
+ JavaCore.setClasspathVariables(
+ new String[] {"INVALID_LIB",},
+ new IPath[] {new Path("/lib/tmp.jar")},
+ null);
+
+ StringBuffer buffer = new StringBuffer(
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<classpath>\n" +
+ " <classpathentry kind=\"var\" path=\"INVALID_LIB\">\n" +
+ " <attributes>\n" +
+ " <attribute name=\"optional\" value=\"true\"/>" +
+ " </attributes>\n" +
+ " </classpathentry>\n" +
+ " <classpathentry kind=\"var\" path=\"UNBOUND_VAR\">\n" +
+ " <attributes>\n" +
+ " <attribute name=\"optional\" value=\"true\"/>" +
+ " </attributes>\n" +
+ " </classpathentry>\n" +
+ " <classpathentry kind=\"con\" path=\"org.eclipse.jdt.core.tests.model.TEST_CONTAINER\">\n" +
+ " <attributes>\n" +
+ " <attribute name=\"optional\" value=\"true\"/>" +
+ " </attributes>\n" +
+ " </classpathentry>\n" +
+ " <classpathentry kind=\"output\" path=\"bin\"/>\n" +
+ "</classpath>"
+ );
+ editFile(
+ "/P/.classpath",
+ buffer.toString()
+ );
+ assertMarkers(
+ "Unexpected markers",
+ "",
+ project);
+ } finally {
+ preferences.setAutoBuilding(autoBuild);
+ deleteProject("P");
+ JavaCore.removeClasspathVariable("INVALID_LIB", null);
+ }
+}
+/**
+ * Additional test for bug 300136 - Test that the errors are reported when the
+ * optional attribute is not used.
+ *
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=300136"
+ */
+public void testBug300136a() throws Exception {
+ boolean autoBuild = getWorkspace().isAutoBuilding();
+ IWorkspaceDescription preferences = getWorkspace().getDescription();
+ try {
+ preferences.setAutoBuilding(false);
+ IJavaProject project = createJavaProject("P");
+ IPath libPath = new Path("/lib/tmp.jar");
+ JavaCore.setClasspathVariables(
+ new String[] {"INVALID_LIB",},
+ new IPath[] {libPath},
+ null);
+
+ StringBuffer buffer = new StringBuffer(
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<classpath>\n" +
+ " <classpathentry kind=\"var\" path=\"INVALID_LIB\" />\n" +
+ " <classpathentry kind=\"var\" path=\"UNBOUND_VAR\" />\n" +
+ " <classpathentry kind=\"con\" path=\"org.eclipse.jdt.core.tests.model.TEST_CONTAINER\">\n" +
+ " </classpathentry>\n" +
+ " <classpathentry kind=\"output\" path=\"bin\"/>\n" +
+ "</classpath>"
+ );
+ editFile(
+ "/P/.classpath",
+ buffer.toString()
+ );
+ assertMarkers(
+ "Unexpected markers",
+ "Project \'P\' is missing required library: \'" + libPath.toOSString() + "'\n" +
+ "Unbound classpath container: \'org.eclipse.jdt.core.tests.model.TEST_CONTAINER\' in project \'P\'\n" +
+ "Unbound classpath variable: \'UNBOUND_VAR\' in project \'P\'",
+ project);
+ } finally {
+ preferences.setAutoBuilding(autoBuild);
+ deleteProject("P");
+ JavaCore.removeClasspathVariable("INVALID_LIB", null);
+ }
+}
+/**
+ * @bug 294360:Duplicate entries in Classpath Resolution when importing dependencies from parent project
+ * Test that duplicate entries are not added to the resolved classpath
+ *
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=294360"
+ * @throws Exception
+ */
+public void testBug294360a() throws Exception {
+ try {
+ IJavaProject p = createJavaProject("P");
+ addExternalLibrary(p, getExternalResourcePath("lib.jar"), new String[0],
+ new String[] {
+ "META-INF/MANIFEST.MF",
+ "Manifest-Version: 1.0\n",
+ },
+ JavaCore.VERSION_1_4);
+ IClasspathEntry[] classpath = new IClasspathEntry[2];
+ classpath[0] = JavaCore.newLibraryEntry(new Path(getExternalResourcePath("lib.jar")), null, null);
+ ContainerInitializer.setInitializer(new DefaultContainerInitializer(new String[] {"P", getExternalResourcePath("lib.jar")}));
+ classpath[1] = JavaCore.newContainerEntry(new Path("org.eclipse.jdt.core.tests.model.TEST_CONTAINER"));
+ setClasspath(p, classpath);
+
+ StringBuffer buffer = new StringBuffer(
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<classpath>\n" +
+ " <classpathentry kind=\"con\" path=\"org.eclipse.jdt.core.tests.model.TEST_CONTAINER\"/>\n" +
+ " <classpathentry kind=\"lib\" path=\""+ getExternalResourcePath("lib.jar") + "\">\n" +
+ " <attributes>\n" +
+ " <attribute name=\"optional\" value=\"true\"/>\n" +
+ " </attributes>\n" +
+ " </classpathentry>\n" +
+ " <classpathentry kind=\"output\" path=\"\"/>\n" +
+ "</classpath>\n");
+
+ editFile(
+ "/P/.classpath",
+ buffer.toString()
+ );
+
+ IClasspathEntry[] resolvedClasspath = p.getResolvedClasspath(true);
+ assertClasspathEquals(resolvedClasspath,
+ ""+ getExternalPath() + "lib.jar[CPE_LIBRARY][K_BINARY][isExported:false]");
+ } finally {
+ deleteProject("P");
+ deleteExternalResource("lib.jar");
+ }
+}
+/**
+ * @bug 252431:New API is needed to better identify referenced jars in the Class-Path: entry
+ * Test that 1) referenced libraries are added to the resolved classpath in the right order
+ * 2) referenced libraries are added to the appropriate referencing library in the correct order
+ * 3) referenced libraries and top-level libraries retain the source attachment and source attachment root path
+ * 4) referenced libraries point to the correct entry as their referencingEntry.
+ * 5) referenced libraries and their attributes are persisted in the .classpath file
+ *
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=252431"
+ * @throws Exception
+ */
+public void testBug252341a() throws Exception {
+ try {
+ IJavaProject p = createJavaProject("P");
+ addLibrary(p, "lib1.jar", "abc.zip", new String[0],
+ new String[] {
+ "META-INF/MANIFEST.MF",
+ "Manifest-Version: 1.0\n" +
+ "Class-Path: lib2.jar lib3.jar\n",
+ },
+ JavaCore.VERSION_1_4);
+ createFile("/P/lib2.jar", "");
+ createFile("/P/lib3.jar", "");
+
+ // Test referenced entries are included in the right order in the resolved classpath
+ IClasspathEntry[] resolvedClasspath = p.getResolvedClasspath(true);
+ assertClasspathEquals(resolvedClasspath,
+ "/P[CPE_SOURCE][K_SOURCE][isExported:false]\n" +
+ ""+ getExternalJCLPathString() + "[CPE_LIBRARY][K_BINARY][isExported:false]\n" +
+ "/P/lib2.jar[CPE_LIBRARY][K_BINARY][isExported:true]\n" +
+ "/P/lib3.jar[CPE_LIBRARY][K_BINARY][isExported:true]\n" +
+ "/P/lib1.jar[CPE_LIBRARY][K_BINARY][sourcePath:/P/abc.zip][isExported:true]");
+
+ IClasspathEntry[] rawClasspath = p.getRawClasspath();
+ assertClasspathEquals(rawClasspath,
+ "/P[CPE_SOURCE][K_SOURCE][isExported:false]\n" +
+ "JCL_LIB[CPE_VARIABLE][K_SOURCE][isExported:false]\n" +
+ "/P/lib1.jar[CPE_LIBRARY][K_BINARY][sourcePath:/P/abc.zip][isExported:true]");
+
+ // Test referenced entries for a particular entry appear in the right order and the referencingEntry
+ // attribute has the correct value
+ IClasspathEntry[] chains = JavaCore.getReferencedClasspathEntries(rawClasspath[2], p);
+ assertClasspathEquals(chains,
+ "/P/lib2.jar[CPE_LIBRARY][K_BINARY][isExported:true]\n" +
+ "/P/lib3.jar[CPE_LIBRARY][K_BINARY][isExported:true]");
+
+ assertSame("Referencing Entry", rawClasspath[2], chains[0].getReferencingEntry());
+ assertSame("Referencing Entry", rawClasspath[2], chains[1].getReferencingEntry());
+
+ // Test a newly created library entry with similar attributes but without any referencing entry is equal to
+ // the original referenced entry
+ IClasspathEntry tempLibEntry = JavaCore.newLibraryEntry(chains[0].getPath(), chains[0].getSourceAttachmentPath(), chains[0].getSourceAttachmentRootPath(), true);
+ assertEquals("Library Entry", tempLibEntry, chains[0]);
+
+ // Test the source attachment and other attributes added to the referenced entries are stored and retrieved properly
+ assertEquals("source attachment", resolvedClasspath[4].getSourceAttachmentPath().toPortableString(), "/P/abc.zip");
+ assertNull("source attachment", chains[0].getSourceAttachmentPath());
+ assertNull("source attachment", chains[1].getSourceAttachmentPath());
+ assertNull("source attachment root", chains[0].getSourceAttachmentRootPath());
+ assertNull("source attachment root", chains[1].getSourceAttachmentRootPath());
+
+ ((ClasspathEntry)chains[0]).sourceAttachmentPath = new Path("/P/efg.zip");
+ ((ClasspathEntry)chains[1]).sourceAttachmentPath = new Path("/P/xyz.zip");
+ ((ClasspathEntry)chains[0]).sourceAttachmentRootPath = new Path("/src2");
+ ((ClasspathEntry)chains[1]).sourceAttachmentRootPath = new Path("/src3");
+
+ IClasspathAttribute javadocLoc = JavaCore.newClasspathAttribute("javadoc_location", "/P/efg.zip");
+ ((ClasspathEntry)chains[0]).extraAttributes = new IClasspathAttribute[]{javadocLoc};
+
+ p.setRawClasspath(rawClasspath, chains, p.getOutputLocation(), null);
+
+ // Test the .classpath file contains all the referenced entries and their attributes
+ String contents = new String (org.eclipse.jdt.internal.core.util.Util.getResourceContentsAsCharArray(getFile("/P/.classpath")));
+ assertSourceEquals(
+ "Unexpected content",
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
+ "<classpath>\n" +
+ " <classpathentry kind=\"src\" path=\"\"/>\n" +
+ " <classpathentry kind=\"var\" path=\"JCL_LIB\"/>\n" +
+ " <classpathentry exported=\"true\" kind=\"lib\" path=\"lib1.jar\" sourcepath=\"abc.zip\"/>\n" +
+ " <classpathentry kind=\"output\" path=\"\"/>\n" +
+ " <referencedentry exported=\"true\" kind=\"lib\" path=\"lib2.jar\" rootpath=\"/src2\" sourcepath=\"efg.zip\">\n" +
+ " <attributes>\n" +
+ " <attribute name=\"javadoc_location\" value=\"/P/efg.zip\"/>\n" +
+ " </attributes>\n" +
+ " </referencedentry>\n" +
+ " <referencedentry exported=\"true\" kind=\"lib\" path=\"lib3.jar\" rootpath=\"/src3\" sourcepath=\"xyz.zip\"/>\n" +
+ "</classpath>\n",
+ contents);
+
+ p.close();
+ p.open(null);
+ rawClasspath = p.getRawClasspath();
+ resolvedClasspath = p.getResolvedClasspath(true);
+
+ assertClasspathEquals(rawClasspath,
+ "/P[CPE_SOURCE][K_SOURCE][isExported:false]\n" +
+ "JCL_LIB[CPE_VARIABLE][K_SOURCE][isExported:false]\n" +
+ "/P/lib1.jar[CPE_LIBRARY][K_BINARY][sourcePath:/P/abc.zip][isExported:true]");
+
+ assertClasspathEquals(resolvedClasspath,
+ "/P[CPE_SOURCE][K_SOURCE][isExported:false]\n" +
+ ""+ getExternalJCLPathString() + "[CPE_LIBRARY][K_BINARY][isExported:false]\n" +
+ "/P/lib2.jar[CPE_LIBRARY][K_BINARY][sourcePath:/P/efg.zip][rootPath:/src2][isExported:true][attributes:javadoc_location=/P/efg.zip]\n" +
+ "/P/lib3.jar[CPE_LIBRARY][K_BINARY][sourcePath:/P/xyz.zip][rootPath:/src3][isExported:true]\n" +
+ "/P/lib1.jar[CPE_LIBRARY][K_BINARY][sourcePath:/P/abc.zip][isExported:true]");
+
+ } finally {
+ deleteProject("P");
+ }
+}
+/**
+ * Additional tests for bug 252431.
+ * When multiple libraries have one or more common referenced library in their MANIFEST
+ * 1) The common referenced libries are added to the first library entry in the raw classpath
+ * 2) Removing one of the top-level library from the raw classpath doesn't remove the referenced
+ * entry that was commonly referenced by another entry and the referenced entry's source
+ * attachment and other attributes are retained.
+ * 3) Passing a NULL referencedEntries array retains the referenced entries
+ * 4) Passing an empty array as referencedEntries clears the earlier referenced entries
+ *
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=252431"
+ * @throws Exception
+ */
+public void testBug252341b() throws Exception {
+ try {
+ IJavaProject p = createJavaProject("P");
+ addLibrary(p, "lib1.jar", null, new String[0],
+ new String[] {
+ "META-INF/MANIFEST.MF",
+ "Manifest-Version: 1.0\n" +
+ "Class-Path: lib3.jar lib4.jar\n",
+ },
+ JavaCore.VERSION_1_4);
+
+ addLibrary(p, "lib2.jar", null, new String[0],
+ new String[] {
+ "META-INF/MANIFEST.MF",
+ "Manifest-Version: 1.0\n" +
+ "Class-Path: lib3.jar lib5.jar\n",
+ },
+ JavaCore.VERSION_1_4);
+ createFile("/P/lib3.jar", "");
+ createFile("/P/lib4.jar", "");
+ createFile("/P/lib5.jar", "");
+
+ // Test that the referenced entries are not included in the raw classpath
+ IClasspathEntry[] rawClasspath = p.getRawClasspath();
+ assertClasspathEquals(
+ rawClasspath,
+ "/P[CPE_SOURCE][K_SOURCE][isExported:false]\n" +
+ "JCL_LIB[CPE_VARIABLE][K_SOURCE][isExported:false]\n" +
+ "/P/lib1.jar[CPE_LIBRARY][K_BINARY][isExported:true]\n" +
+ "/P/lib2.jar[CPE_LIBRARY][K_BINARY][isExported:true]");
+
+ IClasspathEntry[] rawEntries = new IClasspathEntry[2];
+ rawEntries[0] = JavaCore.newLibraryEntry(new Path("/P/lib1.jar"), null, null, true);
+ rawEntries[1] = JavaCore.newLibraryEntry(new Path("/P/lib2.jar"), null, null, true);
+
+ // Test that the referenced entries are included in the raw classpath and in the right order
+ IClasspathEntry[] resolvedClasspath = p.getResolvedClasspath(true);
+ assertClasspathEquals(resolvedClasspath,
+ "/P[CPE_SOURCE][K_SOURCE][isExported:false]\n" +
+ ""+ getExternalJCLPathString() + "[CPE_LIBRARY][K_BINARY][isExported:false]\n" +
+ "/P/lib3.jar[CPE_LIBRARY][K_BINARY][isExported:true]\n" +
+ "/P/lib4.jar[CPE_LIBRARY][K_BINARY][isExported:true]\n" +
+ "/P/lib1.jar[CPE_LIBRARY][K_BINARY][isExported:true]\n" +
+ "/P/lib5.jar[CPE_LIBRARY][K_BINARY][isExported:true]\n" +
+ "/P/lib2.jar[CPE_LIBRARY][K_BINARY][isExported:true]");
+
+ // Test that the referenced classpath entries has the appropriate referencingEntry value
+ IClasspathEntry[] chains = JavaCore.getReferencedClasspathEntries(rawEntries[0], p);
+ assertClasspathEquals(
+ chains,
+ "/P/lib3.jar[CPE_LIBRARY][K_BINARY][isExported:true]\n" +
+ "/P/lib4.jar[CPE_LIBRARY][K_BINARY][isExported:true]");
+ assertEquals("Referencing Entry" , rawEntries[0], chains[0].getReferencingEntry());
+ assertEquals("Referencing Entry" , rawEntries[0], chains[1].getReferencingEntry());
+
+ chains = JavaCore.getReferencedClasspathEntries(rawEntries[1], p);
+ assertClasspathEquals(
+ chains,
+ "/P/lib3.jar[CPE_LIBRARY][K_BINARY][isExported:true]\n" +
+ "/P/lib5.jar[CPE_LIBRARY][K_BINARY][isExported:true]");
+
+ assertEquals("Referencing Entry" , rawEntries[0], chains[0].getReferencingEntry());
+ assertEquals("Referencing Entry" , rawEntries[1], chains[1].getReferencingEntry());
+
+// // Test IPackageFragmentRoot#getResolvedClasspathEntry
+ IPackageFragmentRoot[] roots = p.getPackageFragmentRoots();
+ assertEquals("Package fragment root", roots[2].getResolvedClasspathEntry(), resolvedClasspath[2]);
+ assertEquals("Package fragment root", roots[3].getResolvedClasspathEntry(), resolvedClasspath[3]);
+ assertEquals("Package fragment root", roots[4].getResolvedClasspathEntry(), resolvedClasspath[4]);
+ assertEquals("Package fragment root", roots[5].getResolvedClasspathEntry(), resolvedClasspath[5]);
+ assertEquals("Package fragment root", roots[6].getResolvedClasspathEntry(), resolvedClasspath[6]);
+
+ // Test the attributes added to the referenced classpath entries are stored and retrieved properly
+ ((ClasspathEntry)chains[0]).sourceAttachmentPath = new Path("/P/efg.zip");
+ ((ClasspathEntry)chains[1]).sourceAttachmentPath = new Path("/P/xyz.zip");
+ ((ClasspathEntry)chains[0]).sourceAttachmentRootPath = new Path("/src2");
+ ((ClasspathEntry)chains[1]).sourceAttachmentRootPath = new Path("/src3");
+
+ IClasspathAttribute javadocLoc = JavaCore.newClasspathAttribute("javadoc_location", "/P/efg.zip");
+ ((ClasspathEntry)chains[0]).extraAttributes = new IClasspathAttribute[]{javadocLoc};
+
+ p.setRawClasspath(rawClasspath, chains, p.getOutputLocation(), null);
+ resolvedClasspath = p.getResolvedClasspath(true);
+
+ assertClasspathEquals(resolvedClasspath,
+ "/P[CPE_SOURCE][K_SOURCE][isExported:false]\n" +
+ ""+ getExternalJCLPathString() + "[CPE_LIBRARY][K_BINARY][isExported:false]\n" +
+ "/P/lib3.jar[CPE_LIBRARY][K_BINARY][sourcePath:/P/efg.zip][rootPath:/src2][isExported:true][attributes:javadoc_location=/P/efg.zip]\n" +
+ "/P/lib4.jar[CPE_LIBRARY][K_BINARY][isExported:true]\n" +
+ "/P/lib1.jar[CPE_LIBRARY][K_BINARY][isExported:true]\n" +
+ "/P/lib5.jar[CPE_LIBRARY][K_BINARY][sourcePath:/P/xyz.zip][rootPath:/src3][isExported:true]\n" +
+ "/P/lib2.jar[CPE_LIBRARY][K_BINARY][isExported:true]");
+
+ // Test that removing any of the referencing entry from the raw classpath has the correct effect
+ // on the resolved classpath. Also test passing referencedEntries = null retains the existing
+ // referenced entries
+ IClasspathEntry[] newRawClasspath = new IClasspathEntry[rawClasspath.length-1];
+ System.arraycopy(rawClasspath, 0, newRawClasspath, 0, 2);
+ System.arraycopy(rawClasspath, 3, newRawClasspath, 2, 1);
+ p.setRawClasspath(newRawClasspath, null, p.getOutputLocation(), null);
+ resolvedClasspath = p.getResolvedClasspath(true);
+ assertClasspathEquals(resolvedClasspath,
+ "/P[CPE_SOURCE][K_SOURCE][isExported:false]\n" +
+ ""+ getExternalJCLPathString() + "[CPE_LIBRARY][K_BINARY][isExported:false]\n" +
+ "/P/lib3.jar[CPE_LIBRARY][K_BINARY][sourcePath:/P/efg.zip][rootPath:/src2][isExported:true][attributes:javadoc_location=/P/efg.zip]\n" +
+ "/P/lib5.jar[CPE_LIBRARY][K_BINARY][sourcePath:/P/xyz.zip][rootPath:/src3][isExported:true]\n" +
+ "/P/lib2.jar[CPE_LIBRARY][K_BINARY][isExported:true]");
+
+ // Test that passing empty array of referencedEntries clears all the earlier ones.
+ p.setRawClasspath(newRawClasspath, new IClasspathEntry[]{}, p.getOutputLocation(), null);
+ resolvedClasspath = p.getResolvedClasspath(true);
+ assertClasspathEquals(resolvedClasspath,
+ "/P[CPE_SOURCE][K_SOURCE][isExported:false]\n" +
+ ""+ getExternalJCLPathString() + "[CPE_LIBRARY][K_BINARY][isExported:false]\n" +
+ "/P/lib3.jar[CPE_LIBRARY][K_BINARY][isExported:true]\n" +
+ "/P/lib5.jar[CPE_LIBRARY][K_BINARY][isExported:true]\n" +
+ "/P/lib2.jar[CPE_LIBRARY][K_BINARY][isExported:true]");
+
+ } finally {
+ deleteProject("P");
+ }
+}
+/**
+ * Additional tests for bug 252431.
+ * Test that duplicate referenced entries or entries that are already present in the raw classpath
+ * are excluded from the referenced entries when invoking
+ * {@link IJavaProject#setRawClasspath(IClasspathEntry[], IClasspathEntry[], IPath, IProgressMonitor)}
+ *
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=252431"
+ * @throws Exception
+ */
+public void testBug252341c() throws Exception {
+ try {
+ IJavaProject p = createJavaProject("P");
+ addLibrary(p, "lib1.jar", null, new String[0],
+ new String[] {
+ "META-INF/MANIFEST.MF",
+ "Manifest-Version: 1.0\n" +
+ "Class-Path: lib3.jar lib4.jar\n",
+ },
+ JavaCore.VERSION_1_4);
+
+ addLibrary(p, "lib2.jar", null, new String[0],
+ new String[] {
+ "META-INF/MANIFEST.MF",
+ "Manifest-Version: 1.0\n" +
+ "Class-Path: lib3.jar lib5.jar\n",
+ },
+ JavaCore.VERSION_1_4);
+ createFile("/P/lib3.jar", "");
+ createFile("/P/lib4.jar", "");
+ createFile("/P/lib5.jar", "");
+
+ IClasspathEntry[] rawClasspath = p.getRawClasspath();
+
+ IClasspathEntry[] rawEntries = new IClasspathEntry[2];
+ rawEntries[0] = JavaCore.newLibraryEntry(new Path("/P/lib1.jar"), null, null, true);
+ rawEntries[1] = JavaCore.newLibraryEntry(new Path("/P/lib2.jar"), null, null, true);
+
+ // Test that the referenced classpath entries has the appropriate referencingEntry value
+ IClasspathEntry[] chains = JavaCore.getReferencedClasspathEntries(rawEntries[0], p);
+
+ IClasspathEntry[] referencedEntries = new IClasspathEntry[5];
+ referencedEntries[0] = chains[0];
+ referencedEntries[1] = chains[1];
+
+ chains = JavaCore.getReferencedClasspathEntries(rawEntries[1], p);
+
+ referencedEntries[2] = chains[0];
+ referencedEntries[3] = chains[1];
+ referencedEntries[4] = chains[1];
+
+ p.setRawClasspath(rawClasspath, referencedEntries, p.getOutputLocation(), null);
+
+ p.close();
+ p.open(null);
+
+ IClasspathEntry[] storedReferencedEnties = p.getReferencedClasspathEntries();
+ assertClasspathEquals(storedReferencedEnties,
+ "/P/lib3.jar[CPE_LIBRARY][K_BINARY][isExported:true]\n" +
+ "/P/lib4.jar[CPE_LIBRARY][K_BINARY][isExported:true]\n" +
+ "/P/lib5.jar[CPE_LIBRARY][K_BINARY][isExported:true]");
+ }
+ finally {
+ deleteProject("P");
+ }
+}
+/**
+ * @bug 304081:IJavaProject#isOnClasspath(IJavaElement) returns false for type from referenced JAR
+ * When the JAR, which a variable classpath entry resolves to, references other JAR via
+ * MANIFEST, test that {@link IJavaProject#isOnClasspath(IJavaElement)} returns true
+ * for the referenced classpath entries.
+ *
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=304081"
+ * @throws Exception
+ */
+public void testBug304081() throws Exception {
+ File libDir = null;
+ try {
+
+ IJavaProject proj = this.createJavaProject("P", new String[] {}, "bin");
+ IPath libPath = proj.getResource().getLocation();
+ JavaCore.setClasspathVariable("MyVar", libPath, null);
+ libDir = new File(libPath.toPortableString());
+ IClasspathEntry[] classpath = new IClasspathEntry[1];
+ File libJar = new File(libDir, "variable.jar");
+ libJar.createNewFile();
+
+ addLibrary(proj, "variable.jar", null, new String[0],
+ new String[] {
+ "META-INF/MANIFEST.MF",
+ "Manifest-Version: 1.0\n" +
+ "Class-Path: lib1.jar\n",
+ },
+ JavaCore.VERSION_1_4);
+
+ createFile("/P/lib1.jar", "");
+
+ classpath[0] = JavaCore.newVariableEntry(new Path(
+ "/MyVar/variable.jar"), null, null);
+
+ proj.setRawClasspath(classpath, null);
+ waitForAutoBuild();
+ IProject project = getWorkspaceRoot().getProject("P");
+ IResource resource = project.getFile("variable.jar");
+ assertTrue(proj.isOnClasspath(resource));
+ IJavaElement element = proj.getPackageFragmentRoot(resource);
+ assertTrue(proj.isOnClasspath(element));
+
+ resource = project.getFile("lib1.jar");
+ assertTrue(proj.isOnClasspath(resource));
+ element = proj.getPackageFragmentRoot(resource);
+ assertTrue(proj.isOnClasspath(element));
+ } finally {
+ this.deleteProject("P");
+ JavaCore.removeClasspathVariable("MyVar", null);
+ }
+}
+/**
+ * Additional tests for 304081
+ * When the JAR, which is in the raw classpath, references other JAR via
+ * MANIFEST, test that {@link IJavaProject#isOnClasspath(IJavaElement)} returns true
+ * for the referenced classpath entries.
+ *
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=304081"
+ * @throws Exception
+ */
+public void testBug304081a() throws Exception {
+ try {
+
+ IJavaProject proj = this.createJavaProject("P", new String[] {}, "bin");
+ IClasspathEntry[] classpath = new IClasspathEntry[1];
+
+ addLibrary(proj, "library.jar", null, new String[0],
+ new String[] {
+ "META-INF/MANIFEST.MF",
+ "Manifest-Version: 1.0\n" +
+ "Class-Path: lib1.jar\n",
+ },
+ JavaCore.VERSION_1_4);
+ createFile("/P/lib1.jar", "");
+ classpath[0] = JavaCore.newLibraryEntry(new Path("/P/library.jar"), null, null);
+
+ proj.setRawClasspath(classpath, null);
+ waitForAutoBuild();
+ IProject project = getWorkspaceRoot().getProject("P");
+ IResource resource = project.getFile("library.jar");
+ assertTrue(proj.isOnClasspath(resource));
+ IJavaElement element = proj.getPackageFragmentRoot(resource);
+ assertTrue(proj.isOnClasspath(element));
+
+ resource = project.getFile("lib1.jar");
+ assertTrue(proj.isOnClasspath(resource));
+ element = proj.getPackageFragmentRoot(resource);
+ assertTrue(proj.isOnClasspath(element));
+ } finally {
+ this.deleteProject("P");
+ }
+}
+/**
+ * Additional tests for 304081
+ * When the JAR, which is part of a classpath container, references other JAR via
+ * MANIFEST, test that {@link IJavaProject#isOnClasspath(IJavaElement)} returns true
+ * for the referenced classpath entries.
+ *
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=304081"
+ * @throws Exception
+ */
+public void testBug304081b() throws Exception {
+ File libDir = null;
+ try {
+
+ IJavaProject proj = this.createJavaProject("P", new String[] {}, "bin");
+ IClasspathEntry[] classpath = new IClasspathEntry[1];
+ libDir = new File(proj.getResource().getLocation().toPortableString());
+ File libJar = new File(libDir, "container.jar");
+
+ addLibrary(proj, "container.jar", null, new String[0],
+ new String[] {
+ "META-INF/MANIFEST.MF",
+ "Manifest-Version: 1.0\n" +
+ "Class-Path: lib1.jar\n",
+ },
+ JavaCore.VERSION_1_4);
+ createFile("/P/lib1.jar", "");
+
+ ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(JavaCore.USER_LIBRARY_CONTAINER_ID);
+ String libraryName = "TestUserLibrary";
+ IPath containerPath = new Path(JavaCore.USER_LIBRARY_CONTAINER_ID);
+ UserLibraryClasspathContainer containerSuggestion = new UserLibraryClasspathContainer(libraryName);
+ initializer.requestClasspathContainerUpdate(containerPath.append(libraryName), null, containerSuggestion);
+
+ IEclipsePreferences preferences = new InstanceScope().getNode(JavaCore.PLUGIN_ID);
+ String propertyName = JavaModelManager.CP_USERLIBRARY_PREFERENCES_PREFIX+"TestUserLibrary";
+ StringBuffer propertyValue = new StringBuffer("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<userlibrary systemlibrary=\"false\" version=\"1\">\r\n<archive");
+ propertyValue.append(" path=\"" + libJar.getAbsolutePath());
+ propertyValue.append("\"/>\r\n</userlibrary>\r\n");
+ preferences.put(propertyName, propertyValue.toString());
+ preferences.flush();
+
+ classpath[0] = JavaCore.newContainerEntry(containerSuggestion.getPath());
+
+ proj.setRawClasspath(classpath, null);
+ waitForAutoBuild();
+ IProject project = getWorkspaceRoot().getProject("P");
+ IResource resource = project.getFile("container.jar");
+ assertTrue(proj.isOnClasspath(resource));
+ IJavaElement element = proj.getPackageFragmentRoot(resource);
+ assertTrue(proj.isOnClasspath(element));
+
+ resource = project.getFile("lib1.jar");
+ assertTrue(proj.isOnClasspath(resource));
+ element = proj.getPackageFragmentRoot(resource);
+ assertTrue(proj.isOnClasspath(element));
+
+ } finally {
+ this.deleteProject("P");
+ }
+}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java
index 0c41a51..4b1509a 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompilationUnitTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation 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
@@ -2436,4 +2436,37 @@
annotations);
}
+public void testBug246594() throws CoreException {
+ createWorkingCopy(
+ "package p;\n" +
+ "public class Z<T extends Object & I<? super T>> {\n" +
+ "}\n" +
+ "public interface I<T> {}"
+ );
+ IType type = this.workingCopy.getType("Z");
+ ITypeParameter[] typeParameters = type.getTypeParameters();
+ assertStringsEqual("Type parameter signature", "T:QObject;:QI<-QT;>;\n", type.getTypeParameterSignatures());
+ assertStringsEqual("Type parameter bounds signatures",
+ "QObject;\n" +
+ "QI<-QT;>;\n",
+ typeParameters[0].getBoundsSignatures());
+}
+public void testBug246594a() throws CoreException {
+ createWorkingCopy(
+ "package p;\n" +
+ "interface Collection<E> {\n" +
+ "public <T> boolean containsAll(Collection<T> c);\n" +
+ "public <T extends E & I<? super String>> boolean addAll(Collection<T> c);\n" +
+ "}" +
+ "public interface I<T> {}");
+ IMethod[] methods = this.workingCopy.getType("Collection").getMethods();//<T:TE;>
+ ITypeParameter[] typeParameters = methods[1].getTypeParameters();
+ assertStringsEqual("Type parameter bounds signatures",
+ "QE;\n" +
+ "QI<-QString;>;\n",
+ typeParameters[0].getBoundsSignatures());
+
+}
+
+
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java
index 6edbf0f..90b9b58 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/CompletionTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation 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
@@ -20600,4 +20600,170 @@
requestor.getResults());
}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=287939
+// To verify that auto complete works after instance of expression when content assist is requested on a field
+// Code assist requested in a local variable declaration statement
+public void testBug287939a() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/test/CompletionAfterInstanceOf.java",
+ "package test;\n" +
+ "public class CompletionAfterInstanceOf {\n" +
+ " public int returnZero(){ return 0;}\n" +
+ " public Object a;\n" +
+ " void bar(){\n" +
+ " if (this.a instanceof CompletionAfterInstanceOf) {\n" +
+ " int i = this.a.r\n" +
+ " int j = 0;\n" +
+ " int k = 2;\n" +
+ " int p = 12;\n" +
+ " }\n" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "this.a.r";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+
+ int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED + R_EXACT_EXPECTED_TYPE;
+ int start1 = str.lastIndexOf("r") + "".length();
+ int end1 = start1 + "r".length();
+ int start2 = str.lastIndexOf("this.a.r");
+ int end2 = start2 + "this.a.r".length();
+ int start3 = str.lastIndexOf("this.a.");
+ int end3 = start3 + "this.a".length();
+
+ assertResults(
+ "expectedTypesSignatures={I}\n" +
+ "expectedTypesKeys={I}",
+ requestor.getContext());
+ assertResults(
+ "returnZero[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)this.a).returnZero(), Ltest.CompletionAfterInstanceOf;, ()I, Ltest.CompletionAfterInstanceOf;, returnZero, null, replace["+start2+", "+end2+"], token["+start1+", "+end1+"], receiver["+start3+", "+end3+"], " + (relevance1) + "}",
+ requestor.getResults());
+}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=287939
+// To verify that auto complete works after instance of expression when content assist is requested on a field
+// Code assist requested in an assignment statement
+public void testBug287939b() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/test/CompletionAfterInstanceOf.java",
+ "package test;\n" +
+ "public class CompletionAfterInstanceOf {\n" +
+ " public int returnZero(){ return 0;}\n" +
+ " public Object a;\n" +
+ " void bar(){\n" +
+ " int i;\n" +
+ " if (this.a instanceof CompletionAfterInstanceOf) {\n" +
+ " i = this.a.r\n" +
+ " }\n" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "this.a.r";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+
+ int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED + R_EXACT_EXPECTED_TYPE;
+ int start1 = str.lastIndexOf("r") + "".length();
+ int end1 = start1 + "r".length();
+ int start2 = str.lastIndexOf("this.a.r");
+ int end2 = start2 + "this.a.r".length();
+ int start3 = str.lastIndexOf("this.a.");
+ int end3 = start3 + "this.a".length();
+
+ assertResults(
+ "expectedTypesSignatures={I}\n" +
+ "expectedTypesKeys={I}",
+ requestor.getContext());
+ assertResults(
+ "returnZero[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)this.a).returnZero(), Ltest.CompletionAfterInstanceOf;, ()I, Ltest.CompletionAfterInstanceOf;, returnZero, null, replace["+start2+", "+end2+"], token["+start1+", "+end1+"], receiver["+start3+", "+end3+"], " + (relevance1) + "}",
+ requestor.getResults());
+}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=287939
+// To verify that auto complete works after instance of expression when content assist is requested on a local variable
+// Code assist requested in an assignment statement
+public void testBug287939c() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/test/CompletionAfterInstanceOf.java",
+ "package test;\n" +
+ "public class CompletionAfterInstanceOf {\n" +
+ " public int returnZero(){ return 0;}\n" +
+ " void bar(Object a){\n" +
+ " int i;\n" +
+ " if (a instanceof CompletionAfterInstanceOf) {" +
+ " i = a.r\n" +
+ " }\n" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "a.r";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+
+ int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED + R_EXACT_EXPECTED_TYPE;
+ int start1 = str.lastIndexOf("r") + "".length();
+ int end1 = start1 + "r".length();
+ int start2 = str.lastIndexOf("a.r");
+ int end2 = start2 + "a.r".length();
+ int start3 = str.lastIndexOf("a.");
+ int end3 = start3 + "a".length();
+
+ assertResults(
+ "expectedTypesSignatures={I}\n" +
+ "expectedTypesKeys={I}",
+ requestor.getContext());
+ assertResults(
+ "returnZero[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)a).returnZero(), Ltest.CompletionAfterInstanceOf;, ()I, Ltest.CompletionAfterInstanceOf;, returnZero, null, replace["+start2+", "+end2+"], token["+start1+", "+end1+"], receiver["+start3+", "+end3+"], " + (relevance1) + "}",
+ requestor.getResults());
+}
+
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=287939
+// To verify that auto complete works after instance of expression when content assist is requested on a local variable
+// Code assist requested in a local variable declaration statement
+public void testBug287939d() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Completion/src/test/CompletionAfterInstanceOf.java",
+ "package test;\n" +
+ "public class CompletionAfterInstanceOf {\n" +
+ " public int returnZero(){ return 0;}\n" +
+ " void bar(Object a){\n" +
+ " if (a instanceof CompletionAfterInstanceOf) {" +
+ " int i = a.r\n" +
+ " }\n" +
+ "}\n");
+
+ CompletionTestsRequestor2 requestor = new CompletionTestsRequestor2(true, false, true, true, true, true);
+ requestor.allowAllRequiredProposals();
+ String str = this.workingCopies[0].getSource();
+ String completeBehind = "a.r";
+ int cursorLocation = str.lastIndexOf(completeBehind) + completeBehind.length();
+ this.workingCopies[0].codeComplete(cursorLocation, requestor, this.wcOwner);
+
+ int relevance1 = R_DEFAULT + R_RESOLVED + R_INTERESTING + R_CASE + R_NON_STATIC + R_NON_RESTRICTED + R_EXACT_EXPECTED_TYPE;
+ int start1 = str.lastIndexOf("r") + "".length();
+ int end1 = start1 + "r".length();
+ int start2 = str.lastIndexOf("a.r");
+ int end2 = start2 + "a.r".length();
+ int start3 = str.lastIndexOf("a.");
+ int end3 = start3 + "a".length();
+
+ assertResults(
+ "expectedTypesSignatures={I}\n" +
+ "expectedTypesKeys={I}",
+ requestor.getContext());
+ assertResults(
+ "returnZero[METHOD_REF_WITH_CASTED_RECEIVER]{((CompletionAfterInstanceOf)a).returnZero(), Ltest.CompletionAfterInstanceOf;, ()I, Ltest.CompletionAfterInstanceOf;, returnZero, null, replace["+start2+", "+end2+"], token["+start1+", "+end1+"], receiver["+start3+", "+end3+"], " + (relevance1) + "}",
+ requestor.getResults());
+}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java
index 113d189..8a676f8 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchBugsTests.java
@@ -24,6 +24,7 @@
import org.eclipse.core.resources.IResourceChangeEvent;
import org.eclipse.core.resources.IResourceChangeListener;
import org.eclipse.core.resources.IResourceDelta;
+import org.eclipse.core.resources.IWorkspaceDescription;
import org.eclipse.core.resources.IncrementalProjectBuilder;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
@@ -11461,4 +11462,83 @@
}
}
+/**
+ * @bug 304841: [search] NPE in IndexSelector.initializeIndexLocations
+ * @test Ensure that no NPE occurs when searching for a reference in a CU without primary type
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=304841"
+ */
+public void testBug304841() throws Exception {
+ boolean autoBuild = getWorkspace().isAutoBuilding();
+ IWorkspaceDescription preferences = getWorkspace().getDescription();
+ try {
+ // ensure that the workspace auto-build is ON
+ preferences.setAutoBuilding(true);
+ getWorkspace().setDescription(preferences);
+
+ // create test case
+ IJavaProject project = createJavaProject("P");
+ createFolder("/P/p");
+ createFile(
+ "/P/p/Hello.java",
+ "package p;\n" +
+ "class One {\n" +
+ "}\n" +
+ "class Two {\n" +
+ "}\n"
+ );
+ createFile(
+ "/P/p/Ref.java",
+ "package p;\n" +
+ "class Three {\n" +
+ " Two two;\n" +
+ "}\n"
+ );
+ waitUntilIndexesReady();
+
+ // perform search
+ final ICompilationUnit cu = getCompilationUnit("/P/p/Hello.java");
+ IType type = cu.getType("Two");
+ SearchPattern pattern = SearchPattern.createPattern(type, REFERENCES);
+ MatchLocator.setFocus(pattern, type);
+ new SearchEngine().search(
+ pattern,
+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+ SearchEngine.createJavaSearchScope(new IJavaElement[] { project }),
+ this.resultCollector,
+ null
+ );
+ assertSearchResults(
+ "p/Ref.java p.Three.two [Two] EXACT_MATCH"
+ );
+ } finally {
+ preferences.setAutoBuilding(autoBuild);
+ getWorkspace().setDescription(preferences);
+ deleteProject("P");
+ }
+}
+public void testBug304841b() throws Exception {
+ boolean autoBuild = getWorkspace().isAutoBuilding();
+ IWorkspaceDescription preferences = getWorkspace().getDescription();
+ try {
+ // ensure that the workspace auto-build is ON
+ preferences.setAutoBuilding(true);
+ getWorkspace().setDescription(preferences);
+
+ // perform search
+ IType type = getClassFile("/JavaSearchBugs/lib/Bug148380.class").getType();
+ SearchPattern pattern = SearchPattern.createPattern(type, REFERENCES);
+ MatchLocator.setFocus(pattern, type);
+ new SearchEngine().search(
+ pattern,
+ new SearchParticipant[] {SearchEngine.getDefaultSearchParticipant()},
+ getJavaSearchScope(),
+ this.resultCollector,
+ null
+ );
+ assertSearchResults(""); // No expected results, only verify that no CCE occurs
+ } finally {
+ preferences.setAutoBuilding(autoBuild);
+ getWorkspace().setDescription(preferences);
+ }
+}
}
\ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java
index ed6fe68..36fc8f9 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/JavaSearchTests.java
@@ -661,6 +661,7 @@
getExternalResourcePath("externalLib.abc"));
IJavaProject p = createJavaProject("P", new String[0], new String[] {getExternalResourcePath("externalLib.abc")}, "");
refreshExternalArchives(p);
+ waitUntilIndexesReady();
IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaProject[] {getJavaProject("P")});
search("foo", METHOD, DECLARATIONS, scope);
@@ -688,6 +689,7 @@
},
getExternalResourcePath("externalLib.abc"));
refreshExternalArchives(p);
+ waitUntilIndexesReady();
TypeNameMatchCollector collector = new TypeNameMatchCollector();
new SearchEngine(this.workingCopies).searchAllTypeNames(
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests.java
index 535d6c2..065d3b9 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/ResolveTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2008 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation 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
@@ -12,10 +12,20 @@
import java.io.IOException;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jdt.core.*;
+import junit.framework.Test;
-import junit.framework.*;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IClassFile;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.ILocalVariable;
+import org.eclipse.jdt.core.IMethod;
+import org.eclipse.jdt.core.ISourceRange;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.WorkingCopyOwner;
public class ResolveTests extends AbstractJavaModelTests {
ICompilationUnit wc = null;
@@ -2546,5 +2556,36 @@
elements
);
}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=235658
+// To verify that "open declaration" works for a protected interface, which is
+// an inner type of an extending class's superclass.
+public void testInterfaceX() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[2];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Resolve/src/test/Bug.java",
+ "package test;\n"+
+ "public class Bug {\n" +
+ " void foo() {}\n" +
+ " protected interface Proto {}\n" +
+ "}\n");
+
+ this.workingCopies[1] = getWorkingCopy(
+ "/Resolve/src/Type.java",
+ "import test.Bug;\n"+
+ "import test.Bug.*;\n"+
+ "class Type extends Bug implements Proto {\n" +
+ "}\n");
+
+ String str = this.workingCopies[1].getSource();
+ int start = str.lastIndexOf("Proto");
+ int length = "Proto".length();
+ IJavaElement[] elements = this.workingCopies[1].codeSelect(start, length, this.wcOwner);
+
+ assertElementsEqual(
+ "Unexpected elements",
+ "Proto [in Bug [in [Working copy] Bug.java [in test [in src [in Resolve]]]]]",
+ elements
+ );
+}
}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SignatureTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SignatureTests.java
index b2820cf..2365543 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SignatureTests.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/SignatureTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2009 IBM Corporation and others.
+ * Copyright (c) 2000, 2010 IBM Corporation 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
@@ -39,7 +39,7 @@
// Prefix for tests names to run
// TESTS_PREFIX = "testGetTypeErasure";
// Names of tests to run: can be "testBugXXXX" or "BugXXXX")
-// TESTS_NAMES = new String[] { "testGetSimpleName" };
+// TESTS_NAMES = new String[] { "testToStringMethod13" };
// Numbers of tests to run: "test<number>" will be run for each number of this array
// TESTS_NUMBERS = new int[] { 8 };
// Range numbers of tests to run: all tests between "test<first>" and "test<last>" will be run for { first, last }
@@ -267,6 +267,14 @@
Signature.getParameterCount(methodSig));
}
/*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=267432
+ */
+public void testGetParameterCount19() {
+ String methodSig= "<TYPE:Ljava/lang/Object;>(Ljava/lang/Object;Ljava/lang/Class<TTYPE;>;)TTYPE;";
+ assertEquals("Signature#getParameterCount is not correct", 2,
+ Signature.getParameterCount(methodSig));
+}
+/*
* Ensures that a signature with a '? extends ?' wildcard can be decoded.
* (regression test for bug 92370 [1.5] IAE in Signature.getParameterCount(..) for method proposal on capture type receiver)
*/
@@ -280,9 +288,9 @@
*/
public void testGetParameterTypes() {
String methodSig = "(QString;QObject;I)I";
- String[] types= Signature.getParameterTypes(methodSig);
- assertEquals("Signature#getParameterTypes is not correct1", 3, types.length);
- assertEquals("Signature#getParameterTypes is not correct2", "QObject;", types[1]);
+ String[] parameterTypes = Signature.getParameterTypes(methodSig);
+ assertEquals("Signature#getParameterTypes is not correct1", 3, parameterTypes.length);
+ assertEquals("Signature#getParameterTypes is not correct2", "QObject;", parameterTypes[1]);
try {
Signature.getParameterTypes("");
assertTrue("Signature#getParameterTypes is not correct: exception", false);
@@ -292,60 +300,75 @@
// primitive types
methodSig = "(BCDFIJSVZ)V";
+ parameterTypes = Signature.getParameterTypes(methodSig);
assertEquals("Signature#getParameterTypes 4", 9,
- Signature.getParameterTypes(methodSig).length);
+ parameterTypes.length);
assertEquals("Signature#getParameterTypes 4", "B",
- Signature.getParameterTypes(methodSig)[0]);
+ parameterTypes[0]);
assertEquals("Signature#getParameterTypes 4", "C",
- Signature.getParameterTypes(methodSig)[1]);
+ parameterTypes[1]);
assertEquals("Signature#getParameterTypes 4", "D",
- Signature.getParameterTypes(methodSig)[2]);
+ parameterTypes[2]);
assertEquals("Signature#getParameterTypes 4", "F",
- Signature.getParameterTypes(methodSig)[3]);
+ parameterTypes[3]);
assertEquals("Signature#getParameterTypes 4", "I",
- Signature.getParameterTypes(methodSig)[4]);
+ parameterTypes[4]);
assertEquals("Signature#getParameterTypes 4", "J",
- Signature.getParameterTypes(methodSig)[5]);
+ parameterTypes[5]);
assertEquals("Signature#getParameterTypes 4", "S",
- Signature.getParameterTypes(methodSig)[6]);
+ parameterTypes[6]);
assertEquals("Signature#getParameterTypes 4", "V",
- Signature.getParameterTypes(methodSig)[7]);
+ parameterTypes[7]);
assertEquals("Signature#getParameterTypes 4", "Z",
- Signature.getParameterTypes(methodSig)[8]);
+ parameterTypes[8]);
// array types
methodSig = "([I[[J[[[B[Qstring;[Tv;[Lstring;)V";
+ parameterTypes = Signature.getParameterTypes(methodSig);
assertEquals("Signature#getParameterTypes 5", 6,
- Signature.getParameterTypes(methodSig).length);
+ parameterTypes.length);
assertEquals("Signature#getParameterTypes 5", "[I",
- Signature.getParameterTypes(methodSig)[0]);
+ parameterTypes[0]);
assertEquals("Signature#getParameterTypes 5", "[[J",
- Signature.getParameterTypes(methodSig)[1]);
+ parameterTypes[1]);
assertEquals("Signature#getParameterTypes 5", "[[[B",
- Signature.getParameterTypes(methodSig)[2]);
+ parameterTypes[2]);
assertEquals("Signature#getParameterTypes 5", "[Qstring;",
- Signature.getParameterTypes(methodSig)[3]);
+ parameterTypes[3]);
assertEquals("Signature#getParameterTypes 5", "[Tv;",
- Signature.getParameterTypes(methodSig)[4]);
+ parameterTypes[4]);
assertEquals("Signature#getParameterTypes 5", "[Lstring;",
- Signature.getParameterTypes(methodSig)[5]);
+ parameterTypes[5]);
// resolved types
methodSig = "(La;)V";
- assertEquals("Signature#getParameterTypes 6", 1,
- Signature.getParameterTypes(methodSig).length);
- assertEquals("Signature#getParameterTypes 6", "La;",
- Signature.getParameterTypes(methodSig)[0]);
+ parameterTypes = Signature.getParameterTypes(methodSig);
+ assertEquals("Signature#getParameterTypes 6", 1, parameterTypes.length);
+ assertEquals("Signature#getParameterTypes 6", "La;", parameterTypes[0]);
+
methodSig = "(La<TE;>;)V";
+ parameterTypes = Signature.getParameterTypes(methodSig);
assertEquals("Signature#getParameterTypes 6", 1,
- Signature.getParameterTypes(methodSig).length);
+ parameterTypes.length);
assertEquals("Signature#getParameterTypes 6", "La<TE;>;",
- Signature.getParameterTypes(methodSig)[0]);
- methodSig = "(La/b/c<TE;>.d<TF;>;)V";
+ parameterTypes[0]);
+
+ methodSig = "(La.b.c<TE;>.d<TF;>;)V";
+ parameterTypes = Signature.getParameterTypes(methodSig);
assertEquals("Signature#getParameterTypes 6", 1,
- Signature.getParameterTypes(methodSig).length);
- assertEquals("Signature#getParameterTypes 6", "La/b/c<TE;>.d<TF;>;",
- Signature.getParameterTypes(methodSig)[0]);
+ parameterTypes.length);
+ assertEquals("Signature#getParameterTypes 6", "La.b.c<TE;>.d<TF;>;",
+ parameterTypes[0]);
+
+ // signature with type variable
+ methodSig = "<TYPE:Ljava.lang.Object;>(Ljava.lang.Object;Ljava.lang.Class<TTYPE;>;)TTYPE;";
+ parameterTypes = Signature.getParameterTypes(methodSig);
+ assertEquals("Signature#getParameterTypes 7", 2,
+ parameterTypes.length);
+ assertEquals("Signature#getParameterTypes 7", "Ljava.lang.Object;",
+ parameterTypes[0]);
+ assertEquals("Signature#getParameterTypes 7", "Ljava.lang.Class<TTYPE;>;",
+ parameterTypes[1]);
}
/**
* @see Signature
@@ -1070,7 +1093,6 @@
}
assertTrue("Should get an exception", false);
}
-
/**
* Test the toString() signature of an inner type.
*/
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/UtilTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/UtilTests.java
new file mode 100644
index 0000000..ab13110
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/model/UtilTests.java
@@ -0,0 +1,78 @@
+/*******************************************************************************
+ * Copyright (c) 2010 IBM Corporation 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
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.core.tests.model;
+
+import org.eclipse.jdt.internal.core.util.Util;
+
+import junit.framework.Test;
+
+public class UtilTests extends AbstractJavaModelTests {
+
+ static {
+// TESTS_PREFIX = "testInvalidCompilerOptions";
+// TESTS_NAMES = new String[] { "test028"};
+ }
+
+ public UtilTests(String name) {
+ super(name);
+ }
+
+ public static Test suite() {
+ return buildModelTestSuite(UtilTests.class);
+ }
+ public void test001() {
+ String[] arguments = Util.getProblemArgumentsFromMarker("1:foo");
+ assertStringsEqual("Wrong arguments", new String[] {"foo"}, arguments);
+ }
+ public void test002() {
+ String[] arguments = Util.getProblemArgumentsFromMarker("2:foo#bar");
+ assertStringsEqual("Wrong arguments", new String[] {"foo", "bar"}, arguments);
+ }
+ public void test003() {
+ String[] arguments = Util.getProblemArgumentsFromMarker("1: ");
+ assertStringsEqual("Wrong arguments", new String[] {""}, arguments);
+ }
+ public void test004() {
+ String[] arguments = Util.getProblemArgumentsFromMarker("0:");
+ assertStringsEqual("Wrong arguments", new String[0], arguments);
+ }
+ public void test005() {
+ String[] arguments = Util.getProblemArgumentsFromMarker("3:Task<capture##1-of ?>#getTaskListeners# ");
+ assertStringsEqual("Wrong arguments", new String[] {"Task<capture#1-of ?>", "getTaskListeners", ""}, arguments);
+ }
+ public void test006() {
+ String[] arguments = new String[] {"Task<capture#1-of ?>", "getTaskListeners", ""};
+ String[] result = Util.getProblemArgumentsFromMarker(Util.getProblemArgumentsForMarker(arguments));
+ assertStringsEqual("Wrong arguments", arguments, result);
+ }
+ public void test007() {
+ assertNull("Not null", Util.getProblemArgumentsFromMarker("tt:Task<capture##1-of ?>#getTaskListeners# "));
+ }
+ public void test008() {
+ assertNull("Not null", Util.getProblemArgumentsFromMarker("3Task<capture##1-of ?>#getTaskListeners# "));
+ }
+ public void test009() {
+ assertNull("Not null", Util.getProblemArgumentsFromMarker(null));
+ }
+ public void test010() {
+ assertNull("Not null", Util.getProblemArgumentsFromMarker("0:Task"));
+ }
+ public void test011() {
+ String[] arguments = new String[] {"", "", ""};
+ String[] result = Util.getProblemArgumentsFromMarker(Util.getProblemArgumentsForMarker(arguments));
+ assertStringsEqual("Wrong arguments", arguments, result);
+ }
+ public void test012() {
+ String[] arguments = new String[] {"foo#test", "bar"};
+ String[] result = Util.getProblemArgumentsFromMarker(Util.getProblemArgumentsForMarker(arguments));
+ assertStringsEqual("Wrong arguments", arguments, result);
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java
index 2548559..d53ac2a 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/describing/ImportRewriteTest.java
@@ -26,6 +26,8 @@
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTParser;
+import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.rewrite.ImportRewrite;
import org.eclipse.jdt.core.formatter.DefaultCodeFormatterConstants;
import org.eclipse.jdt.core.tests.model.AbstractJavaModelTests;
@@ -300,6 +302,39 @@
assertEqualString(cu.getSource(), buf.toString());
}
+ public void testAddImports5() throws Exception {
+ getJavaProject("P").setOption(DefaultCodeFormatterConstants.FORMATTER_INSERT_SPACE_BEFORE_SEMICOLON, JavaCore.INSERT);
+
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("pack1", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package pack1;\n");
+ buf.append("\n");
+ buf.append("public class C {\n");
+ buf.append("}\n");
+ ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null);
+
+ String[] order= new String[] { "java", "java.util", "com", "pack" };
+
+ ImportRewrite imports= newImportsRewrite(cu, order, 1, 1, true);
+ imports.setUseContextToFilterImplicitImports(true);
+ imports.addImport("java.util.Map");
+ imports.addImport("java.util.Set");
+ imports.addImport("java.util.Map.Entry");
+ imports.addImport("java.util.Collections");
+
+ apply(imports);
+
+ buf= new StringBuffer();
+ buf.append("package pack1;\n");
+ buf.append("\n");
+ buf.append("import java.util.* ;\n");
+ buf.append("import java.util.Map.Entry ;\n");
+ buf.append("\n");
+ buf.append("public class C {\n");
+ buf.append("}\n");
+ assertEqualString(cu.getSource(), buf.toString());
+ }
+
public void testAddImportsWithGroupsOfUnmatched1() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("pack1", false, null);
@@ -446,6 +481,57 @@
assertEqualString(cu.getSource(), buf.toString());
}
+ public void testRemoveImports3() throws Exception {
+ IPackageFragment pack= this.sourceFolder.createPackageFragment("pack", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package pack;\n");
+ buf.append("\n");
+ buf.append("public class A {\n");
+ buf.append(" public class Inner {\n");
+ buf.append(" }\n");
+ buf.append("}\n");
+ pack.createCompilationUnit("A.java", buf.toString(), false, null);
+
+ IPackageFragment test1= this.sourceFolder.createPackageFragment("test1", false, null);
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("\n");
+ buf.append("import pack.A;\n");
+ buf.append("import pack.A.Inner;\n");
+ buf.append("import pack.A.NotThere;\n");
+ buf.append("import pack.B;\n");
+ buf.append("import pack.B.Inner;\n");
+ buf.append("import pack.B.NotThere;\n");
+ buf.append("\n");
+ buf.append("public class T {\n");
+ buf.append("}\n");
+ ICompilationUnit cuT= test1.createCompilationUnit("T.java", buf.toString(), false, null);
+
+ ASTParser parser= ASTParser.newParser(AST.JLS3);
+ parser.setSource(cuT);
+ parser.setResolveBindings(true);
+ CompilationUnit astRoot= (CompilationUnit) parser.createAST(null);
+
+ ImportRewrite imports= newImportsRewrite(astRoot, new String[0], 99, 99, true);
+ imports.setUseContextToFilterImplicitImports(true);
+
+ imports.removeImport("pack.A.Inner");
+ imports.removeImport("pack.A.NotThere");
+ imports.removeImport("pack.B.Inner");
+ imports.removeImport("pack.B.NotThere");
+
+ apply(imports);
+
+ buf= new StringBuffer();
+ buf.append("package test1;\n");
+ buf.append("\n");
+ buf.append("import pack.A;\n");
+ buf.append("import pack.B;\n");
+ buf.append("\n");
+ buf.append("public class T {\n");
+ buf.append("}\n");
+ assertEqualString(cuT.getSource(), buf.toString());
+ }
public void testAddImports_bug23078() throws Exception {
@@ -572,6 +658,145 @@
assertEqualString(cu.getSource(), buf.toString());
}
+ /**
+ * Test that the Inner class import comes in the right order (i.e. after the enclosing type's import) when re-organized
+ *
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=194358"
+ */
+ public void testBug194358() throws Exception {
+
+ StringBuffer buf= new StringBuffer();
+ buf.append("package pack1;\n");
+ buf.append("\n");
+ buf.append("import pack2.A;\n");
+ buf.append("import pack2.A.Inner;\n");
+ buf.append("import pack2.B;\n");
+ buf.append("\n");
+ buf.append("public class C {\n");
+ buf.append("}\n");
+
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("pack1", false, null);
+ ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null);
+
+ // We need to actually make some state in the AST for the classes, to test that we can
+ // disambiguate between packages and inner classes (see the bug for details).
+ IPackageFragment pack2= this.sourceFolder.createPackageFragment("pack2", false, null);
+ ICompilationUnit aUnit= pack2.createCompilationUnit("A.java", "", false, null);
+ ICompilationUnit bUnit= pack2.createCompilationUnit("B.java", "", false, null);
+ bUnit.createType("class B {}", null, false, null);
+
+ IType aType= aUnit.createType("class A {}", null, false, null);
+ aType.createType("class Inner {}", null, false, null);
+ String[] order= new String[] { "java" };
+
+ ImportRewrite imports= newImportsRewrite(cu, order, 99, 99, false);
+ imports.setUseContextToFilterImplicitImports(true);
+ imports.addImport("pack2.A");
+ imports.addImport("pack2.B");
+ imports.addImport("pack2.A.Inner");
+
+ apply(imports);
+
+ buf= new StringBuffer();
+ buf.append("package pack1;\n");
+ buf.append("\n");
+ buf.append("import pack2.A;\n");
+ buf.append("import pack2.A.Inner;\n");
+ buf.append("import pack2.B;\n");
+ buf.append("\n");
+ buf.append("public class C {\n");
+ buf.append("}\n");
+ assertEqualString(cu.getSource(), buf.toString());
+ }
+
+ /**
+ * Test that a valid inner class import is not removed even when the container
+ * class is implicitly available. This tests the case where the classes are in
+ * different compilation units.
+ *
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=194358"
+ */
+ public void testBug194358a() throws Exception {
+ StringBuffer buf= new StringBuffer();
+ buf.append("package com.pack1;\n");
+ buf.append("\n");
+ buf.append("import com.pack1.A;\n");
+ buf.append("import com.pack1.A.Inner;\n");
+ buf.append("import com.pack2.B;\n");
+ buf.append("\n");
+ buf.append("public class C {\n");
+ buf.append("}\n");
+
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("com.pack1", false, null);
+ ICompilationUnit cu= pack1.createCompilationUnit("C.java", buf.toString(), false, null);
+ ICompilationUnit aUnit= pack1.createCompilationUnit("A.java", "", false, null);
+
+ IPackageFragment pack2= this.sourceFolder.createPackageFragment("com.pack2", false, null);
+ ICompilationUnit bUnit= pack2.createCompilationUnit("B.java", "", false, null);
+ bUnit.createType("class B {}", null, false, null);
+ IType aType= aUnit.createType("class A {}", null, false, null);
+ aType.createType("class Inner {}", null, false, null);
+ String[] order= new String[] { "java" };
+
+ ImportRewrite imports= newImportsRewrite(cu, order, 99, 99, false);
+ imports.setUseContextToFilterImplicitImports(false);
+ imports.addImport("com.pack1.A");
+ imports.addImport("com.pack1.A.Inner");
+ imports.addImport("com.pack2.B");
+
+ apply(imports);
+
+ buf= new StringBuffer();
+ buf.append("package com.pack1;\n");
+ buf.append("\n");
+ buf.append("import com.pack1.A.Inner;\n");
+ buf.append("import com.pack2.B;\n");
+ buf.append("\n");
+ buf.append("public class C {\n");
+ buf.append("}\n");
+ assertEqualString(cu.getSource(), buf.toString());
+ }
+ /**
+ * Test that the Inner type imports are not removed while organizing even though the
+ * containing class is implicitly available - for the case when both the classes are
+ * in the same compilation unit
+ *
+ * see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=235253"
+ */
+ public void testBug235253() throws Exception {
+ StringBuffer buf= new StringBuffer();
+ buf.append("package bug;\n");
+ buf.append("\n");
+ buf.append("class Bug {\n");
+ buf.append("public void addFile(File file) {}\n");
+ buf.append("\tinterface Proto{};\n");
+ buf.append("}\n");
+ buf.append("class Foo implements Proto{}");
+
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("bug", false, null);
+ ICompilationUnit cu= pack1.createCompilationUnit("Bug.java", buf.toString(), false, null);
+ String[] order= new String[] { "bug" , "java" };
+ ImportRewrite imports= newImportsRewrite(cu, order, 99, 99, false);
+ imports.setUseContextToFilterImplicitImports(true);
+ imports.addImport("bug.Bug.Proto");
+ imports.addImport("java.io.File");
+
+ apply(imports);
+ buf = new StringBuffer();
+ buf.append("package bug;\n");
+ buf.append("\n");
+ buf.append("import bug.Bug.Proto;\n");
+ buf.append("\n");
+ buf.append("import java.io.File;\n");
+ buf.append("\n");
+ buf.append("class Bug {\n");
+ buf.append("public void addFile(File file) {}\n");
+ buf.append("\tinterface Proto{};\n");
+ buf.append("}\n");
+ buf.append("class Foo implements Proto{}");
+ assertEqualString(cu.getSource(), buf.toString());
+ }
+
public void testAddStaticImports1() throws Exception {
IPackageFragment pack1= this.sourceFolder.createPackageFragment("pack1", false, null);
@@ -1007,6 +1232,14 @@
return rewrite;
}
+ protected ImportRewrite newImportsRewrite(CompilationUnit cu, String[] order, int normalThreshold, int staticThreshold, boolean restoreExistingImports) {
+ ImportRewrite rewrite= ImportRewrite.create(cu, restoreExistingImports);
+ rewrite.setImportOrder(order);
+ rewrite.setOnDemandImportThreshold(normalThreshold);
+ rewrite.setStaticOnDemandImportThreshold(staticThreshold);
+ return rewrite;
+ }
+
private void apply(ImportRewrite rewrite) throws CoreException, MalformedTreeException, BadLocationException {
TextEdit edit= rewrite.rewriteImports(null);
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingCopyTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingCopyTest.java
index 8965012..46b478a 100644
--- a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingCopyTest.java
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/rewrite/modifying/ASTRewritingModifyingCopyTest.java
@@ -14,10 +14,29 @@
import junit.framework.Test;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IPackageFragment;
-
-import org.eclipse.jdt.core.dom.*;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.ASTParser;
+import org.eclipse.jdt.core.dom.Block;
+import org.eclipse.jdt.core.dom.CatchClause;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.Expression;
+import org.eclipse.jdt.core.dom.ExpressionStatement;
+import org.eclipse.jdt.core.dom.FieldAccess;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.MethodInvocation;
+import org.eclipse.jdt.core.dom.Name;
+import org.eclipse.jdt.core.dom.PrimitiveType;
+import org.eclipse.jdt.core.dom.QualifiedName;
+import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
+import org.eclipse.jdt.core.dom.Statement;
+import org.eclipse.jdt.core.dom.StructuralPropertyDescriptor;
+import org.eclipse.jdt.core.dom.ThrowStatement;
+import org.eclipse.jdt.core.dom.TryStatement;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.core.tests.util.Util;
public class ASTRewritingModifyingCopyTest extends ASTRewritingModifyingTest {
@@ -342,30 +361,30 @@
astRoot.recordModifications();
TypeDeclaration type = (TypeDeclaration) astRoot.types().get(0);
- AST ast = type.getAST();
+ AST ast = type.getAST();
- MethodDeclaration m = ast.newMethodDeclaration();
- type.bodyDeclarations().add(m);
+ MethodDeclaration m = ast.newMethodDeclaration();
+ type.bodyDeclarations().add(m);
- Block block = ast.newBlock();
- m.setName(ast.newSimpleName("foo"));
- m.setReturnType(ast.newPrimitiveType(PrimitiveType.VOID));
- m.setBody(block);
+ Block block = ast.newBlock();
+ m.setName(ast.newSimpleName("foo"));
+ m.setReturnType(ast.newPrimitiveType(PrimitiveType.VOID));
+ m.setBody(block);
- FieldAccess fa = ast.newFieldAccess();
- fa.setExpression(ast.newThisExpression());
- fa.setName(ast.newSimpleName("x"));
- MethodInvocation mi = ast.newMethodInvocation();
- mi.setExpression(fa);
- mi.setName(ast.newSimpleName("llall"));
+ FieldAccess fa = ast.newFieldAccess();
+ fa.setExpression(ast.newThisExpression());
+ fa.setName(ast.newSimpleName("x"));
+ MethodInvocation mi = ast.newMethodInvocation();
+ mi.setExpression(fa);
+ mi.setName(ast.newSimpleName("llall"));
- ExpressionStatement exp = ast.newExpressionStatement(mi);
- block.statements().add(exp);
+ ExpressionStatement exp = ast.newExpressionStatement(mi);
+ block.statements().add(exp);
- StructuralPropertyDescriptor loc = mi.getLocationInParent();
- //This will cause the bug
- ASTNode node = ASTNode.copySubtree(ast, fa);
- exp.setStructuralProperty(loc, node);
+ StructuralPropertyDescriptor loc = mi.getLocationInParent();
+ //This will cause the bug
+ ASTNode node = ASTNode.copySubtree(ast, fa);
+ exp.setStructuralProperty(loc, node);
String preview = evaluateRewrite(cu, astRoot);
@@ -375,58 +394,179 @@
buf.append(" void foo(){this.x;} }");
assertEqualString(Util.convertToIndependantLineDelimiter(preview), Util.convertToIndependantLineDelimiter(buf.toString()));
}
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=304656
+ public void test0008() throws Exception {
+ IPackageFragment pack1= this.sourceFolder.createPackageFragment("test0008", false, null);
+ StringBuffer buf= new StringBuffer();
+ buf.append("package test0008;\n" +
+ "\n" +
+ "public class TestClass {\n" +
+ " Thread t = new Thread(new Runnable(){\n" +
+ "\n" +
+ " @Override\n" +
+ " public void run() {\n" +
+ " try {\n" +
+ " Thread.currentThread().sleep(1000);\n" +
+ " } catch (InterruptedException e) {\n" +
+ " e.printStackTrace();\n" +
+ " }\n" +
+ " }\n" +
+ " \n" +
+ " });\n" +
+ "\n" +
+ " public void testMethod(){\n" +
+ " t.start();\n" +
+ " }\n" +
+ "\n" +
+ " public static Thread staticTestMethod(Thread thread){\n" +
+ " return thread;\n" +
+ " }\n" +
+ "}");
+ ICompilationUnit cu = pack1.createCompilationUnit("Test.java", buf.toString(), false, null);
-// public void test0007() throws Exception {
-// IPackageFragment pack1= fSourceFolder.createPackageFragment("test0007", false, null);
-// StringBuffer buf= new StringBuffer();
-// buf.append("package test0007;\n");
-// buf.append("\n");
-// buf.append("public class X {\n");
-// buf.append(" /**\n");
-// buf.append(" * NOTHING\n");
-// buf.append(" */\n");
-// buf.append(" void foo() {\n");
-// buf.append(" \n");
-// buf.append(" }\n");
-// buf.append(" void bar() {\n");
-// buf.append(" \n");
-// buf.append(" }\n");
-// buf.append("}\n");
-// ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
-//
-// CompilationUnit astRoot= parseCompilationUnit(cu, false);
-//
-// astRoot.recordModifications();
-//
-// AST a = astRoot.getAST();
-//
-// List types = astRoot.types();
-// TypeDeclaration typeDeclaration = (TypeDeclaration)types.get(0);
-// MethodDeclaration methodDeclaration1 = typeDeclaration.getMethods()[0];
-// MethodDeclaration methodDeclaration2 = typeDeclaration.getMethods()[1];
-// Javadoc javadoc1 = methodDeclaration1.getJavadoc();
-// Javadoc javadoc2 = (Javadoc)ASTNode.copySubtree(a, javadoc1);
-// methodDeclaration2.setJavadoc(javadoc2);
-//
-// String preview = evaluateRewrite(cu, astRoot);
-//
-// buf= new StringBuffer();
-// buf.append("package test0007;\n");
-// buf.append("\n");
-// buf.append("public class X {\n");
-// buf.append(" /**\n");
-// buf.append(" * NOTHING\n");
-// buf.append(" */\n");
-// buf.append(" void foo() {\n");
-// buf.append(" \n");
-// buf.append(" }\n");
-// buf.append(" /**\n");
-// buf.append(" * NOTHING\n");
-// buf.append(" */\n");
-// buf.append(" void bar() {\n");
-// buf.append(" \n");
-// buf.append(" }\n");
-// buf.append("}\n");
-// assertEqualString(Util.convertToIndependantLineDelimiter(preview), Util.convertToIndependantLineDelimiter(buf.toString()));
-// }
+ ASTParser astParser = ASTParser.newParser(AST.JLS3);
+ astParser.setSource(cu);
+ ASTNode root = astParser.createAST(new NullProgressMonitor());
+ AST ast = root.getAST();
+
+ CompilationUnit compilationUnit = (CompilationUnit) root;
+ compilationUnit.recordModifications();
+ List types = compilationUnit.types();
+ for (int i = 0, max = types.size(); i < max; i++) {
+ TypeDeclaration td = (TypeDeclaration) types.get(i);
+ MethodDeclaration[] methods = td.getMethods();
+ for (int j = 0, max2 = methods.length; j < max2; j++) {
+ MethodDeclaration md = methods[j];
+ if (md.getName().getFullyQualifiedName().equals("testMethod")) {
+ List statements = md.getBody().statements();
+ ExpressionStatement es = (ExpressionStatement) statements.get(0);
+ MethodInvocation mi = (MethodInvocation) es.getExpression();
+ Expression existingExpression = mi.getExpression();
+ MethodInvocation threadNameInvocation = ast.newMethodInvocation();
+ threadNameInvocation.setExpression(null);
+ threadNameInvocation.setName(ast.newSimpleName("staticTestMethod"));
+ existingExpression.delete();
+ threadNameInvocation.arguments().add(existingExpression);
+ mi.setExpression(threadNameInvocation);
+
+
+ Block code = md.getBody();
+ TryStatement tryStatement = ast.newTryStatement();
+ List catches = tryStatement.catchClauses();
+ // create catch clause
+ CatchClause catchClause = ast.newCatchClause();
+ // exception to catch
+ SingleVariableDeclaration svd = ast.newSingleVariableDeclaration();
+ svd.setType(ast.newSimpleType(ast.newName("Throwable")));
+ svd.setName(ast.newSimpleName("e"));
+ catchClause.setException(svd);
+ // code to run on catch
+ Block catchBody = ast.newBlock();
+ List catchStatements = catchBody.statements();
+ // throw statement
+ ThrowStatement throwStatement = ast.newThrowStatement();
+ Expression throwExpression = ast.newName("e");
+ throwStatement.setExpression(throwExpression);
+ catchStatements.add(throwStatement);
+ catches.add(catchClause);
+ // create finally statement
+ Block finallyBlock = ast.newBlock();
+ statements = code.statements();
+ tryStatement.setFinally(finallyBlock);
+ code.delete();
+ tryStatement.setBody(code);
+ Block tryBlock = ast.newBlock();
+ tryBlock.statements().add(tryStatement);
+ md.setBody(tryBlock);
+ }
+ }
+
+ }
+ String preview = evaluateRewrite(cu, compilationUnit);
+
+ buf= new StringBuffer();
+ buf.append("package test0008;\n");
+ buf.append("\n");
+ buf.append("public class TestClass {\n");
+ buf.append(" Thread t = new Thread(new Runnable(){\n");
+ buf.append("\n");
+ buf.append(" @Override\n");
+ buf.append(" public void run() {\n");
+ buf.append(" try {\n");
+ buf.append(" Thread.currentThread().sleep(1000);\n");
+ buf.append(" } catch (InterruptedException e) {\n");
+ buf.append(" e.printStackTrace();\n");
+ buf.append(" }\n");
+ buf.append(" }\n");
+ buf.append(" \n");
+ buf.append(" });\n");
+ buf.append("\n");
+ buf.append(" public void testMethod(){\n");
+ buf.append(" try {\n");
+ buf.append(" staticTestMethod(t).start();\n");
+ buf.append(" } catch (Throwable e) {\n");
+ buf.append(" } finally {\n");
+ buf.append(" }\n");
+ buf.append(" }\n");
+ buf.append("\n");
+ buf.append(" public static Thread staticTestMethod(Thread thread){\n");
+ buf.append(" return thread;\n");
+ buf.append(" }\n");
+ buf.append("}");
+ assertEqualString(Util.convertToIndependantLineDelimiter(preview), Util.convertToIndependantLineDelimiter(buf.toString()));
+ }
+
+ // public void test0007() throws Exception {
+ // IPackageFragment pack1= fSourceFolder.createPackageFragment("test0007", false, null);
+ // StringBuffer buf= new StringBuffer();
+ // buf.append("package test0007;\n");
+ // buf.append("\n");
+ // buf.append("public class X {\n");
+ // buf.append(" /**\n");
+ // buf.append(" * NOTHING\n");
+ // buf.append(" */\n");
+ // buf.append(" void foo() {\n");
+ // buf.append(" \n");
+ // buf.append(" }\n");
+ // buf.append(" void bar() {\n");
+ // buf.append(" \n");
+ // buf.append(" }\n");
+ // buf.append("}\n");
+ // ICompilationUnit cu= pack1.createCompilationUnit("X.java", buf.toString(), false, null);
+ //
+ // CompilationUnit astRoot= parseCompilationUnit(cu, false);
+ //
+ // astRoot.recordModifications();
+ //
+ // AST a = astRoot.getAST();
+ //
+ // List types = astRoot.types();
+ // TypeDeclaration typeDeclaration = (TypeDeclaration)types.get(0);
+ // MethodDeclaration methodDeclaration1 = typeDeclaration.getMethods()[0];
+ // MethodDeclaration methodDeclaration2 = typeDeclaration.getMethods()[1];
+ // Javadoc javadoc1 = methodDeclaration1.getJavadoc();
+ // Javadoc javadoc2 = (Javadoc)ASTNode.copySubtree(a, javadoc1);
+ // methodDeclaration2.setJavadoc(javadoc2);
+ //
+ // String preview = evaluateRewrite(cu, astRoot);
+ //
+ // buf= new StringBuffer();
+ // buf.append("package test0007;\n");
+ // buf.append("\n");
+ // buf.append("public class X {\n");
+ // buf.append(" /**\n");
+ // buf.append(" * NOTHING\n");
+ // buf.append(" */\n");
+ // buf.append(" void foo() {\n");
+ // buf.append(" \n");
+ // buf.append(" }\n");
+ // buf.append(" /**\n");
+ // buf.append(" * NOTHING\n");
+ // buf.append(" */\n");
+ // buf.append(" void bar() {\n");
+ // buf.append(" \n");
+ // buf.append(" }\n");
+ // buf.append("}\n");
+ // assertEqualString(Util.convertToIndependantLineDelimiter(preview), Util.convertToIndependantLineDelimiter(buf.toString()));
+ // }
}