initial commit in accordance with CQ 3784
diff --git a/org.eclipse.jdt.core.tests.model/.classpath b/org.eclipse.jdt.core.tests.model/.classpath
new file mode 100644
index 0000000..472ee29
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/.classpath
@@ -0,0 +1,7 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.jdt.core.tests.model/.cvsignore b/org.eclipse.jdt.core.tests.model/.cvsignore
new file mode 100644
index 0000000..c5e82d7
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/.cvsignore
@@ -0,0 +1 @@
+bin
\ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/.project b/org.eclipse.jdt.core.tests.model/.project
new file mode 100644
index 0000000..646e096
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/.project
@@ -0,0 +1,26 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.jdt.core.tests.model</name>
+ <comment></comment>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.jdt.core.tests.model/.settings/org.eclipse.core.resources.prefs b/org.eclipse.jdt.core.tests.model/.settings/org.eclipse.core.resources.prefs
new file mode 100644
index 0000000..e36f4c5
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/.settings/org.eclipse.core.resources.prefs
@@ -0,0 +1,3 @@
+#Wed Nov 25 13:03:46 CET 2009
+eclipse.preferences.version=1
+encoding//workspace/Encoding/src/testUTF8/Test.java=UTF-8
diff --git a/org.eclipse.jdt.core.tests.model/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.jdt.core.tests.model/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..a9c37fd
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,97 @@
+#Tue Oct 27 09:15:09 EDT 2009
+eclipse.preferences.version=1
+org.eclipse.jdt.core.builder.cleanOutputFolder=clean
+org.eclipse.jdt.core.builder.duplicateResourceTask=warning
+org.eclipse.jdt.core.builder.invalidClasspath=abort
+org.eclipse.jdt.core.builder.resourceCopyExclusionFilter=*.launch,.svn/
+org.eclipse.jdt.core.circularClasspath=error
+org.eclipse.jdt.core.classpath.exclusionPatterns=enabled
+org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.5
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.doc.comment.support=enabled
+org.eclipse.jdt.core.compiler.maxProblemPerUnit=100
+org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
+org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
+org.eclipse.jdt.core.compiler.problem.deadCode=warning
+org.eclipse.jdt.core.compiler.problem.deprecation=warning
+org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
+org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=enabled
+org.eclipse.jdt.core.compiler.problem.discouragedReference=ignore
+org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.problem.fallthroughCase=warning
+org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled
+org.eclipse.jdt.core.compiler.problem.fieldHiding=warning
+org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
+org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
+org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
+org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
+org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
+org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
+org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning
+org.eclipse.jdt.core.compiler.problem.invalidJavadoc=warning
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsNotVisibleRef=enabled
+org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsVisibility=private
+org.eclipse.jdt.core.compiler.problem.localVariableHiding=warning
+org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
+org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
+org.eclipse.jdt.core.compiler.problem.missingJavadocComments=ignore
+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsOverriding=enabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocCommentsVisibility=public
+org.eclipse.jdt.core.compiler.problem.missingJavadocTags=ignore
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsOverriding=enabled
+org.eclipse.jdt.core.compiler.problem.missingJavadocTagsVisibility=private
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
+org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
+org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
+org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=warning
+org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
+org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
+org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
+org.eclipse.jdt.core.compiler.problem.nullReference=warning
+org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
+org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
+org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=warning
+org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
+org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
+org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
+org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning
+org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
+org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
+org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
+org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=warning
+org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
+org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
+org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
+org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
+org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
+org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=warning
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
+org.eclipse.jdt.core.compiler.problem.unusedImport=error
+org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
+org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
+org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
+org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
+org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
+org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
+org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
+org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
+org.eclipse.jdt.core.compiler.source=1.5
+org.eclipse.jdt.core.incompatibleJDKLevel=ignore
+org.eclipse.jdt.core.incompleteClasspath=error
diff --git a/org.eclipse.jdt.core.tests.model/META-INF/MANIFEST.MF b/org.eclipse.jdt.core.tests.model/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..1a69758
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/META-INF/MANIFEST.MF
@@ -0,0 +1,27 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: %pluginName
+Bundle-SymbolicName: org.eclipse.jdt.core.tests.model; singleton:=true
+Bundle-Version: 3.3.100
+Bundle-ClassPath: jdtcoretestsmodel.jar
+Bundle-Vendor: %providerName
+Bundle-Localization: plugin
+Export-Package: org.eclipse.jdt.core.tests,
+ org.eclipse.jdt.core.tests.dom,
+ org.eclipse.jdt.core.tests.formatter,
+ org.eclipse.jdt.core.tests.formatter.comment,
+ org.eclipse.jdt.core.tests.model,
+ org.eclipse.jdt.core.tests.rewrite.describing,
+ org.eclipse.jdt.core.tests.rewrite.modifying
+Require-Bundle: org.eclipse.core.resources;bundle-version="[3.2.0,4.0.0)",
+ org.eclipse.core.runtime;bundle-version="[3.2.0,4.0.0)",
+ org.eclipse.jdt.core;bundle-version="[3.3.0,4.0.0)",
+ org.junit;bundle-version="3.8.1",
+ org.eclipse.test.performance;bundle-version="[3.1.0,4.0.0)",
+ org.eclipse.jdt.core.tests.compiler;bundle-version="[3.3.0,4.0.0)",
+ org.eclipse.jdt.core.tests.builder;bundle-version="[3.3.0,4.0.0)",
+ org.eclipse.team.core;bundle-version="[3.2.0,4.0.0)",
+ org.eclipse.text;bundle-version="[3.2.0,4.0.0)",
+ com.ibm.icu;bundle-version="[3.4.4,4.3.0)",
+ org.eclipse.core.filesystem;bundle-version="[1.2.0,2.0.0)"
+Bundle-RequiredExecutionEnvironment: J2SE-1.4
diff --git a/org.eclipse.jdt.core.tests.model/about.html b/org.eclipse.jdt.core.tests.model/about.html
new file mode 100644
index 0000000..4602330
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/about.html
@@ -0,0 +1,28 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
+ "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head>
+<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
+<title>About</title>
+</head>
+<body lang="EN-US">
+<h2>About This Content</h2>
+
+<p>June 2, 2006</p>
+<h3>License</h3>
+
+<p>The Eclipse Foundation makes available all content in this plug-in ("Content"). Unless otherwise
+indicated below, the Content is provided to you under the terms and conditions of the
+Eclipse Public License Version 1.0 ("EPL"). A copy of the EPL is available
+at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
+For purposes of the EPL, "Program" will mean the Content.</p>
+
+<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is
+being redistributed by another party ("Redistributor") and different terms and conditions may
+apply to your use of any object code in the Content. Check the Redistributor's license that was
+provided with the Content. If no such license exists, contact the Redistributor. Unless otherwise
+indicated below, the terms and conditions of the EPL still apply to any source code in the Content
+and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p>
+
+</body>
+</html>
\ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/build.properties b/org.eclipse.jdt.core.tests.model/build.properties
new file mode 100644
index 0000000..06adb5c
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/build.properties
@@ -0,0 +1,21 @@
+###############################################################################
+# Copyright (c) 2000, 2009 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
+###############################################################################
+bin.includes = plugin.xml,\
+ plugin.properties,\
+ test.xml,\
+ about.html,\
+ jdtcoretestsmodel.jar,\
+ JCL/,\
+ workspace/,\
+ META-INF/
+src.includes = about.html
+source.jdtcoretestsmodel.jar = src/
+output.jdtcoretestsmodel.jar = bin/
diff --git a/org.eclipse.jdt.core.tests.model/plugin.properties b/org.eclipse.jdt.core.tests.model/plugin.properties
new file mode 100644
index 0000000..5ba1c3b
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/plugin.properties
@@ -0,0 +1,15 @@
+###############################################################################
+# Copyright (c) 2000, 2007 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
+###############################################################################
+providerName=Eclipse.org
+pluginName=Java Model Tests
+
+classpathVariableInitializer.deprecated.0 = Test deprecated flag
+classpathVariableInitializer.deprecated.1 = A deprecated and read-only initializer
\ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/plugin.xml b/org.eclipse.jdt.core.tests.model/plugin.xml
new file mode 100644
index 0000000..380511d
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/plugin.xml
Binary files differ
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunBuilderTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunBuilderTests.java
new file mode 100644
index 0000000..8d5d195
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunBuilderTests.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2006 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;
+
+import org.eclipse.jdt.core.tests.builder.BuilderTests;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Runs all Java builder tests.
+ */
+public class RunBuilderTests extends TestCase {
+public RunBuilderTests(String name) {
+ super(name);
+}
+public static Test suite() {
+ TestSuite suite = new TestSuite(RunBuilderTests.class.getName());
+ suite.addTest(BuilderTests.suite());
+ return suite;
+}
+}
+
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunCompilerTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunCompilerTests.java
new file mode 100644
index 0000000..ca47771
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunCompilerTests.java
@@ -0,0 +1,60 @@
+/*******************************************************************************
+ * Copyright (c) 2005 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;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Runs all compiler tests (including parser tests and evaluation tests) in all compliance mode.
+ * Use -Dcompliance=1.4 as a VM argument if you want to run in 1.4 compliance mode only.
+ * See AbstractCompilerTests for more details.
+ */
+public class RunCompilerTests extends TestCase {
+
+public RunCompilerTests(String name) {
+ super(name);
+}
+public static Class[] getAllTestClasses() {
+ return new Class[] {
+ org.eclipse.jdt.core.tests.compiler.regression.TestAll.class,
+ org.eclipse.jdt.core.tests.compiler.parser.TestAll.class,
+ org.eclipse.jdt.core.tests.eval.TestAll.class,
+ };
+}
+public static Test suite() {
+ TestSuite ts = new TestSuite(RunCompilerTests.class.getName());
+
+ Class[] testClasses = getAllTestClasses();
+ for (int i = 0; i < testClasses.length; i++) {
+ Class testClass = testClasses[i];
+
+ // call the suite() method and add the resulting suite to the suite
+ try {
+ Method suiteMethod = testClass.getDeclaredMethod("suite", new Class[0]); //$NON-NLS-1$
+ Test suite = (Test)suiteMethod.invoke(null, new Object[0]);
+ ts.addTest(suite);
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ e.getTargetException().printStackTrace();
+ } catch (NoSuchMethodException e) {
+ e.printStackTrace();
+ }
+ }
+ return ts;
+}
+}
+
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunDOMTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunDOMTests.java
new file mode 100644
index 0000000..2079723
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunDOMTests.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2005 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;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.jdt.core.tests.dom.RunAllTests;
+
+/**
+ * Runs all DOM AST tests.
+ */
+public class RunDOMTests extends TestCase {
+
+public RunDOMTests(String name) {
+ super(name);
+}
+public static Test suite() {
+ TestSuite suite = new TestSuite(RunDOMTests.class.getName());
+ suite.addTest(RunAllTests.suite());
+ return suite;
+}
+}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunFormatterTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunFormatterTests.java
new file mode 100644
index 0000000..da72556
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunFormatterTests.java
@@ -0,0 +1,90 @@
+/*******************************************************************************
+ * Copyright (c) 2005, 2009 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;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.jdt.core.tests.formatter.*;
+import org.eclipse.jdt.core.tests.formatter.comment.CommentsTestSuite;
+import org.eclipse.jdt.core.tests.junit.extension.TestCase;
+
+/**
+ * Runs all formatter tests.
+ */
+public class RunFormatterTests extends junit.framework.TestCase {
+
+ public final static List TEST_SUITES = new ArrayList();
+ static {
+ TEST_SUITES.add(FormatterCommentsBugsTest.class);
+ TEST_SUITES.add(FormatterCommentsTests.class);
+ TEST_SUITES.add(FormatterCommentsClearBlankLinesTests.class);
+ TEST_SUITES.add(FormatterJavadocDontIndentTagsTests.class);
+ TEST_SUITES.add(FormatterJavadocDontIndentTagsDescriptionTests.class);
+ }
+
+ public static Class[] getTestClasses() {
+ return (Class[]) TEST_SUITES.toArray();
+ }
+
+ public static Test suite() {
+ TestSuite ts = new TestSuite(RunFormatterTests.class.getName());
+
+ // Store test classes with same "JavaSearch"project
+ FormatterCommentsTests.ALL_TEST_SUITES = new ArrayList(TEST_SUITES);
+
+ // Get all classes
+ List allClasses = new ArrayList();
+ String type = System.getProperty("type");
+ if (type == null || !type.equals("javadoc")) {
+ allClasses.add(FormatterRegressionTests.class);
+ allClasses.add(FormatterBugsTests.class);
+ }
+ allClasses.add(CommentsTestSuite.class);
+ allClasses.addAll(TEST_SUITES);
+
+ // Reset forgotten subsets of tests
+ TestCase.TESTS_PREFIX = null;
+ TestCase.TESTS_NAMES = null;
+ TestCase.TESTS_NUMBERS = null;
+ TestCase.TESTS_RANGE = null;
+ TestCase.RUN_ONLY_ID = null;
+
+ // Add all tests suite of tests
+ for (int i = 0, size = allClasses.size(); i < size; i++) {
+ Class testClass = (Class) allClasses.get(i);
+
+ // call the suite() method and add the resulting suite to the suite
+ try {
+ Method suiteMethod = testClass.getDeclaredMethod("suite", new Class[0]); //$NON-NLS-1$
+ Test suite = (Test)suiteMethod.invoke(null, new Object[0]);
+ ts.addTest(suite);
+ } catch (IllegalAccessException e) {
+ e.printStackTrace();
+ } catch (InvocationTargetException e) {
+ e.getTargetException().printStackTrace();
+ } catch (NoSuchMethodException e) {
+ e.printStackTrace();
+ }
+ }
+ return ts;
+ }
+
+public RunFormatterTests(String name) {
+ super(name);
+}
+}
+
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunJDTCoreTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunJDTCoreTests.java
new file mode 100644
index 0000000..72d38d8
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunJDTCoreTests.java
@@ -0,0 +1,34 @@
+/*******************************************************************************
+ * Copyright (c) 2005 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;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Runs all JDT Core tests.
+ */
+public class RunJDTCoreTests extends TestCase {
+public RunJDTCoreTests(String name) {
+ super(name);
+}
+public static Test suite() {
+ TestSuite suite = new TestSuite(RunJDTCoreTests.class.getName());
+ suite.addTest(RunBuilderTests.suite());
+ suite.addTest(RunCompilerTests.suite());
+ suite.addTest(RunDOMTests.suite());
+ suite.addTest(RunFormatterTests.suite());
+ suite.addTest(RunModelTests.suite());
+ return suite;
+}
+}
+
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunModelTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunModelTests.java
new file mode 100644
index 0000000..af5dda7
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/RunModelTests.java
@@ -0,0 +1,32 @@
+/*******************************************************************************
+ * Copyright (c) 2005 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;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.eclipse.jdt.core.tests.model.AllJavaModelTests;
+
+/**
+ * Runs all Java model tests.
+ */
+public class RunModelTests extends TestCase {
+public RunModelTests(String name) {
+ super(name);
+}
+public static Test suite() {
+ TestSuite suite = new TestSuite(RunModelTests.class.getName());
+ suite.addTest(AllJavaModelTests.suite());
+ return suite;
+}
+}
+
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/APIDocumentationTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/APIDocumentationTests.java
new file mode 100644
index 0000000..cfc5de4
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/APIDocumentationTests.java
@@ -0,0 +1,236 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.dom;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import java.lang.reflect.Field;
+import java.lang.reflect.Modifier;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Map;
+
+import junit.framework.Test;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.jdt.core.JavaCore;
+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.ASTVisitor;
+import org.eclipse.jdt.core.dom.FieldDeclaration;
+import org.eclipse.jdt.core.dom.Javadoc;
+import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+
+/**
+ * The intent of this tests series is to check the consistency of parts of our
+ * APIs documentation with real values and results.
+ */
+public class APIDocumentationTests extends AbstractASTTests {
+ public APIDocumentationTests(String name) {
+ super(name);
+ }
+
+ public static Test suite() {
+ return buildModelTestSuite(APIDocumentationTests.class);
+ }
+
+ // Use this static initializer to specify subset for tests
+ // 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_RANGE = new int[] { 83304, -1 };
+ }
+
+/**
+ * Helper class able to analyze JavaCore options javadocs.
+ */
+class JavaCoreJavadocAnalyzer {
+ private String javadoc;
+ void reset(String newJavadoc) {
+ // do not pass null - unchecked
+ this.javadoc = newJavadoc;
+ this.analyzed = false;
+ this.optionID = null;
+ this.defaultValue = null;
+ }
+ private boolean analyzed;
+ private String optionID, defaultValue;
+ private void analyze() {
+ if (!this.analyzed) {
+ this.analyzed = true;
+ BufferedReader javadocReader = new BufferedReader(new StringReader(this.javadoc));
+ String line;
+ try {
+ while ((line = javadocReader.readLine()) != null) {
+ if (line.startsWith(" * <dt>Option id:")) {
+ this.optionID = line.substring(33, line.length() - 13);
+ } else if (line.startsWith(" * <dt>Default:")) {
+ this.defaultValue = line.substring(31, line.length() - 13);
+ return;
+ }
+ }
+ } catch (IOException e) {
+ // silent
+ }
+ }
+ }
+ String getOptionID() {
+ analyze();
+ return this.optionID;
+ }
+ String getDefaultValue() {
+ analyze();
+ return this.defaultValue;
+ }
+ boolean isDeprecated() {
+ return this.javadoc.indexOf("* @deprecated") != -1;
+ }
+}
+// https://bugs.eclipse.org/bugs/show_bug.cgi?id=202490
+// checks that option ids and option default values match between the code and
+// the javadoc
+// TODO maxime: reactivate in early 3.4 M6 and refine for remote execution
+public void test001() throws CoreException, IllegalArgumentException, IllegalAccessException, IOException {
+ // fetch JavaCore class
+ Class javaCoreClass = JavaCore.class;
+ // fetch JavaCore source file
+ File javaCoreSourceFile = new File(FileLocator.toFileURL(JavaCore.getJavaCore().getBundle().getEntry("/model/org/eclipse/jdt/core/JavaCore.java")).getPath());
+ if (javaCoreSourceFile.exists()) {
+ // load field values in a map
+ Hashtable realOptionIDs = new Hashtable();
+ Field[] fields = javaCoreClass.getDeclaredFields();
+ for (int i = 0, l = fields.length; i < l; i++) {
+ Field field = fields[i];
+ int modifiers = field.getModifiers();
+ if (Modifier.isPublic(modifiers) &&
+ Modifier.isStatic(modifiers) &&
+ field.getType() == String.class) {
+ String constantValue = (String) field.get(null);
+ if (constantValue.startsWith(JavaCore.PLUGIN_ID)) {
+ realOptionIDs.put(field.getName(), constantValue);
+ }
+ }
+ }
+ // exempt a few values
+ realOptionIDs.remove("PLUGIN_ID");
+ realOptionIDs.remove("BUILDER_ID");
+ realOptionIDs.remove("JAVA_SOURCE_CONTENT_TYPE");
+ realOptionIDs.remove("MODEL_ID");
+ realOptionIDs.remove("NATURE_ID");
+ // build cross-index
+ Hashtable realOptionNames = new Hashtable();
+ Iterator optionIDs = realOptionIDs.entrySet().iterator();
+ while (optionIDs.hasNext()) {
+ Map.Entry optionID = (Map.Entry) optionIDs.next();
+ realOptionNames.put(optionID.getValue(), optionID.getKey());
+ }
+
+ // fetch default option values
+ Hashtable realDefaultValues = JavaCore.getDefaultOptions();
+ // load documented values in a map
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setSource(org.eclipse.jdt.internal.compiler.util.Util.getFileCharContent(javaCoreSourceFile, null));
+ ASTNode rootNode = parser.createAST(null);
+ final JavaCoreJavadocAnalyzer analyzer = new JavaCoreJavadocAnalyzer();
+ final Hashtable javadocOptionIDs = new Hashtable();
+ final Hashtable javadocDefaultValues = new Hashtable();
+ final Hashtable deprecatedFields = new Hashtable();
+ rootNode.accept(new ASTVisitor() {
+ public boolean visit(FieldDeclaration node) {
+ String key = ((VariableDeclarationFragment) node.fragments().get(0)).getName().getIdentifier();
+ Javadoc javadoc = node.getJavadoc();
+ if (javadoc != null) {
+ analyzer.reset(javadoc.toString());
+ String id, value;
+ if ((id = analyzer.getOptionID()) != null) {
+ javadocOptionIDs.put(key, id);
+ }
+ if ((value = analyzer.getDefaultValue()) != null) {
+ javadocDefaultValues.put(id, value);
+ }
+ if (analyzer.isDeprecated()) {
+ deprecatedFields.put(key, key /* not null */);
+ }
+ }
+ return super.visit(node);
+ }
+ });
+ // checking ids
+ Iterator check = realOptionIDs.entrySet().iterator();
+ String key, value;
+ String expected = "", actual = "";
+ while (check.hasNext()) {
+ Map.Entry entry = (Map.Entry) check.next();
+ key = (String) entry.getKey();
+ value = (String) entry.getValue();
+ if (deprecatedFields.get(key) == null) {
+ if (!value.equals(javadocOptionIDs.get(key))) {
+ expected = value;
+ actual = (String) javadocOptionIDs.get(key);
+ System.out.println("option ID mismatch for " + key + ", real: " + expected +
+ ", javadoc: " + actual);
+ }
+ }
+ }
+ check = javadocOptionIDs.entrySet().iterator();
+ while (check.hasNext()) {
+ Map.Entry entry = (Map.Entry) check.next();
+ key = (String) entry.getKey();
+ value = (String) entry.getValue();
+ if (!value.equals(realOptionIDs.get(key))) {
+ expected = value;
+ actual = (String) realOptionIDs.get(key);
+ System.out.println("option ID mismatch, javadoc " + expected +
+ ", real " + actual);
+ }
+ }
+ // checking default values
+ check = realDefaultValues.entrySet().iterator();
+ while (check.hasNext()) {
+ Map.Entry entry = (Map.Entry) check.next();
+ key = (String) entry.getKey();
+ value = (String) entry.getValue();
+ String name = (String) realOptionNames.get(key);
+ if (name != null && deprecatedFields.get(name) == null) {
+ if (!value.equals(javadocDefaultValues.get(key)) &&
+ !"org.eclipse.jdt.core.encoding".equals(key)) {
+ expected = value;
+ actual = (String) javadocDefaultValues.get(key);
+ System.out.println("default value mismatch for " + key + ", real: " + expected +
+ ", javadoc: " + actual);
+ }
+ }
+ }
+ check = javadocDefaultValues.entrySet().iterator();
+ while (check.hasNext()) {
+ Map.Entry entry = (Map.Entry) check.next();
+ key = (String) entry.getKey();
+ value = (String) entry.getValue();
+ if (!value.equals(realDefaultValues.get(key)) &&
+ !"org.eclipse.jdt.core.compiler.problem.booleanMethodThrowingException".equals(key)) { // will remove once bug 216571 is fixed
+ expected = value;
+ actual = (String) realDefaultValues.get(key);
+ System.out.println("default value mismatch for " + key + ", javadoc " + expected +
+ ", real " + actual);
+ }
+ }
+ assertEquals("One or many discrepancies, including: ", expected, actual);
+ } else {
+ System.err.println("JavaCore.java not found, skipping APIDocumentationTests#test001");
+ }
+}
+}
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
new file mode 100644
index 0000000..45021b9
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter15Test.java
@@ -0,0 +1,10918 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2009 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.dom;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.Test;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.BindingKey;
+import org.eclipse.jdt.core.IAnnotation;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.Signature;
+import org.eclipse.jdt.core.dom.*;
+import org.eclipse.jdt.core.tests.util.Util;
+
+public class ASTConverter15Test extends ConverterTestSetup {
+
+ ICompilationUnit workingCopy;
+
+ public void setUpSuite() throws Exception {
+ super.setUpSuite();
+ this.ast = AST.newAST(AST.JLS3);
+ }
+
+ public ASTConverter15Test(String name) {
+ super(name);
+ }
+
+ static {
+// TESTS_NUMBERS = new int[] { 340 };
+// TESTS_RANGE = new int[] { 325, -1 };
+// TESTS_NAMES = new String[] {"test0204"};
+ }
+ public static Test suite() {
+ return buildModelTestSuite(ASTConverter15Test.class);
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ if (this.workingCopy != null) {
+ this.workingCopy.discardWorkingCopy();
+ this.workingCopy = null;
+ }
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=234609 BindingKey#toSignature() fails with key from createWilcardTypeBindingKey(..)
+ public void test234609() throws JavaModelException {
+
+ String newContents = "package p;\n" +
+ "import java.util.HashMap;\n" +
+ "public class X {\n" +
+ " /*start*/HashMap<? extends Integer,? super String>/*end*/ s;" +
+ "}";
+
+ this.workingCopy = getWorkingCopy("/Converter15/src/p/X.java", true/*resolve*/);
+
+ Type node = (Type) buildAST(
+ newContents,
+ this.workingCopy);
+
+ ITypeBinding bindingFromAST = node.resolveBinding();
+ String recoveredBindingKey = bindingFromAST.getKey();
+
+ String genericTypeKey = BindingKey.createTypeBindingKey("java.util.HashMap");
+ String [] wildcardKeys = new String [] { BindingKey.createWildcardTypeBindingKey(genericTypeKey, Signature.C_EXTENDS, BindingKey.createTypeBindingKey("java.lang.Integer"), 0),
+ BindingKey.createWildcardTypeBindingKey(genericTypeKey, Signature.C_SUPER, BindingKey.createTypeBindingKey("java.lang.String"), 1)
+ };
+
+ String composedBindingKey = BindingKey.createParameterizedTypeBindingKey(genericTypeKey, wildcardKeys);
+
+ if (!composedBindingKey.equals(recoveredBindingKey))
+ fail("Composed binding key differs from Recovered binding key");
+
+
+ this.workingCopy.discardWorkingCopy();
+ this.workingCopy = null;
+
+ ITypeBinding [] bindingFromKey = createTypeBindings(
+ new String[] {
+ "/Converter15/src/p/X.java",
+ newContents
+ },
+ new String[] {
+ composedBindingKey
+ },
+ getJavaProject("Converter15")
+ );
+
+ if (bindingFromKey.length != 1)
+ fail("Problem in going from key to binding\n");
+ if (!composedBindingKey.equals(bindingFromKey[0].getKey()))
+ fail ("Binding key mismatch");
+ String signature = new BindingKey(composedBindingKey).toSignature();
+ if (!signature.equals("Ljava.util.HashMap<+Ljava.lang.Integer;-Ljava.lang.String;>;"))
+ fail("Bad signature");
+
+ assertTrue("Equals", bindingFromKey[0].isEqualTo(bindingFromAST));
+
+ // check existence of getGenericType() API.
+ ITypeBinding gType = bindingFromAST.getTypeArguments()[0].getGenericTypeOfWildcardType();
+ if (gType == null)
+ fail("Missing generic type");
+ if (!gType.getKey().equals("Ljava/util/HashMap<TK;TV;>;"))
+ fail("getKey() API is broken");
+
+ // test for getRank API.
+ if (bindingFromAST.getTypeArguments()[0].getRank() != 0)
+ fail ("Wrong rank");
+
+ if (bindingFromAST.getTypeArguments()[1].getRank() != 1)
+ fail ("Wrong rank");
+ }
+
+ // Similar test as above - variation in wildcard type being unbounded.
+ public void test234609b() throws JavaModelException {
+
+ String newContents = "package p;\n" +
+ "import java.util.ArrayList;\n" +
+ "public class X {\n" +
+ " /*start*/ArrayList<?>/*end*/ s;" +
+ "}";
+
+ this.workingCopy = getWorkingCopy("/Converter15/src/p/X.java", true/*resolve*/);
+
+ Type node = (Type) buildAST(
+ newContents,
+ this.workingCopy);
+
+ ITypeBinding bindingFromAST = node.resolveBinding();
+ String recoveredBindingKey = bindingFromAST.getKey();
+
+ String genericTypeKey = BindingKey.createTypeBindingKey("java.util.ArrayList");
+ String [] wildcardKeys = new String [] { BindingKey.createWildcardTypeBindingKey(genericTypeKey, Signature.C_STAR, null, 0) };
+
+ String composedBindingKey = BindingKey.createParameterizedTypeBindingKey(genericTypeKey, wildcardKeys);
+
+ if (!composedBindingKey.equals(recoveredBindingKey))
+ fail("Composed binding key differs from Recovered binding key");
+
+
+ this.workingCopy.discardWorkingCopy();
+ this.workingCopy = null;
+
+ ITypeBinding [] bindingFromKey = createTypeBindings(
+ new String[] {
+ "/Converter15/src/p/X.java",
+ newContents
+ },
+ new String[] {
+ composedBindingKey
+ },
+ getJavaProject("Converter15")
+ );
+
+ if (bindingFromKey.length != 1)
+ fail("Problem in going from key to binding\n");
+ if (!composedBindingKey.equals(bindingFromKey[0].getKey()))
+ fail ("Binding key mismatch");
+ String signature = new BindingKey(composedBindingKey).toSignature();
+ if (!signature.equals("Ljava.util.ArrayList<*>;"))
+ fail("Bad signature");
+ assertTrue("Equals", bindingFromKey[0].isEqualTo(bindingFromAST));
+ }
+
+ public void test0001() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0001", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ List types = compilationUnit.types();
+ assertEquals("Wrong number of types", 1, types.size());
+ AbstractTypeDeclaration typeDeclaration = (AbstractTypeDeclaration) types.get(0);
+ assertEquals("wrong type", ASTNode.TYPE_DECLARATION, typeDeclaration.getNodeType());
+ TypeDeclaration typeDeclaration2 = (TypeDeclaration) typeDeclaration;
+ List modifiers = typeDeclaration2.modifiers();
+ assertEquals("Wrong number of modifiers", 1, modifiers.size());
+ Modifier modifier = (Modifier) modifiers.get(0);
+ checkSourceRange(modifier, "public", source);
+
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Wrong type", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ modifiers = fieldDeclaration.modifiers();
+ assertEquals("Wrong number of modifiers", 3, modifiers.size());
+ modifier = (Modifier) modifiers.get(0);
+ checkSourceRange(modifier, "public", source);
+ modifier = (Modifier) modifiers.get(1);
+ checkSourceRange(modifier, "static", source);
+ modifier = (Modifier) modifiers.get(2);
+ checkSourceRange(modifier, "final", source);
+
+ node = getASTNode(compilationUnit, 0, 1);
+ assertEquals("Wrong type", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ modifiers = methodDeclaration.modifiers();
+ assertEquals("Wrong number of modifiers", 2, modifiers.size());
+ modifier = (Modifier) modifiers.get(0);
+ checkSourceRange(modifier, "private", source);
+ modifier = (Modifier) modifiers.get(1);
+ checkSourceRange(modifier, "static", source);
+ List parameters = methodDeclaration.parameters();
+ assertEquals("Wrong number of parameters", 1, parameters.size());
+ SingleVariableDeclaration variableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ modifiers = variableDeclaration.modifiers();
+ assertEquals("Wrong number of modifiers", 1, modifiers.size());
+ modifier = (Modifier) modifiers.get(0);
+ checkSourceRange(modifier, "final", source);
+
+ node = getASTNode(compilationUnit, 0, 2);
+ assertEquals("Wrong type", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ methodDeclaration = (MethodDeclaration) node;
+ modifiers = methodDeclaration.modifiers();
+ assertEquals("Wrong number of modifiers", 2, modifiers.size());
+ modifier = (Modifier) modifiers.get(0);
+ checkSourceRange(modifier, "public", source);
+ modifier = (Modifier) modifiers.get(1);
+ checkSourceRange(modifier, "static", source);
+ }
+
+ public void test0002() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0002", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ }
+
+ public void test0003() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0003", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ List types = compilationUnit.types();
+ assertEquals("Wrong number of types", 3, types.size());
+ AbstractTypeDeclaration typeDeclaration = (AbstractTypeDeclaration) types.get(2);
+ assertEquals("wrong type", ASTNode.TYPE_DECLARATION, typeDeclaration.getNodeType());
+ TypeDeclaration typeDeclaration2 = (TypeDeclaration) typeDeclaration;
+ List modifiers = typeDeclaration2.modifiers();
+ assertEquals("Wrong number of modifiers", 2, modifiers.size());
+ ASTNode modifier = (ASTNode) modifiers.get(0);
+ checkSourceRange(modifier, "@Author(@Name(first=\"Joe\", last=\"Hacker\"))", source);
+ assertEquals("wrong type", ASTNode.SINGLE_MEMBER_ANNOTATION, modifier.getNodeType());
+ SingleMemberAnnotation annotation = (SingleMemberAnnotation) modifier;
+ checkSourceRange(annotation.getTypeName(), "Author", source);
+ Expression value = annotation.getValue();
+ assertEquals("wrong type", ASTNode.NORMAL_ANNOTATION, value.getNodeType());
+ NormalAnnotation normalAnnotation = (NormalAnnotation) value;
+ checkSourceRange(normalAnnotation.getTypeName(), "Name", source);
+ List values = normalAnnotation.values();
+ assertEquals("wrong size", 2, values.size());
+ MemberValuePair memberValuePair = (MemberValuePair) values.get(0);
+ checkSourceRange(memberValuePair, "first=\"Joe\"", source);
+ checkSourceRange(memberValuePair.getName(), "first", source);
+ checkSourceRange(memberValuePair.getValue(), "\"Joe\"", source);
+ memberValuePair = (MemberValuePair) values.get(1);
+ checkSourceRange(memberValuePair, "last=\"Hacker\"", source);
+ checkSourceRange(memberValuePair.getName(), "last", source);
+ checkSourceRange(memberValuePair.getValue(), "\"Hacker\"", source);
+ modifier = (ASTNode) modifiers.get(1);
+ checkSourceRange(modifier, "public", source);
+ }
+
+ public void test0004() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0004", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ List types = compilationUnit.types();
+ assertEquals("Wrong number of types", 3, types.size());
+ AbstractTypeDeclaration typeDeclaration = (AbstractTypeDeclaration) types.get(2);
+ assertEquals("wrong type", ASTNode.TYPE_DECLARATION, typeDeclaration.getNodeType());
+ TypeDeclaration typeDeclaration2 = (TypeDeclaration) typeDeclaration;
+ List modifiers = typeDeclaration2.modifiers();
+ assertEquals("Wrong number of modifiers", 2, modifiers.size());
+ ASTNode modifier = (ASTNode) modifiers.get(1);
+ checkSourceRange(modifier, "@Author(@Name(first=\"Joe\", last=\"Hacker\"))", source);
+ assertEquals("wrong type", ASTNode.SINGLE_MEMBER_ANNOTATION, modifier.getNodeType());
+ SingleMemberAnnotation annotation = (SingleMemberAnnotation) modifier;
+ checkSourceRange(annotation.getTypeName(), "Author", source);
+ Expression value = annotation.getValue();
+ assertEquals("wrong type", ASTNode.NORMAL_ANNOTATION, value.getNodeType());
+ NormalAnnotation normalAnnotation = (NormalAnnotation) value;
+ checkSourceRange(normalAnnotation.getTypeName(), "Name", source);
+ List values = normalAnnotation.values();
+ assertEquals("wrong size", 2, values.size());
+ MemberValuePair memberValuePair = (MemberValuePair) values.get(0);
+ checkSourceRange(memberValuePair, "first=\"Joe\"", source);
+ checkSourceRange(memberValuePair.getName(), "first", source);
+ checkSourceRange(memberValuePair.getValue(), "\"Joe\"", source);
+ memberValuePair = (MemberValuePair) values.get(1);
+ checkSourceRange(memberValuePair, "last=\"Hacker\"", source);
+ checkSourceRange(memberValuePair.getName(), "last", source);
+ checkSourceRange(memberValuePair.getValue(), "\"Hacker\"", source);
+ modifier = (ASTNode) modifiers.get(0);
+ checkSourceRange(modifier, "public", source);
+ }
+
+ public void test0005() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0005", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ List types = compilationUnit.types();
+ assertEquals("Wrong number of types", 4, types.size());
+ AbstractTypeDeclaration typeDeclaration = (AbstractTypeDeclaration) types.get(3);
+ assertEquals("wrong type", ASTNode.TYPE_DECLARATION, typeDeclaration.getNodeType());
+ TypeDeclaration typeDeclaration2 = (TypeDeclaration) typeDeclaration;
+ List modifiers = typeDeclaration2.modifiers();
+ assertEquals("Wrong number of modifiers", 3, modifiers.size());
+ ASTNode modifier = (ASTNode) modifiers.get(0);
+ checkSourceRange(modifier, "@Retention", source);
+ assertEquals("wrong type", ASTNode.MARKER_ANNOTATION, modifier.getNodeType());
+ MarkerAnnotation markerAnnotation = (MarkerAnnotation) modifier;
+ checkSourceRange(markerAnnotation.getTypeName(), "Retention", source);
+ modifier = (ASTNode) modifiers.get(2);
+ checkSourceRange(modifier, "@Author(@Name(first=\"Joe\", last=\"Hacker\", age=32))", source);
+ assertEquals("wrong type", ASTNode.SINGLE_MEMBER_ANNOTATION, modifier.getNodeType());
+ SingleMemberAnnotation annotation = (SingleMemberAnnotation) modifier;
+ checkSourceRange(annotation.getTypeName(), "Author", source);
+ Expression value = annotation.getValue();
+ assertEquals("wrong type", ASTNode.NORMAL_ANNOTATION, value.getNodeType());
+ NormalAnnotation normalAnnotation = (NormalAnnotation) value;
+ checkSourceRange(normalAnnotation.getTypeName(), "Name", source);
+ List values = normalAnnotation.values();
+ assertEquals("wrong size", 3, values.size());
+ MemberValuePair memberValuePair = (MemberValuePair) values.get(0);
+ checkSourceRange(memberValuePair, "first=\"Joe\"", source);
+ checkSourceRange(memberValuePair.getName(), "first", source);
+ checkSourceRange(memberValuePair.getValue(), "\"Joe\"", source);
+ memberValuePair = (MemberValuePair) values.get(1);
+ checkSourceRange(memberValuePair, "last=\"Hacker\"", source);
+ checkSourceRange(memberValuePair.getName(), "last", source);
+ checkSourceRange(memberValuePair.getValue(), "\"Hacker\"", source);
+ memberValuePair = (MemberValuePair) values.get(2);
+ checkSourceRange(memberValuePair, "age=32", source);
+ checkSourceRange(memberValuePair.getName(), "age", source);
+ checkSourceRange(memberValuePair.getValue(), "32", source);
+ modifier = (ASTNode) modifiers.get(1);
+ checkSourceRange(modifier, "public", source);
+
+ typeDeclaration = (AbstractTypeDeclaration) types.get(0);
+ assertEquals("wrong type", ASTNode.ANNOTATION_TYPE_DECLARATION, typeDeclaration.getNodeType());
+ AnnotationTypeDeclaration annotationTypeDeclaration = (AnnotationTypeDeclaration) typeDeclaration;
+ List bodyDeclarations = annotationTypeDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 3, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertEquals("wrong type", ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION, bodyDeclaration.getNodeType());
+ AnnotationTypeMemberDeclaration annotationTypeMemberDeclaration = (AnnotationTypeMemberDeclaration) bodyDeclaration;
+ IMethodBinding methodBinding = annotationTypeMemberDeclaration.resolveBinding();
+ assertNotNull("No binding", methodBinding);
+ checkSourceRange(annotationTypeMemberDeclaration, "String first() default \"Joe\";", source);
+ Expression expression = annotationTypeMemberDeclaration.getDefault();
+ checkSourceRange(expression, "\"Joe\"", source);
+ bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(2);
+ assertEquals("wrong type", ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION, bodyDeclaration.getNodeType());
+ annotationTypeMemberDeclaration = (AnnotationTypeMemberDeclaration) bodyDeclaration;
+ checkSourceRange(annotationTypeMemberDeclaration, "int age();", source);
+ expression = annotationTypeMemberDeclaration.getDefault();
+ assertNull("Got a default", expression);
+ }
+
+ public void test0006() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0006", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ final String expectedOutput = "Package annotations must be in file package-info.java";
+ assertProblemsSize(compilationUnit, 1, expectedOutput);
+ PackageDeclaration packageDeclaration = compilationUnit.getPackage();
+ assertNotNull("No package declaration", packageDeclaration);
+ checkSourceRange(packageDeclaration, "@Retention package test0006;", source);
+ List annotations = packageDeclaration.annotations();
+ assertEquals("Wrong size", 1, annotations.size());
+ Annotation annotation = (Annotation) annotations.get(0);
+ checkSourceRange(annotation, "@Retention", source);
+ assertEquals("Not a marker annotation", annotation.getNodeType(), ASTNode.MARKER_ANNOTATION);
+ MarkerAnnotation markerAnnotation = (MarkerAnnotation) annotation;
+ checkSourceRange(markerAnnotation.getTypeName(), "Retention", source);
+ }
+
+ public void test0007() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0007", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ List imports = compilationUnit.imports();
+ assertEquals("Wrong size", 2, imports.size());
+ ImportDeclaration importDeclaration = (ImportDeclaration) imports.get(0);
+ checkSourceRange(importDeclaration, "import java.util.*;", source);
+ assertFalse("is static", importDeclaration.isStatic());
+ importDeclaration = (ImportDeclaration) imports.get(1);
+ checkSourceRange(importDeclaration, "import static java.io.File.*;", source);
+ assertTrue("not static", importDeclaration.isStatic());
+ }
+
+ /** @deprecated using deprecated code */
+ public void test0008() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0008", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS2, sourceUnit, true);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ List imports = compilationUnit.imports();
+ assertEquals("Wrong size", 2, imports.size());
+ ImportDeclaration importDeclaration = (ImportDeclaration) imports.get(1);
+ assertTrue("Not malformed", isMalformed(importDeclaration));
+ }
+
+ public void test0009() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0009", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ char[] source = sourceUnit.getSource().toCharArray();
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a foreach statement", node.getNodeType() == ASTNode.ENHANCED_FOR_STATEMENT);
+ EnhancedForStatement enhancedForStatement = (EnhancedForStatement) node;
+ checkSourceRange(enhancedForStatement, "for (String s : args) {System.out.println(s);}", source);
+ SingleVariableDeclaration singleVariableDeclaration = enhancedForStatement.getParameter();
+ checkSourceRange(singleVariableDeclaration, "String s", source);
+ Type type = singleVariableDeclaration.getType();
+ checkSourceRange(type, "String", source);
+ SimpleName simpleName = singleVariableDeclaration.getName();
+ assertEquals("Wrong name", "s", simpleName.getIdentifier());
+ checkSourceRange(simpleName, "s", source);
+ Expression expression = enhancedForStatement.getExpression();
+ checkSourceRange(expression, "args", source);
+ Statement body = enhancedForStatement.getBody();
+ checkSourceRange(body, "{System.out.println(s);}", source);
+ }
+
+ public void test0010() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0010", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ char[] source = sourceUnit.getSource().toCharArray();
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 1, 0, 0);
+ assertTrue("Not a foreach statement", node.getNodeType() == ASTNode.ENHANCED_FOR_STATEMENT);
+ EnhancedForStatement enhancedForStatement = (EnhancedForStatement) node;
+ checkSourceRange(enhancedForStatement, "for (@Foo final String s : args) {System.out.println(s);}", source);
+ SingleVariableDeclaration singleVariableDeclaration = enhancedForStatement.getParameter();
+ checkSourceRange(singleVariableDeclaration, "@Foo final String s", source);
+ SimpleName simpleName = singleVariableDeclaration.getName();
+ List modifiers = singleVariableDeclaration.modifiers();
+ assertEquals("Wrong number of modifiers", 2, modifiers.size());
+ IExtendedModifier modifier = (IExtendedModifier) modifiers.get(0);
+ checkSourceRange((ASTNode) modifier, "@Foo", source);
+ modifier = (IExtendedModifier) modifiers.get(1);
+ checkSourceRange((ASTNode) modifier, "final", source);
+ Type type = singleVariableDeclaration.getType();
+ checkSourceRange(type, "String", source);
+ assertEquals("Wrong name", "s", simpleName.getIdentifier());
+ checkSourceRange(simpleName, "s", source);
+ Expression expression = enhancedForStatement.getExpression();
+ checkSourceRange(expression, "args", source);
+ Statement body = enhancedForStatement.getBody();
+ checkSourceRange(body, "{System.out.println(s);}", source);
+ }
+
+ public void test0011() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0011", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ char[] source = sourceUnit.getSource().toCharArray();
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 1, 0, 0);
+ assertTrue("Not a foreach statement", node.getNodeType() == ASTNode.ENHANCED_FOR_STATEMENT);
+ EnhancedForStatement enhancedForStatement = (EnhancedForStatement) node;
+ checkSourceRange(enhancedForStatement, "for (@Foo final String s[] : args) {System.out.println(s);}", source);
+ SingleVariableDeclaration singleVariableDeclaration = enhancedForStatement.getParameter();
+ checkSourceRange(singleVariableDeclaration, "@Foo final String s[]", source);
+ SimpleName simpleName = singleVariableDeclaration.getName();
+ List modifiers = singleVariableDeclaration.modifiers();
+ assertEquals("Wrong number of modifiers", 2, modifiers.size());
+ IExtendedModifier modifier = (IExtendedModifier) modifiers.get(0);
+ checkSourceRange((ASTNode) modifier, "@Foo", source);
+ modifier = (IExtendedModifier) modifiers.get(1);
+ checkSourceRange((ASTNode) modifier, "final", source);
+ assertEquals("Wrong dimension", 1, singleVariableDeclaration.getExtraDimensions());
+ Type type = singleVariableDeclaration.getType();
+ checkSourceRange(type, "String", source);
+ assertEquals("Wrong name", "s", simpleName.getIdentifier());
+ checkSourceRange(simpleName, "s", source);
+ Expression expression = enhancedForStatement.getExpression();
+ checkSourceRange(expression, "args", source);
+ Statement body = enhancedForStatement.getBody();
+ checkSourceRange(body, "{System.out.println(s);}", source);
+ }
+
+ public void test0012() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0012", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ char[] source = sourceUnit.getSource().toCharArray();
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 1, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION);
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ assertEquals("wrong size", 1, parameters.size());
+ SingleVariableDeclaration parameter = (SingleVariableDeclaration) parameters.get(0);
+ checkSourceRange(parameter, "@Foo final String[][]... args", source);
+ List modifiers = parameter.modifiers();
+ assertEquals("Wrong number of modifiers", 2, modifiers.size());
+ ASTNode modifier = (ASTNode) modifiers.get(0);
+ checkSourceRange(modifier, "@Foo", source);
+ modifier = (ASTNode) modifiers.get(1);
+ checkSourceRange(modifier, "final", source);
+ assertEquals("Wrong name", "args", parameter.getName().getIdentifier());
+ assertTrue("Not a variable argument", parameter.isVarargs());
+ }
+
+ public void test0013() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0013", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ char[] source = sourceUnit.getSource().toCharArray();
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION);
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ SimpleName name = typeDeclaration.getName();
+ assertEquals("Wrong name", "Convertible", name.getIdentifier());
+ checkSourceRange(name, "Convertible", source);
+ List typeParameters = typeDeclaration.typeParameters();
+ assertEquals("Wrong size", 1, typeParameters.size());
+ TypeParameter typeParameter = (TypeParameter) typeParameters.get(0);
+ checkSourceRange(typeParameter, "T", source);
+ checkSourceRange(typeParameter.getName(), "T", source);
+ node = getASTNode(compilationUnit, 1);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION);
+ typeDeclaration = (TypeDeclaration) node;
+ name = typeDeclaration.getName();
+ assertEquals("Wrong name", "X", name.getIdentifier());
+ checkSourceRange(name, "X", source);
+ typeParameters = typeDeclaration.typeParameters();
+ assertEquals("Wrong size", 2, typeParameters.size());
+ typeParameter = (TypeParameter) typeParameters.get(0);
+ checkSourceRange(typeParameter.getName(), "A", source);
+ checkSourceRange(typeParameter, "A extends Convertible<B>", source);
+ typeParameter = (TypeParameter) typeParameters.get(1);
+ checkSourceRange(typeParameter.getName(), "B", source);
+ checkSourceRange(typeParameter, "B extends Convertible<A>", source);
+ List typeBounds = typeParameter.typeBounds();
+ assertEquals("Wrong size", 1, typeBounds.size());
+ Type typeBound = (Type) typeBounds.get(0);
+ checkSourceRange(typeBound, "Convertible<A>", source);
+ assertEquals("wrong type", ASTNode.PARAMETERIZED_TYPE, typeBound.getNodeType());
+ ParameterizedType parameterizedType = (ParameterizedType) typeBound;
+ List typeArguments = parameterizedType.typeArguments();
+ assertEquals("Wrong size", 1, typeArguments.size());
+ Type typeArgument = (Type) typeArguments.get(0);
+ checkSourceRange(typeArgument, "A", source);
+ }
+
+ public void test0014() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0014", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ char[] source = sourceUnit.getSource().toCharArray();
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 1);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION);
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ SimpleName name = typeDeclaration.getName();
+ assertEquals("Wrong name", "X", name.getIdentifier());
+ checkSourceRange(name, "X", source);
+ List typeParameters = typeDeclaration.typeParameters();
+ assertEquals("Wrong size", 1, typeParameters.size());
+ TypeParameter typeParameter = (TypeParameter) typeParameters.get(0);
+ checkSourceRange(typeParameter.getName(), "A", source);
+ checkSourceRange(typeParameter, "A extends Convertible<Convertible<A>>", source);
+ List typeBounds = typeParameter.typeBounds();
+ assertEquals("Wrong size", 1, typeBounds.size());
+ Type typeBound = (Type) typeBounds.get(0);
+ checkSourceRange(typeBound, "Convertible<Convertible<A>>", source);
+ assertEquals("wrong type", ASTNode.PARAMETERIZED_TYPE, typeBound.getNodeType());
+ ParameterizedType parameterizedType = (ParameterizedType) typeBound;
+ List typeArguments = parameterizedType.typeArguments();
+ assertEquals("Wrong size", 1, typeArguments.size());
+ Type typeArgument = (Type) typeArguments.get(0);
+ checkSourceRange(typeArgument, "Convertible<A>", source);
+ assertEquals("wrong type", ASTNode.PARAMETERIZED_TYPE, typeArgument.getNodeType());
+ parameterizedType = (ParameterizedType) typeArgument;
+ typeArguments = parameterizedType.typeArguments();
+ assertEquals("Wrong size", 1, typeArguments.size());
+ typeArgument = (Type) typeArguments.get(0);
+ checkSourceRange(typeArgument, "A", source);
+ }
+
+ public void test0015() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0015", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ char[] source = sourceUnit.getSource().toCharArray();
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION);
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ SimpleName name = typeDeclaration.getName();
+ assertEquals("Wrong name", "X", name.getIdentifier());
+ checkSourceRange(name, "X", source);
+ List typeParameters = typeDeclaration.typeParameters();
+ assertEquals("Wrong size", 1, typeParameters.size());
+ TypeParameter typeParameter = (TypeParameter) typeParameters.get(0);
+ checkSourceRange(typeParameter.getName(), "A", source);
+ checkSourceRange(typeParameter, "A extends Object & java.io.Serializable & Comparable<?>", source);
+ List typeBounds = typeParameter.typeBounds();
+ assertEquals("Wrong size", 3, typeBounds.size());
+ Type typeBound = (Type) typeBounds.get(0);
+ checkSourceRange(typeBound, "Object", source);
+ typeBound = (Type) typeBounds.get(1);
+ checkSourceRange(typeBound, "java.io.Serializable", source);
+ typeBound = (Type) typeBounds.get(2);
+ checkSourceRange(typeBound, "Comparable<?>", source);
+ }
+
+ public void test0016() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0016", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ char[] source = sourceUnit.getSource().toCharArray();
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ String expectedProblems =
+ "Pair is a raw type. References to generic type Pair<A,B> should be parameterized\n" +
+ "Pair is a raw type. References to generic type Pair<A,B> should be parameterized\n" +
+ "Pair is a raw type. References to generic type Pair<A,B> should be parameterized";
+ assertProblemsSize(compilationUnit, 3, expectedProblems);
+ ASTNode node = getASTNode(compilationUnit, 0, 5);
+ assertEquals("Wrong first character", '<', source[node.getStartPosition()]);
+ }
+
+ public void test0017() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0017", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ char[] source = sourceUnit.getSource().toCharArray();
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 1, 0, 0);
+ assertTrue("Not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression initializer = fragment.getInitializer();
+ assertNotNull("No initializer", initializer);
+ ITypeBinding binding = initializer.resolveTypeBinding();
+ assertNotNull("No binding", binding);
+ Type type = statement.getType();
+ assertTrue("Not a parameterized type", type.getNodeType() == ASTNode.PARAMETERIZED_TYPE);
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ List typeArguments = parameterizedType.typeArguments();
+ assertEquals("wrong size", 1, typeArguments.size());
+ Type typeArgument = (Type) typeArguments.get(0);
+ checkSourceRange(typeArgument, "Integer", source);
+ Type innerType = parameterizedType.getType();
+ assertTrue("Not a qualified type", innerType.getNodeType() == ASTNode.QUALIFIED_TYPE);
+ QualifiedType qualifiedType = (QualifiedType) innerType;
+ checkSourceRange(qualifiedType.getName(), "B", source);
+ Type qualifier = qualifiedType.getQualifier();
+ checkSourceRange(qualifier, "test0017.A<String>", source);
+ assertTrue("Not a parameterized type", qualifier.getNodeType() == ASTNode.PARAMETERIZED_TYPE);
+ ParameterizedType parameterizedType2 = (ParameterizedType) qualifier;
+ typeArguments = parameterizedType2.typeArguments();
+ assertEquals("wrong size", 1, typeArguments.size());
+ typeArgument = (Type) typeArguments.get(0);
+ checkSourceRange(typeArgument, "String", source);
+ innerType = parameterizedType2.getType();
+ assertTrue("Not a simple type", innerType.getNodeType() == ASTNode.SIMPLE_TYPE);
+ SimpleType simpleType = (SimpleType) innerType;
+ checkSourceRange(simpleType, "test0017.A", source);
+ Name name = simpleType.getName();
+ assertTrue("Not a qualified name", name.getNodeType() == ASTNode.QUALIFIED_NAME);
+ QualifiedName qualifiedName = (QualifiedName) name;
+ checkSourceRange(qualifiedName.getQualifier(), "test0017", source);
+ checkSourceRange(qualifiedName.getName(), "A", source);
+ }
+
+ public void test0018() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0018", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ char[] source = sourceUnit.getSource().toCharArray();
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 1, 0, 0);
+ assertTrue("Not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ Type type = statement.getType();
+ assertTrue("Not a parameterized type", type.getNodeType() == ASTNode.PARAMETERIZED_TYPE);
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ List typeArguments = parameterizedType.typeArguments();
+ assertEquals("wrong size", 1, typeArguments.size());
+ Type typeArgument = (Type) typeArguments.get(0);
+ checkSourceRange(typeArgument, "Float", source);
+ Type innerType = parameterizedType.getType();
+ assertTrue("Not a qualified type", innerType.getNodeType() == ASTNode.QUALIFIED_TYPE);
+ QualifiedType qualifiedType = (QualifiedType) innerType;
+ checkSourceRange(qualifiedType.getName(), "C", source);
+ Type qualifier = qualifiedType.getQualifier();
+ checkSourceRange(qualifier, "test0018.A<String>.B", source);
+ assertTrue("Not a qualified type", qualifier.getNodeType() == ASTNode.QUALIFIED_TYPE);
+ qualifiedType = (QualifiedType) qualifier;
+ checkSourceRange(qualifiedType.getName(), "B", source);
+ qualifier = qualifiedType.getQualifier();
+ checkSourceRange(qualifier, "test0018.A<String>", source);
+ assertTrue("Not a parameterized type", qualifier.getNodeType() == ASTNode.PARAMETERIZED_TYPE);
+ ParameterizedType parameterizedType2 = (ParameterizedType) qualifier;
+ typeArguments = parameterizedType2.typeArguments();
+ assertEquals("wrong size", 1, typeArguments.size());
+ typeArgument = (Type) typeArguments.get(0);
+ checkSourceRange(typeArgument, "String", source);
+ innerType = parameterizedType2.getType();
+ assertTrue("Not a simple type", innerType.getNodeType() == ASTNode.SIMPLE_TYPE);
+ SimpleType simpleType = (SimpleType) innerType;
+ checkSourceRange(simpleType, "test0018.A", source);
+ Name name = simpleType.getName();
+ assertTrue("Not a qualified name", name.getNodeType() == ASTNode.QUALIFIED_NAME);
+ QualifiedName qualifiedName = (QualifiedName) name;
+ checkSourceRange(qualifiedName.getQualifier(), "test0018", source);
+ checkSourceRange(qualifiedName.getName(), "A", source);
+ }
+
+ public void test0019() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0019", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ char[] source = sourceUnit.getSource().toCharArray();
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 1, 0, 0);
+ assertTrue("Not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ Type type = statement.getType();
+ assertTrue("Not a qualified type", type.getNodeType() == ASTNode.QUALIFIED_TYPE);
+ QualifiedType qualifiedType = (QualifiedType) type;
+ checkSourceRange(qualifiedType.getName(), "C", source);
+ Type qualifier = qualifiedType.getQualifier();
+ checkSourceRange(qualifier, "test0019.A<String>.B<Integer>", source);
+ assertTrue("Not a parameterized type", qualifier.getNodeType() == ASTNode.PARAMETERIZED_TYPE);
+ ParameterizedType parameterizedType = (ParameterizedType) qualifier;
+ List typeArguments = parameterizedType.typeArguments();
+ assertEquals("wrong size", 1, typeArguments.size());
+ Type typeArgument = (Type) typeArguments.get(0);
+ checkSourceRange(typeArgument, "Integer", source);
+ Type innerType = parameterizedType.getType();
+ assertTrue("Not a qualified type", innerType.getNodeType() == ASTNode.QUALIFIED_TYPE);
+ qualifiedType = (QualifiedType) innerType;
+ checkSourceRange(qualifiedType.getName(), "B", source);
+ qualifier = qualifiedType.getQualifier();
+ checkSourceRange(qualifier, "test0019.A<String>", source);
+ assertTrue("Not a parameterized type", qualifier.getNodeType() == ASTNode.PARAMETERIZED_TYPE);
+ ParameterizedType parameterizedType2 = (ParameterizedType) qualifier;
+ typeArguments = parameterizedType2.typeArguments();
+ assertEquals("wrong size", 1, typeArguments.size());
+ typeArgument = (Type) typeArguments.get(0);
+ checkSourceRange(typeArgument, "String", source);
+ innerType = parameterizedType2.getType();
+ assertTrue("Not a simple type", innerType.getNodeType() == ASTNode.SIMPLE_TYPE);
+ SimpleType simpleType = (SimpleType) innerType;
+ checkSourceRange(simpleType, "test0019.A", source);
+ Name name = simpleType.getName();
+ assertTrue("Not a qualified name", name.getNodeType() == ASTNode.QUALIFIED_NAME);
+ QualifiedName qualifiedName = (QualifiedName) name;
+ checkSourceRange(qualifiedName.getQualifier(), "test0019", source);
+ checkSourceRange(qualifiedName.getName(), "A", source);
+ }
+
+ public void test0020() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0020", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ char[] source = sourceUnit.getSource().toCharArray();
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION);
+ MethodDeclaration declaration = (MethodDeclaration) node;
+ List parameters = declaration.parameters();
+ assertEquals("Wrong size", 1, parameters.size());
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ Type type = singleVariableDeclaration.getType();
+ assertTrue("Not a parameterized type", type.getNodeType() == ASTNode.PARAMETERIZED_TYPE);
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ List typeArguments = parameterizedType.typeArguments();
+ assertEquals("Wrong size", 1, typeArguments.size());
+ Type typeArgument = (Type) typeArguments.get(0);
+ checkSourceRange(typeArgument, "?", source);
+ }
+
+ public void test0021() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0021", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ char[] source = sourceUnit.getSource().toCharArray();
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION);
+ MethodDeclaration declaration = (MethodDeclaration) node;
+ List parameters = declaration.parameters();
+ assertEquals("Wrong size", 1, parameters.size());
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ Type type = singleVariableDeclaration.getType();
+ assertTrue("Not a parameterized type", type.getNodeType() == ASTNode.PARAMETERIZED_TYPE);
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ List typeArguments = parameterizedType.typeArguments();
+ assertEquals("Wrong size", 1, typeArguments.size());
+ Type typeArgument = (Type) typeArguments.get(0);
+ checkSourceRange(typeArgument, "? extends E", source);
+ assertTrue("Not a wildcard type", typeArgument.getNodeType() == ASTNode.WILDCARD_TYPE);
+ WildcardType wildcardType = (WildcardType) typeArgument;
+ Type bound = wildcardType.getBound();
+ checkSourceRange(bound, "E", source);
+ assertTrue("Not an upper bound", wildcardType.isUpperBound());
+ }
+
+ public void test0022() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0022", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ char[] source = sourceUnit.getSource().toCharArray();
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION);
+ MethodDeclaration declaration = (MethodDeclaration) node;
+ List parameters = declaration.parameters();
+ assertEquals("Wrong size", 1, parameters.size());
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ Type type = singleVariableDeclaration.getType();
+ assertTrue("Not a parameterized type", type.getNodeType() == ASTNode.PARAMETERIZED_TYPE);
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ List typeArguments = parameterizedType.typeArguments();
+ assertEquals("Wrong size", 1, typeArguments.size());
+ Type typeArgument = (Type) typeArguments.get(0);
+ checkSourceRange(typeArgument, "? super E", source);
+ assertTrue("Not a wildcard type", typeArgument.getNodeType() == ASTNode.WILDCARD_TYPE);
+ WildcardType wildcardType = (WildcardType) typeArgument;
+ Type bound = wildcardType.getBound();
+ checkSourceRange(bound, "E", source);
+ assertFalse("Is an upper bound", wildcardType.isUpperBound());
+ }
+
+ public void test0023() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0023", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ char[] source = sourceUnit.getSource().toCharArray();
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ String expectedProblems =
+ "Pair is a raw type. References to generic type Pair<A,B> should be parameterized\n" +
+ "Pair is a raw type. References to generic type Pair<A,B> should be parameterized\n" +
+ "Pair is a raw type. References to generic type Pair<A,B> should be parameterized";
+ assertProblemsSize(compilationUnit, 3, expectedProblems);
+ ASTNode node = getASTNode(compilationUnit, 0, 5);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("Wrong name", "zip", methodDeclaration.getName().getIdentifier());
+ List typeParameters = methodDeclaration.typeParameters();
+ assertNotNull("No type parameters", typeParameters);
+ assertEquals("Wrong size", 1, typeParameters.size());
+ TypeParameter typeParameter = (TypeParameter) typeParameters.get(0);
+ checkSourceRange(typeParameter, "T", source);
+ }
+
+ public void test0024() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0024", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ char[] source = sourceUnit.getSource().toCharArray();
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement declarationStatement = (VariableDeclarationStatement) node;
+ List fragments = declarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not a class instance creation", ASTNode.CLASS_INSTANCE_CREATION, expression.getNodeType());
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ List typeArguments = classInstanceCreation.typeArguments();
+ assertEquals("wrong size", 1, typeArguments.size());
+ Type type = (Type) typeArguments.get(0);
+ checkSourceRange(type, "String", source);
+ }
+
+ public void test0025() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0025", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ char[] source = sourceUnit.getSource().toCharArray();
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not a constructor invocation", ASTNode.CONSTRUCTOR_INVOCATION, node.getNodeType());
+ ConstructorInvocation constructorInvocation = (ConstructorInvocation) node;
+ List typeArguments = constructorInvocation.typeArguments();
+ assertEquals("wrong size", 1, typeArguments.size());
+ Type type = (Type) typeArguments.get(0);
+ checkSourceRange(type, "E", source);
+ }
+
+ public void test0026() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0026", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertEquals("Not an enum declaration", ASTNode.ENUM_DECLARATION, node.getNodeType());
+ EnumDeclaration enumDeclaration = (EnumDeclaration) node;
+ ITypeBinding typeBinding2 = enumDeclaration.resolveBinding();
+ assertNotNull("No binding", typeBinding2);
+ List modifiers = enumDeclaration.modifiers();
+ assertEquals("Wrong number of modifiers", 1, modifiers.size());
+ IExtendedModifier extendedModifier = (IExtendedModifier) modifiers.get(0);
+ assertTrue("Not a modifier", extendedModifier instanceof Modifier);
+ Modifier modifier = (Modifier) extendedModifier;
+ checkSourceRange(modifier, "public", source);
+ assertEquals("wrong name", "X", enumDeclaration.getName().getIdentifier());
+ List enumConstants = enumDeclaration.enumConstants();
+ assertEquals("wrong size", 4, enumConstants.size());
+ List bodyDeclarations = enumDeclaration.bodyDeclarations();
+ assertEquals("wrong size", 2, bodyDeclarations.size());
+ EnumConstantDeclaration enumConstantDeclaration = (EnumConstantDeclaration) enumConstants.get(0);
+ IMethodBinding methodBinding = enumConstantDeclaration.resolveConstructorBinding();
+ assertNotNull("No binding", methodBinding);
+ assertTrue("Not a constructor", methodBinding.isConstructor());
+ checkSourceRange(enumConstantDeclaration.getName(), "PLUS", source);
+ checkSourceRange(enumConstantDeclaration, "PLUS {\n" +
+ " @Override\n" +
+ " double eval(double x, double y) { return x + y; }\n" +
+ " }", source);
+ assertEquals("wrong size", 0, enumConstantDeclaration.arguments().size());
+ AnonymousClassDeclaration anonymousClassDeclaration = enumConstantDeclaration.getAnonymousClassDeclaration();
+ assertNotNull("No anonymous class", anonymousClassDeclaration);
+ checkSourceRange(anonymousClassDeclaration, "{\n" +
+ " @Override\n" +
+ " double eval(double x, double y) { return x + y; }\n" +
+ " }", source);
+ ITypeBinding typeBinding = anonymousClassDeclaration.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertTrue("Not a enum type", typeBinding.isEnum());
+ bodyDeclarations = anonymousClassDeclaration.bodyDeclarations();
+ assertEquals("wrong size", 1, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, bodyDeclaration.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ checkSourceRange(methodDeclaration.getName(), "eval", source);
+ checkSourceRange(methodDeclaration, "@Override\n double eval(double x, double y) { return x + y; }", source);
+ assertEquals("wrong size", 0, enumConstantDeclaration.arguments().size());
+
+ enumConstantDeclaration = (EnumConstantDeclaration) enumConstants.get(1);
+ methodBinding = enumConstantDeclaration.resolveConstructorBinding();
+ assertNotNull("No binding", methodBinding);
+ assertTrue("Not a constructor", methodBinding.isConstructor());
+ checkSourceRange(enumConstantDeclaration.getName(), "MINUS", source);
+ checkSourceRange(enumConstantDeclaration, "MINUS {\n" +
+ " @Override\n" +
+ " double eval(double x, double y) { return x - y; }\n" +
+ " }", source);
+ anonymousClassDeclaration = enumConstantDeclaration.getAnonymousClassDeclaration();
+ typeBinding = anonymousClassDeclaration.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertTrue("Not a enum type", typeBinding.isEnum());
+ assertNotNull("No anonymous class", anonymousClassDeclaration);
+ checkSourceRange(anonymousClassDeclaration, "{\n" +
+ " @Override\n" +
+ " double eval(double x, double y) { return x - y; }\n" +
+ " }", source);
+ bodyDeclarations = anonymousClassDeclaration.bodyDeclarations();
+ assertEquals("wrong size", 1, bodyDeclarations.size());
+ bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, bodyDeclaration.getNodeType());
+ methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ checkSourceRange(methodDeclaration.getName(), "eval", source);
+ checkSourceRange(methodDeclaration, "@Override\n double eval(double x, double y) { return x - y; }", source);
+ assertEquals("wrong size", 0, enumConstantDeclaration.arguments().size());
+
+ enumConstantDeclaration = (EnumConstantDeclaration) enumConstants.get(2);
+ methodBinding = enumConstantDeclaration.resolveConstructorBinding();
+ assertNotNull("No binding", methodBinding);
+ assertTrue("Not a constructor", methodBinding.isConstructor());
+ checkSourceRange(enumConstantDeclaration.getName(), "TIMES", source);
+ checkSourceRange(enumConstantDeclaration, "TIMES {\n" +
+ " @Override\n" +
+ " double eval(double x, double y) { return x * y; }\n" +
+ " }", source);
+ anonymousClassDeclaration = enumConstantDeclaration.getAnonymousClassDeclaration();
+ assertNotNull("No anonymous class", anonymousClassDeclaration);
+ checkSourceRange(anonymousClassDeclaration, "{\n" +
+ " @Override\n" +
+ " double eval(double x, double y) { return x * y; }\n" +
+ " }", source);
+ typeBinding = anonymousClassDeclaration.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertTrue("Not a enum type", typeBinding.isEnum());
+ bodyDeclarations = anonymousClassDeclaration.bodyDeclarations();
+ assertEquals("wrong size", 1, bodyDeclarations.size());
+ bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, bodyDeclaration.getNodeType());
+ methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ checkSourceRange(methodDeclaration.getName(), "eval", source);
+ checkSourceRange(methodDeclaration, "@Override\n double eval(double x, double y) { return x * y; }", source);
+ assertEquals("wrong size", 0, enumConstantDeclaration.arguments().size());
+
+ enumConstantDeclaration = (EnumConstantDeclaration) enumConstants.get(3);
+ methodBinding = enumConstantDeclaration.resolveConstructorBinding();
+ assertNotNull("No binding", methodBinding);
+ assertTrue("Not a constructor", methodBinding.isConstructor());
+ checkSourceRange(enumConstantDeclaration.getName(), "DIVIDED_BY", source);
+ checkSourceRange(enumConstantDeclaration, "DIVIDED_BY {\n" +
+ " @Override\n" +
+ " double eval(double x, double y) { return x / y; }\n" +
+ " }", source);
+ anonymousClassDeclaration = enumConstantDeclaration.getAnonymousClassDeclaration();
+ assertNotNull("No anonymous class", anonymousClassDeclaration);
+ checkSourceRange(anonymousClassDeclaration, "{\n" +
+ " @Override\n" +
+ " double eval(double x, double y) { return x / y; }\n" +
+ " }", source);
+ typeBinding = anonymousClassDeclaration.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertTrue("Not a enum type", typeBinding.isEnum());
+ bodyDeclarations = anonymousClassDeclaration.bodyDeclarations();
+ assertEquals("wrong size", 1, bodyDeclarations.size());
+ bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, bodyDeclaration.getNodeType());
+ methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ checkSourceRange(methodDeclaration.getName(), "eval", source);
+ checkSourceRange(methodDeclaration, "@Override\n double eval(double x, double y) { return x / y; }", source);
+ assertEquals("wrong size", 0, enumConstantDeclaration.arguments().size());
+ }
+
+ public void test0027() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0027", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0);
+ char[] source = sourceUnit.getSource().toCharArray();
+ assertEquals("Not an enum declaration", ASTNode.ENUM_DECLARATION, node.getNodeType());
+ EnumDeclaration enumDeclaration = (EnumDeclaration) node;
+ List modifiers = enumDeclaration.modifiers();
+ assertEquals("Wrong number of modifiers", 1, modifiers.size());
+ IExtendedModifier extendedModifier = (IExtendedModifier) modifiers.get(0);
+ assertTrue("Not a modifier", extendedModifier instanceof Modifier);
+ Modifier modifier = (Modifier) extendedModifier;
+ checkSourceRange(modifier, "public", source);
+ assertEquals("wrong name", "X", enumDeclaration.getName().getIdentifier());
+ List enumConstants = enumDeclaration.enumConstants();
+ assertEquals("wrong size", 4, enumConstants.size());
+ EnumConstantDeclaration enumConstantDeclaration = (EnumConstantDeclaration) enumConstants.get(0);
+ IMethodBinding methodBinding = enumConstantDeclaration.resolveConstructorBinding();
+ assertNotNull("No binding", methodBinding);
+ assertTrue("Not a constructor", methodBinding.isConstructor());
+ checkSourceRange(enumConstantDeclaration.getName(), "PENNY", source);
+ checkSourceRange(enumConstantDeclaration, "PENNY(1)", source);
+ List arguments = enumConstantDeclaration.arguments();
+ assertEquals("wrong size", 1, arguments.size());
+ Expression argument = (Expression) arguments.get(0);
+ checkSourceRange(argument, "1", source);
+ assertEquals("not an number literal", ASTNode.NUMBER_LITERAL, argument.getNodeType());
+ IVariableBinding binding = enumConstantDeclaration.resolveVariable();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong name", "PENNY", binding.getName());
+ ASTNode node2 = compilationUnit.findDeclaringNode(binding);
+ assertTrue("Different node", node2 == enumConstantDeclaration);
+
+ enumConstantDeclaration = (EnumConstantDeclaration) enumConstants.get(1);
+ methodBinding = enumConstantDeclaration.resolveConstructorBinding();
+ assertNotNull("No binding", methodBinding);
+ assertTrue("Not a constructor", methodBinding.isConstructor());
+ checkSourceRange(enumConstantDeclaration.getName(), "NICKEL", source);
+ checkSourceRange(enumConstantDeclaration, "NICKEL(5)", source);
+ arguments = enumConstantDeclaration.arguments();
+ assertEquals("wrong size", 1, arguments.size());
+ argument = (Expression) arguments.get(0);
+ checkSourceRange(argument, "5", source);
+ assertEquals("not an number literal", ASTNode.NUMBER_LITERAL, argument.getNodeType());
+ binding = enumConstantDeclaration.resolveVariable();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong name", "NICKEL", binding.getName());
+
+ enumConstantDeclaration = (EnumConstantDeclaration) enumConstants.get(2);
+ methodBinding = enumConstantDeclaration.resolveConstructorBinding();
+ assertNotNull("No binding", methodBinding);
+ assertTrue("Not a constructor", methodBinding.isConstructor());
+ checkSourceRange(enumConstantDeclaration.getName(), "DIME", source);
+ checkSourceRange(enumConstantDeclaration, "DIME(10)", source);
+ arguments = enumConstantDeclaration.arguments();
+ assertEquals("wrong size", 1, arguments.size());
+ argument = (Expression) arguments.get(0);
+ checkSourceRange(argument, "10", source);
+ assertEquals("not an number literal", ASTNode.NUMBER_LITERAL, argument.getNodeType());
+ binding = enumConstantDeclaration.resolveVariable();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong name", "DIME", binding.getName());
+
+
+ enumConstantDeclaration = (EnumConstantDeclaration) enumConstants.get(3);
+ methodBinding = enumConstantDeclaration.resolveConstructorBinding();
+ assertNotNull("No binding", methodBinding);
+ checkSourceRange(enumConstantDeclaration.getName(), "QUARTER", source);
+ checkSourceRange(enumConstantDeclaration, "QUARTER(25)", source);
+ arguments = enumConstantDeclaration.arguments();
+ assertEquals("wrong size", 1, arguments.size());
+ argument = (Expression) arguments.get(0);
+ checkSourceRange(argument, "25", source);
+ assertEquals("not an number literal", ASTNode.NUMBER_LITERAL, argument.getNodeType());
+ binding = enumConstantDeclaration.resolveVariable();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong name", "QUARTER", binding.getName());
+ }
+
+ public void test0028() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0028", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ checkSourceRange(methodDeclaration.getName(), "foo", source);
+ checkSourceRange(methodDeclaration, "void foo(String[] args) {\n" +
+ " if (args.length < 2) {\n" +
+ " System.out.println(\"Usage: X <double> <double>\");\n" +
+ " return;\n" +
+ " }\n" +
+ " double x = Double.parseDouble(args[0]);\n" +
+ " double y = Double.parseDouble(args[1]);\n" +
+ "\n" +
+ " for (X op : X.values())\n" +
+ " System.out.println(x + \" \" + op + \" \" + y + \" = \" + op.eval(x, y));\n" +
+ " }", source);
+ node = getASTNode(compilationUnit, 0, 1);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ methodDeclaration = (MethodDeclaration) node;
+ checkSourceRange(methodDeclaration.getName(), "bar", source);
+ checkSourceRange(methodDeclaration, "abstract double bar(double x, double y);", source);
+ }
+
+ public void test0029() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0029", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ }
+
+ /**
+ * Test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=67790
+ */
+ public void test0030() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0030", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not a constructor invocation", ASTNode.CONSTRUCTOR_INVOCATION, node.getNodeType());
+ checkSourceRange(node, "<T>this();", source);
+ }
+
+ public void test0031() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0031", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ }
+
+ public void test0032() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0032", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 1);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ List superInterfaces = typeDeclaration.superInterfaceTypes();
+ assertEquals("wrong size", 1, superInterfaces.size());
+ Type type = (Type) superInterfaces.get(0);
+ assertEquals("wrong type", ASTNode.PARAMETERIZED_TYPE, type.getNodeType());
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ Type type2 = parameterizedType.getType();
+ checkSourceRange(type2, "C", source);
+ }
+
+ public void test0033() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0033", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ }
+
+ public void test0034() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0034", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ }
+
+ /**
+ * Test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=70292
+ */
+ public void test0035() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0035", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ }
+
+ /**
+ * Test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=67790
+ */
+ public void test0036() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0036", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ checkSourceRange(expressionStatement, "this.<T>foo();", source);
+ Expression expression = expressionStatement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ checkSourceRange(methodInvocation, "this.<T>foo()", source);
+ List typeArguments = methodInvocation.typeArguments();
+ assertEquals("Wrong size", 1, typeArguments.size());
+ }
+
+ /**
+ * Test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=68838
+ */
+ public void test0037() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0037", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ List typeParameters = typeDeclaration.typeParameters();
+ assertEquals("Wrong size", 2, typeParameters.size());
+ TypeParameter typeParameter = (TypeParameter) typeParameters.get(0);
+ IBinding binding = typeParameter.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong type", IBinding.TYPE, binding.getKind());
+ ITypeBinding typeBinding = (ITypeBinding) binding;
+ assertEquals("Wrong name", "T", typeBinding.getName());
+ assertTrue("Not a type variable", typeBinding.isTypeVariable());
+ assertTrue("Not from source", typeBinding.isFromSource());
+ assertEquals("Wrong key", "Ltest0037/X;:TT;", typeBinding.getKey());
+ SimpleName simpleName = typeParameter.getName();
+ assertEquals("Wrong name", "T", simpleName.getIdentifier());
+ IBinding binding2 = simpleName.resolveBinding();
+ assertNotNull("No binding", binding2);
+ assertEquals("Wrong type", IBinding.TYPE, binding2.getKind());
+ ITypeBinding typeBinding2 = (ITypeBinding) binding2;
+ assertEquals("Wrong name", "T", typeBinding2.getName());
+ ITypeBinding typeBinding3 = simpleName.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding3);
+ assertEquals("Wrong type", IBinding.TYPE, typeBinding3.getKind());
+ assertEquals("Wrong name", "T", typeBinding3.getName());
+
+ typeParameter = (TypeParameter) typeParameters.get(1);
+ binding = typeParameter.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong type", IBinding.TYPE, binding.getKind());
+ typeBinding = (ITypeBinding) binding;
+ assertEquals("Wrong name", "U", typeBinding.getName());
+ assertTrue("Not a type variable", typeBinding.isTypeVariable());
+ assertTrue("Not from source", typeBinding.isFromSource());
+ assertEquals("Wrong key", "Ltest0037/X;:TU;", typeBinding.getKey());
+ simpleName = typeParameter.getName();
+ assertEquals("Wrong name", "U", simpleName.getIdentifier());
+ binding2 = simpleName.resolveBinding();
+ assertNotNull("No binding", binding2);
+ assertEquals("Wrong type", IBinding.TYPE, binding2.getKind());
+ typeBinding2 = (ITypeBinding) binding2;
+ assertEquals("Wrong name", "U", typeBinding2.getName());
+ typeBinding3 = simpleName.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding3);
+ assertEquals("Wrong type", IBinding.TYPE, typeBinding3.getKind());
+ assertEquals("Wrong name", "U", typeBinding3.getName());
+ }
+
+ /**
+ * Test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=69066
+ */
+ public void test0038() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0038", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ Type type = statement.getType();
+ assertTrue("Not a parameterized type", type.isParameterizedType());
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ List typeArguments = parameterizedType.typeArguments();
+ assertEquals("Wrong size", 1, typeArguments.size());
+ Type typeArgument = (Type) typeArguments.get(0);
+ checkSourceRange(typeArgument, "T", source);
+ ITypeBinding typeBinding = typeArgument.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertEquals("Wrong name", "T", typeBinding.getName());
+ ITypeBinding[] typeParameters = typeBinding.getTypeParameters();
+ assertEquals("Wrong size", 0, typeParameters.length);
+ assertEquals("Wrong isArray", false, typeBinding.isArray());
+ assertEquals("Wrong isAnnotation", false, typeBinding.isAnnotation());
+ assertEquals("Wrong isAnonymous", false, typeBinding.isAnonymous());
+ assertEquals("Wrong isClass", false, typeBinding.isClass());
+ assertEquals("Wrong isEnum", false, typeBinding.isEnum());
+ assertEquals("Wrong isInterface", false, typeBinding.isInterface());
+ assertEquals("Wrong isGenericType", false, typeBinding.isGenericType());
+ assertEquals("Wrong isLocal", false, typeBinding.isLocal());
+ assertEquals("Wrong isMember", false, typeBinding.isMember());
+ assertEquals("Wrong isNested", false, typeBinding.isNested());
+ assertEquals("Wrong isNullType", false, typeBinding.isNullType());
+ assertEquals("Wrong isParameterizedType", false, typeBinding.isParameterizedType());
+ assertEquals("Wrong isPrimitive", false, typeBinding.isPrimitive());
+ assertEquals("Wrong isRawType", false, typeBinding.isRawType());
+ assertEquals("Wrong isTopLevel", false, typeBinding.isTopLevel());
+ assertEquals("Wrong isUpperbound", false, typeBinding.isUpperbound());
+ assertEquals("Wrong isTypeVariable", true, typeBinding.isTypeVariable());
+ assertTrue("Not from source", typeBinding.isFromSource());
+ assertEquals("Wrong isWildcardType", false, typeBinding.isWildcardType());
+ ITypeBinding typeBinding2 = type.resolveBinding();
+ assertEquals("Wrong name", "X<T>", typeBinding2.getName());
+ assertEquals("Wrong isArray", false, typeBinding2.isArray());
+ assertEquals("Wrong isAnnotation", false, typeBinding2.isAnnotation());
+ assertEquals("Wrong isAnonymous", false, typeBinding2.isAnonymous());
+ assertEquals("Wrong isClass", true, typeBinding2.isClass());
+ assertEquals("Wrong isEnum", false, typeBinding2.isEnum());
+ assertEquals("Wrong isInterface", false, typeBinding2.isInterface());
+ assertEquals("Wrong isGenericType", false, typeBinding2.isGenericType());
+ assertEquals("Wrong isLocal", false, typeBinding2.isLocal());
+ assertEquals("Wrong isMember", false, typeBinding2.isMember());
+ assertEquals("Wrong isNested", false, typeBinding2.isNested());
+ assertEquals("Wrong isNullType", false, typeBinding2.isNullType());
+ assertEquals("Wrong isParameterizedType", true, typeBinding2.isParameterizedType());
+ assertEquals("Wrong isPrimitive", false, typeBinding2.isPrimitive());
+ assertEquals("Wrong isRawType", false, typeBinding2.isRawType());
+ assertEquals("Wrong isTopLevel", true, typeBinding2.isTopLevel());
+ assertEquals("Wrong isUpperbound", false, typeBinding2.isUpperbound());
+ assertEquals("Wrong isTypeVariable", false, typeBinding2.isTypeVariable());
+ assertEquals("Wrong isWildcardType", false, typeBinding2.isWildcardType());
+ typeParameters = typeBinding2.getTypeParameters();
+ assertEquals("Wrong size", 0, typeParameters.length);
+ }
+
+ /**
+ * Test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=72233
+ */
+ public void test0039() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0039", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ }
+
+ /**
+ * Test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=72248
+ */
+ public void test0040() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0040", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List typeParameters = methodDeclaration.typeParameters();
+ assertEquals("wrong size", 1, typeParameters.size());
+ TypeParameter parameter = (TypeParameter) typeParameters.get(0);
+ IBinding binding = parameter.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("wrong type", IBinding.TYPE, binding.getKind());
+ assertEquals("wrong key", "Ltest0040/X;.foo<T:Ljava/lang/Object;>()TT;:TT;", binding.getKey());
+ Type returnType = methodDeclaration.getReturnType2();
+ IBinding binding2 = returnType.resolveBinding();
+ assertNotNull("No binding", binding2);
+ assertEquals("wrong type", IBinding.TYPE, binding2.getKind());
+ assertEquals("wrong key", "Ltest0040/X;.foo<T:Ljava/lang/Object;>()TT;:TT;", binding2.getKey());
+ }
+
+ /**
+ * Test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=72477
+ */
+ public void test0041() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0041", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ }
+
+ /**
+ * Test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=73048
+ */
+ public void test0042() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0042", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List typeParameters = methodDeclaration.typeParameters();
+ assertEquals("wrong size", 1, typeParameters.size());
+ TypeParameter parameter = (TypeParameter) typeParameters.get(0);
+ IBinding binding = parameter.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("wrong type", IBinding.TYPE, binding.getKind());
+ assertEquals("wrong key", "Ltest0042/X;.foo<T:Ljava/lang/Object;>()[TT;:TT;", binding.getKey());
+ Type returnType = methodDeclaration.getReturnType2();
+ IBinding binding2 = returnType.resolveBinding();
+ assertNotNull("No binding", binding2);
+ assertEquals("wrong type", IBinding.TYPE, binding2.getKind());
+ assertEquals("wrong key", "[Ltest0042/X;.foo<T:Ljava/lang/Object;>()[TT;:TT;", binding2.getKey());
+ }
+
+ /**
+ * Test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=72882
+ */
+ public void test0043() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0043", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ List typeParameters = typeDeclaration.typeParameters();
+ assertEquals("Wrong size", 1, typeParameters.size());
+ TypeParameter typeParameter = (TypeParameter) typeParameters.get(0);
+ IBinding binding = typeParameter.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong type", IBinding.TYPE, binding.getKind());
+ ITypeBinding typeBinding = (ITypeBinding) binding;
+ assertEquals("Wrong qualified name", "T", typeBinding.getQualifiedName());
+ }
+
+ /**
+ * Test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=72891
+ */
+ public void test0044() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0044", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List typeParameters = methodDeclaration.typeParameters();
+ assertEquals("wrong size", 1, typeParameters.size());
+ TypeParameter parameter = (TypeParameter) typeParameters.get(0);
+ IBinding binding = parameter.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("wrong type", IBinding.TYPE, binding.getKind());
+ assertEquals("wrong key", "Ltest0044/X;.foo<Z:Ljava/lang/Object;>(TZ;)V:TZ;", binding.getKey());
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ assertNotNull("no binding", methodBinding);
+ assertFalse("Wrong isConstructor", methodBinding.isConstructor());
+ assertFalse("Wrong isDefaultConstructor", methodBinding.isDefaultConstructor());
+ assertFalse("Wrong isDeprecated", methodBinding.isDeprecated());
+ assertTrue("Wrong isGenericMethod", methodBinding.isGenericMethod());
+ assertFalse("Wrong isParameterizedMethod", methodBinding.isParameterizedMethod());
+ assertFalse("Wrong isRawMethod", methodBinding.isRawMethod());
+ assertFalse("Wrong isSynthetic", methodBinding.isSynthetic());
+ assertFalse("Wrong isVarargs", methodBinding.isVarargs());
+ ITypeBinding[] typeParametersBindings = methodBinding.getTypeParameters();
+ assertNotNull("No type parameters", typeParametersBindings);
+ assertEquals("Wrong size", 1, typeParametersBindings.length);
+ ITypeBinding typeBinding = typeParametersBindings[0];
+ assertTrue("Not a type variable", typeBinding.isTypeVariable());
+ assertTrue("Not from source", typeBinding.isFromSource());
+ assertEquals("Wrong fully qualified name", "Z", typeBinding.getQualifiedName());
+ }
+
+ /**
+ * Test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=72891
+ */
+ public void test0045() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0045", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 1, 0, 1);
+ assertEquals("Not a expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertEquals("Not a expression statement", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();
+ assertTrue("Not parameterized", methodBinding.isParameterizedMethod());
+ ITypeBinding[] typeArguments = methodBinding.getTypeArguments();
+ assertNotNull("No type arguments", typeArguments);
+ assertEquals("Wrong size", 1, typeArguments.length);
+ assertEquals("Wrong qualified name", "java.lang.String", typeArguments[0].getQualifiedName());
+ IMethodBinding genericMethod = methodBinding.getMethodDeclaration();
+ assertNotNull("No generic method", genericMethod);
+ assertFalse("Not a parameterized method", genericMethod.isParameterizedMethod());
+ }
+
+ /**
+ * Test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=72889
+ */
+ public void test0046() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0046", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 1);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ Type superclassType = typeDeclaration.getSuperclassType();
+ ITypeBinding typeBinding = superclassType.resolveBinding();
+ assertNotNull("No type binding", typeBinding);
+ String key1 = typeBinding.getKey();
+ node = getASTNode(compilationUnit, 1, 0);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ Type type = fieldDeclaration.getType();
+ typeBinding = type.resolveBinding();
+ assertNotNull("No type binding", typeBinding);
+ String key2 = typeBinding.getKey();
+ assertFalse("Same keys", key1.equals(key2));
+ }
+
+ /**
+ * Test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=72859
+ */
+ public void test0047() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0047", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ }
+
+ /**
+ * Test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=73561
+ */
+ public void test0048() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0048", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertEquals("Not an enum declaration", ASTNode.ENUM_DECLARATION, node.getNodeType());
+ EnumDeclaration enumDeclaration = (EnumDeclaration) node;
+ List enumConstants = enumDeclaration.enumConstants();
+ assertEquals("wrong size", 2, enumConstants.size());
+ EnumConstantDeclaration enumConstantDeclaration = (EnumConstantDeclaration) enumConstants.get(0);
+ IMethodBinding methodBinding = enumConstantDeclaration.resolveConstructorBinding();
+ assertNotNull("No binding", methodBinding);
+ assertTrue("Not a constructor", methodBinding.isConstructor());
+ checkSourceRange(enumConstantDeclaration, "GREEN(0, 1)", source);
+ checkSourceRange(enumConstantDeclaration.getName(), "GREEN", source);
+ enumConstantDeclaration = (EnumConstantDeclaration) enumConstants.get(1);
+ methodBinding = enumConstantDeclaration.resolveConstructorBinding();
+ assertNotNull("No binding", methodBinding);
+ assertTrue("Not a constructor", methodBinding.isConstructor());
+ checkSourceRange(enumConstantDeclaration.getName(), "RED", source);
+ checkSourceRange(enumConstantDeclaration, "RED()", source);
+ }
+
+ /**
+ * Test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=73561
+ */
+ public void test0049() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0049", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertEquals("Not an enum declaration", ASTNode.ENUM_DECLARATION, node.getNodeType());
+ EnumDeclaration enumDeclaration = (EnumDeclaration) node;
+ List enumConstants = enumDeclaration.enumConstants();
+ assertEquals("wrong size", 2, enumConstants.size());
+ EnumConstantDeclaration enumConstantDeclaration = (EnumConstantDeclaration) enumConstants.get(0);
+ IMethodBinding methodBinding = enumConstantDeclaration.resolveConstructorBinding();
+ assertNotNull("No binding", methodBinding);
+ assertTrue("Not a constructor", methodBinding.isConstructor());
+ checkSourceRange(enumConstantDeclaration, "GREEN(0, 1)", source);
+ checkSourceRange(enumConstantDeclaration.getName(), "GREEN", source);
+ enumConstantDeclaration = (EnumConstantDeclaration) enumConstants.get(1);
+ methodBinding = enumConstantDeclaration.resolveConstructorBinding();
+ assertNotNull("No binding", methodBinding);
+ assertTrue("Not a constructor", methodBinding.isConstructor());
+ checkSourceRange(enumConstantDeclaration.getName(), "RED", source);
+ checkSourceRange(enumConstantDeclaration, "RED", source);
+ }
+
+ /**
+ * Ellipsis
+ */
+ public void test0050() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0050", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ final String expectedOutput = "Extended dimensions are illegal for a variable argument";
+ assertProblemsSize(compilationUnit, 1, expectedOutput);
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ assertEquals("Wrong size", 1, parameters.size());
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ assertTrue("Not a varargs", singleVariableDeclaration.isVarargs());
+ final Type type = singleVariableDeclaration.getType();
+ checkSourceRange(type, "String[]", source);
+ assertTrue("not an array type", type.isArrayType());
+ ArrayType arrayType = (ArrayType) type;
+ checkSourceRange(arrayType.getComponentType(), "String", source);
+ assertEquals("Wrong extra dimensions", 1, singleVariableDeclaration.getExtraDimensions());
+ }
+
+ /**
+ * Ellipsis
+ */
+ public void test0051() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0051", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ assertTrue("Not a varargs", methodBinding.isVarargs());
+ List parameters = methodDeclaration.parameters();
+ assertEquals("Wrong size", 1, parameters.size());
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ assertTrue("Not a varargs", singleVariableDeclaration.isVarargs());
+ final Type type = singleVariableDeclaration.getType();
+ checkSourceRange(type, "String[]", source);
+ assertTrue("not an array type", type.isArrayType());
+ ArrayType arrayType = (ArrayType) type;
+ checkSourceRange(arrayType.getComponentType(), "String", source);
+ assertEquals("Wrong extra dimensions", 0, singleVariableDeclaration.getExtraDimensions());
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=76103
+ */
+ public void test0052() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0052", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=76100
+ */
+ public void test0053() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0053", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertEquals("Not an annotation type declaration", ASTNode.ANNOTATION_TYPE_DECLARATION, node.getNodeType());
+ AnnotationTypeDeclaration annotationTypeDeclaration = (AnnotationTypeDeclaration) node;
+ assertNotNull("No javadoc", annotationTypeDeclaration.getJavadoc());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=76100
+ */
+ public void test0054() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0054", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertEquals("Not an annotation type declaration", ASTNode.ENUM_DECLARATION, node.getNodeType());
+ EnumDeclaration enumDeclaration = (EnumDeclaration) node;
+ assertNotNull("No javadoc", enumDeclaration.getJavadoc());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=76100
+ */
+ public void test0055() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0055", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertEquals("Not an annotation type declaration", ASTNode.ANNOTATION_TYPE_DECLARATION, node.getNodeType());
+ AnnotationTypeDeclaration annotationTypeDeclaration = (AnnotationTypeDeclaration) node;
+ assertNotNull("No javadoc", annotationTypeDeclaration.getJavadoc());
+ }
+
+ /**
+ *
+ */
+ public void test0056() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0056", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ final String expectedOutput = "Zork1 cannot be resolved to a type";
+ assertProblemsSize(compilationUnit, 1, expectedOutput);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=77175
+ */
+ public void test0057() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0057", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertEquals("Not an enum declaration", ASTNode.ENUM_DECLARATION, node.getNodeType());
+ EnumDeclaration enumDeclaration = (EnumDeclaration) node;
+ ITypeBinding typeBinding = enumDeclaration.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertTrue("Not an enum type", typeBinding.isEnum());
+ assertTrue("Not a top level type", typeBinding.isTopLevel());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=77249
+ */
+ public void test0058() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0058", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, false, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ assertTrue("Not public type declaration", Modifier.isPublic(typeDeclaration.getModifiers()));
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=77772
+ */
+ public void test0059() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0059", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ }
+
+ /*
+ * Ensures that the type parameters of a method are included in its binding key.
+ * (regression test for 73970 [1.5][dom] overloaded parameterized methods have same method binding key)
+ */
+ public void test0060() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/p/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ "package p;\n" +
+ "/*start*/public class X {\n" +
+ " <T> void foo(T t) {\n" +
+ " }\n" +
+ " <T extends X> void foo(T t) {\n" +
+ " }\n" +
+ " <T extends Class> void foo(T t) {\n" +
+ " }\n" +
+ " <T extends Exception & Runnable> void foo(T t) {\n" +
+ " }\n" +
+ "}/*end*/",
+ this.workingCopy,
+ false);
+ MethodDeclaration[] methods = ((TypeDeclaration) node).getMethods();
+ int length = methods.length;
+ String[] keys = new String[length];
+ for (int i = 0; i < length; i++)
+ keys[i] = methods[i].resolveBinding().getKey();
+ assertBindingKeysEqual(
+ "Lp/X;.foo<T:Ljava/lang/Object;>(TT;)V\n" +
+ "Lp/X;.foo<T:Lp/X;>(TT;)V\n" +
+ "Lp/X;.foo<T:Ljava/lang/Class;>(TT;)V\n" +
+ "Lp/X;.foo<T:Ljava/lang/Exception;:Ljava/lang/Runnable;>(TT;)V",
+ keys);
+ }
+
+ /*
+ * Ensures that the type parameters of a generic type are included in its binding key.
+ * (regression test for 77808 [1.5][dom] type bindings for raw List and List<E> have same key)
+ */
+ public void test0061() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/p/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ "package p;\n" +
+ "/*start*/public class X<T> {\n" +
+ "}/*end*/",
+ this.workingCopy);
+ IBinding binding = ((TypeDeclaration) node).resolveBinding();
+ assertBindingKeyEquals(
+ "Lp/X<TT;>;",
+ binding.getKey());
+ }
+
+ /*
+ * Ensures that the type arguments of a parameterized type are included in its binding key.
+ */
+ public void test0062() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/p/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ "package p;\n" +
+ "public class X<T> {\n" +
+ " /*start*/X<Class>/*end*/ f;\n" +
+ "}",
+ this.workingCopy,
+ false);
+ IBinding binding = ((Type) node).resolveBinding();
+ assertBindingKeyEquals(
+ "Lp/X<Ljava/lang/Class<>;>;",
+ binding.getKey());
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78183
+ */
+ public void test0063() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0063", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertEquals("Wrong node", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertEquals("Wrong qualified name", "test0063.X", typeBinding.getQualifiedName());
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Wrong node", ASTNode.RETURN_STATEMENT, node.getNodeType());
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ typeBinding = expression.resolveTypeBinding();
+ assertTrue("Not parameterized", typeBinding.isParameterizedType());
+ assertEquals("Wrong qualified name", "test0063.X<java.lang.String>", typeBinding.getQualifiedName());
+ node = getASTNode(compilationUnit, 0, 1);
+ assertEquals("Wrong node", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ assertEquals("Wrong size", 1, parameters.size());
+ SingleVariableDeclaration declaration = (SingleVariableDeclaration) parameters.get(0);
+ Type type = declaration.getType();
+ typeBinding = type.resolveBinding();
+ assertEquals("Wrong qualified name", "java.util.List<? extends test0063.X<?>>", typeBinding.getQualifiedName());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78183
+ */
+ public void test0064() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0064", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertEquals("Wrong node", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertEquals("Wrong qualified name", "test0064.X", typeBinding.getQualifiedName());
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Wrong node", ASTNode.RETURN_STATEMENT, node.getNodeType());
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ typeBinding = expression.resolveTypeBinding();
+ assertTrue("Not parameterized", typeBinding.isParameterizedType());
+ assertEquals("Wrong qualified name", "test0064.X<java.lang.String,java.lang.Integer>", typeBinding.getQualifiedName());
+ node = getASTNode(compilationUnit, 0, 1);
+ assertEquals("Wrong node", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ assertEquals("Wrong size", 1, parameters.size());
+ SingleVariableDeclaration declaration = (SingleVariableDeclaration) parameters.get(0);
+ Type type = declaration.getType();
+ typeBinding = type.resolveBinding();
+ assertEquals("Wrong qualified name", "java.util.List<? extends test0064.X<?,?>>", typeBinding.getQualifiedName());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78183
+ */
+ public void test0065() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0065", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertEquals("Wrong node", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertEquals("Wrong qualified name", "test0065.X", typeBinding.getQualifiedName());
+ ITypeBinding genericType = typeBinding.getTypeDeclaration();
+ assertEquals("Wrong qualified name", "test0065.X", genericType.getQualifiedName());
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Wrong node", ASTNode.RETURN_STATEMENT, node.getNodeType());
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ typeBinding = expression.resolveTypeBinding();
+ assertTrue("Not parameterized", typeBinding.isParameterizedType());
+ assertEquals("Wrong qualified name", "test0065.X<java.lang.String,java.util.List<?>>", typeBinding.getQualifiedName());
+ node = getASTNode(compilationUnit, 0, 1);
+ assertEquals("Wrong node", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ assertEquals("Wrong size", 1, parameters.size());
+ SingleVariableDeclaration declaration = (SingleVariableDeclaration) parameters.get(0);
+ Type type = declaration.getType();
+ typeBinding = type.resolveBinding();
+ assertEquals("Wrong qualified name", "java.util.List<? extends test0065.X<?,?>>", typeBinding.getQualifiedName());
+ }
+
+ /*
+ * Ensures that a raw type doesn't include the type parameters in its binding key.
+ * (regression test for 77808 [1.5][dom] type bindings for raw List and List<E> have same key)
+ */
+ public void test0066() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/p/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ "package p;\n" +
+ "public class X<T> {\n" +
+ " /*start*/X/*end*/ field;" +
+ "}",
+ this.workingCopy,
+ false);
+ IBinding binding = ((Type) node).resolveBinding();
+ assertBindingKeyEquals(
+ "Lp/X<>;",
+ binding.getKey());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78649
+ */
+ public void test0067() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0067", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Wrong node", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ assertEquals("Wrong size", 1, parameters.size());
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ Type type = singleVariableDeclaration.getType();
+ assertTrue("Not a parameterized type", type.isParameterizedType());
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ List typeArguments = parameterizedType.typeArguments();
+ assertEquals("Wrong size", 1, typeArguments.size());
+ Type type2 = (Type) typeArguments.get(0);
+ assertTrue("Not a wildcard type", type2.isWildcardType());
+ WildcardType wildcardType = (WildcardType) type2;
+ assertTrue("Not an upperbound type", wildcardType.isUpperBound());
+ ITypeBinding typeBinding = wildcardType.resolveBinding();
+ assertTrue("Not an upperbound type binding", typeBinding.isUpperbound());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78649
+ */
+ public void test0068() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0068", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Wrong node", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ assertEquals("Wrong size", 1, parameters.size());
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ Type type = singleVariableDeclaration.getType();
+ assertTrue("Not a parameterized type", type.isParameterizedType());
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ List typeArguments = parameterizedType.typeArguments();
+ assertEquals("Wrong size", 1, typeArguments.size());
+ Type type2 = (Type) typeArguments.get(0);
+ assertTrue("Not a wildcard type", type2.isWildcardType());
+ WildcardType wildcardType = (WildcardType) type2;
+ assertFalse("An upperbound type", wildcardType.isUpperBound());
+ ITypeBinding typeBinding = wildcardType.resolveBinding();
+ assertFalse("An upperbound type binding", typeBinding.isUpperbound());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78934
+ */
+ public void test0069() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0069", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 1, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ Type type = statement.getType();
+ assertTrue("Not a parameterized type", type.isParameterizedType());
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ assertNotNull("No binding", parameterizedType.resolveBinding());
+ Type type2 = parameterizedType.getType();
+ assertTrue("Not a qualified type", type2.isQualifiedType());
+ QualifiedType qualifiedType = (QualifiedType) type2;
+ ITypeBinding typeBinding = qualifiedType.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertEquals("Wrong name 1", "test0069.Outer<java.lang.String>.Inner<java.lang.Integer>", typeBinding.getQualifiedName());
+ SimpleName simpleName = qualifiedType.getName();
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", simpleName.resolveBinding());
+ assertEquals("Wrong name 2", "test0069.Outer<java.lang.String>.Inner<java.lang.Integer>", typeBinding.getQualifiedName());
+ Type type3 = qualifiedType.getQualifier();
+ assertTrue("Not a parameterized type", type3.isParameterizedType());
+ ParameterizedType parameterizedType2 = (ParameterizedType) type3;
+ typeBinding = parameterizedType2.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertEquals("Wrong name 3", "test0069.Outer<java.lang.String>", typeBinding.getQualifiedName());
+ Type type4 = parameterizedType2.getType();
+ assertTrue("Not a simple type", type4.isSimpleType());
+ SimpleType simpleType = (SimpleType) type4;
+ assertNotNull("No binding", simpleType.resolveBinding());
+ Name name = simpleType.getName();
+ assertTrue("Not a qualified name", name.isQualifiedName());
+ QualifiedName qualifiedName = (QualifiedName) name;
+ assertNotNull("No binding", qualifiedName.resolveBinding());
+ Name name2 = qualifiedName.getQualifier();
+ assertTrue("Not a simpleName", name2.isSimpleName());
+ SimpleName simpleName2 = (SimpleName) name2;
+ binding = simpleName2.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("wrong type", IBinding.PACKAGE, binding.getKind());
+ SimpleName simpleName3 = qualifiedName.getName();
+ assertNotNull("No binding", simpleName3.resolveBinding());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78934
+ */
+ public void test0070() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0070", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 1, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ Type type = statement.getType();
+ assertTrue("Not a parameterized type", type.isParameterizedType());
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ assertNotNull("No binding", parameterizedType.resolveBinding());
+ Type type2 = parameterizedType.getType();
+ assertTrue("Not a qualified type", type2.isQualifiedType());
+ QualifiedType qualifiedType = (QualifiedType) type2;
+ ITypeBinding typeBinding = qualifiedType.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertEquals("Wrong name 1", "test0070.Outer<java.lang.String>.Inner<java.lang.Number>", typeBinding.getQualifiedName());
+ SimpleName simpleName = qualifiedType.getName();
+ typeBinding = simpleName.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding);
+ assertEquals("Wrong name 2", "test0070.Outer<java.lang.String>.Inner<java.lang.Number>", typeBinding.getQualifiedName());
+ Type type3 = qualifiedType.getQualifier();
+ assertTrue("Not a parameterized type", type3.isParameterizedType());
+ ParameterizedType parameterizedType2 = (ParameterizedType) type3;
+ typeBinding = parameterizedType2.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertEquals("Wrong name 3", "test0070.Outer<java.lang.String>", typeBinding.getQualifiedName());
+ Type type4 = parameterizedType2.getType();
+ assertTrue("Not a simple type", type4.isSimpleType());
+ SimpleType simpleType = (SimpleType) type4;
+ typeBinding = simpleType.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertEquals("Wrong name 3", "test0070.Outer<java.lang.String>", typeBinding.getQualifiedName());
+ Name name = simpleType.getName();
+ assertTrue("Not a simpleName", name.isSimpleName());
+ SimpleName simpleName2 = (SimpleName) name;
+ typeBinding = simpleName2.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding);
+ assertEquals("Wrong name 3", "test0070.Outer", typeBinding.getQualifiedName());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78930
+ */
+ public void test0071() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0071", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List typeParameters = methodDeclaration.typeParameters();
+ assertEquals("wrong size", 1, typeParameters.size());
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ ITypeBinding[] typeBindings = methodBinding.getTypeParameters();
+ assertEquals("wrong size", 1, typeBindings.length);
+ ITypeBinding typeBinding = typeBindings[0];
+ IJavaElement javaElement = typeBinding.getJavaElement();
+ assertNotNull("No java element", javaElement);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=77645
+ */
+ public void test0072() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15", "src", "test0072", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertProblemsSize(unit, 0);
+ unit.accept(new ASTVisitor() {
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.SingleVariableDeclaration)
+ */
+ public boolean visit(SingleVariableDeclaration node) {
+ IVariableBinding binding = node.resolveBinding();
+ assertNotNull("No method", binding.getDeclaringMethod());
+ return false;
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.VariableDeclarationFragment)
+ */
+ public boolean visit(VariableDeclarationFragment node) {
+ IVariableBinding binding = node.resolveBinding();
+ ASTNode parent = node.getParent();
+ if (parent != null && binding != null) {
+ final IMethodBinding declaringMethod = binding.getDeclaringMethod();
+ final String variableBindingName = binding.getName();
+ switch(parent.getNodeType()) {
+ case ASTNode.FIELD_DECLARATION :
+ assertNull("Got a method", declaringMethod);
+ break;
+ default :
+ if (variableBindingName.equals("var1")
+ || variableBindingName.equals("var2")) {
+ assertNull("Got a method", declaringMethod);
+ } else {
+ assertNotNull("No method", declaringMethod);
+ String methodName = declaringMethod.getName();
+ if (variableBindingName.equals("var4")) {
+ assertEquals("Wrong method", "foo", methodName);
+ } else if (variableBindingName.equals("var5")) {
+ assertEquals("Wrong method", "foo2", methodName);
+ } else if (variableBindingName.equals("var7")) {
+ assertEquals("Wrong method", "foo3", methodName);
+ } else if (variableBindingName.equals("var8")) {
+ assertEquals("Wrong method", "X", methodName);
+ } else if (variableBindingName.equals("var9")) {
+ assertEquals("Wrong method", "bar3", methodName);
+ } else if (variableBindingName.equals("var10")) {
+ assertEquals("Wrong method", "bar3", methodName);
+ } else if (variableBindingName.equals("var11")) {
+ assertEquals("Wrong method", "bar3", methodName);
+ } else if (variableBindingName.equals("var12")) {
+ assertEquals("Wrong method", "X", methodName);
+ }
+ }
+ }
+ }
+ return false;
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.FieldAccess)
+ */
+ public boolean visit(FieldAccess node) {
+ IVariableBinding binding = node.resolveFieldBinding();
+ assertNull("No method", binding.getDeclaringMethod());
+ return false;
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.SuperFieldAccess)
+ */
+ public boolean visit(SuperFieldAccess node) {
+ IVariableBinding binding = node.resolveFieldBinding();
+ assertNull("No method", binding.getDeclaringMethod());
+ return false;
+ }
+ });
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=77806
+ */
+ public void test0073() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0073", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Type type = methodDeclaration.getReturnType2();
+ assertTrue("Not a parameterized type", type.isParameterizedType());
+ assertNotNull("No binding", type.resolveBinding());
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ ITypeBinding binding = parameterizedType.resolveBinding();
+ assertNotNull("No binding", binding);
+ Type type2 = parameterizedType.getType();
+ assertTrue("Not a simple type", type2.isSimpleType());
+ ITypeBinding binding2 = type2.resolveBinding();
+ assertNotNull("No binding", binding2);
+ SimpleType simpleType = (SimpleType) type2;
+ Name name = simpleType.getName();
+ assertTrue("Not a simpleName", name.isSimpleName());
+ SimpleName simpleName = (SimpleName) name;
+ ITypeBinding binding3 = simpleName.resolveTypeBinding();
+ assertNotNull("No binding", binding3);
+ assertTrue("Different binding", binding3.isEqualTo(binding));
+ assertTrue("Different binding", binding2.isEqualTo(binding));
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78934
+ */
+ public void test0074() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0074", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Type type = methodDeclaration.getReturnType2();
+ assertTrue("Not a parameterized type", type.isParameterizedType());
+ assertNotNull("No binding", type.resolveBinding());
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ Type type2 = parameterizedType.getType();
+ assertTrue("Not a simple type", type2.isSimpleType());
+ final ITypeBinding binding = type2.resolveBinding();
+ assertNotNull("No binding", binding);
+ SimpleType simpleType = (SimpleType) type2;
+ Name name = simpleType.getName();
+ assertTrue("Not a qualified name", name.isQualifiedName());
+ QualifiedName qualifiedName = (QualifiedName) name;
+ SimpleName simpleName = qualifiedName.getName();
+ ITypeBinding binding2 = simpleName.resolveTypeBinding();
+ assertNotNull("No binding", binding2);
+ assertTrue("Different binding", binding2.isEqualTo(binding));
+ assertEquals("wrong name", "java.util.List<java.lang.String>", binding2.getQualifiedName());
+ Name name2 = qualifiedName.getQualifier();
+ assertTrue("Not a qualified name", name2.isQualifiedName());
+ QualifiedName qualifiedName2 = (QualifiedName) name2;
+ IBinding binding3 = qualifiedName2.resolveBinding();
+ assertNotNull("No binding", binding3);
+ assertEquals("wrong kind", IBinding.PACKAGE, binding3.getKind());
+ assertEquals("wrong name2", "java.util", binding3.getName());
+ simpleName = qualifiedName2.getName();
+ binding3 = simpleName.resolveBinding();
+ assertNotNull("No binding", binding3);
+ assertEquals("wrong kind", IBinding.PACKAGE, binding3.getKind());
+ assertEquals("wrong name2", "java.util", binding3.getName());
+ name2 = qualifiedName2.getQualifier();
+ assertTrue("Not a simple name", name2.isSimpleName());
+ simpleName = (SimpleName) name2;
+ binding3 = simpleName.resolveBinding();
+ assertNotNull("No binding", binding3);
+ assertEquals("wrong kind", IBinding.PACKAGE, binding3.getKind());
+ assertEquals("wrong name2", "java", binding3.getName());
+ }
+
+ /*
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=79271
+ */
+ public void test0075() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/p/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ "package p;\n" +
+ "import java.util.ArrayList;\n" +
+ "public class X {\n" +
+ " /*start*/ArrayList<Integer>/*end*/ field;" +
+ "}",
+ this.workingCopy);
+ ITypeBinding binding = ((Type) node).resolveBinding();
+ ITypeBinding genericType = binding.getTypeDeclaration();
+ assertFalse("Equals", binding.isEqualTo(genericType));
+ }
+
+ /*
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=79362
+ */
+ public void test0076() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0076", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ String expectedOutput = "Type mismatch: cannot convert from Map[] to Map<String,Double>[][]";
+ assertProblemsSize(compilationUnit, 1, expectedOutput);
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Wrong type", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ Type type = fieldDeclaration.getType();
+ checkSourceRange(type, "Map<String, Double>[][]", source);
+ assertEquals("wrong type", ASTNode.ARRAY_TYPE, type.getNodeType());
+ ArrayType arrayType = (ArrayType) type;
+ type = arrayType.getComponentType();
+ checkSourceRange(type, "Map<String, Double>[]", source);
+ assertEquals("wrong type", ASTNode.ARRAY_TYPE, type.getNodeType());
+ arrayType = (ArrayType) type;
+ type = arrayType.getComponentType();
+ checkSourceRange(type, "Map<String, Double>", source);
+ }
+
+ /*
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=79362
+ */
+ public void test0077() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0077", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ String expectedOutput = "Type mismatch: cannot convert from Map[] to Map<String,Double>[][]";
+ assertProblemsSize(compilationUnit, 1, expectedOutput);
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Wrong type", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ Type type = fieldDeclaration.getType();
+ checkSourceRange(type, "java.util.Map<String, Double>[][]", source);
+ assertEquals("wrong type", ASTNode.ARRAY_TYPE, type.getNodeType());
+ ArrayType arrayType = (ArrayType) type;
+ type = arrayType.getComponentType();
+ checkSourceRange(type, "java.util.Map<String, Double>[]", source);
+ assertEquals("wrong type", ASTNode.ARRAY_TYPE, type.getNodeType());
+ arrayType = (ArrayType) type;
+ type = arrayType.getComponentType();
+ checkSourceRange(type, "java.util.Map<String, Double>", source);
+ }
+
+ /*
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=79460
+ */
+ public void test0078() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/p/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ "package p;\n" +
+ "public class X<T> {\n" +
+ " String foo(int i) { return /*start*/Integer.toString(i)/*end*/;}" +
+ "}",
+ this.workingCopy);
+ IMethodBinding methodBinding = ((MethodInvocation) node).resolveMethodBinding();
+ assertFalse("Is a raw method", methodBinding.isRawMethod());
+ assertFalse("Is a parameterized method", methodBinding.isParameterizedMethod());
+ assertFalse("Is a generic method", methodBinding.isGenericMethod());
+ }
+
+ /*
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=79460
+ */
+ public void test0079() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/p/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ "package p;\n" +
+ "public class X {\n" +
+ " \n" +
+ " /*start*/<T extends A> T foo(T t) {\n" +
+ " return t;\n" +
+ " }/*end*/\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().bar();\n" +
+ " }\n" +
+ " void bar() {\n" +
+ " B b = foo(new B());\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "class A {}\n" +
+ "class B extends A {}\n",
+ this.workingCopy);
+ IMethodBinding methodBinding = ((MethodDeclaration) node).resolveBinding();
+ assertFalse("Is a raw method", methodBinding.isRawMethod());
+ assertFalse("Is a parameterized method", methodBinding.isParameterizedMethod());
+ assertTrue("Not a generic method", methodBinding.isGenericMethod());
+ }
+
+ /*
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=79460
+ */
+ public void test0080() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/p/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ "package p;\n" +
+ "public class X {\n" +
+ " \n" +
+ " <T extends A> T foo(T t) {\n" +
+ " return t;\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().bar();\n" +
+ " }\n" +
+ " void bar() {\n" +
+ " B b = /*start*/foo(new B())/*end*/;\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "class A {}\n" +
+ "class B extends A {}\n",
+ this.workingCopy);
+ IMethodBinding methodBinding = ((MethodInvocation) node).resolveMethodBinding();
+ assertFalse("Is a raw method", methodBinding.isRawMethod());
+ assertTrue("Not a parameterized method", methodBinding.isParameterizedMethod());
+ assertFalse("Is a generic method", methodBinding.isGenericMethod());
+ }
+
+ /*
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=79460
+ */
+ public void test0081() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0081", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ String expectedOutput =
+ "Class is a raw type. References to generic type Class<T> should be parameterized\n" +
+ "Class is a raw type. References to generic type Class<T> should be parameterized\n" +
+ "Type safety: The method foo(Object) belongs to the raw type Y. References to generic type Y<T> should be parameterized\n" +
+ "Y is a raw type. References to generic type Y<T> should be parameterized";
+ assertProblemsSize(compilationUnit, 4, expectedOutput);
+ ASTNode node = getASTNode(compilationUnit, 1, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not an method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();
+ assertEquals("Wrong name", "foo", methodBinding.getName());
+ assertTrue("Not a raw method", methodBinding.isRawMethod());
+ assertFalse("Is a parameterized method", methodBinding.isParameterizedMethod());
+ assertFalse("Is a generic method", methodBinding.isGenericMethod());
+ assertFalse("Doesn't override itself", methodBinding.overrides(methodBinding));
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78183
+ */
+ public void test0082() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0082", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ String expectedOutput =
+ "Gen is a raw type. References to generic type Gen<X> should be parameterized\n" +
+ "Gen.Inn is a raw type. References to generic type Gen<X>.Inn should be parameterized";
+ assertProblemsSize(compilationUnit, 2, expectedOutput);
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertEquals("Wrong name", "Gen", typeBinding.getName());
+ assertEquals("Wrong name", "test0082.Gen", typeBinding.getQualifiedName());
+ assertTrue("Not a class", typeBinding.isClass());
+ assertTrue("Not a generic type", typeBinding.isGenericType());
+ assertTrue("Not a top level", typeBinding.isTopLevel());
+
+ node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a member type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ typeDeclaration = (TypeDeclaration) node;
+ typeBinding = typeDeclaration.resolveBinding();
+ assertEquals("Wrong name", "Inn", typeBinding.getName());
+ assertEquals("Wrong name", "test0082.Gen.Inn", typeBinding.getQualifiedName());
+ assertTrue("Not a class", typeBinding.isClass());
+ assertTrue("Not a member", typeBinding.isMember());
+ assertTrue("Not a nested class", typeBinding.isNested());
+
+ node = getASTNode(compilationUnit, 0, 1);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ typeBinding = fieldDeclaration.getType().resolveBinding();
+ assertEquals("Wrong name", "Gen<String>", typeBinding.getName());
+ assertEquals("Wrong name", "test0082.Gen<java.lang.String>", typeBinding.getQualifiedName());
+ assertTrue("Not a class", typeBinding.isClass());
+ assertTrue("Not a parameterized type", typeBinding.isParameterizedType());
+ assertTrue("Not a toplevel", typeBinding.isTopLevel());
+
+ node = getASTNode(compilationUnit, 0, 2);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ fieldDeclaration = (FieldDeclaration) node;
+ typeBinding = fieldDeclaration.getType().resolveBinding();
+ assertEquals("Wrong name", "Inn", typeBinding.getName());
+ assertEquals("Wrong name", "test0082.Gen<java.lang.String>.Inn", typeBinding.getQualifiedName());
+ assertTrue("Not a class", typeBinding.isClass());
+ assertTrue("Not a member", typeBinding.isMember());
+ assertTrue("Not a nested class", typeBinding.isNested());
+ assertFalse("Is parameterized", typeBinding.isParameterizedType());
+
+ node = getASTNode(compilationUnit, 0, 3);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ fieldDeclaration = (FieldDeclaration) node;
+ typeBinding = fieldDeclaration.getType().resolveBinding();
+ assertEquals("Wrong name", "Gen", typeBinding.getName());
+ assertEquals("Wrong name", "test0082.Gen", typeBinding.getQualifiedName());
+ assertTrue("Not a class", typeBinding.isClass());
+ assertTrue("Not a raw type", typeBinding.isRawType());
+ assertTrue("Not a toplevel", typeBinding.isTopLevel());
+
+ node = getASTNode(compilationUnit, 0, 4);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ fieldDeclaration = (FieldDeclaration) node;
+ typeBinding = fieldDeclaration.getType().resolveBinding();
+ assertEquals("Wrong name", "Inn", typeBinding.getName());
+ assertEquals("Wrong name", "test0082.Gen.Inn", typeBinding.getQualifiedName());
+ assertTrue("Not a class", typeBinding.isClass());
+ assertTrue("Not a member", typeBinding.isMember());
+ assertTrue("Not a nested type", typeBinding.isNested());
+ assertFalse("Is parameterized", typeBinding.isParameterizedType());
+ }
+
+ /*
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=79544
+ */
+ public void test0083() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0083", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ ITypeBinding typeBinding = fieldDeclaration.getType().resolveBinding();
+
+ node = getASTNode(compilationUnit, 0, 1);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ fieldDeclaration = (FieldDeclaration) node;
+ ITypeBinding typeBinding2 = fieldDeclaration.getType().resolveBinding();
+
+ node = getASTNode(compilationUnit, 0, 2);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ fieldDeclaration = (FieldDeclaration) node;
+ ITypeBinding typeBinding3 = fieldDeclaration.getType().resolveBinding();
+
+ node = getASTNode(compilationUnit, 0, 3);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ fieldDeclaration = (FieldDeclaration) node;
+ ITypeBinding typeBinding4 = fieldDeclaration.getType().resolveBinding();
+
+ assertFalse("Binding are equals", typeBinding.isEqualTo(typeBinding2));
+ assertFalse("Binding are equals", typeBinding.isEqualTo(typeBinding3));
+ assertFalse("Binding are equals", typeBinding.isEqualTo(typeBinding4));
+ assertFalse("Binding are equals", typeBinding2.isEqualTo(typeBinding3));
+ assertFalse("Binding are equals", typeBinding2.isEqualTo(typeBinding4));
+ assertFalse("Binding are equals", typeBinding3.isEqualTo(typeBinding4));
+ }
+
+ /*
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=79612
+ */
+ public void test0084() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0084", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ ITypeBinding typeBinding = fieldDeclaration.getType().resolveBinding();
+
+ node = getASTNode(compilationUnit, 0, 1);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ fieldDeclaration = (FieldDeclaration) node;
+ ITypeBinding typeBinding2 = fieldDeclaration.getType().resolveBinding();
+
+ assertFalse("Binding are equals", typeBinding.isEqualTo(typeBinding2));
+ }
+
+ /*
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=79609
+ */
+ public void test0085() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0085", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List typeParameters = methodDeclaration.typeParameters();
+ assertEquals("wrong size", 1, typeParameters.size());
+ TypeParameter typeParameter = (TypeParameter) typeParameters.get(0);
+ IBinding binding = typeParameter.resolveBinding();
+ assertEquals("wrong type", IBinding.TYPE, binding.getKind());
+ ITypeBinding typeBinding = (ITypeBinding) binding;
+
+ node = getASTNode(compilationUnit, 0, 1);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ methodDeclaration = (MethodDeclaration) node;
+ typeParameters = methodDeclaration.typeParameters();
+ assertEquals("wrong size", 1, typeParameters.size());
+ typeParameter = (TypeParameter) typeParameters.get(0);
+ binding = typeParameter.resolveBinding();
+ assertEquals("wrong type", IBinding.TYPE, binding.getKind());
+ ITypeBinding typeBinding2 = (ITypeBinding) binding;
+
+ assertFalse("Binding are equals", typeBinding.isEqualTo(typeBinding2));
+ }
+ /*
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=79512
+ */
+ public void test0086() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/p/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ "package p;\n" +
+ "public class X {\n" +
+ " \n" +
+ "public Object foo() {\n" +
+ " return /*start*/X.class/*end*/;\n" +
+ " }" +
+ "}\n" +
+ "\n" +
+ "class A {}\n" +
+ "class B extends A {}\n",
+ this.workingCopy);
+ TypeLiteral typeLiteral = (TypeLiteral) node;
+ ITypeBinding typeBinding = typeLiteral.resolveTypeBinding();
+ assertEquals("Wrong name", "java.lang.Class<p.X>", typeBinding.getQualifiedName());
+ assertEquals("Wrong name", "Class<X>", typeBinding.getName());
+ }
+
+ /*
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=79775
+ */
+ public void test0087() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/p/X.java", true/*resolve*/);
+ buildAST(
+ "package p;\n" +
+ "public class X<T1> {\n" +
+ " public <M1> X() {\n" +
+ " }\n" +
+ " class Y<T2> {\n" +
+ " public <M2> Y() {\n" +
+ " }\n" +
+ " }\n" +
+ " void foo() {\n" +
+ " new <Object>X<Object>().new <Object>Y<Object>();\n" +
+ " }\n" +
+ "}\n",
+ this.workingCopy);
+ }
+
+ /*
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=79690
+ */
+ public void test0088() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0088", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Wrong type", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ Type type = statement.getType();
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertEquals("Wrong name", "E", typeBinding.getName());
+ assertTrue("Not a type variable", typeBinding.isTypeVariable());
+ assertTrue("Not from source", typeBinding.isFromSource());
+ ASTNode node2 = compilationUnit.findDeclaringNode(typeBinding);
+ assertNotNull("No declaring node", node2);
+ ASTNode node3 = compilationUnit.findDeclaringNode(typeBinding.getKey());
+ assertNotNull("No declaring node", node3);
+ assertTrue("Nodes don't match", node2.subtreeMatch(new ASTMatcher(), node3));
+ node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Wrong type", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List typeParameters = methodDeclaration.typeParameters();
+ assertEquals("Wrong size", 1, typeParameters.size());
+ TypeParameter typeParameter = (TypeParameter) typeParameters.get(0);
+ assertTrue("Nodes don't match", typeParameter.subtreeMatch(new ASTMatcher(), node3));
+ assertTrue("Nodes don't match", typeParameter.subtreeMatch(new ASTMatcher(), node2));
+ }
+
+ /*
+ * Ensures that a parameterized method binding (with a wildcard parameter) doesn't throw a NPE when computing its binding key.
+ * (regression test for 79967 NPE in WildcardBinding.signature with Mark Occurrences in Collections.class)
+ */
+ public void test0089() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/p/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ "package p;\n" +
+ "public class X<T> {\n" +
+ " void foo() {\n" +
+ " }\n" +
+ " void bar(X<?> x) {\n" +
+ " /*start*/x.foo()/*end*/;\n"+
+ " }\n" +
+ "}",
+ this.workingCopy);
+ IBinding binding = ((MethodInvocation) node).resolveMethodBinding();
+ assertBindingKeyEquals(
+ "Lp/X<!Lp/X;{0}*75;>;.foo()V",
+ binding.getKey());
+ }
+
+ /*
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=80021
+ */
+ public void test0090() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/p/X.java", true/*resolve*/);
+ ASTNode result = buildAST(
+ "package p;\n" +
+ "public class X {\n" +
+ " public void foo() {}\n" +
+ " public void bar(X x, int f) {\n" +
+ " x.foo();\n" +
+ " }\n" +
+ "}",
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ compilationUnit.accept(new ASTVisitor() {
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.SingleVariableDeclaration)
+ */
+ public boolean visit(SingleVariableDeclaration node) {
+ IVariableBinding binding = node.resolveBinding();
+ assertNotNull("No binding", binding);
+ IJavaElement javaElement = binding.getJavaElement();
+ assertNotNull("No java element", javaElement);
+ return false;
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.VariableDeclarationFragment)
+ */
+ public boolean visit(VariableDeclarationFragment node) {
+ IVariableBinding binding = node.resolveBinding();
+ assertNotNull("No binding", binding);
+ IJavaElement javaElement = binding.getJavaElement();
+ assertNotNull("No java element", javaElement);
+ return false;
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.FieldAccess)
+ */
+ public boolean visit(FieldAccess node) {
+ IVariableBinding binding = node.resolveFieldBinding();
+ assertNotNull("No binding", binding);
+ IJavaElement javaElement = binding.getJavaElement();
+ assertNotNull("No java element", javaElement);
+ return false;
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.SuperFieldAccess)
+ */
+ public boolean visit(SuperFieldAccess node) {
+ IVariableBinding binding = node.resolveFieldBinding();
+ assertNotNull("No binding", binding);
+ IJavaElement javaElement = binding.getJavaElement();
+ assertNotNull("No java element", javaElement);
+ return false;
+ }
+ });
+ }
+
+ /*
+ * Check bindings for annotation type declaration
+ */
+ public void test0091() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/p/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ "package p;\n" +
+ "@interface X {\n" +
+ " int id() default 0;\n" +
+ "}",
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ node = getASTNode(compilationUnit, 0);
+ assertEquals("Not an annotation type declaration", ASTNode.ANNOTATION_TYPE_DECLARATION, node.getNodeType());
+ AnnotationTypeDeclaration annotationTypeDeclaration = (AnnotationTypeDeclaration) node;
+ ITypeBinding binding = annotationTypeDeclaration.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertTrue("Not an annotation", binding.isAnnotation());
+ assertEquals("Wrong name", "X", binding.getName());
+ node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not an annotation type member declaration", ASTNode.ANNOTATION_TYPE_MEMBER_DECLARATION, node.getNodeType());
+ AnnotationTypeMemberDeclaration memberDeclaration = (AnnotationTypeMemberDeclaration) node;
+ IMethodBinding methodBinding = memberDeclaration.resolveBinding();
+ assertNotNull("No binding", methodBinding);
+ assertEquals("Wrong name", "id", methodBinding.getName());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=80960
+ */
+ public void test0092() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/p/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ "import java.util.*;\n" +
+ "public class X {\n" +
+ " public enum Rank { DEUCE, THREE, FOUR, FIVE, SIX,\n" +
+ " SEVEN, EIGHT, NINE, TEN, JACK, QUEEN, KING, ACE }\n" +
+ "\n" +
+ " //public enum Suit { CLUBS, DIAMONDS, HEARTS, SPADES }\n" +
+ " public enum Suit{\n" +
+ "\n" +
+ " private X(int rank, int suit) { \n" +
+ " }\n" +
+ " \n" +
+ " private static final List<X> protoDeck = new ArrayList<X>();\n" +
+ " \n" +
+ " public static ArrayList<X> newDeck() {\n" +
+ " return new ArrayList<X>(protoDeck); // Return copy of prototype deck\n" +
+ " }\n" +
+ "}",
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=81023
+ */
+ public void test0093() throws JavaModelException {
+ String contents =
+ "public class Test {\n" +
+ " public <U> Test(U u) {\n" +
+ " }\n" +
+ "\n" +
+ " void bar() {\n" +
+ " new <String> Test(null) {};\n" +
+ " }\n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/Test.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ node = getASTNode(compilationUnit, 0, 1, 0);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement statement = (ExpressionStatement) node;
+ Expression expression = statement.getExpression();
+ checkSourceRange(expression, "new <String> Test(null) {}", contents.toCharArray());
+ ITypeBinding typeBinding = expression.resolveTypeBinding();
+ IJavaElement element = typeBinding.getJavaElement();
+ assertNotNull("No java element", element);
+ }
+
+
+ public void test0094() throws JavaModelException {
+ String contents =
+ "import java.lang.annotation.Target;\n" +
+ "import java.lang.annotation.Retention;\n" +
+ "\n" +
+ "@Retention(RetentionPolicy.SOURCE)\n" +
+ "@Target(ElementType.METHOD)\n" +
+ "@interface ThrowAwayMethod {\n" +
+ "\n" +
+ " /**\n" +
+ " * Comment for <code>test</code>\n" +
+ " */\n" +
+ " protected final Test test;\n" +
+ "\n" +
+ " /**\n" +
+ " * @param test\n" +
+ " */\n" +
+ " ThrowAwayMethod(Test test) {\n" +
+ " this.test= test;\n" +
+ " }\n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/ThrowAwayMethod.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ }
+
+ /*
+ * Ensures that resolving a generic method with a non existing parameter type doesn't throw a NPE when computing its binding key.
+ * (regression test for 81134 [dom] [5.0] NPE when creating AST
+ */
+ public void test0095() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " /*start*/<T> void foo(NonExisting arg) {\n" +
+ " }/*end*/\n" +
+ "}",
+ this.workingCopy,
+ false,
+ false,
+ true);
+ IMethodBinding methodBinding = ((MethodDeclaration) node).resolveBinding();
+ assertNotNull("No binding", methodBinding);
+ assertEquals("LX;.foo<T:Ljava/lang/Object;>(LNonExisting;)V", methodBinding.getKey());
+ assertFalse("Method should not be flagged as recovered", methodBinding.isRecovered());
+ assertTrue("Method argument type should be flagged as recovered", methodBinding.getParameterTypes()[0].isRecovered());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82140
+ */
+ public void test0096() throws JavaModelException {
+ String contents =
+ "public @interface An1 {\n" +
+ " String value();\n" +
+ " String item() default \"Hello\";\n" +
+ "\n" +
+ "}\n" +
+ "\n" +
+ "@An1(value=\"X\") class A {\n" +
+ " \n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/An1.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ node = getASTNode(compilationUnit, 1);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ assertEquals("Wrong name", "A", typeDeclaration.getName().getIdentifier());
+ List modifiers = typeDeclaration.modifiers();
+ assertEquals("Wrong size", 1, modifiers.size());
+ IExtendedModifier modifier = (IExtendedModifier) modifiers.get(0);
+ assertTrue("Not an annotation", modifier instanceof Annotation);
+ checkSourceRange((Annotation) modifier, "@An1(value=\"X\")", contents.toCharArray());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82140
+ */
+ public void test0097() throws JavaModelException {
+ String contents =
+ "@interface An1 {}\n" +
+ "@interface An2 {}\n" +
+ "@interface An3 {}\n" +
+ "@An2 class X {\n" +
+ " @An1 Object o;\n" +
+ " @An3 void foo() {\n" +
+ " \n" +
+ " }\n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 3);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ List modifiers = typeDeclaration.modifiers();
+ assertEquals("Wrong size", 1, modifiers.size());
+ IExtendedModifier modifier = (IExtendedModifier) modifiers.get(0);
+ assertTrue("Not an annotation", modifier instanceof Annotation);
+ checkSourceRange((Annotation) modifier, "@An2", contents.toCharArray());
+
+ node = getASTNode(compilationUnit, 3, 0);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ modifiers = fieldDeclaration.modifiers();
+ assertEquals("Wrong size", 1, modifiers.size());
+ modifier = (IExtendedModifier) modifiers.get(0);
+ assertTrue("Not an annotation", modifier instanceof Annotation);
+ checkSourceRange((Annotation) modifier, "@An1", contents.toCharArray());
+
+ node = getASTNode(compilationUnit, 3, 1);
+ assertEquals("Not a field declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ modifiers = methodDeclaration.modifiers();
+ assertEquals("Wrong size", 1, modifiers.size());
+ modifier = (IExtendedModifier) modifiers.get(0);
+ assertTrue("Not an annotation", modifier instanceof Annotation);
+ checkSourceRange((Annotation) modifier, "@An3", contents.toCharArray());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82140
+ */
+ public void test0098() throws JavaModelException {
+ String contents =
+ "class X {\n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ List modifiers = typeDeclaration.modifiers();
+ assertEquals("Wrong size", 0, modifiers.size());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82141
+ */
+ public void test0099() throws JavaModelException {
+ String contents =
+ "public class X {\n" +
+ " @Override @Annot(value=\"Hello\") public String toString() {\n" +
+ " return super.toString();\n" +
+ " }\n" +
+ " @Annot(\"Hello\") void bar() {\n" +
+ " }\n" +
+ " @interface Annot {\n" +
+ " String value();\n" +
+ " }\n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List modifiers = methodDeclaration.modifiers();
+ assertEquals("Wrong size", 3, modifiers.size());
+ IExtendedModifier modifier = (IExtendedModifier) modifiers.get(0);
+ assertTrue("Wrong type", modifier instanceof Annotation);
+ Annotation annotation = (Annotation) modifier;
+ ITypeBinding binding = annotation.resolveTypeBinding();
+ assertNotNull("No binding", binding);
+
+ modifier = (IExtendedModifier) modifiers.get(1);
+ assertTrue("Wrong type", modifier instanceof Annotation);
+ annotation = (Annotation) modifier;
+ binding = annotation.resolveTypeBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong type", ASTNode.NORMAL_ANNOTATION, annotation.getNodeType());
+ NormalAnnotation normalAnnotation = (NormalAnnotation) annotation;
+ List values = normalAnnotation.values();
+ assertEquals("wrong size", 1, values.size());
+ MemberValuePair valuePair = (MemberValuePair) values.get(0);
+ SimpleName name = valuePair.getName();
+ IBinding binding2 = name.resolveBinding();
+ assertNotNull("No binding", binding2);
+ ITypeBinding typeBinding = name.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding);
+
+ node = getASTNode(compilationUnit, 0, 1);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ methodDeclaration = (MethodDeclaration) node;
+ modifiers = methodDeclaration.modifiers();
+ assertEquals("Wrong size", 1, modifiers.size());
+ modifier = (IExtendedModifier) modifiers.get(0);
+ assertTrue("Wrong type", modifier instanceof Annotation);
+ annotation = (Annotation) modifier;
+ binding = annotation.resolveTypeBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82216
+ */
+ public void test0100() throws JavaModelException {
+ String contents =
+ "public enum E {\n" +
+ " A, B, C;\n" +
+ " public static final E D = B;\n" +
+ " public static final String F = \"Hello\";\n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/E.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0);
+ assertEquals("Not an enum declaration", ASTNode.ENUM_DECLARATION, node.getNodeType());
+ EnumDeclaration enumDeclaration = (EnumDeclaration) node;
+ List enumConstants = enumDeclaration.enumConstants();
+ assertEquals("wrong size", 3, enumConstants.size());
+ EnumConstantDeclaration enumConstantDeclaration = (EnumConstantDeclaration) enumConstants.get(0);
+ IMethodBinding methodBinding = enumConstantDeclaration.resolveConstructorBinding();
+ assertNotNull("No binding", methodBinding);
+ assertTrue("Not a constructor", methodBinding.isConstructor());
+ IVariableBinding variableBinding = enumConstantDeclaration.resolveVariable();
+ assertNotNull("no binding", variableBinding);
+ assertNull("is constant", variableBinding.getConstantValue());
+ assertTrue("Not an enum constant", variableBinding.isEnumConstant());
+
+ node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ assertEquals("wrong name", "D", fragment.getName().getIdentifier());
+ variableBinding = fragment.resolveBinding();
+ assertNotNull("no binding", variableBinding);
+ assertFalse("An enum constant", variableBinding.isEnumConstant());
+
+ node = getASTNode(compilationUnit, 0, 1);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ assertEquals("wrong name", "F", fragment.getName().getIdentifier());
+ variableBinding = fragment.resolveBinding();
+ assertNotNull("no binding", variableBinding);
+ assertNotNull("is constant", variableBinding.getConstantValue());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=68823
+ */
+ public void test0101() throws JavaModelException {
+ String contents =
+ "public class X{\n" +
+ " public void foo() {\n" +
+ " assert (true): (\"hello\");\n" +
+ " }\n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ this.workingCopy.getBuffer().setContents(contents.toCharArray());
+ ASTNode node = runConversion(AST.JLS3, this.workingCopy, true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ String expectedOutput = "Dead code";
+ assertProblemsSize(compilationUnit, 1, expectedOutput);
+
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not an assert statement", ASTNode.ASSERT_STATEMENT, node.getNodeType());
+ AssertStatement assertStatement = (AssertStatement) node;
+ final char[] source = contents.toCharArray();
+ checkSourceRange(assertStatement.getExpression(), "(true)", source);
+ checkSourceRange(assertStatement.getMessage(), "(\"hello\")", source);
+ checkSourceRange(assertStatement, "assert (true): (\"hello\");", source);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82670
+ */
+ public void test0102() throws JavaModelException {
+ String contents =
+ "import java.util.HashMap;\n" +
+ "\n" +
+ "public class X {\n" +
+ " Object o= new HashMap<?, ?>[0];\n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ checkSourceRange(fragment, "o= new HashMap<?, ?>[0]", contents.toCharArray());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82985
+ */
+ public void test0103() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0103", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ List imports = compilationUnit.imports();
+ assertEquals("Wrong size", 2, imports.size());
+ ImportDeclaration importDeclaration = (ImportDeclaration) imports.get(0);
+ IBinding binding = importDeclaration.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong type", IBinding.VARIABLE, binding.getKind());
+ Name name = importDeclaration.getName();
+ binding = name.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong type", IBinding.VARIABLE, binding.getKind());
+ assertEquals("Not a qualified name", ASTNode.QUALIFIED_NAME, name.getNodeType());
+ QualifiedName qualifiedName = (QualifiedName) name;
+ SimpleName simpleName = qualifiedName.getName();
+ binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong type", IBinding.VARIABLE, binding.getKind());
+
+ Name name2 = qualifiedName.getQualifier();
+ binding = name2.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong type", IBinding.TYPE, binding.getKind());
+
+ assertEquals("Not a qualified name", ASTNode.QUALIFIED_NAME, name2.getNodeType());
+ qualifiedName = (QualifiedName) name2;
+ simpleName = qualifiedName.getName();
+ binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong type", IBinding.TYPE, binding.getKind());
+
+ Name name3 = qualifiedName.getQualifier();
+ binding = name3.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong type", IBinding.PACKAGE, binding.getKind());
+
+ assertEquals("Not a simple name", ASTNode.SIMPLE_NAME, name3.getNodeType());
+
+ importDeclaration = (ImportDeclaration) imports.get(1);
+ binding = importDeclaration.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertFalse("Not a single name import", importDeclaration.isOnDemand());
+ name = importDeclaration.getName();
+ binding = name.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong type", IBinding.METHOD, binding.getKind());
+
+ assertEquals("Not a qualified name", ASTNode.QUALIFIED_NAME, name.getNodeType());
+ qualifiedName = (QualifiedName) name;
+ simpleName = qualifiedName.getName();
+ binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong type", IBinding.METHOD, binding.getKind());
+
+ name2 = qualifiedName.getQualifier();
+ binding = name2.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong type", IBinding.TYPE, binding.getKind());
+ assertEquals("Not a qualified name", ASTNode.QUALIFIED_NAME, name2.getNodeType());
+ qualifiedName = (QualifiedName) name2;
+ simpleName = qualifiedName.getName();
+ binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong type", IBinding.TYPE, binding.getKind());
+
+ name2 = qualifiedName.getQualifier();
+ binding = name2.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong type", IBinding.PACKAGE, binding.getKind());
+ assertEquals("Not a simple name", ASTNode.SIMPLE_NAME, name2.getNodeType());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82985
+ */
+ public void test0104() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0104", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ List imports = compilationUnit.imports();
+ assertEquals("Wrong size", 1, imports.size());
+ ImportDeclaration importDeclaration = (ImportDeclaration) imports.get(0);
+ IBinding binding = importDeclaration.resolveBinding();
+ assertNotNull("No binding", binding);
+ int kind = binding.getKind();
+ assertTrue("Wrong type", kind == IBinding.VARIABLE || kind == IBinding.METHOD);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=83011
+ */
+ public void test0105() throws JavaModelException {
+ String contents =
+ "@interface Ann {}\n" +
+ "\n" +
+ "@Ann public class X {}\n";
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 1);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ List modifiers = typeDeclaration.modifiers();
+ assertEquals("Wrong size", 2, modifiers.size());
+ IExtendedModifier extendedModifier = (IExtendedModifier) modifiers.get(0);
+ assertTrue("Not a marker annotation", extendedModifier instanceof MarkerAnnotation);
+ MarkerAnnotation markerAnnotation = (MarkerAnnotation) extendedModifier;
+ ITypeBinding binding = markerAnnotation.resolveTypeBinding();
+ assertNotNull("No binding", binding);
+ Name name = markerAnnotation.getTypeName();
+ binding = name.resolveTypeBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=83011
+ */
+ public void test0106() throws JavaModelException {
+ String contents =
+ "package p;\n" +
+ "@interface Ann {}\n" +
+ "\n" +
+ "@p.Ann public class X {}\n";
+ this.workingCopy = getWorkingCopy("/Converter15/src/p/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 1);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ List modifiers = typeDeclaration.modifiers();
+ assertEquals("Wrong size", 2, modifiers.size());
+ IExtendedModifier extendedModifier = (IExtendedModifier) modifiers.get(0);
+ assertTrue("Not a marker annotation", extendedModifier instanceof MarkerAnnotation);
+ MarkerAnnotation markerAnnotation = (MarkerAnnotation) extendedModifier;
+ ITypeBinding typeBinding = markerAnnotation.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding);
+ Name name = markerAnnotation.getTypeName();
+ typeBinding = name.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding);
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong kind of binding", IBinding.TYPE, binding.getKind());
+ assertEquals("Not a qualified name", ASTNode.QUALIFIED_NAME, name.getNodeType());
+ QualifiedName qualifiedName = (QualifiedName) name;
+ SimpleName simpleName = qualifiedName.getName();
+ binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding);
+ name = qualifiedName.getQualifier();
+ binding = name.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong kind of binding", IBinding.PACKAGE, binding.getKind());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=83013
+ */
+ public void test0107() throws JavaModelException {
+ String contents =
+ "@interface A {\n" +
+ " String value() default \"\";\n" +
+ "}\n" +
+ "@interface Main {\n" +
+ " A child() default @A(\"Void\");\n" +
+ "}\n" +
+ "@Main(child=@A(\"\")) @A class X {}\n";
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 2);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ checkSourceRange(node, "@Main(child=@A(\"\")) @A class X {}", contents.toCharArray());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=83228
+ */
+ public void test0108() throws JavaModelException {
+ String contents =
+ "class X<E> {\n" +
+ " enum Numbers {\n" +
+ " ONE {\n" +
+ " Numbers getSquare() {\n" +
+ " return ONE;\n" +
+ " }\n" +
+ " };\n" +
+ " abstract Numbers getSquare();\n" +
+ " }\n" +
+ "}\n";
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0);
+ EnumDeclaration enumDeclaration = (EnumDeclaration) node;
+
+ List bodyDeclarations = enumDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclarations.get(0);
+ Type returnType = methodDeclaration.getReturnType2();
+ ITypeBinding typeBinding = returnType.resolveBinding();
+
+ List enumConstants = enumDeclaration.enumConstants();
+ assertEquals("Wrong size", 1, enumConstants.size());
+ EnumConstantDeclaration constantDeclaration = (EnumConstantDeclaration) enumConstants.get(0);
+ AnonymousClassDeclaration anonymousClassDeclaration = constantDeclaration.getAnonymousClassDeclaration();
+ assertNotNull("No anonymous", anonymousClassDeclaration);
+ bodyDeclarations = anonymousClassDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, bodyDeclaration.getNodeType());
+ methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ Type type = methodDeclaration.getReturnType2();
+ assertEquals("Not a simple type", ASTNode.SIMPLE_TYPE, type.getNodeType());
+ SimpleType simpleType = (SimpleType) type;
+ Name name = simpleType.getName();
+ assertEquals("Not a simple name", ASTNode.SIMPLE_NAME, name.getNodeType());
+ SimpleName simpleName = (SimpleName) name;
+ ITypeBinding typeBinding2 = simpleName.resolveTypeBinding();
+
+ assertTrue("Not equals", typeBinding.isEqualTo(typeBinding2));
+ assertTrue("Not identical", typeBinding == typeBinding2);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=883297
+ */
+ public void test0109() throws JavaModelException {
+ String contents =
+ "@Annot(value=\"Hello\", count=-1)\n" +
+ "@interface Annot {\n" +
+ " String value();\n" +
+ " int count();\n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/Annot.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0);
+ AnnotationTypeDeclaration annotationTypeDeclaration = (AnnotationTypeDeclaration) node;
+ ITypeBinding typeBinding = annotationTypeDeclaration.resolveBinding();
+ assertNotNull("No type binding", typeBinding);
+ IMethodBinding[] methods = typeBinding.getDeclaredMethods();
+ assertEquals("Wrong size", 2, methods.length);
+ }
+
+ /*
+ * Ensures that the type declaration of a top level type binding is correct.
+ */
+ public void test0110() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ TypeDeclaration type = (TypeDeclaration) buildAST(
+ "/*start*/public class X {\n" +
+ "}/*end*/",
+ this.workingCopy);
+ ITypeBinding binding = type.resolveBinding().getTypeDeclaration();
+ assertBindingEquals(
+ "LX;",
+ binding);
+ }
+
+ /*
+ * Ensures that the type declaration of a generic type binding is correct.
+ */
+ public void test0111() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ TypeDeclaration type = (TypeDeclaration) buildAST(
+ "/*start*/public class X<E> {\n" +
+ "}/*end*/",
+ this.workingCopy);
+ ITypeBinding binding = type.resolveBinding().getTypeDeclaration();
+ assertBindingEquals(
+ "LX<TE;>;",
+ binding);
+ }
+
+ /*
+ * Ensures that the type declaration of a parameterized type binding is correct.
+ */
+ public void test0112() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ Type type = (Type) buildAST(
+ "public class X<E> {\n" +
+ " /*start*/X<String>/*end*/ field;\n" +
+ "}",
+ this.workingCopy,
+ false);
+ ITypeBinding binding = type.resolveBinding().getTypeDeclaration();
+ assertBindingEquals(
+ "LX<TE;>;",
+ binding);
+ }
+
+ /*
+ * Ensures that the type declaration of a raw type binding is correct.
+ */
+ public void test0113() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ Type type = (Type) buildAST(
+ "public class X<E> {\n" +
+ " /*start*/X/*end*/ field;\n" +
+ "}",
+ this.workingCopy,
+ false);
+ ITypeBinding binding = type.resolveBinding().getTypeDeclaration();
+ assertBindingEquals(
+ "LX<TE;>;",
+ binding);
+ }
+
+ /*
+ * Ensures that the type declaration of a wildcard type binding is correct.
+ */
+ public void test0114() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ Type type = (Type) buildAST(
+ "public class X<E> {\n" +
+ " X</*start*/? extends String/*end*/> field;\n" +
+ "}",
+ this.workingCopy);
+ ITypeBinding binding = type.resolveBinding().getTypeDeclaration();
+ assertBindingEquals(
+ "LX;{0}+Ljava/lang/String;",
+ binding);
+ }
+
+ /*
+ * Ensures that the type declaration of a type variable binding is correct.
+ */
+ public void test0115() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ TypeParameter type = (TypeParameter) buildAST(
+ "public class X</*start*/E/*end*/> {\n" +
+ "}",
+ this.workingCopy);
+ ITypeBinding binding = type.resolveBinding().getTypeDeclaration();
+ assertBindingEquals(
+ "LX;:TE;",
+ binding);
+ }
+
+ /*
+ * Ensures that the erasure of a top level type binding is correct.
+ */
+ public void test0116() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ TypeDeclaration type = (TypeDeclaration) buildAST(
+ "/*start*/public class X {\n" +
+ "}/*end*/",
+ this.workingCopy);
+ ITypeBinding binding = type.resolveBinding().getErasure();
+ assertBindingEquals(
+ "LX;",
+ binding);
+ }
+
+ /*
+ * Ensures that the erasure of a generic type binding is correct.
+ */
+ public void test0117() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ TypeDeclaration type = (TypeDeclaration) buildAST(
+ "/*start*/public class X<E> {\n" +
+ "}/*end*/",
+ this.workingCopy);
+ ITypeBinding binding = type.resolveBinding().getErasure();
+ assertBindingEquals(
+ "LX<TE;>;",
+ binding);
+ }
+
+ /*
+ * Ensures that the erasure of a parameterized type binding is correct.
+ */
+ public void test0118() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ Type type = (Type) buildAST(
+ "public class X<E> {\n" +
+ " /*start*/X<String>/*end*/ field;\n" +
+ "}",
+ this.workingCopy);
+ ITypeBinding binding = type.resolveBinding().getErasure();
+ assertBindingEquals(
+ "LX<TE;>;",
+ binding);
+ }
+
+ /*
+ * Ensures that the erasure of a raw type binding is correct.
+ */
+ public void test0119() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ Type type = (Type) buildAST(
+ "public class X<E> {\n" +
+ " /*start*/X/*end*/ field;\n" +
+ "}",
+ this.workingCopy,
+ false);
+ ITypeBinding binding = type.resolveBinding().getErasure();
+ assertBindingEquals(
+ "LX<TE;>;",
+ binding);
+ }
+
+ /*
+ * Ensures that the erasure of a wildcard type binding is correct.
+ */
+ public void test0120() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ Type type = (Type) buildAST(
+ "public class X<E> {\n" +
+ " X</*start*/? extends String/*end*/> field;\n" +
+ "}",
+ this.workingCopy);
+ ITypeBinding binding = type.resolveBinding().getErasure();
+ assertBindingEquals(
+ "Ljava/lang/String;",
+ binding);
+ }
+
+ /*
+ * Ensures that the erasure of a type variable binding is correct.
+ */
+ public void test0121() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ TypeParameter type = (TypeParameter) buildAST(
+ "public class X</*start*/E/*end*/> {\n" +
+ "}",
+ this.workingCopy);
+ ITypeBinding binding = type.resolveBinding().getErasure();
+ assertBindingEquals(
+ "Ljava/lang/Object;",
+ binding);
+ }
+
+ /*
+ * Ensures that the declaration of a non generic method binding is correct.
+ */
+ public void test0122() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ MethodDeclaration method = (MethodDeclaration) buildAST(
+ "public class X {\n" +
+ " /*start*/void foo() {\n" +
+ " }/*end*/\n" +
+ "}",
+ this.workingCopy);
+ IMethodBinding binding = method.resolveBinding().getMethodDeclaration();
+ assertBindingEquals(
+ "LX;.foo()V",
+ binding);
+ }
+
+ /*
+ * Ensures that the declaration of a generic method binding is correct.
+ */
+ public void test0123() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ MethodDeclaration method = (MethodDeclaration) buildAST(
+ "public class X {\n" +
+ " /*start*/<E> void foo() {\n" +
+ " }/*end*/\n" +
+ "}",
+ this.workingCopy);
+ IMethodBinding binding = method.resolveBinding().getMethodDeclaration();
+ assertBindingEquals(
+ "LX;.foo<E:Ljava/lang/Object;>()V",
+ binding);
+ }
+
+ /*
+ * Ensures that the declaration of a parameterized method binding is correct.
+ */
+ public void test0124() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ MethodInvocation method = (MethodInvocation) buildAST(
+ "public class X {\n" +
+ " <E> void foo() {\n" +
+ " }\n" +
+ " void bar() {\n" +
+ " /*start*/this.<String>foo()/*end*/;\n" +
+ " }\n" +
+ "}",
+ this.workingCopy);
+ IMethodBinding binding = method.resolveMethodBinding().getMethodDeclaration();
+ assertBindingEquals(
+ "LX;.foo<E:Ljava/lang/Object;>()V",
+ binding);
+ }
+
+ /*
+ * Ensures that the declaration of a raw method binding is correct.
+ */
+ public void test0125() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ MethodInvocation method = (MethodInvocation) buildAST(
+ "public class X {\n" +
+ " <E> void foo() {\n" +
+ " }\n" +
+ " void bar() {\n" +
+ " /*start*/this.foo()/*end*/;\n" +
+ " }\n" +
+ "}",
+ this.workingCopy);
+ IMethodBinding binding = method.resolveMethodBinding().getMethodDeclaration();
+ assertBindingEquals(
+ "LX;.foo<E:Ljava/lang/Object;>()V",
+ binding);
+ }
+
+ /*
+ * Ensures that the key for a parameterized type binding with an extends wildcard bounded to a type variable
+ * is correct.
+ */
+ public void test0126() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ Type type = (Type) buildAST(
+ "public class X<E> {\n" +
+ " /*start*/Class<? extends E>/*end*/ field;\n" +
+ "}",
+ this.workingCopy);
+ ITypeBinding binding = type.resolveBinding();
+ assertBindingEquals(
+ "Ljava/lang/Class<Ljava/lang/Class;{0}+LX;:TE;>;",
+ binding);
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83817
+ public void test0127() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ "class X<T> {\n" +
+ " public void method(Number num) {}\n" +
+ "}\n" +
+ "\n" +
+ "class Z {\n" +
+ " void test() {\n" +
+ " new X<String>().method(0);\n" +
+ " new X<Integer>().method(1);\n" +
+ " }\n" +
+ "}",
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 1, 0, 0);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement statement = (ExpressionStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();
+ node = getASTNode(compilationUnit, 1, 0, 1);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ statement = (ExpressionStatement) node;
+ expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ methodInvocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding2 = methodInvocation.resolveMethodBinding();
+ assertFalse("Keys are equals", methodBinding.getKey().equals(methodBinding2.getKey()));
+ assertFalse("bindings are equals", methodBinding.isEqualTo(methodBinding2));
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84064
+ public void test0128() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ final String contents =
+ "class X {\n" +
+ " static X x;\n" +
+ "\n" +
+ " static class G extends E {\n" +
+ " public G() {\n" +
+ " x.<String> super();\n" +
+ " }\n" +
+ " }\n" +
+ "\n" +
+ " class E {\n" +
+ " public <T> E() {\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ final char[] source = contents.toCharArray();
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 1, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Not a constructor", methodDeclaration.isConstructor());
+ Block body = methodDeclaration.getBody();
+ assertNotNull("No body", body);
+ List statements = body.statements();
+ assertEquals("Wrong size", 1, statements.size());
+ Statement statement = (Statement) statements.get(0);
+ assertEquals("Not a super constructor invocation", ASTNode.SUPER_CONSTRUCTOR_INVOCATION, statement.getNodeType());
+ SuperConstructorInvocation constructorInvocation = (SuperConstructorInvocation) statement;
+ checkSourceRange(constructorInvocation, "x.<String> super();", source);
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84064
+ public void test0129() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ final String contents =
+ "class X {\n" +
+ " static X x;\n" +
+ " static class G extends E {\n" +
+ " public <T> G() {\n" +
+ " x.<String> this();\n" +
+ " }\n" +
+ " }\n" +
+ " static class E {\n" +
+ " public <T> E() {\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ final char[] source = contents.toCharArray();
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ String expectedProblem = "Illegal enclosing instance specification for type X.G";
+ assertProblemsSize(compilationUnit, 1, expectedProblem);
+ node = getASTNode(compilationUnit, 0, 1, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Not a constructor", methodDeclaration.isConstructor());
+ Block body = methodDeclaration.getBody();
+ assertNotNull("No body", body);
+ List statements = body.statements();
+ assertEquals("Wrong size", 1, statements.size());
+ Statement statement = (Statement) statements.get(0);
+ assertEquals("Not a constructor invocation", ASTNode.CONSTRUCTOR_INVOCATION, statement.getNodeType());
+ ConstructorInvocation constructorInvocation = (ConstructorInvocation) statement;
+ checkSourceRange(constructorInvocation, "x.<String> this();", source);
+ assertTrue("Node is not malformed", isMalformed(constructorInvocation));
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78934
+ public void test0130() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ final String contents =
+ "class Outer<A> {\n" +
+ " class Inner {\n" +
+ " class InnerInner<C> {\n" +
+ " }\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "public class X {\n" +
+ " void foo() {\n" +
+ " Outer<String>.Inner.InnerInner<Integer> in = new Outer<String>().new Inner(). new InnerInner<Integer>();\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 1, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ Type type = statement.getType();
+ assertTrue("Not a parameterized type", type.isParameterizedType());
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ ITypeBinding typeBinding = parameterizedType.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertEquals("Wrong qualified name 1", "Outer<java.lang.String>.Inner.InnerInner<java.lang.Integer>", typeBinding.getQualifiedName());
+ type = parameterizedType.getType();
+ assertTrue("Not a qualified type", type.isQualifiedType());
+ QualifiedType qualifiedType = (QualifiedType) type;
+ typeBinding = qualifiedType.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertEquals("Wrong qualified name 2", "Outer<java.lang.String>.Inner.InnerInner<java.lang.Integer>", typeBinding.getQualifiedName());
+ SimpleName simpleName = qualifiedType.getName();
+ typeBinding = simpleName.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding);
+ assertEquals("Wrong qualified name 3", "Outer<java.lang.String>.Inner.InnerInner<java.lang.Integer>", typeBinding.getQualifiedName());
+ type = qualifiedType.getQualifier();
+ assertTrue("Not a qualified type", type.isQualifiedType());
+ qualifiedType = (QualifiedType) type;
+ typeBinding = qualifiedType.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertEquals("Wrong qualified name 4", "Outer<java.lang.String>.Inner", typeBinding.getQualifiedName());
+ simpleName = qualifiedType.getName();
+ typeBinding = simpleName.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding);
+ assertEquals("Wrong qualified name 5", "Outer.Inner", typeBinding.getQualifiedName());
+ type = qualifiedType.getQualifier();
+ assertTrue("Not a parameterized type", type.isParameterizedType());
+ parameterizedType = (ParameterizedType) type;
+ typeBinding = parameterizedType.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertEquals("Wrong qualified name 6", "Outer<java.lang.String>", typeBinding.getQualifiedName());
+ type = parameterizedType.getType();
+ assertTrue("Not a simple type", type.isSimpleType());
+ SimpleType simpleType = (SimpleType) type;
+ typeBinding = simpleType.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertEquals("Wrong qualified name 7", "Outer<java.lang.String>", typeBinding.getQualifiedName());
+ Name name = simpleType.getName();
+ assertTrue("Not a simple name", name.isSimpleName());
+ simpleName = (SimpleName) name;
+ typeBinding = simpleName.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding);
+ assertEquals("Wrong qualified name 8", "Outer", typeBinding.getQualifiedName());
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84140
+ public void test0131() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public void bar(String... args){\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ assertEquals("Wrong size", 1, parameters.size());
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ assertTrue("Not a var args", singleVariableDeclaration.isVarargs());
+ Type type = singleVariableDeclaration.getType();
+ checkSourceRange(type, "String", contents);
+ assertTrue("Not a simple type", type.isSimpleType());
+ checkSourceRange(type, "String", contents);
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertFalse("An array", typeBinding.isArray());
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ ITypeBinding[] parameterTypes = methodBinding.getParameterTypes();
+ ITypeBinding parameterType = parameterTypes[0];
+ assertTrue("Not an array binding", parameterType.isArray());
+ assertTrue("Not equals", parameterType.getComponentType() == parameterType.getElementType());
+ assertEquals("wrong dimension", 1, parameterType.getDimensions());
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84140
+ public void test0132() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public void bar(String[]... args[]){\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 1, "Extended dimensions are illegal for a variable argument");
+ node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ assertEquals("Wrong size", 1, parameters.size());
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ assertTrue("Not a var args", singleVariableDeclaration.isVarargs());
+ assertTrue("Not a malformed node", isMalformed(singleVariableDeclaration));
+ Type type = singleVariableDeclaration.getType();
+ checkSourceRange(type, "String[]", contents);
+ assertTrue("Not an array type", type.isArrayType());
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertTrue("Not an array", typeBinding.isArray());
+ assertEquals("wrong dimensions", 1, typeBinding.getDimensions());
+ ArrayType arrayType = (ArrayType) type;
+ assertEquals("Wrong dimension", 1, arrayType.getDimensions());
+ type = arrayType.getComponentType();
+ assertTrue("Not a simple type", type.isSimpleType());
+ checkSourceRange(type, "String", contents);
+ assertEquals("Wrong extra dimension", 1, singleVariableDeclaration.getExtraDimensions());
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ ITypeBinding[] parameterTypes = methodBinding.getParameterTypes();
+ ITypeBinding parameterType = parameterTypes[0];
+ assertTrue("Not an array binding", parameterType.isArray());
+ assertEquals("wrong dimension", 3, parameterType.getDimensions());
+ ITypeBinding componentType = parameterType.getComponentType();
+ assertEquals("wrong dimension", 2, componentType.getDimensions());
+ assertTrue("Not equal", parameterType.getElementType() == componentType.getElementType());
+ ITypeBinding componentType2 = componentType.getComponentType();
+ assertEquals("wrong dimension", 1, componentType2.getDimensions());
+ assertTrue("Not equal", parameterType.getElementType() == componentType2.getElementType());
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84181
+ public void test0133() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "import java.util.Vector;\n" +
+ "\n" +
+ "public class X {\n" +
+ " void k() {\n" +
+ " Vector v2 = /*start*/new Vector()/*end*/;\n" +
+ " Vector v3 = new Vector();\n" +
+ "\n" +
+ " v3.add(\"fff\");\n" +
+ " v2.add(v3);\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertNotNull("No node", node);
+ assertEquals("Not a class instance creation unit", ASTNode.CLASS_INSTANCE_CREATION, node.getNodeType());
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) node;
+ ITypeBinding typeBinding = classInstanceCreation.resolveTypeBinding();
+ assertEquals("wrong qualified name", "java.util.Vector", typeBinding.getQualifiedName());
+ assertTrue("Not a raw type", typeBinding.isRawType());
+ assertFalse("From source", typeBinding.isFromSource());
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84181
+ public void test0134() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "import java.util.Vector;\n" +
+ "\n" +
+ "public class X {\n" +
+ " void k() {\n" +
+ " Vector v2 = /*start*/new Vector<String>()/*end*/;\n" +
+ "\n" +
+ " v2.add(\"\");\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertNotNull("No node", node);
+ assertEquals("Not a class instance creation unit", ASTNode.CLASS_INSTANCE_CREATION, node.getNodeType());
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) node;
+ ITypeBinding typeBinding = classInstanceCreation.resolveTypeBinding();
+ assertEquals("wrong qualified name", "java.util.Vector<java.lang.String>", typeBinding.getQualifiedName());
+ assertTrue("Not a parameterized type", typeBinding.isParameterizedType());
+ assertFalse("From source", typeBinding.isFromSource());
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78934
+ public void test0135() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "class X {\n" +
+ " public static X instance= new X();\n" +
+ "\n" +
+ " int s;\n" +
+ "\n" +
+ " int f() {\n" +
+ " System.out.println(X.instance.s + 1);\n" +
+ " return 1;\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ compilationUnit.accept(new ASTVisitor() {
+ public boolean visit(QualifiedName qualifiedName) {
+ ITypeBinding typeBinding = qualifiedName.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding);
+ return true;
+ }
+ });
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=78934
+ public void test0136() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "class X {\n" +
+ " public static X instance= new X();\n" +
+ " public X instance2 = new X();\n" +
+ " int s;\n" +
+ " int f() {\n" +
+ " System.out.println(X.instance.instance2.s + 1);\n" +
+ " return 1;\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ compilationUnit.accept(new ASTVisitor() {
+ public boolean visit(QualifiedName qualifiedName) {
+ ITypeBinding typeBinding = qualifiedName.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding);
+ return true;
+ }
+ });
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=79696
+ */
+ public void test0137() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0137", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Wrong node", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ Type type = statement.getType();
+ assertTrue("Not a parameterized type", type.isParameterizedType());
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ type = parameterizedType.getType();
+ assertTrue("Not a parameterized type", type.isSimpleType());
+ SimpleType simpleType = (SimpleType) type;
+ Name name = simpleType.getName();
+ assertTrue("Not a qualified name", name.isQualifiedName());
+ QualifiedName qualifiedName = (QualifiedName) name;
+ name = qualifiedName.getQualifier();
+ assertTrue("Not a simple name", name.isSimpleName());
+ ITypeBinding typeBinding = name.resolveTypeBinding();
+ assertEquals("Wrong name", "test0137.Source", typeBinding.getQualifiedName());
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=81544
+ public void test0138() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ final String contents =
+ "class X {\n" +
+ " java.util.List<URL> method(java.util.List<URL> list) {\n" +
+ " java.util.List<URL> url= new java.util.List<URL>();\n" +
+ " return url;\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false,
+ false,
+ true);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 5,
+ "URL cannot be resolved to a type\n" +
+ "URL cannot be resolved to a type\n" +
+ "URL cannot be resolved to a type\n" +
+ "Cannot instantiate the type List<URL>\n" +
+ "URL cannot be resolved to a type");
+ compilationUnit.accept(new ASTVisitor() {
+ public boolean visit(ParameterizedType type) {
+ checkSourceRange(type, "java.util.List<URL>", contents);
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ return true;
+ }
+ });
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=84358
+ */
+ public void test0139() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0139", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, false, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 1, "The type test0139a.C is not visible");
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Wrong node", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ Type type = statement.getType();
+ assertTrue("Not a parameterized type", type.isParameterizedType());
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ type = parameterizedType.getType();
+ assertTrue("Not a parameterized type", type.isSimpleType());
+ SimpleType simpleType = (SimpleType) type;
+ Name name = simpleType.getName();
+ assertTrue("Not a qualified name", name.isQualifiedName());
+ QualifiedName qualifiedName = (QualifiedName) name;
+ IBinding binding = qualifiedName.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("wrong type", IBinding.TYPE, binding.getKind());
+ ITypeBinding typeBinding = (ITypeBinding) binding;
+ assertEquals("wrong qualified name", "test0139a.C", typeBinding.getQualifiedName());
+ SimpleName simpleName = qualifiedName.getName();
+ binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("wrong type", IBinding.TYPE, binding.getKind());
+ typeBinding = (ITypeBinding) binding;
+ assertEquals("wrong qualified name", "test0139a.C", typeBinding.getQualifiedName());
+ name = qualifiedName.getQualifier();
+ assertEquals("Not a simpleName", ASTNode.SIMPLE_NAME, name.getNodeType());
+ binding = name.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("wrong type", IBinding.PACKAGE, binding.getKind());
+ IPackageBinding packageBinding = (IPackageBinding) binding;
+ assertEquals("wrong name", "test0139a", packageBinding.getName());
+ assertEquals("Wrong modifier", Modifier.NONE, packageBinding.getModifiers());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=85115
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=85215
+ */
+ public void test0140() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0140", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertNotNull("No node", node);
+ assertEquals("Not an enum declaration", ASTNode.ENUM_DECLARATION, node.getNodeType());
+ EnumDeclaration enumDeclaration = (EnumDeclaration) node;
+ List modifiers = enumDeclaration.modifiers();
+ assertEquals("Wrong size", 2, modifiers.size());
+ IExtendedModifier modifier = (IExtendedModifier) modifiers.get(0);
+ assertTrue("Wrong type", modifier instanceof MarkerAnnotation);
+ MarkerAnnotation markerAnnotation = (MarkerAnnotation) modifier;
+ ITypeBinding typeBinding = markerAnnotation.resolveTypeBinding();
+ assertTrue("Not an annotation", typeBinding.isAnnotation());
+ assertTrue("Not a top level type", typeBinding.isTopLevel());
+
+ sourceUnit = getCompilationUnit("Converter15" , "src", "test0140", "Annot.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ result = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0);
+ assertNotNull("No node", node);
+ assertEquals("Not an annotation declaration", ASTNode.ANNOTATION_TYPE_DECLARATION, node.getNodeType());
+ AnnotationTypeDeclaration annotationTypeDeclaration = (AnnotationTypeDeclaration) node;
+ modifiers = annotationTypeDeclaration.modifiers();
+ assertEquals("Wrong size", 1, modifiers.size());
+ typeBinding = annotationTypeDeclaration.resolveBinding();
+ int modifierValue = typeBinding.getModifiers();
+ assertEquals("Type is not public", Modifier.PUBLIC, modifierValue);
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83100
+ public void test0141() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ final String contents =
+ "public class X<T> {\n" +
+ " int x;\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(new X<String>().x);\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertFalse("Not a parameter", variableBinding.isParameter());
+ node = getASTNode(compilationUnit, 0, 1, 0);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement statement = (ExpressionStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ List arguments = methodInvocation.arguments();
+ assertEquals("Wrong size", 1, arguments.size());
+ Expression expression2 = (Expression) arguments.get(0);
+ assertEquals("Not a field access", ASTNode.FIELD_ACCESS, expression2.getNodeType());
+ FieldAccess fieldAccess = (FieldAccess) expression2;
+ IVariableBinding variableBinding2 = fieldAccess.resolveFieldBinding();
+ assertFalse("Not a parameter", variableBinding2.isParameter());
+ assertFalse("Bindings are not equals", variableBinding.isEqualTo(variableBinding2));
+ IVariableBinding variableBinding3 = variableBinding2.getVariableDeclaration();
+ assertTrue("Bindings are equals", variableBinding.isEqualTo(variableBinding3));
+ node = compilationUnit.findDeclaringNode(variableBinding2);
+ assertNotNull("No declaring node", node);
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=83100
+ public void test0142() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ final String contents =
+ "public class X<T> {\n" +
+ " public static void main(String[] args) {\n" +
+ " int x = 0;\n" +
+ " System.out.println(x);\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ assertEquals("Wrong name", "x", fragment.getName().getIdentifier());
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ IVariableBinding variableBinding2 = variableBinding.getVariableDeclaration();
+ assertFalse("Not a parameter", variableBinding.isParameter());
+ assertFalse("Not a parameter", variableBinding2.isParameter());
+ assertTrue("Bindings are equals", variableBinding.isEqualTo(variableBinding2));
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=84140
+ public void test0143() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public void bar(String[]... args){\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ assertEquals("Wrong size", 1, parameters.size());
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ assertTrue("Not a var args", singleVariableDeclaration.isVarargs());
+ Type type = singleVariableDeclaration.getType();
+ checkSourceRange(type, "String[]", contents);
+ assertTrue("Not an array type", type.isArrayType());
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertTrue("Not an array", typeBinding.isArray());
+ assertEquals("wrong dimensions", 1, typeBinding.getDimensions());
+ ArrayType arrayType = (ArrayType) type;
+ assertEquals("Wrong dimension", 1, arrayType.getDimensions());
+ type = arrayType.getComponentType();
+ assertTrue("Not a simple type", type.isSimpleType());
+ checkSourceRange(type, "String", contents);
+ assertEquals("Wrong extra dimension", 0, singleVariableDeclaration.getExtraDimensions());
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ ITypeBinding[] parameterTypes = methodBinding.getParameterTypes();
+ ITypeBinding parameterType = parameterTypes[0];
+ assertTrue("Not an array binding", parameterType.isArray());
+ assertEquals("wrong dimension", 2, parameterType.getDimensions());
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=87171
+ public void test0144() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X<T> {\n" +
+ " void foo(T t) {\n" +
+ " System.out.println(t);\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "class Use {\n" +
+ " public static void main(String[] args) {\n" +
+ " X<String> i= new X<String>();\n" +
+ " i.foo(\"Eclipse\");\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 1, 0, 1);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement statement = (ExpressionStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();
+ node = compilationUnit.findDeclaringNode(methodBinding);
+ assertNotNull("No declaring node", node);
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=87350
+ public void test0145() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public enum X {\n" +
+ " RED, GREEN(), BLUE(17), PINK(1) {/*anon*};\n" +
+ " Color() {}\n" +
+ " Color(int i) {}\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ String expectedErrors = "The constructor X(int) is undefined\n" +
+ "The constructor X(int) is undefined\n" +
+ "Unexpected end of comment";
+ assertProblemsSize(compilationUnit, 3, expectedErrors);
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=87481
+ public void test0146() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "import java.util.Iterator;\n" +
+ "public class X {\n" +
+ " void doit() {\n" +
+ " Iterator iter= (Iterator) null;\n" +
+ " System.out.println(iter);\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ String expectedProblems =
+ "Iterator is a raw type. References to generic type Iterator<E> should be parameterized\n" +
+ "Iterator is a raw type. References to generic type Iterator<E> should be parameterized";
+ assertProblemsSize(compilationUnit, 2, expectedProblems);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertNotNull("No initializer", expression);
+ assertEquals("Not a cast expression", ASTNode.CAST_EXPRESSION, expression.getNodeType());
+ CastExpression castExpression = (CastExpression) expression;
+ Type type = castExpression.getType();
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertEquals("Wrong type", "java.util.Iterator", typeBinding.getQualifiedName());
+ assertTrue("Not a raw type", typeBinding.isRawType());
+ assertFalse("Is a generic type", typeBinding.isGenericType());
+ assertFalse("Is a parameterized type", typeBinding.isParameterizedType());
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=87498
+ public void test0147() throws CoreException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0147", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=87350
+ public void test0148() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public enum X {\n" +
+ " RED, GREEN(), BLUE(17), PINK(1) {/*anon*};\n" +
+ " Color() {}\n" +
+ " Color(int i) {}\n";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ String expectedErrors = "The constructor X(int) is undefined\n" +
+ "The constructor X(int) is undefined\n" +
+ "Unexpected end of comment";
+ assertProblemsSize(compilationUnit, 3, expectedErrors);
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=88252
+ public void test0149() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ " interface Jpf {\n" +
+ " @interface Action {\n" +
+ " ValidatableProperty[] validatableProperties();\n" +
+ " }\n" +
+ " \n" +
+ " @interface ValidatableProperty {\n" +
+ " String propertyName();\n" +
+ " ValidationLocaleRules[] localeRules();\n" +
+ " }\n" +
+ " \n" +
+ " @interface ValidationLocaleRules {\n" +
+ " ValidateMinLength validateMinLength();\n" +
+ " }\n" +
+ " \n" +
+ " @interface ValidateMinLength {\n" +
+ " String chars();\n" +
+ " }\n" +
+ "}\n" +
+ " \n" +
+ " public class X {\n" +
+ " \n" +
+ " @Jpf.Action(\n" +
+ " validatableProperties={@Jpf.ValidatableProperty(propertyName=\"fooField\",\n" +
+ " localeRules={@Jpf.ValidationLocaleRules(\n" +
+ " validateMinLength=@Jpf.ValidateMinLength(chars=\"12\")\n" +
+ " )}\n" +
+ " )}\n" +
+ " )\n" +
+ " public String actionForValidationRuleTest() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 1, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List modifiers = methodDeclaration.modifiers();
+ assertEquals("Wrong size", 2, modifiers.size());
+ IExtendedModifier modifier = (IExtendedModifier) modifiers.get(0);
+ assertTrue("Not a normal annotation", modifier instanceof NormalAnnotation);
+ NormalAnnotation annotation = (NormalAnnotation) modifier;
+ List values = annotation.values();
+ assertEquals("wrong size", 1, values.size());
+ MemberValuePair memberValuePair = (MemberValuePair) values.get(0);
+ Expression expression = memberValuePair.getValue();
+ assertEquals("Not an array initializer", ASTNode.ARRAY_INITIALIZER, expression.getNodeType());
+ ArrayInitializer arrayInitializer = (ArrayInitializer) expression;
+ List expressions = arrayInitializer.expressions();
+ assertEquals("wrong size", 1, expressions.size());
+ Expression expression2 = (Expression) expressions.get(0);
+ assertEquals("Not a normal annotation", ASTNode.NORMAL_ANNOTATION, expression2.getNodeType());
+ NormalAnnotation annotation2 = (NormalAnnotation) expression2;
+ values = annotation2.values();
+ assertEquals("wrong size", 2, values.size());
+ MemberValuePair memberValuePair2 = (MemberValuePair) values.get(1);
+ Expression expression3 = memberValuePair2.getValue();
+ assertEquals("Not an array initializer", ASTNode.ARRAY_INITIALIZER, expression3.getNodeType());
+ arrayInitializer = (ArrayInitializer) expression3;
+ expressions = arrayInitializer.expressions();
+ assertEquals("wrong size", 1, expressions.size());
+ Expression expression4 = (Expression) expressions.get(0);
+ assertEquals("Not a normal annotation", ASTNode.NORMAL_ANNOTATION, expression4.getNodeType());
+ NormalAnnotation annotation3 = (NormalAnnotation) expression4;
+ values = annotation3.values();
+ assertEquals("wrong size", 1, values.size());
+ MemberValuePair memberValuePair3 = (MemberValuePair) values.get(0);
+ Expression expression5 = memberValuePair3.getValue();
+ assertEquals("Not a normal annotation", ASTNode.NORMAL_ANNOTATION, expression5.getNodeType());
+ NormalAnnotation annotation4 = (NormalAnnotation) expression5;
+ checkSourceRange(annotation4, "@Jpf.ValidateMinLength(chars=\"12\")", contents);
+ checkSourceRange(memberValuePair3, "validateMinLength=@Jpf.ValidateMinLength(chars=\"12\")", contents);
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=88224
+ public void test0150() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " void foo() {\n" +
+ " class Local {\n" +
+ " static enum E {\n" +
+ " C, B;\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ " void bar() {\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ final String expectedErrors = "The member enum E cannot be local";
+ assertProblemsSize(compilationUnit, 1, expectedErrors);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not a type declaration statement", ASTNode.TYPE_DECLARATION_STATEMENT, node.getNodeType());
+ TypeDeclarationStatement typeDeclarationStatement = (TypeDeclarationStatement) node;
+ AbstractTypeDeclaration typeDeclaration = typeDeclarationStatement.getDeclaration();
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertEquals("Not an enum declaration", ASTNode.ENUM_DECLARATION, bodyDeclaration.getNodeType());
+ EnumDeclaration enumDeclaration = (EnumDeclaration) bodyDeclaration;
+ List enumConstants = enumDeclaration.enumConstants();
+ assertEquals("Wrong size", 2, enumConstants.size());
+ EnumConstantDeclaration enumConstantDeclaration = (EnumConstantDeclaration) enumConstants.get(0);
+ checkSourceRange(enumConstantDeclaration, "C", contents);
+ enumConstantDeclaration = (EnumConstantDeclaration) enumConstants.get(1);
+ checkSourceRange(enumConstantDeclaration, "B", contents);
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=88548
+ public void test0151() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public enum X {\n" +
+ " RED, GREEN(), BLUE(17);\n" +
+ " X() {}\n" +
+ " X(int i) {}\n" +
+ " public static void main(String[] args) {\n" +
+ " for (X x : X.values()) {\n" +
+ " switch(x) {\n" +
+ " case RED :\n" +
+ " System.out.println(\"ROUGE\");\n" +
+ " break;\n" +
+ " case GREEN :\n" +
+ " System.out.println(\"VERT\");\n" +
+ " break;\n" +
+ " case BLUE :\n" +
+ " System.out.println(\"BLEU\");\n" +
+ " break;\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0);
+ assertEquals("Not an enum declaration", ASTNode.ENUM_DECLARATION, node.getNodeType());
+ EnumDeclaration enumDeclaration = (EnumDeclaration) node;
+ List bodyDeclarations = enumDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 3, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(2);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, bodyDeclaration.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ Block block = methodDeclaration.getBody();
+ assertNotNull("No body", block);
+ List statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size());
+ Statement statement = (Statement) statements.get(0);
+ assertEquals("Not an enhanced for statement", ASTNode.ENHANCED_FOR_STATEMENT, statement.getNodeType());
+ EnhancedForStatement forStatement = (EnhancedForStatement) statement;
+ Statement statement2 = forStatement.getBody();
+ assertEquals("Not a block", ASTNode.BLOCK, statement2.getNodeType());
+ Block block2 = (Block) statement2;
+ statements = block2.statements();
+ assertEquals("Wrong size", 1, statements.size());
+ statement = (Statement) statements.get(0);
+ assertEquals("Not a switch statement", ASTNode.SWITCH_STATEMENT, statement.getNodeType());
+ SwitchStatement switchStatement = (SwitchStatement) statement;
+ statements = switchStatement.statements();
+ assertEquals("Wrong size", 9, statements.size());
+ statement = (Statement) statements.get(0);
+ assertEquals("Not a switch case statement", ASTNode.SWITCH_CASE, statement.getNodeType());
+ SwitchCase switchCase = (SwitchCase) statement;
+ Expression expression = switchCase.getExpression();
+ assertNull("Got a constant", expression.resolveConstantExpressionValue());
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=88548
+ public void test0152() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public static final int CONST1 = 1;\n" +
+ " public static final int CONST2 = 2;\n" +
+ " public static void main(String[] args) {\n" +
+ " int[] intTab = new int[] {2, 3};\n" +
+ " for (int i : intTab) {\n" +
+ " switch(i) {\n" +
+ " case CONST1 :\n" +
+ " System.out.println(\"1\");\n" +
+ " break;\n" +
+ " case CONST2 :\n" +
+ " System.out.println(\"2\");\n" +
+ " break;\n" +
+ " default :\n" +
+ " System.out.println(\"default\");\n" +
+ " break;\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 3, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(2);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, bodyDeclaration.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ Block block = methodDeclaration.getBody();
+ assertNotNull("No body", block);
+ List statements = block.statements();
+ assertEquals("Wrong size", 2, statements.size());
+ Statement statement = (Statement) statements.get(1);
+ assertEquals("Not an enhanced for statement", ASTNode.ENHANCED_FOR_STATEMENT, statement.getNodeType());
+ EnhancedForStatement forStatement = (EnhancedForStatement) statement;
+ Statement statement2 = forStatement.getBody();
+ assertEquals("Not a block", ASTNode.BLOCK, statement2.getNodeType());
+ Block block2 = (Block) statement2;
+ statements = block2.statements();
+ assertEquals("Wrong size", 1, statements.size());
+ statement = (Statement) statements.get(0);
+ assertEquals("Not a switch statement", ASTNode.SWITCH_STATEMENT, statement.getNodeType());
+ SwitchStatement switchStatement = (SwitchStatement) statement;
+ statements = switchStatement.statements();
+ assertEquals("Wrong size", 9, statements.size());
+ statement = (Statement) statements.get(0);
+ assertEquals("Not a switch case statement", ASTNode.SWITCH_CASE, statement.getNodeType());
+ SwitchCase switchCase = (SwitchCase) statement;
+ Expression expression = switchCase.getExpression();
+ Object constant = expression.resolveConstantExpressionValue();
+ assertNotNull("No constant", constant);
+ assertEquals("Wrong value", "1", String.valueOf(constant));
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=88841
+ public void test0153() throws CoreException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0153", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=87173
+ public void test0154() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public static void main(String[] s) {\n" +
+ " test(/*start*/1/*end*/);\n" +
+ " }\n" +
+ " public static void test(Integer i) {}\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a number literal", ASTNode.NUMBER_LITERAL, node.getNodeType());
+ NumberLiteral literal = (NumberLiteral) node;
+ assertTrue("Not boxed", literal.resolveBoxing());
+ assertFalse("Is unboxed", literal.resolveUnboxing());
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=87173
+ public void test0155() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public static int bar() {return 1;}\n" +
+ " public static void main(String[] s) {\n" +
+ " test(/*start*/bar()/*end*/);\n" +
+ " }\n" +
+ " public static void test(Integer i) {}\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, node.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) node;
+ assertTrue("Not boxed", methodInvocation.resolveBoxing());
+ assertFalse("Is unboxed", methodInvocation.resolveUnboxing());
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=87173
+ public void test0156() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public static void main(String[] s) {\n" +
+ " test(/*start*/new Integer(1)/*end*/);\n" +
+ " }\n" +
+ " public static void test(int i) {}\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a class instance creation", ASTNode.CLASS_INSTANCE_CREATION, node.getNodeType());
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) node;
+ assertFalse("Is boxed", classInstanceCreation.resolveBoxing());
+ assertTrue("Not unboxed", classInstanceCreation.resolveUnboxing());
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=88548
+ public void test0157() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public static void main(String[] s) {\n" +
+ " test(/*start*/null/*end*/);\n" +
+ " }\n" +
+ " public static void test(Object o) {}\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a null literal", ASTNode.NULL_LITERAL, node.getNodeType());
+ NullLiteral nullLiteral = (NullLiteral) node;
+ assertNull("Got a constant", nullLiteral.resolveConstantExpressionValue());
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=88548
+ public void test0158() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " private static final String CONST = \"Hello World\";\n" +
+ " public static void main(String[] s) {\n" +
+ " System.out.println(/*start*/CONST/*end*/);\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a simple name", ASTNode.SIMPLE_NAME, node.getNodeType());
+ SimpleName name = (SimpleName) node;
+ assertNotNull("No constant", name.resolveConstantExpressionValue());
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=87173
+ public void test0159() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public static void main(String[] s) {\n" +
+ " test(/*start*/new Integer(1)/*end*/);\n" +
+ " }\n" +
+ " public static void test(Integer i) {}\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a class instance creation", ASTNode.CLASS_INSTANCE_CREATION, node.getNodeType());
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) node;
+ assertFalse("Is boxed", classInstanceCreation.resolveBoxing());
+ assertFalse("Is unboxed", classInstanceCreation.resolveUnboxing());
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=87173
+ public void test0160() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public static void main(String[] s) {\n" +
+ " Y.test(1, new Integer(2), -3);\n" +
+ " }\n" +
+ "}\n" +
+ "class Y {\n" +
+ " public static void test(int ... i) {}\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertEquals("Not method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ List arguments = methodInvocation.arguments();
+ assertEquals("Wrong size", 3, arguments.size());
+ Expression argument = (Expression) arguments.get(0);
+ assertFalse("Is boxed", argument.resolveBoxing());
+ assertFalse("Is unboxed", argument.resolveUnboxing());
+ argument = (Expression) arguments.get(1);
+ assertFalse("Is boxed", argument.resolveBoxing());
+ assertTrue("Not unboxed", argument.resolveUnboxing());
+ argument = (Expression) arguments.get(2);
+ assertFalse("Is boxed", argument.resolveBoxing());
+ assertFalse("Is unboxed", argument.resolveUnboxing());
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=87173
+ public void test0161() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public static void main(String[] s) {\n" +
+ " new Y().test(new Integer(1), 1);\n" +
+ " new Y().test(1, new Integer(1));\n" +
+ " }\n" +
+ "}\n" +
+ "class Y {\n" +
+ " void test(Integer i, int j) { System.out.print(1); }\n" +
+ " void test(int i, Integer j) { System.out.print(2); }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertEquals("Not method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ List arguments = methodInvocation.arguments();
+ assertEquals("Wrong size", 2, arguments.size());
+ Expression argument = (Expression) arguments.get(0);
+ assertFalse("Is boxed", argument.resolveBoxing());
+ assertFalse("Is unboxed", argument.resolveUnboxing());
+ argument = (Expression) arguments.get(1);
+ assertFalse("Is boxed", argument.resolveBoxing());
+ assertFalse("Is unboxed", argument.resolveUnboxing());
+ getASTNode(compilationUnit, 0, 0, 1);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ expressionStatement = (ExpressionStatement) node;
+ expression = expressionStatement.getExpression();
+ assertEquals("Not method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ methodInvocation = (MethodInvocation) expression;
+ arguments = methodInvocation.arguments();
+ assertEquals("Wrong size", 2, arguments.size());
+ argument = (Expression) arguments.get(0);
+ assertFalse("Is boxed", argument.resolveBoxing());
+ assertFalse("Is unboxed", argument.resolveUnboxing());
+ argument = (Expression) arguments.get(1);
+ assertFalse("Is boxed", argument.resolveBoxing());
+ assertFalse("Is unboxed", argument.resolveUnboxing());
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=87173
+ public void test0162() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public static void main(String[] s) {\n" +
+ " int i = Y.test();\n" +
+ " System.out.print(i);\n" +
+ " }\n" +
+ "}\n" +
+ "class Y {\n" +
+ " public static Byte test() { return new Byte((byte) 1); }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertFalse("Is boxed", expression.resolveBoxing());
+ assertTrue("Not unboxed", expression.resolveUnboxing());
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=86580
+ public void test0163() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X<T>{\n" +
+ " void f(T t){}\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ assertEquals("Wrong size", 1, parameters.size());
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ Type type = singleVariableDeclaration.getType();
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertTrue("Not a type variable", typeBinding.isTypeVariable());
+ assertTrue("Not from source", typeBinding.isFromSource());
+ final ITypeBinding declaringClass = typeBinding.getDeclaringClass();
+ assertNotNull("No declaring class", declaringClass);
+ assertTrue("Not a generic class", declaringClass.isGenericType());
+ assertEquals("Wrong name", "X", declaringClass.getName());
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=86580
+ public void test0164() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "class X {\n" +
+ " <U> void foo(U u) {}\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ assertEquals("Wrong size", 1, parameters.size());
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ Type type = singleVariableDeclaration.getType();
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertTrue("Not a type variable", typeBinding.isTypeVariable());
+ assertTrue("Not from source", typeBinding.isFromSource());
+ final IMethodBinding methodBinding = typeBinding.getDeclaringMethod();
+ assertNotNull("No declaring method", methodBinding);
+ assertEquals("Wrong name", "foo", methodBinding.getName());
+ assertTrue("Not a generic method", methodBinding.isGenericMethod());
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=86580
+ public void test0165() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "class X {\n" +
+ " <U> void foo(U u) {\n" +
+ " class C {}\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not a type declaration statement", ASTNode.TYPE_DECLARATION_STATEMENT, node.getNodeType());
+ TypeDeclarationStatement statement = (TypeDeclarationStatement) node;
+ AbstractTypeDeclaration typeDeclaration = statement.getDeclaration();
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertTrue("Not a local type", typeBinding.isLocal());
+ ITypeBinding declaringClass = typeBinding.getDeclaringClass();
+ assertNotNull("No declaring class", declaringClass);
+ IMethodBinding declaringMethod = typeBinding.getDeclaringMethod();
+ assertNotNull("No declaring method", declaringMethod);
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=86580
+ public void test0166() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "class X {\n" +
+ " {\n" +
+ " class C {}\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not a type declaration statement", ASTNode.TYPE_DECLARATION_STATEMENT, node.getNodeType());
+ TypeDeclarationStatement statement = (TypeDeclarationStatement) node;
+ AbstractTypeDeclaration typeDeclaration = statement.getDeclaration();
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertTrue("Not a local type", typeBinding.isLocal());
+ ITypeBinding declaringClass = typeBinding.getDeclaringClass();
+ assertNotNull("No declaring class", declaringClass);
+ IMethodBinding declaringMethod = typeBinding.getDeclaringMethod();
+ assertNull("No declaring method", declaringMethod);
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=88841
+ public void test0167() throws CoreException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0167", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ ASTNode node = getASTNode(compilationUnit, 1, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ assertEquals("wrong size", 4, parameters.size());
+ SingleVariableDeclaration param = (SingleVariableDeclaration)parameters.get(3);
+ Type t = param.getType();
+ String typeName = ((SimpleType)t).getName().getFullyQualifiedName();
+
+ IType[] types = sourceUnit.getTypes();
+ assertEquals("wrong size", 2, types.length);
+ IType mainType = types[1];
+ String[][] typeMatches = mainType.resolveType( typeName );
+ assertNotNull(typeMatches);
+ assertEquals("wrong size", 1, typeMatches.length);
+ String[] typesNames = typeMatches[0];
+ assertEquals("wrong size", 2, typesNames.length);
+ assertEquals("Wrong part 1", "java.lang", typesNames[0]);
+ assertEquals("Wrong part 2", "Object", typesNames[1]);
+ }
+
+ public void test0168() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ final String contents =
+ "import java.util.List;\n" +
+ "public class X {\n" +
+ " void f() {\n" +
+ " List<?> list = null;\n" +
+ " System.out.println(list);\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0, 1);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement statement = (ExpressionStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ List arguments = methodInvocation.arguments();
+ assertEquals("Wrong size", 1, arguments.size());
+ Expression argument = (Expression) arguments.get(0);
+ ITypeBinding typeBinding = argument.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding);
+ assertTrue("Not a parameterized binding", typeBinding.isParameterizedType());
+ ITypeBinding[] typeArguments = typeBinding.getTypeArguments();
+ assertEquals("Wrong size", 1, typeArguments.length);
+ final ITypeBinding typeBinding2 = typeArguments[0];
+ assertTrue("Not a capture binding", typeBinding2.isCapture());
+ assertTrue("Not from source", typeBinding2.isFromSource());
+ assertNotNull("No wildcard", typeBinding2.getWildcard());
+ }
+
+ public void test0169() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " static class BB<T, S> { }\n" +
+ " static class BD<T> extends BB<T, T> { }\n" +
+ " void f() {\n" +
+ " BB<? extends Number, ? super Integer> bb = null;\n" +
+ " Object o = (BD<Number>) bb;\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 1, "Type safety: Unchecked cast from X.BB<capture#1-of ? extends Number,capture#2-of ? super Integer> to X.BD<Number>");
+ node = getASTNode(compilationUnit, 0, 2, 1);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not a cast expression", ASTNode.CAST_EXPRESSION, expression.getNodeType());
+ CastExpression castExpression = (CastExpression) expression;
+ Expression expression2 = castExpression.getExpression();
+ ITypeBinding typeBinding = expression2.resolveTypeBinding();
+ assertTrue("Not a parameterized type", typeBinding.isParameterizedType());
+ ITypeBinding[] typeArguments = typeBinding.getTypeArguments();
+ assertEquals("Wrong size", 2, typeArguments.length);
+ final ITypeBinding typeBinding2 = typeArguments[0];
+ assertTrue("Not a capture binding", typeBinding2.isCapture());
+ ITypeBinding wildcardBinding = typeBinding2.getWildcard();
+ assertNotNull("No wildcard binding", wildcardBinding);
+ assertTrue("Not from source", typeBinding2.isFromSource());
+ assertTrue("Not a wildcard", wildcardBinding.isWildcardType());
+ }
+
+ public void test0170() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " static class BB<T, S> { }\n" +
+ " static class BD<T> extends BB<T, T> { }\n" +
+ " static BB<? extends Number, ? super Integer> bb = null;\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(/*start*/X.bb/*end*/);\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertNotNull("No node", node);
+ assertEquals("Not a qualified name", ASTNode.QUALIFIED_NAME, node.getNodeType());
+ QualifiedName qualifiedName = (QualifiedName) node;
+ ITypeBinding typeBinding = qualifiedName.resolveTypeBinding();
+ assertTrue("Not a parameterized type", typeBinding.isParameterizedType());
+ ITypeBinding[] typeArguments = typeBinding.getTypeArguments();
+ assertEquals("Wrong size", 2, typeArguments.length);
+ final ITypeBinding typeBinding2 = typeArguments[0];
+ assertTrue("Not a capture binding", typeBinding2.isCapture());
+ ITypeBinding wildcardBinding = typeBinding2.getWildcard();
+ assertNotNull("No wildcard binding", wildcardBinding);
+ assertTrue("Not from source", typeBinding2.isFromSource());
+ assertTrue("Not a wildcard", wildcardBinding.isWildcardType());
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=92361
+ */
+ public void test0171() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ "\n" +
+ " java.util.List<? extends Runnable> list;\n" +
+ " Object o= /*start*/list/*end*/;\n" +
+ "}\n";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a simple name", ASTNode.SIMPLE_NAME, node.getNodeType());
+ ITypeBinding type = ((SimpleName)node).resolveTypeBinding();
+ assertNull("Unexpected element", type.getTypeArguments()[0].getJavaElement());
+ }
+
+ /*
+ * Ensures that 2 different capture bindings are not "isEqualTo(...)".
+ * (regression test for bug 92888 ITypeBinding#isEqualTo(..) is wrong for capture bindings)
+ */
+ public void test0172() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X<T> {\n" +
+ " private static X<? super Number> num() {\n" +
+ " return null;\n" +
+ " }\n" +
+ " void add(T t) {\n" +
+ " }\n" +
+ " void foo() {\n" +
+ " Number n= null;\n" +
+ " /*start1*/num().add(null)/*end1*/;\n" +
+ " /*start2*/num().add(n)/*end2*/;\n" +
+ " }\n" +
+ "}\n";
+ IBinding[] bindings = resolveBindings(contents, this.workingCopy);
+ assertTrue("2 different capture bindings should not be equals", !bindings[0].isEqualTo(bindings[1]));
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=93093
+ */
+ public void test0173() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "import java.util.Vector;\n" +
+ "\n" +
+ "@SuppressWarnings(\"null\")\n" +
+ "public class X {\n" +
+ " void test1() {\n" +
+ " Vector<? extends Number[]> v = null;\n" +
+ " /*start*/v.get(0)/*end*/;\n" +
+ " }\n" +
+ "}\n";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ ITypeBinding type = ((Expression)node).resolveTypeBinding();
+ assertTrue("Should be one bound", type.getTypeBounds().length == 1);
+ assertEquals("Invalid bound", "[Ljava.lang.Number;", type.getTypeBounds()[0].getBinaryName());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=92982
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=88202
+ */
+ public void test0174() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "import java.util.*;\n" +
+ "\n" +
+ "public class X {\n" +
+ " void test1() {\n" +
+ " List<? extends Collection> l = null;\n" +
+ " /*start*/l.get(0)/*end*/;\n" +
+ " }\n" +
+ "}\n";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ ITypeBinding type = ((Expression)node).resolveTypeBinding();
+ assertTrue("Should be one bound", type.getTypeBounds().length == 1);
+ assertEquals("Invalid bound", "java.util.Collection", type.getTypeBounds()[0].getBinaryName());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=88202
+ */
+ public void test0175() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "import java.util.*;\n" +
+ "\n" +
+ "@SuppressWarnings(\"null\")\n" +
+ "public class X {\n" +
+ " void test1() {\n" +
+ " List<?> l = null;\n" +
+ " /*start*/l.get(0)/*end*/;\n" +
+ " }\n" +
+ "}\n";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ ITypeBinding type = ((Expression)node).resolveTypeBinding();
+ assertTrue("Should be no bound", type.getTypeBounds().length == 0);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=92982
+ */
+ public void test0176() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "import java.util.*;\n" +
+ "\n" +
+ "public class X<T extends Collection> {\n" +
+ " void test1() {\n" +
+ " List<T> l = null;\n" +
+ " /*start*/l.get(0)/*end*/;\n" +
+ " }\n" +
+ "}\n";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ ITypeBinding type = ((Expression)node).resolveTypeBinding();
+ assertTrue("Should be one bound", type.getTypeBounds().length == 1);
+ assertEquals("Invalid bound", "java.util.Collection", type.getTypeBounds()[0].getBinaryName());
+ }
+
+ /*
+ * Ensure that the declaring class of a capture binding is correct
+ * (https://bugs.eclipse.org/bugs/show_bug.cgi?id=93275)
+ */
+ public void test0177() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X<T> {\n" +
+ " Object foo(X<?> list) {\n" +
+ " return /*start*/list.get()/*end*/;\n" +
+ " }\n" +
+ " T get() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ MethodInvocation methodInvocation = (MethodInvocation) node;
+ ITypeBinding capture = methodInvocation.resolveTypeBinding();
+ ITypeBinding declaringClass = capture.getDeclaringClass();
+ assertBindingEquals("LX<TT;>;", declaringClass);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=93075
+ */
+ public void test0178() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "import java.util.Vector;\n" +
+ "\n" +
+ "public class X {\n" +
+ " void foo() {\n" +
+ " Vector< ? super java.util.Collection<? super java.lang.Number> > lhs= null; \n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ Type type = statement.getType();
+ checkSourceRange(type, "Vector< ? super java.util.Collection<? super java.lang.Number> >", contents);
+ assertEquals("Not a parameterized type", ASTNode.PARAMETERIZED_TYPE, type.getNodeType());
+ ParameterizedType parameterizedType = (ParameterizedType) type;
+ List typeArguments = parameterizedType.typeArguments();
+ assertEquals("Wrong size", 1, typeArguments.size());
+ Type typeArgument = (Type) typeArguments.get(0);
+ assertEquals("Not a wildcard type", ASTNode.WILDCARD_TYPE, typeArgument.getNodeType());
+ WildcardType wildcardType = (WildcardType) typeArgument;
+ checkSourceRange(wildcardType, "? super java.util.Collection<? super java.lang.Number>", contents);
+ Type bound = wildcardType.getBound();
+ assertEquals("Not a parameterized type", ASTNode.PARAMETERIZED_TYPE, bound.getNodeType());
+ ParameterizedType parameterizedType2 = (ParameterizedType) bound;
+ checkSourceRange(bound, "java.util.Collection<? super java.lang.Number>", contents);
+ typeArguments = parameterizedType2.typeArguments();
+ assertEquals("Wrong size", 1, typeArguments.size());
+ typeArgument = (Type) typeArguments.get(0);
+ assertEquals("Not a wildcard type", ASTNode.WILDCARD_TYPE, typeArgument.getNodeType());
+ wildcardType = (WildcardType) typeArgument;
+ checkSourceRange(wildcardType, "? super java.lang.Number", contents);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=93075
+ */
+ public void test0179() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "@interface Test {}\n" +
+ "public enum X\n" +
+ "{\n" +
+ " /*start*/@Test HISTORY/*end*/\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not an enum constant declaration", ASTNode.ENUM_CONSTANT_DECLARATION, node.getNodeType());
+ EnumConstantDeclaration constantDeclaration = (EnumConstantDeclaration) node;
+ List modifiers = constantDeclaration.modifiers();
+ assertEquals("Wrong size", 1, modifiers.size());
+ IExtendedModifier modifier = (IExtendedModifier) modifiers.get(0);
+ assertTrue("Not a marker annotation", modifier instanceof MarkerAnnotation);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=92360
+ */
+ public void test0180() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "import java.util.List;\n" +
+ "public class X {\n" +
+ " List</*start*/? extends Runnable/*end*/> list;\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a wildcard type", ASTNode.WILDCARD_TYPE, node.getNodeType());
+ WildcardType wildcardType = (WildcardType) node;
+ ITypeBinding typeBinding = wildcardType.resolveBinding();
+ assertTrue("Not a wildcard type", typeBinding.isWildcardType());
+ assertFalse("Not an class", typeBinding.isClass());
+ }
+
+ /*
+ * Ensures that 2 different parameterized type bindings are not "isEqualTo(...)".
+ * (regression test for bug 93408 ITypeBinding#isEqualTo(..) does not resolve type variables)
+ */
+ public void test0181() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X<E> {\n" +
+ " /*start1*/Y<E>/*end1*/ y;\n" +
+ " static class Other<E> {\n" +
+ " /*start2*/Y<E>/*end2*/ y;\n" +
+ " }\n" +
+ "}\n" +
+ "class Y<E> {\n" +
+ "}";
+ IBinding[] bindings = resolveBindings(contents, this.workingCopy);
+ assertTrue("2 different parameterized type bindings should not be equals", !bindings[0].isEqualTo(bindings[1]));
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=95911
+ */
+ public void test0182() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ final String contents =
+ "import java.util.Map;\n" +
+ "\n" +
+ "public class X {\n" +
+ " public void foo() {\n" +
+ " Map<String, Number> map= new Map<String, Number>() {\n" +
+ " };\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ String expectedSource = "map= new Map<String, Number>() {\n" +
+ " }";
+ checkSourceRange(fragment, expectedSource, contents);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=95911
+ */
+ public void test0183() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ final String contents =
+ "import java.util.Map;\n" +
+ "\n" +
+ "public class X {\n" +
+ " Map<String, Number> map= new Map<String, Number>() {\n" +
+ " };\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ String expectedSource = "map= new Map<String, Number>() {\n" +
+ " }";
+ checkSourceRange(fragment, expectedSource, contents);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=97841
+ */
+ public void test0184() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ final String contents =
+ "public class X {\n" +
+ " java.util.Map<String, Number> map= new java.util.Map<String, Number>() {\n" +
+ " };\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression initializer = fragment.getInitializer();
+ assertNotNull("No initializer", initializer);
+ ITypeBinding binding = initializer.resolveTypeBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=98086
+ */
+ public void test0185() throws JavaModelException {
+ final ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0185", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertEquals("Wrong setting", JavaCore.WARNING, sourceUnit.getJavaProject().getOption(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, true));
+ final ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ final CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=98086
+ */
+ public void test0186() throws JavaModelException {
+ final ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0186", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertEquals("Wrong setting", JavaCore.WARNING, sourceUnit.getJavaProject().getOption(JavaCore.COMPILER_PB_UNCHECKED_TYPE_OPERATION, true));
+ final ASTNode result = runJLS3Conversion(sourceUnit, true, true);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ final CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 2, "Type safety: The expression of type ArrayList needs unchecked conversion to conform to List<String>\n" +
+ "ArrayList is a raw type. References to generic type ArrayList<T> should be parameterized");
+ }
+
+ /*
+ * Ensures that the binding key of a parameterized type can be computed when it contains a reference to a type variable.
+ * (regression test for bug 98259 NPE computing ITypeBinding#getKey())
+ */
+ public void test0187() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ final String contents =
+ "public class X {\n" +
+ " <T> /*start*/Y<T>/*end*/ foo() {\n" +
+ " return null;" +
+ " };\n" +
+ "}\n" +
+ "class Y<E> {\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ ParameterizedType type = (ParameterizedType) node;
+ assertBindingEquals(
+ "LX~Y<LX;:1TT;>;",
+ type.resolveBinding());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=98473
+ */
+ public void test0188() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ final String contents =
+ "import java.util.List;\n" +
+ "\n" +
+ "public class X {\n" +
+ " class Counter<T, /*start*/L extends List<T>/*end*/> {\n" +
+ " private L _attribute;\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a type parameter", ASTNode.TYPE_PARAMETER, node.getNodeType());
+ ITypeBinding typeBinding = ((TypeParameter) node).resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertFalse("Cannot be top level", typeBinding.isTopLevel());
+ assertFalse("A class", typeBinding.isClass());
+ assertFalse("An interface", typeBinding.isInterface());
+ assertTrue("Not a type variable", typeBinding.isTypeVariable());
+ assertTrue("Not from source", typeBinding.isFromSource());
+ }
+
+ public void test0189() throws CoreException, IOException {
+ try {
+ IJavaProject project = createJavaProject("P1", new String[] {""}, new String[] {"CONVERTER_JCL15_LIB"}, "", "1.5");
+ addLibrary(project, "lib.jar", "src.zip", new String[] {
+ "/P1/p/I1.java",
+ "package p;\n" +
+ "public class I1<E> {\n" +
+ "}",
+ "/P1/p/I2.java",
+ "package p;\n" +
+ "public interface I2<K, V> {\n" +
+ " interface I3<K,V> {}\n" +
+ " I1<I2.I3<K, V>> foo();\n" +
+ "}",
+ "/P1/p/X.java",
+ "package p;\n" +
+ "public class X<K,V> implements I2<K,V> {\n" +
+ " public I1<I2.I3<K,V>> foo() {\n" +
+ " return null;\n" +
+ " } \n" +
+ "}"
+ }, "1.5");
+ this.workingCopy = getWorkingCopy("/P1/p1/Y.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ "package p1;\n" +
+ "import p.*;\n" +
+ "public abstract class Y implements I2 {\n" +
+ " public I1 foo() {\n" +
+ " return /*start*/bar().foo()/*end*/;\n" +
+ " }\n" +
+ " private X bar() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}",
+ this.workingCopy,
+ false);
+ MethodInvocation method = (MethodInvocation) node;
+ IMethodBinding methodBinding = method.resolveMethodBinding();
+ assertBindingEquals(
+ "Lp/X;.foo()Lp/I1<Lp/I2$I3<TK;TV;>;>;",
+ methodBinding.getMethodDeclaration());
+ } finally {
+ deleteProject("P1");
+ }
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=99355
+ public void test0190() throws CoreException, IOException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ final String contents =
+ "class Container<T> {\n" +
+ " private final T m_t;\n" +
+ "\n" +
+ " public Container(T t) {\n" +
+ " m_t = t;\n" +
+ " }\n" +
+ "\n" +
+ " T get() {\n" +
+ " return m_t;\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "class GenericContainer {\n" +
+ " private final Container<?> m_c;\n" +
+ "\n" +
+ " public GenericContainer(Container<?> c) {\n" +
+ " m_c = c;\n" +
+ " }\n" +
+ "\n" +
+ " public Container<?> getC() {\n" +
+ " return m_c;\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "public class X {\n" +
+ " GenericContainer createContainer() {\n" +
+ " final Container<String> innerContainer = new Container<String>(\"hello\");\n" +
+ " final Container<Container<String>> outerContainer = new Container<Container<String>>(\n" +
+ " innerContainer);\n" +
+ " return new GenericContainer(outerContainer);\n" +
+ " }\n" +
+ "\n" +
+ " void method() {\n" +
+ " final GenericContainer createContainer = createContainer();\n" +
+ " /*start*/@SuppressWarnings(\"unchecked\")\n" +
+ " final Container<Container<String>> c = (Container<Container<String>>) createContainer.getC();/*end*/\n" +
+ " final Container<String> container = c.get();\n" +
+ " final String string = container.get();\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List modifiers = statement.modifiers();
+ assertEquals("Wrong size", 2, modifiers.size());
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=99510
+ public void test0191() throws CoreException, IOException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0191", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode node = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 1, "Type safety: Unchecked cast from Collection<capture#1-of ? extends Number> to Vector<Object>");
+ node = getASTNode(unit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression initializer = fragment.getInitializer();
+ assertNotNull("No initializer", initializer);
+ assertEquals("Not a cast expression", ASTNode.CAST_EXPRESSION, initializer.getNodeType());
+ CastExpression castExpression = (CastExpression) initializer;
+ Type type = castExpression.getType();
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ Expression expression = castExpression.getExpression();
+ ITypeBinding typeBinding2 = expression.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding2);
+ assertTrue("Not cast compatible", typeBinding2.isCastCompatible(typeBinding));
+ }
+
+ // Wrong ParameterizedTypeBinding yields null type declaration result
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=100584
+ public void test0192() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X<E> {\n" +
+ " public static class InnerClass {\n" +
+ " static class InnerInnerClass {\n" +
+ " /*start*/X.WrongInnerClass/*end*/.InnerInnerClass m;\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ IBinding[] bindings = resolveBindings(contents, this.workingCopy, false/*don't report errors*/);
+ if (bindings[0] != null) {
+ // should not get here if patch 100584 applied
+ try {
+ bindings[0].toString();
+ fail("should get an exception if bug 100584 present");
+ // which means that the code would now return a non null,
+ // erroneous binding, yet able to respond to toString
+ } catch (Throwable t) {/* absorb quietly */}
+ }
+ assertTrue("should yield a null, not a malformed binding",
+ bindings[0] == null);
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=104492
+ public void test0193() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " byte[] b1 = new byte[0];\n" +
+ " byte[] b2 = new byte[0];\n" +
+ " for (byte[] bs : new byte[][] { b1, b2 }) {}\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ node = getASTNode(unit, 0, 0, 2);
+ assertEquals("Not an enhanced for statement", ASTNode.ENHANCED_FOR_STATEMENT, node.getNodeType());
+ EnhancedForStatement forStatement = (EnhancedForStatement) node;
+ SingleVariableDeclaration singleVariableDeclaration = forStatement.getParameter();
+ assertEquals("Should be 0", 0, singleVariableDeclaration.getExtraDimensions());
+ Type type = singleVariableDeclaration.getType();
+ assertEquals("Not an array type", ASTNode.ARRAY_TYPE, type.getNodeType());
+ ArrayType arrayType = (ArrayType) type;
+ assertEquals("Should be 1", 1, arrayType.getDimensions());
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=104492
+ public void test0194() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " byte[] b1 = new byte[0];\n" +
+ " byte[] b2 = new byte[0];\n" +
+ " for (byte[] bs/*comment*/ [ /*comment*/ ]: new byte[][][] { new byte[][] { b1, b2 }}) {}\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ node = getASTNode(unit, 0, 0, 2);
+ assertEquals("Not an enhanced for statement", ASTNode.ENHANCED_FOR_STATEMENT, node.getNodeType());
+ EnhancedForStatement forStatement = (EnhancedForStatement) node;
+ SingleVariableDeclaration singleVariableDeclaration = forStatement.getParameter();
+ assertEquals("Should be 1", 1, singleVariableDeclaration.getExtraDimensions());
+ Type type = singleVariableDeclaration.getType();
+ assertEquals("Not an array type", ASTNode.ARRAY_TYPE, type.getNodeType());
+ ArrayType arrayType = (ArrayType) type;
+ assertEquals("Should be 1", 1, arrayType.getDimensions());
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=106834
+ public void test0195() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " <S extends Number, T> void take(S e, T f) {}\n" +
+ " <S extends Number, T> void take(T e, S f) {}\n" +
+ " <S extends Number, T extends S> void take(T e, S f) {}\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+
+ node = getASTNode(unit, 0, 1);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration2 = (MethodDeclaration) node;
+ IMethodBinding methodBinding2 = methodDeclaration2.resolveBinding();
+
+ node = getASTNode(unit, 0, 2);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration3 = (MethodDeclaration) node;
+ IMethodBinding methodBinding3 = methodDeclaration3.resolveBinding();
+
+ assertFalse("Bindings are equals", methodBinding.isEqualTo(methodBinding2));
+ assertFalse("Bindings are equals", methodBinding2.isEqualTo(methodBinding));
+ assertFalse("Bindings are equals", methodBinding3.isEqualTo(methodBinding));
+ assertFalse("Bindings are equals", methodBinding3.isEqualTo(methodBinding2));
+ assertFalse("Bindings are equals", methodBinding2.isEqualTo(methodBinding3));
+ assertFalse("Bindings are equals", methodBinding.isEqualTo(methodBinding3));
+ assertTrue("Bindings are not equals", methodBinding3.isEqualTo(methodBinding3));
+ assertTrue("Bindings are not equals", methodBinding2.isEqualTo(methodBinding2));
+ assertTrue("Bindings are not equals", methodBinding.isEqualTo(methodBinding));
+ }
+
+ /*
+ * Ensures that the signature of and IBinding representing a local type ends with the local type's simple name.
+ * (regression test for bug 104879 BindingKey#internalToSignature() returns invalid signature for local type
+ */
+ public void test0196() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " void foo() {\n" +
+ " /*start*/class Y {\n" +
+ " }/*end*/\n" +
+ " }\n" +
+ "}",
+ this.workingCopy);
+ IBinding binding = ((TypeDeclarationStatement) node).resolveBinding();
+ assertNotNull("No binding", binding);
+
+ String key = binding.getKey();
+ String signature = new BindingKey(key).toSignature();
+ String simpleName = Signature.getSimpleName(Signature.toString(signature));
+ assertEquals("Unexpected simple name", "Y", simpleName);
+ }
+
+
+ /*
+ * Ensures that creating an AST with binding resolution where there is a problem in a binary
+ * doesn't throw an NPE
+ * (regression test for bug 100606 NPE during reconcile)
+ */
+ public void test0197() throws CoreException {
+ try {
+ createJavaProject("P", new String[] {"src" }, new String[] {"CONVERTER_JCL15_LIB", "/P/lib"}, "bin", "1.5");
+ IFolder folder = createFolder("/P/lib");
+ String classesPath = folder.getLocation().toOSString();
+ Map options = new HashMap();
+ String[] pathsAndContents = new String[] {
+ "p/Bin.java",
+ "package p;\n" +
+ "public class Bin {\n" +
+ "}",
+ "p/BinSub.java",
+ "package p;\n" +
+ "public class BinSub extends Bin {\n" +
+ "}",
+ };
+ Util.compile(pathsAndContents, options, classesPath);
+ folder.refreshLocal(IResource.DEPTH_INFINITE, null);
+// folder.getFolder("p").getFile("Bin.class").delete(false, null);
+ Util.delete(folder.getFolder("p").getFile("Bin.class"));
+ this.workingCopy = getWorkingCopy("/P/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " void bar() throws p.BinSub {\n" +
+ " }\n" +
+ " </*start*/T/*end*/> void foo() {\n" +
+ " }\n" +
+ "}";
+ IBinding[] bindings = resolveBindings(contents, this.workingCopy, false/*don't report errors*/);
+ assertBindingsEqual(
+ "LX;.foo<T:Ljava/lang/Object;>()V:TT;",
+ bindings);
+ } finally {
+ deleteProject("P");
+ }
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=110773
+ */
+ public void test0198() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ "public class X<E> {\n" +
+ " class B { }\n" +
+ " {\n" +
+ " X<String>.B b;\n" +
+ " }\n" +
+ "}",
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 1);
+ assertEquals("Not a initializer", ASTNode.INITIALIZER, node.getNodeType());
+ Initializer initializer = (Initializer) node;
+ Block block = initializer.getBody();
+ assertNotNull("No block", block);
+ List statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size());
+ Statement statement = (Statement) statements.get(0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, statement.getNodeType());
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) statement;
+ Type type = variableDeclarationStatement.getType();
+ ITypeBinding typeBinding = type.resolveBinding();
+ node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding2 = typeDeclaration.resolveBinding();
+ assertTrue("Not a member type", typeDeclaration.isMemberTypeDeclaration());
+ assertFalse("Binding should not be equals", typeBinding.isEqualTo(typeBinding2));
+ assertFalse("Binding should not be equals", typeBinding2.isEqualTo(typeBinding));
+ ITypeBinding typeBinding3 = typeBinding.getTypeDeclaration();
+ assertFalse("Binding should not be equals", typeBinding.isEqualTo(typeBinding3));
+ assertFalse("Binding should not be equals", typeBinding3.isEqualTo(typeBinding));
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=110657
+ */
+ public void test0199() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ final String source = "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " byte[] b1 = new byte[0];\n" +
+ " byte[] b2 = new byte[0];\n" +
+ " for (byte[] bs : new byte[][] { b1, b2 }) {\n" +
+ " System.out.println(bs);\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ source,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0, 2);
+ assertEquals("Not an enhanced for statement", ASTNode.ENHANCED_FOR_STATEMENT, node.getNodeType());
+ EnhancedForStatement forStatement = (EnhancedForStatement) node;
+ final SingleVariableDeclaration parameter = forStatement.getParameter();
+ final Type type = parameter.getType();
+ checkSourceRange(type, "byte[]", source);
+ checkSourceRange(parameter, "byte[] bs", source);
+ assertTrue("not an array type", type.isArrayType());
+ ArrayType arrayType = (ArrayType) type;
+ Type elementType = arrayType.getElementType();
+ assertTrue("not a primitive type", elementType.isPrimitiveType());
+ checkSourceRange(elementType, "byte", source);
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=110657
+ */
+ public void test0200() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ final String source = "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " byte[] b1 = new byte[0];\n" +
+ " byte[] b2 = new byte[0];\n" +
+ " for (final byte[] bs : new byte[][] { b1, b2 }) {\n" +
+ " System.out.println(bs);\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ source,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0, 2);
+ assertEquals("Not an enhanced for statement", ASTNode.ENHANCED_FOR_STATEMENT, node.getNodeType());
+ EnhancedForStatement forStatement = (EnhancedForStatement) node;
+ final SingleVariableDeclaration parameter = forStatement.getParameter();
+ final Type type = parameter.getType();
+ checkSourceRange(type, "byte[]", source);
+ checkSourceRange(parameter, "final byte[] bs", source);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=110657
+ */
+ public void test0201() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ final String source = "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " byte[] b1 = new byte[0];\n" +
+ " byte[] b2 = new byte[0];\n" +
+ " for (final byte bs[] : new byte[][] { b1, b2 }) {\n" +
+ " System.out.println(bs);\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ source,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0, 2);
+ assertEquals("Not an enhanced for statement", ASTNode.ENHANCED_FOR_STATEMENT, node.getNodeType());
+ EnhancedForStatement forStatement = (EnhancedForStatement) node;
+ final SingleVariableDeclaration parameter = forStatement.getParameter();
+ final Type type = parameter.getType();
+ assertEquals("Wrong extended dimension", 1, parameter.getExtraDimensions());
+ checkSourceRange(type, "byte", source);
+ checkSourceRange(parameter, "final byte bs[]", source);
+ assertTrue("not a primitive type", type.isPrimitiveType());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=110657
+ */
+ public void test0202() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ final String source = "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " byte[] b1 = new byte[0];\n" +
+ " byte[] b2 = new byte[0];\n" +
+ " for (@Ann final byte bs[] : new byte[][] { b1, b2 }) {\n" +
+ " System.out.println(bs);\n" +
+ " }\n" +
+ " }\n" +
+ "}\n" +
+ "@interface Ann {}";
+ ASTNode node = buildAST(
+ source,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0, 2);
+ assertEquals("Not an enhanced for statement", ASTNode.ENHANCED_FOR_STATEMENT, node.getNodeType());
+ EnhancedForStatement forStatement = (EnhancedForStatement) node;
+ final SingleVariableDeclaration parameter = forStatement.getParameter();
+ final Type type = parameter.getType();
+ assertEquals("Wrong extended dimension", 1, parameter.getExtraDimensions());
+ checkSourceRange(type, "byte", source);
+ checkSourceRange(parameter, "@Ann final byte bs[]", source);
+ assertTrue("not a primitive type", type.isPrimitiveType());
+ List modifiers = parameter.modifiers();
+ assertEquals("Wrong size", 2, modifiers.size());
+ final ASTNode modifier1 = ((ASTNode) modifiers.get(0));
+ assertEquals("Not an annotation", ASTNode.MARKER_ANNOTATION, modifier1.getNodeType());
+ final ASTNode modifier2 = ((ASTNode) modifiers.get(1));
+ assertEquals("Not a modifier", ASTNode.MODIFIER, modifier2.getNodeType());
+ checkSourceRange(modifier1, "@Ann", source);
+ checkSourceRange(modifier2, "final", source);
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=80472
+ */
+ public void test0203() throws CoreException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ final String source = "class X<T> {\n" +
+ " X<T> list= this;\n" +
+ " X<? super T> list2= this;\n" +
+ "}";
+ ASTNode node = buildAST(
+ source,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression initializer = fragment.getInitializer();
+ ITypeBinding typeBinding = initializer.resolveTypeBinding();
+ assertTrue("Not a parameterized binding", typeBinding.isParameterizedType());
+
+ node = getASTNode(compilationUnit, 0, 1);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ initializer = fragment.getInitializer();
+ typeBinding = initializer.resolveTypeBinding();
+ assertTrue("Not a parameterized binding", typeBinding.isParameterizedType());
+ }
+
+ /*
+ * Ensures that the key of parameterized type binding with a raw enclosing type is correct
+ * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=83064)
+ */
+ public void test0204() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X<T> {\n" +
+ " static class Y {\n" +
+ " /*start*/Y/*end*/ y;\n" +
+ " }\n" +
+ "}";
+ IBinding[] bindings = resolveBindings(contents, this.workingCopy);
+ assertBindingsEqual(
+ "LX<>.Y;",
+ bindings);
+ }
+
+ /*
+ * Ensures that the declaration method binding and the reference method bindings are the same
+ * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=83064)
+ */
+ public void test0205() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X<E> {\n" +
+ " @I(12)\n" +
+ " @interface I {\n" +
+ " @I(/*start1*/value/*end1*/=13)\n" +
+ " int /*start2*/value/*end2*/();\n" +
+ " }\n" +
+ "}";
+ IBinding[] bindings = resolveBindings(contents, this.workingCopy);
+ assertFalse("Declaration and reference keys should not be the same", bindings[0].getKey().equals(bindings[1].getKey()));
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=120263
+ */
+ public void test0206() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public @interface Annot {\n" +
+ " }\n" +
+ " @Annot(newAttrib= {1, 2})\n" +
+ " public void foo() {\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 1, "The attribute newAttrib is undefined for the annotation type X.Annot");
+ node = getASTNode(compilationUnit, 0, 1);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List modifiers = methodDeclaration.modifiers();
+ assertEquals("Wrong size", 2, modifiers.size());
+ IExtendedModifier extendedModifier = (IExtendedModifier) modifiers.get(0);
+ assertTrue("Not a normal annotation", extendedModifier instanceof NormalAnnotation);
+ NormalAnnotation annotation = (NormalAnnotation) extendedModifier;
+ List values = annotation.values();
+ assertEquals("Wrong size", 1, values.size());
+ MemberValuePair memberValuePair = (MemberValuePair) values.get(0);
+ Expression value = memberValuePair.getValue();
+ assertEquals("Not an array initializer", ASTNode.ARRAY_INITIALIZER, value.getNodeType());
+ ArrayInitializer arrayInitializer = (ArrayInitializer) value;
+ ITypeBinding typeBinding = arrayInitializer.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=124716
+ */
+ public void test0207() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " void m() {\n" +
+ " new Object() {};\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ Expression expression = ((ExpressionStatement) node).getExpression();
+ assertEquals("Not a class instance creation", ASTNode.CLASS_INSTANCE_CREATION, expression.getNodeType());
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ IMethodBinding binding = classInstanceCreation.resolveConstructorBinding();
+ assertNotNull("Should not be null", binding);
+ IAnnotationBinding[] annotations = binding.getAnnotations();
+ assertNotNull("Should not be null", annotations);
+ assertEquals("Should be empty", 0, annotations.length);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=125807
+ */
+ public void test0208() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "/*start*/@Override(x= 1)/*end*/\n" +
+ "public class X { }";
+ NormalAnnotation normalAnnotation = (NormalAnnotation) buildAST(
+ contents,
+ this.workingCopy,
+ false,
+ true,
+ false);
+ IAnnotationBinding annotationBinding = normalAnnotation.resolveAnnotationBinding();
+ IMemberValuePairBinding[] pairs = annotationBinding.getDeclaredMemberValuePairs();
+ assertEquals("Wrong size", 0, pairs.length);
+ List values = normalAnnotation.values();
+ assertEquals("Wrong size", 1, values.size());
+ MemberValuePair pair = (MemberValuePair) values.get(0);
+ assertNotNull("no value", pair.getValue());
+ }
+
+ public void test0209() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test/V.java", true/*resolve*/);
+ String contents =
+ "package test;\n" +
+ "import pack.*;\n" +
+ "public class V {\n" +
+ " void bar() {\n" +
+ " }\n" +
+ " void foo() {\n" +
+ " @A3(\n" +
+ " annot = @A2(\n" +
+ " annot = @A1(value = E.CV, list = new E[] { E.CAV, E.CAV}, clazz = E.class),\n" +
+ " value = E.CV,\n" +
+ " list = new E[] { E.CAV, E.CAV},\n" +
+ " clazz = E.class),\n" +
+ " value = E.CV,\n" +
+ " list = new E[] { E.CAV, E.CAV},\n" +
+ " clazz = E.class)\n" +
+ " int x = 0;\n" +
+ " System.out.println(x);\n" +
+ " System.out.println(x + 1);\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ String problems =
+ "The value for annotation attribute A1.list must be an array initializer\n" +
+ "The value for annotation attribute A2.list must be an array initializer\n" +
+ "The value for annotation attribute A3.list must be an array initializer";
+ assertProblemsSize(compilationUnit, 3, problems);
+ List imports = compilationUnit.imports();
+ assertEquals("wrong size", 1, imports.size());
+ ImportDeclaration importDeclaration = (ImportDeclaration) imports.get(0);
+ Name name = importDeclaration.getName();
+ assertEquals("Not a simple name", ASTNode.SIMPLE_NAME, name.getNodeType());
+ SimpleName simpleName = (SimpleName) name;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong type", IBinding.PACKAGE, binding.getKind());
+ }
+ public void test0210() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", false);
+ String contents =
+ "public class X {\n" +
+ " void foo(Object r) {\n" +
+ " if (r instanceof Future<?>) {\n" +
+ " System.out.println(\"TRUE\");\n" +
+ " } else {\n" +
+ " System.out.println(\"FALSE\");\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertNotNull("No node", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not an if statement", ASTNode.IF_STATEMENT, node.getNodeType());
+ IfStatement ifStatement = (IfStatement) node;
+ Expression expression = ifStatement.getExpression();
+ checkSourceRange(expression, "r instanceof Future<?>", contents);
+ assertEquals("Not an instanceof expression", ASTNode.INSTANCEOF_EXPRESSION, expression.getNodeType());
+ InstanceofExpression instanceofExpression = (InstanceofExpression) expression;
+ Type type = instanceofExpression.getRightOperand();
+ checkSourceRange(type, "Future<?>", contents);
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=129096
+ */
+ public void test0211() throws JavaModelException {
+ String contents =
+ "public class X {\n" +
+ " void foo(java.util.List<?> tab[]) {\n" +
+ " }\n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration declaration = (MethodDeclaration) node;
+ List parameters = declaration.parameters();
+ assertEquals("wrong number", 1, parameters.size());
+ SingleVariableDeclaration variableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ checkSourceRange(variableDeclaration, "java.util.List<?> tab[]", contents);
+ checkSourceRange(variableDeclaration.getType(), "java.util.List<?>", contents);
+ checkSourceRange(variableDeclaration.getName(), "tab", contents);
+ assertEquals("wrong number of extra dimensions", 1, variableDeclaration.getExtraDimensions());
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=129096
+ */
+ public void test0212() throws JavaModelException {
+ String contents =
+ "public class X {\n" +
+ " void foo(java.util.List<?> tab[][]) {\n" +
+ " }\n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration declaration = (MethodDeclaration) node;
+ List parameters = declaration.parameters();
+ assertEquals("wrong number", 1, parameters.size());
+ SingleVariableDeclaration variableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ checkSourceRange(variableDeclaration, "java.util.List<?> tab[][]", contents);
+ checkSourceRange(variableDeclaration.getType(), "java.util.List<?>", contents);
+ checkSourceRange(variableDeclaration.getName(), "tab", contents);
+ assertEquals("wrong number of extra dimensions", 2, variableDeclaration.getExtraDimensions());
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=130528
+ */
+ public void test0213() throws JavaModelException {
+ String contents =
+ "public class X {\n" +
+ " int test(String[] strings) {\n" +
+ " return strings.length;\n" +
+ " }\n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a return statement", ASTNode.RETURN_STATEMENT, node.getNodeType());
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertNotNull("No expression", expression);
+ assertEquals("Not a qualified name", ASTNode.QUALIFIED_NAME, expression.getNodeType());
+ QualifiedName name = (QualifiedName) expression;
+ SimpleName simpleName = name.getName();
+ checkSourceRange(simpleName, "length", contents);
+ IBinding binding = simpleName.resolveBinding();
+ assertEquals("Not a field", IBinding.VARIABLE, binding.getKind());
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("No annotations", 0, variableBinding.getAnnotations().length);
+ }
+
+ /*
+ * Check unique instance of generic method bindings
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=104293
+ */
+ public void test0214() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " \n" +
+ " <T extends A> T foo(T t) {\n" +
+ " return t;\n" +
+ " }\n" +
+ " public static void main(String[] args) {\n" +
+ " new X().bar();\n" +
+ " }\n" +
+ " void bar() {\n" +
+ " B b1 = foo(new B());\n" +
+ " B b2 = foo(new B());\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "class A {}\n" +
+ "class B extends A {}\n";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 2, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment= (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ MethodInvocation invocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding = invocation.resolveMethodBinding();
+
+ node = getASTNode(unit, 0, 2, 1);
+ assertEquals("Not a compilation unit", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ statement = (VariableDeclarationStatement) node;
+ fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment= (VariableDeclarationFragment) fragments.get(0);
+ expression = fragment.getInitializer();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ invocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding2 = invocation.resolveMethodBinding();
+
+ assertTrue("Not identical", methodBinding == methodBinding2);
+ }
+
+ /*
+ * Check unique instance of generic method bindings
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=104293
+ */
+ public void test0215() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " static <T> T identity(T t) { return t; }\n" +
+ "\n" +
+ " public static void main(String[] args) {\n" +
+ " String s = \"aaa\";\n" +
+ " identity(s);\n" +
+ " identity(s);\n" +
+ " identity(s);\n" +
+ "\n" +
+ " Object o = new Object();\n" +
+ " identity(o);\n" +
+ " identity(o);\n" +
+ " identity(o);\n" +
+ "\n" +
+ " Throwable t = null;\n" +
+ " identity(t);\n" +
+ " identity(t);\n" +
+ " identity(t);\n" +
+ "\n" +
+ " Exception e = null;\n" +
+ " identity(e);\n" +
+ " identity(e);\n" +
+ " identity(e);\n" +
+ "\n" +
+ " NullPointerException npe = null;\n" +
+ " identity(npe);\n" +
+ " identity(npe);\n" +
+ " identity(npe);\n" +
+ "\n" +
+ " Cloneable c = null;\n" +
+ " identity(c);\n" +
+ " identity(c);\n" +
+ " identity(c);\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 1, 1);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement statement = (ExpressionStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ MethodInvocation invocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding = invocation.resolveMethodBinding();
+
+ node = getASTNode(unit, 0, 1, 2);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ statement = (ExpressionStatement) node;
+ expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ invocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding2 = invocation.resolveMethodBinding();
+
+ node = getASTNode(unit, 0, 1, 3);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ statement = (ExpressionStatement) node;
+ expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ invocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding3 = invocation.resolveMethodBinding();
+
+ node = getASTNode(unit, 0, 1, 5);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ statement = (ExpressionStatement) node;
+ expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ invocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding4 = invocation.resolveMethodBinding();
+
+ node = getASTNode(unit, 0, 1, 6);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ statement = (ExpressionStatement) node;
+ expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ invocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding5 = invocation.resolveMethodBinding();
+
+ node = getASTNode(unit, 0, 1, 9);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ statement = (ExpressionStatement) node;
+ expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ invocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding6 = invocation.resolveMethodBinding();
+
+ node = getASTNode(unit, 0, 1, 10);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ statement = (ExpressionStatement) node;
+ expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ invocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding7 = invocation.resolveMethodBinding();
+
+ node = getASTNode(unit, 0, 1, 11);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ statement = (ExpressionStatement) node;
+ expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ invocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding8 = invocation.resolveMethodBinding();
+
+ node = getASTNode(unit, 0, 1, 13);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ statement = (ExpressionStatement) node;
+ expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ invocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding9 = invocation.resolveMethodBinding();
+
+ node = getASTNode(unit, 0, 1, 14);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ statement = (ExpressionStatement) node;
+ expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ invocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding10 = invocation.resolveMethodBinding();
+
+ node = getASTNode(unit, 0, 1, 15);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ statement = (ExpressionStatement) node;
+ expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ invocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding11 = invocation.resolveMethodBinding();
+
+ node = getASTNode(unit, 0, 1, 17);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ statement = (ExpressionStatement) node;
+ expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ invocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding12 = invocation.resolveMethodBinding();
+
+ node = getASTNode(unit, 0, 1, 18);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ statement = (ExpressionStatement) node;
+ expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ invocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding13 = invocation.resolveMethodBinding();
+
+ node = getASTNode(unit, 0, 1, 19);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ statement = (ExpressionStatement) node;
+ expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ invocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding14 = invocation.resolveMethodBinding();
+
+ node = getASTNode(unit, 0, 1, 21);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ statement = (ExpressionStatement) node;
+ expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ invocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding15 = invocation.resolveMethodBinding();
+
+ node = getASTNode(unit, 0, 1, 22);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ statement = (ExpressionStatement) node;
+ expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ invocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding16 = invocation.resolveMethodBinding();
+
+ node = getASTNode(unit, 0, 1, 23);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ statement = (ExpressionStatement) node;
+ expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ invocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding17 = invocation.resolveMethodBinding();
+
+ assertTrue("method bindings are not equals", methodBinding == methodBinding2);
+ assertTrue("method bindings are not equals", methodBinding2 == methodBinding3);
+ assertTrue("method bindings are not equals", methodBinding4 == methodBinding5);
+ assertTrue("method bindings are not equals", methodBinding6 == methodBinding7);
+ assertTrue("method bindings are not equals", methodBinding7 == methodBinding8);
+ assertTrue("method bindings are not equals", methodBinding9 == methodBinding10);
+ assertTrue("method bindings are not equals", methodBinding9 == methodBinding11);
+ assertTrue("method bindings are not equals", methodBinding12 == methodBinding13);
+ assertTrue("method bindings are not equals", methodBinding14 == methodBinding13);
+ assertTrue("method bindings are not equals", methodBinding15 == methodBinding16);
+ assertTrue("method bindings are not equals", methodBinding17 == methodBinding16);
+ }
+
+ /*
+ * Check unique instance of generic method bindings
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=104293
+ */
+ public void test0216() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "class Y<T> {\n" +
+ " <T> Class foo(T t) {\n" +
+ " return t.getClass();\n" +
+ " }\n" +
+ "}\n" +
+ "public class X { \n" +
+ " \n" +
+ " public static void main(String[] args) { \n" +
+ " Class c = new Y().foo(null);\n" +
+ " Class c2 = new Y().foo(null);\n" +
+ " } \n" +
+ "}\n" +
+ "";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedOutput =
+ "Class is a raw type. References to generic type Class<T> should be parameterized\n" +
+ "Class is a raw type. References to generic type Class<T> should be parameterized\n" +
+ "Type safety: The method foo(Object) belongs to the raw type Y. References to generic type Y<T> should be parameterized\n" +
+ "Y is a raw type. References to generic type Y<T> should be parameterized\n" +
+ "Class is a raw type. References to generic type Class<T> should be parameterized\n" +
+ "Type safety: The method foo(Object) belongs to the raw type Y. References to generic type Y<T> should be parameterized\n" +
+ "Y is a raw type. References to generic type Y<T> should be parameterized";
+ assertProblemsSize(unit, 7, expectedOutput);
+ node = getASTNode(unit, 1, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment= (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ MethodInvocation invocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding = invocation.resolveMethodBinding();
+ assertTrue("Not a raw method", methodBinding.isRawMethod());
+
+ node = getASTNode(unit, 1, 0, 1);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ statement = (VariableDeclarationStatement) node;
+ fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment= (VariableDeclarationFragment) fragments.get(0);
+ expression = fragment.getInitializer();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ invocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding2 = invocation.resolveMethodBinding();
+ assertTrue("Not a raw method", methodBinding2.isRawMethod());
+
+ assertTrue("Method bindings are not identical", methodBinding == methodBinding2);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=110799
+ */
+ public void test0217() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "class Generic<E> {\n" +
+ "}\n" +
+ "public class X {\n" +
+ " Generic raw;\n" +
+ " java.util.Collection rawCollection;\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedOutput =
+ "Generic is a raw type. References to generic type Generic<E> should be parameterized\n" +
+ "Collection is a raw type. References to generic type Collection<T> should be parameterized";
+ assertProblemsSize(unit, 2, expectedOutput);
+ node = getASTNode(unit, 1, 0);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ Type type = fieldDeclaration.getType();
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertTrue("isRaw", typeBinding.isRawType());
+
+ node = getASTNode(unit, 1, 1);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ fieldDeclaration = (FieldDeclaration) node;
+ type = fieldDeclaration.getType();
+ ITypeBinding typeBinding2 = type.resolveBinding();
+ assertTrue("isRaw", typeBinding2.isRawType());
+
+ ITypeBinding[] typeParameters = typeBinding.getTypeParameters();
+ assertEquals("Wrong size", 0, typeParameters.length);
+
+ ITypeBinding[] typeArguments = typeBinding.getTypeArguments();
+ assertEquals("Wrong size", 0, typeArguments.length);
+
+ typeParameters = typeBinding2.getTypeParameters();
+ assertEquals("Wrong size", 0, typeParameters.length);
+
+ typeArguments = typeBinding2.getTypeArguments();
+ assertEquals("Wrong size", 0, typeArguments.length);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=140318
+ */
+ public void test0218() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "import java.util.List;\n" +
+ "\n" +
+ "public class X {\n" +
+ " /**\n" +
+ " * @category fo\n" +
+ " */\n" +
+ " @Test private int fXoo;\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false,
+ false,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 1, "Test cannot be resolved to a type");
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration declaration = (FieldDeclaration) node;
+ List modifiers = declaration.modifiers();
+ assertEquals("wrong size", 2, modifiers.size());
+ assertEquals("Not a marker annotation", ASTNode.MARKER_ANNOTATION, ((ASTNode) modifiers.get(0)).getNodeType());
+ MarkerAnnotation annotation = (MarkerAnnotation) modifiers.get(0);
+ Name name = annotation.getTypeName();
+ assertEquals("Not a simple name", ASTNode.SIMPLE_NAME, name.getNodeType());
+ ITypeBinding binding = name.resolveTypeBinding();
+ assertNotNull("No binding", binding);
+ IBinding binding2 = name.resolveBinding();
+ assertNotNull("No binding", binding2);
+ IAnnotationBinding annotationBinding = annotation.resolveAnnotationBinding();
+ assertNotNull("No binding", annotationBinding);
+ assertEquals("LX;.fXoo)I@LTest;", annotationBinding.getKey());
+ assertTrue("Annotation should not flagged as recovered", annotationBinding.isRecovered());
+ assertTrue("Annotation type should be flagged as recovered", annotationBinding.getAnnotationType().isRecovered());
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=140318
+ */
+ public void test0219() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "import java.util.List;\n" +
+ "\n" +
+ "public class X {\n" +
+ " /**\n" +
+ " * @category fo\n" +
+ " */\n" +
+ " @Test private int fXoo;\n" +
+ "}\n" +
+ "class Test {}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 1, "Type mismatch: cannot convert from Test to Annotation");
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration declaration = (FieldDeclaration) node;
+ List modifiers = declaration.modifiers();
+ assertEquals("wrong size", 2, modifiers.size());
+ assertEquals("Not a marker annotation", ASTNode.MARKER_ANNOTATION, ((ASTNode) modifiers.get(0)).getNodeType());
+ MarkerAnnotation annotation = (MarkerAnnotation) modifiers.get(0);
+ Name name = annotation.getTypeName();
+ assertEquals("Not a simple name", ASTNode.SIMPLE_NAME, name.getNodeType());
+ ITypeBinding binding = name.resolveTypeBinding();
+ assertNotNull("No binding", binding);
+ IBinding binding2 = name.resolveBinding();
+ assertNotNull("No binding", binding2);
+ IAnnotationBinding annotationBinding = annotation.resolveAnnotationBinding();
+ assertNull("Got a binding", annotationBinding);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=142793
+ * updated for https://bugs.eclipse.org/bugs/show_bug.cgi?id=143001
+ */
+ public void test0220() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " void bar(String[] c) {\n" +
+ " for(String s: c) {\n" +
+ " try {\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 1, "Syntax error, insert \"Finally\" to complete BlockStatements");
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block body = methodDeclaration.getBody();
+ assertNotNull("No body", body);
+ List statements = body.statements();
+ assertEquals("Wrong size", 1, statements.size());
+ assertTrue("Recovered", !isRecovered(body));
+ assertFalse("Malformed", isMalformed(body));
+
+ Statement statement = (Statement)statements.get(0);
+ assertEquals("Not an enhanced for statement", ASTNode.ENHANCED_FOR_STATEMENT, statement.getNodeType());
+ EnhancedForStatement enhancedForStatement = (EnhancedForStatement) statement;
+ Statement forBody = enhancedForStatement.getBody();
+ assertNotNull("No body", forBody);
+ assertEquals("Not a block", ASTNode.BLOCK, forBody.getNodeType());
+
+ statements = ((Block)forBody).statements();
+ assertEquals("Wrong size", 1, statements.size());
+ statement = (Statement)statements.get(0);
+ assertEquals("Not an try statement", ASTNode.TRY_STATEMENT, statement.getNodeType());
+ TryStatement tryStatement = (TryStatement) statement;
+ Block finallyBlock = tryStatement.getFinally();
+ assertNotNull("No finally block", finallyBlock);
+ assertTrue("Not recovered", isRecovered(finallyBlock));
+
+
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=147875
+ */
+ public void test0221() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "import p1.p2.MyEnum;\n" +
+ "public class X {\n" +
+ " MyEnum foo() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=148797
+ */
+ public void test0222() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public void a() {\n" +
+ " Object a = null;\n" +
+ " for (Object o : a.getClass()()) {\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 2, "Syntax error on token \")\", invalid Name\n" +
+ "Syntax error, insert \")\" to complete EnhancedForStatementHeader");
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block body = methodDeclaration.getBody();
+ assertNotNull("No body", body);
+ List statements = body.statements();
+ assertEquals("Wrong size", 2, statements.size());
+ Statement statement = (Statement) statements.get(1);
+ assertEquals("Not an enhanced for statement", ASTNode.ENHANCED_FOR_STATEMENT, statement.getNodeType());
+ EnhancedForStatement forStatement = (EnhancedForStatement) statement;
+ Expression expression = forStatement.getExpression();
+ assertNotNull("No expression", expression);
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=153303
+ */
+ public void test0223() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " @Zork\n" +
+ " public void foo( ) {\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false,
+ false,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 1, "Zork cannot be resolved to a type");
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ IAnnotationBinding[] annotations = methodBinding.getAnnotations();
+ assertEquals("Wrong size", 1, annotations.length);
+ assertNotNull("No binding", annotations[0]);
+ assertEquals("LX;.foo()V@LZork;", annotations[0].getKey());
+ assertTrue("Annotation should be flagged as recovered", annotations[0].isRecovered());
+ assertTrue("Annotation type should be flagged as recovered", annotations[0].getAnnotationType().isRecovered());
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=153303
+ */
+ public void test0224() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "@Zork\n" +
+ "public class X {\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false,
+ false,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 1, "Zork cannot be resolved to a type");
+ node = getASTNode(unit, 0);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ IAnnotationBinding[] annotations = typeBinding.getAnnotations();
+ assertEquals("Wrong size", 1, annotations.length);
+ assertNotNull("No binding", annotations[0]);
+ assertEquals("LX;@LZork;", annotations[0].getKey());
+ assertTrue("Annotation should be flagged as recovered", annotations[0].isRecovered());
+ assertTrue("Annotation type should be flagged as recovered", annotations[0].getAnnotationType().isRecovered());
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=153303
+ */
+ public void test0225() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public void foo(@Zork String s) {\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false,
+ false,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 1, "Zork cannot be resolved to a type");
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ assertEquals("wrong size", 1, parameters.size());
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ IVariableBinding variableBinding = singleVariableDeclaration.resolveBinding();
+ IAnnotationBinding[] bindings = variableBinding.getAnnotations();
+ assertEquals("Wrong size", 1, bindings.length);
+ assertNotNull("No binding", bindings[0]);
+ assertEquals("@LZork;", bindings[0].getKey());
+ assertTrue("Annotation should be flagged as recovered", bindings[0].isRecovered());
+ assertTrue("Annotation type should be flagged as recovered", bindings[0].getAnnotationType().isRecovered());
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=153303
+ */
+ public void test0226() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/p/package-info.java", true/*resolve*/);
+ String contents =
+ "@Zork package p;";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 1, "Zork cannot be resolved to a type");
+ PackageDeclaration packageDeclaration = unit.getPackage();
+ IPackageBinding packageBinding = packageDeclaration.resolveBinding();
+ IAnnotationBinding[] annotations = packageBinding.getAnnotations();
+ assertEquals("Wrong size", 0, annotations.length);
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=155115
+ public void test0227() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "import anno.Anno;\n" +
+ "import binary.B;\n" +
+ "import intf.IFoo;\n" +
+ "\n" +
+ "public class X extends B {\n" +
+ " @Anno(clz=IFoo.IBar.class)\n" +
+ // the annotation we chase up is not this one, but the one
+ // carried by B#f
+ " public void f() {}\n" +
+ " IFoo.IBar m;\n" +
+ "}";
+ class TestASTRequestor extends ASTRequestor {
+ public ArrayList asts = new ArrayList();
+ public void acceptAST(ICompilationUnit source, CompilationUnit compilationUnit) {
+ this.asts.add(compilationUnit);
+ }
+ public void acceptBinding(String bindingKey, IBinding binding) {
+ }
+ }
+ this.workingCopy.getBuffer().setContents(contents);
+ this.workingCopy.save(null, true);
+ TestASTRequestor requestor = new TestASTRequestor();
+ resolveASTs(new ICompilationUnit[] { this.workingCopy } , new String[0], requestor, getJavaProject("Converter15"), null);
+ ArrayList asts = requestor.asts;
+ assertEquals("Wrong size", 1, asts.size());
+ CompilationUnit compilationUnit = (CompilationUnit) asts.get(0);
+ assertNotNull("No compilation unit", compilationUnit);
+ List types = compilationUnit.types();
+ assertEquals("Wrong size", 1, types.size());
+ AbstractTypeDeclaration abstractTypeDeclaration = (AbstractTypeDeclaration) types.get(0);
+ assertEquals("Wrong type", ASTNode.TYPE_DECLARATION, abstractTypeDeclaration.getNodeType());
+ TypeDeclaration declaration = (TypeDeclaration) abstractTypeDeclaration;
+ Type superclass = declaration.getSuperclassType();
+ assertNotNull("No superclass", superclass);
+ ITypeBinding typeBinding = superclass.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ IMethodBinding[] methods = typeBinding.getDeclaredMethods();
+ assertNotNull("No methods", methods);
+ assertEquals("Wrong size", 2, methods.length);
+ IMethodBinding methodBinding = null;
+ for(int i = 0; i < 2; i++) {
+ methodBinding = methods[i];
+ if (methodBinding.getName().equals("f")) {
+ break;
+ }
+ }
+ assertEquals("Wrong name", "f", methodBinding.getName());
+ IAnnotationBinding[] annotationBindings = methodBinding.getAnnotations();
+ assertNotNull("No annotations", annotationBindings);
+ assertEquals("Wrong size", 1, annotationBindings.length);
+ IAnnotationBinding annotationBinding = annotationBindings[0];
+ IMemberValuePairBinding[] pairs = annotationBinding.getAllMemberValuePairs();
+ assertNotNull("no pairs", pairs);
+ assertEquals("Wrong size", 1, pairs.length);
+ IMemberValuePairBinding memberValuePairBinding = pairs[0];
+ assertEquals("Wrong kind", IBinding.MEMBER_VALUE_PAIR, memberValuePairBinding.getKind());
+ Object value = memberValuePairBinding.getValue();
+ assertNotNull("No value", value);
+ assertTrue("Not a type binding", value instanceof ITypeBinding);
+ assertEquals("Wrong qualified name", "intf.IFoo.IBar",
+ ((ITypeBinding) value).getQualifiedName());
+ IVariableBinding[] fields =
+ declaration.resolveBinding().getDeclaredFields();
+ assertTrue("Bad field definition", fields != null && fields.length == 1);
+ assertEquals("Type binding mismatch", value, fields[0].getType());
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=157403
+ */
+ public void test0228() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "@interface Ann {\n" +
+ " int foo();\n" +
+ "}\n" +
+ "@Ann(foo = bar())\n" +
+ "public class X {\n" +
+ " public static int bar() {\n" +
+ " return 0;\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 1, "The method bar() is undefined for the type X");
+ List types = unit.types();
+ assertEquals("wrong size", 2, types.size());
+ AbstractTypeDeclaration typeDeclaration = (AbstractTypeDeclaration) types.get(1);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, typeDeclaration.getNodeType());
+ TypeDeclaration declaration = (TypeDeclaration) typeDeclaration;
+ List modifiers = declaration.modifiers();
+ assertEquals("wrong size", 2, modifiers.size());
+ IExtendedModifier modifier = (IExtendedModifier) modifiers.get(0);
+ assertTrue("not an annotation", modifier.isAnnotation());
+ Annotation annotation = (Annotation) modifier;
+ assertEquals("Not a normal annotation", ASTNode.NORMAL_ANNOTATION, annotation.getNodeType());
+ NormalAnnotation normalAnnotation = (NormalAnnotation) annotation;
+ List values = normalAnnotation.values();
+ assertEquals("wrong size", 1, values.size());
+ MemberValuePair pair = (MemberValuePair) values.get(0);
+ IBinding binding = pair.getName().resolveBinding();
+ assertNotNull("No binding", binding);
+ binding = pair.getValue().resolveTypeBinding();
+ assertNull("Got a binding", binding);
+ binding = pair.resolveMemberValuePairBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=160089
+ */
+ public void test0229() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "import java.util.List;\n" +
+ "import java.util.Collection;\n" +
+ "public class X {\n" +
+ " public static List<String> bar;\n" +
+ " @SuppressWarnings(\"rawtypes\")\n" +
+ " public static Collection bar2;\n" +
+ "}";
+ this.workingCopy.getBuffer().setContents(contents);
+ this.workingCopy.save(null, true);
+ final ASTNode[] asts = new ASTNode[1];
+ final IBinding[] bindings = new IBinding[1];
+ final String key = BindingKey.createParameterizedTypeBindingKey(
+ "Ljava/util/Collection<TE;>;", new String[] {});
+ resolveASTs(
+ new ICompilationUnit[] {
+ this.workingCopy
+ },
+ new String[] {
+ key
+ },
+ new ASTRequestor() {
+ public void acceptAST(ICompilationUnit source, CompilationUnit localAst) {
+ asts[0] = localAst;
+ }
+ public void acceptBinding(String bindingKey, IBinding binding) {
+ if (key.equals(bindingKey)) {
+ bindings[0] = binding;
+ }
+ }
+ },
+ getJavaProject("Converter15"),
+ null);
+ ASTNode node = asts[0];
+ assertNotNull("Should not be null", node);
+ assertNotNull("Should not be null", bindings[0]);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a compilation unit", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ Type type = fieldDeclaration.getType();
+ ITypeBinding typeBinding = type.resolveBinding();
+ node = getASTNode(unit, 0, 1);
+ assertEquals("Not a compilation unit", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ fieldDeclaration = (FieldDeclaration) node;
+ type = fieldDeclaration.getType();
+ ITypeBinding typeBinding2 = type.resolveBinding();
+ final ITypeBinding collectionTypeBinding = (ITypeBinding) bindings[0];
+ assertTrue("Not a raw type", collectionTypeBinding.isRawType());
+ assertTrue("Not assignement compatible", typeBinding.isAssignmentCompatible(typeBinding2));
+ assertTrue("Not assignement compatible", typeBinding.isAssignmentCompatible(collectionTypeBinding));
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=156352
+ */
+ public void test0230() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0230", "Test3.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType type = sourceUnit.getType("Test3");//$NON-NLS-1$
+
+ assertNotNull("Should not be null", type);
+ ASTParser parser= ASTParser.newParser(AST.JLS3);
+ parser.setProject(type.getJavaProject());
+ IBinding[] bindings= parser.createBindings(new IJavaElement[] { type }, null);
+ if (bindings.length == 1 && bindings[0] instanceof ITypeBinding) {
+ ITypeBinding typeBinding= (ITypeBinding) bindings[0];
+ StringBuffer buffer = new StringBuffer();
+ while (typeBinding != null) {
+ buffer.append(typeBinding.getAnnotations().length);
+ typeBinding= typeBinding.getSuperclass();
+ }
+ assertEquals("Wrong number of annotations", "000", String.valueOf(buffer));
+ }
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=156352
+ */
+ public void test0231() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0231", "Test3.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType type = sourceUnit.getType("Test3");//$NON-NLS-1$
+
+ assertNotNull("Should not be null", type);
+ ASTParser parser= ASTParser.newParser(AST.JLS3);
+ parser.setSource(sourceUnit);
+ parser.setKind(ASTParser.K_COMPILATION_UNIT);
+ parser.setResolveBindings(true);
+ CompilationUnit unit = (CompilationUnit) parser.createAST(null);
+ List types = unit.types();
+ TypeDeclaration typeDeclaration = (TypeDeclaration) types.get(0);
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ StringBuffer buffer = new StringBuffer();
+ while (typeBinding != null) {
+ buffer.append(typeBinding.getAnnotations().length);
+ typeBinding= typeBinding.getSuperclass();
+ }
+ assertEquals("Wrong number of annotations", "020", String.valueOf(buffer));
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=167958
+ */
+ public void test0232() throws JavaModelException {
+ /*
+ package test0232;
+ import static java.lang.annotation.ElementType.*;
+ import static java.lang.annotation.RetentionPolicy.*;
+ import java.lang.annotation.Retention;
+ import java.lang.annotation.Target;
+
+ @Target(TYPE)
+ @Retention(RUNTIME)
+ @interface Annot {
+ }
+ package test0232;
+ @Annot
+ public class X {
+ }
+ */
+ String contents =
+ "import test0232.X;\n" +
+ "public class A {\n" +
+ " X test() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/A.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration declaration = (MethodDeclaration) node;
+ Type type = declaration.getReturnType2();
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertTrue("Not a binary type binding", !typeBinding.isFromSource());
+ IAnnotationBinding[] annotations = typeBinding.getAnnotations();
+ assertNotNull("No annotations", annotations);
+ assertEquals("Wrong size", 1, annotations.length);
+ IAnnotationBinding annotationBinding = annotations[0];
+ assertEquals("Wrong name", "Annot", annotationBinding.getName());
+ ITypeBinding binding = annotationBinding.getAnnotationType();
+ assertEquals("Wrong name", "test0232.Annot", binding.getQualifiedName());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=167958
+ */
+ public void test0233() throws JavaModelException {
+ /*
+ package test0233;
+
+ import static java.lang.annotation.ElementType.*;
+ import static java.lang.annotation.RetentionPolicy.*;
+
+ import java.lang.annotation.Retention;
+ import java.lang.annotation.Target;
+
+ @Target(TYPE)
+ @Retention(CLASS)
+ @interface Annot {
+ String message() default "";
+ }
+
+ package test0233;
+
+ @Annot(message="Hello, World!")
+ public class X {
+ }
+ */
+ String contents =
+ "import test0233.X;\n" +
+ "public class A {\n" +
+ " X test() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/A.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration declaration = (MethodDeclaration) node;
+ Type type = declaration.getReturnType2();
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertTrue("Not a binary type binding", !typeBinding.isFromSource());
+ IAnnotationBinding[] annotations = typeBinding.getAnnotations();
+ assertNotNull("No annotations", annotations);
+ assertEquals("Wrong size", 1, annotations.length);
+ IAnnotationBinding annotationBinding = annotations[0];
+ assertEquals("Wrong name", "Annot", annotationBinding.getName());
+ ITypeBinding binding = annotationBinding.getAnnotationType();
+ assertEquals("Wrong name", "test0233.Annot", binding.getQualifiedName());
+ IMemberValuePairBinding[] pairs = annotationBinding.getAllMemberValuePairs();
+ assertEquals("Wrong number", 1, pairs.length);
+ assertEquals("Wrong key", "message", pairs[0].getName());
+ assertEquals("Wrong value", "Hello, World!", pairs[0].getValue());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=169744
+ */
+ public void test0234() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "class B {\n" +
+ " <T> int m() {\n" +
+ " return 0;\n" +
+ " }\n" +
+ "}\n" +
+ "public class X<T> extends B {\n" +
+ " int i = super.<T> m();\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 1, 0);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ checkSourceRange(expression, "super.<T> m()", contents);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=172633
+ */
+ public void test0235() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0235/X.java", true/*resolve*/);
+ String contents =
+ "package test0235;\n" +
+ "public class X implements I {\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false,
+ false,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedProblems = "The hierarchy of the type X is inconsistent\n" +
+ "The type test0235.Zork cannot be resolved. It is indirectly referenced from required .class files";
+ assertProblemsSize(unit, 2, expectedProblems);
+ node = getASTNode(unit, 0);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ ITypeBinding[] interfaces = typeBinding.getInterfaces();
+ assertNotNull("No interfaces", interfaces);
+ assertEquals("Wrong size", 1, interfaces.length);
+ assertNotNull("Should not be null", interfaces[0]);
+ ITypeBinding typeBinding2 = interfaces[0];
+ interfaces = typeBinding2.getInterfaces();
+ assertNotNull("No interfaces", interfaces);
+ assertEquals("Wrong size", 1, interfaces.length);
+ assertNotNull("No binding", interfaces[0]);
+ assertEquals("Ltest0235/Zork;", interfaces[0].getKey());
+ assertFalse("I should not be flagged as recovered", typeBinding2.isRecovered());
+ assertTrue("Zork should be flagged as recovered", interfaces[0].isRecovered());
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=172633
+ */
+ public void test0236() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X implements Runnable, Zork {\n" +
+ " public void run() {}\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false,
+ false,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedProblems = "Zork cannot be resolved to a type";
+ assertProblemsSize(unit, 1, expectedProblems);
+ node = getASTNode(unit, 0);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ ITypeBinding[] interfaces = typeBinding.getInterfaces();
+ assertNotNull("No interfaces", interfaces);
+ assertEquals("Wrong size", 2, interfaces.length);
+ assertEquals("Ljava/lang/Runnable;", interfaces[0].getKey());
+ assertFalse("Runnable should not be flagged as recovered", interfaces[0].isRecovered());
+ assertEquals("LZork;", interfaces[1].getKey());
+ assertTrue("Zork should be flagged as recovered", interfaces[1].isRecovered());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=173338
+ */
+ public void test0237() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0237/X.java", true/*resolve*/);
+ String contents =
+ "package test0237;\n" +
+ "public class X {\n" +
+ " Zork foo() {}\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false,
+ false,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedProblems = "Zork cannot be resolved to a type";
+ assertProblemsSize(unit, 1, expectedProblems);
+ node = getASTNode(unit, 0);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ IMethodBinding[] methodBindings = typeBinding.getDeclaredMethods();
+ assertNotNull("No method bindings", methodBindings);
+ assertEquals("wrong size", 2, methodBindings.length);
+ assertEquals("Ltest0237/X;.()V", methodBindings[0].getKey());
+ assertEquals("Ltest0237/X;.foo()LZork;", methodBindings[1].getKey());
+ assertFalse("#foo() should not be flagged as recovered", methodBindings[1].isRecovered());
+ assertTrue("Zork should be flagged as recovered", methodBindings[1].getReturnType().isRecovered());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=173338
+ */
+ public void test0238() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0238/X.java", true/*resolve*/);
+ String contents =
+ "package test0238;\n" +
+ "public class X extends A {\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ typeBinding = typeBinding.getSuperclass();
+ IMethodBinding[] methodBindings = typeBinding.getDeclaredMethods();
+ assertNotNull("No method bindings", methodBindings);
+ assertEquals("wrong size", 1, methodBindings.length);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=173338
+ */
+ public void test0238_2() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0238/X.java", true/*resolve*/);
+ String contents =
+ "package test0238;\n" +
+ "public class X extends A {\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false,
+ false,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ typeBinding = typeBinding.getSuperclass();
+ IMethodBinding[] methodBindings = typeBinding.getDeclaredMethods();
+ assertNotNull("No method bindings", methodBindings);
+ assertEquals("wrong size", 2, methodBindings.length);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=173338
+ */
+ public void test0239() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0239/X.java", true/*resolve*/);
+ String contents =
+ "package test0239;\n" +
+ "public class X extends A {\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ typeBinding = typeBinding.getSuperclass();
+ IVariableBinding[] variableBindings = typeBinding.getDeclaredFields();
+ assertNotNull("No variable bindings", variableBindings);
+ assertEquals("wrong size", 0, variableBindings.length);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=173338
+ */
+ public void test0239_2() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0239/X.java", true/*resolve*/);
+ String contents =
+ "package test0239;\n" +
+ "public class X extends A {\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false,
+ true,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ typeBinding = typeBinding.getSuperclass();
+ IVariableBinding[] variableBindings = typeBinding.getDeclaredFields();
+ assertNotNull("No variable bindings", variableBindings);
+ assertEquals("wrong size", 1, variableBindings.length);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=107001
+ */
+ public void test0240() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X<T> {}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ ITypeBinding[] typeParameters = typeBinding.getTypeParameters();
+ assertEquals("Wrong size", 1, typeParameters.length);
+ ITypeBinding typeParameter = typeParameters[0];
+ assertTrue("Not a type variable", typeParameter.isTypeVariable());
+ assertEquals("Wrong binary name", "X$T", typeParameter.getBinaryName());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=107001
+ */
+ public void test0241() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " <T> void foo() {}\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ assertNotNull("No binding", methodBinding);
+ ITypeBinding[] typeParameters = methodBinding.getTypeParameters();
+ assertEquals("Wrong size", 1, typeParameters.length);
+ ITypeBinding typeParameter = typeParameters[0];
+ assertTrue("Not a type variable", typeParameter.isTypeVariable());
+ assertEquals("Wrong binary name", "X$()V$T", typeParameter.getBinaryName());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=107001
+ */
+ public void test0242() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " <T> X() {}\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ assertNotNull("No binding", methodBinding);
+ ITypeBinding[] typeParameters = methodBinding.getTypeParameters();
+ assertEquals("Wrong size", 1, typeParameters.length);
+ ITypeBinding typeParameter = typeParameters[0];
+ assertTrue("Not a type variable", typeParameter.isTypeVariable());
+ assertEquals("Wrong binary name", "X$()V$T", typeParameter.getBinaryName());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=107001
+ */
+ public void test0243() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/p/X.java", true/*resolve*/);
+ String contents =
+ "package p;\n" +
+ "public class X<U,V> {\n" +
+ " <T> X(Integer i) {}\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ assertNotNull("No binding", methodBinding);
+ ITypeBinding[] typeParameters = methodBinding.getTypeParameters();
+ assertEquals("Wrong size", 1, typeParameters.length);
+ ITypeBinding typeParameter = typeParameters[0];
+ assertTrue("Not a type variable", typeParameter.isTypeVariable());
+ assertEquals("Wrong binary name", "p.X$(Ljava/lang/Integer;)V$T", typeParameter.getBinaryName());
+ }
+
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=173849
+ public void test0244() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/xy/X.java", true/*resolve*/);
+ String contents =
+ "package xy;\n" +
+ "\n" +
+ "public class X {\n" +
+ " protected class Inner {\n" +
+ " }\n" +
+ "\n" +
+ " Inner[] i;\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 1);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ Type type = fieldDeclaration.getType();
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ IJavaElement element = typeBinding.getJavaElement();
+ assertNotNull("No element", element);
+ assertTrue("Doesn't exist", element.exists());
+ assertEquals("Wrong handle identifier", "=Converter15/src<xy{X.java[X[Inner", element.getHandleIdentifier());
+ }
+
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=173849
+ public void test0245() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/xy/X.java", true/*resolve*/);
+ String contents =
+ "package xy;\n" +
+ "\n" +
+ "public class X {\n" +
+ " protected class Inner {\n" +
+ " }\n" +
+ "\n" +
+ " Inner i;\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 1);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ Type type = fieldDeclaration.getType();
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ IJavaElement element = typeBinding.getJavaElement();
+ assertNotNull("No element", element);
+ assertTrue("Doesn't exist", element.exists());
+ assertEquals("Wrong handle identifier", "=Converter15/src<xy{X.java[X[Inner", element.getHandleIdentifier());
+ }
+
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=173849
+ public void test0246() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/xy/X.java", true/*resolve*/);
+ String contents =
+ "package xy;\n" +
+ "\n" +
+ "public class X {\n" +
+ " protected class Inner {\n" +
+ " }\n" +
+ "\n" +
+ " Inner[][] i;\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 1);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ Type type = fieldDeclaration.getType();
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ IJavaElement element = typeBinding.getJavaElement();
+ assertNotNull("No element", element);
+ assertTrue("Doesn't exist", element.exists());
+ assertEquals("Wrong handle identifier", "=Converter15/src<xy{X.java[X[Inner", element.getHandleIdentifier());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=156352
+ */
+ public void test0247() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0247", "EclipseCompiler.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true, true);
+ assertNotNull("Not a compilation unit", result);
+ }
+
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=175409
+ public void test0248() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "import java.util.Arrays;\n" +
+ "import java.util.List;\n" +
+ "public class X {\n" +
+ " public <T> void find(T a, List<T> b) {\n" +
+ " }\n" +
+ " public void foo() {\n" +
+ " find(x, Arrays.asList(\"a\"));\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedError = "x cannot be resolved to a variable";
+ assertProblemsSize(unit, 1, expectedError);
+ node = getASTNode(unit, 0, 1, 0);
+ assertEquals("Not a expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement statement = (ExpressionStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ MethodInvocation invocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding = invocation.resolveMethodBinding();
+ assertNotNull("No binding", methodBinding);
+ assertTrue("Not a parameterized method", methodBinding.isParameterizedMethod());
+ }
+
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=174436
+ public void test0249() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "import java.util.Collections;\n" +
+ "import java.util.Map;\n" +
+ "\n" +
+ "public class X {\n" +
+ " void caller() {\n" +
+ " Map<String, String> explicitEmptyMap = Collections.<String, String> emptyMap();\n" +
+ " method(explicitEmptyMap);\n" +
+ " Map<String, String> emptyMap = Collections.emptyMap();\n" +
+ " method(emptyMap);\n" +
+ " }\n" +
+ "\n" +
+ " void method(Map<String, String> map) {\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement= (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ assertFalse("Wrong value", methodInvocation.isResolvedTypeInferredFromExpectedType());
+
+ node = getASTNode(unit, 0, 0, 2);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ statement= (VariableDeclarationStatement) node;
+ fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ expression = fragment.getInitializer();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ methodInvocation = (MethodInvocation) expression;
+ assertTrue("Wrong value", methodInvocation.isResolvedTypeInferredFromExpectedType());
+ }
+
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=174436
+ public void test0250() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "import java.util.Map;\n" +
+ "\n" +
+ "class A {\n" +
+ " public <K,V> Map<K,V> foo() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n" +
+ "public class X extends A {\n" +
+ " void caller() {\n" +
+ " Map<String, String> explicitEmptyMap = super.<String, String> foo();\n" +
+ " method(explicitEmptyMap);\n" +
+ " Map<String, String> emptyMap = super.foo();\n" +
+ " method(emptyMap);\n" +
+ " }\n" +
+ "\n" +
+ " void method(Map<String, String> map) {\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 1, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement= (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not a super method invocation", ASTNode.SUPER_METHOD_INVOCATION, expression.getNodeType());
+ SuperMethodInvocation methodInvocation = (SuperMethodInvocation) expression;
+ assertFalse("Wrong value", methodInvocation.isResolvedTypeInferredFromExpectedType());
+
+ node = getASTNode(unit, 1, 0, 2);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ statement= (VariableDeclarationStatement) node;
+ fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ expression = fragment.getInitializer();
+ assertEquals("Not a super method invocation", ASTNode.SUPER_METHOD_INVOCATION, expression.getNodeType());
+ methodInvocation = (SuperMethodInvocation) expression;
+ assertTrue("Wrong value", methodInvocation.isResolvedTypeInferredFromExpectedType());
+ }
+
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=174436
+ public void test0251() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0251", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode node = runConversion(AST.JLS3, sourceUnit, false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement= (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ assertFalse("Wrong value", methodInvocation.isResolvedTypeInferredFromExpectedType());
+
+ node = getASTNode(unit, 0, 0, 2);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ statement= (VariableDeclarationStatement) node;
+ fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ expression = fragment.getInitializer();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ methodInvocation = (MethodInvocation) expression;
+ assertFalse("Wrong value", methodInvocation.isResolvedTypeInferredFromExpectedType());
+ }
+
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=174436
+ public void test0252() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter15" , "src", "test0252", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode node = runConversion(AST.JLS3, sourceUnit, false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 1, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement= (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not a super method invocation", ASTNode.SUPER_METHOD_INVOCATION, expression.getNodeType());
+ SuperMethodInvocation methodInvocation = (SuperMethodInvocation) expression;
+ assertFalse("Wrong value", methodInvocation.isResolvedTypeInferredFromExpectedType());
+
+ node = getASTNode(unit, 1, 0, 2);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ statement= (VariableDeclarationStatement) node;
+ fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ expression = fragment.getInitializer();
+ assertEquals("Not a super method invocation", ASTNode.SUPER_METHOD_INVOCATION, expression.getNodeType());
+ methodInvocation = (SuperMethodInvocation) expression;
+ assertFalse("Wrong value", methodInvocation.isResolvedTypeInferredFromExpectedType());
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=149567
+ */
+ public void test0253() throws JavaModelException {
+ String contents =
+ "public class X {\n" +
+ " protected Object foo() {\n" +
+ " List<String> c = null;\n" +
+ " return c;\n" +
+ " }\n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ this.workingCopy.getBuffer().setContents(contents);
+ ASTNode node = runConversion(AST.JLS3, this.workingCopy, true, true, true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedError = "List cannot be resolved to a type";
+ assertProblemsSize(unit, 1, expectedError);
+ assertTrue("No binding recovery", unit.getAST().hasBindingsRecovery());
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("No fragments", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertFalse("A recovered binding", variableBinding.isRecovered());
+ ITypeBinding typeBinding = variableBinding.getType();
+ assertNotNull("No binding", typeBinding);
+ assertTrue("Not a recovered binding", typeBinding.isRecovered());
+ assertEquals("Wrong name", "List<String>", typeBinding.getName());
+ assertEquals("Wrong dimension", 0, typeBinding.getDimensions());
+ assertEquals("LList<Ljava/lang/String;>;", typeBinding.getKey());
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=149567
+ */
+ public void test0254() throws JavaModelException {
+ String contents =
+ "import java.util.List;\n" +
+ "\n" +
+ "public class X {\n" +
+ " protected Object foo() {\n" +
+ " List<String> c = null;\n" +
+ " return c;\n" +
+ " }\n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ this.workingCopy.getBuffer().setContents(contents);
+ ASTNode node = runConversion(AST.JLS3, this.workingCopy, true, true, true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ assertTrue("No binding recovery", unit.getAST().hasBindingsRecovery());
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("No fragments", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertFalse("A recovered binding", variableBinding.isRecovered());
+ ITypeBinding typeBinding = variableBinding.getType();
+ assertNotNull("No binding", typeBinding);
+ assertFalse("A recovered binding", typeBinding.isRecovered());
+ assertEquals("Wrong name", "List<String>", typeBinding.getName());
+ assertEquals("Wrong dimension", 0, typeBinding.getDimensions());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=130001
+ */
+ public void test0255() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ ICompilationUnit.FORCE_PROBLEM_DETECTION | ICompilationUnit.ENABLE_BINDINGS_RECOVERY | ICompilationUnit.ENABLE_STATEMENTS_RECOVERY);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertTrue("No statement recovery", unit.getAST().hasStatementsRecovery());
+ assertTrue("No binding recovery", unit.getAST().hasBindingsRecovery());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=130001
+ */
+ public void test0256() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ ICompilationUnit.ENABLE_STATEMENTS_RECOVERY);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertTrue("No statement recovery", unit.getAST().hasStatementsRecovery());
+ assertFalse("Has binding recovery", unit.getAST().hasBindingsRecovery());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=130001
+ */
+ public void test0257() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ 0);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertFalse("Has statement recovery", unit.getAST().hasStatementsRecovery());
+ assertFalse("Has binding recovery", unit.getAST().hasBindingsRecovery());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=179042
+ */
+ public void test0258() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "@interface Annot {\n" +
+ " public int id() default 0;\n" +
+ "}\n" +
+ "@Annot(id=4)\n" +
+ "public class X {\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ 0);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 1);
+ assertEquals("Not a type declaration unit", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ List modifiers = typeDeclaration.modifiers();
+ assertEquals("wrong size", 2, modifiers.size());
+ IExtendedModifier modifier = (IExtendedModifier) modifiers.get(0);
+ assertTrue("Not an annotation", modifier.isAnnotation());
+ Annotation annotation = (Annotation) modifier;
+ assertEquals("Not a normal annotation", ASTNode.NORMAL_ANNOTATION, annotation.getNodeType());
+ NormalAnnotation normalAnnotation = (NormalAnnotation) annotation;
+ IAnnotationBinding annotationBinding = normalAnnotation.resolveAnnotationBinding();
+ assertEquals("Wrong size", 0, annotationBinding.getAnnotations().length);
+ IJavaElement javaElement = annotationBinding.getJavaElement();
+ assertNotNull("No java element", javaElement);
+ assertEquals("Wrong kind", IBinding.ANNOTATION, annotationBinding.getKind());
+ assertEquals("Unexpected key", "LX;@LX~Annot;", annotationBinding.getKey());
+ assertEquals("Wrong modifier", Modifier.NONE, annotationBinding.getModifiers());
+ assertFalse("A deprecated annotation", annotationBinding.isDeprecated());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=179042
+ */
+ public void test0259() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "@Deprecated\n" +
+ "@interface Annot {\n" +
+ " public int id() default 0;\n" +
+ "}\n" +
+ "@Annot(id=4)\n" +
+ "public class X {\n" +
+ "}\n" +
+ "@Annot(id=4) class Y {\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ 0);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 1);
+ assertEquals("Not a type declaration unit", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ List modifiers = typeDeclaration.modifiers();
+ assertEquals("wrong size", 2, modifiers.size());
+ IExtendedModifier modifier = (IExtendedModifier) modifiers.get(0);
+ assertTrue("Not an annotation", modifier.isAnnotation());
+ Annotation annotation = (Annotation) modifier;
+ assertEquals("Not a normal annotation", ASTNode.NORMAL_ANNOTATION, annotation.getNodeType());
+ NormalAnnotation normalAnnotation = (NormalAnnotation) annotation;
+ IAnnotationBinding annotationBinding = normalAnnotation.resolveAnnotationBinding();
+ assertEquals("Wrong size", 0, annotationBinding.getAnnotations().length);
+ IJavaElement javaElement = annotationBinding.getJavaElement();
+ assertNotNull("No java element", javaElement);
+ assertEquals("Wrong kind", IBinding.ANNOTATION, annotationBinding.getKind());
+ assertEquals("Unexpected key", "LX;@LX~Annot;", annotationBinding.getKey());
+ assertEquals("Wrong modifier", Modifier.NONE, annotationBinding.getModifiers());
+ assertTrue("Not a deprecated annotation", annotationBinding.isDeprecated());
+ IMemberValuePairBinding[] allMemberValuePairs = annotationBinding.getAllMemberValuePairs();
+ assertEquals("Wrong size", 1, allMemberValuePairs.length);
+ assertFalse("Not a recovered binding", annotationBinding.isRecovered());
+ assertFalse("Not a synthetic binding", annotationBinding.isSynthetic());
+
+ node = getASTNode(unit, 2);
+ assertEquals("Not a type declaration unit", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ typeDeclaration = (TypeDeclaration) node;
+ modifiers = typeDeclaration.modifiers();
+ assertEquals("wrong size", 1, modifiers.size());
+ modifier = (IExtendedModifier) modifiers.get(0);
+ assertTrue("Not an annotation", modifier.isAnnotation());
+ annotation = (Annotation) modifier;
+ assertEquals("Not a normal annotation", ASTNode.NORMAL_ANNOTATION, annotation.getNodeType());
+ normalAnnotation = (NormalAnnotation) annotation;
+ IAnnotationBinding annotationBinding2 = normalAnnotation.resolveAnnotationBinding();
+
+ assertTrue("Should be equal", annotationBinding2.isEqualTo(annotationBinding));
+ assertTrue("Should be equal", annotationBinding.isEqualTo(annotationBinding2));
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=179042
+ */
+ public void test0260() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "@interface Annot {\n" +
+ " public int id() default 0;\n" +
+ " public String name() default \"\";\n" +
+ "}\n" +
+ "@Annot(id=4)\n" +
+ "public class X {\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ 0);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 1);
+ assertEquals("Not a type declaration unit", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ List modifiers = typeDeclaration.modifiers();
+ assertEquals("wrong size", 2, modifiers.size());
+ IExtendedModifier modifier = (IExtendedModifier) modifiers.get(0);
+ assertTrue("Not an annotation", modifier.isAnnotation());
+ Annotation annotation = (Annotation) modifier;
+ assertEquals("Not a normal annotation", ASTNode.NORMAL_ANNOTATION, annotation.getNodeType());
+ NormalAnnotation normalAnnotation = (NormalAnnotation) annotation;
+ IAnnotationBinding annotationBinding = normalAnnotation.resolveAnnotationBinding();
+ assertEquals("Wrong size", 0, annotationBinding.getAnnotations().length);
+ IJavaElement javaElement = annotationBinding.getJavaElement();
+ assertNotNull("No java element", javaElement);
+ assertEquals("Wrong kind", IBinding.ANNOTATION, annotationBinding.getKind());
+ assertEquals("Unexpected key", "LX;@LX~Annot;", annotationBinding.getKey());
+ assertEquals("Wrong modifier", Modifier.NONE, annotationBinding.getModifiers());
+ assertFalse("Not a deprecated annotation", annotationBinding.isDeprecated());
+ IMemberValuePairBinding[] declaredMemberValuePairs = annotationBinding.getDeclaredMemberValuePairs();
+ assertEquals("Wrong size", 1, declaredMemberValuePairs.length);
+ IMemberValuePairBinding[] allMemberValuePairs = annotationBinding.getAllMemberValuePairs();
+ assertEquals("Wrong size", 2, allMemberValuePairs.length);
+ assertFalse("Not a recovered binding", annotationBinding.isRecovered());
+ assertFalse("Not a synthetic binding", annotationBinding.isSynthetic());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=179065
+ */
+ public void test0261() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "@interface Annot {\n" +
+ " public boolean booleanValue() default true;\n" +
+ "\n" +
+ " public byte byteValue() default 0;\n" +
+ "\n" +
+ " public char charValue() default \' \';\n" +
+ "\n" +
+ " public double doubleValue() default 0.0;\n" +
+ "\n" +
+ " public float floatValue() default 0.0f;\n" +
+ "\n" +
+ " public int intValue() default 1;\n" +
+ "\n" +
+ " public long longValue() default Long.MAX_VALUE;\n" +
+ "\n" +
+ " public short shortValue() default 127;\n" +
+ "\n" +
+ " public String stringValue() default \"\";\n" +
+ "\n" +
+ " public E enumValue() default E.A;\n" +
+ "\n" +
+ " public Class classValue() default String.class;\n" +
+ "\n" +
+ " @Deprecated public Ann annotationValue() default @Ann();\n" +
+ "\n" +
+ " public boolean[] booleanArrayValue() default { true, false };\n" +
+ "\n" +
+ " public byte[] byteArrayValue() default { 0, 1 };\n" +
+ "\n" +
+ " public char[] charArrayValue() default { \'#\' };\n" +
+ "\n" +
+ " @Deprecated public double[] doubleArrayValue() default { 2.0 };\n" +
+ "\n" +
+ " public float[] floatArrayValue() default { 1.0f };\n" +
+ "\n" +
+ " public int[] intArrayValue() default { 0, 1 };\n" +
+ "\n" +
+ " public long[] longArrayValue() default { Long.MIN_VALUE };\n" +
+ "\n" +
+ " public short[] shortArrayValue() default { 127 };\n" +
+ "\n" +
+ " public String[] stringArrayValue() default { \"Hello\", \"World\" };\n" +
+ "\n" +
+ " public E[] enumArrayValue() default { E.A, E.B };\n" +
+ "\n" +
+ " public Class[] classArrayValue() default { Object.class, Annot.class };\n" +
+ "\n" +
+ " public Ann[] annotationArrayValue() default {};\n" +
+ "}\n" +
+ "\n" +
+ "enum E {\n" +
+ " A, B, C, D\n" +
+ "}\n" +
+ "\n" +
+ "@interface Ann {}\n" +
+ "\n" +
+ "@Annot(\n" +
+ " booleanValue = true,\n" +
+ " byteValue = (byte) 1,\n" +
+ " charValue = \' \',\n" +
+ " doubleValue = 4.0,\n" +
+ " floatValue = 3.0f,\n" +
+ " intValue = 1,\n" +
+ " longValue = 65535L,\n" +
+ " shortValue = (short) 128,\n" +
+ " stringValue = \"SUCCESS\",\n" +
+ " enumValue = E.B,\n" +
+ " classValue = Object.class,\n" +
+ " annotationValue = @Ann())\n" +
+ "public class X {\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ 0);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedProblems =
+ "Class is a raw type. References to generic type Class<T> should be parameterized\n" +
+ "Class is a raw type. References to generic type Class<T> should be parameterized";
+ assertProblemsSize(unit, 2, expectedProblems);
+ node = getASTNode(unit, 3);
+ assertEquals("Not a type declaration unit", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ List modifiers = typeDeclaration.modifiers();
+ assertEquals("wrong size", 2, modifiers.size());
+ IExtendedModifier modifier = (IExtendedModifier) modifiers.get(0);
+ assertTrue("Not an annotation", modifier.isAnnotation());
+ Annotation annotation = (Annotation) modifier;
+ assertEquals("Not a normal annotation", ASTNode.NORMAL_ANNOTATION, annotation.getNodeType());
+ NormalAnnotation normalAnnotation = (NormalAnnotation) annotation;
+ IAnnotationBinding annotationBinding = normalAnnotation.resolveAnnotationBinding();
+ assertEquals("Wrong size", 0, annotationBinding.getAnnotations().length);
+ IJavaElement javaElement = annotationBinding.getJavaElement();
+ assertNotNull("No java element", javaElement);
+ assertEquals("Wrong kind", IBinding.ANNOTATION, annotationBinding.getKind());
+ assertEquals("Unexpected key", "LX;@LX~Annot;", annotationBinding.getKey());
+ assertEquals("Wrong modifier", Modifier.NONE, annotationBinding.getModifiers());
+ assertFalse("Not a deprecated annotation", annotationBinding.isDeprecated());
+ IMemberValuePairBinding[] declaredMemberValuePairs = annotationBinding.getDeclaredMemberValuePairs();
+ assertEquals("Wrong size", 12, declaredMemberValuePairs.length);
+
+ IMemberValuePairBinding pairBinding = declaredMemberValuePairs[0];
+ assertEquals("Wrong name", "booleanValue", pairBinding.getName());
+ Object value = pairBinding.getValue();
+ assertTrue("Not a Boolean", value instanceof Boolean);
+ assertEquals("Wrong value", Boolean.TRUE, value);
+ assertTrue("Not the default value", pairBinding.isDefault());
+ IMethodBinding methodBinding = pairBinding.getMethodBinding();
+ assertNotNull("No method binding", methodBinding);
+ assertEquals("Wrong name", "booleanValue", methodBinding.getName());
+ Object defaultValue = methodBinding.getDefaultValue();
+ assertTrue("Different values", value.equals(defaultValue));
+ assertFalse("Is deprecated", pairBinding.isDeprecated());
+
+ pairBinding = declaredMemberValuePairs[1];
+ assertEquals("Wrong name", "byteValue", pairBinding.getName());
+ value = pairBinding.getValue();
+ assertTrue("Not a Byte", value instanceof Byte);
+ assertEquals("Wrong value", new Byte((byte) 1), value);
+ assertFalse("The default value", pairBinding.isDefault());
+ methodBinding = pairBinding.getMethodBinding();
+ assertNotNull("No method binding", methodBinding);
+ assertEquals("Wrong name", "byteValue", methodBinding.getName());
+ defaultValue = methodBinding.getDefaultValue();
+ assertFalse("Same values", value.equals(defaultValue));
+ assertFalse("Is deprecated", pairBinding.isDeprecated());
+
+ pairBinding = declaredMemberValuePairs[2];
+ assertEquals("Wrong name", "charValue", pairBinding.getName());
+ value = pairBinding.getValue();
+ assertTrue("Not a Character", value instanceof Character);
+ assertEquals("Wrong value", new Character(' '), value);
+ assertTrue("Not the default value", pairBinding.isDefault());
+ methodBinding = pairBinding.getMethodBinding();
+ assertNotNull("No method binding", methodBinding);
+ assertEquals("Wrong name", "charValue", methodBinding.getName());
+ defaultValue = methodBinding.getDefaultValue();
+ assertTrue("Different values", value.equals(defaultValue));
+ assertFalse("Is deprecated", pairBinding.isDeprecated());
+
+ pairBinding = declaredMemberValuePairs[3];
+ assertEquals("Wrong name", "doubleValue", pairBinding.getName());
+ value = pairBinding.getValue();
+ assertTrue("Not a Double", value instanceof Double);
+ assertEquals("Wrong value", new Double(4.0), value);
+ assertFalse("The default value", pairBinding.isDefault());
+ methodBinding = pairBinding.getMethodBinding();
+ assertNotNull("No method binding", methodBinding);
+ assertEquals("Wrong name", "doubleValue", methodBinding.getName());
+ defaultValue = methodBinding.getDefaultValue();
+ assertFalse("Same values", value.equals(defaultValue));
+ assertFalse("Is deprecated", pairBinding.isDeprecated());
+
+ pairBinding = declaredMemberValuePairs[4];
+ assertEquals("Wrong name", "floatValue", pairBinding.getName());
+ value = pairBinding.getValue();
+ assertTrue("Not a Float", value instanceof Float);
+ assertEquals("Wrong value", new Float(3.0f), value);
+ assertFalse("The default value", pairBinding.isDefault());
+ methodBinding = pairBinding.getMethodBinding();
+ assertNotNull("No method binding", methodBinding);
+ assertEquals("Wrong name", "floatValue", methodBinding.getName());
+ defaultValue = methodBinding.getDefaultValue();
+ assertFalse("Same values", value.equals(defaultValue));
+ assertFalse("Is deprecated", pairBinding.isDeprecated());
+
+ pairBinding = declaredMemberValuePairs[5];
+ assertEquals("Wrong name", "intValue", pairBinding.getName());
+ value = pairBinding.getValue();
+ assertTrue("Not an Integer", value instanceof Integer);
+ assertEquals("Wrong value", new Integer(1), value);
+ assertTrue("Not the default value", pairBinding.isDefault());
+ methodBinding = pairBinding.getMethodBinding();
+ assertNotNull("No method binding", methodBinding);
+ assertEquals("Wrong name", "intValue", methodBinding.getName());
+ defaultValue = methodBinding.getDefaultValue();
+ assertTrue("Different values", value.equals(defaultValue));
+ assertFalse("Is deprecated", pairBinding.isDeprecated());
+
+ pairBinding = declaredMemberValuePairs[6];
+ assertEquals("Wrong name", "longValue", pairBinding.getName());
+ value = pairBinding.getValue();
+ assertTrue("Not a Long", value instanceof Long);
+ assertEquals("Wrong value", new Long(65535L), value);
+ assertFalse("The default value", pairBinding.isDefault());
+ methodBinding = pairBinding.getMethodBinding();
+ assertNotNull("No method binding", methodBinding);
+ assertEquals("Wrong name", "longValue", methodBinding.getName());
+ defaultValue = methodBinding.getDefaultValue();
+ assertFalse("Same values", value.equals(defaultValue));
+ assertFalse("Is deprecated", pairBinding.isDeprecated());
+
+ pairBinding = declaredMemberValuePairs[7];
+ assertEquals("Wrong name", "shortValue", pairBinding.getName());
+ value = pairBinding.getValue();
+ assertTrue("Not a Short", value instanceof Short);
+ assertEquals("Wrong value", new Short((short) 128), value);
+ assertFalse("The default value", pairBinding.isDefault());
+ methodBinding = pairBinding.getMethodBinding();
+ assertNotNull("No method binding", methodBinding);
+ assertEquals("Wrong name", "shortValue", methodBinding.getName());
+ defaultValue = methodBinding.getDefaultValue();
+ assertFalse("Same values", value.equals(defaultValue));
+ assertFalse("Is deprecated", pairBinding.isDeprecated());
+
+ pairBinding = declaredMemberValuePairs[8];
+ assertEquals("Wrong name", "stringValue", pairBinding.getName());
+ value = pairBinding.getValue();
+ assertTrue("Not a String", value instanceof String);
+ assertEquals("Wrong value", "SUCCESS", value);
+ assertFalse("The default value", pairBinding.isDefault());
+ methodBinding = pairBinding.getMethodBinding();
+ assertNotNull("No method binding", methodBinding);
+ assertEquals("Wrong name", "stringValue", methodBinding.getName());
+ defaultValue = methodBinding.getDefaultValue();
+ assertFalse("Same values", value.equals(defaultValue));
+ assertFalse("Is deprecated", pairBinding.isDeprecated());
+
+ pairBinding = declaredMemberValuePairs[9];
+ assertEquals("Wrong name", "enumValue", pairBinding.getName());
+ value = pairBinding.getValue();
+ assertTrue("Not an IVariableBinding", value instanceof IVariableBinding);
+ IVariableBinding variableBinding = (IVariableBinding) value;
+ assertEquals("Wrong value", "B", variableBinding.getName());
+ assertFalse("The default value", pairBinding.isDefault());
+ methodBinding = pairBinding.getMethodBinding();
+ assertNotNull("No method binding", methodBinding);
+ assertEquals("Wrong name", "enumValue", methodBinding.getName());
+ defaultValue = methodBinding.getDefaultValue();
+ assertFalse("Same values", value.equals(defaultValue));
+ assertFalse("Is deprecated", pairBinding.isDeprecated());
+
+ pairBinding = declaredMemberValuePairs[10];
+ assertEquals("Wrong name", "classValue", pairBinding.getName());
+ value = pairBinding.getValue();
+ assertTrue("Not an ITypeBinding", value instanceof ITypeBinding);
+ ITypeBinding typeBinding = (ITypeBinding) value;
+ assertEquals("Wrong value", "java.lang.Object", typeBinding.getQualifiedName());
+ assertFalse("The default value", pairBinding.isDefault());
+ methodBinding = pairBinding.getMethodBinding();
+ assertNotNull("No method binding", methodBinding);
+ assertEquals("Wrong name", "classValue", methodBinding.getName());
+ defaultValue = methodBinding.getDefaultValue();
+ assertFalse("Same values", value.equals(defaultValue));
+ assertFalse("Is deprecated", pairBinding.isDeprecated());
+
+ pairBinding = declaredMemberValuePairs[11];
+ assertEquals("Wrong name", "annotationValue", pairBinding.getName());
+ value = pairBinding.getValue();
+ assertTrue("Not an IAnnotationBinding", value instanceof IAnnotationBinding);
+ IAnnotationBinding annotationBinding2 = (IAnnotationBinding) value;
+ assertEquals("Wrong value", "Ann", annotationBinding2.getName());
+ assertTrue("The default value", pairBinding.isDefault());
+ methodBinding = pairBinding.getMethodBinding();
+ assertNotNull("No method binding", methodBinding);
+ assertEquals("Wrong name", "annotationValue", methodBinding.getName());
+ defaultValue = methodBinding.getDefaultValue();
+ assertTrue("not a IBinding", defaultValue instanceof IBinding);
+ assertTrue("Same values", annotationBinding2.isEqualTo((IBinding) defaultValue));
+ assertTrue("Not deprecated", pairBinding.isDeprecated());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=166963
+ */
+ public void test0262() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public X(String s) {\n" +
+ " }\n" +
+ " public X() {\n" +
+ " String s = \"\";\n" +
+ " System.out.println();\n" +
+ " this(zork);\n" +
+ " Zork.this.this();\n" +
+ " <Zork>this(s);\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ 0);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedErrors = "Constructor call must be the first statement in a constructor\n" +
+ "zork cannot be resolved to a variable\n" +
+ "Constructor call must be the first statement in a constructor\n" +
+ "Zork cannot be resolved to a type\n" +
+ "Zork cannot be resolved to a type\n" +
+ "Constructor call must be the first statement in a constructor";
+ assertProblemsSize(unit, 6, expectedErrors);
+ node = getASTNode(unit, 0, 1, 4);
+ assertEquals("Not a constructor invocation", ASTNode.CONSTRUCTOR_INVOCATION, node.getNodeType());
+ ConstructorInvocation constructorInvocation = (ConstructorInvocation) node;
+ assertNull("Got a binding", constructorInvocation.resolveConstructorBinding());
+ List arguments = constructorInvocation.arguments();
+ assertEquals("wrong size", 1, arguments.size());
+ Expression expression = (Expression) arguments.get(0);
+ ITypeBinding typeBinding = expression.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding);
+ assertEquals("Wrong type", "java.lang.String", typeBinding.getQualifiedName());
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=183468
+ */
+ public void test0263() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "@interface Annot {\n" +
+ " int[] array();\n" +
+ "}\n" +
+ "@Annot(array=1)\n" +
+ "public class X {\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 1);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ List modifiers = typeDeclaration.modifiers();
+ assertEquals("Wrong size", 2, modifiers.size());
+ IExtendedModifier modifier = (IExtendedModifier) modifiers.get(0);
+ assertTrue("Not an annotation", modifier.isAnnotation());
+ Annotation annotation = (Annotation) modifier;
+ assertTrue("Not a normal annotation", annotation.isNormalAnnotation());
+ NormalAnnotation normalAnnotation = (NormalAnnotation) annotation;
+ List values = normalAnnotation.values();
+ assertEquals("Wrong size", 1, values.size());
+ MemberValuePair pair = (MemberValuePair) values.get(0);
+ IMemberValuePairBinding memberValuePairBinding = pair.resolveMemberValuePairBinding();
+ assertFalse("Is default value", memberValuePairBinding.isDefault());
+ }
+
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=175409
+ public void test0264() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "import java.util.*;\n" +
+ "\n" +
+ "public class X {\n" +
+ " private <T> T find(T a, List<T> b) {\n" +
+ " return null;\n" +
+ " }\n" +
+ " public void foo1() {\n" +
+ " // T x;\n" +
+ " find(x, Arrays.asList(\"a\")); // closestMatch: #find(String,List<String>)\n" +
+ " find(x, 0); // closestMatch: #find(Object,List<Object>)\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedErrors =
+ "x cannot be resolved to a variable\n" +
+ "x cannot be resolved to a variable";
+ assertProblemsSize(unit, 2, expectedErrors);
+ node = getASTNode(unit, 0, 1, 0);
+ assertEquals("Not a expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement statement = (ExpressionStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ MethodInvocation invocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding = invocation.resolveMethodBinding();
+ assertNotNull("No binding", methodBinding);
+ assertTrue("Not a parameterized method", methodBinding.isParameterizedMethod());
+ node = getASTNode(unit, 0, 1, 1);
+ assertEquals("Not a expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ statement = (ExpressionStatement) node;
+ expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ invocation = (MethodInvocation) expression;
+ methodBinding = invocation.resolveMethodBinding();
+ assertNotNull("No binding", methodBinding);
+ assertFalse("Not a parameterized method", methodBinding.isParameterizedMethod());
+ assertTrue("Not a raw method", methodBinding.isRawMethod());
+ }
+
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=175409
+ public void test0265() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "import java.util.*;\n" +
+ "\n" +
+ "public class X {\n" +
+ " <T> X(T a, List<T> b) {\n" +
+ " }\n" +
+ "\n" +
+ " public void foo1() {\n" +
+ " // T x;\n" +
+ " new X(x, Arrays.asList(\"a\")); // closestMatch:#X(String,List<String>)\n" +
+ " new X(x, 0); // closestMatch: #X(Object,List<Object>)\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedErrors =
+ "x cannot be resolved to a variable\n" +
+ "x cannot be resolved to a variable";
+ assertProblemsSize(unit, 2, expectedErrors);
+ node = getASTNode(unit, 0, 1, 0);
+ assertEquals("Not a expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement statement = (ExpressionStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("Not a class instance creation", ASTNode.CLASS_INSTANCE_CREATION, expression.getNodeType());
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ IMethodBinding methodBinding = classInstanceCreation.resolveConstructorBinding();
+ assertNotNull("No binding", methodBinding);
+ assertTrue("Not a parameterized method", methodBinding.isParameterizedMethod());
+ node = getASTNode(unit, 0, 1, 1);
+ assertEquals("Not a expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ statement = (ExpressionStatement) node;
+ expression = statement.getExpression();
+ assertEquals("Not a class instance creation", ASTNode.CLASS_INSTANCE_CREATION, expression.getNodeType());
+ classInstanceCreation = (ClassInstanceCreation) expression;
+ methodBinding = classInstanceCreation.resolveConstructorBinding();
+ assertNotNull("No binding", methodBinding);
+ assertFalse("Not a parameterized method", methodBinding.isParameterizedMethod());
+ assertTrue("Not a raw method", methodBinding.isRawMethod());
+ }
+
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=175409
+ public void test0266() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "import java.util.*;\n" +
+ "\n" +
+ "public class X {\n" +
+ " class M {\n" +
+ " <T> M(T a, List<T> b) {\n" +
+ " }\n" +
+ " }\n" +
+ " public void foo1() {\n" +
+ " // T x;\n" +
+ " this.new M(x, Arrays.asList(\"a\")); // closestMatch: #X(String,List<String>)\n" +
+ " this.new M(x, 0); // closestMatch: #X(Object,List<Object>)\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedErrors =
+ "x cannot be resolved to a variable\n" +
+ "x cannot be resolved to a variable";
+ assertProblemsSize(unit, 2, expectedErrors);
+ node = getASTNode(unit, 0, 1, 0);
+ assertEquals("Not a expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement statement = (ExpressionStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("Not a class instance creation", ASTNode.CLASS_INSTANCE_CREATION, expression.getNodeType());
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ IMethodBinding methodBinding = classInstanceCreation.resolveConstructorBinding();
+ assertNotNull("No binding", methodBinding);
+ assertTrue("Not a parameterized method", methodBinding.isParameterizedMethod());
+ node = getASTNode(unit, 0, 1, 1);
+ assertEquals("Not a expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ statement = (ExpressionStatement) node;
+ expression = statement.getExpression();
+ assertEquals("Not a class instance creation", ASTNode.CLASS_INSTANCE_CREATION, expression.getNodeType());
+ classInstanceCreation = (ClassInstanceCreation) expression;
+ methodBinding = classInstanceCreation.resolveConstructorBinding();
+ assertNotNull("No binding", methodBinding);
+ assertFalse("Not a parameterized method", methodBinding.isParameterizedMethod());
+ assertTrue("Not a raw method", methodBinding.isRawMethod());
+ }
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=175409
+ public void test0267() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "import java.util.*;\n" +
+ "\n" +
+ "public class X {\n" +
+ " class M {\n" +
+ " <T> M(T a, List<T> b) {\n" +
+ " }\n" +
+ " }\n" +
+ " public void foo1() {\n" +
+ " // T x;\n" +
+ " this.new M(x, Arrays.asList(\"a\")) {\n" +
+ " }; // closestMatch:#X(String,List<String>)\n" +
+ " this.new M(x, 0) {\n" +
+ " }; // closestMatch: #X(Object,List<Object>)\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedErrors =
+ "x cannot be resolved to a variable\n" +
+ "x cannot be resolved to a variable";
+ assertProblemsSize(unit, 2, expectedErrors);
+ node = getASTNode(unit, 0, 1, 0);
+ assertEquals("Not a expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement statement = (ExpressionStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("Not a class instance creation", ASTNode.CLASS_INSTANCE_CREATION, expression.getNodeType());
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ IMethodBinding methodBinding = classInstanceCreation.resolveConstructorBinding();
+ assertNotNull("No binding", methodBinding);
+ assertTrue("Not a parameterized method", methodBinding.isParameterizedMethod());
+ node = getASTNode(unit, 0, 1, 1);
+ assertEquals("Not a expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ statement = (ExpressionStatement) node;
+ expression = statement.getExpression();
+ assertEquals("Not a class instance creation", ASTNode.CLASS_INSTANCE_CREATION, expression.getNodeType());
+ classInstanceCreation = (ClassInstanceCreation) expression;
+ methodBinding = classInstanceCreation.resolveConstructorBinding();
+ assertNotNull("No binding", methodBinding);
+ assertFalse("Not a parameterized method", methodBinding.isParameterizedMethod());
+ assertTrue("Not a raw method", methodBinding.isRawMethod());
+ }
+
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=175409
+ public void test0268() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "import java.util.*;\n" +
+ "\n" +
+ "class Super {\n" +
+ " <T> Super(T a, List<T> b) {\n" +
+ " }\n" +
+ "}\n" +
+ "public class X extends Super {\n" +
+ " public X() {\n" +
+ " // T x;\n" +
+ " super(x, Arrays.asList(\"a\")); // closestMatch:#X(String,List<String>)\n" +
+ " }\n" +
+ " public X(boolean b) {\n" +
+ " // T x;\n" +
+ " super(x, 0); // closestMatch: #X(Object,List<Object>)\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedErrors =
+ "x cannot be resolved to a variable\n" +
+ "x cannot be resolved to a variable";
+ assertProblemsSize(unit, 2, expectedErrors);
+ node = getASTNode(unit, 1, 0, 0);
+ assertEquals("Not a super constructor invocation", ASTNode.SUPER_CONSTRUCTOR_INVOCATION, node.getNodeType());
+ SuperConstructorInvocation invocation = (SuperConstructorInvocation) node;
+ IMethodBinding methodBinding = invocation.resolveConstructorBinding();
+ assertNotNull("No binding", methodBinding);
+ assertTrue("Not a parameterized method", methodBinding.isParameterizedMethod());
+ node = getASTNode(unit, 1, 1, 0);
+ assertEquals("Not a expression statement", ASTNode.SUPER_CONSTRUCTOR_INVOCATION, node.getNodeType());
+ invocation = (SuperConstructorInvocation) node;
+ methodBinding = invocation.resolveConstructorBinding();
+ assertNotNull("No binding", methodBinding);
+ assertFalse("Not a parameterized method", methodBinding.isParameterizedMethod());
+ assertTrue("Not a raw method", methodBinding.isRawMethod());
+ }
+
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=175409
+ public void test0269() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "import java.util.*;\n" +
+ "\n" +
+ "public class X {\n" +
+ " <T extends Comparable<T>> void find(T a, String[] b, List<T> c) {\n" +
+ " }\n" +
+ " void foo(String[] s) {\n" +
+ " find(x, Arrays.asList(\"a\"), s);\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedError = "x cannot be resolved to a variable";
+ assertProblemsSize(unit, 1, expectedError);
+ node = getASTNode(unit, 0, 1, 0);
+ assertEquals("Not a expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement statement = (ExpressionStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ MethodInvocation invocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding = invocation.resolveMethodBinding();
+ assertNotNull("No binding", methodBinding);
+ assertFalse("Not a parameterized method", methodBinding.isParameterizedMethod());
+ assertTrue("Not a parameterized method", methodBinding.isRawMethod());
+ }
+
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=180966
+ public void _test0270() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/foo/X.java", true/*resolve*/);
+ String contents =
+ "package foo;\n" +
+ "\n" +
+ "class GenericBase<T> {\n" +
+ " public void someMethod() {}\n" +
+ "}\n" +
+ "public class X extends GenericBase<String> {\n" +
+ " @Override\n" +
+ " public void someMethod() {}\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration declaration = (MethodDeclaration) node;
+ IMethodBinding methodBinding = declaration.resolveBinding();
+ node = getASTNode(unit, 1, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ declaration = (MethodDeclaration) node;
+ IMethodBinding methodBinding2 = declaration.resolveBinding();
+ assertTrue("Doesn't override", methodBinding2.overrides(methodBinding));
+ }
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=180966
+ public void _test0271() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/foo/X.java", true/*resolve*/);
+ String contents =
+ "package foo;\n" +
+ "\n" +
+ "class GenericBase<T> {\n" +
+ " public void someMethod() {}\n" +
+ "}\n" +
+ "public class X extends GenericBase<String> {\n" +
+ " @Override\n" +
+ " public void someMethod() {}\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 1, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration declaration = (MethodDeclaration) node;
+ IMethodBinding methodBinding = declaration.resolveBinding();
+ node = getASTNode(unit, 1, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ declaration = (MethodDeclaration) node;
+ IMethodBinding methodBinding2 = declaration.resolveBinding();
+ IMethodBinding[] declaredMethods = methodBinding.getDeclaringClass().getSuperclass().getDeclaredMethods();
+ IMethodBinding methodBinding3 = null;
+ loop: for (int i = 0, max = declaredMethods.length; i < max; i++) {
+ if (declaredMethods[i].getName().equals(methodBinding.getName())) {
+ methodBinding3 = declaredMethods[i];
+ break loop;
+ }
+ }
+ assertNotNull("Super method not found", methodBinding3);
+ assertTrue("Should be the same", methodBinding3.isEqualTo(methodBinding2));
+ assertTrue("Doesn't override", methodBinding.overrides(methodBinding3));
+ }
+
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=186189
+ public void test0272() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "import java.util.List;\n" +
+ "\n" +
+ "public class X {\n" +
+ " <T> T foo(T t) {\n" +
+ " return null;\n" +
+ " }\n" +
+ " Object bar() {\n" +
+ " return new Object() {\n" +
+ " void bar(List<?> l) {\n" +
+ " foo(l.get(0));\n" +
+ " }\n" +
+ " };\n" +
+ " }\n" +
+ " \n" +
+ " public static void main(String args[]) {\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 1, 0);
+ assertEquals("Not a return statement", ASTNode.RETURN_STATEMENT, node.getNodeType());
+ ReturnStatement statement = (ReturnStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("Not a class instance creation", ASTNode.CLASS_INSTANCE_CREATION, expression.getNodeType());
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ List bodyDeclarations = anonymousClassDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, bodyDeclaration.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ Block body = methodDeclaration.getBody();
+ assertNotNull("No block", body);
+ List statements = body.statements();
+ assertEquals("Wrong size", 1, statements.size());
+ Statement statement2 = (Statement) statements.get(0);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, statement2.getNodeType());
+ Expression expression2 = ((ExpressionStatement) statement2).getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression2.getNodeType());
+ ITypeBinding typeBinding = ((MethodInvocation) expression2).resolveTypeBinding();
+ assertTrue("Not a capture", typeBinding.isCapture());
+ assertNull("No binary type", typeBinding.getBinaryName());
+ }
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=185129
+ public void test0273() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "import test0273.B;\n" +
+ "import test0273.A;\n" +
+ "public class X {\n" +
+ " Object foo() {\n" +
+ " return new B(new A());\n" +
+ " }\n" +
+ " void bar(String s) {\n" +
+ " System.out.println(s);\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 1, "The type A is not generic; it cannot be parameterized with arguments <?>");
+ }
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=191908
+ public void test0274() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " @Deprecated\n" +
+ " public static int x= 5, y= 10;\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 2, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding binding = fragment.resolveBinding();
+ assertTrue("Not deprecated", binding.isDeprecated());
+ fragment = (VariableDeclarationFragment) fragments.get(1);
+ binding = fragment.resolveBinding();
+ assertTrue("Not deprecated", binding.isDeprecated());
+ }
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=191908
+ public void test0275() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public void foo() {\n" +
+ " @Deprecated\n" +
+ " int x= 5, y= 10;\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 2, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding binding = fragment.resolveBinding();
+ IAnnotationBinding[] annotations = binding.getAnnotations();
+ assertEquals("Wrong size", 1, annotations.length);
+ fragment = (VariableDeclarationFragment) fragments.get(1);
+ binding = fragment.resolveBinding();
+ annotations = binding.getAnnotations();
+ assertEquals("Wrong size", 1, annotations.length);
+ }
+
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=192774
+ //Test ability to distinguish AST nodes of multiple similar annotations.
+ public void test0276() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "@interface Annot {\n" +
+ " public int value();\n" +
+ "}\n" +
+ "\n" +
+ "public class X {\n" +
+ " @Annot(1) String foo1() { return null; }\n" +
+ " @Annot(1) String foo2() { return null; }\n" +
+ "}";
+ this.workingCopy.getBuffer().setContents(contents);
+
+ class CompilationUnitRequestor extends ASTRequestor {
+ public void acceptAST(ICompilationUnit source, CompilationUnit node) {
+ MethodDeclaration methodDeclaration = (MethodDeclaration)getASTNode(node, 1, 0);
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ IAnnotationBinding annoBinding = methodBinding.getAnnotations()[0];
+ ASTNode annoNode = node.findDeclaringNode(annoBinding);
+ int position1 = annoNode.getStartPosition();
+
+ methodDeclaration = (MethodDeclaration)getASTNode(node, 1, 1);
+ methodBinding = methodDeclaration.resolveBinding();
+ IAnnotationBinding annoBinding2 = methodBinding.getAnnotations()[0];
+ annoNode = node.findDeclaringNode(annoBinding2);
+ int position2 = annoNode.getStartPosition();
+ assertTrue("Anno 2 position <= anno 1 position", position2 > position1);
+ }
+ }
+
+ CompilationUnitRequestor requestor = new CompilationUnitRequestor();
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setResolveBindings(true);
+ parser.setProject(getJavaProject("Converter15"));
+ parser.setKind(ASTParser.K_COMPILATION_UNIT);
+ parser.createASTs(new ICompilationUnit[]{this.workingCopy}, new String[0], requestor, null);
+ }
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=191908
+ public void test0277() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public static void method() {\n" +
+ " }\n" +
+ "}\n" +
+ "class Y extends X {\n" +
+ " public static void method() {\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ IMethodBinding methodBinding1 = methodDeclaration.resolveBinding();
+
+ node = getASTNode(unit, 1, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ methodDeclaration = (MethodDeclaration) node;
+ IMethodBinding methodBinding2 = methodDeclaration.resolveBinding();
+
+ assertFalse("Overrides", methodBinding2.overrides(methodBinding1));
+ }
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=191908
+ public void test0278() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public void method() {\n" +
+ " }\n" +
+ "}\n" +
+ "class Y extends X {\n" +
+ " public static void method() {\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 1, "This static method cannot hide the instance method from X");
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ IMethodBinding methodBinding1 = methodDeclaration.resolveBinding();
+
+ node = getASTNode(unit, 1, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ methodDeclaration = (MethodDeclaration) node;
+ IMethodBinding methodBinding2 = methodDeclaration.resolveBinding();
+
+ assertFalse("Overrides", methodBinding2.overrides(methodBinding1));
+ }
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=191908
+ public void test0279() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public static void method() {\n" +
+ " }\n" +
+ "}\n" +
+ "class Y extends X {\n" +
+ " public void method() {\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 1, "This instance method cannot override the static method from X");
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ IMethodBinding methodBinding1 = methodDeclaration.resolveBinding();
+
+ node = getASTNode(unit, 1, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ methodDeclaration = (MethodDeclaration) node;
+ IMethodBinding methodBinding2 = methodDeclaration.resolveBinding();
+
+ assertFalse("Overrides", methodBinding2.overrides(methodBinding1));
+ }
+
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=191908
+ public void test0280() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public void method() {\n" +
+ " }\n" +
+ "}\n" +
+ "class Y extends X {\n" +
+ " @Override\n" +
+ " public void method() {\n" +
+ " }\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ IMethodBinding methodBinding1 = methodDeclaration.resolveBinding();
+
+ node = getASTNode(unit, 1, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ methodDeclaration = (MethodDeclaration) node;
+ IMethodBinding methodBinding2 = methodDeclaration.resolveBinding();
+
+ assertTrue("Doesn't overrides", methodBinding2.overrides(methodBinding1));
+ }
+
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=198085
+ public void test0281() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "@Invalid\n" +
+ "@Deprecated\n" +
+ "public class X {}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false,
+ false,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 1, "Invalid cannot be resolved to a type");
+ node = getASTNode(unit, 0);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ IAnnotationBinding[] annotations = typeBinding.getAnnotations();
+ assertEquals("wrong size", 2, annotations.length);
+ assertEquals("LX;@LInvalid;", annotations[0].getKey());
+ assertTrue("Annotation should be flagged as recovered", annotations[0].isRecovered());
+ assertTrue("Annotation type should be flagged as recovered", annotations[0].getAnnotationType().isRecovered());
+ assertEquals("LX;@Ljava/lang/Deprecated;", annotations[1].getKey());
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=190622
+ public void test0282() throws JavaModelException {
+ String contents =
+ "public class X {\n" +
+ " public @interface Moo {\n" +
+ " Class<?> value();\n" +
+ " }\n" +
+ " @Moo(Bar.Baz.class)\n" +
+ " public static class Bar {\n" +
+ " public static class Baz {\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ this.workingCopy.getBuffer().setContents(contents);
+ ASTNode node = runConversion(AST.JLS3, this.workingCopy, true, true, true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 1);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ final List modifiers = typeDeclaration.modifiers();
+ assertEquals("Wrong size", 3, modifiers.size());
+ IExtendedModifier extendedModifier = (IExtendedModifier) modifiers.get(0);
+ assertTrue("Not an annotation", extendedModifier instanceof SingleMemberAnnotation);
+ SingleMemberAnnotation annotation = (SingleMemberAnnotation) extendedModifier;
+ final Expression value = annotation.getValue();
+ assertEquals("Not a type literal", ASTNode.TYPE_LITERAL, value.getNodeType());
+ TypeLiteral typeLiteral = (TypeLiteral) value;
+ final Type type = typeLiteral.getType();
+ assertEquals("Not a simple type", ASTNode.SIMPLE_TYPE, type.getNodeType());
+ SimpleType simpleType = (SimpleType) type;
+ final Name name = simpleType.getName();
+ assertEquals("Not a qualified name", ASTNode.QUALIFIED_NAME, name.getNodeType());
+ QualifiedName qualifiedName = (QualifiedName) name;
+ final IBinding binding = qualifiedName.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong value", "Bar.Baz", qualifiedName.getFullyQualifiedName());
+ final SimpleName simpleName = qualifiedName.getName();
+ final IBinding binding2 = simpleName.resolveBinding();
+ assertNotNull("No binding2", binding2);
+ assertFalse("Not a recovered binding", binding2.isRecovered());
+ final Name qualifier = qualifiedName.getQualifier();
+ assertEquals("Not a simple name", ASTNode.SIMPLE_NAME, qualifier.getNodeType());
+ SimpleName simpleName2 = (SimpleName) qualifier;
+ final IBinding binding3 = simpleName2.resolveBinding();
+ assertNotNull("No binding3", binding3);
+ assertFalse("Not a recovered binding", binding3.isRecovered());
+ final IJavaElement javaElement = binding3.getJavaElement();
+ assertNotNull("No java element", javaElement);
+ assertEquals("Not a type", IJavaElement.TYPE, javaElement.getElementType());
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=201104
+ public void test0283() throws JavaModelException {
+ String contents =
+ "public class X {\n" +
+ " public @interface Moo {\n" +
+ " Class<?> value();\n" +
+ " }\n" +
+ " @Moo(Bar2.Baz.class)\n" +
+ " public static class Bar {\n" +
+ " public static class Baz {\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ this.workingCopy.getBuffer().setContents(contents);
+ ASTNode node = runConversion(AST.JLS3, this.workingCopy, true, true, true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 1, "Bar2 cannot be resolved to a type");
+ node = getASTNode(unit, 0, 1);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ final List modifiers = typeDeclaration.modifiers();
+ assertEquals("Wrong size", 3, modifiers.size());
+ IExtendedModifier extendedModifier = (IExtendedModifier) modifiers.get(0);
+ assertTrue("Not an annotation", extendedModifier instanceof SingleMemberAnnotation);
+ SingleMemberAnnotation annotation = (SingleMemberAnnotation) extendedModifier;
+ final Expression value = annotation.getValue();
+ assertEquals("Not a type literal", ASTNode.TYPE_LITERAL, value.getNodeType());
+ TypeLiteral typeLiteral = (TypeLiteral) value;
+ final Type type = typeLiteral.getType();
+ assertEquals("Not a simple type", ASTNode.SIMPLE_TYPE, type.getNodeType());
+ SimpleType simpleType = (SimpleType) type;
+ final Name name = simpleType.getName();
+ assertEquals("Not a qualified name", ASTNode.QUALIFIED_NAME, name.getNodeType());
+ QualifiedName qualifiedName = (QualifiedName) name;
+ final IBinding binding = qualifiedName.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong value", "Bar2.Baz", qualifiedName.getFullyQualifiedName());
+ final Name qualifier = qualifiedName.getQualifier();
+ assertEquals("Not a simple name", ASTNode.SIMPLE_NAME, qualifier.getNodeType());
+ SimpleName simpleName2 = (SimpleName) qualifier;
+ final IBinding binding3 = simpleName2.resolveBinding();
+ assertNotNull("No binding3", binding3);
+ assertTrue("Not a recovered binding", binding3.isRecovered());
+ final IJavaElement javaElement = binding3.getJavaElement();
+ assertNotNull("No java element", javaElement);
+ assertEquals("Not a compilation unit", IJavaElement.COMPILATION_UNIT, javaElement.getElementType());
+ assertNotNull("No parent", javaElement.getParent());
+ }
+
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=203342
+ */
+ public void test0284() throws JavaModelException {
+ String contents =
+ "public class X {\n" +
+ " public static final double VAR = 0x0.0000000000001P-1022;\n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ final List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ final Expression initializer = fragment.getInitializer();
+ assertEquals("Not a number literal", ASTNode.NUMBER_LITERAL, initializer.getNodeType());
+ checkSourceRange(initializer, "0x0.0000000000001P-1022", contents);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=223488
+ */
+ public void test0285() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/p/X.java", true/* resolve */);
+ PackageDeclaration packageDeclaration = (PackageDeclaration) buildAST(
+ "/*start*/package p;/*end*/\n" +
+ "public class X {\n" +
+ "}",
+ this.workingCopy,
+ false/*don't report errors*/);
+ IPackageBinding packageBinding = packageDeclaration.resolveBinding();
+ try {
+ startLogListening();
+ packageBinding.getAnnotations();
+ assertLogEquals("");
+ } finally {
+ stopLogListening();
+ }
+ }
+
+ /**
+ * @bug 187430: Unresolved types surfacing through DOM AST for annotation default values
+ * @test That the qualified name of the default value does not contain any '$' character
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=187430"
+ */
+ public void testBug187430() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/b187430/Test.java", true/*resolve*/);
+ String contents =
+ "package b187430;\n" +
+ "@C\n" +
+ "public class Test {}\n";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0, "");
+ List types = unit.types();
+ assertEquals("Wrong size", 1, types.size());
+ AbstractTypeDeclaration abstractTypeDeclaration = (AbstractTypeDeclaration) types.get(0);
+ assertEquals("Wrong type", ASTNode.TYPE_DECLARATION, abstractTypeDeclaration.getNodeType());
+ TypeDeclaration declaration = (TypeDeclaration) abstractTypeDeclaration;
+ ITypeBinding typeBinding = declaration.resolveBinding();
+ IAnnotationBinding[] annotations = typeBinding.getAnnotations();
+ assertEquals("Wrong size", 1, annotations.length);
+ IMemberValuePairBinding[] allMemberValuePairs = annotations[0].getAllMemberValuePairs();
+ assertEquals("Expected 'intval' and 'classval' member pair values", 2, allMemberValuePairs.length);
+ IMethodBinding methodBinding = allMemberValuePairs[0].getMethodBinding();
+ Object defaultValue = methodBinding.getDefaultValue();
+ ITypeBinding iTypeBinding = (ITypeBinding) defaultValue;
+ assertEquals("Unexpected default value", "b187430.A.B", iTypeBinding.getQualifiedName());
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228691
+ */
+ public void test0286() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0286/X.java", true/*resolve*/);
+ String contents =
+ "package test0286;\n" +
+ "public class X {\n" +
+ " int i;\n" +
+ " Integer integer;\n" +
+ "}\n";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ ASTNode node2 = getASTNode(unit, 0, 0);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node2.getNodeType());
+ FieldDeclaration declaration = (FieldDeclaration) node2;
+ ITypeBinding typeBinding = declaration.getType().resolveBinding();
+ node2 = getASTNode(unit, 0, 1);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node2.getNodeType());
+ declaration = (FieldDeclaration) node2;
+ ITypeBinding typeBinding2 = declaration.getType().resolveBinding();
+ assertEquals("Wrong type", "int", typeBinding.getName());
+ assertEquals("Wrong type", "Integer", typeBinding2.getName());
+ assertTrue("Not assignmentCompatible: Integer -> int", typeBinding2.isAssignmentCompatible(typeBinding));
+ assertTrue("Not assignmentCompatible: int -> Integer", typeBinding.isAssignmentCompatible(typeBinding2));
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651
+ */
+ public void test0287() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0287/A.java", true/*resolve*/);
+ MemberValuePair pair = (MemberValuePair) buildAST(
+ "package test0287;\n" +
+ "@ABC (/*start*/name1=\"\"/*end*/)\n" +
+ "public class A {}",
+ this.workingCopy,
+ false/*don't report errors*/,
+ true,
+ true);
+ IMemberValuePairBinding resolveMemberValuePairBinding = pair.resolveMemberValuePairBinding();
+ assertNull("Got a binding", resolveMemberValuePairBinding);
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651
+ */
+ public void test0288() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0288/A.java", true/*resolve*/);
+ MemberValuePair pair = (MemberValuePair) buildAST(
+ "package test0288;\n" +
+ "@ABC (/*start*/name1=\"\"/*end*/)\n" +
+ "public class A {}",
+ this.workingCopy,
+ false/*don't report errors*/,
+ true,
+ false);
+ IMemberValuePairBinding resolveMemberValuePairBinding = pair.resolveMemberValuePairBinding();
+ assertNull("Got a binding", resolveMemberValuePairBinding);
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651
+ */
+ public void test0289() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0289/A.java", true/*resolve*/);
+ NormalAnnotation annotation = (NormalAnnotation) buildAST(
+ "package test0289;\n" +
+ "/*start*/@ABC (name1=\"\")/*end*/\n" +
+ "public class A {}",
+ this.workingCopy,
+ false/*don't report errors*/,
+ true,
+ false);
+ IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding();
+ assertNull("No binding", resolveAnnotationBinding);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651
+ */
+ public void test0290() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0290/A.java", true/*resolve*/);
+ NormalAnnotation annotation = (NormalAnnotation) buildAST(
+ "package test0290;\n" +
+ "/*start*/@ABC (name1=\"\")/*end*/\n" +
+ "public class A {}",
+ this.workingCopy,
+ false/*don't report errors*/,
+ true,
+ true);
+ IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding();
+ assertTrue("Not recovered", resolveAnnotationBinding.isRecovered());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651
+ */
+ public void test0291() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0291/A.java", true/*resolve*/);
+ NormalAnnotation annotation = (NormalAnnotation) buildAST(
+ "package test0291;\n" +
+ "/*start*/@ABC (name1=\"\")/*end*/\n" +
+ "public class A {}",
+ this.workingCopy,
+ false/*don't report errors*/,
+ true,
+ true);
+ IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding();
+ assertEquals("Wrong size", 0, resolveAnnotationBinding.getAllMemberValuePairs().length);
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651
+ */
+ public void test0292() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0292/A.java", true/*resolve*/);
+ NormalAnnotation annotation = (NormalAnnotation) buildAST(
+ "package test0292;\n" +
+ "@interface ABC {\n" +
+ " String name1() default \"\";\n" +
+ "}\n" +
+ "/*start*/@ABC(name1=\"\", id=0)/*end*/\n" +
+ "public class A {}",
+ this.workingCopy,
+ false/*don't report errors*/,
+ true,
+ true);
+ IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding();
+ assertFalse("Recovered", resolveAnnotationBinding.isRecovered());
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651
+ */
+ public void test0293() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0293/A.java", true/*resolve*/);
+ NormalAnnotation annotation = (NormalAnnotation) buildAST(
+ "package test0293;\n" +
+ "@interface ABC {\n" +
+ " String name1() default \"\";\n" +
+ "}\n" +
+ "/*start*/@ABC(name1=\"\", id=0)/*end*/\n" +
+ "public class A {}",
+ this.workingCopy,
+ false/*don't report errors*/,
+ true,
+ true);
+ IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding();
+ assertEquals("Wrong size", 1, resolveAnnotationBinding.getAllMemberValuePairs().length);
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651
+ */
+ public void test0294() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0294/A.java", true/*resolve*/);
+ NormalAnnotation annotation = (NormalAnnotation) buildAST(
+ "package test0294;\n" +
+ "@interface ABC {\n" +
+ " String name1() default \"\";\n" +
+ "}\n" +
+ "/*start*/@ABC(name1=\"\", id=0)/*end*/\n" +
+ "public class A {}",
+ this.workingCopy,
+ false/*don't report errors*/,
+ true,
+ true);
+ IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding();
+ assertEquals("Wrong size", 1, resolveAnnotationBinding.getDeclaredMemberValuePairs().length);
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651
+ */
+ public void test0295() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0295/A.java", true/*resolve*/);
+ NormalAnnotation annotation = (NormalAnnotation) buildAST(
+ "package test0295;\n" +
+ "@interface ABC {\n" +
+ " String name1() default \"\";\n" +
+ "}\n" +
+ "/*start*/@ABC(id=0)/*end*/\n" +
+ "public class A {}",
+ this.workingCopy,
+ false/*don't report errors*/,
+ true,
+ true);
+ IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding();
+ assertEquals("Wrong size", 1, resolveAnnotationBinding.getAllMemberValuePairs().length);
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651
+ */
+ public void test0296() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0296/A.java", true/*resolve*/);
+ NormalAnnotation annotation = (NormalAnnotation) buildAST(
+ "package test0296;\n" +
+ "@interface ABC {\n" +
+ " String name1() default \"\";\n" +
+ "}\n" +
+ "/*start*/@ABC(id=0)/*end*/\n" +
+ "public class A {}",
+ this.workingCopy,
+ false/*don't report errors*/,
+ true,
+ false);
+ IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding();
+ assertEquals("Wrong size", 1, resolveAnnotationBinding.getAllMemberValuePairs().length);
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=228651
+ */
+ public void test0297() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0297/A.java", true/*resolve*/);
+ NormalAnnotation annotation = (NormalAnnotation) buildAST(
+ "package test0297;\n" +
+ "@interface ABC {\n" +
+ " String name1() default \"\";\n" +
+ "}\n" +
+ "/*start*/@ABC(name1=\"\", id=0)/*end*/\n" +
+ "public class A {}",
+ this.workingCopy,
+ false/*don't report errors*/,
+ true,
+ false);
+ IAnnotationBinding resolveAnnotationBinding = annotation.resolveAnnotationBinding();
+ assertEquals("Wrong size", 1, resolveAnnotationBinding.getDeclaredMemberValuePairs().length);
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=230127
+ */
+ public void test0298() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0298/X.java", true/*resolve*/);
+ Type type = (Type) buildAST(
+ "package test0298;\n" +
+ "import java.util.List;\n" +
+ "public interface X {\n" +
+ " /*start*/List<IEntity>/*end*/ foo();\n" +
+ "}",
+ this.workingCopy,
+ false/*don't report errors*/,
+ true,
+ false);
+ ITypeBinding binding = type.resolveBinding();
+ assertNull("Got a binding", binding);
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=230127
+ */
+ public void test0299() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0299/X.java", true/*resolve*/);
+ Type type = (Type) buildAST(
+ "package test0299;\n" +
+ "public interface X {\n" +
+ " /*start*/List<IEntity>/*end*/ foo();\n" +
+ "}",
+ this.workingCopy,
+ false/*don't report errors*/,
+ true,
+ false);
+ ITypeBinding binding = type.resolveBinding();
+ assertNull("Got a binding", binding);
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=230127
+ */
+ public void test0300() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0300/X.java", true/*resolve*/);
+ Type type = (Type) buildAST(
+ "package test0300;\n" +
+ "public interface X {\n" +
+ " /*start*/ArrayList<IEntity>/*end*/ foo();\n" +
+ "}",
+ this.workingCopy,
+ false/*don't report errors*/,
+ true,
+ false);
+ ITypeBinding binding = type.resolveBinding();
+ assertNull("Got a binding", binding);
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=230127
+ */
+ public void test0301() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0301/X.java", true/*resolve*/);
+ Type type = (Type) buildAST(
+ "package test03018;\n" +
+ "import java.util.List;\n" +
+ "public interface X {\n" +
+ " /*start*/List<IEntity>/*end*/ foo();\n" +
+ "}",
+ this.workingCopy,
+ false/*don't report errors*/,
+ true,
+ true);
+ ITypeBinding binding = type.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=230127
+ */
+ public void test0302() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0302/X.java", true/*resolve*/);
+ Type type = (Type) buildAST(
+ "package test0302;\n" +
+ "public interface X {\n" +
+ " /*start*/List<IEntity>/*end*/ foo();\n" +
+ "}",
+ this.workingCopy,
+ false/*don't report errors*/,
+ true,
+ true);
+ ITypeBinding binding = type.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=230127
+ */
+ public void test0303() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0303/X.java", true/*resolve*/);
+ ParameterizedType type = (ParameterizedType) buildAST(
+ "package test0303;\n" +
+ "public interface X {\n" +
+ " /*start*/ArrayList<IEntity>/*end*/ foo();\n" +
+ "}",
+ this.workingCopy,
+ false/*don't report errors*/,
+ true,
+ true);
+ ITypeBinding binding = type.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=230127
+ */
+ public void test0304() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0304/X.java", true/*resolve*/);
+ Type type = (Type) buildAST(
+ "package test0304;\n" +
+ "public interface X {\n" +
+ " ArrayList</*start*/IEntity/*end*/> foo();\n" +
+ "}",
+ this.workingCopy,
+ false/*don't report errors*/,
+ true,
+ true);
+ ITypeBinding binding = type.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=230127
+ */
+ public void test0305() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0305/X.java", true/*resolve*/);
+ Type type = (Type) buildAST(
+ "package test0305;\n" +
+ "public interface X {\n" +
+ " ArrayList</*start*/IEntity/*end*/> foo();\n" +
+ "}",
+ this.workingCopy,
+ false/*don't report errors*/,
+ true,
+ false);
+ ITypeBinding binding = type.resolveBinding();
+ assertNull("Got a binding", binding);
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=230127
+ */
+ public void test0306() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0306/X.java", true/*resolve*/);
+ VariableDeclarationStatement statement= (VariableDeclarationStatement) buildAST(
+ "package test0306;\n" +
+ "public class X {\n" +
+ " void foo() {\n" +
+ " /*start*/ArrayList<IEntity> list;/*end*/\n" +
+ " }\n" +
+ "}",
+ this.workingCopy,
+ false/*don't report errors*/,
+ true,
+ false);
+ List fragments = statement.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding binding = fragment.resolveBinding();
+ assertNull("Got a binding", binding);
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=230127
+ */
+ public void test0307() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0307/X.java", true/*resolve*/);
+ VariableDeclarationStatement statement= (VariableDeclarationStatement) buildAST(
+ "package test0307;\n" +
+ "public class X {\n" +
+ " void foo() {\n" +
+ " /*start*/ArrayList<IEntity> list;/*end*/\n" +
+ " }\n" +
+ "}",
+ this.workingCopy,
+ false/*don't report errors*/,
+ true,
+ true);
+ List fragments = statement.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding binding = fragment.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=230127
+ */
+ public void test0308() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0308/X.java", true/*resolve*/);
+ MethodDeclaration declaration= (MethodDeclaration) buildAST(
+ "package test0308;\n" +
+ "public class X {\n" +
+ " /*start*/ArrayList<IEntity> foo() {\n" +
+ " return null;\n" +
+ " }/*end*/\n" +
+ "}",
+ this.workingCopy,
+ false/*don't report errors*/,
+ true,
+ false);
+ IMethodBinding binding = declaration.resolveBinding();
+ assertNull("Got a binding", binding);
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=230127
+ */
+ public void test0309() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0309/X.java", true/*resolve*/);
+ MethodDeclaration declaration= (MethodDeclaration) buildAST(
+ "package test0309;\n" +
+ "public class X {\n" +
+ " /*start*/ArrayList<IEntity> foo() {\n" +
+ " return null;\n" +
+ " }/*end*/\n" +
+ "}",
+ this.workingCopy,
+ false/*don't report errors*/,
+ true,
+ true);
+ IMethodBinding binding = declaration.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=230127
+ */
+ public void test0310() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0310/X.java", true/*resolve*/);
+ MethodDeclaration declaration= (MethodDeclaration) buildAST(
+ "package test0310;\n" +
+ "public class X {\n" +
+ " /*start*/void foo(ArrayList<IEntity> list) {\n" +
+ " }/*end*/\n" +
+ "}",
+ this.workingCopy,
+ false/*don't report errors*/,
+ true,
+ false);
+ IMethodBinding binding = declaration.resolveBinding();
+ assertNull("Got a binding", binding);
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=230127
+ */
+ public void test0311() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0311/X.java", true/*resolve*/);
+ MethodDeclaration declaration= (MethodDeclaration) buildAST(
+ "package test0311;\n" +
+ "public class X {\n" +
+ " /*start*/void foo(ArrayList<IEntity> list) {\n" +
+ " }/*end*/\n" +
+ "}",
+ this.workingCopy,
+ false/*don't report errors*/,
+ true,
+ true);
+ IMethodBinding binding = declaration.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /*
+ * Ensures that requesting a type binding with a non-existing parameterized type doesn't throw an OutOfMemoryError
+ * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=233625 )
+ */
+ public void test0312() throws JavaModelException {
+ String[] bindingKeys = new String[] {"Ljava/util/Map<Ljava/lang/Class<Ljava/lang/Class;*>;Ljava/util/List<LUnknown;>;>;"};
+ BindingRequestor requestor = new BindingRequestor();
+ resolveASTs(new ICompilationUnit[] {} , bindingKeys, requestor, getJavaProject("Converter15"), null);
+ assertBindingsEqual(
+ "<null>",
+ requestor.getBindings(bindingKeys));
+ }
+
+ /*
+ * Ensures that requesting a method binding with a non-existing parameterized type doesn't throw an OutOfMemoryError
+ * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=233625 )
+ */
+ public void test0313() throws JavaModelException {
+ String[] bindingKeys = new String[] {"Ljava/util/Collections;.emptyMap<K:Ljava/lang/Object;V:Ljava/lang/Object;>()Ljava/util/Map<TK;TV;>;%<Ljava/lang/Class<Ljava/lang/Class;*>;Ljava/util/List<LUnknown;>;>"};
+ BindingRequestor requestor = new BindingRequestor();
+ resolveASTs(new ICompilationUnit[] {} , bindingKeys, requestor, getJavaProject("Converter15"), null);
+ assertBindingsEqual(
+ "<null>",
+ requestor.getBindings(bindingKeys));
+ }
+
+ /*
+ * Ensures that requesting a type binding with a non-existing parameterized type returns null
+ * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=233625 )
+ */
+ public void test0314() throws JavaModelException {
+ String[] bindingKeys = new String[] {"Ljava/util/List<LZork;>.Map<Ljava/lang/Object;Ljava/lang/Number;>;"};
+ BindingRequestor requestor = new BindingRequestor();
+ resolveASTs(new ICompilationUnit[] {} , bindingKeys, requestor, getJavaProject("Converter15"), null);
+ assertBindingsEqual(
+ "<null>",
+ requestor.getBindings(bindingKeys));
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=120082
+ */
+ public void test0315() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/pack1/E.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ "package pack1;\n" +
+ "public class E<X> {\n" +
+ " public static <T> E<T> bar(T t) {\n" +
+ " return null;\n" +
+ " }\n" +
+ "\n" +
+ " public void foo(E<?> e) {\n" +
+ " /*start*/bar(e)/*end*/;\n" +
+ " }\n" +
+ "}",
+ this.workingCopy);
+ IBinding binding = ((MethodInvocation) node).resolveTypeBinding();
+ assertBindingKeyEquals(
+ "Lpack1/E<Lpack1/E<!Lpack1/E;{0}*122;>;>;",
+ binding.getKey());
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=239439
+ */
+ public void test0316() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0316/X.java", true/*resolve*/);
+ ClassInstanceCreation expression = (ClassInstanceCreation) buildAST(
+ "package test0316;\n" +
+ "class AbstractClass {\n" +
+ " XXList<Class> statements = null;\n" +
+ "}\n" +
+ "import java.util.ArrayList;\n" +
+ "public class X extends AbstractClass {\n" +
+ " public List<Class> compute() {\n" +
+ " statements = /*start*/new ArrayList<Class>()/*end*/;\n" +
+ " return statements;\n" +
+ " }\n" +
+ "}",
+ this.workingCopy,
+ false,
+ true,
+ true);
+ ITypeBinding typeBinding = expression.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding);
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=239439
+ */
+ public void test0317() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0317/X.java", true/*resolve*/);
+ ClassInstanceCreation expression = (ClassInstanceCreation) buildAST(
+ "package test0317;\n" +
+ "import java.util.ArrayList;\n" +
+ "import java.util.List;\n" +
+ "public class X {\n" +
+ " XXList<Class> statements = null;\n" +
+ " public List<Class> compute() {\n" +
+ " statements = /*start*/new ArrayList<Class>()/*end*/;\n" +
+ " return statements;\n" +
+ " }\n" +
+ "}",
+ this.workingCopy,
+ false,
+ true,
+ true);
+ ITypeBinding typeBinding = expression.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding);
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=218500
+ */
+ public void test0318() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0317/X.java", true/*resolve*/);
+ SimpleType type = (SimpleType) buildAST(
+ "class X {\n" +
+ " {\n" +
+ " abstract class B<T> {\n" +
+ " abstract class A {}\n" +
+ " public void foo() {\n" +
+ " new /*start*/A/*end*/() {};\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ "}",
+ this.workingCopy,
+ false,
+ true,
+ true);
+ ITypeBinding typeBinding = type.getName().resolveTypeBinding();
+ assertEquals("Not an empty name", 0, typeBinding.getQualifiedName().length());
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=212034
+ */
+ public void test0319() throws JavaModelException {
+ String contents =
+ "package test0319;\n" +
+ "public class Test {\n" +
+ " /*start*/@Deprecated\n" +
+ " @Invalid\n" +
+ " public void foo() {}/*end*/" +
+ "}\n";
+ this.workingCopy = getWorkingCopy(
+ "/Converter15/src/test0319/Test.java",
+ contents,
+ true/*resolve*/
+ );
+ MethodDeclaration methodDeclaration = (MethodDeclaration) buildAST(contents, this.workingCopy, false, false, false);
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ IAnnotationBinding[] annotations = methodBinding.getAnnotations();
+ assertEquals("Got more than one annotation binding", 1, annotations.length);
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=212034
+ */
+ public void test0320() throws JavaModelException {
+ String contents =
+ "package test0320;\n" +
+ "public class Test {\n" +
+ " /*start*/@Deprecated\n" +
+ " @Invalid\n" +
+ " public int i;/*end*/" +
+ "}\n";
+ this.workingCopy = getWorkingCopy(
+ "/Converter15/src/test0320/Test.java",
+ contents,
+ true/*resolve*/
+ );
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) buildAST(contents, this.workingCopy, false, false, false);
+ List fragments = fieldDeclaration.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ IAnnotationBinding[] annotations = variableBinding.getAnnotations();
+ assertEquals("Got more than one annotation binding", 1, annotations.length);
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=103643
+ */
+ public void _test0321() throws JavaModelException {
+ String contents =
+ "package test0321;\n" +
+ "import java.util.*;\n" +
+ "class X {\n" +
+ " <T extends Collection<? extends Number>> T getLonger(T t1, T t2) {\n" +
+ " return t1.size() > t2.size() ? t1 : t2;\n" +
+ " }\n" +
+ " void m(HashSet<? extends Double> list, ArrayList<? extends Integer> set) {\n" +
+ " /*start*/getLonger(list, set)/*end*/;\n" +
+ " }\n" +
+ "}";
+ this.workingCopy = getWorkingCopy(
+ "/Converter15/src/test0321/X.java",
+ contents,
+ true/*resolve*/
+ );
+ MethodInvocation invocation = (MethodInvocation) buildAST(contents, this.workingCopy, true, true, true);
+ IMethodBinding methodBinding = invocation.resolveMethodBinding();
+ System.out.println(methodBinding.getReturnType().getQualifiedName());
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=242933
+ */
+ public void test0322() throws JavaModelException {
+ String contents =
+ "package test0322;\n" +
+ "@interface Range {\n" +
+ " long min() default -9223372036854775808L;\n" +
+ " long max() default 9223372036854775807L;\n" +
+ " String message() default \"\";\n" +
+ "}\n" +
+ "public class X {\n" +
+ " private int id;\n" +
+ " /*start*/@Range(max=9999999999999999)/*end*/\n" +
+ " public long getId() {\n" +
+ " return id;\n" +
+ " }\n" +
+ "}";
+ this.workingCopy = getWorkingCopy(
+ "/Converter15/src/test0322/X.java",
+ contents,
+ true/*resolve*/
+ );
+ NormalAnnotation annotation = (NormalAnnotation) buildAST(contents, this.workingCopy, false, true, true);
+ IAnnotationBinding annotationBinding = annotation.resolveAnnotationBinding();
+ IMemberValuePairBinding[] memberValuePairBindings = annotationBinding.getDeclaredMemberValuePairs();
+ IMemberValuePairBinding pairBinding = memberValuePairBindings[0];
+ assertNull("Got a value", pairBinding.getValue());
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=245563
+ */
+ public void test0323() throws JavaModelException {
+ String contents =
+ "class X {\n" +
+ " {\n" +
+ " for(Object obj:\n" +
+ " new Object[]{\n" +
+ " new Object(){\n" +
+ " int field=method(\n" +
+ " });\n" +
+ " }\n" +
+ " });\n" +
+ " }\n" +
+ " int method(int...args){\n" +
+ " return args.length;\n" +
+ " }\n" +
+ "}\n" +
+ "";
+ this.workingCopy = getWorkingCopy(
+ "/Converter15/src/test0322/X.java",
+ contents,
+ true/*resolve*/
+ );
+ assertNotNull("No node", buildAST(contents, this.workingCopy, false, true, true));
+ }
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=270367
+ public void test0324() throws JavaModelException {
+ String contents = "package test0324;\n"
+ + "public class X {\n"
+ + " public void someMethod() {\n"
+ + " int i = /*start*/(new Integer(getId())).intValue()/*end*/;\n"
+ + " }\n"
+ + " public String getId() {\n"
+ + " return null;\n"
+ + " }\n"
+ + "}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/test0324/X.java", contents, true/*resolve*/
+ );
+ MethodInvocation methodCall = (MethodInvocation) buildAST(contents, this.workingCopy, false, true, true);
+ ParenthesizedExpression intValueReceiver = (ParenthesizedExpression) methodCall.getExpression();
+ ParenthesizedExpression newParenthesizedExpression = (ParenthesizedExpression) ASTNode.copySubtree(
+ intValueReceiver.getAST(), intValueReceiver);
+ replaceNodeInParent(methodCall, newParenthesizedExpression);
+
+ // copied node
+ ClassInstanceCreation constructorCall = (ClassInstanceCreation) newParenthesizedExpression.getExpression();
+ constructorCall.resolveTypeBinding();
+ IMethodBinding constructorBinding = constructorCall.resolveConstructorBinding();
+ assertNull("Not null constructor binding", constructorBinding);
+
+ // original node
+ constructorCall = (ClassInstanceCreation) intValueReceiver.getExpression();
+ constructorCall.resolveTypeBinding(); // This should not throw a NPE
+ constructorBinding = constructorCall.resolveConstructorBinding();
+ assertNotNull("Null constructor binding", constructorBinding);
+ }
+
+ // Utility method to replace "node" by "replacement"
+ private void replaceNodeInParent(Expression node, Expression replacement) {
+ StructuralPropertyDescriptor loc = node.getLocationInParent();
+ if (loc.isChildProperty()) {
+ node.getParent().setStructuralProperty(loc, replacement);
+ }
+ else {
+ List l = (List) node.getParent().getStructuralProperty(loc);
+ for (int i = 0; i < l.size(); i++) {
+ if (node.equals(l.get(i))) {
+ l.set(i, replacement);
+ break;
+ }
+ }
+ }
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=271561
+ */
+ public void test0325() throws JavaModelException {
+ String contents =
+ "package test0325;\n" +
+ "public class Y {}";
+ this.workingCopy = getWorkingCopy(
+ "/Converter15/src/test0325/Y.java",
+ contents,
+ true/*resolve*/
+ );
+ IAnnotation[] annotations = this.workingCopy.getJavaProject().findType("test0325.X").getAnnotations();
+ assertAnnotationsEqual("@test0325.SecondaryTables({@test0325.SecondaryTable(name=\"FOO\"), @test0325.SecondaryTable(name=\"BAR\")})\n", annotations);
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=271561
+ */
+ public void test0326() throws JavaModelException {
+ String contents =
+ "package test0326;\n" +
+ "@SecondaryTables({@SecondaryTable(name=\"FOO\"), @SecondaryTable(name=\"BAR\")})\n" +
+ "public class X {}";
+ this.workingCopy = getWorkingCopy(
+ "/Converter15/src/test0326/X.java",
+ contents,
+ true/*resolve*/
+ );
+ IAnnotation[] annotations = this.workingCopy.getType("X").getAnnotations();
+ assertAnnotationsEqual("@SecondaryTables({@SecondaryTable(name=\"FOO\"), @SecondaryTable(name=\"BAR\")})\n", annotations);
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=271561
+ */
+ public void test0327() throws JavaModelException {
+ String contents =
+ "package test0327;\n" +
+ "@SecondaryTables({@SecondaryTable(name=\"FOO\"), @SecondaryTable(name=\"BAR\")})\n" +
+ "public class X {}";
+ this.workingCopy = getWorkingCopy(
+ "/Converter15/src/test0327/X.java",
+ contents,
+ true/*resolve*/
+ );
+ IAnnotation[] annotations = this.workingCopy.getType("X").getAnnotations();
+ assertAnnotationsEqual("@SecondaryTables({@SecondaryTable(name=\"FOO\"), @SecondaryTable(name=\"BAR\")})\n", annotations);
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=271561
+ */
+ public void test0328() throws JavaModelException {
+ String contents =
+ "package test0328;\n" +
+ "public class Y {}";
+ this.workingCopy = getWorkingCopy(
+ "/Converter15/src/test0328/Y.java",
+ contents,
+ true/*resolve*/
+ );
+ IAnnotation[] annotations = this.workingCopy.getJavaProject().findType("test0328.X").getAnnotations();
+ assertAnnotationsEqual("@test0328.JoinTable(name=\"EMP_PROJ\", joinColumns={@test0328.JoinColumn(name=\"EMP_ID\", referencedColumnName=\"EMP_ID\")}, inverseJoinColumns={@test0328.JoinColumn(name=\"PROJ_ID\", referencedColumnName=\"PROJ_ID\")})\n", annotations);
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=271561
+ */
+ public void test0329() throws JavaModelException {
+ String contents =
+ "package test0329;\n" +
+ "@JoinTable(\n" +
+ " name=\"EMP_PROJ\",\n" +
+ " joinColumns = {\n" +
+ " @JoinColumn(name = \"EMP_ID\", referencedColumnName = \"EMP_ID\")\n" +
+ " },\n" +
+ " inverseJoinColumns = {\n" +
+ " @JoinColumn(name = \"PROJ_ID\", referencedColumnName = \"PROJ_ID\")\n" +
+ " }\n" +
+ ")\n" +
+ "public class X {}";
+ this.workingCopy = getWorkingCopy(
+ "/Converter15/src/test0329/X.java",
+ contents,
+ true/*resolve*/
+ );
+ IAnnotation[] annotations = this.workingCopy.getType("X").getAnnotations();
+ assertAnnotationsEqual("@JoinTable(name=\"EMP_PROJ\", joinColumns={@JoinColumn(name=\"EMP_ID\", referencedColumnName=\"EMP_ID\")}, inverseJoinColumns={@JoinColumn(name=\"PROJ_ID\", referencedColumnName=\"PROJ_ID\")})\n", annotations);
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=271561
+ */
+ public void test0330() throws JavaModelException {
+ String contents =
+ "package test0330;\n" +
+ "public class Y {}";
+ this.workingCopy = getWorkingCopy(
+ "/Converter15/src/test0330/Y.java",
+ contents,
+ true/*resolve*/
+ );
+ IAnnotation[] annotations = this.workingCopy.getJavaProject().findType("test0330.X").getAnnotations();
+ assertAnnotationsEqual("@test0330.JoinTable(name=\"EMP_PROJ\", joinColumns=@test0330.JoinColumn(name=\"EMP_ID\", referencedColumnName=\"EMP_ID\"), inverseJoinColumns=@test0330.JoinColumn(name=\"PROJ_ID\", referencedColumnName=\"PROJ_ID\"))\n", annotations);
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=271561
+ */
+ public void test0331() throws JavaModelException {
+ String contents =
+ "package test0331;\n" +
+ "@JoinTable(\n" +
+ " name=\"EMP_PROJ\",\n" +
+ " joinColumns = @JoinColumn(name = \"EMP_ID\", referencedColumnName = \"EMP_ID\"),\n" +
+ " inverseJoinColumns = @JoinColumn(name = \"PROJ_ID\", referencedColumnName = \"PROJ_ID\")\n" +
+ ")\n" +
+ "public class X {}";
+ this.workingCopy = getWorkingCopy(
+ "/Converter15/src/test0331/X.java",
+ contents,
+ true/*resolve*/
+ );
+ IAnnotation[] annotations = this.workingCopy.getType("X").getAnnotations();
+ assertAnnotationsEqual("@JoinTable(name=\"EMP_PROJ\", joinColumns=@JoinColumn(name=\"EMP_ID\", referencedColumnName=\"EMP_ID\"), inverseJoinColumns=@JoinColumn(name=\"PROJ_ID\", referencedColumnName=\"PROJ_ID\"))\n", annotations);
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=271561
+ */
+ public void test0332() throws JavaModelException {
+ String contents =
+ "package test0332;\n" +
+ "public class Y {}";
+ this.workingCopy = getWorkingCopy(
+ "/Converter15/src/test0332/Y.java",
+ contents,
+ true/*resolve*/
+ );
+ IAnnotation[] annotations = this.workingCopy.getJavaProject().findType("test0332.X").getAnnotations();
+ assertAnnotationsEqual("@test0332.JoinTable(name=\"EMP_PROJ\", joinColumns=@test0332.JoinColumn(name=\"EMP_ID\", referencedColumnClass=java.lang.Object.class), inverseJoinColumns=@test0332.JoinColumn(name=\"PROJ_ID\", referencedColumnClass=java.lang.Class.class), getLocalClass=java.lang.String.class)\n", annotations);
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=271561
+ */
+ public void test0333() throws JavaModelException {
+ String contents =
+ "package test0333;\n" +
+ "public class Y {}";
+ this.workingCopy = getWorkingCopy(
+ "/Converter15/src/test0333/Y.java",
+ contents,
+ true/*resolve*/
+ );
+ IAnnotation[] annotations = this.workingCopy.getJavaProject().findType("test0333.X").getAnnotations();
+ assertAnnotationsEqual("@test0333.JoinTable(name=\"EMP_PROJ\", joinColumns=@test0333.JoinColumn(name=\"EMP_ID\", referencedColumnClass=java.lang.Class.class), inverseJoinColumns=@test0333.JoinColumn(name=\"PROJ_ID\", referencedColumnClass=java.lang.Class.class), getLocalClass=java.lang.String.class)\n", annotations);
+ }
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=286407
+ public void test0334() throws CoreException, IOException {
+ String contents =
+ "package test0334;\n" +
+ "public class Y {}";
+ this.workingCopy = getWorkingCopy(
+ "/Converter15/src/test0334/Y.java",
+ contents,
+ true/*resolve*/
+ );
+ IJavaProject javaProject = this.workingCopy.getJavaProject();
+ String typeName = "test0334.MyAnnotation";
+ class BindingRequestor extends ASTRequestor {
+ ITypeBinding _result = null;
+ public void acceptBinding(String bindingKey, IBinding binding) {
+ if (this._result == null && binding != null && binding.getKind() == IBinding.TYPE)
+ this._result = (ITypeBinding) binding;
+ }
+ }
+ String[] keys = new String[] {
+ BindingKey.createTypeBindingKey(typeName)
+ };
+ final BindingRequestor requestor = new BindingRequestor();
+ final ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setResolveBindings(true);
+ parser.setProject(javaProject);
+ // this doesn't really do a parse; it's a type lookup
+ parser.createASTs(new ICompilationUnit[] {}, keys, requestor, null);
+ ITypeBinding typeBinding = requestor._result;
+ assertFalse("Is from source", typeBinding.isFromSource());
+ IAnnotationBinding[] annotations = typeBinding.getAnnotations();
+ assertEquals("Wrong number", 1, annotations.length);
+ IMemberValuePairBinding[] allMemberValuePairs = annotations[0].getAllMemberValuePairs();
+ assertEquals("Wrong number", 1, allMemberValuePairs.length);
+ }
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=286407
+ public void test0335() throws CoreException, IOException {
+ String contents =
+ "package test0335;\n" +
+ "public class Y {}";
+ this.workingCopy = getWorkingCopy(
+ "/Converter15/src/test0335/Y.java",
+ contents,
+ true/*resolve*/
+ );
+ IJavaProject javaProject = this.workingCopy.getJavaProject();
+ String typeName = "test0335.MyAnnotation";
+ class BindingRequestor extends ASTRequestor {
+ ITypeBinding _result = null;
+ public void acceptBinding(String bindingKey, IBinding binding) {
+ if (this._result == null && binding != null && binding.getKind() == IBinding.TYPE)
+ this._result = (ITypeBinding) binding;
+ }
+ }
+ String[] keys = new String[] {
+ BindingKey.createTypeBindingKey(typeName)
+ };
+ final BindingRequestor requestor = new BindingRequestor();
+ final ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setResolveBindings(true);
+ parser.setProject(javaProject);
+ // this doesn't really do a parse; it's a type lookup
+ parser.createASTs(new ICompilationUnit[] {}, keys, requestor, null);
+ ITypeBinding typeBinding = requestor._result;
+ assertFalse("Is from source", typeBinding.isFromSource());
+ IAnnotationBinding[] annotations = typeBinding.getAnnotations();
+ assertEquals("Wrong number", 1, annotations.length);
+ IMemberValuePairBinding[] allMemberValuePairs = annotations[0].getAllMemberValuePairs();
+ assertEquals("Wrong number", 1, allMemberValuePairs.length);
+ IMemberValuePairBinding memberValuePair = allMemberValuePairs[0];
+ IVariableBinding variableBinding = (IVariableBinding) memberValuePair.getValue();
+ assertEquals("Wrong field", "RUNTIME", variableBinding.getName());
+ }
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=286407
+ public void test0336() throws CoreException, IOException {
+ String contents =
+ "package test0336;\n" +
+ "public class Y {}";
+ this.workingCopy = getWorkingCopy(
+ "/Converter15/src/test0336/Y.java",
+ contents,
+ true/*resolve*/
+ );
+ IJavaProject javaProject = this.workingCopy.getJavaProject();
+ String typeName = "test0336.MyAnnotation";
+ class BindingRequestor extends ASTRequestor {
+ ITypeBinding _result = null;
+ public void acceptBinding(String bindingKey, IBinding binding) {
+ if (this._result == null && binding != null && binding.getKind() == IBinding.TYPE)
+ this._result = (ITypeBinding) binding;
+ }
+ }
+ String[] keys = new String[] {
+ BindingKey.createTypeBindingKey(typeName)
+ };
+ final BindingRequestor requestor = new BindingRequestor();
+ final ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setResolveBindings(true);
+ parser.setProject(javaProject);
+ // this doesn't really do a parse; it's a type lookup
+ parser.createASTs(new ICompilationUnit[] {}, keys, requestor, null);
+ ITypeBinding typeBinding = requestor._result;
+ assertFalse("Is from source", typeBinding.isFromSource());
+ IAnnotationBinding[] annotations = typeBinding.getAnnotations();
+ assertEquals("Wrong number", 1, annotations.length);
+ IMemberValuePairBinding[] allMemberValuePairs = annotations[0].getAllMemberValuePairs();
+ assertEquals("Wrong number", 1, allMemberValuePairs.length);
+ IMemberValuePairBinding memberValuePair = allMemberValuePairs[0];
+ IVariableBinding variableBinding = (IVariableBinding) memberValuePair.getValue();
+ assertEquals("Wrong field", "CLASS", variableBinding.getName());
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=287701
+ */
+ public void test0337() throws JavaModelException {
+ String contents =
+ "public class X {\n" +
+ " void m() {\n" +
+ " int x= 1 ;\n" +
+ " int y= - 1 , z=0 ;\n" +
+ " // Assignment nodes too long:\n" +
+ " int a= x = 2 ;\n" +
+ " System.out.print( x=1 );\n" +
+ " java.util.Arrays.asList( x = 1 /*bla*/ , x= 2\n" +
+ " // comment \n" +
+ " );\n" +
+ " }\n" +
+ "}\n" +
+ "";
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ CompilationUnit unit= (CompilationUnit) buildAST(
+ contents,
+ this.workingCopy,
+ true,
+ true,
+ true);
+ ASTNode node = getASTNode(unit, 0, 0, 2);
+ checkSourceRange(node, "int a= x = 2 ;", contents);
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) ((VariableDeclarationStatement) node).fragments().get(0);
+ checkSourceRange(fragment, "a= x = 2", contents);
+ node = getASTNode(unit, 0, 0, 3);
+ Expression expression = (Expression) ((MethodInvocation) ((ExpressionStatement) node).getExpression()).arguments().get(0);
+ checkSourceRange(expression, "x=1", contents);
+ node = getASTNode(unit, 0, 0, 4);
+ List arguments = ((MethodInvocation) ((ExpressionStatement) node).getExpression()).arguments();
+ ASTNode node2 = (ASTNode) arguments.get(0);
+ checkSourceRange(node2, "x = 1", contents);
+ checkSourceRange((ASTNode) arguments.get(1), "x= 2", contents);
+ int extendedLength = unit.getExtendedLength(node2);
+ int extendedStartPosition = unit.getExtendedStartPosition(node2);
+ checkSourceRange(extendedStartPosition, extendedLength, "x = 1 /*bla*/", contents);
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=290877
+ */
+ public void test0338() throws JavaModelException {
+ String contents =
+ "/**\n" +
+ " * The first enum value for my enum.\n" +
+ " *\n" +
+ " * @enum myEnum\n" +
+ " */\n" +
+ "public class X {}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ CompilationUnit unit= (CompilationUnit) buildAST(
+ contents,
+ this.workingCopy,
+ true,
+ true,
+ true);
+ TypeDeclaration node = (TypeDeclaration) getASTNode(unit, 0);
+ Javadoc javadoc = node.getJavadoc();
+ List tags = javadoc.tags();
+ assertEquals("Wrong size", "@enum", ((TagElement) tags.get(1)).getTagName());
+ checkSourceRange((TagElement) tags.get(1), "@enum myEnum", contents);
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=290877
+ */
+ public void test0339() throws JavaModelException {
+ String contents =
+ "/**\n" +
+ " * Use const as a tag element name.\n" +
+ " *\n" +
+ " * @const new constant\n" +
+ " */\n" +
+ "public class X {}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ CompilationUnit unit= (CompilationUnit) buildAST(
+ contents,
+ this.workingCopy,
+ true,
+ true,
+ true);
+ TypeDeclaration node = (TypeDeclaration) getASTNode(unit, 0);
+ Javadoc javadoc = node.getJavadoc();
+ List tags = javadoc.tags();
+ assertEquals("Wrong size", "@const", ((TagElement) tags.get(1)).getTagName());
+ checkSourceRange((TagElement) tags.get(1), "@const new constant", contents);
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=290877
+ */
+ public void test0340() throws JavaModelException {
+ String contents =
+ "/**\n" +
+ " * Use the goto as a tag element name.\n" +
+ " *\n" +
+ " * @goto new position\n" +
+ " */\n" +
+ "public class X {}";
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ CompilationUnit unit= (CompilationUnit) buildAST(
+ contents,
+ this.workingCopy,
+ true,
+ true,
+ true);
+ TypeDeclaration node = (TypeDeclaration) getASTNode(unit, 0);
+ Javadoc javadoc = node.getJavadoc();
+ List tags = javadoc.tags();
+ assertEquals("Wrong size", "@goto", ((TagElement) tags.get(1)).getTagName());
+ checkSourceRange((TagElement) tags.get(1), "@goto new position", contents);
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter16Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter16Test.java
new file mode 100644
index 0000000..7a3f1d4
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverter16Test.java
@@ -0,0 +1,81 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2009 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.dom;
+
+import java.util.List;
+
+import junit.framework.Test;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.Expression;
+import org.eclipse.jdt.core.dom.FieldDeclaration;
+import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+
+public class ASTConverter16Test extends ConverterTestSetup {
+
+ ICompilationUnit workingCopy;
+
+ public void setUpSuite() throws Exception {
+ super.setUpSuite();
+ this.ast = AST.newAST(AST.JLS3);
+ }
+
+ public ASTConverter16Test(String name) {
+ super(name);
+ }
+
+ static {
+// TESTS_NUMBERS = new int[] { 284 };
+// TESTS_RANGE = new int[] { 277, -1 };
+// TESTS_NAMES = new String[] {"test0204"};
+ }
+ public static Test suite() {
+ return buildModelTestSuite(ASTConverter16Test.class);
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ if (this.workingCopy != null) {
+ this.workingCopy.discardWorkingCopy();
+ this.workingCopy = null;
+ }
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=203342
+ */
+ public void test0001() throws JavaModelException {
+ String contents =
+ "public class X {\n" +
+ " public static final double VAR = 0x0.0000000000001P-1022;\n" +
+ "}";
+ this.workingCopy = getWorkingCopy("/Converter16/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ final List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ final Expression initializer = fragment.getInitializer();
+ assertEquals("Not a number literal", ASTNode.NUMBER_LITERAL, initializer.getNodeType());
+ checkSourceRange(initializer, "0x0.0000000000001P-1022", contents);
+ }
+}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST3Test.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST3Test.java
new file mode 100644
index 0000000..8f45c71
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterAST3Test.java
@@ -0,0 +1,9764 @@
+/*******************************************************************************
+ * 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.jdt.core.tests.dom;
+
+import java.util.*;
+
+import junit.framework.Test;
+
+import org.eclipse.jdt.core.*;
+import org.eclipse.jdt.core.dom.*;
+import org.eclipse.jdt.core.jdom.*;
+import org.eclipse.jdt.core.util.IModifierConstants;
+
+public class ASTConverterAST3Test extends ConverterTestSetup {
+
+ public void setUpSuite() throws Exception {
+ super.setUpSuite();
+ this.ast = AST.newAST(AST.JLS3);
+ }
+
+ public ASTConverterAST3Test(String name) {
+ super(name);
+ }
+
+ static {
+// TESTS_NUMBERS = new int[] { 356 };
+ }
+ public static Test suite() {
+ return buildModelTestSuite(ASTConverterAST3Test.class);
+ }
+
+ public void test0001() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0001", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+
+ // check that we have the right tree
+ CompilationUnit unit = this.ast.newCompilationUnit();
+ PackageDeclaration packageDeclaration = this.ast.newPackageDeclaration();
+ packageDeclaration.setName(this.ast.newSimpleName("test0001"));//$NON-NLS-1$
+ unit.setPackage(packageDeclaration);
+ ImportDeclaration importDeclaration = this.ast.newImportDeclaration();
+ QualifiedName name =
+ this.ast.newQualifiedName(
+ this.ast.newSimpleName("java"),//$NON-NLS-1$
+ this.ast.newSimpleName("util"));//$NON-NLS-1$
+ importDeclaration.setName(name);
+ importDeclaration.setOnDemand(true);
+ unit.imports().add(importDeclaration);
+ TypeDeclaration type = this.ast.newTypeDeclaration();
+ type.setInterface(false);
+ type.modifiers().add(this.ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
+ type.setName(this.ast.newSimpleName("Test"));//$NON-NLS-1$
+ MethodDeclaration methodDeclaration = this.ast.newMethodDeclaration();
+ methodDeclaration.setConstructor(false);
+ methodDeclaration.modifiers().add(this.ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
+ methodDeclaration.modifiers().add(this.ast.newModifier(Modifier.ModifierKeyword.STATIC_KEYWORD));
+ methodDeclaration.setName(this.ast.newSimpleName("main"));//$NON-NLS-1$
+ methodDeclaration.setReturnType2(this.ast.newPrimitiveType(PrimitiveType.VOID));
+ SingleVariableDeclaration variableDeclaration = this.ast.newSingleVariableDeclaration();
+ variableDeclaration.setType(this.ast.newArrayType(this.ast.newSimpleType(this.ast.newSimpleName("String"))));//$NON-NLS-1$
+ variableDeclaration.setName(this.ast.newSimpleName("args"));//$NON-NLS-1$
+ methodDeclaration.parameters().add(variableDeclaration);
+ org.eclipse.jdt.core.dom.Block block = this.ast.newBlock();
+ MethodInvocation methodInvocation = this.ast.newMethodInvocation();
+ name =
+ this.ast.newQualifiedName(
+ this.ast.newSimpleName("System"),//$NON-NLS-1$
+ this.ast.newSimpleName("out"));//$NON-NLS-1$
+ methodInvocation.setExpression(name);
+ methodInvocation.setName(this.ast.newSimpleName("println")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setOperator(InfixExpression.Operator.PLUS);
+ StringLiteral literal = this.ast.newStringLiteral();
+ literal.setLiteralValue("Hello");//$NON-NLS-1$
+ infixExpression.setLeftOperand(literal);
+ literal = this.ast.newStringLiteral();
+ literal.setLiteralValue(" world");//$NON-NLS-1$
+ infixExpression.setRightOperand(literal);//$NON-NLS-1$
+ methodInvocation.arguments().add(infixExpression);
+ ExpressionStatement expressionStatement = this.ast.newExpressionStatement(methodInvocation);
+ block.statements().add(expressionStatement);
+ methodDeclaration.setBody(block);
+ type.bodyDeclarations().add(methodDeclaration);
+ unit.types().add(type);
+ assertTrue("Both AST trees should be identical", result.subtreeMatch(new ASTMatcher(), unit));//$NON-NLS-1$
+ String expected =
+ "package test0001;\n" +
+ "import java.util.*;\n" +
+ "public class Test {\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(\"Hello\" + \" world\");\n" +
+ " }\n" +
+ "}";
+ checkSourceRange(result, expected, source);
+ }
+
+ /**
+ * Test allocation expression: new Object() ==> ClassInstanceCreation
+ */
+ public void test0002() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0002", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = this.ast.newClassInstanceCreation();
+ classInstanceCreation.setType(this.ast.newSimpleType(this.ast.newSimpleName("Object"))); //$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", classInstanceCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "new Object()", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Test allocation expression: new java.lang.Object() ==> ClassInstanceCreation
+ */
+ public void test0003() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0003", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = this.ast.newClassInstanceCreation();
+ QualifiedName name =
+ this.ast.newQualifiedName(
+ this.ast.newQualifiedName(
+ this.ast.newSimpleName("java"), //$NON-NLS-1$
+ this.ast.newSimpleName("lang")), //$NON-NLS-1$
+ this.ast.newSimpleName("Object"));//$NON-NLS-1$
+ classInstanceCreation.setType(this.ast.newSimpleType(name));
+ assertTrue("Both AST trees should be identical", classInstanceCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "new java.lang.Object()", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Test allocation expression: new java.lang.Exception("ERROR") ==> ClassInstanceCreation
+ */
+ public void test0004() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0004", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = this.ast.newClassInstanceCreation();
+ QualifiedName name =
+ this.ast.newQualifiedName(
+ this.ast.newQualifiedName(
+ this.ast.newSimpleName("java"), //$NON-NLS-1$
+ this.ast.newSimpleName("lang")), //$NON-NLS-1$
+ this.ast.newSimpleName("Exception"));//$NON-NLS-1$
+ classInstanceCreation.setType(this.ast.newSimpleType(name));
+ StringLiteral literal = this.ast.newStringLiteral();
+ literal.setLiteralValue("ERROR"); //$NON-NLS-1$
+ classInstanceCreation.arguments().add(literal);
+ assertTrue("Both AST trees should be identical", classInstanceCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "new java.lang.Exception(\"ERROR\")", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Test allocation expression: new java.lang.Object() {} ==> ClassInstanceCreation
+ */
+ public void test0005() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0005", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = this.ast.newClassInstanceCreation();
+ QualifiedName name =
+ this.ast.newQualifiedName(
+ this.ast.newQualifiedName(
+ this.ast.newSimpleName("java"), //$NON-NLS-1$
+ this.ast.newSimpleName("lang")), //$NON-NLS-1$
+ this.ast.newSimpleName("Object"));//$NON-NLS-1$
+ classInstanceCreation.setType(this.ast.newSimpleType(name));
+ AnonymousClassDeclaration anonymousClassDeclaration = this.ast.newAnonymousClassDeclaration();
+ classInstanceCreation.setAnonymousClassDeclaration(anonymousClassDeclaration);
+ assertTrue("Both AST trees should be identical", classInstanceCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "new java.lang.Object() {}", source); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation2 = (ClassInstanceCreation) expression;
+ Type type = classInstanceCreation2.getType();
+ checkSourceRange(type, "java.lang.Object", source); //$NON-NLS-1$
+ }
+
+
+ /**
+ * Test allocation expression: new java.lang.Runnable() { public void run() {}} ==> ClassInstanceCreation
+ */
+ public void test0006() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0006", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = this.ast.newClassInstanceCreation();
+ QualifiedName name =
+ this.ast.newQualifiedName(
+ this.ast.newQualifiedName(
+ this.ast.newSimpleName("java"), //$NON-NLS-1$
+ this.ast.newSimpleName("lang")), //$NON-NLS-1$
+ this.ast.newSimpleName("Runnable"));//$NON-NLS-1$
+ classInstanceCreation.setType(this.ast.newSimpleType(name));
+ MethodDeclaration methodDeclaration = this.ast.newMethodDeclaration();
+ methodDeclaration.setBody(this.ast.newBlock());
+ methodDeclaration.setConstructor(false);
+ methodDeclaration.modifiers().add(this.ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
+ methodDeclaration.setName(this.ast.newSimpleName("run"));//$NON-NLS-1$
+ methodDeclaration.setReturnType2(this.ast.newPrimitiveType(PrimitiveType.VOID));
+ AnonymousClassDeclaration anonymousClassDeclaration = this.ast.newAnonymousClassDeclaration();
+ anonymousClassDeclaration.bodyDeclarations().add(methodDeclaration);
+ classInstanceCreation.setAnonymousClassDeclaration(anonymousClassDeclaration);
+ assertTrue("Both AST trees should be identical", classInstanceCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "new java.lang.Runnable() { public void run() {}}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Test allocation expression: new Test().new D() ==> ClassInstanceCreation
+ */
+ public void test0007() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0007", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ ASTNode expression = (ASTNode) ((MethodInvocation) expressionStatement.getExpression()).arguments().get(0);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = this.ast.newClassInstanceCreation();
+ classInstanceCreation.setType(this.ast.newSimpleType(this.ast.newSimpleName("D"))); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreationExpression = this.ast.newClassInstanceCreation();
+ classInstanceCreationExpression.setType(this.ast.newSimpleType(this.ast.newSimpleName("Test"))); //$NON-NLS-1$
+ classInstanceCreation.setExpression(classInstanceCreationExpression);
+ assertTrue("Both AST trees should be identical", classInstanceCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "new Test().new D()", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Test allocation expression: new int[] {1, 2, 3, 4} ==> ArrayCreation
+ */
+ public void test0008() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0008", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ ArrayCreation arrayCreation = this.ast.newArrayCreation();
+ arrayCreation.setType(this.ast.newArrayType(this.ast.newPrimitiveType(PrimitiveType.INT), 1));
+ ArrayInitializer arrayInitializer = this.ast.newArrayInitializer();
+ arrayInitializer.expressions().add(this.ast.newNumberLiteral("1"));//$NON-NLS-1$
+ arrayInitializer.expressions().add(this.ast.newNumberLiteral("2"));//$NON-NLS-1$
+ arrayInitializer.expressions().add(this.ast.newNumberLiteral("3"));//$NON-NLS-1$
+ arrayInitializer.expressions().add(this.ast.newNumberLiteral("4"));//$NON-NLS-1$
+ arrayCreation.setInitializer(arrayInitializer);
+ assertTrue("Both AST trees should be identical", arrayCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "new int[] {1, 2, 3, 4}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Test allocation expression: new int[][] {{1}, {2}} ==> ArrayCreation
+ */
+ public void test0009() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0009", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ ArrayCreation arrayCreation = this.ast.newArrayCreation();
+ arrayCreation.setType(this.ast.newArrayType(this.ast.newPrimitiveType(PrimitiveType.INT), 2));
+ ArrayInitializer arrayInitializer = this.ast.newArrayInitializer();
+ ArrayInitializer innerArrayInitializer = this.ast.newArrayInitializer();
+ innerArrayInitializer.expressions().add(this.ast.newNumberLiteral("1"));//$NON-NLS-1$
+ arrayInitializer.expressions().add(innerArrayInitializer);
+ innerArrayInitializer = this.ast.newArrayInitializer();
+ innerArrayInitializer.expressions().add(this.ast.newNumberLiteral("2"));//$NON-NLS-1$
+ arrayInitializer.expressions().add(innerArrayInitializer);
+ arrayCreation.setInitializer(arrayInitializer);
+ assertTrue("Both AST trees should be identical", arrayCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "new int[][] {{1}, {2}}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Test allocation expression: new int[3] ==> ArrayCreation
+ */
+ public void test0010() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0010", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ ArrayCreation arrayCreation = this.ast.newArrayCreation();
+ arrayCreation.setType(this.ast.newArrayType(this.ast.newPrimitiveType(PrimitiveType.INT), 1));
+ arrayCreation.dimensions().add(this.ast.newNumberLiteral("3")); //$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", arrayCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "new int[3]", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Test allocation expression: new int[3][] ==> ArrayCreation
+ */
+ public void test0011() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0011", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ ArrayCreation arrayCreation = this.ast.newArrayCreation();
+ arrayCreation.setType(this.ast.newArrayType(this.ast.newPrimitiveType(PrimitiveType.INT), 2));
+ arrayCreation.dimensions().add(this.ast.newNumberLiteral("3")); //$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", arrayCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "new int[3][]", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Test allocation expression: new int[][] {{},{}} ==> ArrayCreation
+ */
+ public void test0012() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0012", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ ArrayCreation arrayCreation = this.ast.newArrayCreation();
+ arrayCreation.setType(this.ast.newArrayType(this.ast.newPrimitiveType(PrimitiveType.INT), 2));
+ ArrayInitializer arrayInitializer = this.ast.newArrayInitializer();
+ ArrayInitializer innerArrayInitializer = this.ast.newArrayInitializer();
+ arrayInitializer.expressions().add(innerArrayInitializer);
+ innerArrayInitializer = this.ast.newArrayInitializer();
+ arrayInitializer.expressions().add(innerArrayInitializer);
+ arrayCreation.setInitializer(arrayInitializer);
+ assertTrue("Both AST trees should be identical", arrayCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "new int[][] {{}, {}}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * int i; ==> VariableDeclarationFragment
+ */
+ public void test0013() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0013", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int i;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * int i = 0; ==> VariableDeclarationFragment
+ */
+ public void test0014() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0014", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(this.ast.newNumberLiteral("0"));//$NON-NLS-1$
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int i = 0;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i = 1; ==> ExpressionStatement(Assignment)
+ */
+ public void test0015() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0015", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Assignment assignment = this.ast.newAssignment();
+ assignment.setLeftHandSide(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ assignment.setRightHandSide(this.ast.newNumberLiteral("1")); //$NON-NLS-1$
+ assignment.setOperator(Assignment.Operator.ASSIGN);
+ ExpressionStatement statement = this.ast.newExpressionStatement(assignment);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i = 1;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i += 2; ==> ExpressionStatement(Assignment)
+ */
+ public void test0016() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0016", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Assignment assignment = this.ast.newAssignment();
+ assignment.setLeftHandSide(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$
+ assignment.setOperator(Assignment.Operator.PLUS_ASSIGN);
+ ExpressionStatement statement = this.ast.newExpressionStatement(assignment);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i += 2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i -= 2; ==> ExpressionStatement(Assignment)
+ */
+ public void test0017() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0017", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Assignment assignment = this.ast.newAssignment();
+ assignment.setLeftHandSide(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$
+ assignment.setOperator(Assignment.Operator.MINUS_ASSIGN);
+ ExpressionStatement statement = this.ast.newExpressionStatement(assignment);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i -= 2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i *= 2; ==> ExpressionStatement(Assignment)
+ */
+ public void test0018() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0018", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Assignment assignment = this.ast.newAssignment();
+ assignment.setLeftHandSide(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$
+ assignment.setOperator(Assignment.Operator.TIMES_ASSIGN);
+ ExpressionStatement statement = this.ast.newExpressionStatement(assignment);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i *= 2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i /= 2; ==> ExpressionStatement(Assignment)
+ */
+ public void test0019() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0019", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Assignment assignment = this.ast.newAssignment();
+ assignment.setLeftHandSide(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$
+ assignment.setOperator(Assignment.Operator.DIVIDE_ASSIGN);
+ ExpressionStatement statement = this.ast.newExpressionStatement(assignment);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i /= 2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i &= 2 ==> ExpressionStatement(Assignment)
+ */
+ public void test0020() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0020", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Assignment assignment = this.ast.newAssignment();
+ assignment.setLeftHandSide(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$
+ assignment.setOperator(Assignment.Operator.BIT_AND_ASSIGN);
+ ExpressionStatement statement = this.ast.newExpressionStatement(assignment);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i &= 2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i |= 2; ==> ExpressionStatement(Assignment)
+ */
+ public void test0021() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0021", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Assignment assignment = this.ast.newAssignment();
+ assignment.setLeftHandSide(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$
+ assignment.setOperator(Assignment.Operator.BIT_OR_ASSIGN);
+ ExpressionStatement statement = this.ast.newExpressionStatement(assignment);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i |= 2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i ^= 2; ==> ExpressionStatement(Assignment)
+ */
+ public void test0022() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0022", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Assignment assignment = this.ast.newAssignment();
+ assignment.setLeftHandSide(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$
+ assignment.setOperator(Assignment.Operator.BIT_XOR_ASSIGN);
+ ExpressionStatement statement = this.ast.newExpressionStatement(assignment);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i ^= 2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i %= 2; ==> ExpressionStatement(Assignment)
+ */
+ public void test0023() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0023", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Assignment assignment = this.ast.newAssignment();
+ assignment.setLeftHandSide(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$
+ assignment.setOperator(Assignment.Operator.REMAINDER_ASSIGN);
+ ExpressionStatement statement = this.ast.newExpressionStatement(assignment);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i %= 2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i <<= 2; ==> ExpressionStatement(Assignment)
+ */
+ public void test0024() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0024", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Assignment assignment = this.ast.newAssignment();
+ assignment.setLeftHandSide(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$
+ assignment.setOperator(Assignment.Operator.LEFT_SHIFT_ASSIGN);
+ ExpressionStatement statement = this.ast.newExpressionStatement(assignment);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i <<= 2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i >>= 2; ==> ExpressionStatement(Assignment)
+ */
+ public void test0025() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0025", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Assignment assignment = this.ast.newAssignment();
+ assignment.setLeftHandSide(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$
+ assignment.setOperator(Assignment.Operator.RIGHT_SHIFT_SIGNED_ASSIGN);
+ ExpressionStatement statement = this.ast.newExpressionStatement(assignment);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i >>= 2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i >>>= 2; ==> ExpressionStatement(Assignment)
+ */
+ public void test0026() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0026", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Assignment assignment = this.ast.newAssignment();
+ assignment.setLeftHandSide(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$
+ assignment.setOperator(Assignment.Operator.RIGHT_SHIFT_UNSIGNED_ASSIGN);
+ ExpressionStatement statement = this.ast.newExpressionStatement(assignment);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i >>>= 2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * --i; ==> ExpressionStatement(PrefixExpression)
+ */
+ public void test0027() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0027", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ PrefixExpression prefixExpression = this.ast.newPrefixExpression();
+ prefixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ prefixExpression.setOperator(PrefixExpression.Operator.DECREMENT);//$NON-NLS-1$
+ ExpressionStatement statement = this.ast.newExpressionStatement(prefixExpression);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "--i;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * --i; ==> ExpressionStatement(PrefixExpression)
+ */
+ public void test0028() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0028", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ PrefixExpression prefixExpression = this.ast.newPrefixExpression();
+ prefixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ prefixExpression.setOperator(PrefixExpression.Operator.INCREMENT);//$NON-NLS-1$
+ ExpressionStatement statement = this.ast.newExpressionStatement(prefixExpression);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "++i;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i--; ==> ExpressionStatement(PostfixExpression)
+ */
+ public void test0029() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0029", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ PostfixExpression postfixExpression = this.ast.newPostfixExpression();
+ postfixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ postfixExpression.setOperator(PostfixExpression.Operator.DECREMENT);//$NON-NLS-1$
+ ExpressionStatement statement = this.ast.newExpressionStatement(postfixExpression);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i--;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i++; ==> ExpressionStatement(PostfixExpression)
+ */
+ public void test0030() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0030", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ PostfixExpression postfixExpression = this.ast.newPostfixExpression();
+ postfixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ postfixExpression.setOperator(PostfixExpression.Operator.INCREMENT);//$NON-NLS-1$
+ ExpressionStatement statement = this.ast.newExpressionStatement(postfixExpression);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i++;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * (String) o; ==> ExpressionStatement(CastExpression)
+ */
+ public void test0031() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0031", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("s")); //$NON-NLS-1$
+ CastExpression castExpression = this.ast.newCastExpression();
+ castExpression.setExpression(this.ast.newSimpleName("o"));//$NON-NLS-1$
+ castExpression.setType(this.ast.newSimpleType(this.ast.newSimpleName("String")));//$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(castExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newSimpleType(this.ast.newSimpleName("String")));//$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "String s = (String) o;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * (int) d; ==> ExpressionStatement(CastExpression)
+ */
+ public void test0032() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0032", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ CastExpression castExpression = this.ast.newCastExpression();
+ castExpression.setExpression(this.ast.newSimpleName("d"));//$NON-NLS-1$
+ castExpression.setType(this.ast.newPrimitiveType(PrimitiveType.INT));//$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(castExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));//$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int i = (int) d;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * (float) d; ==> ExpressionStatement(CastExpression)
+ */
+ public void test0033() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0033", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("f")); //$NON-NLS-1$
+ CastExpression castExpression = this.ast.newCastExpression();
+ castExpression.setExpression(this.ast.newSimpleName("d"));//$NON-NLS-1$
+ castExpression.setType(this.ast.newPrimitiveType(PrimitiveType.FLOAT));//$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(castExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.FLOAT));//$NON-NLS-1$
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "float f = (float) d;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * (byte) d; ==> ExpressionStatement(CastExpression)
+ */
+ public void test0034() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0034", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("b")); //$NON-NLS-1$
+ CastExpression castExpression = this.ast.newCastExpression();
+ castExpression.setExpression(this.ast.newSimpleName("d"));//$NON-NLS-1$
+ castExpression.setType(this.ast.newPrimitiveType(PrimitiveType.BYTE));//$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(castExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.BYTE));//$NON-NLS-1$
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "byte b = (byte) d;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * (short) d; ==> ExpressionStatement(CastExpression)
+ */
+ public void test0035() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0035", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("s")); //$NON-NLS-1$
+ CastExpression castExpression = this.ast.newCastExpression();
+ castExpression.setExpression(this.ast.newSimpleName("d"));//$NON-NLS-1$
+ castExpression.setType(this.ast.newPrimitiveType(PrimitiveType.SHORT));//$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(castExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.SHORT));//$NON-NLS-1$
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "short s = (short) d;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * (long) d; ==> ExpressionStatement(CastExpression)
+ */
+ public void test0036() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0036", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("l")); //$NON-NLS-1$
+ CastExpression castExpression = this.ast.newCastExpression();
+ castExpression.setExpression(this.ast.newSimpleName("d"));//$NON-NLS-1$
+ castExpression.setType(this.ast.newPrimitiveType(PrimitiveType.LONG));//$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(castExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.LONG));//$NON-NLS-1$
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "long l = (long) d;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * (char) i; ==> ExpressionStatement(CastExpression)
+ */
+ public void test0037() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0037", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("c")); //$NON-NLS-1$
+ CastExpression castExpression = this.ast.newCastExpression();
+ castExpression.setExpression(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ castExpression.setType(this.ast.newPrimitiveType(PrimitiveType.CHAR));//$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(castExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.CHAR));//$NON-NLS-1$
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "char c = (char) i;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * int.class; ==> ExpressionStatement(TypeLiteral)
+ */
+ public void test0038() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0038", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("c")); //$NON-NLS-1$
+ TypeLiteral typeLiteral = this.ast.newTypeLiteral();
+ typeLiteral.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+ variableDeclarationFragment.setInitializer(typeLiteral);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newSimpleType(this.ast.newSimpleName("Class")));//$NON-NLS-1$
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(((VariableDeclarationFragment)((VariableDeclarationStatement)node).fragments().get(0)).getInitializer(), "int.class", source); //$NON-NLS-1$
+ }
+
+ /**
+ * void.class; ==> ExpressionStatement(TypeLiteral)
+ */
+ public void test0039() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0039", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("c")); //$NON-NLS-1$
+ TypeLiteral typeLiteral = this.ast.newTypeLiteral();
+ typeLiteral.setType(this.ast.newPrimitiveType(PrimitiveType.VOID));
+ variableDeclarationFragment.setInitializer(typeLiteral);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newSimpleType(this.ast.newSimpleName("Class")));//$NON-NLS-1$
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(((VariableDeclarationFragment)((VariableDeclarationStatement)node).fragments().get(0)).getInitializer(), "void.class", source); //$NON-NLS-1$
+ }
+
+ /**
+ * double.class; ==> ExpressionStatement(TypeLiteral)
+ */
+ public void test0040() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0040", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("c")); //$NON-NLS-1$
+ TypeLiteral typeLiteral = this.ast.newTypeLiteral();
+ typeLiteral.setType(this.ast.newPrimitiveType(PrimitiveType.DOUBLE));
+ variableDeclarationFragment.setInitializer(typeLiteral);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newSimpleType(this.ast.newSimpleName("Class")));//$NON-NLS-1$
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(((VariableDeclarationFragment)((VariableDeclarationStatement)node).fragments().get(0)).getInitializer(), "double.class", source); //$NON-NLS-1$
+ }
+
+ /**
+ * long.class; ==> ExpressionStatement(TypeLiteral)
+ */
+ public void test0041() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0041", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("c")); //$NON-NLS-1$
+ TypeLiteral typeLiteral = this.ast.newTypeLiteral();
+ typeLiteral.setType(this.ast.newPrimitiveType(PrimitiveType.LONG));
+ variableDeclarationFragment.setInitializer(typeLiteral);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newSimpleType(this.ast.newSimpleName("Class")));//$NON-NLS-1$
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(((VariableDeclarationFragment)((VariableDeclarationStatement)node).fragments().get(0)).getInitializer(), "long.class", source); //$NON-NLS-1$
+ }
+
+ /**
+ * false ==> BooleanLiteral
+ */
+ public void test0042() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0042", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ BooleanLiteral literal = this.ast.newBooleanLiteral(false);
+ assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "false", source); //$NON-NLS-1$
+ }
+
+ /**
+ * true ==> BooleanLiteral
+ */
+ public void test0043() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0043", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ BooleanLiteral literal = this.ast.newBooleanLiteral(true);
+ assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "true", source); //$NON-NLS-1$
+ }
+
+ /**
+ * null ==> NullLiteral
+ */
+ public void test0044() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0044", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ NullLiteral literal = this.ast.newNullLiteral();
+ assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "null", source); //$NON-NLS-1$
+ }
+
+ /**
+ * CharLiteral ==> CharacterLiteral
+ */
+ public void test0045() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0045", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ CharacterLiteral literal = this.ast.newCharacterLiteral();
+ literal.setEscapedValue("'c'"); //$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "'c'", source); //$NON-NLS-1$
+ }
+
+ /**
+ * DoubleLiteral ==> NumberLiteral
+ */
+ public void test0046() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0046", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ NumberLiteral literal = this.ast.newNumberLiteral("1.00001");//$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "1.00001", source); //$NON-NLS-1$
+ }
+
+ /**
+ * FloatLiteral ==> NumberLiteral
+ */
+ public void test0047() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0047", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ NumberLiteral literal = this.ast.newNumberLiteral("1.00001f");//$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "1.00001f", source); //$NON-NLS-1$
+ }
+
+ /**
+ * IntLiteral ==> NumberLiteral
+ */
+ public void test0048() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0048", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ NumberLiteral literal = this.ast.newNumberLiteral("30000");//$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "30000", source); //$NON-NLS-1$
+ }
+
+ /**
+ * IntLiteralMinValue ==> NumberLiteral
+ */
+ public void test0049() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0049", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ NumberLiteral literal = this.ast.newNumberLiteral("-2147483648");//$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "-2147483648", source); //$NON-NLS-1$
+ }
+
+ /**
+ * LongLiteral ==> NumberLiteral
+ */
+ public void test0050() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0050", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ NumberLiteral literal = this.ast.newNumberLiteral("2147483648L");//$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "2147483648L", source); //$NON-NLS-1$
+ }
+
+ /**
+ * LongLiteral ==> NumberLiteral (negative value)
+ */
+ public void test0051() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0051", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ NumberLiteral literal = this.ast.newNumberLiteral("2147483648L");//$NON-NLS-1$
+ PrefixExpression prefixExpression = this.ast.newPrefixExpression();
+ prefixExpression.setOperand(literal);
+ prefixExpression.setOperator(PrefixExpression.Operator.MINUS);
+ assertTrue("Both AST trees should be identical", prefixExpression.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "-2147483648L", source); //$NON-NLS-1$
+ }
+
+ /**
+ * LongLiteralMinValue ==> NumberLiteral
+ */
+ public void test0052() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0052", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ NumberLiteral literal = this.ast.newNumberLiteral("-9223372036854775808L");//$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "-9223372036854775808L", source); //$NON-NLS-1$
+ }
+
+ /**
+ * ExtendedStringLiteral ==> StringLiteral
+ */
+ public void test0053() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0053", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ /*
+ StringLiteral literal = this.ast.newStringLiteral();//$NON-NLS-1$
+ literal.setLiteralValue("Hello World");*/
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setOperator(InfixExpression.Operator.PLUS);
+ StringLiteral literal = this.ast.newStringLiteral();
+ literal.setLiteralValue("Hello");//$NON-NLS-1$
+ infixExpression.setLeftOperand(literal);
+ literal = this.ast.newStringLiteral();
+ literal.setLiteralValue(" World");//$NON-NLS-1$
+ infixExpression.setRightOperand(literal);//$NON-NLS-1$
+
+ assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "\"Hello\" + \" World\"", source); //$NON-NLS-1$
+ }
+
+ /**
+ * AND_AND_Expression ==> InfixExpression
+ */
+ public void test0054() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0054", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("b3")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("b")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("b2")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.CONDITIONAL_AND);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "boolean b3 = b && b2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * OR_OR_Expression ==> InfixExpression
+ */
+ public void test0055() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0055", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("b3")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("b")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("b2")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.CONDITIONAL_OR);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "boolean b3 = b || b2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * EqualExpression ==> InfixExpression
+ */
+ public void test0056() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0056", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("b3")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("b")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("b2")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.EQUALS);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "boolean b3 = b == b2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression (+) ==> InfixExpression
+ */
+ public void test0057() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0057", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("n")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("j")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.PLUS);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int n = i + j;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression (-) ==> InfixExpression
+ */
+ public void test0058() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0058", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("n")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("j")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.MINUS);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int n = i - j;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression (*) ==> InfixExpression
+ */
+ public void test0059() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0059", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("n")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("j")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.TIMES);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int n = i * j;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression (/) ==> InfixExpression
+ */
+ public void test0060() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0060", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("n")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("j")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.DIVIDE);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int n = i / j;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression (%) ==> InfixExpression
+ */
+ public void test0061() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0061", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("n")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("j")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.REMAINDER);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int n = i % j;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression (^) ==> InfixExpression
+ */
+ public void test0062() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0062", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("n")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("j")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.XOR);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int n = i ^ j;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression (&) ==> InfixExpression
+ */
+ public void test0063() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0063", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("n")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("j")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.AND);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int n = i & j;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression (|) ==> InfixExpression
+ */
+ public void test0064() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0064", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("n")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("j")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.OR);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int n = i | j;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression (<) ==> InfixExpression
+ */
+ public void test0065() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0065", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("b2")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("b")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("b1")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.LESS);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "boolean b2 = b < b1;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression (<=) ==> InfixExpression
+ */
+ public void test0066() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0066", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("b2")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("b")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("b1")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.LESS_EQUALS);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "boolean b2 = b <= b1;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression (>) ==> InfixExpression
+ */
+ public void test0067() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0067", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("b2")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("b")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("b1")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.GREATER);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "boolean b2 = b > b1;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression (>=) ==> InfixExpression
+ */
+ public void test0068() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0068", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("b2")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("b")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("b1")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.GREATER_EQUALS);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "boolean b2 = b >= b1;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression (!=) ==> InfixExpression
+ */
+ public void test0069() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0069", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("b2")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("b")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("b1")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.NOT_EQUALS);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "boolean b2 = b != b1;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * InstanceofExpression ==> InfixExpression
+ */
+ public void test0070() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0070", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("b")); //$NON-NLS-1$
+ InstanceofExpression instanceOfExpression = this.ast.newInstanceofExpression();
+ instanceOfExpression.setLeftOperand(this.ast.newSimpleName("o"));//$NON-NLS-1$
+ SimpleType simpleType = this.ast.newSimpleType(this.ast.newSimpleName("Integer"));//$NON-NLS-1$
+ instanceOfExpression.setRightOperand(simpleType);
+ variableDeclarationFragment.setInitializer(instanceOfExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "boolean b = o instanceof Integer;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * InstanceofExpression ==> InfixExpression
+ */
+ public void test0071() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0071", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("b")); //$NON-NLS-1$
+ InstanceofExpression instanceOfExpression = this.ast.newInstanceofExpression();
+ instanceOfExpression.setLeftOperand(this.ast.newSimpleName("o")); //$NON-NLS-1$
+ QualifiedName name =
+ this.ast.newQualifiedName(
+ this.ast.newQualifiedName(
+ this.ast.newSimpleName("java"), //$NON-NLS-1$
+ this.ast.newSimpleName("lang")), //$NON-NLS-1$
+ this.ast.newSimpleName("Integer")); //$NON-NLS-1$
+ Type type = this.ast.newSimpleType(name);
+ instanceOfExpression.setRightOperand(type);
+ variableDeclarationFragment.setInitializer(instanceOfExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "boolean b = o instanceof java.lang.Integer;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * UnaryExpression (!) ==> PrefixExpression
+ */
+ public void test0072() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0072", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("b1")); //$NON-NLS-1$
+ PrefixExpression prefixExpression = this.ast.newPrefixExpression();
+ prefixExpression.setOperator(PrefixExpression.Operator.NOT);
+ prefixExpression.setOperand(this.ast.newSimpleName("b"));//$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(prefixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "boolean b1 = !b;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * UnaryExpression (~) ==> PrefixExpression
+ */
+ public void test0073() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0073", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("n")); //$NON-NLS-1$
+ PrefixExpression prefixExpression = this.ast.newPrefixExpression();
+ prefixExpression.setOperator(PrefixExpression.Operator.COMPLEMENT);
+ prefixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(prefixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int n = ~i;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * UnaryExpression (+) ==> PrefixExpression
+ */
+ public void test0074() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0074", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ PrefixExpression prefixExpression = this.ast.newPrefixExpression();
+ prefixExpression.setOperator(PrefixExpression.Operator.PLUS);
+ prefixExpression.setOperand(this.ast.newNumberLiteral("2"));//$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(prefixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int i = +2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * UnaryExpression (-) ==> PrefixExpression
+ */
+ public void test0075() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0075", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ PrefixExpression prefixExpression = this.ast.newPrefixExpression();
+ prefixExpression.setOperator(PrefixExpression.Operator.MINUS);
+ prefixExpression.setOperand(this.ast.newNumberLiteral("2"));//$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(prefixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int i = -2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * ConditionalExpression ==> ConditionalExpression
+ */
+ public void test0076() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0076", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("b")); //$NON-NLS-1$
+ ConditionalExpression conditionalExpression = this.ast.newConditionalExpression();
+ InfixExpression condition = this.ast.newInfixExpression();
+ condition.setLeftOperand(this.ast.newSimpleName("args")); //$NON-NLS-1$
+ condition.setRightOperand(this.ast.newNullLiteral()); //$NON-NLS-1$
+ condition.setOperator(InfixExpression.Operator.NOT_EQUALS);
+ conditionalExpression.setExpression(condition);
+ conditionalExpression.setThenExpression(this.ast.newBooleanLiteral(true));
+ conditionalExpression.setElseExpression(this.ast.newBooleanLiteral(false));
+ variableDeclarationFragment.setInitializer(conditionalExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN));
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "boolean b = args != null ? true : false;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * ConditionalExpression ==> ConditionalExpression
+ */
+ public void test0077() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0077", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ ConditionalExpression conditionalExpression = this.ast.newConditionalExpression();
+ conditionalExpression.setExpression(this.ast.newBooleanLiteral(true));
+ QualifiedName name =
+ this.ast.newQualifiedName(
+ this.ast.newSimpleName("args"), //$NON-NLS-1$
+ this.ast.newSimpleName("length")); //$NON-NLS-1$
+ conditionalExpression.setThenExpression(name);
+ conditionalExpression.setElseExpression(this.ast.newNumberLiteral("0"));//$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(conditionalExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int i = true ? args.length: 0;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * MessageSend ==> SuperMethodInvocation
+ */
+ public void test0078() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0078", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ SuperMethodInvocation superMethodInvocation = this.ast.newSuperMethodInvocation();
+ superMethodInvocation.setName(this.ast.newSimpleName("bar")); //$NON-NLS-1$
+ ExpressionStatement statement = this.ast.newExpressionStatement(superMethodInvocation);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "super.bar();", source); //$NON-NLS-1$
+ }
+
+ /**
+ * MessageSend ==> SuperMethodInvocation
+ */
+ public void test0079() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0079", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ SuperMethodInvocation superMethodInvocation = this.ast.newSuperMethodInvocation();
+ superMethodInvocation.setName(this.ast.newSimpleName("bar")); //$NON-NLS-1$
+ superMethodInvocation.arguments().add(this.ast.newNumberLiteral("4"));//$NON-NLS-1$
+ ExpressionStatement statement = this.ast.newExpressionStatement(superMethodInvocation);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "super.bar(4);", source); //$NON-NLS-1$
+ }
+
+ /**
+ * MessageSend ==> MethodInvocation
+ */
+ public void test0080() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0080", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ MethodInvocation methodInvocation = this.ast.newMethodInvocation();
+ methodInvocation.setName(this.ast.newSimpleName("bar")); //$NON-NLS-1$
+ methodInvocation.arguments().add(this.ast.newNumberLiteral("4"));//$NON-NLS-1$
+ ExpressionStatement statement = this.ast.newExpressionStatement(methodInvocation);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "bar(4);", source); //$NON-NLS-1$
+ }
+
+ /**
+ * MessageSend ==> MethodInvocation
+ */
+ public void test0081() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0081", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ MethodInvocation methodInvocation = this.ast.newMethodInvocation();
+ methodInvocation.setName(this.ast.newSimpleName("bar")); //$NON-NLS-1$
+ methodInvocation.setExpression(this.ast.newThisExpression());
+ methodInvocation.arguments().add(this.ast.newNumberLiteral("4"));//$NON-NLS-1$
+ ExpressionStatement statement = this.ast.newExpressionStatement(methodInvocation);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "this.bar(4);", source); //$NON-NLS-1$
+ }
+
+ /**
+ * ForStatement ==> ForStatement
+ */
+ public void test0082() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0082", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ForStatement forStatement = this.ast.newForStatement();
+ forStatement.setBody(this.ast.newEmptyStatement());
+ assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "for (;;);", source); //$NON-NLS-1$
+ }
+
+ /**
+ * ForStatement ==> ForStatement
+ */
+ public void test0083() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0083", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ForStatement forStatement = this.ast.newForStatement();
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(this.ast.newNumberLiteral("0"));//$NON-NLS-1$
+ VariableDeclarationExpression variableDeclarationExpression = this.ast.newVariableDeclarationExpression(variableDeclarationFragment);
+ variableDeclarationExpression.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+ forStatement.initializers().add(variableDeclarationExpression);
+ PostfixExpression postfixExpression = this.ast.newPostfixExpression();
+ postfixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ postfixExpression.setOperator(PostfixExpression.Operator.INCREMENT);
+ forStatement.updaters().add(postfixExpression);
+ forStatement.setBody(this.ast.newBlock());
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.LESS);
+ infixExpression.setRightOperand(this.ast.newNumberLiteral("10")); //$NON-NLS-1$
+ forStatement.setExpression(infixExpression);
+ assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "for (int i = 0; i < 10; i++) {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * ForStatement ==> ForStatement
+ */
+ public void test0084() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0084", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ForStatement forStatement = this.ast.newForStatement();
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(this.ast.newNumberLiteral("0"));//$NON-NLS-1$
+
+ VariableDeclarationExpression variableDeclarationExpression = this.ast.newVariableDeclarationExpression(variableDeclarationFragment);
+ variableDeclarationExpression.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ forStatement.initializers().add(variableDeclarationExpression);
+ PostfixExpression postfixExpression = this.ast.newPostfixExpression();
+ postfixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ postfixExpression.setOperator(PostfixExpression.Operator.INCREMENT);
+ forStatement.updaters().add(postfixExpression);
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.LESS);
+ infixExpression.setRightOperand(this.ast.newNumberLiteral("10")); //$NON-NLS-1$
+ forStatement.setExpression(infixExpression);
+ forStatement.setBody(this.ast.newEmptyStatement());
+ assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "for (int i = 0; i < 10; i++);", source); //$NON-NLS-1$
+ }
+
+ /**
+ * ForStatement ==> ForStatement
+ */
+ public void test0085() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0085", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ForStatement forStatement = this.ast.newForStatement();
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(this.ast.newNumberLiteral("0"));//$NON-NLS-1$
+
+ VariableDeclarationExpression variableDeclarationExpression = this.ast.newVariableDeclarationExpression(variableDeclarationFragment);
+ variableDeclarationExpression.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ forStatement.initializers().add(variableDeclarationExpression);
+ PostfixExpression postfixExpression = this.ast.newPostfixExpression();
+ postfixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ postfixExpression.setOperator(PostfixExpression.Operator.INCREMENT);
+ forStatement.updaters().add(postfixExpression);
+ forStatement.setBody(this.ast.newEmptyStatement());
+ assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "for (int i = 0;; i++);", source); //$NON-NLS-1$
+ }
+
+ /**
+ * ForStatement ==> ForStatement
+ */
+ public void test0086() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0086", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ForStatement forStatement = this.ast.newForStatement();
+ PostfixExpression postfixExpression = this.ast.newPostfixExpression();
+ postfixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ postfixExpression.setOperator(PostfixExpression.Operator.INCREMENT);
+ forStatement.updaters().add(postfixExpression);
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.LESS);
+ infixExpression.setRightOperand(this.ast.newNumberLiteral("10")); //$NON-NLS-1$
+ forStatement.setExpression(infixExpression);
+ forStatement.setBody(this.ast.newEmptyStatement());
+ assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "for (; i < 10; i++);", source); //$NON-NLS-1$
+ }
+
+ /**
+ * ForStatement ==> ForStatement
+ */
+ public void test0087() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0087", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ForStatement forStatement = this.ast.newForStatement();
+ PostfixExpression postfixExpression = this.ast.newPostfixExpression();
+ postfixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ postfixExpression.setOperator(PostfixExpression.Operator.INCREMENT);
+ forStatement.updaters().add(postfixExpression);
+ forStatement.setBody(this.ast.newEmptyStatement());
+ assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "for (;;i++);", source); //$NON-NLS-1$
+ }
+
+ /**
+ * LocalDeclaration ==> VariableDeclarationStatement
+ */
+ public void test0088() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0088", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int i;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * LocalDeclaration ==> VariableDeclarationStatement
+ */
+ public void test0089() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0089", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("s")); //$NON-NLS-1$
+
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ QualifiedName name =
+ this.ast.newQualifiedName(
+ this.ast.newQualifiedName(
+ this.ast.newSimpleName("java"),//$NON-NLS-1$
+ this.ast.newSimpleName("lang")//$NON-NLS-1$
+ ),
+ this.ast.newSimpleName("String") //$NON-NLS-1$
+ );
+ statement.setType(this.ast.newSimpleType(name));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "java.lang.String s;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * LocalDeclaration ==> VariableDeclarationStatement
+ */
+ public void test0090() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0090", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ ArrayInitializer initializer = this.ast.newArrayInitializer();
+ initializer.expressions().add(this.ast.newNumberLiteral("1"));//$NON-NLS-1$
+ initializer.expressions().add(this.ast.newNumberLiteral("2"));//$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(initializer);
+ variableDeclarationFragment.setName(this.ast.newSimpleName("tab")); //$NON-NLS-1$
+
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newArrayType(this.ast.newPrimitiveType(PrimitiveType.INT), 1));
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int[] tab = {1, 2};", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Argument ==> SingleVariableDeclaration
+ */
+ public void test0091() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0091", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ MethodDeclaration method = (MethodDeclaration)((TypeDeclaration) ((CompilationUnit) result).types().get(0)).bodyDeclarations().get(0);
+ SingleVariableDeclaration node = (SingleVariableDeclaration) method.parameters().get(0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ SingleVariableDeclaration variableDeclaration = this.ast.newSingleVariableDeclaration();
+ variableDeclaration.setType(this.ast.newSimpleType(this.ast.newSimpleName("String")));//$NON-NLS-1$
+ variableDeclaration.setName(this.ast.newSimpleName("s")); //$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", variableDeclaration.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "String s", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Argument ==> SingleVariableDeclaration
+ */
+ public void test0092() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0092", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ MethodDeclaration method = (MethodDeclaration)((TypeDeclaration) ((CompilationUnit) result).types().get(0)).bodyDeclarations().get(0);
+ SingleVariableDeclaration node = (SingleVariableDeclaration) method.parameters().get(0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ SingleVariableDeclaration variableDeclaration = this.ast.newSingleVariableDeclaration();
+ variableDeclaration.modifiers().add(this.ast.newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD));
+ variableDeclaration.setType(this.ast.newSimpleType(this.ast.newSimpleName("String")));//$NON-NLS-1$
+ variableDeclaration.setName(this.ast.newSimpleName("s")); //$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", variableDeclaration.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "final String s", source); //$NON-NLS-1$
+ assertEquals("Wrong dimension", 0, node.getExtraDimensions()); //$NON-NLS-1$
+ }
+
+ /**
+ * Break ==> BreakStatement
+ */
+ public void test0093() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0093", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ ForStatement forStatement = (ForStatement) node;
+ BreakStatement statement = (BreakStatement) ((Block) forStatement.getBody()).statements().get(0);
+ assertNotNull("Expression should not be null", statement); //$NON-NLS-1$
+ BreakStatement breakStatement = this.ast.newBreakStatement();
+ assertTrue("Both AST trees should be identical", breakStatement.subtreeMatch(new ASTMatcher(), statement)); //$NON-NLS-1$
+ checkSourceRange(statement, "break;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Continue ==> ContinueStatement
+ */
+ public void test0094() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0094", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ ForStatement forStatement = (ForStatement) node;
+ ContinueStatement statement = (ContinueStatement) ((Block) forStatement.getBody()).statements().get(0);
+ assertNotNull("Expression should not be null", statement); //$NON-NLS-1$
+ ContinueStatement continueStatement = this.ast.newContinueStatement();
+ assertTrue("Both AST trees should be identical", continueStatement.subtreeMatch(new ASTMatcher(), statement)); //$NON-NLS-1$
+ checkSourceRange(statement, "continue;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Continue with Label ==> ContinueStatement
+ */
+ public void test0095() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0095", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ LabeledStatement labeledStatement = (LabeledStatement) getASTNode((CompilationUnit) result, 0, 0, 0);
+ ForStatement forStatement = (ForStatement) labeledStatement.getBody();
+ ContinueStatement statement = (ContinueStatement) ((Block) forStatement.getBody()).statements().get(0);
+ assertNotNull("Expression should not be null", statement); //$NON-NLS-1$
+ ContinueStatement continueStatement = this.ast.newContinueStatement();
+ continueStatement.setLabel(this.ast.newSimpleName("label")); //$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", continueStatement.subtreeMatch(new ASTMatcher(), statement)); //$NON-NLS-1$
+ checkSourceRange(statement, "continue label;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Break + label ==> BreakStatement
+ */
+ public void test0096() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0096", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ LabeledStatement labeledStatement = (LabeledStatement) getASTNode((CompilationUnit) result, 0, 0, 0);
+ ForStatement forStatement = (ForStatement) labeledStatement.getBody();
+ BreakStatement statement = (BreakStatement) ((Block) forStatement.getBody()).statements().get(0);
+ assertNotNull("Expression should not be null", statement); //$NON-NLS-1$
+ BreakStatement breakStatement = this.ast.newBreakStatement();
+ breakStatement.setLabel(this.ast.newSimpleName("label")); //$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", breakStatement.subtreeMatch(new ASTMatcher(), statement)); //$NON-NLS-1$
+ checkSourceRange(statement, "break label;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * SwitchStatement ==> SwitchStatement
+ */
+ public void test0097() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0097", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ SwitchStatement switchStatement = this.ast.newSwitchStatement();
+ switchStatement.setExpression(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ SwitchCase _case = this.ast.newSwitchCase();
+ _case.setExpression(this.ast.newNumberLiteral("1"));//$NON-NLS-1$
+ switchStatement.statements().add(_case);
+ switchStatement.statements().add(this.ast.newBreakStatement());
+ _case = this.ast.newSwitchCase();
+ _case.setExpression(this.ast.newNumberLiteral("2"));//$NON-NLS-1$
+ switchStatement.statements().add(_case);
+ MethodInvocation methodInvocation = this.ast.newMethodInvocation();
+ QualifiedName name =
+ this.ast.newQualifiedName(
+ this.ast.newSimpleName("System"),//$NON-NLS-1$
+ this.ast.newSimpleName("out"));//$NON-NLS-1$
+ methodInvocation.setExpression(name);
+ methodInvocation.setName(this.ast.newSimpleName("println")); //$NON-NLS-1$
+ methodInvocation.arguments().add(this.ast.newNumberLiteral("2"));//$NON-NLS-1$
+ ExpressionStatement expressionStatement = this.ast.newExpressionStatement(methodInvocation);
+ switchStatement.statements().add(expressionStatement);
+ switchStatement.statements().add(this.ast.newBreakStatement());
+ _case = this.ast.newSwitchCase();
+ _case.setExpression(null);
+ switchStatement.statements().add(_case);
+ methodInvocation = this.ast.newMethodInvocation();
+ name =
+ this.ast.newQualifiedName(
+ this.ast.newSimpleName("System"),//$NON-NLS-1$
+ this.ast.newSimpleName("out"));//$NON-NLS-1$
+ methodInvocation.setExpression(name);
+ methodInvocation.setName(this.ast.newSimpleName("println")); //$NON-NLS-1$
+ StringLiteral literal = this.ast.newStringLiteral();
+ literal.setLiteralValue("default"); //$NON-NLS-1$
+ methodInvocation.arguments().add(literal);
+ expressionStatement = this.ast.newExpressionStatement(methodInvocation);
+ switchStatement.statements().add(expressionStatement);
+ assertTrue("Both AST trees should be identical", switchStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ String expectedSource = "switch(i) {\n" +//$NON-NLS-1$
+ " case 1: \n" +//$NON-NLS-1$
+ " break;\n" +//$NON-NLS-1$
+ " case 2:\n" +//$NON-NLS-1$
+ " System.out.println(2);\n" +//$NON-NLS-1$
+ " break;\n" +//$NON-NLS-1$
+ " default:\n" +//$NON-NLS-1$
+ " System.out.println(\"default\");\n" +//$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(node, expectedSource, source);
+ SwitchStatement switchStatement2 = (SwitchStatement) node;
+ List statements = switchStatement2.statements();
+ assertEquals("wrong size", 7, statements.size()); //$NON-NLS-1$
+ Statement stmt = (Statement) statements.get(5);
+ assertTrue("Not a case statement", stmt instanceof SwitchCase); //$NON-NLS-1$
+ SwitchCase switchCase = (SwitchCase) stmt;
+ assertTrue("Not the default case", switchCase.isDefault()); //$NON-NLS-1$
+ }
+
+ /**
+ * EmptyStatement ==> EmptyStatement
+ */
+ public void test0098() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0098", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ EmptyStatement emptyStatement = this.ast.newEmptyStatement();
+ assertTrue("Both AST trees should be identical", emptyStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, ";", source); //$NON-NLS-1$
+ }
+
+ /**
+ * DoStatement ==> DoStatement
+ */
+ public void test0099() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0099", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ DoStatement doStatement = this.ast.newDoStatement();
+ Block block = this.ast.newBlock();
+ block.statements().add(this.ast.newEmptyStatement());
+ doStatement.setBody(block);
+ doStatement.setExpression(this.ast.newBooleanLiteral(true));
+ assertTrue("Both AST trees should be identical", doStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ String expectedSource = "do {;\n" +//$NON-NLS-1$
+ " } while(true);";//$NON-NLS-1$
+ checkSourceRange(node, expectedSource, source);
+ }
+
+ /**
+ * WhileStatement ==> WhileStatement
+ */
+ public void test0100() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0100", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ WhileStatement whileStatement = this.ast.newWhileStatement();
+ whileStatement.setExpression(this.ast.newBooleanLiteral(true));
+ whileStatement.setBody(this.ast.newEmptyStatement());
+ assertTrue("Both AST trees should be identical", whileStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "while(true);", source);//$NON-NLS-1$
+ }
+
+ /**
+ * WhileStatement ==> WhileStatement
+ */
+ public void test0101() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0101", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ WhileStatement whileStatement = this.ast.newWhileStatement();
+ whileStatement.setExpression(this.ast.newBooleanLiteral(true));
+ whileStatement.setBody(this.ast.newBlock());
+ assertTrue("Both AST trees should be identical", whileStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "while(true) {}", source);//$NON-NLS-1$
+ }
+
+ /**
+ * ExtendedStringLiteral ==> StringLiteral
+ */
+ public void test0102() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0102", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setOperator(InfixExpression.Operator.PLUS);
+ StringLiteral literal = this.ast.newStringLiteral();//$NON-NLS-1$
+ literal.setLiteralValue("Hello"); //$NON-NLS-1$
+ infixExpression.setLeftOperand(literal);
+ literal = this.ast.newStringLiteral();//$NON-NLS-1$
+ literal.setLiteralValue(" World"); //$NON-NLS-1$
+ infixExpression.setRightOperand(literal);
+ literal = this.ast.newStringLiteral();//$NON-NLS-1$
+ literal.setLiteralValue("!"); //$NON-NLS-1$
+ infixExpression.extendedOperands().add(literal);
+ assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "\"Hello\" + \" World\" + \"!\"", source);//$NON-NLS-1$
+ }
+
+ /**
+ * ExtendedStringLiteral ==> StringLiteral
+ */
+ public void test0103() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0103", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setOperator(InfixExpression.Operator.PLUS);
+ StringLiteral literal = this.ast.newStringLiteral();//$NON-NLS-1$
+ literal.setLiteralValue("Hello"); //$NON-NLS-1$
+ infixExpression.setLeftOperand(literal);
+ literal = this.ast.newStringLiteral();//$NON-NLS-1$
+ literal.setLiteralValue(" World"); //$NON-NLS-1$
+ infixExpression.setRightOperand(literal);
+ literal = this.ast.newStringLiteral();//$NON-NLS-1$
+ literal.setLiteralValue("!"); //$NON-NLS-1$
+ infixExpression.extendedOperands().add(literal);
+ literal = this.ast.newStringLiteral();//$NON-NLS-1$
+ literal.setLiteralValue("!"); //$NON-NLS-1$
+ infixExpression.extendedOperands().add(literal);
+ assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "\"Hello\" + \" World\" + \"!\" + \"!\"", source);//$NON-NLS-1$
+ }
+
+ /**
+ * ExtendedStringLiteral ==> StringLiteral
+ */
+ public void test0104() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0104", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setOperator(InfixExpression.Operator.PLUS);
+ StringLiteral literal = this.ast.newStringLiteral();//$NON-NLS-1$
+ literal.setLiteralValue("Hello"); //$NON-NLS-1$
+ infixExpression.setLeftOperand(literal);
+ literal = this.ast.newStringLiteral();//$NON-NLS-1$
+ literal.setLiteralValue(" World"); //$NON-NLS-1$
+ infixExpression.setRightOperand(literal);
+ literal = this.ast.newStringLiteral();//$NON-NLS-1$
+ literal.setLiteralValue("!"); //$NON-NLS-1$
+ infixExpression.extendedOperands().add(literal);
+ NumberLiteral numberLiteral = this.ast.newNumberLiteral();//$NON-NLS-1$
+ numberLiteral.setToken("4"); //$NON-NLS-1$
+ infixExpression.extendedOperands().add(numberLiteral);
+ assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "\"Hello\" + \" World\" + \"!\" + 4", source);//$NON-NLS-1$
+ }
+
+ /**
+ * NumberLiteral ==> InfixExpression
+ */
+ public void test0105() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0105", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setOperator(InfixExpression.Operator.PLUS);
+ NumberLiteral literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("4"); //$NON-NLS-1$
+ infixExpression.setLeftOperand(literal);
+ literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("5"); //$NON-NLS-1$
+ infixExpression.setRightOperand(literal);
+ literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("6"); //$NON-NLS-1$
+ infixExpression.extendedOperands().add(literal);
+ literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("4"); //$NON-NLS-1$
+ infixExpression.extendedOperands().add(literal);
+ assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "4 + 5 + 6 + 4", source);//$NON-NLS-1$
+ }
+
+ /**
+ * NumberLiteral ==> InfixExpression
+ */
+ public void test0106() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0106", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setOperator(InfixExpression.Operator.MINUS);
+ NumberLiteral literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("4"); //$NON-NLS-1$
+ infixExpression.setLeftOperand(literal);
+ literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("5"); //$NON-NLS-1$
+ infixExpression.setRightOperand(literal);
+
+ InfixExpression infixExpression2 = this.ast.newInfixExpression();
+ infixExpression2.setOperator(InfixExpression.Operator.PLUS);
+ infixExpression2.setLeftOperand(infixExpression);
+ literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("6"); //$NON-NLS-1$
+ infixExpression2.setRightOperand(literal);
+
+ InfixExpression infixExpression3 = this.ast.newInfixExpression();
+ infixExpression3.setOperator(InfixExpression.Operator.PLUS);
+ infixExpression3.setLeftOperand(infixExpression2);
+ literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("4"); //$NON-NLS-1$
+ infixExpression3.setRightOperand(literal);
+
+ assertTrue("Both AST trees should be identical", infixExpression3.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "4 - 5 + 6 + 4", source);//$NON-NLS-1$
+ }
+
+ /**
+ * NumberLiteral ==> InfixExpression
+ */
+ public void test0107() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0107", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setOperator(InfixExpression.Operator.MINUS);
+ NumberLiteral literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("4"); //$NON-NLS-1$
+ infixExpression.setLeftOperand(literal);
+ literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("5"); //$NON-NLS-1$
+ infixExpression.setRightOperand(literal);
+ literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("6"); //$NON-NLS-1$
+ infixExpression.extendedOperands().add(literal);
+ literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("4"); //$NON-NLS-1$
+ infixExpression.extendedOperands().add(literal);
+ assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "4 - 5 - 6 - 4", source);//$NON-NLS-1$
+ }
+
+ /**
+ * NumberLiteral ==> InfixExpression
+ */
+ public void test0108() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0108", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setOperator(InfixExpression.Operator.PLUS);
+ StringLiteral stringLiteral = this.ast.newStringLiteral();//$NON-NLS-1$
+ stringLiteral.setLiteralValue("4"); //$NON-NLS-1$
+ infixExpression.setLeftOperand(stringLiteral);
+ NumberLiteral literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("5"); //$NON-NLS-1$
+ infixExpression.setRightOperand(literal);
+ literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("6"); //$NON-NLS-1$
+ infixExpression.extendedOperands().add(literal);
+ literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("4"); //$NON-NLS-1$
+ infixExpression.extendedOperands().add(literal);
+ assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "\"4\" + 5 + 6 + 4", source);//$NON-NLS-1$
+ }
+
+ /**
+ * NumberLiteral ==> InfixExpression
+ */
+ public void test0109() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0109", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setOperator(InfixExpression.Operator.MINUS);
+ StringLiteral stringLiteral = this.ast.newStringLiteral();//$NON-NLS-1$
+ stringLiteral.setLiteralValue("4"); //$NON-NLS-1$
+ infixExpression.setLeftOperand(stringLiteral);
+ NumberLiteral literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("5"); //$NON-NLS-1$
+ infixExpression.setRightOperand(literal);
+
+ InfixExpression infixExpression2 = this.ast.newInfixExpression();
+ infixExpression2.setOperator(InfixExpression.Operator.PLUS);
+ infixExpression2.setLeftOperand(infixExpression);
+ literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("6"); //$NON-NLS-1$
+ infixExpression2.setRightOperand(literal);
+
+ InfixExpression infixExpression3 = this.ast.newInfixExpression();
+ infixExpression3.setOperator(InfixExpression.Operator.PLUS);
+ infixExpression3.setLeftOperand(infixExpression2);
+ literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("4"); //$NON-NLS-1$
+ infixExpression3.setRightOperand(literal);
+
+ assertTrue("Both AST trees should be identical", infixExpression3.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "\"4\" - 5 + 6 + 4", source);//$NON-NLS-1$
+ }
+
+ /**
+ * ReturnStatement ==> ReturnStatement
+ */
+ public void test0110() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0110", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ReturnStatement returnStatement = this.ast.newReturnStatement();
+ NumberLiteral literal = this.ast.newNumberLiteral();
+ literal.setToken("2");//$NON-NLS-1$
+ returnStatement.setExpression(literal);
+ assertTrue("Both AST trees should be identical", returnStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "return 2;", source);//$NON-NLS-1$
+ }
+
+ /**
+ * ReturnStatement ==> ReturnStatement
+ */
+ public void test0111() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0111", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ReturnStatement returnStatement = this.ast.newReturnStatement();
+ NumberLiteral literal = this.ast.newNumberLiteral();
+ literal.setToken("2");//$NON-NLS-1$
+ returnStatement.setExpression(literal);
+ assertTrue("Both AST trees should be identical", returnStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "return 2\\u003B", source);//$NON-NLS-1$
+ }
+
+ /**
+ * SynchronizedStatement ==> SynchronizedStatement
+ */
+ public void test0112() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0112", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ SynchronizedStatement synchronizedStatement = this.ast.newSynchronizedStatement();
+ synchronizedStatement.setExpression(this.ast.newThisExpression());
+ synchronizedStatement.setBody(this.ast.newBlock());
+ assertTrue("Both AST trees should be identical", synchronizedStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ String expectedSource = "synchronized(this) {\n" +//$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(node, expectedSource, source);
+ }
+
+ /**
+ * TryStatement ==> TryStatement
+ */
+ public void test0113() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0113", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ TryStatement tryStatement = this.ast.newTryStatement();
+ tryStatement.setBody(this.ast.newBlock());
+ tryStatement.setFinally(this.ast.newBlock());
+ CatchClause catchBlock = this.ast.newCatchClause();
+ catchBlock.setBody(this.ast.newBlock());
+ SingleVariableDeclaration exceptionVariable = this.ast.newSingleVariableDeclaration();
+ exceptionVariable.setName(this.ast.newSimpleName("e"));//$NON-NLS-1$
+ exceptionVariable.setType(this.ast.newSimpleType(this.ast.newSimpleName("Exception")));//$NON-NLS-1$
+ catchBlock.setException(exceptionVariable);
+ tryStatement.catchClauses().add(catchBlock);
+ assertTrue("Both AST trees should be identical", tryStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ String expectedSource = "try {\n" +//$NON-NLS-1$
+ " } catch(Exception e) {\n" +//$NON-NLS-1$
+ " } finally {\n" +//$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(node, expectedSource, source);
+ }
+
+ /**
+ * TryStatement ==> TryStatement
+ */
+ public void test0114() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0114", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ TryStatement tryStatement = this.ast.newTryStatement();
+ tryStatement.setBody(this.ast.newBlock());
+ CatchClause catchBlock = this.ast.newCatchClause();
+ catchBlock.setBody(this.ast.newBlock());
+ SingleVariableDeclaration exceptionVariable = this.ast.newSingleVariableDeclaration();
+ exceptionVariable.setName(this.ast.newSimpleName("e"));//$NON-NLS-1$
+ exceptionVariable.setType(this.ast.newSimpleType(this.ast.newSimpleName("Exception")));//$NON-NLS-1$
+ catchBlock.setException(exceptionVariable);
+ tryStatement.catchClauses().add(catchBlock);
+ assertTrue("Both AST trees should be identical", tryStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ String expectedSource = "try {\n" +//$NON-NLS-1$
+ " } catch(Exception e) {\n" +//$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(node, expectedSource, source);
+ }
+
+ /**
+ * TryStatement ==> TryStatement
+ */
+ public void test0115() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0115", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ TryStatement tryStatement = this.ast.newTryStatement();
+ Block block = this.ast.newBlock();
+ ReturnStatement returnStatement = this.ast.newReturnStatement();
+ NumberLiteral literal = this.ast.newNumberLiteral();
+ literal.setToken("2");//$NON-NLS-1$
+ returnStatement.setExpression(literal);
+ block.statements().add(returnStatement);
+ tryStatement.setBody(block);
+ CatchClause catchBlock = this.ast.newCatchClause();
+ catchBlock.setBody(this.ast.newBlock());
+ SingleVariableDeclaration exceptionVariable = this.ast.newSingleVariableDeclaration();
+ exceptionVariable.setName(this.ast.newSimpleName("e"));//$NON-NLS-1$
+ exceptionVariable.setType(this.ast.newSimpleType(this.ast.newSimpleName("Exception")));//$NON-NLS-1$
+ catchBlock.setException(exceptionVariable);
+ tryStatement.catchClauses().add(catchBlock);
+ assertTrue("Both AST trees should be identical", tryStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ String expectedSource = "try {\n" +//$NON-NLS-1$
+ " return 2;\n" +//$NON-NLS-1$
+ " } catch(Exception e) {\n" +//$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(node, expectedSource, source);
+ }
+
+ /**
+ * ThrowStatement ==> ThrowStatement
+ */
+ public void test0116() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0116", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ThrowStatement throwStatement = this.ast.newThrowStatement();
+ throwStatement.setExpression(this.ast.newSimpleName("e")); //$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", throwStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "throw e \\u003B", source);//$NON-NLS-1$
+ }
+
+ /**
+ * ThrowStatement ==> ThrowStatement
+ */
+ public void test0117() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0117", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ThrowStatement throwStatement = this.ast.newThrowStatement();
+ throwStatement.setExpression(this.ast.newSimpleName("e")); //$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", throwStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "throw e /* comment in the middle of a throw */ \\u003B", source);//$NON-NLS-1$
+ }
+
+ /**
+ * ThrowStatement ==> ThrowStatement
+ */
+ public void test0118() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0118", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ThrowStatement throwStatement = this.ast.newThrowStatement();
+ throwStatement.setExpression(this.ast.newSimpleName("e")); //$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", throwStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "throw e /* comment in the middle of a throw */ \\u003B", source);//$NON-NLS-1$
+ }
+
+ /**
+ * IfStatement ==> IfStatement
+ */
+ public void test0119() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0119", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ IfStatement ifStatement = this.ast.newIfStatement();
+ ifStatement.setExpression(this.ast.newBooleanLiteral(true));
+ ifStatement.setThenStatement(this.ast.newEmptyStatement());
+ assertTrue("Both AST trees should be identical", ifStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "if (true)\\u003B", source);//$NON-NLS-1$
+ }
+
+ /**
+ * IfStatement ==> IfStatement
+ */
+ public void test0120() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0120", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ IfStatement ifStatement = this.ast.newIfStatement();
+ ifStatement.setExpression(this.ast.newBooleanLiteral(true));
+ ifStatement.setThenStatement(this.ast.newEmptyStatement());
+ ifStatement.setElseStatement(this.ast.newEmptyStatement());
+ assertTrue("Both AST trees should be identical", ifStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ String expectedSource = "if (true)\\u003B\n" +//$NON-NLS-1$
+ "\t\telse ;"; //$NON-NLS-1$
+ checkSourceRange(node, expectedSource, source);
+ }
+
+ /**
+ * IfStatement ==> IfStatement
+ */
+ public void test0121() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0121", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ IfStatement ifStatement = this.ast.newIfStatement();
+ ifStatement.setExpression(this.ast.newBooleanLiteral(true));
+ ifStatement.setThenStatement(this.ast.newBlock());
+ ifStatement.setElseStatement(this.ast.newEmptyStatement());
+ assertTrue("Both AST trees should be identical", ifStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ String expectedSource = "if (true) {}\n" +//$NON-NLS-1$
+ " else ;"; //$NON-NLS-1$
+ checkSourceRange(node, expectedSource, source);
+ }
+
+ /**
+ * IfStatement ==> IfStatement
+ */
+ public void test0122() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0122", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ IfStatement ifStatement = this.ast.newIfStatement();
+ ifStatement.setExpression(this.ast.newBooleanLiteral(true));
+ ReturnStatement returnStatement = this.ast.newReturnStatement();
+ NumberLiteral literal = this.ast.newNumberLiteral();
+ literal.setToken("2");//$NON-NLS-1$
+ returnStatement.setExpression(literal);
+ ifStatement.setThenStatement(returnStatement);
+ assertTrue("Both AST trees should be identical", ifStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "if (true) return 2\\u003B", source);//$NON-NLS-1$
+ }
+
+ /**
+ * IfStatement ==> IfStatement
+ */
+ public void test0123() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0123", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ IfStatement ifStatement = this.ast.newIfStatement();
+ ifStatement.setExpression(this.ast.newBooleanLiteral(true));
+ ReturnStatement returnStatement = this.ast.newReturnStatement();
+ NumberLiteral literal = this.ast.newNumberLiteral();
+ literal.setToken("2");//$NON-NLS-1$
+ returnStatement.setExpression(literal);
+ ifStatement.setThenStatement(returnStatement);
+ returnStatement = this.ast.newReturnStatement();
+ literal = this.ast.newNumberLiteral();
+ literal.setToken("3");//$NON-NLS-1$
+ returnStatement.setExpression(literal);
+ ifStatement.setElseStatement(returnStatement);
+ assertTrue("Both AST trees should be identical", ifStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ String expectedSource = "if (true) return 2;\n" +//$NON-NLS-1$
+ " else return 3;"; //$NON-NLS-1$
+ checkSourceRange(node, expectedSource, source);
+ }
+
+ /**
+ * Multiple local declaration => VariabledeclarationStatement
+ */
+ public void test0124() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0124", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = this.ast.newVariableDeclarationFragment();
+ fragment.setName(this.ast.newSimpleName("x"));//$NON-NLS-1$
+ NumberLiteral literal = this.ast.newNumberLiteral();
+ literal.setToken("10");//$NON-NLS-1$
+ fragment.setInitializer(literal);
+ fragment.setExtraDimensions(0);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(fragment);
+ fragment = this.ast.newVariableDeclarationFragment();
+ fragment.setName(this.ast.newSimpleName("z"));//$NON-NLS-1$
+ fragment.setInitializer(this.ast.newNullLiteral());
+ fragment.setExtraDimensions(1);
+ statement.fragments().add(fragment);
+ fragment = this.ast.newVariableDeclarationFragment();
+ fragment.setName(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ fragment.setExtraDimensions(0);
+ statement.fragments().add(fragment);
+ fragment = this.ast.newVariableDeclarationFragment();
+ fragment.setName(this.ast.newSimpleName("j"));//$NON-NLS-1$
+ fragment.setExtraDimensions(2);
+ statement.fragments().add(fragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ VariableDeclarationFragment[] fragments = (VariableDeclarationFragment[])((VariableDeclarationStatement) node).fragments().toArray(new VariableDeclarationFragment[4]);
+ assertTrue("fragments.length != 4", fragments.length == 4); //$NON-NLS-1$
+ checkSourceRange(fragments[0], "x= 10", source);//$NON-NLS-1$
+ checkSourceRange(fragments[1], "z[] = null", source);//$NON-NLS-1$
+ checkSourceRange(fragments[2], "i", source);//$NON-NLS-1$
+ checkSourceRange(fragments[3], "j[][]", source);//$NON-NLS-1$
+ checkSourceRange(node, "int x= 10, z[] = null, i, j[][];", source);//$NON-NLS-1$
+ }
+
+ /**
+ * Multiple local declaration => VariabledeclarationStatement
+ */
+ public void test0125() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0125", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = this.ast.newVariableDeclarationFragment();
+ fragment.setName(this.ast.newSimpleName("x"));//$NON-NLS-1$
+ NumberLiteral literal = this.ast.newNumberLiteral();
+ literal.setToken("10");//$NON-NLS-1$
+ fragment.setInitializer(literal);
+ fragment.setExtraDimensions(0);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(fragment);
+ fragment = this.ast.newVariableDeclarationFragment();
+ fragment.setName(this.ast.newSimpleName("z"));//$NON-NLS-1$
+ fragment.setInitializer(this.ast.newNullLiteral());
+ fragment.setExtraDimensions(1);
+ statement.fragments().add(fragment);
+ fragment = this.ast.newVariableDeclarationFragment();
+ fragment.setName(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ fragment.setExtraDimensions(0);
+ statement.fragments().add(fragment);
+ fragment = this.ast.newVariableDeclarationFragment();
+ fragment.setName(this.ast.newSimpleName("j"));//$NON-NLS-1$
+ fragment.setExtraDimensions(2);
+ statement.fragments().add(fragment);
+ statement.setType(this.ast.newArrayType(this.ast.newPrimitiveType(PrimitiveType.INT), 1));
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int[] x= 10, z[] = null, i, j[][];", source); //$NON-NLS-1$
+ VariableDeclarationFragment[] fragments = (VariableDeclarationFragment[])((VariableDeclarationStatement) node).fragments().toArray(new VariableDeclarationFragment[4]);
+ assertTrue("fragments.length != 4", fragments.length == 4); //$NON-NLS-1$
+ checkSourceRange(fragments[0], "x= 10", source);//$NON-NLS-1$
+ checkSourceRange(fragments[1], "z[] = null", source);//$NON-NLS-1$
+ checkSourceRange(fragments[2], "i", source);//$NON-NLS-1$
+ checkSourceRange(fragments[3], "j[][]", source);//$NON-NLS-1$
+ }
+
+ /**
+ * ForStatement
+ */
+ public void test0126() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0126", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ForStatement forStatement = this.ast.newForStatement();
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("tab")); //$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(this.ast.newNullLiteral());//$NON-NLS-1$
+ variableDeclarationFragment.setExtraDimensions(1);
+ VariableDeclarationExpression variableDeclarationExpression = this.ast.newVariableDeclarationExpression(variableDeclarationFragment);
+ variableDeclarationExpression.setType(this.ast.newArrayType(this.ast.newSimpleType(this.ast.newSimpleName("String")), 1));//$NON-NLS-1$
+ forStatement.initializers().add(variableDeclarationExpression);
+ PrefixExpression prefixExpression = this.ast.newPrefixExpression();
+ prefixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ prefixExpression.setOperator(PrefixExpression.Operator.INCREMENT);
+ forStatement.updaters().add(prefixExpression);
+ forStatement.setBody(this.ast.newBlock());
+ assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "for (String[] tab[] = null;; ++i) {}", source); //$NON-NLS-1$
+ checkSourceRange((ASTNode) ((ForStatement) node).updaters().get(0), "++i", source); //$NON-NLS-1$
+ checkSourceRange((ASTNode) ((ForStatement) node).initializers().get(0), "String[] tab[] = null", source); //$NON-NLS-1$
+ }
+
+ /**
+ * ForStatement
+ */
+ public void test0127() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0127", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ForStatement forStatement = this.ast.newForStatement();
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("tab")); //$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(this.ast.newNullLiteral());//$NON-NLS-1$
+ variableDeclarationFragment.setExtraDimensions(1);
+ VariableDeclarationExpression variableDeclarationExpression = this.ast.newVariableDeclarationExpression(variableDeclarationFragment);
+ variableDeclarationExpression.setType(this.ast.newSimpleType(this.ast.newSimpleName("String")));//$NON-NLS-1$
+ forStatement.initializers().add(variableDeclarationExpression);
+ PrefixExpression prefixExpression = this.ast.newPrefixExpression();
+ prefixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ prefixExpression.setOperator(PrefixExpression.Operator.INCREMENT);
+ forStatement.updaters().add(prefixExpression);
+ forStatement.setBody(this.ast.newBlock());
+ assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "for (String tab[] = null;; ++i) {}", source); //$NON-NLS-1$
+ checkSourceRange((ASTNode) ((ForStatement) node).updaters().get(0), "++i", source); //$NON-NLS-1$
+ checkSourceRange((ASTNode) ((ForStatement) node).initializers().get(0), "String tab[] = null", source); //$NON-NLS-1$
+ }
+
+ /**
+ * ForStatement
+ */
+ public void test0128() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0128", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ForStatement forStatement = this.ast.newForStatement();
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("tab")); //$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(this.ast.newNullLiteral());//$NON-NLS-1$
+ variableDeclarationFragment.setExtraDimensions(1);
+ VariableDeclarationExpression variableDeclarationExpression = this.ast.newVariableDeclarationExpression(variableDeclarationFragment);
+ variableDeclarationExpression.setType(this.ast.newSimpleType(this.ast.newSimpleName("String")));//$NON-NLS-1$
+ forStatement.initializers().add(variableDeclarationExpression);
+ PostfixExpression postfixExpression = this.ast.newPostfixExpression();
+ postfixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ postfixExpression.setOperator(PostfixExpression.Operator.INCREMENT);
+ forStatement.updaters().add(postfixExpression);
+ forStatement.setBody(this.ast.newBlock());
+ assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "for (String tab[] = null;; i++/**/) {}", source); //$NON-NLS-1$
+ checkSourceRange((ASTNode) ((ForStatement) node).updaters().get(0), "i++", source); //$NON-NLS-1$
+ checkSourceRange((ASTNode) ((ForStatement) node).initializers().get(0), "String tab[] = null", source); //$NON-NLS-1$
+ }
+
+ /**
+ * FieldDeclaration
+ */
+ public void test0129() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0129", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a FieldDeclaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ VariableDeclarationFragment frag = (VariableDeclarationFragment) ((FieldDeclaration) node).fragments().get(0);
+ assertTrue("Not a declaration", frag.getName().isDeclaration()); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = this.ast.newVariableDeclarationFragment();
+ fragment.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ fragment.setExtraDimensions(0);
+ FieldDeclaration fieldDeclaration = this.ast.newFieldDeclaration(fragment);
+ fieldDeclaration.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+ assertTrue("Both AST trees should be identical", fieldDeclaration.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int i;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * FieldDeclaration
+ */
+ public void test0130() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0130", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a FieldDeclaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = this.ast.newVariableDeclarationFragment();
+ fragment.setName(this.ast.newSimpleName("x")); //$NON-NLS-1$
+ NumberLiteral literal = this.ast.newNumberLiteral();
+ literal.setToken("10"); //$NON-NLS-1$
+ fragment.setInitializer(literal);
+ fragment.setExtraDimensions(0);
+ FieldDeclaration fieldDeclaration = this.ast.newFieldDeclaration(fragment);
+ fieldDeclaration.modifiers().add(this.ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD));
+ fieldDeclaration.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+ fragment = this.ast.newVariableDeclarationFragment();
+ fragment.setName(this.ast.newSimpleName("y"));//$NON-NLS-1$
+ fragment.setExtraDimensions(1);
+ fragment.setInitializer(this.ast.newNullLiteral());
+ fieldDeclaration.fragments().add(fragment);
+ fragment = this.ast.newVariableDeclarationFragment();
+ fragment.setName(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ fragment.setExtraDimensions(0);
+ fieldDeclaration.fragments().add(fragment);
+ fragment = this.ast.newVariableDeclarationFragment();
+ fragment.setName(this.ast.newSimpleName("j"));//$NON-NLS-1$
+ fragment.setExtraDimensions(2);
+ fieldDeclaration.fragments().add(fragment);
+ assertTrue("Both AST trees should be identical", fieldDeclaration.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "public int x= 10, y[] = null, i, j[][];", source); //$NON-NLS-1$
+ VariableDeclarationFragment[] fragments = (VariableDeclarationFragment[])((FieldDeclaration) node).fragments().toArray(new VariableDeclarationFragment[4]);
+ assertTrue("fragments.length != 4", fragments.length == 4); //$NON-NLS-1$
+ checkSourceRange(fragments[0], "x= 10", source);//$NON-NLS-1$
+ checkSourceRange(fragments[1], "y[] = null", source);//$NON-NLS-1$
+ checkSourceRange(fragments[2], "i", source);//$NON-NLS-1$
+ checkSourceRange(fragments[3], "j[][]", source);//$NON-NLS-1$
+ }
+
+ /**
+ * Argument with final modifier
+ */
+ public void test0131() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0131", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a MethodDeclaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ assertTrue("Not a declaration", ((MethodDeclaration) node).getName().isDeclaration()); //$NON-NLS-1$
+ List parameters = ((MethodDeclaration) node).parameters();
+ assertTrue("Parameters.length != 1", parameters.size() == 1); //$NON-NLS-1$
+ SingleVariableDeclaration arg = (SingleVariableDeclaration) ((MethodDeclaration) node).parameters().get(0);
+ SingleVariableDeclaration singleVariableDeclaration = this.ast.newSingleVariableDeclaration();
+ singleVariableDeclaration.modifiers().add(this.ast.newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD));
+ singleVariableDeclaration.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ singleVariableDeclaration.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+ assertTrue("Both AST trees should be identical", singleVariableDeclaration.subtreeMatch(new ASTMatcher(), arg)); //$NON-NLS-1$
+ checkSourceRange(node, "void foo(final int i) {}", source); //$NON-NLS-1$
+ checkSourceRange(arg, "final int i", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for MethodDeclaration
+ * @deprecated marking deprecated since using deprecated code
+ */
+ public void test0132() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0132", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a MethodDeclaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((MethodDeclaration) node).getJavadoc();
+ checkSourceRange(node, "/** JavaDoc Comment*/\n void foo(final int i) {}", source); //$NON-NLS-1$
+ checkSourceRange(actualJavadoc, "/** JavaDoc Comment*/", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for MethodDeclaration
+ */
+ public void test0133() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0133", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a MethodDeclaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((MethodDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "void foo(final int i) {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for MethodDeclaration
+ */
+ public void test0134() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0134", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a MethodDeclaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((MethodDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "void foo(final int i) {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for FieldDeclaration
+ * @deprecated marking deprecated since using deprecated code
+ */
+ public void test0135() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0135", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a FieldDeclaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+// Javadoc actualJavadoc = ((FieldDeclaration) node).getJavadoc();
+ checkSourceRange(node, "/** JavaDoc Comment*/\n int i;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for FieldDeclaration
+ */
+ public void test0136() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0136", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a FieldDeclaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((FieldDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "int i;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for FieldDeclaration
+ */
+ public void test0137() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0137", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a FieldDeclaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((FieldDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "int i;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for TypeDeclaration
+ */
+ public void test0138() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0138", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ String expectedContents = "public class Test {\n" +//$NON-NLS-1$
+ " int i;\n" +//$NON-NLS-1$
+ "}";//$NON-NLS-1$
+ checkSourceRange(node, expectedContents, source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for TypeDeclaration
+ */
+ public void test0139() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0139", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ String expectedContents = "public class Test {\n" +//$NON-NLS-1$
+ " int i;\n" +//$NON-NLS-1$
+ "}";//$NON-NLS-1$
+ checkSourceRange(node, expectedContents, source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for TypeDeclaration
+ * @deprecated marking deprecated since using deprecated code
+ */
+ public void test0140() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0140", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ String expectedContents =
+ "/** JavaDoc Comment*/\n" + //$NON-NLS-1$
+ "public class Test {\n" +//$NON-NLS-1$
+ " int i;\n" +//$NON-NLS-1$
+ "}";//$NON-NLS-1$
+ checkSourceRange(node, expectedContents, source); //$NON-NLS-1$
+ checkSourceRange(actualJavadoc, "/** JavaDoc Comment*/", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for MemberTypeDeclaration
+ * @deprecated marking deprecated since using deprecated code
+ */
+ public void test0141() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0141", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ String expectedContents =
+ "/** JavaDoc Comment*/\n" + //$NON-NLS-1$
+ " class B {}";//$NON-NLS-1$
+ checkSourceRange(node, expectedContents, source); //$NON-NLS-1$
+ checkSourceRange(actualJavadoc, "/** JavaDoc Comment*/", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for MemberTypeDeclaration
+ */
+ public void test0142() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0142", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "class B {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for MemberTypeDeclaration
+ */
+ public void test0143() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0143", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "public static class B {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for MemberTypeDeclaration
+ */
+ public void test0144() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0144", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "public static class B {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking initializers
+ */
+ public void test0145() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0145", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ checkSourceRange(node, "{}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking initializers
+ */
+ public void test0146() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0146", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ checkSourceRange(node, "static {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking initializers
+ * @deprecated marking deprecated since using deprecated code
+ */
+ public void test0147() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0147", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((Initializer) node).getJavadoc();
+ assertNotNull("Javadoc comment should no be null", actualJavadoc); //$NON-NLS-1$
+ String expectedContents =
+ "/** JavaDoc Comment*/\n" + //$NON-NLS-1$
+ " static {}";//$NON-NLS-1$
+ checkSourceRange(node, expectedContents, source); //$NON-NLS-1$
+ checkSourceRange(actualJavadoc, "/** JavaDoc Comment*/", source); //$NON-NLS-1$
+
+ }
+
+ /**
+ * Checking initializers
+ * @deprecated marking deprecated since using deprecated code
+ */
+ public void test0148() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0148", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((Initializer) node).getJavadoc();
+ assertNotNull("Javadoc comment should not be null", actualJavadoc); //$NON-NLS-1$
+ String expectedContents =
+ "/** JavaDoc Comment*/\n" + //$NON-NLS-1$
+ " {}";//$NON-NLS-1$
+ checkSourceRange(node, expectedContents, source); //$NON-NLS-1$
+ checkSourceRange(actualJavadoc, "/** JavaDoc Comment*/", source); //$NON-NLS-1$
+
+ }
+
+ /**
+ * Checking initializers
+ */
+ public void test0149() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0149", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((Initializer) node).getJavadoc();
+ assertNull("Javadoc comment should be null", actualJavadoc); //$NON-NLS-1$
+ checkSourceRange(node, "{}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking syntax error
+ */
+ public void test0150() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0150", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertTrue("The compilation unit is malformed", !isMalformed(unit)); //$NON-NLS-1$
+ assertTrue("The package declaration is not malformed", isMalformed(unit.getPackage())); //$NON-NLS-1$
+ List imports = unit.imports();
+ assertTrue("The imports list size is not one", imports.size() == 1); //$NON-NLS-1$
+ assertTrue("The first import is malformed", !isMalformed((ASTNode) imports.get(0))); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking syntax error
+ */
+ public void test0151() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0151", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The compilation unit is malformed", !isMalformed(result)); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking syntax error
+ */
+ public void test0152() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0152", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The compilation unit is malformed", !isMalformed(result)); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The type is malformed", !isMalformed(node)); //$NON-NLS-1$
+ node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The field is not malformed", isMalformed(node)); //$NON-NLS-1$
+ node = getASTNode((CompilationUnit) result, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The method is not malformed", isMalformed(node)); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking syntax error
+ */
+ public void test0153() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0153", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The compilation unit is malformed", !isMalformed(result)); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The method is not original", isOriginal(node)); //$NON-NLS-1$
+ assertTrue("The method is not malformed", isMalformed(node)); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking binding of package declaration
+ */
+ public void test0154() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0154", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ IBinding binding = compilationUnit.getPackage().getName().resolveBinding();
+ assertNotNull("The package binding is null", binding); //$NON-NLS-1$
+ assertTrue("The binding is not a package binding", binding instanceof IPackageBinding); //$NON-NLS-1$
+ IPackageBinding packageBinding = (IPackageBinding) binding;
+ assertEquals("The package name is incorrect", "test0154", packageBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding2 = compilationUnit.getPackage().getName().resolveBinding();
+ assertTrue("The package binding is not canonical", binding == binding2); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking arguments positions
+ */
+ public void test0155() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0155", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("The result is not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDecl = (MethodDeclaration) node;
+ List parameters = methodDecl.parameters();
+ assertTrue("The parameters size is different from 2", parameters.size() == 2); //$NON-NLS-1$
+ Object parameter = parameters.get(0);
+ assertTrue("The parameter is not a SingleVariableDeclaration", parameter instanceof SingleVariableDeclaration); //$NON-NLS-1$
+ checkSourceRange((ASTNode) parameter, "int i", source); //$NON-NLS-1$
+ parameter = parameters.get(1);
+ assertTrue("The parameter is not a SingleVariableDeclaration", parameter instanceof SingleVariableDeclaration); //$NON-NLS-1$
+ checkSourceRange((ASTNode) parameter, "final boolean b", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking arguments positions
+ */
+ public void test0156() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0156", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("The result is not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDecl = (MethodDeclaration) node;
+ List parameters = methodDecl.parameters();
+ assertTrue("The parameters size is different from 1", parameters.size() == 1); //$NON-NLS-1$
+ Object parameter = parameters.get(0);
+ assertTrue("The parameter is not a SingleVariableDeclaration", parameter instanceof SingleVariableDeclaration); //$NON-NLS-1$
+ checkSourceRange((ASTNode) parameter, "int i", source); //$NON-NLS-1$
+ Block block = methodDecl.getBody();
+ List statements = block.statements();
+ assertTrue("The statements size is different from 2", statements.size() == 2); //$NON-NLS-1$
+ ASTNode statement = (ASTNode) statements.get(0);
+ assertTrue("The statements[0] is a postfixExpression statement", statement instanceof ExpressionStatement); //$NON-NLS-1$
+ }
+
+ /**
+ * Check canonic binding for fields
+ */
+ public void test0157() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "", "Test0157.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ List types = compilationUnit.types();
+ assertTrue("The types list is empty", types.size() != 0); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) types.get(0);
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("Type binding is null", typeBinding); //$NON-NLS-1$
+ assertTrue("The type binding is canonical", typeBinding == typeDeclaration.resolveBinding()); //$NON-NLS-1$
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertTrue("The body declaration list is empty", bodyDeclarations.size() != 0); //$NON-NLS-1$
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue("This is not a field", bodyDeclaration instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) bodyDeclaration;
+ List variableFragments = fieldDeclaration.fragments();
+ assertTrue("The fragment list is empty", variableFragments.size() != 0); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) variableFragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNotNull("the field binding is null", variableBinding); //$NON-NLS-1$
+ assertFalse("Not a parameter", variableBinding.isParameter());
+ assertTrue("The field binding is not canonical", variableBinding == fragment.resolveBinding()); //$NON-NLS-1$
+ typeBinding = variableBinding.getType();
+ assertTrue("The type is not an array type", typeBinding.isArray()); //$NON-NLS-1$
+ assertTrue("The type binding for the field is not canonical", typeBinding == variableBinding.getType()); //$NON-NLS-1$
+ SimpleName name = fragment.getName();
+ assertTrue("is a declaration", name.isDeclaration()); //$NON-NLS-1$
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("wrong type", IBinding.VARIABLE, binding.getKind()); //$NON-NLS-1$
+ assertTrue("not a field", ((IVariableBinding) binding).isField()); //$NON-NLS-1$
+ }
+
+ /**
+ * Check canonic bindings for fields
+ */
+ public void test0158() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "", "Test0158.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ List types = compilationUnit.types();
+ assertTrue("The types list is empty", types.size() != 0); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) types.get(0);
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("Type binding is null", typeBinding); //$NON-NLS-1$
+ assertTrue("The type binding is canonical", typeBinding == typeDeclaration.resolveBinding()); //$NON-NLS-1$
+ SimpleName simpleName = typeDeclaration.getName();
+ assertTrue("is a declaration", simpleName.isDeclaration()); //$NON-NLS-1$
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("wrong type", IBinding.TYPE, binding.getKind()); //$NON-NLS-1$
+ assertEquals("wrong name", simpleName.getIdentifier(), binding.getName()); //$NON-NLS-1$
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertTrue("The body declaration list is empty", bodyDeclarations.size() != 0); //$NON-NLS-1$
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue("This is not a field", bodyDeclaration instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) bodyDeclaration;
+ List variableFragments = fieldDeclaration.fragments();
+ assertTrue("The fragment list is empty", variableFragments.size() != 0); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) variableFragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNotNull("the field binding is null", variableBinding); //$NON-NLS-1$
+ assertTrue("The field binding is not canonical", variableBinding == fragment.resolveBinding()); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = variableBinding.getType();
+ assertTrue("The type is not an array type", typeBinding2.isArray()); //$NON-NLS-1$
+ assertTrue("The type binding for the field is not canonical", typeBinding2 == variableBinding.getType()); //$NON-NLS-1$
+ assertTrue("The type binding for the field is not canonical with the declaration type binding", typeBinding == typeBinding2.getElementType()); //$NON-NLS-1$
+ }
+
+ /**
+ * Define an anonymous type
+ */
+ public void test0159() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0159", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ }
+
+ /**
+ * Check bindings for multiple field declarations
+ */
+ public void test0160() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0160", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ List types = compilationUnit.types();
+ assertTrue("The types list is empty", types.size() != 0); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) types.get(0);
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("Type binding is null", typeBinding); //$NON-NLS-1$
+ assertTrue("The type binding is canonical", typeBinding == typeDeclaration.resolveBinding()); //$NON-NLS-1$
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertTrue("The body declaration list is empty", bodyDeclarations.size() != 0); //$NON-NLS-1$
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue("This is not a field", bodyDeclaration instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) bodyDeclaration;
+ List variableFragments = fieldDeclaration.fragments();
+ assertTrue("The fragment list size is not 2", variableFragments.size() == 2); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) variableFragments.get(0);
+ IVariableBinding variableBinding1 = fragment.resolveBinding();
+ assertNotNull("the field binding is null", variableBinding1); //$NON-NLS-1$
+ assertTrue("The field binding is not canonical", variableBinding1 == fragment.resolveBinding()); //$NON-NLS-1$
+ ITypeBinding type1 = variableBinding1.getType();
+ assertNotNull("The type is null", type1); //$NON-NLS-1$
+ assertTrue("The field type is canonical", type1 == variableBinding1.getType()); //$NON-NLS-1$
+ assertTrue("The type is not an array type",type1.isArray()); //$NON-NLS-1$
+ assertTrue("The type dimension is 1", type1.getDimensions() == 1); //$NON-NLS-1$
+ fragment = (VariableDeclarationFragment) variableFragments.get(1);
+ IVariableBinding variableBinding2 = fragment.resolveBinding();
+ assertNotNull("the field binding is null", variableBinding2); //$NON-NLS-1$
+ assertTrue("The field binding is not canonical", variableBinding2 == fragment.resolveBinding()); //$NON-NLS-1$
+ ITypeBinding type2 = variableBinding2.getType();
+ type2 = variableBinding2.getType();
+ assertNotNull("The type is null", type2); //$NON-NLS-1$
+ assertTrue("The field type is canonical", type2 == variableBinding2.getType()); //$NON-NLS-1$
+ assertTrue("The type is not an array type",type2.isArray()); //$NON-NLS-1$
+ assertTrue("The type dimension is 2", type2.getDimensions() == 2); //$NON-NLS-1$
+ assertTrue("Element type is canonical", type1.getElementType() == type2.getElementType()); //$NON-NLS-1$
+ assertTrue("type1.id < type2.id", variableBinding1.getVariableId() < variableBinding2.getVariableId()); //$NON-NLS-1$
+
+ }
+
+ /**
+ * Check ITypeBinding APIs:
+ * - getModifiers()
+ * - getElementType() when it is not an array type
+ * - getDimensions() when it is not an array type
+ * - getDeclaringClass()
+ * - getDeclaringName()
+ * - getName()
+ * - isNested()
+ * - isAnonymous()
+ * - isLocal()
+ * - isMember()
+ * - isArray()
+ * - getDeclaredMethods() => returns binding for default constructor
+ * - isPrimitive()
+ * - isTopLevel()
+ * - getSuperclass()
+ */
+ public void test0161() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0161", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ List types = compilationUnit.types();
+ assertTrue("The types list is empty", types.size() != 0); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) types.get(0);
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("The type binding should not be null", typeBinding); //$NON-NLS-1$
+ assertEquals("The modifier is PUBLIC", Modifier.PUBLIC, typeBinding.getModifiers()); //$NON-NLS-1$
+ assertNull("There is no element type", typeBinding.getElementType()); //$NON-NLS-1$
+ assertEquals("There is no dimension", 0, typeBinding.getDimensions()); //$NON-NLS-1$
+ assertNull("This is not a member type", typeBinding.getDeclaringClass()); //$NON-NLS-1$
+ IMethodBinding[] methods = typeBinding.getDeclaredMethods();
+ assertEquals("Contains the default constructor", 1, methods.length); //$NON-NLS-1$
+ assertEquals("The name is not Test", "Test", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("An anonymous class", !typeBinding.isAnonymous()); //$NON-NLS-1$
+ assertTrue("A local class", !typeBinding.isLocal()); //$NON-NLS-1$
+ assertTrue("A nested class", !typeBinding.isNested()); //$NON-NLS-1$
+ assertTrue("A member class", !typeBinding.isMember()); //$NON-NLS-1$
+ assertTrue("An array", !typeBinding.isArray()); //$NON-NLS-1$
+ assertTrue("Not a class", typeBinding.isClass()); //$NON-NLS-1$
+ assertTrue("An interface", !typeBinding.isInterface()); //$NON-NLS-1$
+ assertTrue("Not from source", typeBinding.isFromSource()); //$NON-NLS-1$
+ assertTrue("Is nested", typeBinding.isTopLevel()); //$NON-NLS-1$
+ assertTrue("A primitive type", !typeBinding.isPrimitive()); //$NON-NLS-1$
+ ITypeBinding superclass = typeBinding.getSuperclass();
+ assertNotNull("No superclass", superclass); //$NON-NLS-1$
+ assertTrue("From source", !superclass.isFromSource()); //$NON-NLS-1$
+ ITypeBinding supersuperclass = superclass.getSuperclass();
+ assertNull("No superclass for java.lang.Object", supersuperclass); //$NON-NLS-1$
+ ITypeBinding[] interfaces = typeBinding.getInterfaces();
+ assertNotNull("No interfaces", interfaces); //$NON-NLS-1$
+ assertEquals("More then one super interface", 1, interfaces.length); //$NON-NLS-1$
+ assertTrue("is not an interface", interfaces[0].isInterface()); //$NON-NLS-1$
+ assertTrue("From source", !interfaces[0].isFromSource()); //$NON-NLS-1$
+ assertEquals("Has fields", 0, typeBinding.getDeclaredFields().length); //$NON-NLS-1$
+ }
+
+ /**
+ * Check ITypeBinding APIs:
+ * - getModifiers()
+ * - getElementType() when it is not an array type
+ * - getDimensions() when it is not an array type
+ * - getDeclaringClass()
+ * - getDeclaringName()
+ * - getName()
+ * - isNested()
+ * - isAnonymous()
+ * - isLocal()
+ * - isMember()
+ * - isArray()
+ * - getDeclaredMethods() => returns binding for default constructor
+ * - isPrimitive()
+ * - isTopLevel()
+ * - getSuperclass()
+ */
+ public void test0162() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0162", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ List types = compilationUnit.types();
+ assertTrue("The types list is empty", types.size() != 0); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) types.get(0);
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("The type binding should not be null", typeBinding); //$NON-NLS-1$
+ assertEquals("The modifier is PUBLIC", Modifier.PUBLIC, typeBinding.getModifiers()); //$NON-NLS-1$
+ assertNull("There is no element type", typeBinding.getElementType()); //$NON-NLS-1$
+ assertEquals("There is no dimension", 0, typeBinding.getDimensions()); //$NON-NLS-1$
+ assertNull("This is not a member type", typeBinding.getDeclaringClass()); //$NON-NLS-1$
+ IMethodBinding[] methods = typeBinding.getDeclaredMethods();
+ assertEquals("Contains no methos", 0, methods.length); //$NON-NLS-1$
+ assertEquals("The name is not Test", "Test", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("An anonymous class", !typeBinding.isAnonymous()); //$NON-NLS-1$
+ assertTrue("A local class", !typeBinding.isLocal()); //$NON-NLS-1$
+ assertTrue("A nested class", !typeBinding.isNested()); //$NON-NLS-1$
+ assertTrue("A member class", !typeBinding.isMember()); //$NON-NLS-1$
+ assertTrue("An array", !typeBinding.isArray()); //$NON-NLS-1$
+ assertTrue("A class", !typeBinding.isClass()); //$NON-NLS-1$
+ assertTrue("Not an interface", typeBinding.isInterface()); //$NON-NLS-1$
+ assertTrue("Not from source", typeBinding.isFromSource()); //$NON-NLS-1$
+ assertTrue("Is nested", typeBinding.isTopLevel()); //$NON-NLS-1$
+ assertTrue("A primitive type", !typeBinding.isPrimitive()); //$NON-NLS-1$
+ ITypeBinding superclass = typeBinding.getSuperclass();
+ assertNull("No superclass", superclass); //$NON-NLS-1$
+ assertEquals("Has fields", 0, typeBinding.getDeclaredFields().length); //$NON-NLS-1$
+ }
+
+ /**
+ * Test binding for anonymous declaration: new java.lang.Object() {}
+ */
+ public void test0163() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0163", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ assertTrue("Not an anonymous type declaration", expression instanceof ClassInstanceCreation); //$NON-NLS-1$
+ ClassInstanceCreation anonymousClass = (ClassInstanceCreation) expression;
+ ITypeBinding typeBinding = anonymousClass.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertTrue("Not an anonymous class", typeBinding.isAnonymous()); //$NON-NLS-1$
+ assertEquals("The modifier is not default", Modifier.NONE, typeBinding.getModifiers()); //$NON-NLS-1$
+ assertNull("There is no element type", typeBinding.getElementType()); //$NON-NLS-1$
+ assertEquals("There is no dimension", 0, typeBinding.getDimensions()); //$NON-NLS-1$
+ assertNotNull("This is a member type", typeBinding.getDeclaringClass()); //$NON-NLS-1$
+ assertEquals("The name is not empty", "", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IMethodBinding[] methods = typeBinding.getDeclaredMethods();
+ assertEquals("Contains the default constructor", 1, methods.length); //$NON-NLS-1$
+ assertTrue("Not a local class", typeBinding.isLocal()); //$NON-NLS-1$
+ assertTrue("Not a nested class", typeBinding.isNested()); //$NON-NLS-1$
+ assertTrue("A member class", !typeBinding.isMember()); //$NON-NLS-1$
+ assertTrue("An array", !typeBinding.isArray()); //$NON-NLS-1$
+ assertTrue("Not a class", typeBinding.isClass()); //$NON-NLS-1$
+ assertTrue("An interface", !typeBinding.isInterface()); //$NON-NLS-1$
+ assertTrue("Not from source", typeBinding.isFromSource()); //$NON-NLS-1$
+ assertTrue("Is a top level", !typeBinding.isTopLevel()); //$NON-NLS-1$
+ assertTrue("A primitive type", !typeBinding.isPrimitive()); //$NON-NLS-1$
+ assertEquals("wrong qualified name", "", typeBinding.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ITypeBinding superclass = typeBinding.getSuperclass();
+ assertNotNull("No superclass", superclass); //$NON-NLS-1$
+ assertEquals("Has fields", 0, typeBinding.getDeclaredFields().length); //$NON-NLS-1$
+ }
+
+ /**
+ * Test binding for member type declaration
+ */
+ public void test0164() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0164", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("Not an type declaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertTrue("An anonymous class", !typeBinding.isAnonymous()); //$NON-NLS-1$
+ assertEquals("The modifier is not default", Modifier.PRIVATE, typeBinding.getModifiers()); //$NON-NLS-1$
+ assertNull("There is no element type", typeBinding.getElementType()); //$NON-NLS-1$
+ assertEquals("There is no dimension", 0, typeBinding.getDimensions()); //$NON-NLS-1$
+ assertNotNull("This is not a member type", typeBinding.getDeclaringClass()); //$NON-NLS-1$
+ assertEquals("The name is not 'B'", "B", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IMethodBinding[] methods = typeBinding.getDeclaredMethods();
+ assertEquals("Contains the default constructor", 1, methods.length); //$NON-NLS-1$
+ assertTrue("A local class", !typeBinding.isLocal()); //$NON-NLS-1$
+ assertTrue("Not a nested class", typeBinding.isNested()); //$NON-NLS-1$
+ assertTrue("Not a member class", typeBinding.isMember()); //$NON-NLS-1$
+ assertTrue("An array", !typeBinding.isArray()); //$NON-NLS-1$
+ assertTrue("Not a class", typeBinding.isClass()); //$NON-NLS-1$
+ assertTrue("An interface", !typeBinding.isInterface()); //$NON-NLS-1$
+ assertTrue("Not from source", typeBinding.isFromSource()); //$NON-NLS-1$
+ assertTrue("Is a top level", !typeBinding.isTopLevel()); //$NON-NLS-1$
+ assertTrue("A primitive type", !typeBinding.isPrimitive()); //$NON-NLS-1$
+ ITypeBinding superclass = typeBinding.getSuperclass();
+ assertNotNull("No superclass", superclass); //$NON-NLS-1$
+ assertEquals("Has fields", 0, typeBinding.getDeclaredFields().length); //$NON-NLS-1$
+ }
+
+ /**
+ * Test binding for local type declaration
+ */
+ public void test0165() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0165", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("Not an type declaration", node instanceof TypeDeclarationStatement); //$NON-NLS-1$
+ TypeDeclarationStatement statement = (TypeDeclarationStatement) node;
+ AbstractTypeDeclaration typeDeclaration = statement.getDeclaration();
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertTrue("An anonymous class", !typeBinding.isAnonymous()); //$NON-NLS-1$
+ assertEquals("The modifier is not default", Modifier.NONE, typeBinding.getModifiers()); //$NON-NLS-1$
+ assertNull("There is no element type", typeBinding.getElementType()); //$NON-NLS-1$
+ assertEquals("There is no dimension", 0, typeBinding.getDimensions()); //$NON-NLS-1$
+ assertNotNull("This is not a member type", typeBinding.getDeclaringClass()); //$NON-NLS-1$
+ assertEquals("The name is not 'C'", "C", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IMethodBinding[] methods = typeBinding.getDeclaredMethods();
+ assertEquals("Contains the default constructor", 1, methods.length); //$NON-NLS-1$
+ assertTrue("Not a local class", typeBinding.isLocal()); //$NON-NLS-1$
+ assertTrue("Not a nested class", typeBinding.isNested()); //$NON-NLS-1$
+ assertTrue("A member class", !typeBinding.isMember()); //$NON-NLS-1$
+ assertTrue("An array", !typeBinding.isArray()); //$NON-NLS-1$
+ assertTrue("Not a class", typeBinding.isClass()); //$NON-NLS-1$
+ assertTrue("An interface", !typeBinding.isInterface()); //$NON-NLS-1$
+ assertTrue("Not from source", typeBinding.isFromSource()); //$NON-NLS-1$
+ assertTrue("Is a top level", !typeBinding.isTopLevel()); //$NON-NLS-1$
+ assertTrue("A primitive type", !typeBinding.isPrimitive()); //$NON-NLS-1$
+ assertEquals("wrong qualified name", "", typeBinding.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ITypeBinding superclass = typeBinding.getSuperclass();
+ assertNotNull("No superclass", superclass); //$NON-NLS-1$
+ assertEquals("Has fields", 0, typeBinding.getDeclaredFields().length); //$NON-NLS-1$
+ }
+
+ /**
+ * Multiple local declaration => VariabledeclarationStatement
+ */
+ public void test0166() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0166", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertTrue("Fragment list is not 4 ", fragments.size() == 4); //$NON-NLS-1$
+ VariableDeclarationFragment fragment1 = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding binding1 = fragment1.resolveBinding();
+ assertNotNull("Binding is null", binding1); //$NON-NLS-1$
+ assertEquals("wrong name for binding1", "x", binding1.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong modifier for binding1", 0, binding1.getModifiers()); //$NON-NLS-1$
+ assertTrue("a field", !binding1.isField()); //$NON-NLS-1$
+ assertNull("declaring class is not null", binding1.getDeclaringClass()); //$NON-NLS-1$
+ ITypeBinding typeBinding1 = binding1.getType();
+ assertNotNull("typeBinding1 is null", typeBinding1); //$NON-NLS-1$
+ assertTrue("typeBinding1 is not a primitive type", typeBinding1.isPrimitive()); //$NON-NLS-1$
+ assertTrue("typeBinding1 is not canonical", typeBinding1 == binding1.getType()); //$NON-NLS-1$
+ VariableDeclarationFragment fragment2 = (VariableDeclarationFragment) fragments.get(1);
+ IVariableBinding binding2 = fragment2.resolveBinding();
+ assertNotNull("Binding is null", binding2); //$NON-NLS-1$
+ assertEquals("wrong name for binding2", "z", binding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong modifier for binding2", 0, binding2.getModifiers()); //$NON-NLS-1$
+ assertTrue("a field", !binding2.isField()); //$NON-NLS-1$
+ assertNull("declaring class is not null", binding2.getDeclaringClass()); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = binding2.getType();
+ assertNotNull("typeBinding2 is null", typeBinding2); //$NON-NLS-1$
+ assertTrue("typeBinding2 is not an array type", typeBinding2.isArray()); //$NON-NLS-1$
+ assertTrue("typeBinding2 is not canonical", typeBinding2 == binding2.getType()); //$NON-NLS-1$
+ assertTrue("primitive type is not canonical", typeBinding1 == typeBinding2.getElementType()); //$NON-NLS-1$
+ assertEquals("dimension is 1", 1, typeBinding2.getDimensions()); //$NON-NLS-1$
+ assertEquals("it is not int[]", "int[]", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ VariableDeclarationFragment fragment3 = (VariableDeclarationFragment) fragments.get(2);
+ IVariableBinding binding3 = fragment3.resolveBinding();
+ assertNotNull("Binding is null", binding3); //$NON-NLS-1$
+ assertEquals("wrong name for binding3", "i", binding3.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong modifier for binding3", 0, binding3.getModifiers()); //$NON-NLS-1$
+ assertTrue("a field", !binding3.isField()); //$NON-NLS-1$
+ assertNull("declaring class is not null", binding3.getDeclaringClass()); //$NON-NLS-1$
+ ITypeBinding typeBinding3 = binding3.getType();
+ assertNotNull("typeBinding3 is null", typeBinding3); //$NON-NLS-1$
+ assertTrue("typeBinding3 is not an primitive type", typeBinding3.isPrimitive()); //$NON-NLS-1$
+ assertTrue("typeBinding3 is not canonical", typeBinding3 == binding3.getType()); //$NON-NLS-1$
+ assertTrue("primitive type is not canonical", typeBinding1 == typeBinding3); //$NON-NLS-1$
+ assertEquals("dimension is 0", 0, typeBinding3.getDimensions()); //$NON-NLS-1$
+ assertEquals("it is not the primitive type int", "int", typeBinding3.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ VariableDeclarationFragment fragment4 = (VariableDeclarationFragment) fragments.get(3);
+ IVariableBinding binding4 = fragment4.resolveBinding();
+ assertNotNull("Binding is null", binding4); //$NON-NLS-1$
+ assertEquals("wrong name for binding4", "j", binding4.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong modifier for binding4", 0, binding4.getModifiers()); //$NON-NLS-1$
+ assertTrue("a field", !binding4.isField()); //$NON-NLS-1$
+ assertNull("declaring class is not null", binding4.getDeclaringClass()); //$NON-NLS-1$
+ ITypeBinding typeBinding4 = binding4.getType();
+ assertNotNull("typeBinding4 is null", typeBinding4); //$NON-NLS-1$
+ assertTrue("typeBinding4 is not an array type", typeBinding4.isArray()); //$NON-NLS-1$
+ assertTrue("typeBinding4 is not canonical", typeBinding4 == binding4.getType()); //$NON-NLS-1$
+ assertTrue("primitive type is not canonical", typeBinding1 == typeBinding4.getElementType()); //$NON-NLS-1$
+ assertEquals("dimension is 2", 2, typeBinding4.getDimensions()); //$NON-NLS-1$
+ assertEquals("it is not int[][]", "int[][]", typeBinding4.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("ids in the wrong order", binding1.getVariableId() < binding2.getVariableId()); //$NON-NLS-1$
+ assertTrue("ids in the wrong order", binding2.getVariableId() < binding3.getVariableId()); //$NON-NLS-1$
+ assertTrue("ids in the wrong order", binding3.getVariableId() < binding4.getVariableId()); //$NON-NLS-1$
+ }
+
+ /**
+ * Check source position for new Test[1+2].length.
+ */
+ public void test0167() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0167", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("Instance of VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertTrue("fragment list size is not 1", fragments.size() == 1); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression initialization = fragment.getInitializer();
+ assertNotNull("No initialization", initialization); //$NON-NLS-1$
+ assertTrue("Not a FieldAccess", initialization instanceof FieldAccess); //$NON-NLS-1$
+ checkSourceRange(initialization, "new Test[1+2].length", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check package binding: test0168.test
+ */
+ public void test0168() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0168.test1", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ List types = compilationUnit.types();
+ assertTrue("The types list is empty", types.size() != 0); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) types.get(0);
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("Binding not null", typeBinding); //$NON-NLS-1$
+ IPackageBinding packageBinding = typeBinding.getPackage();
+ assertNotNull("No package binding", packageBinding); //$NON-NLS-1$
+ assertEquals("wrong name", "test0168.test1", packageBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ String[] components = packageBinding.getNameComponents();
+ assertNotNull("no components", components); //$NON-NLS-1$
+ assertTrue("components size != 2", components.length == 2); //$NON-NLS-1$
+ assertEquals("wrong component name", "test0168", components[0]); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong component name", "test1", components[1]); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong type", IBinding.PACKAGE, packageBinding.getKind()); //$NON-NLS-1$
+ assertTrue("Unnamed package", !packageBinding.isUnnamed()); //$NON-NLS-1$
+ assertTrue("Package binding is not canonical", packageBinding == typeBinding.getPackage()); //$NON-NLS-1$
+ }
+
+ /**
+ * Check package binding: test0169
+ */
+ public void test0169() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0169", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ List types = compilationUnit.types();
+ assertTrue("The types list is empty", types.size() != 0); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) types.get(0);
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("Binding not null", typeBinding); //$NON-NLS-1$
+ IPackageBinding packageBinding = typeBinding.getPackage();
+ assertNotNull("No package binding", packageBinding); //$NON-NLS-1$
+ assertEquals("wrong name", "test0169", packageBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ String[] components = packageBinding.getNameComponents();
+ assertNotNull("no components", components); //$NON-NLS-1$
+ assertTrue("components size != 1", components.length == 1); //$NON-NLS-1$
+ assertEquals("wrong component name", "test0169", components[0]); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong type", IBinding.PACKAGE, packageBinding.getKind()); //$NON-NLS-1$
+ assertTrue("Unnamed package", !packageBinding.isUnnamed()); //$NON-NLS-1$
+ assertTrue("Package binding is not canonical", packageBinding == typeBinding.getPackage()); //$NON-NLS-1$
+ }
+
+ /**
+ * Check package binding: test0170
+ */
+ public void test0170() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "", "Test0170.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ List types = compilationUnit.types();
+ assertTrue("The types list is empty", types.size() != 0); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) types.get(0);
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("Binding not null", typeBinding); //$NON-NLS-1$
+ IPackageBinding packageBinding = typeBinding.getPackage();
+ assertNotNull("No package binding", packageBinding); //$NON-NLS-1$
+ assertEquals("wrong name", "", packageBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ String[] components = packageBinding.getNameComponents();
+ assertNotNull("no components", components); //$NON-NLS-1$
+ assertTrue("components size != 0", components.length == 0); //$NON-NLS-1$
+ assertEquals("wrong type", IBinding.PACKAGE, packageBinding.getKind()); //$NON-NLS-1$
+ assertTrue("Not an unnamed package", packageBinding.isUnnamed()); //$NON-NLS-1$
+ assertTrue("Package binding is not canonical", packageBinding == typeBinding.getPackage()); //$NON-NLS-1$
+ }
+
+ /**
+ * Check package binding: test0171
+ */
+ public void test0171() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0171", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ List types = compilationUnit.types();
+ assertTrue("The types list is empty", types.size() == 2); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) types.get(0);
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("Binding not null", typeBinding); //$NON-NLS-1$
+ IPackageBinding packageBinding = typeBinding.getPackage();
+ assertNotNull("No package binding", packageBinding); //$NON-NLS-1$
+ assertEquals("wrong name", "test0171", packageBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ String[] components = packageBinding.getNameComponents();
+ assertNotNull("no components", components); //$NON-NLS-1$
+ assertTrue("components size != 1", components.length == 1); //$NON-NLS-1$
+ assertEquals("wrong component name", "test0171", components[0]); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong type", IBinding.PACKAGE, packageBinding.getKind()); //$NON-NLS-1$
+ assertTrue("Unnamed package", !packageBinding.isUnnamed()); //$NON-NLS-1$
+ assertTrue("Package binding is not canonical", packageBinding == typeBinding.getPackage()); //$NON-NLS-1$
+
+ typeDeclaration = (TypeDeclaration) types.get(1);
+ typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("Binding not null", typeBinding); //$NON-NLS-1$
+ IPackageBinding packageBinding2 = typeBinding.getPackage();
+ assertNotNull("No package binding", packageBinding); //$NON-NLS-1$
+ assertTrue("Package binding is not canonical", packageBinding == packageBinding2); //$NON-NLS-1$
+ }
+
+ /**
+ * Check method binding
+ */
+ public void test0172() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0172", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ List types = compilationUnit.types();
+ assertTrue("The types list is empty", types.size() != 0); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) types.get(0);
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("Binding not null", typeBinding); //$NON-NLS-1$
+ IMethodBinding[] methods = typeBinding.getDeclaredMethods();
+ assertEquals("methods.length != 4", 4, methods.length); //$NON-NLS-1$
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("body declaration size != 3", 3, bodyDeclarations.size()); //$NON-NLS-1$
+ MethodDeclaration method1 = (MethodDeclaration) bodyDeclarations.get(0);
+ IMethodBinding methodBinding1 = method1.resolveBinding();
+ assertNotNull("No method binding for foo", methodBinding1); //$NON-NLS-1$
+ SimpleName simpleName = method1.getName();
+ assertTrue("not a declaration", simpleName.isDeclaration()); //$NON-NLS-1$
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("wrong name", binding.getName(), simpleName.getIdentifier()); //$NON-NLS-1$
+ // search method foo
+ IMethodBinding methodBinding = null;
+ loop: for (int i = 0, max = methods.length; i < max; i++) {
+ IMethodBinding currentMethod = methods[i];
+ if ("foo".equals(currentMethod.getName())) {
+ methodBinding = currentMethod;
+ break loop;
+ }
+ }
+ assertNotNull("Cannot be null", methodBinding);
+ assertTrue("Canonical method binding", methodBinding1 == methodBinding); //$NON-NLS-1$
+ assertTrue("declaring class is canonical", typeBinding == methodBinding1.getDeclaringClass()); //$NON-NLS-1$
+ ITypeBinding[] exceptionTypes = methodBinding1.getExceptionTypes();
+ assertNotNull("No exception types", exceptionTypes); //$NON-NLS-1$
+ assertEquals("One exception", 1, exceptionTypes.length); //$NON-NLS-1$
+ assertEquals("wrong name for exception", "IOException", exceptionTypes[0].getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong modifier", Modifier.NONE, methodBinding1.getModifiers()); //$NON-NLS-1$
+ assertEquals("wrong name for method", "foo", methodBinding1.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ITypeBinding[] parameters = methodBinding1.getParameterTypes();
+ assertNotNull("No parameters", parameters); //$NON-NLS-1$
+ assertEquals("wrong size", 1, parameters.length); //$NON-NLS-1$
+ assertEquals("wrong type", "int[]", parameters[0].getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong return type", "void", methodBinding1.getReturnType().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("A constructor", !methodBinding1.isConstructor()); //$NON-NLS-1$
+
+ MethodDeclaration method2 = (MethodDeclaration) bodyDeclarations.get(1);
+ IMethodBinding methodBinding2 = method2.resolveBinding();
+ assertNotNull("No method binding for main", methodBinding2); //$NON-NLS-1$
+ // search main
+ methodBinding = null;
+ loop: for (int i = 0, max = methods.length; i < max; i++) {
+ IMethodBinding currentMethod = methods[i];
+ if ("main".equals(currentMethod.getName())) {
+ methodBinding = currentMethod;
+ break loop;
+ }
+ }
+ assertNotNull("Cannot be null", methodBinding);
+ assertTrue("Canonical method binding", methodBinding2 == methodBinding); //$NON-NLS-1$
+ assertTrue("declaring class is canonical", typeBinding == methodBinding2.getDeclaringClass()); //$NON-NLS-1$
+ ITypeBinding[] exceptionTypes2 = methodBinding2.getExceptionTypes();
+ assertNotNull("No exception types", exceptionTypes2); //$NON-NLS-1$
+ assertEquals("No exception", 0, exceptionTypes2.length); //$NON-NLS-1$
+ assertEquals("wrong modifier", Modifier.PUBLIC | Modifier.STATIC, methodBinding2.getModifiers()); //$NON-NLS-1$
+ assertEquals("wrong name for method", "main", methodBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ITypeBinding[] parameters2 = methodBinding2.getParameterTypes();
+ assertNotNull("No parameters", parameters2); //$NON-NLS-1$
+ assertEquals("wrong size", 1, parameters2.length); //$NON-NLS-1$
+ assertEquals("wrong type for parameter2[0]", "String[]", parameters2[0].getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong return type", "void", methodBinding2.getReturnType().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("A constructor", !methodBinding2.isConstructor()); //$NON-NLS-1$
+
+ MethodDeclaration method3 = (MethodDeclaration) bodyDeclarations.get(2);
+ IMethodBinding methodBinding3 = method3.resolveBinding();
+ assertNotNull("No method binding for bar", methodBinding3); //$NON-NLS-1$
+ // search method bar
+ methodBinding = null;
+ loop: for (int i = 0, max = methods.length; i < max; i++) {
+ IMethodBinding currentMethod = methods[i];
+ if ("bar".equals(currentMethod.getName())) {
+ methodBinding = currentMethod;
+ break loop;
+ }
+ }
+ assertNotNull("Cannot be null", methodBinding);
+ assertTrue("Canonical method binding", methodBinding3 == methodBinding); //$NON-NLS-1$
+ assertTrue("declaring class is canonical", typeBinding == methodBinding3.getDeclaringClass()); //$NON-NLS-1$
+ ITypeBinding[] exceptionTypes3 = methodBinding3.getExceptionTypes();
+ assertNotNull("No exception types", exceptionTypes3); //$NON-NLS-1$
+ assertEquals("No exception", 1, exceptionTypes3.length); //$NON-NLS-1$
+ assertEquals("wrong modifier", Modifier.PRIVATE, methodBinding3.getModifiers()); //$NON-NLS-1$
+ assertEquals("wrong name for method", "bar", methodBinding3.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ITypeBinding[] parameters3 = methodBinding3.getParameterTypes();
+ assertNotNull("No parameters", parameters3); //$NON-NLS-1$
+ assertEquals("wrong size", 1, parameters3.length); //$NON-NLS-1$
+ assertEquals("wrong type", "String", parameters3[0].getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong return type", "String", methodBinding3.getReturnType().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("A constructor", !methodBinding3.isConstructor()); //$NON-NLS-1$
+ assertTrue("The binding is not canonical", parameters3[0] == methodBinding3.getReturnType()); //$NON-NLS-1$
+ }
+
+ /**
+ * i++; IVariableBinding
+ */
+ public void test0173() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0173", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("Not an expressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression ex = expressionStatement.getExpression();
+ assertTrue("Not a postfixexpression", ex instanceof PostfixExpression); //$NON-NLS-1$
+ PostfixExpression postfixExpression = (PostfixExpression) ex;
+ Expression expr = postfixExpression.getOperand();
+ assertTrue("Not a simpleName", expr instanceof SimpleName); //$NON-NLS-1$
+ SimpleName name = (SimpleName) expr;
+ assertTrue("a declaration", !name.isDeclaration()); //$NON-NLS-1$
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("VariableDeclarationStatement", node2 instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node2;
+ List fragments = variableDeclarationStatement.fragments();
+ assertTrue("No fragment", fragments.size() == 1); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertTrue(variableBinding == binding);
+ }
+
+ /**
+ * i++; IVariableBinding (field)
+ */
+ public void test0174() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0174", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 1, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("Not an expressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression ex = expressionStatement.getExpression();
+ assertTrue("Not a postfixexpression", ex instanceof PostfixExpression); //$NON-NLS-1$
+ PostfixExpression postfixExpression = (PostfixExpression) ex;
+ Expression expr = postfixExpression.getOperand();
+ assertTrue("Not a simpleName", expr instanceof SimpleName); //$NON-NLS-1$
+ SimpleName name = (SimpleName) expr;
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("FieldDeclaration", node2 instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node2;
+ List fragments = fieldDeclaration.fragments();
+ assertTrue("No fragment", fragments.size() == 1); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertTrue(variableBinding == binding);
+ }
+
+ /**
+ * int i = 0; Test IntBinding for the field declaration and the 0 literal
+ */
+ public void test0175() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0175", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("VariableDeclarationStatement", node2 instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node2;
+ List fragments = fieldDeclaration.fragments();
+ assertTrue("No fragment", fragments.size() == 1); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ ITypeBinding typeBinding = fragment.getInitializer().resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertTrue("Not a primitive type", typeBinding.isPrimitive()); //$NON-NLS-1$
+ assertEquals("Not int", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue(variableBinding.getType() == typeBinding);
+ }
+
+ /**
+ * ThisReference
+ */
+ public void test0176() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0176", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 1, 0);
+ assertTrue("Return statement", node2 instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node2;
+ assertTrue("Not a field access", returnStatement.getExpression() instanceof FieldAccess); //$NON-NLS-1$
+ FieldAccess fieldAccess = (FieldAccess) returnStatement.getExpression();
+ ITypeBinding typeBinding = fieldAccess.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertTrue("Not a primitive type", typeBinding.isPrimitive()); //$NON-NLS-1$
+ assertEquals("Not int", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Expression expr = fieldAccess.getExpression();
+ assertTrue("Not a this expression", expr instanceof ThisExpression); //$NON-NLS-1$
+ ThisExpression thisExpression = (ThisExpression) expr;
+ ITypeBinding typeBinding2 = thisExpression.resolveTypeBinding();
+ assertNotNull("No type binding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("Not Test", "Test", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * i++; IVariableBinding
+ */
+ public void test0177() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0177", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 1, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("Not an expressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression ex = expressionStatement.getExpression();
+ assertTrue("Not a postfixexpression", ex instanceof PostfixExpression); //$NON-NLS-1$
+ PostfixExpression postfixExpression = (PostfixExpression) ex;
+ Expression expr = postfixExpression.getOperand();
+ assertTrue("Not a simpleName", expr instanceof SimpleName); //$NON-NLS-1$
+ SimpleName name = (SimpleName) expr;
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 1, 0);
+ assertTrue("VariableDeclarationStatement", node2 instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node2;
+ List fragments = variableDeclarationStatement.fragments();
+ assertTrue("No fragment", fragments.size() == 1); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertEquals("return type is not int", "int", variableBinding.getType().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue(variableBinding == binding);
+ }
+
+ /**
+ * SuperReference
+ */
+ public void test0178() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0178", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 1, 0, 0);
+ assertTrue("Return statement", node2 instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node2;
+ Expression expr = returnStatement.getExpression();
+ assertTrue("Not a field access", expr instanceof SuperFieldAccess); //$NON-NLS-1$
+ SuperFieldAccess fieldAccess = (SuperFieldAccess) expr;
+ ITypeBinding typeBinding = fieldAccess.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertTrue("Not a primitive type", typeBinding.isPrimitive()); //$NON-NLS-1$
+ assertEquals("Not int", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Allocation expression
+ */
+ public void test0179() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0179", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("VariableDeclarationStatement", node2 instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node2;
+ List fragments = variableDeclarationStatement.fragments();
+ assertTrue("No fragment", fragments.size() == 1); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ Expression initialization = fragment.getInitializer();
+ ITypeBinding typeBinding = initialization.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertTrue(variableBinding.getType() == typeBinding);
+ }
+
+ /**
+ * Allocation expression
+ */
+ public void test0180() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0180", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("VariableDeclarationStatement", node2 instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node2;
+ List fragments = variableDeclarationStatement.fragments();
+ assertTrue("No fragment", fragments.size() == 1); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ Expression initialization = fragment.getInitializer();
+ assertTrue("No an array creation", initialization instanceof ArrayCreation); //$NON-NLS-1$
+ ITypeBinding typeBinding = initialization.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertTrue("Not an array", typeBinding.isArray()); //$NON-NLS-1$
+ assertTrue(variableBinding.getType() == typeBinding);
+ }
+
+ /**
+ * Allocation expression
+ */
+ public void test0181() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0181", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("VariableDeclarationStatement", node2 instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node2;
+ List fragments = variableDeclarationStatement.fragments();
+ assertTrue("No fragment", fragments.size() == 1); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ Expression initialization = fragment.getInitializer();
+ ITypeBinding typeBinding = initialization.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertTrue("Not an array", typeBinding.isArray()); //$NON-NLS-1$
+ assertTrue(variableBinding.getType() == typeBinding);
+ }
+
+ /**
+ * BinaryExpression
+ */
+ public void test0182() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0182", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertTrue("IfStatement", node2 instanceof IfStatement); //$NON-NLS-1$
+ IfStatement ifStatement = (IfStatement) node2;
+ Expression expr = ifStatement.getExpression();
+ assertNotNull("No condition", expr); //$NON-NLS-1$
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not a boolean", "boolean", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(expr, "i < 10", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression
+ */
+ public void test0183() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0183", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertTrue("IfStatement", node2 instanceof IfStatement); //$NON-NLS-1$
+ IfStatement ifStatement = (IfStatement) node2;
+ Expression expr = ifStatement.getExpression();
+ assertNotNull("No condition", expr); //$NON-NLS-1$
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not a boolean", "boolean", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(expr, "i < 10 && i < 20", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression
+ */
+ public void test0184() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0184", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertTrue("IfStatement", node2 instanceof IfStatement); //$NON-NLS-1$
+ IfStatement ifStatement = (IfStatement) node2;
+ Expression expr = ifStatement.getExpression();
+ assertNotNull("No condition", expr); //$NON-NLS-1$
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not a boolean", "boolean", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(expr, "i < 10 || i < 20", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression
+ */
+ public void test0185() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0185", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertTrue("IfStatement", node2 instanceof IfStatement); //$NON-NLS-1$
+ IfStatement ifStatement = (IfStatement) node2;
+ Expression expr = ifStatement.getExpression();
+ assertNotNull("No condition", expr); //$NON-NLS-1$
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not a boolean", "boolean", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(expr, "i == 10", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression
+ */
+ public void test0186() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0186", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertTrue("IfStatement", node2 instanceof IfStatement); //$NON-NLS-1$
+ IfStatement ifStatement = (IfStatement) node2;
+ Expression expr = ifStatement.getExpression();
+ assertNotNull("No condition", expr); //$NON-NLS-1$
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not a boolean", "boolean", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(expr, "o == o", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression
+ */
+ public void test0187() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0187", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertTrue("IfStatement", node2 instanceof WhileStatement); //$NON-NLS-1$
+ WhileStatement whileStatement = (WhileStatement) node2;
+ Expression expr = whileStatement.getExpression();
+ assertNotNull("No condition", expr); //$NON-NLS-1$
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not a boolean", "boolean", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(expr, "i <= 10", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression
+ */
+ public void test0188() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0188", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertTrue("DoStatement", node2 instanceof DoStatement); //$NON-NLS-1$
+ DoStatement statement = (DoStatement) node2;
+ Expression expr = statement.getExpression();
+ assertNotNull("No condition", expr); //$NON-NLS-1$
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not a boolean", "boolean", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(expr, "i <= 10", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression
+ */
+ public void test0189() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0189", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("ForStatement", node2 instanceof ForStatement); //$NON-NLS-1$
+ ForStatement statement = (ForStatement) node2;
+ Expression expr = statement.getExpression();
+ assertNotNull("No condition", expr); //$NON-NLS-1$
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not a boolean", "boolean", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(expr, "i < 10", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression
+ */
+ public void test0190() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0190", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 2, 1);
+ assertTrue("IfStatement", node2 instanceof IfStatement); //$NON-NLS-1$
+ IfStatement statement = (IfStatement) node2;
+ Expression expr = statement.getExpression();
+ assertNotNull("No condition", expr); //$NON-NLS-1$
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not a boolean", "boolean", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(expr, "scanner.x < selection.start && selection.start < scanner.y", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression
+ */
+ public void test0191() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0191", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertTrue("ExpressionStatement", node2 instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node2;
+ Expression ex = expressionStatement.getExpression();
+ assertTrue("Assignment", ex instanceof Assignment); //$NON-NLS-1$
+ Assignment statement = (Assignment) ex;
+ Expression rightExpr = statement.getRightHandSide();
+ assertTrue("Not an infix expression", rightExpr instanceof InfixExpression); //$NON-NLS-1$
+ InfixExpression infixExpression = (InfixExpression) rightExpr;
+ Expression expr = infixExpression.getRightOperand();
+ assertNotNull("No right hand side expression", expr); //$NON-NLS-1$
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not a boolean", "boolean", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(expr, "2 < 20", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Initializer
+ */
+ public void test0192() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0192", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("VariableDeclarationStatement", node2 instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node2;
+ List fragments = variableDeclarationStatement.fragments();
+ assertTrue("No fragment", fragments.size() == 1); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ Expression initialization = fragment.getInitializer();
+ ITypeBinding typeBinding = initialization.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertTrue(variableBinding.getType() == typeBinding);
+ checkSourceRange(initialization, "0", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Initializer
+ */
+ public void test0193() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0193", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 1, 0);
+ assertTrue("VariableDeclarationStatement", node2 instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node2;
+ List fragments = variableDeclarationStatement.fragments();
+ assertTrue("No fragment", fragments.size() == 1); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ Expression initialization = fragment.getInitializer();
+ ITypeBinding typeBinding = initialization.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertTrue(variableBinding.getType() == typeBinding);
+ checkSourceRange(initialization, "new Inner()", source); //$NON-NLS-1$
+ assertEquals("Wrong type", "Inner", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Initializer
+ */
+ public void test0194() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0194", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 1, 0);
+ assertTrue("VariableDeclarationStatement", node2 instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node2;
+ List fragments = variableDeclarationStatement.fragments();
+ assertTrue("No fragment", fragments.size() == 1); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ Expression initialization = fragment.getInitializer();
+ ITypeBinding typeBinding = initialization.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertTrue(variableBinding.getType() == typeBinding);
+ checkSourceRange(initialization, "new Inner[10]", source); //$NON-NLS-1$
+ assertTrue("Not an array", typeBinding.isArray()); //$NON-NLS-1$
+ assertEquals("Wrong type", "Inner[]", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Initializer
+ */
+ public void test0195() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0195", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 1, 0, 1);
+ assertTrue("ExpressionStatement", node2 instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node2;
+ Expression ex = expressionStatement.getExpression();
+ assertTrue("MethodInvocation", ex instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) ex;
+ checkSourceRange(methodInvocation, "a.useFile(/*]*/a.getFile()/*[*/)", source); //$NON-NLS-1$
+ List list = methodInvocation.arguments();
+ assertTrue("Parameter list not empty", list.size() == 1); //$NON-NLS-1$
+ Expression parameter = (Expression) list.get(0);
+ assertTrue("Not a method invocation", parameter instanceof MethodInvocation); //$NON-NLS-1$
+ ITypeBinding typeBinding = parameter.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not a boolean", "File", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(parameter, "a.getFile()", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Initializer
+ */
+ public void test0196() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0196", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 1, 2);
+ assertTrue("ExpressionStatement", node2 instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node2;
+ Expression ex = expressionStatement.getExpression();
+ assertTrue("Assignment", ex instanceof Assignment); //$NON-NLS-1$
+ Assignment statement = (Assignment) ex;
+ Expression rightExpr = statement.getRightHandSide();
+ assertTrue("Not an instanceof expression", rightExpr instanceof InstanceofExpression); //$NON-NLS-1$
+ ITypeBinding typeBinding = rightExpr.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("wrong type", "boolean", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(rightExpr, "inner instanceof Inner", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Initializer
+ */
+ public void test0197() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0197", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType());
+ CompilationUnit unit = (CompilationUnit) result;
+ assertProblemsSize(unit, 0);
+ ASTNode node2 = getASTNode(unit, 1, 0, 1);
+ assertTrue("ExpressionStatement", node2 instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node2;
+ Expression ex = expressionStatement.getExpression();
+ assertTrue("MethodInvocation", ex instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) ex;
+ checkSourceRange(methodInvocation, "a.getFile()/*[*/.getName()", source); //$NON-NLS-1$
+ Expression receiver = methodInvocation.getExpression();
+ assertTrue("Not a method invocation", receiver instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation2 = (MethodInvocation) receiver;
+ ITypeBinding typeBinding = methodInvocation2.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "File", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(methodInvocation2, "a.getFile()", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Initializer
+ */
+ public void test0198() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0198", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("ReturnStatement", node2 instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node2;
+ Expression expr = returnStatement.getExpression();
+ assertTrue("Not an infixExpression", expr instanceof InfixExpression); //$NON-NLS-1$
+ InfixExpression infixExpression = (InfixExpression) expr;
+ Expression left = infixExpression.getLeftOperand();
+ assertTrue("Not an InfixExpression", left instanceof InfixExpression); //$NON-NLS-1$
+ InfixExpression infixExpression2 = (InfixExpression) left;
+ Expression right = infixExpression2.getRightOperand();
+ assertTrue("Not an InfixExpression", right instanceof InfixExpression); //$NON-NLS-1$
+ InfixExpression infixExpression3 = (InfixExpression) right;
+ assertEquals("A multiplication", InfixExpression.Operator.TIMES, infixExpression3.getOperator()); //$NON-NLS-1$
+ ITypeBinding typeBinding = infixExpression3.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not int", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(infixExpression3, "20 * 30", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Initializer
+ */
+ public void test0199() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0199", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("VariableDeclarationStatement", node2 instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node2;
+ List fragments = variableDeclarationStatement.fragments();
+ assertTrue("No fragment", fragments.size() == 1); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression initialization = fragment.getInitializer();
+ assertTrue("Not an infixExpression", initialization instanceof InfixExpression); //$NON-NLS-1$
+ InfixExpression infixExpression = (InfixExpression) initialization;
+ Expression left = infixExpression.getLeftOperand();
+ assertTrue("Not an InfixExpression", left instanceof InfixExpression); //$NON-NLS-1$
+ InfixExpression infixExpression2 = (InfixExpression) left;
+ Expression right = infixExpression2.getRightOperand();
+ assertTrue("Not an InfixExpression", right instanceof InfixExpression); //$NON-NLS-1$
+ InfixExpression infixExpression3 = (InfixExpression) right;
+ assertEquals("A multiplication", InfixExpression.Operator.TIMES, infixExpression3.getOperator()); //$NON-NLS-1$
+ ITypeBinding typeBinding = infixExpression3.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not int", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(infixExpression3, "10 * 30", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Initializer
+ */
+ public void test0200() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0200", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 1, 0, 0);
+ assertTrue("VariableDeclarationStatement", node2 instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node2;
+ List fragments = variableDeclarationStatement.fragments();
+ assertTrue("No fragment", fragments.size() == 1); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression initialization = fragment.getInitializer();
+ assertTrue("Not an infixExpression", initialization instanceof FieldAccess); //$NON-NLS-1$
+ FieldAccess fieldAccess = (FieldAccess) initialization;
+ Expression receiver = fieldAccess.getExpression();
+ assertTrue("ArrayCreation", receiver instanceof ArrayCreation); //$NON-NLS-1$
+ ArrayCreation arrayCreation = (ArrayCreation) receiver;
+ List dimensions = arrayCreation.dimensions();
+ assertEquals("Wrong dimension", 1, dimensions.size()); //$NON-NLS-1$
+ Expression dim = (Expression) dimensions.get(0);
+ assertTrue("InfixExpression", dim instanceof InfixExpression); //$NON-NLS-1$
+ InfixExpression infixExpression = (InfixExpression) dim;
+ ITypeBinding typeBinding = infixExpression.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not int", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(infixExpression, "1 + 2", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Position inside for statement: PR 3300
+ */
+ public void test0201() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0201", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertTrue("ForStatement", node2 instanceof ForStatement); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node2;
+ List initializers = forStatement.initializers();
+ assertTrue("wrong size", initializers.size() == 1); //$NON-NLS-1$
+ Expression init = (Expression) initializers.get(0);
+ checkSourceRange(init, "int i= 0", source); //$NON-NLS-1$
+ }
+
+ /**
+ * PR 7386
+ */
+ public void test0202() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0202", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("FieldDeclaration", node2 instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node2;
+ checkSourceRange(fieldDeclaration, "int f= (2);", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression initialization = fragment.getInitializer();
+ assertTrue("Not a parenthesized expression", initialization instanceof ParenthesizedExpression); //$NON-NLS-1$
+ checkSourceRange(initialization, "(2)", source); //$NON-NLS-1$
+ ITypeBinding typeBinding = initialization.resolveTypeBinding();
+ assertNotNull("no binding", typeBinding); //$NON-NLS-1$
+ assertEquals("not int", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * PR 7386
+ */
+ public void test0203() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0203", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("FieldDeclaration", node2 instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node2;
+ checkSourceRange(fieldDeclaration, "int f= (2);", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression initialization = fragment.getInitializer();
+ assertTrue("Not a parenthesized expression", initialization instanceof ParenthesizedExpression); //$NON-NLS-1$
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) initialization;
+ checkSourceRange(parenthesizedExpression, "(2)", source); //$NON-NLS-1$
+ Expression expr = parenthesizedExpression.getExpression();
+ checkSourceRange(expr, "2", source); //$NON-NLS-1$
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("no binding", typeBinding); //$NON-NLS-1$
+ assertEquals("not int", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("type binding is canonical", typeBinding == parenthesizedExpression.resolveTypeBinding()); //$NON-NLS-1$
+ }
+
+ /**
+ * PR 7386
+ */
+ public void test0204() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0204", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("FieldDeclaration", node2 instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node2;
+ checkSourceRange(fieldDeclaration, "int f= ((2));", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression initialization = fragment.getInitializer();
+ assertTrue("Not a parenthesized expression", initialization instanceof ParenthesizedExpression); //$NON-NLS-1$
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) initialization;
+ checkSourceRange(parenthesizedExpression, "((2))", source); //$NON-NLS-1$
+ Expression expr = parenthesizedExpression.getExpression();
+ assertTrue("Not a parenthesized expression", expr instanceof ParenthesizedExpression); //$NON-NLS-1$
+ ParenthesizedExpression parenthesizedExpression2 = (ParenthesizedExpression) expr;
+ checkSourceRange(parenthesizedExpression2, "(2)", source); //$NON-NLS-1$
+ expr = parenthesizedExpression2.getExpression();
+ checkSourceRange(expr, "2", source); //$NON-NLS-1$
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("no binding", typeBinding); //$NON-NLS-1$
+ assertEquals("not int", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = parenthesizedExpression.resolveTypeBinding();
+ assertNotNull("no binding", typeBinding); //$NON-NLS-1$
+ assertEquals("not int", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("type binding is canonical", typeBinding == parenthesizedExpression2.resolveTypeBinding()); //$NON-NLS-1$
+ }
+
+
+ /**
+ * Local class end position when trailing comment
+ */
+ public void test0205() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0205", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("TypeDeclarationStatement", node2 instanceof TypeDeclarationStatement); //$NON-NLS-1$
+ TypeDeclarationStatement typeDeclarationStatement = (TypeDeclarationStatement) node2;
+ AbstractTypeDeclaration typeDeclaration = typeDeclarationStatement.getDeclaration();
+ assertEquals("wrong name", "AA", typeDeclaration.getName().getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(typeDeclaration, "class AA extends Test {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * QualifiedName
+ */
+ public void test0206() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0206", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 5, 0);
+ assertTrue("ReturnStatement", node2 instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node2;
+ Expression expr = returnStatement.getExpression();
+ assertTrue("Not a qualifiedName", expr instanceof QualifiedName); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) expr;
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not an int (typeBinding)", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(qualifiedName, "field1.field2.field3.field4.i", source); //$NON-NLS-1$
+ assertTrue("Not a simple name", qualifiedName.getName().isSimpleName()); //$NON-NLS-1$
+ SimpleName simpleName = qualifiedName.getName();
+ assertTrue("a declaration", !simpleName.isDeclaration()); //$NON-NLS-1$
+ checkSourceRange(simpleName, "i", source); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = simpleName.resolveTypeBinding();
+ assertNotNull("No typebinding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("Not an int (typeBinding2)", "int", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("VariableBinding", binding instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Not Test", "Test", variableBinding.getDeclaringClass().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Not default", Modifier.PUBLIC, variableBinding.getModifiers()); //$NON-NLS-1$
+ Name qualifierName = qualifiedName.getQualifier();
+ assertTrue("Not a qualified name", qualifierName.isQualifiedName()); //$NON-NLS-1$
+ checkSourceRange(qualifierName, "field1.field2.field3.field4", source); //$NON-NLS-1$
+ ITypeBinding typeBinding5 = qualifierName.resolveTypeBinding();
+ assertNotNull("No binding5", typeBinding5); //$NON-NLS-1$
+ assertEquals("Not Test", "Test", typeBinding5.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+
+ qualifiedName = (QualifiedName) qualifierName;
+ simpleName = qualifiedName.getName();
+ checkSourceRange(simpleName, "field4", source); //$NON-NLS-1$
+ ITypeBinding typeBinding6 = simpleName.resolveTypeBinding();
+ assertNotNull("No binding6", typeBinding6); //$NON-NLS-1$
+ assertEquals("Not Test", "Test", typeBinding6.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+
+ qualifierName = qualifiedName.getQualifier();
+ assertTrue("Not a qualified name", qualifierName.isQualifiedName()); //$NON-NLS-1$
+ checkSourceRange(qualifierName, "field1.field2.field3", source); //$NON-NLS-1$
+ ITypeBinding typeBinding7 = qualifierName.resolveTypeBinding();
+ assertNotNull("No binding7", typeBinding7); //$NON-NLS-1$
+ assertEquals("Not Test", "Test", typeBinding7.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+
+ qualifiedName = (QualifiedName) qualifierName;
+ simpleName = qualifiedName.getName();
+ checkSourceRange(simpleName, "field3", source); //$NON-NLS-1$
+ qualifierName = qualifiedName.getQualifier();
+ assertTrue("Not a qualified name", qualifierName.isQualifiedName()); //$NON-NLS-1$
+ checkSourceRange(qualifierName, "field1.field2", source); //$NON-NLS-1$
+ ITypeBinding typeBinding3 = qualifierName.resolveTypeBinding();
+ assertNotNull("No binding3", typeBinding3); //$NON-NLS-1$
+ assertEquals("Not Test", "Test", typeBinding3.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ qualifiedName = (QualifiedName) qualifierName;
+ simpleName = qualifiedName.getName();
+ checkSourceRange(simpleName, "field2", source); //$NON-NLS-1$
+ qualifierName = qualifiedName.getQualifier();
+ assertTrue("Not a simple name", qualifierName.isSimpleName()); //$NON-NLS-1$
+ assertTrue("a declaration", !((SimpleName)qualifierName).isDeclaration()); //$NON-NLS-1$
+ checkSourceRange(qualifierName, "field1", source); //$NON-NLS-1$
+ ITypeBinding typeBinding4 = qualifierName.resolveTypeBinding();
+ assertNotNull("No binding4", typeBinding4); //$NON-NLS-1$
+ assertEquals("Not Test", "Test", typeBinding4.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Check javadoc for MethodDeclaration
+ * @deprecated marking deprecated since using deprecated code
+ */
+ public void test0207() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0207", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a MethodDeclaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((MethodDeclaration) node).getJavadoc();
+ checkSourceRange(node, "/** JavaDoc Comment*/\n void foo(final int i) {}", source); //$NON-NLS-1$
+ checkSourceRange(actualJavadoc, "/** JavaDoc Comment*/", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for MethodDeclaration
+ */
+ public void test0208() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0208", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a MethodDeclaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((MethodDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "void foo(final int i) {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for MethodDeclaration
+ */
+ public void test0209() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0209", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a MethodDeclaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((MethodDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "void foo(final int i) {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for FieldDeclaration
+ * @deprecated marking deprecated since using deprecated code
+ */
+ public void test0210() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0210", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a FieldDeclaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+// Javadoc actualJavadoc = ((FieldDeclaration) node).getJavadoc();
+ checkSourceRange(node, "/** JavaDoc Comment*/\n int i;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for FieldDeclaration
+ */
+ public void test0211() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0211", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a FieldDeclaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((FieldDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "int i;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for FieldDeclaration
+ */
+ public void test0212() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0212", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a FieldDeclaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((FieldDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "int i;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for TypeDeclaration
+ */
+ public void test0213() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0213", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ String expectedContents = "public class Test {\n" +//$NON-NLS-1$
+ " int i;\n" +//$NON-NLS-1$
+ "}";//$NON-NLS-1$
+ checkSourceRange(node, expectedContents, source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for TypeDeclaration
+ */
+ public void test0214() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0214", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ String expectedContents = "public class Test {\n" +//$NON-NLS-1$
+ " int i;\n" +//$NON-NLS-1$
+ "}";//$NON-NLS-1$
+ checkSourceRange(node, expectedContents, source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for TypeDeclaration
+ * @deprecated marking deprecated since using deprecated code
+ */
+ public void test0215() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0215", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ String expectedContents =
+ "/** JavaDoc Comment*/\n" + //$NON-NLS-1$
+ "public class Test {\n" +//$NON-NLS-1$
+ " int i;\n" +//$NON-NLS-1$
+ "}";//$NON-NLS-1$
+ checkSourceRange(node, expectedContents, source); //$NON-NLS-1$
+ checkSourceRange(actualJavadoc, "/** JavaDoc Comment*/", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for MemberTypeDeclaration
+ * @deprecated marking deprecated since using deprecated code
+ */
+ public void test0216() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0216", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ String expectedContents =
+ "/** JavaDoc Comment*/\n" + //$NON-NLS-1$
+ " class B {}";//$NON-NLS-1$
+ checkSourceRange(node, expectedContents, source); //$NON-NLS-1$
+ checkSourceRange(actualJavadoc, "/** JavaDoc Comment*/", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for MemberTypeDeclaration
+ */
+ public void test0217() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0217", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "class B {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for MemberTypeDeclaration
+ */
+ public void test0218() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0218", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "public static class B {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for MemberTypeDeclaration
+ */
+ public void test0219() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0219", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "public static class B {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking initializers
+ */
+ public void test0220() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0220", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ checkSourceRange(node, "{}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking initializers
+ */
+ public void test0221() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0221", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ checkSourceRange(node, "static {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking initializers
+ * @deprecated marking deprecated since using deprecated code
+ */
+ public void test0222() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0222", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((Initializer) node).getJavadoc();
+ assertNotNull("Javadoc comment should no be null", actualJavadoc); //$NON-NLS-1$
+ String expectedContents =
+ "/** JavaDoc Comment*/\n" + //$NON-NLS-1$
+ " static {}";//$NON-NLS-1$
+ checkSourceRange(node, expectedContents, source); //$NON-NLS-1$
+ checkSourceRange(actualJavadoc, "/** JavaDoc Comment*/", source); //$NON-NLS-1$
+
+ }
+
+ /**
+ * Checking initializers
+ * @deprecated marking deprecated since using deprecated code
+ */
+ public void test0223() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0223", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((Initializer) node).getJavadoc();
+ assertNotNull("Javadoc comment should not be null", actualJavadoc); //$NON-NLS-1$
+ String expectedContents =
+ "/** JavaDoc Comment*/\n" + //$NON-NLS-1$
+ " {}";//$NON-NLS-1$
+ checkSourceRange(node, expectedContents, source); //$NON-NLS-1$
+ checkSourceRange(actualJavadoc, "/** JavaDoc Comment*/", source); //$NON-NLS-1$
+
+ }
+
+ /**
+ * Checking initializers
+ */
+ public void test0224() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0224", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((Initializer) node).getJavadoc();
+ assertNull("Javadoc comment should be null", actualJavadoc); //$NON-NLS-1$
+ checkSourceRange(node, "{}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Continue ==> ContinueStatement
+ */
+ public void test0225() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0225", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ LabeledStatement labeledStatement = (LabeledStatement) getASTNode((CompilationUnit) result, 0, 0, 0);
+ checkSourceRange(labeledStatement.getLabel(), "label", source); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) labeledStatement.getBody();
+ ContinueStatement statement = (ContinueStatement) ((Block) forStatement.getBody()).statements().get(0);
+ assertNotNull("Expression should not be null", statement); //$NON-NLS-1$
+ ContinueStatement continueStatement = this.ast.newContinueStatement();
+ continueStatement.setLabel(this.ast.newSimpleName("label")); //$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", continueStatement.subtreeMatch(new ASTMatcher(), statement)); //$NON-NLS-1$
+ checkSourceRange(statement, "continue label;", source); //$NON-NLS-1$
+ checkSourceRange(statement.getLabel(), "label", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Break + label ==> BreakStatement
+ */
+ public void test0226() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0226", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ LabeledStatement labeledStatement = (LabeledStatement) getASTNode((CompilationUnit) result, 0, 0, 0);
+ checkSourceRange(labeledStatement.getLabel(), "label", source); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) labeledStatement.getBody();
+ BreakStatement statement = (BreakStatement) ((Block) forStatement.getBody()).statements().get(0);
+ assertNotNull("Expression should not be null", statement); //$NON-NLS-1$
+ BreakStatement breakStatement = this.ast.newBreakStatement();
+ breakStatement.setLabel(this.ast.newSimpleName("label")); //$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", breakStatement.subtreeMatch(new ASTMatcher(), statement)); //$NON-NLS-1$
+ checkSourceRange(statement, "break label;", source); //$NON-NLS-1$
+ checkSourceRange(statement.getLabel(), "label", source); //$NON-NLS-1$
+ }
+
+ /**
+ * QualifiedName
+ */
+ public void test0227() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0227", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 3, 2, 0);
+ assertTrue("ReturnStatement", node2 instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node2;
+ Expression expr = returnStatement.getExpression();
+ assertTrue("Not a qualifiedName", expr instanceof QualifiedName); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) expr;
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not an long (typeBinding)", "long", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(qualifiedName, "field.fB.fA.j", source); //$NON-NLS-1$
+
+ SimpleName simpleName = qualifiedName.getName();
+ checkSourceRange(simpleName, "j", source); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = simpleName.resolveTypeBinding();
+ assertEquals("Not an long (typeBinding2)", "long", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("VariableBinding", binding instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Not A", "A", variableBinding.getDeclaringClass().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Not default", Modifier.NONE, variableBinding.getModifiers()); //$NON-NLS-1$
+ assertEquals("wrong name", "j", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+
+ Name qualifierName = qualifiedName.getQualifier();
+ assertTrue("Not a qualified name", qualifierName.isQualifiedName()); //$NON-NLS-1$
+ checkSourceRange(qualifierName, "field.fB.fA", source); //$NON-NLS-1$
+ qualifiedName = (QualifiedName) qualifierName;
+ ITypeBinding typeBinding3 = qualifiedName.resolveTypeBinding();
+ assertNotNull("No type binding3", typeBinding3); //$NON-NLS-1$
+ assertEquals("Not an A", "A", typeBinding3.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ simpleName = qualifiedName.getName();
+ checkSourceRange(simpleName, "fA", source); //$NON-NLS-1$
+ ITypeBinding typeBinding4 = simpleName.resolveTypeBinding();
+ assertNotNull("No typeBinding4", typeBinding4); //$NON-NLS-1$
+ assertEquals("Not an A", "A", typeBinding4.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding2 = qualifiedName.resolveBinding();
+ assertNotNull("No binding2", binding2); //$NON-NLS-1$
+ assertTrue("VariableBinding", binding2 instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding2 = (IVariableBinding) binding2;
+ assertEquals("Not B", "B", variableBinding2.getDeclaringClass().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Not default", Modifier.NONE, variableBinding2.getModifiers()); //$NON-NLS-1$
+ assertEquals("wrong name", "fA", variableBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+
+ qualifierName = qualifiedName.getQualifier();
+ assertTrue("Not a qualified name", qualifierName.isQualifiedName()); //$NON-NLS-1$
+ checkSourceRange(qualifierName, "field.fB", source); //$NON-NLS-1$
+ qualifiedName = (QualifiedName) qualifierName;
+ ITypeBinding typeBinding5 = qualifiedName.resolveTypeBinding();
+ assertNotNull("No typeBinding5", typeBinding5); //$NON-NLS-1$
+ assertEquals("Not a B", "B", typeBinding5.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ simpleName = qualifiedName.getName();
+ checkSourceRange(simpleName, "fB", source); //$NON-NLS-1$
+ ITypeBinding typeBinding6 = simpleName.resolveTypeBinding();
+ assertNotNull("No typebinding6", typeBinding6); //$NON-NLS-1$
+ assertEquals("not a B", "B", typeBinding6.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding3 = qualifiedName.resolveBinding();
+ assertNotNull("No binding2", binding3); //$NON-NLS-1$
+ assertTrue("VariableBinding", binding3 instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding3 = (IVariableBinding) binding3;
+ assertEquals("Not C", "C", variableBinding3.getDeclaringClass().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Not default", Modifier.NONE, variableBinding3.getModifiers()); //$NON-NLS-1$
+ assertEquals("wrong name", "fB", variableBinding3.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+
+ qualifierName = qualifiedName.getQualifier();
+ assertTrue("Not a simple name", qualifierName.isSimpleName()); //$NON-NLS-1$
+ checkSourceRange(qualifierName, "field", source); //$NON-NLS-1$
+ simpleName = (SimpleName) qualifierName;
+ ITypeBinding typeBinding7 = simpleName.resolveTypeBinding();
+ assertNotNull("No typeBinding7", typeBinding7); //$NON-NLS-1$
+ assertEquals("Not a C", "C", typeBinding7.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding4 = simpleName.resolveBinding();
+ assertNotNull("No binding4", binding4); //$NON-NLS-1$
+ assertTrue("VariableBinding", binding4 instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding4 = (IVariableBinding) binding4;
+ assertEquals("Not Test", "Test", variableBinding4.getDeclaringClass().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Not public", Modifier.PUBLIC, variableBinding4.getModifiers()); //$NON-NLS-1$
+ assertEquals("wrong name", "field", variableBinding4.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong return type", "C", variableBinding4.getType().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * QualifiedName as TypeReference
+ */
+ public void test0228() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0228", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 1, 0);
+ assertTrue("ReturnStatement", node2 instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node2;
+ Expression expr = returnStatement.getExpression();
+ checkSourceRange(expr, "test0228.Test.foo()", source); //$NON-NLS-1$
+ assertTrue("MethodInvocation", expr instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expr;
+ Expression qualifier = methodInvocation.getExpression();
+ assertNotNull("no qualifier", qualifier); //$NON-NLS-1$
+ assertTrue("QualifiedName", qualifier instanceof QualifiedName); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) qualifier;
+ checkSourceRange(qualifiedName, "test0228.Test", source); //$NON-NLS-1$
+ ITypeBinding typeBinding = qualifiedName.resolveTypeBinding();
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong type", "Test", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding = qualifiedName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("Not a type", IBinding.TYPE, binding.getKind()); //$NON-NLS-1$
+
+ }
+
+ /**
+ * MethodInvocation
+ */
+ public void test0229() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0229", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("ExpressionStatement", node2 instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node2;
+ Expression expr = expressionStatement.getExpression();
+ assertTrue("MethodInvocation", expr instanceof MethodInvocation); //$NON-NLS-1$
+ checkSourceRange(expr, "System.err.println()", source); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expr;
+ Expression qualifier = methodInvocation.getExpression();
+ assertTrue("QualifiedName", qualifier instanceof QualifiedName); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) qualifier;
+ ITypeBinding typeBinding = qualifier.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "PrintStream", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding = qualifiedName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("VariableBinding", binding instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("wrong name", "err", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ SimpleName methodName = methodInvocation.getName();
+ IBinding binding2 = methodName.resolveBinding();
+ assertNotNull("No binding2", binding2); //$NON-NLS-1$
+ }
+
+ /**
+ * MethodInvocation
+ */
+ public void test0230() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0230", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 1, 0);
+ assertTrue("ExpressionStatement", node2 instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node2;
+ Expression expr = expressionStatement.getExpression();
+ assertTrue("MethodInvocation", expr instanceof MethodInvocation); //$NON-NLS-1$
+ checkSourceRange(expr, "err.println()", source); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expr;
+ Expression qualifier = methodInvocation.getExpression();
+ assertTrue("SimpleName", qualifier instanceof SimpleName); //$NON-NLS-1$
+ SimpleName name = (SimpleName) qualifier;
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong name", "err", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ITypeBinding typeBinding = name.resolveTypeBinding();
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wron type name", "PrintStream", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * MethodInvocation
+ */
+ public void test0231() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0231", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("ExpressionStatement", node2 instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node2;
+ Expression expr = expressionStatement.getExpression();
+ assertTrue("MethodInvocation", expr instanceof MethodInvocation); //$NON-NLS-1$
+ checkSourceRange(expr, "System.err.println()", source); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expr;
+ Expression qualifier = methodInvocation.getExpression();
+ assertTrue("QualifiedName", qualifier instanceof QualifiedName); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) qualifier;
+ ITypeBinding typeBinding = qualifier.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "PrintStream", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding = qualifiedName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("VariableBinding", binding instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("wrong name", "err", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ SimpleName methodName = methodInvocation.getName();
+ IBinding binding2 = methodName.resolveBinding();
+ assertNotNull("No binding2", binding2); //$NON-NLS-1$
+ Name name = qualifiedName.getQualifier();
+ assertTrue("SimpleName", name.isSimpleName()); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) name;
+ ITypeBinding typeBinding2 = simpleName.resolveTypeBinding();
+ assertNotNull("No typeBinding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("wrong type name", "System", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * MethodInvocation
+ */
+ public void test0232() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0232", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("VariableDeclarationStatement", node2 instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node2;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression initialization = variableDeclarationFragment.getInitializer();
+ ITypeBinding typeBinding = initialization.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertTrue("Not a primitive type", typeBinding.isPrimitive()); //$NON-NLS-1$
+ assertEquals("wrong name", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("QualifiedName", initialization instanceof QualifiedName); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) initialization;
+ SimpleName simpleName = qualifiedName.getName();
+ ITypeBinding typeBinding2 = simpleName.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding2); //$NON-NLS-1$
+ assertTrue("Not a primitive type", typeBinding2.isPrimitive()); //$NON-NLS-1$
+ assertEquals("wrong name", "int", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("IVariableBinding", binding instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertNull("No declaring class", variableBinding.getDeclaringClass()); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking that only syntax errors are reported for the MALFORMED tag
+ */
+ public void test0233() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0233", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The compilation unit is malformed", !isMalformed(result)); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("The fiels is not malformed", !isMalformed(node)); //$NON-NLS-1$
+ assertEquals("No problem found", 1, unit.getMessages().length); //$NON-NLS-1$
+ assertEquals("No problem found", 1, unit.getProblems().length); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking that null is returned for a resolveBinding if the type is unknown
+ */
+ public void test0234() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0234", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true, true, true);
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("The fiels is not malformed", !isMalformed(node)); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("No problem found", 1, unit.getMessages().length); //$NON-NLS-1$
+ assertEquals("No problem found", 1, unit.getProblems().length); //$NON-NLS-1$
+ assertTrue("FieldDeclaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding); //$NON-NLS-1$
+ assertEquals("Ltest0234/Test;.field)LList;", variableBinding.getKey());
+ }
+
+ /**
+ * Checking that null is returned for a resolveBinding if the type is unknown
+ */
+ public void test0234_2() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0234", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true, true, false);
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("The fiels is not malformed", !isMalformed(node)); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("No problem found", 1, unit.getMessages().length); //$NON-NLS-1$
+ assertEquals("No problem found", 1, unit.getProblems().length); //$NON-NLS-1$
+ assertTrue("FieldDeclaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNull("Got a binding", variableBinding); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking that null is returned for a resolveBinding if the type is unknown
+ */
+ public void test0235() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0235", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("The fiels is not malformed", !isMalformed(node)); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("problems found", 0, unit.getMessages().length); //$NON-NLS-1$
+ assertEquals("problems found", 0, unit.getProblems().length); //$NON-NLS-1$
+ assertTrue("FieldDeclaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=9452
+ */
+ public void test0237() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "junit.framework", "TestCase.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ }
+
+ /**
+ * Check ThisExpression
+ */
+ public void test0238() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0238", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ char[] source = sourceUnit.getSource().toCharArray();
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not a type declaration statement", node instanceof TypeDeclarationStatement); //$NON-NLS-1$
+ TypeDeclarationStatement typeDeclarationStatement = (TypeDeclarationStatement) node;
+ AbstractTypeDeclaration typeDecl = typeDeclarationStatement.getDeclaration();
+ Object o = typeDecl.bodyDeclarations().get(0);
+ assertTrue("Not a method", o instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDecl = (MethodDeclaration) o;
+ Block block = methodDecl.getBody();
+ List statements = block.statements();
+ assertEquals("Not 1", 1, statements.size()); //$NON-NLS-1$
+ Statement stmt = (Statement) statements.get(0);
+ assertTrue("Not a return statement", stmt instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) stmt;
+ Expression expr = returnStatement.getExpression();
+ assertTrue("Not a method invocation", expr instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expr;
+ checkSourceRange(methodInvocation, "Test.this.bar()", source); //$NON-NLS-1$
+ Expression qualifier = methodInvocation.getExpression();
+ assertTrue("Not a ThisExpression", qualifier instanceof ThisExpression); //$NON-NLS-1$
+ ThisExpression thisExpression = (ThisExpression) qualifier;
+ Name name = thisExpression.getQualifier();
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("wrong name", "Test", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Check ThisExpression
+ */
+ public void test0239() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0239", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 1, 0, 0);
+ assertTrue("Not a type declaration statement", node instanceof TypeDeclarationStatement); //$NON-NLS-1$
+ TypeDeclarationStatement typeDeclarationStatement = (TypeDeclarationStatement) node;
+ AbstractTypeDeclaration typeDecl = typeDeclarationStatement.getDeclaration();
+ Object o = typeDecl.bodyDeclarations().get(0);
+ assertTrue("Not a method", o instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDecl = (MethodDeclaration) o;
+ Block block = methodDecl.getBody();
+ List statements = block.statements();
+ assertEquals("Not 1", 1, statements.size()); //$NON-NLS-1$
+ Statement stmt = (Statement) statements.get(0);
+ assertTrue("Not a return statement", stmt instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) stmt;
+ Expression expr = returnStatement.getExpression();
+ assertTrue("Not a SuperMethodInvocation", expr instanceof SuperMethodInvocation); //$NON-NLS-1$
+ SuperMethodInvocation superMethodInvocation = (SuperMethodInvocation) expr;
+ Name name = superMethodInvocation.getQualifier();
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("A type binding", binding instanceof ITypeBinding); //$NON-NLS-1$
+ assertEquals("Not Test", "Test", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Name methodName = superMethodInvocation.getName();
+ IBinding binding2 = methodName.resolveBinding();
+ assertNotNull("No binding2", binding2); //$NON-NLS-1$
+ assertTrue("No an IMethodBinding", binding2 instanceof IMethodBinding); //$NON-NLS-1$
+ IMethodBinding methodBinding = (IMethodBinding) binding2;
+ assertEquals("Not bar", "bar", methodBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Not T", "T", methodBinding.getDeclaringClass().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Check FieldAccess
+ */
+ public void test0240() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0240", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not a type declaration statement", node instanceof TypeDeclarationStatement); //$NON-NLS-1$
+ TypeDeclarationStatement typeDeclarationStatement = (TypeDeclarationStatement) node;
+ AbstractTypeDeclaration typeDecl = typeDeclarationStatement.getDeclaration();
+ Object o = typeDecl.bodyDeclarations().get(0);
+ assertTrue("Not a method", o instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDecl = (MethodDeclaration) o;
+ Block block = methodDecl.getBody();
+ List statements = block.statements();
+ assertEquals("Not 1", 1, statements.size()); //$NON-NLS-1$
+ Statement stmt = (Statement) statements.get(0);
+ assertTrue("Not a return statement", stmt instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) stmt;
+ Expression expr = returnStatement.getExpression();
+ assertTrue("Not a field access", expr instanceof FieldAccess); //$NON-NLS-1$
+ FieldAccess fieldAccess = (FieldAccess) expr;
+ Expression qualifier = fieldAccess.getExpression();
+ assertTrue("Not a ThisExpression", qualifier instanceof ThisExpression); //$NON-NLS-1$
+ ThisExpression thisExpression = (ThisExpression) qualifier;
+ Name name = thisExpression.getQualifier();
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("Not Test", "Test", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Name fieldName = fieldAccess.getName();
+ IBinding binding2 = fieldName.resolveBinding();
+ assertNotNull("No binding2", binding2); //$NON-NLS-1$
+ assertEquals("Wrong name", "f", binding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong modifier", Modifier.PUBLIC, binding2.getModifiers()); //$NON-NLS-1$
+ ITypeBinding typeBinding = fieldName.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not int", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Check order of body declarations
+ */
+ public void test0241() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0241", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0);
+ assertTrue("Not a type declaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ assertTrue("Not a declaration", ((TypeDeclaration) node).getName().isDeclaration()); //$NON-NLS-1$
+ assertEquals("Wrong size", 11, ((TypeDeclaration)node).bodyDeclarations().size()); //$NON-NLS-1$
+ node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ node = getASTNode((CompilationUnit) result, 0, 1);
+ assertTrue("Not a MethodDeclaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ node = getASTNode((CompilationUnit) result, 0, 2);
+ assertTrue("Not a Type declaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ node = getASTNode((CompilationUnit) result, 0, 3);
+ assertTrue("Not a Type declaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ node = getASTNode((CompilationUnit) result, 0, 4);
+ assertTrue("Not a MethodDeclaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ node = getASTNode((CompilationUnit) result, 0, 5);
+ assertTrue("Not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ node = getASTNode((CompilationUnit) result, 0, 6);
+ assertTrue("Not a MethodDeclaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ node = getASTNode((CompilationUnit) result, 0, 7);
+ assertTrue("Not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ node = getASTNode((CompilationUnit) result, 0, 8);
+ assertTrue("Not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ node = getASTNode((CompilationUnit) result, 0, 9);
+ assertTrue("Not a MethodDeclaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ node = getASTNode((CompilationUnit) result, 0, 10);
+ assertTrue("Not a Type declaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ }
+
+ /**
+ * Check ThisExpression
+ */
+ public void test0242() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0242", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 1, 0, 0);
+ assertTrue("Not a type declaration statement", node instanceof TypeDeclarationStatement); //$NON-NLS-1$
+ TypeDeclarationStatement typeDeclarationStatement = (TypeDeclarationStatement) node;
+ AbstractTypeDeclaration typeDecl = typeDeclarationStatement.getDeclaration();
+ Object o = typeDecl.bodyDeclarations().get(0);
+ assertTrue("Not a method", o instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDecl = (MethodDeclaration) o;
+ Block block = methodDecl.getBody();
+ List statements = block.statements();
+ assertEquals("Not 1", 1, statements.size()); //$NON-NLS-1$
+ Statement stmt = (Statement) statements.get(0);
+ assertTrue("Not a return statement", stmt instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) stmt;
+ Expression expr = returnStatement.getExpression();
+ assertTrue("Not a SuperFieldAccess", expr instanceof SuperFieldAccess); //$NON-NLS-1$
+ SuperFieldAccess superFieldAccess = (SuperFieldAccess) expr;
+ Name name = superFieldAccess.getQualifier();
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("A type binding", binding instanceof ITypeBinding); //$NON-NLS-1$
+ assertEquals("Not Test", "Test", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Name fieldName = superFieldAccess.getName();
+ IBinding binding2 = fieldName.resolveBinding();
+ assertNotNull("No binding2", binding2); //$NON-NLS-1$
+ assertTrue("No an IVariableBinding", binding2 instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding2;
+ assertEquals("Not f", "f", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Not T", "T", variableBinding.getDeclaringClass().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ITypeBinding typeBinding2 = fieldName.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding2); //$NON-NLS-1$
+ assertEquals("Not int", "int", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Check catch clause positions:
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10570
+ */
+ public void test0243() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0243", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not a try statement", node instanceof TryStatement); //$NON-NLS-1$
+ TryStatement tryStatement = (TryStatement) node;
+ List catchClauses = tryStatement.catchClauses();
+ assertEquals("wrong size", 1, catchClauses.size()); //$NON-NLS-1$
+ CatchClause catchClause = (CatchClause) catchClauses.get(0);
+ checkSourceRange(catchClause, "catch (Exception e){m();}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check catch clause positions:
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10570
+ */
+ public void test0244() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0244", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not a try statement", node instanceof TryStatement); //$NON-NLS-1$
+ TryStatement tryStatement = (TryStatement) node;
+ List catchClauses = tryStatement.catchClauses();
+ assertEquals("wrong size", 2, catchClauses.size()); //$NON-NLS-1$
+ CatchClause catchClause = (CatchClause) catchClauses.get(0);
+ checkSourceRange(catchClause, "catch (RuntimeException e){m();}", source); //$NON-NLS-1$
+ catchClause = (CatchClause) catchClauses.get(1);
+ checkSourceRange(catchClause, "catch(Exception e) {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=10587
+ */
+ public void test0245() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0245", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertTrue("Not a return statement", node instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expr = returnStatement.getExpression();
+ assertTrue("not a name", expr instanceof Name); //$NON-NLS-1$
+ Name name = (Name) expr;
+ IBinding binding = name.resolveBinding();
+ assertTrue("Not a variable binding", binding instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Not i", "i", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Not int", "int", variableBinding.getType().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ASTNode declaringNode = unit.findDeclaringNode(variableBinding);
+ assertNotNull("No declaring node", declaringNode); //$NON-NLS-1$
+ assertTrue("Not a VariableDeclarationFragment", declaringNode instanceof VariableDeclarationFragment); //$NON-NLS-1$
+ }
+
+ /**
+ * Test binding resolution for import declaration
+ */
+ public void test0246() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0246", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ List imports = unit.imports();
+ assertEquals("wrong imports size", 2, imports.size()); //$NON-NLS-1$
+ ImportDeclaration importDeclaration = (ImportDeclaration) imports.get(0);
+ assertTrue("Not on demand", importDeclaration.isOnDemand()); //$NON-NLS-1$
+ checkSourceRange(importDeclaration, "import java.util.*;", source); //$NON-NLS-1$
+ IBinding binding = importDeclaration.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.PACKAGE, binding.getKind()); //$NON-NLS-1$
+ assertEquals("Wrong name", "java.util", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ importDeclaration = (ImportDeclaration) imports.get(1);
+ assertTrue("On demand", !importDeclaration.isOnDemand()); //$NON-NLS-1$
+ checkSourceRange(importDeclaration, "import java.io.IOException;", source); //$NON-NLS-1$
+ binding = importDeclaration.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.TYPE, binding.getKind()); //$NON-NLS-1$
+ assertEquals("Wrong name", "IOException", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test binding resolution for import declaration
+ */
+ public void test0247() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0247", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ PackageDeclaration packageDeclaration = unit.getPackage();
+ checkSourceRange(packageDeclaration, "package test0247;", source); //$NON-NLS-1$
+ IPackageBinding binding = packageDeclaration.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.PACKAGE, binding.getKind()); //$NON-NLS-1$
+ assertEquals("Wrong name", "test0247", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10592
+ */
+ public void test0248() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0248", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ assertEquals("wrong size", 1, parameters.size()); //$NON-NLS-1$
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ Name name = singleVariableDeclaration.getName();
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("Not a variable binding", binding instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Wrong name", "i", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong type", "int", variableBinding.getType().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10592
+ */
+ public void test0249() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0249", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 2, 1);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not an assignment", expression instanceof Assignment); //$NON-NLS-1$
+ Assignment assignment = (Assignment) expression;
+ Expression leftHandSide = assignment.getLeftHandSide();
+ assertTrue("Not a qualified name", leftHandSide instanceof QualifiedName); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) leftHandSide;
+ Name simpleName = qualifiedName.getName();
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("no binding", binding); //$NON-NLS-1$
+ assertTrue("Not a IVariableBinding", binding instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Wrong name", "k", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong modifier", Modifier.STATIC, variableBinding.getModifiers()); //$NON-NLS-1$
+ assertEquals("Wrong type", "int", variableBinding.getType().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong declaring class name", "j", variableBinding.getDeclaringClass().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10592
+ */
+ public void test0250() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0250", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ assertEquals("wrong size", 2, parameters.size()); //$NON-NLS-1$
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ Name name = singleVariableDeclaration.getName();
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("Not a variable binding", binding instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Wrong name", "i", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong type", "int", variableBinding.getType().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Check qualified name resolution for static fields
+ */
+ public void test0251() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0251", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not a ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ checkSourceRange(methodInvocation, "java.lang.System.out.println()", source); //$NON-NLS-1$
+ Expression qualifier = methodInvocation.getExpression();
+ assertTrue("Not a qualified name", qualifier instanceof QualifiedName); //$NON-NLS-1$
+ checkSourceRange(qualifier, "java.lang.System.out", source); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) qualifier;
+ Name typeName = qualifiedName.getQualifier();
+ assertTrue("Not a QualifiedName", typeName instanceof QualifiedName); //$NON-NLS-1$
+ QualifiedName qualifiedTypeName = (QualifiedName) typeName;
+ IBinding binding = qualifiedTypeName.getName().resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong name", "System", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ binding = qualifiedTypeName.getQualifier().resolveBinding();
+ assertNotNull("No binding2", binding); //$NON-NLS-1$
+ assertEquals("Wrong type binding", IBinding.PACKAGE, binding.getKind()); //$NON-NLS-1$
+ }
+
+ /**
+ * Check binding for anonymous class
+ */
+ public void test0252() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0252", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertTrue("Not a return statement", node instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertTrue("Not a classinstancecreation", expression instanceof ClassInstanceCreation); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ IMethodBinding methodBinding = classInstanceCreation.resolveConstructorBinding();
+ assertNotNull("No methodBinding", methodBinding); //$NON-NLS-1$
+ assertTrue("Not a constructor", methodBinding.isConstructor()); //$NON-NLS-1$
+ assertTrue("Not an anonymous class", methodBinding.getDeclaringClass().isAnonymous()); //$NON-NLS-1$
+ assertEquals("Not an anonymous class of java.lang.Object", "Object", methodBinding.getDeclaringClass().getSuperclass().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Not an anonymous class of java.lang.Object", "java.lang", methodBinding.getDeclaringClass().getSuperclass().getPackage().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Check binding for allocation expression
+ */
+ public void test0253() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0253", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not a return statement", node instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertTrue("Not a classinstancecreation", expression instanceof ClassInstanceCreation); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ IMethodBinding methodBinding = classInstanceCreation.resolveConstructorBinding();
+ assertNotNull("No methodBinding", methodBinding); //$NON-NLS-1$
+ assertTrue("Not a constructor", methodBinding.isConstructor()); //$NON-NLS-1$
+ assertEquals("Wrong size", 1, methodBinding.getParameterTypes().length); //$NON-NLS-1$
+ assertEquals("Wrong type", "String", methodBinding.getParameterTypes()[0].getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Check binding for allocation expression
+ */
+ public void test0254() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0254", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 1, 0);
+ assertTrue("Not a return statement", node instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertTrue("Not a class instance creation", expression instanceof ClassInstanceCreation); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ IMethodBinding binding = classInstanceCreation.resolveConstructorBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("wrong type", "C", binding.getDeclaringClass().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+
+ /**
+ * Check binding for allocation expression
+ */
+ public void test0255() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0255", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a MethodInvocation", expression instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ List arguments = methodInvocation.arguments();
+ assertEquals("wrong size", 1, arguments.size()); //$NON-NLS-1$
+ Expression expression2 = (Expression) arguments.get(0);
+ assertTrue("Not a CastExpression", expression2 instanceof CastExpression); //$NON-NLS-1$
+ CastExpression castExpression = (CastExpression) expression2;
+ Type type = castExpression.getType();
+ ITypeBinding binding = type.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("Not an array type", binding.isArray()); //$NON-NLS-1$
+ }
+
+ /**
+ * Check binding for allocation expression
+ */
+ public void test0256() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0256", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a MethodInvocation", expression instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ List arguments = methodInvocation.arguments();
+ assertEquals("wrong size", 1, arguments.size()); //$NON-NLS-1$
+ Expression expression2 = (Expression) arguments.get(0);
+ assertTrue("Not a CastExpression", expression2 instanceof CastExpression); //$NON-NLS-1$
+ CastExpression castExpression = (CastExpression) expression2;
+ Type type = castExpression.getType();
+ assertTrue("Not a simple type", type.isSimpleType()); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type;
+ ITypeBinding binding = type.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("Not a class", binding.isClass()); //$NON-NLS-1$
+ Name name = simpleType.getName();
+ IBinding binding2 = name.resolveBinding();
+ assertNotNull("No binding2", binding2); //$NON-NLS-1$
+ assertEquals("Wrong type", "Object", binding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Check binding for allocation expression
+ */
+ public void test0257() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0257", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a MethodInvocation", expression instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ List arguments = methodInvocation.arguments();
+ assertEquals("wrong size", 1, arguments.size()); //$NON-NLS-1$
+ Expression expression2 = (Expression) arguments.get(0);
+ assertTrue("Not a CastExpression", expression2 instanceof CastExpression); //$NON-NLS-1$
+ CastExpression castExpression = (CastExpression) expression2;
+ Type type = castExpression.getType();
+ assertTrue("Not a primitive type", type.isPrimitiveType()); //$NON-NLS-1$
+ PrimitiveType primitiveType = (PrimitiveType) type;
+ assertEquals("Not int", PrimitiveType.INT, primitiveType.getPrimitiveTypeCode()); //$NON-NLS-1$
+ }
+
+ /**
+ * Check binding for allocation expression
+ */
+ public void test0258() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0258", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a MethodInvocation", expression instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ List arguments = methodInvocation.arguments();
+ assertEquals("wrong size", 1, arguments.size()); //$NON-NLS-1$
+ Expression expression2 = (Expression) arguments.get(0);
+ assertTrue("Not a CastExpression", expression2 instanceof CastExpression); //$NON-NLS-1$
+ CastExpression castExpression = (CastExpression) expression2;
+ Type type = castExpression.getType();
+ assertTrue("Not a simple type", type.isSimpleType()); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type;
+ ITypeBinding binding = type.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("Not a class", binding.isClass()); //$NON-NLS-1$
+ Name name = simpleType.getName();
+ IBinding binding2 = name.resolveBinding();
+ assertNotNull("No binding2", binding2); //$NON-NLS-1$
+ assertEquals("Wrong type", "Object", binding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10663
+ */
+ public void test0259() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0259", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10592
+ */
+ public void test0260() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0260", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ assertEquals("wrong size", 2, parameters.size()); //$NON-NLS-1$
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ IBinding binding = singleVariableDeclaration.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ Name name = singleVariableDeclaration.getName();
+ assertTrue("Not a simple name", name instanceof SimpleName); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) name;
+ assertEquals("Wrong name", "i", simpleName.getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding2 = name.resolveBinding();
+ assertNotNull("No binding", binding2); //$NON-NLS-1$
+ assertTrue("binding == binding2", binding == binding2); //$NON-NLS-1$
+ assertTrue("Not a variable binding", binding2 instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding2;
+ assertEquals("Wrong name", "i", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong type", "int", variableBinding.getType().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10679
+ */
+ public void test0261() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0261", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("Wrong msg size", 1, compilationUnit.getMessages().length); //$NON-NLS-1$
+ assertEquals("Wrong pb size", 1, compilationUnit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a return statement", node instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ ITypeBinding binding = expression.resolveTypeBinding();
+ assertNull("got a binding", binding); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10676
+ */
+ public void test0262() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0262", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expr = expressionStatement.getExpression();
+ assertTrue("Not a MethodInvocation", expr instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expr;
+ List arguments = methodInvocation.arguments();
+ assertEquals("Wrong argument list size", 1, arguments.size()); //$NON-NLS-1$
+ Expression expr2 = (Expression) arguments.get(0);
+ assertTrue("Not a class instance creation", expr2 instanceof ClassInstanceCreation); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expr2;
+ arguments = classInstanceCreation.arguments();
+ assertEquals("Wrong size", 1, arguments.size()); //$NON-NLS-1$
+ Expression expression2 = (Expression) arguments.get(0);
+ assertTrue("Not a string literal", expression2 instanceof StringLiteral); //$NON-NLS-1$
+ StringLiteral stringLiteral = (StringLiteral) expression2;
+ ITypeBinding typeBinding = stringLiteral.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "String", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10700
+ */
+ public void test0263() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0263", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expr = expressionStatement.getExpression();
+ assertTrue("Not a MethodInvocation", expr instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expr;
+ List arguments = methodInvocation.arguments();
+ assertEquals("Wrong argument list size", 1, arguments.size()); //$NON-NLS-1$
+ Expression expr2 = (Expression) arguments.get(0);
+ assertTrue("Not a simple name", expr2 instanceof SimpleName); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) expr2;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10699
+ */
+ public void test0264() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0264", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("Wrong fragment size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a classinstancecreation", expression instanceof ClassInstanceCreation); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ assertNotNull("No anonymousclassdeclaration", anonymousClassDeclaration); //$NON-NLS-1$
+ String expectedSourceRange =
+ "{\n"+ //$NON-NLS-1$
+ " void m(int k){\n"+ //$NON-NLS-1$
+ " k= i;\n"+ //$NON-NLS-1$
+ " }\n"+ //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(anonymousClassDeclaration, expectedSourceRange, source);
+ List bodyDeclarations = anonymousClassDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size()); //$NON-NLS-1$
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue("Not a method declaration", bodyDeclaration instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ assertEquals("Wrong name", "m", methodDeclaration.getName().getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10698
+ */
+ public void test0265() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0265", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10759
+ */
+ public void test0266() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0266", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ checkSourceRange(type, "Inner\\u005b]", source); //$NON-NLS-1$
+ assertTrue("Not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ Type type2 = arrayType.getElementType();
+ assertTrue("Not a simple type", type2.isSimpleType()); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type2;
+ checkSourceRange(simpleType, "Inner", source); //$NON-NLS-1$
+ Name name = simpleType.getName();
+ assertTrue("not a simple name", name.isSimpleName()); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) name;
+ checkSourceRange(simpleName, "Inner", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10759
+ */
+ public void test0267() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0267", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ checkSourceRange(type, "Inner[]", source); //$NON-NLS-1$
+ assertTrue("Not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ Type type2 = arrayType.getElementType();
+ assertTrue("Not a simple type", type2.isSimpleType()); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type2;
+ checkSourceRange(simpleType, "Inner", source); //$NON-NLS-1$
+ Name name = simpleType.getName();
+ assertTrue("not a simple name", name.isSimpleName()); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) name;
+ checkSourceRange(simpleName, "Inner", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10759
+ */
+ public void test0268() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0268", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ checkSourceRange(type, "test0268.Test.Inner[]", source); //$NON-NLS-1$
+ assertTrue("Not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ Type type2 = arrayType.getElementType();
+ assertTrue("Not a simple type", type2.isSimpleType()); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type2;
+ checkSourceRange(simpleType, "test0268.Test.Inner", source); //$NON-NLS-1$
+ Name name = simpleType.getName();
+ assertTrue("not a qualified name", name.isQualifiedName()); //$NON-NLS-1$
+ checkSourceRange(name, "test0268.Test.Inner", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10759
+ */
+ public void test0269() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0269", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ checkSourceRange(type, "test0269.Test.Inner[/**/]", source); //$NON-NLS-1$
+ assertTrue("Not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ Type type2 = arrayType.getElementType();
+ assertTrue("Not a simple type", type2.isSimpleType()); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type2;
+ checkSourceRange(simpleType, "test0269.Test.Inner", source); //$NON-NLS-1$
+ Name name = simpleType.getName();
+ assertTrue("not a qualified name", name.isQualifiedName()); //$NON-NLS-1$
+ checkSourceRange(name, "test0269.Test.Inner", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10759
+ */
+ public void test0270() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0270", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ checkSourceRange(type, "test0270.Test.Inner", source); //$NON-NLS-1$
+ assertTrue("Not a simple type", type.isSimpleType()); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type;
+ Name name = simpleType.getName();
+ assertTrue("not a qualified name", name.isQualifiedName()); //$NON-NLS-1$
+ checkSourceRange(name, "test0270.Test.Inner", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10759
+ */
+ public void test0271() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0271", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ checkSourceRange(type, "test0271.Test.Inner[]", source); //$NON-NLS-1$
+ assertTrue("Not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ Type type2 = arrayType.getElementType();
+ assertTrue("Not a simple type", type2.isSimpleType()); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type2;
+ checkSourceRange(simpleType, "test0271.Test.Inner", source); //$NON-NLS-1$
+ Name name = simpleType.getName();
+ assertTrue("not a qualified name", name.isQualifiedName()); //$NON-NLS-1$
+ checkSourceRange(name, "test0271.Test.Inner", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10843
+ */
+ public void test0272() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0272", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a For statement", node instanceof ForStatement); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node;
+ checkSourceRange(forStatement, "for (int i= 0; i < 10; i++) foo();", source); //$NON-NLS-1$
+ Statement action = forStatement.getBody();
+ checkSourceRange(action, "foo();", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10843
+ */
+ public void test0273() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0273", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a For statement", node instanceof ForStatement); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node;
+ checkSourceRange(forStatement, "for (int i= 0; i < 10; i++) { foo(); }", source); //$NON-NLS-1$
+ Statement action = forStatement.getBody();
+ checkSourceRange(action, "{ foo(); }", source); //$NON-NLS-1$
+ assertTrue("Not a block", action instanceof Block); //$NON-NLS-1$
+ Block block = (Block) action;
+ List statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement stmt = (Statement) statements.get(0);
+ checkSourceRange(stmt, "foo();", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10843
+ */
+ public void test0274() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0274", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 1);
+ assertTrue("Not a While statement", node instanceof WhileStatement); //$NON-NLS-1$
+ WhileStatement whileStatement = (WhileStatement) node;
+ checkSourceRange(whileStatement, "while (i < 10) { foo(i++); }", source); //$NON-NLS-1$
+ Statement action = whileStatement.getBody();
+ checkSourceRange(action, "{ foo(i++); }", source); //$NON-NLS-1$
+ assertTrue("Not a block", action instanceof Block); //$NON-NLS-1$
+ Block block = (Block) action;
+ List statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement stmt = (Statement) statements.get(0);
+ checkSourceRange(stmt, "foo(i++);", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10843
+ */
+ public void test0275() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0275", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 1);
+ assertTrue("Not a While statement", node instanceof WhileStatement); //$NON-NLS-1$
+ WhileStatement whileStatement = (WhileStatement) node;
+ checkSourceRange(whileStatement, "while (i < 10) foo(i++);", source); //$NON-NLS-1$
+ Statement action = whileStatement.getBody();
+ checkSourceRange(action, "foo(i++);", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10798
+ */
+ public void test0276() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0276", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ String expectedSource =
+ "public void foo() {\n" + //$NON-NLS-1$
+ " foo();\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(methodDeclaration, expectedSource, source);
+ expectedSource =
+ "{\n" + //$NON-NLS-1$
+ " foo();\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(methodDeclaration.getBody(), expectedSource, source);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10798
+ */
+ public void test0277() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0277", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ String expectedSource =
+ "public void foo() {\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(methodDeclaration, expectedSource, source);
+ expectedSource =
+ "{\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(methodDeclaration.getBody(), expectedSource, source);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10861
+ */
+ public void test0278() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0278", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "Class c = java.lang.String.class;", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a type literal", expression instanceof TypeLiteral); //$NON-NLS-1$
+ ITypeBinding typeBinding = expression.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Class", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10861
+ */
+ public void test0279() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0279", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0,0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ checkSourceRange(variableDeclarationStatement, "Class c = java.lang.String.class;", source); //$NON-NLS-1$
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a type literal", expression instanceof TypeLiteral); //$NON-NLS-1$
+ ITypeBinding typeBinding = expression.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Class", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10865
+ * Check well known types
+ */
+ public void test0280() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0280", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ AST newAst = result.getAST();
+ ITypeBinding typeBinding = newAst.resolveWellKnownType("boolean"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "boolean", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("char"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "char", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("byte"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "byte", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("short"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "short", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("int"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("long"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "long", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("float"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "float", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("double"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "double", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("void"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "void", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Object", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("java.lang.String"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "String", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("java.lang.StringBuffer"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "StringBuffer", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Throwable"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Throwable", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Exception"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Exception", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("java.lang.RuntimeException"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "RuntimeException", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Error"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Error", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Class"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Class", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Runnable"); //$NON-NLS-1$
+ assertNull("typeBinding not null", typeBinding); //$NON-NLS-1$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Cloneable"); //$NON-NLS-1$
+ assertNotNull("typeBinding not null", typeBinding); //$NON-NLS-1$
+ typeBinding = newAst.resolveWellKnownType("java.io.Serializable"); //$NON-NLS-1$
+ assertNotNull("typeBinding not null", typeBinding); //$NON-NLS-1$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Boolean"); //$NON-NLS-1$
+ assertNotNull("typeBinding not null", typeBinding); //$NON-NLS-1$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Byte"); //$NON-NLS-1$
+ assertNotNull("typeBinding not null", typeBinding); //$NON-NLS-1$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Character"); //$NON-NLS-1$
+ assertNotNull("typeBinding not null", typeBinding); //$NON-NLS-1$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Double"); //$NON-NLS-1$
+ assertNotNull("typeBinding not null", typeBinding); //$NON-NLS-1$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Float"); //$NON-NLS-1$
+ assertNotNull("typeBinding not null", typeBinding); //$NON-NLS-1$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Integer"); //$NON-NLS-1$
+ assertNotNull("typeBinding not null", typeBinding); //$NON-NLS-1$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Long"); //$NON-NLS-1$
+ assertNotNull("typeBinding not null", typeBinding); //$NON-NLS-1$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Short"); //$NON-NLS-1$
+ assertNotNull("typeBinding not null", typeBinding); //$NON-NLS-1$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Void"); //$NON-NLS-1$
+ assertNotNull("typeBinding not null", typeBinding); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10874
+ */
+ public void test0281() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0281", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "Object o= /*]*/new Object()/*[*/;", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ checkSourceRange(expression, "new Object()", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10874
+ */
+ public void test0282() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0282", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "boolean b = /*]*/true/*[*/;", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ checkSourceRange(expression, "true", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10874
+ */
+ public void test0283() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0283", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "char c = /*]*/'c'/*[*/;", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ checkSourceRange(expression, "'c'", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10874
+ */
+ public void test0284() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0284", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "Object o = /*]*/null/*[*/;", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ checkSourceRange(expression, "null", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10874
+ */
+ public void test0285() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0285", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "Object o = /*]*/Object.class/*[*/;", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ checkSourceRange(expression, "Object.class", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10874
+ */
+ public void test0286() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0286", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "int i = /**/(2)/**/;", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ checkSourceRange(expression, "(2)", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10874
+ */
+ public void test0287() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0287", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "String[] tab = /**/new String[3]/**/;", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ checkSourceRange(expression, "new String[3]", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10874
+ */
+ public void test0288() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0288", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "String[] tab = /**/{ }/**/;", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ checkSourceRange(expression, "{ }", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10874
+ */
+ public void test0289() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0289", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 1);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "String s = /**/tab1[0]/**/;", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ checkSourceRange(expression, "tab1[0]", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10874
+ */
+ public void test0290() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0290", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "Object o = /*]*/new java.lang.Object()/*[*/;", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ checkSourceRange(expression, "new java.lang.Object()", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10898
+ */
+ public void test0291() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0291", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("no errors", 1, unit.getMessages().length); //$NON-NLS-1$
+ assertEquals("no errors", 1, unit.getProblems().length); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10913
+ */
+ public void test0292() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0292", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a return statement", node instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertTrue("Not a qualifiedName", expression instanceof QualifiedName); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) expression;
+ SimpleName simpleName = qualifiedName.getName();
+ assertEquals("Wrong name", "x", simpleName.getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("NO binding", binding); //$NON-NLS-1$
+ assertTrue("Not a variable binding", binding instanceof IVariableBinding); //$NON-NLS-1$
+ assertEquals("wrong name", "x", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Name name = qualifiedName.getQualifier();
+ assertTrue("Not a simpleName", name instanceof SimpleName); //$NON-NLS-1$
+ SimpleName simpleName2 = (SimpleName) name;
+ IBinding binding2 = simpleName2.resolveBinding();
+ assertNotNull("No binding2", binding2); //$NON-NLS-1$
+ assertTrue("Not a type binding", binding2 instanceof ITypeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Test", binding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10933
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10935
+ */
+ public void test0293() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0293", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a class instance creation", expression instanceof ClassInstanceCreation); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ assertNotNull("No body", anonymousClassDeclaration); //$NON-NLS-1$
+ String expectedSource =
+ "{\n" + //$NON-NLS-1$
+ " public void run() {\n" + //$NON-NLS-1$
+ " /*]*/foo();/*[*/\n" + //$NON-NLS-1$
+ " }\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(anonymousClassDeclaration, expectedSource, source);
+ expectedSource =
+ "run= new Runnable() {\n" + //$NON-NLS-1$
+ " public void run() {\n" + //$NON-NLS-1$
+ " /*]*/foo();/*[*/\n" + //$NON-NLS-1$
+ " }\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(variableDeclarationFragment, expectedSource, source);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10984
+ */
+ public void test0294() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0294", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ String expectedSource =
+ "public void fails() {\n" + //$NON-NLS-1$
+ " foo()\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(methodDeclaration, expectedSource, source);
+ Block block = methodDeclaration.getBody();
+ expectedSource =
+ "{\n" + //$NON-NLS-1$
+ " foo()\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(block, expectedSource, source);
+ node = getASTNode(compilationUnit, 0, 1);
+ assertTrue("Not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10986
+ */
+ public void test0295() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0295", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true, false, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("Wrong size", 2, compilationUnit.getMessages().length); //$NON-NLS-1$
+ assertEquals("Wrong size", 2, compilationUnit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("not a method invocation", expression instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ ITypeBinding typeBinding = methodInvocation.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("LList;", typeBinding.getKey());
+ assertEquals("Ltest0295/Test;.g()LList;", methodInvocation.resolveMethodBinding().getKey());
+ }
+
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10984
+ */
+ public void test0296() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0296", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ String expectedSource =
+ "public void fails() {\n" + //$NON-NLS-1$
+ " foo()\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(methodDeclaration, expectedSource, source);
+ Block block = methodDeclaration.getBody();
+ expectedSource =
+ "{\n" + //$NON-NLS-1$
+ " foo()\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(block, expectedSource, source);
+ node = getASTNode(compilationUnit, 0, 1);
+ assertTrue("Not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11037
+ */
+ public void test0297() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0297", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ runConversion(AST.JLS3, sourceUnit, false);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10984
+ */
+ public void test0298() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0298", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a ReturnStatement", node instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ checkSourceRange(expression, "a().length != 3", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10874
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11104
+ */
+ public void test0299() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0299", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "int i = (/**/2/**/);", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a parenthesized expression", expression instanceof ParenthesizedExpression); //$NON-NLS-1$
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression;
+ Expression expression2 = parenthesizedExpression.getExpression();
+ checkSourceRange(expression2, "2", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10874
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11104
+ */
+ public void test0300() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0300", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "boolean b = /**/true/**/;", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ checkSourceRange(expression, "true", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10874
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11104
+ */
+ public void test0301() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0301", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "Object o = /**/null/**/;", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ checkSourceRange(expression, "null", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11106
+ */
+ public void test0302() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0302", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a DoStatement", node instanceof DoStatement); //$NON-NLS-1$
+ DoStatement doStatement = (DoStatement) node;
+ String expectedSource =
+ "do\n" + //$NON-NLS-1$
+ " foo();\n" + //$NON-NLS-1$
+ " while(1 < 10);"; //$NON-NLS-1$
+ checkSourceRange(doStatement, expectedSource, source);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11129
+ */
+ public void test0303() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0303", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 1);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression2 = expressionStatement.getExpression();
+ assertTrue("Not an Assignement", expression2 instanceof Assignment); //$NON-NLS-1$
+ Assignment assignment = (Assignment) expression2;
+ Expression expression = assignment.getRightHandSide();
+ assertTrue("Not a CastExpression", expression instanceof CastExpression); //$NON-NLS-1$
+ CastExpression castExpression = (CastExpression) expression;
+ ITypeBinding typeBinding = castExpression.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "char", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Type type = castExpression.getType();
+ ITypeBinding typeBinding2 = type.resolveBinding();
+ assertNotNull("No binding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("Wrong name", "char", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11151
+ */
+ public void test0304() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0304", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ checkSourceRange(node, "public void foo(int arg);", source); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block block = methodDeclaration.getBody();
+ assertNull("Has a body", block); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11125
+ */
+ public void test0305() {
+ char[] source =
+ ("package test0305;\n" + //$NON-NLS-1$
+ "\n" + //$NON-NLS-1$
+ "class Test {\n" + //$NON-NLS-1$
+ " public void foo(int arg) {}\n" + //$NON-NLS-1$
+ "}").toCharArray(); //$NON-NLS-1$
+ IJavaProject project = getJavaProject("Converter"); //$NON-NLS-1$
+ ASTNode result = runConversion(AST.JLS3, source, "Test.java", project, true); //$NON-NLS-1$
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertTrue("not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Test", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong package", "test0305", typeBinding.getPackage().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("Not an interface", typeBinding.isClass()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11125
+ */
+ public void test0306() {
+ char[] source =
+ ("package java.lang;\n" + //$NON-NLS-1$
+ "\n" + //$NON-NLS-1$
+ "class Object {\n" + //$NON-NLS-1$
+ " public void foo(int arg) {}\n" + //$NON-NLS-1$
+ "}").toCharArray(); //$NON-NLS-1$
+ IJavaProject project = getJavaProject("Converter"); //$NON-NLS-1$
+ ASTNode result = runConversion(AST.JLS3, source, "Object.java", project, true); //$NON-NLS-1$
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertTrue("not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Object", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong package", "java.lang", typeBinding.getPackage().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("Not an interface", typeBinding.isClass()); //$NON-NLS-1$
+ assertEquals("Wrong size", 2, typeBinding.getDeclaredMethods().length); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11371
+ */
+ public void test0307() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0307", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertTrue("not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block block = methodDeclaration.getBody();
+ assertNotNull("No body", block); //$NON-NLS-1$
+ List statements = block.statements();
+ assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("Not a super constructor invocation", statement instanceof SuperConstructorInvocation); //$NON-NLS-1$
+ checkSourceRange(statement, "super(10);", source);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11371
+ */
+ public void test0308() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0308", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertTrue("not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block block = methodDeclaration.getBody();
+ assertNotNull("No body", block); //$NON-NLS-1$
+ List statements = block.statements();
+ assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("Not a super constructor invocation", statement instanceof SuperConstructorInvocation); //$NON-NLS-1$
+ SuperConstructorInvocation superConstructorInvocation = (SuperConstructorInvocation) statement;
+ IMethodBinding methodBinding = superConstructorInvocation.resolveConstructorBinding();
+ assertNotNull("No methodBinding", methodBinding); //$NON-NLS-1$
+ IMethodBinding methodBinding2 = methodDeclaration.resolveBinding();
+ assertNotNull("No methodBinding2", methodBinding2); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11380
+ */
+ public void test0309() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0309", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a conditional expression", expression instanceof ConditionalExpression); //$NON-NLS-1$
+ ConditionalExpression conditionalExpression = (ConditionalExpression) expression;
+ ITypeBinding typeBinding = conditionalExpression.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("wrong name", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11380
+ */
+ public void test0310() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0310", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("not a FieldDeclaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a qualified name", expression instanceof QualifiedName); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) expression;
+ Name qualifier = qualifiedName.getQualifier();
+ IBinding binding = qualifier.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("wrong name", "I", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11638
+ */
+ public void test0311() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0311", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 1);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("not a class instance creation", expression instanceof ClassInstanceCreation); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ assertNotNull("No body", anonymousClassDeclaration); //$NON-NLS-1$
+ List bodyDeclarations = anonymousClassDeclaration.bodyDeclarations();
+ assertEquals("wrong size for body declarations", 1, bodyDeclarations.size()); //$NON-NLS-1$
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue("Not a method declaration", bodyDeclaration instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ Block block = methodDeclaration.getBody();
+ assertNotNull("no body", block); //$NON-NLS-1$
+ List statements = block.statements();
+ assertEquals("Wrong size for statements", 1, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("not a variable declaration statement", statement instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement2 = (VariableDeclarationStatement) statement;
+ List fragments2 = variableDeclarationStatement2.fragments();
+ assertEquals("wrong size for fragments2", 1, fragments2.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment2 = (VariableDeclarationFragment) fragments2.get(0);
+ Expression expression2 = variableDeclarationFragment2.getInitializer();
+ assertTrue("Not a name", expression2 instanceof Name); //$NON-NLS-1$
+ Name name = (Name) expression2;
+ checkSourceRange(name, "j", source); //$NON-NLS-1$
+ IBinding binding = name.resolveBinding();
+ ASTNode declaringNode = compilationUnit.findDeclaringNode(binding);
+ assertNotNull("No declaring node", declaringNode); //$NON-NLS-1$
+ checkSourceRange(declaringNode, "int j", source); //$NON-NLS-1$
+ assertTrue("Not a single variable declaration", declaringNode instanceof SingleVariableDeclaration); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11638
+ * There is a error in this source. A is unresolved. Then there is no
+ * declaring node.
+ */
+ public void test0312() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0312", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 1);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("not a class instance creation", expression instanceof ClassInstanceCreation); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ assertNotNull("No body", anonymousClassDeclaration); //$NON-NLS-1$
+ List bodyDeclarations = anonymousClassDeclaration.bodyDeclarations();
+ assertEquals("wrong size for body declarations", 1, bodyDeclarations.size()); //$NON-NLS-1$
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue("Not a method declaration", bodyDeclaration instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ Block block = methodDeclaration.getBody();
+ assertNotNull("no body", block); //$NON-NLS-1$
+ List statements = block.statements();
+ assertEquals("Wrong size for statements", 1, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("not a variable declaration statement", statement instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement2 = (VariableDeclarationStatement) statement;
+ List fragments2 = variableDeclarationStatement2.fragments();
+ assertEquals("wrong size for fragments2", 1, fragments2.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment2 = (VariableDeclarationFragment) fragments2.get(0);
+ Expression expression2 = variableDeclarationFragment2.getInitializer();
+ assertTrue("Not a name", expression2 instanceof Name); //$NON-NLS-1$
+ Name name = (Name) expression2;
+ checkSourceRange(name, "j", source); //$NON-NLS-1$
+ IBinding binding = name.resolveBinding();
+ ASTNode declaringNode = compilationUnit.findDeclaringNode(binding);
+ assertNotNull("No declaring node is available", declaringNode); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11659
+ */
+ public void test0313() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0313", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not an InfixExpression", expression instanceof InfixExpression); //$NON-NLS-1$
+ InfixExpression infixExpression = (InfixExpression) expression;
+ checkSourceRange(infixExpression, "i+j", source); //$NON-NLS-1$
+ Expression expression2 = infixExpression.getLeftOperand();
+ checkSourceRange(expression2, "i", source); //$NON-NLS-1$
+ assertTrue("Not a name", expression2 instanceof Name); //$NON-NLS-1$
+ Name name = (Name) expression2;
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ ASTNode astNode = compilationUnit.findDeclaringNode(binding);
+ assertNotNull("No declaring node", astNode); //$NON-NLS-1$
+ checkSourceRange(astNode, "int i", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=12326
+ */
+ public void test0314() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0314", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ assertNotNull("No result", result); //$NON-NLS-1$
+ assertTrue("Not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("Wrong line number", 1, compilationUnit.getLineNumber(0)); //$NON-NLS-1$
+ // ensure that last character is on the last line
+ assertEquals("Wrong line number", 3, compilationUnit.getLineNumber(source.length - 1)); //$NON-NLS-1$
+ // source.length is beyond the size of the compilation unit source
+ assertEquals("Wrong line number", -1, compilationUnit.getLineNumber(source.length)); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=12326
+ */
+ public void test0315() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0315", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a Return statement", node instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertTrue("Not an instanceof expression", expression instanceof InstanceofExpression); //$NON-NLS-1$
+ InstanceofExpression instanceOfExpression = (InstanceofExpression) expression;
+ Type rightOperand = instanceOfExpression.getRightOperand();
+ assertTrue("Not a simpleType", rightOperand instanceof SimpleType); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) rightOperand;
+ Name n = simpleType.getName();
+ assertTrue("Not a qualified name", n instanceof QualifiedName); //$NON-NLS-1$
+ QualifiedName name = (QualifiedName) n;
+ checkSourceRange(name, "java.io.Serializable", source); //$NON-NLS-1$
+ ITypeBinding typeBinding = name.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Serializable", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Name qualifier = name.getQualifier();
+ assertTrue("Not a qualified name", qualifier instanceof QualifiedName); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = qualifier.resolveTypeBinding();
+ assertNull("typebinding2 is not null", typeBinding2); //$NON-NLS-1$
+ IBinding binding = qualifier.resolveBinding();
+ assertNotNull("no binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.PACKAGE, binding.getKind()); //$NON-NLS-1$
+ IPackageBinding pBinding = (IPackageBinding) binding;
+ assertEquals("Wrong name", "java.io", pBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=12454
+ */
+ public void test0316() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "", "Hello.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No result", result); //$NON-NLS-1$
+ assertTrue("Not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("Wrong size", 1, compilationUnit.getMessages().length); //$NON-NLS-1$
+ assertEquals("Wrong size", 1, compilationUnit.getProblems().length); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=12781
+ */
+ public void test0317() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0317", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a return statement", node instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertTrue("not an instanceof expression", expression instanceof InstanceofExpression); //$NON-NLS-1$
+ InstanceofExpression instanceOfExpression = (InstanceofExpression) expression;
+ Expression left = instanceOfExpression.getLeftOperand();
+ assertTrue("Not a Name", left instanceof Name); //$NON-NLS-1$
+ Name name = (Name) left;
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("wrong name", "x", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ITypeBinding typeBinding = name.resolveTypeBinding();
+ assertNotNull("No typebinding", typeBinding); //$NON-NLS-1$
+ assertEquals("wrong type", "Object", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Type right = instanceOfExpression.getRightOperand();
+ assertTrue("Not a simpleType", right instanceof SimpleType); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) right;
+ name = simpleType.getName();
+ assertTrue("Not a simpleName", name instanceof SimpleName); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) name;
+ IBinding binding2 = simpleName.resolveBinding();
+ assertNotNull("No binding2", binding2); //$NON-NLS-1$
+ assertEquals("Wrong name", "Vector", binding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ITypeBinding typeBinding2 = simpleName.resolveTypeBinding();
+ assertNotNull("No typeBinding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("Wrong name", "Vector", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=13233
+ */
+ public void test0318() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0318", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("No error", 1, unit.getMessages().length); //$NON-NLS-1$
+ assertEquals("No error", 1, unit.getProblems().length); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=13807
+ */
+ public void test0319() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0319", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not an array creation", expression instanceof ArrayCreation); //$NON-NLS-1$
+ ArrayCreation arrayCreation = (ArrayCreation) expression;
+ ITypeBinding typeBinding = arrayCreation.resolveTypeBinding();
+ assertNotNull("no type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[]", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ArrayType arrayType = arrayCreation.getType();
+ ITypeBinding typeBinding2 = arrayType.resolveBinding();
+ assertNotNull("no type binding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[]", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Type type = arrayType.getElementType();
+ assertTrue("Not a simple type", type instanceof SimpleType); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type;
+ ITypeBinding typeBinding3 = simpleType.resolveBinding();
+ assertNotNull("no type binding3", typeBinding3); //$NON-NLS-1$
+ assertEquals("wrong name", "Object", typeBinding3.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=13807
+ */
+ public void test0320() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0320", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ checkSourceRange(type, "int[]", source); //$NON-NLS-1$
+ assertTrue("Not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ ITypeBinding typeBinding = arrayType.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ Type elementType = arrayType.getElementType();
+ assertTrue("Not a simple type", elementType.isPrimitiveType()); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = elementType.resolveBinding();
+ assertNotNull("No type binding2", typeBinding2); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=13807
+ */
+ public void test0321() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0321", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ assertTrue("Not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ ITypeBinding typeBinding = arrayType.resolveBinding();
+ checkSourceRange(type, "java.lang.Object[][]", source); //$NON-NLS-1$
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ Type elementType = arrayType.getComponentType();
+ ITypeBinding typeBinding2 = elementType.resolveBinding();
+ assertNotNull("No type binding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("wrong dimension", 1, typeBinding2.getDimensions()); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[]", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("Not an array type", elementType.isArrayType()); //$NON-NLS-1$
+ Type elementType2 = ((ArrayType) elementType).getComponentType();
+ assertTrue("Not a simple type", elementType2.isSimpleType()); //$NON-NLS-1$
+ ITypeBinding typeBinding3 = elementType2.resolveBinding();
+ assertNotNull("No type binding3", typeBinding3); //$NON-NLS-1$
+ assertEquals("wrong dimension", 0, typeBinding3.getDimensions()); //$NON-NLS-1$
+ assertEquals("wrong name", "Object", typeBinding3.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=13231
+ */
+ public void test0322() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0322", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a FieldDeclaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a null literal", expression instanceof NullLiteral); //$NON-NLS-1$
+ NullLiteral nullLiteral = (NullLiteral) expression;
+ ITypeBinding typeBinding = nullLiteral.resolveTypeBinding();
+ assertNotNull("no type binding", typeBinding); //$NON-NLS-1$
+ assertTrue("Not the null type", typeBinding.isNullType()); //$NON-NLS-1$
+ assertEquals("Wrong qualified name", typeBinding.getQualifiedName(), "null"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=14198
+ */
+ public void test0323() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0323", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 1);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression2 = expressionStatement.getExpression();
+ assertTrue("Not an Assignement", expression2 instanceof Assignment); //$NON-NLS-1$
+ Assignment assignment = (Assignment) expression2;
+ Expression expression = assignment.getRightHandSide();
+ assertTrue("Not a CastExpression", expression instanceof CastExpression); //$NON-NLS-1$
+ CastExpression castExpression = (CastExpression) expression;
+ ITypeBinding typeBinding = castExpression.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Object", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Type type = castExpression.getType();
+ ITypeBinding typeBinding2 = type.resolveBinding();
+ assertNotNull("No binding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("Wrong name", "Object", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=14198
+ */
+ public void test0324() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0324", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 1);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression2 = expressionStatement.getExpression();
+ assertTrue("Not an Assignement", expression2 instanceof Assignment); //$NON-NLS-1$
+ Assignment assignment = (Assignment) expression2;
+ Expression expression = assignment.getRightHandSide();
+ assertTrue("Not a CastExpression", expression instanceof CastExpression); //$NON-NLS-1$
+ CastExpression castExpression = (CastExpression) expression;
+ ITypeBinding typeBinding = castExpression.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Object[]", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Type type = castExpression.getType();
+ ITypeBinding typeBinding2 = type.resolveBinding();
+ assertNotNull("No binding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("Wrong name", "Object[]", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=14198
+ */
+ public void test0325() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0325", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 1);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression2 = expressionStatement.getExpression();
+ assertTrue("Not an Assignement", expression2 instanceof Assignment); //$NON-NLS-1$
+ Assignment assignment = (Assignment) expression2;
+ Expression expression = assignment.getRightHandSide();
+ assertTrue("Not a CastExpression", expression instanceof CastExpression); //$NON-NLS-1$
+ CastExpression castExpression = (CastExpression) expression;
+ ITypeBinding typeBinding = castExpression.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "int[]", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Type type = castExpression.getType();
+ ITypeBinding typeBinding2 = type.resolveBinding();
+ assertNotNull("No binding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("Wrong name", "int[]", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=14217
+ */
+ public void test0326() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0326", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ char[] source = sourceUnit.getSource().toCharArray();
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ checkSourceRange(expressionStatement.getExpression(), "a().f= a()", source); //$NON-NLS-1$
+ checkSourceRange(expressionStatement, "a().f= a();", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=14198
+ */
+ public void test0327() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0327", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("Wrong number of errors", 2, compilationUnit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not an VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a CastExpression", expression instanceof CastExpression); //$NON-NLS-1$
+ CastExpression castExpression = (CastExpression) expression;
+ ITypeBinding typeBinding = castExpression.resolveTypeBinding();
+ assertNotNull("No typebinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "String", typeBinding.getName());
+ Type type = castExpression.getType();
+ ITypeBinding typeBinding2 = type.resolveBinding();
+ assertNotNull("No binding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("Wrong name", "String", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=13807
+ */
+ public void test0328() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0328", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ checkSourceRange(type, "java.lang.Object[]", source); //$NON-NLS-1$
+ assertTrue("Not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ ITypeBinding typeBinding = arrayType.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[]", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Type elementType = arrayType.getElementType();
+ assertTrue("Not a simple type", elementType.isSimpleType()); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = elementType.resolveBinding();
+ assertNotNull("No type binding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("wrong name", "Object", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a array creation", expression instanceof ArrayCreation); //$NON-NLS-1$
+ ITypeBinding typeBinding3 = expression.resolveTypeBinding();
+ assertNotNull("No typeBinding3", typeBinding3); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[]", typeBinding3.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ArrayCreation arrayCreation = (ArrayCreation) expression;
+ ArrayInitializer arrayInitializer = arrayCreation.getInitializer();
+ assertNotNull("not array initializer", arrayInitializer); //$NON-NLS-1$
+ ITypeBinding typeBinding4 = arrayInitializer.resolveTypeBinding();
+ assertNotNull("No typeBinding4", typeBinding3); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[]", typeBinding4.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=13807
+ */
+ public void test0329() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0329", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ checkSourceRange(type, "java.lang.Object[]", source); //$NON-NLS-1$
+ assertTrue("Not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ ITypeBinding typeBinding = arrayType.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[]", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Type elementType = arrayType.getElementType();
+ assertTrue("Not a simple type", elementType.isSimpleType()); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = elementType.resolveBinding();
+ assertNotNull("No type binding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("wrong name", "Object", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a array creation", expression instanceof ArrayCreation); //$NON-NLS-1$
+ ITypeBinding typeBinding3 = expression.resolveTypeBinding();
+ assertNotNull("No typeBinding3", typeBinding3); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[]", typeBinding3.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ArrayCreation arrayCreation = (ArrayCreation) expression;
+ ArrayInitializer arrayInitializer = arrayCreation.getInitializer();
+ assertNotNull("not array initializer", arrayInitializer); //$NON-NLS-1$
+ ITypeBinding typeBinding4 = arrayInitializer.resolveTypeBinding();
+ assertNotNull("No typeBinding4", typeBinding3); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[]", typeBinding4.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=14313
+ */
+ public void test0330() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0330", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("wrong size", 2, compilationUnit.getMessages().length); //$NON-NLS-1$
+ assertEquals("wrong size", 2, compilationUnit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("no type binding", typeBinding); //$NON-NLS-1$
+ IMethodBinding[] methods = typeBinding.getDeclaredMethods();
+ assertEquals("wrong size", 1, methods.length); //$NON-NLS-1$
+ assertTrue("not a constructor", methods[0].isConstructor()); //$NON-NLS-1$
+ assertTrue("wrong name", !methods[0].getName().equals("foo")); //$NON-NLS-1$ //$NON-NLS-2$
+ node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a methodDeclaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ assertNull("method binding not null", methodBinding); //$NON-NLS-1$
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a return statement", node.getNodeType() == ASTNode.RETURN_STATEMENT); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ ITypeBinding typeBinding2 = expression.resolveTypeBinding();
+ assertNotNull("no type binding2", typeBinding2); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=14322
+ */
+ public void test0331() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0331", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not an VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a QualifiedName", expression instanceof QualifiedName); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) expression;
+ IBinding binding = qualifiedName.getName().resolveBinding();
+ assertNotNull("no binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.VARIABLE, binding.getKind()); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertTrue("Not a field", variableBinding.isField()); //$NON-NLS-1$
+ assertNull("Got a declaring class", variableBinding.getDeclaringClass()); //$NON-NLS-1$
+ assertEquals("wrong name", "length", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=14403
+ */
+ public void test0332() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0332", "LocalSelectionTransfer.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=13807
+ */
+ public void test0333() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0333", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not an array creation", expression instanceof ArrayCreation); //$NON-NLS-1$
+ ArrayCreation arrayCreation = (ArrayCreation) expression;
+ ITypeBinding typeBinding = arrayCreation.resolveTypeBinding();
+ assertNotNull("no type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[][]", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ArrayType arrayType = arrayCreation.getType();
+ ITypeBinding typeBinding2 = arrayType.resolveBinding();
+ assertNotNull("no type binding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[][]", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Type type = arrayType.getElementType();
+ assertTrue("Not a simple type", type instanceof SimpleType); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type;
+ ITypeBinding typeBinding3 = simpleType.resolveBinding();
+ assertNotNull("no type binding3", typeBinding3); //$NON-NLS-1$
+ assertEquals("wrong name", "Object", typeBinding3.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ type = arrayType.getComponentType();
+ assertTrue("Not an array type", type instanceof ArrayType); //$NON-NLS-1$
+ ArrayType arrayType2 = (ArrayType) type;
+ ITypeBinding typeBinding4 = arrayType2.resolveBinding();
+ assertNotNull("no type binding4", typeBinding4); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[]", typeBinding4.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=13807
+ */
+ public void test0334() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0334", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not an array creation", expression instanceof ArrayCreation); //$NON-NLS-1$
+ ArrayCreation arrayCreation = (ArrayCreation) expression;
+ ITypeBinding typeBinding = arrayCreation.resolveTypeBinding();
+ assertNotNull("no type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[][][]", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ArrayType arrayType = arrayCreation.getType();
+ checkSourceRange(arrayType, "Object[10][][]", source); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = arrayType.resolveBinding();
+ assertNotNull("no type binding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[][][]", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Type type = arrayType.getElementType();
+ assertTrue("Not a simple type", type instanceof SimpleType); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type;
+ checkSourceRange(simpleType, "Object", source); //$NON-NLS-1$
+ ITypeBinding typeBinding3 = simpleType.resolveBinding();
+ assertNotNull("no type binding3", typeBinding3); //$NON-NLS-1$
+ assertEquals("wrong name", "Object", typeBinding3.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ type = arrayType.getComponentType();
+ assertTrue("Not an array type", type instanceof ArrayType); //$NON-NLS-1$
+ ArrayType arrayType2 = (ArrayType) type;
+ checkSourceRange(arrayType2, "Object[10][]", source); //$NON-NLS-1$
+ ITypeBinding typeBinding4 = arrayType2.resolveBinding();
+ assertNotNull("no type binding4", typeBinding4); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[][]", typeBinding4.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ type = arrayType2.getComponentType();
+ assertTrue("Not an array type", type instanceof ArrayType); //$NON-NLS-1$
+ ArrayType arrayType3 = (ArrayType) type;
+ ITypeBinding typeBinding5 = arrayType3.resolveBinding();
+ assertNotNull("no type binding5", typeBinding5); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[]", typeBinding5.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(arrayType3, "Object[10]", source); //$NON-NLS-1$
+ }
+
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=14526
+ */
+ public void test0335() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0335", "ExceptionTestCaseTest.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ assertEquals("errors found", 0, compilationUnit.getProblems().length); //$NON-NLS-1$
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("not a type declaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ Type superclassType = typeDeclaration.getSuperclassType();
+ assertNotNull("no super class", superclassType); //$NON-NLS-1$
+ assertEquals("Wrong type", superclassType.getNodeType(), ASTNode.SIMPLE_TYPE);
+ SimpleType simpleType = (SimpleType) superclassType;
+ Name name = simpleType.getName();
+ assertTrue("not a qualified name", name.isQualifiedName()); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) name;
+ name = qualifiedName.getQualifier();
+ assertTrue("not a qualified name", name.isQualifiedName()); //$NON-NLS-1$
+ qualifiedName = (QualifiedName) name;
+ name = qualifiedName.getQualifier();
+ assertTrue("not a simple name", name.isSimpleName()); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) name;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("no binding", binding); //$NON-NLS-1$
+ assertEquals("wrong type", IBinding.PACKAGE, binding.getKind()); //$NON-NLS-1$
+ assertEquals("wrong name", "junit", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=14526
+ */
+ public void test0336() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0336", "SorterTest.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ assertEquals("errors found", 0, compilationUnit.getProblems().length); //$NON-NLS-1$
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("not a type declaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ List superInterfaces = typeDeclaration.superInterfaceTypes();
+ assertEquals("wrong size", 1, superInterfaces.size()); //$NON-NLS-1$
+ Type type = (Type) superInterfaces.get(0);
+ assertEquals("wrong type", type.getNodeType(), ASTNode.SIMPLE_TYPE);
+ SimpleType simpleType = (SimpleType) type;
+ Name name = simpleType.getName();
+ assertTrue("not a qualified name", name.isQualifiedName()); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) name;
+ name = qualifiedName.getQualifier();
+ assertTrue("not a simple name", name.isSimpleName()); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) name;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("no binding", binding); //$NON-NLS-1$
+ assertEquals("wrong type", IBinding.TYPE, binding.getKind()); //$NON-NLS-1$
+ assertEquals("wrong name", "Sorter", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=14602
+ */
+ public void test0337() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0337", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ checkSourceRange(variableDeclarationFragment, "message= Test.m(\"s\", new String[]{\"g\"})", source); //$NON-NLS-1$
+ checkSourceRange(fieldDeclaration, "String message= Test.m(\"s\", new String[]{\"g\"});", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=14852
+ */
+ public void test0338() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0338", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("not a MethodDeclaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List thrownExceptions = methodDeclaration.thrownExceptions();
+ assertEquals("Wrong size", 1, thrownExceptions.size()); //$NON-NLS-1$
+ Name name = (Name) thrownExceptions.get(0);
+ IBinding binding = name.resolveBinding();
+ assertEquals("wrong type", IBinding.TYPE, binding.getKind()); //$NON-NLS-1$
+ assertEquals("wrong name", "IOException", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=15061
+ */
+ public void test0339() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0339", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("No errors found", 3, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("not a Type declaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("wrong size", 1, bodyDeclarations.size()); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclarations.get(0);
+ checkSourceRange(methodDeclaration, "int doQuery(boolean x);", source); //$NON-NLS-1$
+ node = getASTNode(compilationUnit, 0, 1);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("not a MethodDeclaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ String expectedSource =
+ "public void setX(boolean x) {\n" + //$NON-NLS-1$
+ " {\n" + //$NON-NLS-1$
+ " z\n" + //$NON-NLS-1$
+ " }\n" + //$NON-NLS-1$
+ "}"; //$NON-NLS-1$
+ checkSourceRange(node, expectedSource, source);
+ int methodEndPosition = node.getStartPosition() + node.getLength();
+ node = getASTNode(compilationUnit, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ int typeEndPosition = node.getStartPosition() + node.getLength();
+ assertEquals("different positions", methodEndPosition, typeEndPosition); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=14852
+ */
+ public void test0340() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "p3", "B.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not an method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ assertNotNull("No receiver", expression2); //$NON-NLS-1$
+ ITypeBinding binding = expression2.resolveTypeBinding();
+ assertNotNull("No type binding", binding); //$NON-NLS-1$
+ assertEquals("wrong name", "A", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong name", "p2", binding.getPackage().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("Not a qualified name", expression2.getNodeType() == ASTNode.QUALIFIED_NAME); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) expression2;
+ SimpleName simpleName = qualifiedName.getName();
+ assertEquals("wrong name", "A", simpleName.getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ ITypeBinding typeBinding = simpleName.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("wrong name", "A", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong name", "p2", typeBinding.getPackage().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Name name = qualifiedName.getQualifier();
+ assertTrue("Not a simple name", name.getNodeType() == ASTNode.SIMPLE_NAME); //$NON-NLS-1$
+ SimpleName simpleName2 = (SimpleName) name;
+ assertEquals("wrong name", "p2", simpleName2.getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding2 = simpleName2.resolveBinding();
+ assertNotNull("No binding", binding2); //$NON-NLS-1$
+ assertEquals("wrong type", IBinding.PACKAGE, binding2.getKind()); //$NON-NLS-1$
+ assertEquals("wrong name", "p2", binding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ node = getASTNode(compilationUnit, 0, 1, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement2 = (ExpressionStatement) node;
+ Expression expression3 = expressionStatement2.getExpression();
+ assertTrue("Not an method invocation", expression3.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation2 = (MethodInvocation) expression3;
+ Expression expression4 = methodInvocation2.getExpression();
+ assertNotNull("No receiver", expression4); //$NON-NLS-1$
+ ITypeBinding binding3 = expression4.resolveTypeBinding();
+ assertNotNull("No type binding", binding3); //$NON-NLS-1$
+ assertEquals("wrong name", "A", binding3.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong name", "p1", binding3.getPackage().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=15804
+ */
+ public void test0341() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0341", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an if statement", node.getNodeType() == ASTNode.IF_STATEMENT); //$NON-NLS-1$
+ String expectedSource =
+ "if (field != null) {\n" + //$NON-NLS-1$
+ " throw new IOException();\n" + //$NON-NLS-1$
+ " } else if (field == null) {\n" + //$NON-NLS-1$
+ " throw new MalformedURLException();\n" + //$NON-NLS-1$
+ " } else if (field == null) {\n" + //$NON-NLS-1$
+ " throw new InterruptedIOException();\n" + //$NON-NLS-1$
+ " } else {\n" + //$NON-NLS-1$
+ " throw new UnsupportedEncodingException();\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(node, expectedSource, source);
+ IfStatement ifStatement = (IfStatement) node;
+ Statement thenStatement = ifStatement.getThenStatement();
+ expectedSource =
+ "{\n" + //$NON-NLS-1$
+ " throw new IOException();\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(thenStatement, expectedSource, source);
+ Statement elseStatement = ifStatement.getElseStatement();
+ expectedSource =
+ "if (field == null) {\n" + //$NON-NLS-1$
+ " throw new MalformedURLException();\n" + //$NON-NLS-1$
+ " } else if (field == null) {\n" + //$NON-NLS-1$
+ " throw new InterruptedIOException();\n" + //$NON-NLS-1$
+ " } else {\n" + //$NON-NLS-1$
+ " throw new UnsupportedEncodingException();\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(elseStatement, expectedSource, source);
+ assertTrue("Not a if statement", elseStatement.getNodeType() == ASTNode.IF_STATEMENT); //$NON-NLS-1$
+ ifStatement = (IfStatement) elseStatement;
+ thenStatement = ifStatement.getThenStatement();
+ expectedSource =
+ "{\n" + //$NON-NLS-1$
+ " throw new MalformedURLException();\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(thenStatement, expectedSource, source);
+ elseStatement = ifStatement.getElseStatement();
+ expectedSource =
+ "if (field == null) {\n" + //$NON-NLS-1$
+ " throw new InterruptedIOException();\n" + //$NON-NLS-1$
+ " } else {\n" + //$NON-NLS-1$
+ " throw new UnsupportedEncodingException();\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(elseStatement, expectedSource, source);
+ assertTrue("Not a if statement", elseStatement.getNodeType() == ASTNode.IF_STATEMENT); //$NON-NLS-1$
+ ifStatement = (IfStatement) elseStatement;
+ thenStatement = ifStatement.getThenStatement();
+ expectedSource =
+ "{\n" + //$NON-NLS-1$
+ " throw new InterruptedIOException();\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(thenStatement, expectedSource, source);
+ elseStatement = ifStatement.getElseStatement();
+ expectedSource =
+ "{\n" + //$NON-NLS-1$
+ " throw new UnsupportedEncodingException();\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(elseStatement, expectedSource, source);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=15657
+ * @deprecated marked deprecated to suppress JDOM-related deprecation warnings
+ */
+ public void test0342() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0342", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IDOMCompilationUnit dcompUnit = new DOMFactory().createCompilationUnit(sourceUnit.getSource(), sourceUnit.getElementName());
+ assertNotNull("dcompUnit is null", dcompUnit); //$NON-NLS-1$
+
+ // searching class
+ IDOMType classNode = null;
+ Enumeration children = dcompUnit.getChildren();
+ assertNotNull("dcompUnit has no children", children); //$NON-NLS-1$
+
+ while (children.hasMoreElements()) {
+ IDOMNode child = (IDOMNode) children.nextElement();
+ if (child.getNodeType() == IDOMNode.TYPE) {
+ classNode = (IDOMType) child;
+ break;
+ }
+ }
+ assertNotNull("classNode is null", classNode); //$NON-NLS-1$
+
+ // searching for methods
+ children = classNode.getChildren();
+
+ assertNotNull("classNode has no children", children); //$NON-NLS-1$
+
+ while (children.hasMoreElements()) {
+ IDOMNode child = (IDOMNode) children.nextElement();
+ if (child.getNodeType() == IDOMNode.METHOD) {
+ IDOMMethod childMethod = (IDOMMethod) child;
+
+ // returnType is always null;
+ String returnType = childMethod.getReturnType();
+ if (childMethod.isConstructor()) {
+ assertNull(returnType);
+ } else {
+ assertNotNull("no return type", returnType); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=16051
+ */
+ public void test0343() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0343", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 1);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an if statement", node.getNodeType() == ASTNode.IF_STATEMENT); //$NON-NLS-1$
+ String expectedSource =
+ "if (flag)\n" + //$NON-NLS-1$
+ " i= 10;"; //$NON-NLS-1$
+ checkSourceRange(node, expectedSource, source);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=16132
+ */
+ public void test0344() throws JavaModelException {
+ IJavaProject project = null;
+ String pb_assert = null;
+ String compiler_source = null;
+ String compiler_compliance = null;
+ try {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0344", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ project = sourceUnit.getJavaProject();
+ pb_assert = project.getOption(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, true);
+ compiler_source = project.getOption(JavaCore.COMPILER_SOURCE, true);
+ compiler_compliance = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
+ project.setOption(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR);
+ project.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4);
+ project.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4);
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ } finally {
+ if (project != null) {
+ project.setOption(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, pb_assert);
+ project.setOption(JavaCore.COMPILER_SOURCE, compiler_source);
+ project.setOption(JavaCore.COMPILER_COMPLIANCE, compiler_compliance);
+ }
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=17922
+ */
+ public void test0345() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0345", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not an ArrayCreation", expression.getNodeType() == ASTNode.ARRAY_CREATION); //$NON-NLS-1$
+ ArrayCreation arrayCreation = (ArrayCreation) expression;
+ ArrayType arrayType = arrayCreation.getType();
+ IBinding binding2 = arrayType.resolveBinding();
+ assertNotNull("no binding2", binding2); //$NON-NLS-1$
+ assertEquals("not a type", binding2.getKind(), IBinding.TYPE); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = (ITypeBinding) binding2;
+ assertTrue("Not an array type binding2", typeBinding2.isArray()); //$NON-NLS-1$
+ Type type = arrayType.getElementType();
+ assertTrue("Not a simple type", type.isSimpleType()); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type;
+ Name name = simpleType.getName();
+ assertTrue("QualifiedName", name.getNodeType() == ASTNode.QUALIFIED_NAME); //$NON-NLS-1$
+ SimpleName simpleName = ((QualifiedName) name).getName();
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("no binding", binding); //$NON-NLS-1$
+ assertEquals("not a type", binding.getKind(), IBinding.TYPE); //$NON-NLS-1$
+ ITypeBinding typeBinding = (ITypeBinding) binding;
+ assertTrue("An array type binding", !typeBinding.isArray()); //$NON-NLS-1$
+ Type type2 = fieldDeclaration.getType();
+ assertTrue("Not a array type", type2.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType2 = (ArrayType) type2;
+ Type type3 = arrayType2.getElementType();
+ assertTrue("Not a simple type", type3.isSimpleType()); //$NON-NLS-1$
+ SimpleType simpleType2 = (SimpleType) type3;
+ Name name2 = simpleType2.getName();
+ assertTrue("Not a qualified name", name2.getNodeType() == ASTNode.QUALIFIED_NAME); //$NON-NLS-1$
+ SimpleName simpleName2 = ((QualifiedName) name2).getName();
+ IBinding binding3 = simpleName2.resolveBinding();
+ assertNotNull("no binding", binding3); //$NON-NLS-1$
+ assertEquals("not a type", binding3.getKind(), IBinding.TYPE); //$NON-NLS-1$
+ ITypeBinding typeBinding3 = (ITypeBinding) binding3;
+ assertTrue("An array type binding", !typeBinding3.isArray()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=18138
+ */
+ public void test0346() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0346", "Test2.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an variable declaration", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ checkSourceRange(type, "Vector", source); //$NON-NLS-1$
+ assertTrue("not an array type", !type.isArrayType()); //$NON-NLS-1$
+ assertTrue("Not a simple type", type.isSimpleType()); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type;
+ Name name = simpleType.getName();
+ assertTrue("Not a simpleName", name.isSimpleName()); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) name;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.TYPE, binding.getKind()); //$NON-NLS-1$
+ ITypeBinding typeBinding = (ITypeBinding) binding;
+ assertTrue("An array", !typeBinding.isArray()); //$NON-NLS-1$
+ assertEquals("Wrong name", "Vector", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ITypeBinding typeBinding2 = simpleType.resolveBinding();
+ assertNotNull("No binding", typeBinding2); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.TYPE, typeBinding2.getKind()); //$NON-NLS-1$
+ assertTrue("An array", !typeBinding2.isArray()); //$NON-NLS-1$
+ assertEquals("Wrong name", "Vector", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=18138
+ */
+ public void test0347() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0347", "Test2.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an variable declaration", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ checkSourceRange(type, "Vector[]", source); //$NON-NLS-1$
+ assertTrue("not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ ITypeBinding binding = arrayType.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.TYPE, binding.getKind()); //$NON-NLS-1$
+ assertTrue("Not an array type", binding.isArray()); //$NON-NLS-1$
+ assertEquals("Wrong name", "Vector[]", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=18138
+ */
+ public void test0348() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0348", "Test2.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an variable declaration", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ checkSourceRange(type, "Vector[][]", source); //$NON-NLS-1$
+ assertTrue("not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ ITypeBinding binding = arrayType.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.TYPE, binding.getKind()); //$NON-NLS-1$
+ assertTrue("Not an array type", binding.isArray()); //$NON-NLS-1$
+ assertEquals("Wrong name", "Vector[][]", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=18138
+ */
+ public void test0349() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0349", "Test2.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ Type type = fieldDeclaration.getType();
+ checkSourceRange(type, "Vector[][]", source); //$NON-NLS-1$
+ assertTrue("not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ ITypeBinding binding = arrayType.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.TYPE, binding.getKind()); //$NON-NLS-1$
+ assertTrue("Not an array type", binding.isArray()); //$NON-NLS-1$
+ assertEquals("Wrong name", "Vector[][]", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=18138
+ */
+ public void test0350() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0350", "Test2.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ Type type = fieldDeclaration.getType();
+ checkSourceRange(type, "Vector", source); //$NON-NLS-1$
+ assertTrue("not a simple type", type.isSimpleType()); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type;
+ ITypeBinding binding = simpleType.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.TYPE, binding.getKind()); //$NON-NLS-1$
+ assertTrue("An array type", binding.isClass()); //$NON-NLS-1$
+ assertEquals("Wrong name", "Vector", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=18169
+ */
+ public void test0351() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0351", "Test2.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ assertEquals("wrong size", 2, parameters.size()); //$NON-NLS-1$
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ checkSourceRange(singleVariableDeclaration, "int a", source); //$NON-NLS-1$
+ singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(1);
+ checkSourceRange(singleVariableDeclaration, "int[] b", source); //$NON-NLS-1$
+ node = getASTNode(compilationUnit, 0, 1);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ parameters = methodDeclaration.parameters();
+ assertEquals("wrong size", 2, parameters.size()); //$NON-NLS-1$
+ singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ checkSourceRange(singleVariableDeclaration, "int a", source); //$NON-NLS-1$
+ singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(1);
+ checkSourceRange(singleVariableDeclaration, "int b[]", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=18169
+ */
+ public void test0352() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0352", "Test2.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ assertEquals("wrong size", 2, parameters.size()); //$NON-NLS-1$
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ checkSourceRange(singleVariableDeclaration, "final int a", source); //$NON-NLS-1$
+ singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(1);
+ checkSourceRange(singleVariableDeclaration, "final int[] b", source); //$NON-NLS-1$
+ node = getASTNode(compilationUnit, 0, 1);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ parameters = methodDeclaration.parameters();
+ assertEquals("wrong size", 2, parameters.size()); //$NON-NLS-1$
+ singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ checkSourceRange(singleVariableDeclaration, "final int a", source); //$NON-NLS-1$
+ singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(1);
+ checkSourceRange(singleVariableDeclaration, "final int b[]", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=18042
+ */
+ public void test0353() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0353", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an variable declaration", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ checkSourceRange(type, "InputStream", source); //$NON-NLS-1$
+ assertTrue("not a simple type", type.isSimpleType()); //$NON-NLS-1$
+ ITypeBinding binding = type.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.TYPE, binding.getKind()); //$NON-NLS-1$
+ assertTrue("Not a class", binding.isClass()); //$NON-NLS-1$
+ assertEquals("Wrong name", "InputStream", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong package", "java.io", binding.getPackage().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ SimpleType simpleType = (SimpleType) type;
+ Name name = simpleType.getName();
+ IBinding binding2 = name.resolveBinding();
+ assertNotNull("No binding", binding2); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.TYPE, binding2.getKind()); //$NON-NLS-1$
+ ITypeBinding typeBinding = (ITypeBinding) binding2;
+ assertTrue("Not a class", typeBinding.isClass()); //$NON-NLS-1$
+ assertEquals("Wrong name", "InputStream", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong package", "java.io", typeBinding.getPackage().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=19851
+ */
+ public void test0354() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0354", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 2, compilationUnit.getMessages().length); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=20520
+ */
+ public void test0355() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0355", "Foo.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not an if statement", node.getNodeType() == ASTNode.IF_STATEMENT); //$NON-NLS-1$
+ IfStatement ifStatement = (IfStatement) node;
+ Expression condition = ifStatement.getExpression();
+ assertTrue("Not an infixExpression", condition.getNodeType() == ASTNode.INFIX_EXPRESSION); //$NON-NLS-1$
+ InfixExpression infixExpression = (InfixExpression) condition;
+ Expression expression = infixExpression.getLeftOperand();
+ assertTrue("Not a method invocation expression", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ assertTrue("Not a parenthesis expression", expression2.getNodeType() == ASTNode.PARENTHESIZED_EXPRESSION); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=20865
+ */
+ public void test0356() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0356", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 1, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ ITypeBinding binding = type.resolveBinding();
+ assertNotNull("Binding should NOT be null for type: "+type, binding);
+
+ // Verify that class instance creation has a null binding
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("Expect only one fragment for VariableDeclarationStatement: "+variableDeclarationStatement, 1, fragments.size());
+ node = (ASTNode) fragments.get(0);
+ assertEquals("Not a variable declaration fragment", ASTNode.VARIABLE_DECLARATION_FRAGMENT, node.getNodeType()); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) node;
+ Expression initializer = fragment.getInitializer();
+ assertEquals("Expect a class instance creation for initializer: "+initializer, ASTNode.CLASS_INSTANCE_CREATION, initializer.getNodeType()); //$NON-NLS-1$
+ ClassInstanceCreation instanceCreation = (ClassInstanceCreation) initializer;
+ type = instanceCreation.getType();
+ binding = type.resolveBinding();
+ assertNull("Binding should BE null for type: "+type, binding);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=21757
+ */
+ public void test0357() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0357", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertNotNull(node);
+ assertTrue("Not a type declaration statement", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ SimpleName name = typeDeclaration.getName();
+ checkSourceRange(name, "A", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=21768
+ */
+ public void test0358() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0358", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0,0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration statement", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ SimpleName name = methodDeclaration.getName();
+ checkSourceRange(name, "mdd", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=21768
+ */
+ public void test0359() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0359", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0,0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration statement", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ SimpleName name = methodDeclaration.getName();
+ checkSourceRange(name, "mdd", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=21916
+ */
+ public void test0360() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0360", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0,0, 0);
+ assertNotNull(node);
+ assertTrue("Not a for statement", node.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node;
+ List initializers = forStatement.initializers();
+ assertEquals("Wrong size", 1, initializers.size()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=21916
+ */
+ public void test0361() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0361", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0,0, 0);
+ assertNotNull(node);
+ assertTrue("Not a for statement", node.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node;
+ List initializers = forStatement.initializers();
+ assertEquals("Wrong size", 1, initializers.size()); //$NON-NLS-1$
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=21916
+ */
+ public void test0362() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0362", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ForStatement forStatement = this.ast.newForStatement();
+
+ VariableDeclarationFragment iFragment = this.ast.newVariableDeclarationFragment();
+ iFragment.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ iFragment.setInitializer(this.ast.newNumberLiteral("0"));//$NON-NLS-1$
+ VariableDeclarationFragment jFragment = this.ast.newVariableDeclarationFragment();
+ jFragment.setName(this.ast.newSimpleName("j")); //$NON-NLS-1$
+ jFragment.setInitializer(this.ast.newNumberLiteral("0"));//$NON-NLS-1$
+ VariableDeclarationFragment kFragment = this.ast.newVariableDeclarationFragment();
+ kFragment.setName(this.ast.newSimpleName("k")); //$NON-NLS-1$
+ kFragment.setInitializer(this.ast.newNumberLiteral("0"));//$NON-NLS-1$
+
+ VariableDeclarationExpression variableDeclarationExpression = this.ast.newVariableDeclarationExpression(iFragment);
+ variableDeclarationExpression.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+ variableDeclarationExpression.fragments().add(jFragment);
+ variableDeclarationExpression.fragments().add(kFragment);
+ forStatement.initializers().add(variableDeclarationExpression);
+
+ PostfixExpression iPostfixExpression = this.ast.newPostfixExpression();
+ iPostfixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ iPostfixExpression.setOperator(PostfixExpression.Operator.INCREMENT);
+ forStatement.updaters().add(iPostfixExpression);
+
+ PostfixExpression jPostfixExpression = this.ast.newPostfixExpression();
+ jPostfixExpression.setOperand(this.ast.newSimpleName("j"));//$NON-NLS-1$
+ jPostfixExpression.setOperator(PostfixExpression.Operator.INCREMENT);
+ forStatement.updaters().add(jPostfixExpression);
+
+ PostfixExpression kPostfixExpression = this.ast.newPostfixExpression();
+ kPostfixExpression.setOperand(this.ast.newSimpleName("k"));//$NON-NLS-1$
+ kPostfixExpression.setOperator(PostfixExpression.Operator.INCREMENT);
+ forStatement.updaters().add(kPostfixExpression);
+
+ forStatement.setBody(this.ast.newBlock());
+
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.LESS);
+ infixExpression.setRightOperand(this.ast.newNumberLiteral("10")); //$NON-NLS-1$
+ forStatement.setExpression(infixExpression);
+
+ assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "for (int i=0, j=0, k=0; i<10 ; i++, j++, k++) {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22939
+ */
+ public void test0363() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0363", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 1);
+ assertNotNull(node);
+ assertTrue("Not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a parenthesized expression", expression.getNodeType() == ASTNode.PARENTHESIZED_EXPRESSION); //$NON-NLS-1$
+ Expression expression2 = ((ParenthesizedExpression) expression).getExpression();
+ checkSourceRange(expression2, "xxxx", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11529
+ */
+ public void test0364() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0364", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ checkSourceRange(variableDeclarationStatement, "int local;", source); //$NON-NLS-1$
+ SimpleName simpleName = variableDeclarationFragment.getName();
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11529
+ */
+ public void test0365() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0365", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a for statement", node.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node;
+ List initializers = forStatement.initializers();
+ assertEquals("Wrong size", 1, initializers.size()); //$NON-NLS-1$
+ VariableDeclarationExpression variableDeclarationExpression = (VariableDeclarationExpression) initializers.get(0);
+ List fragments = variableDeclarationExpression.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ SimpleName simpleName = variableDeclarationFragment.getName();
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23048
+ */
+ public void test0366() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0366", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a for statement", node.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node;
+ checkSourceRange(forStatement, "for (int i = 0; i < 5; ++i);", source); //$NON-NLS-1$
+ Statement statement = forStatement.getBody();
+ assertTrue("Not an empty statement", statement.getNodeType() == ASTNode.EMPTY_STATEMENT); //$NON-NLS-1$
+ checkSourceRange(statement, ";", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23048
+ */
+ public void test0367() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0367", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a while statement", node.getNodeType() == ASTNode.WHILE_STATEMENT); //$NON-NLS-1$
+ WhileStatement whileStatement = (WhileStatement) node;
+ checkSourceRange(whileStatement, "while(i == 2);", source); //$NON-NLS-1$
+ Statement statement = whileStatement.getBody();
+ assertTrue("Not an empty statement", statement.getNodeType() == ASTNode.EMPTY_STATEMENT); //$NON-NLS-1$
+ checkSourceRange(statement, ";", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23048
+ */
+ public void test0368() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0368", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 1, "The label test is never explicitly referenced"); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a labeled statement", node.getNodeType() == ASTNode.LABELED_STATEMENT); //$NON-NLS-1$
+ LabeledStatement labeledStatement = (LabeledStatement) node;
+ checkSourceRange(labeledStatement, "test:;", source); //$NON-NLS-1$
+ Statement statement = labeledStatement.getBody();
+ assertTrue("Not an empty statement", statement.getNodeType() == ASTNode.EMPTY_STATEMENT); //$NON-NLS-1$
+ checkSourceRange(statement, ";", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23048
+ */
+ public void test0369() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0369", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 1, "The label test is never explicitly referenced"); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a labeled statement", node.getNodeType() == ASTNode.LABELED_STATEMENT); //$NON-NLS-1$
+ LabeledStatement labeledStatement = (LabeledStatement) node;
+ checkSourceRange(labeledStatement, "test:\\u003B", source); //$NON-NLS-1$
+ Statement statement = labeledStatement.getBody();
+ assertTrue("Not an empty statement", statement.getNodeType() == ASTNode.EMPTY_STATEMENT); //$NON-NLS-1$
+ checkSourceRange(statement, "\\u003B", source); //$NON-NLS-1$
+ }
+
+ /**
+ * DoStatement ==> DoStatement
+ */
+ public void test0370() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0370", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ DoStatement doStatement = this.ast.newDoStatement();
+ doStatement.setBody(this.ast.newEmptyStatement());
+ doStatement.setExpression(this.ast.newBooleanLiteral(true));
+ assertTrue("Both AST trees should be identical", doStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ String expectedSource = "do ; while(true);";//$NON-NLS-1$
+ checkSourceRange(node, expectedSource, source);
+ DoStatement doStatement2 = (DoStatement) node;
+ Statement statement = doStatement2.getBody();
+ assertTrue("Not an empty statement", statement.getNodeType() == ASTNode.EMPTY_STATEMENT); //$NON-NLS-1$
+ checkSourceRange(statement, ";", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23048
+ */
+ public void test0371() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0371", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a labeled statement", node.getNodeType() == ASTNode.IF_STATEMENT); //$NON-NLS-1$
+ IfStatement ifStatement = (IfStatement) node;
+ checkSourceRange(ifStatement, "if (i == 6);", source); //$NON-NLS-1$
+ Statement statement = ifStatement.getThenStatement();
+ assertTrue("Not an empty statement", statement.getNodeType() == ASTNode.EMPTY_STATEMENT); //$NON-NLS-1$
+ checkSourceRange(statement, ";", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23048
+ */
+ public void test0372() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0372", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a labeled statement", node.getNodeType() == ASTNode.IF_STATEMENT); //$NON-NLS-1$
+ IfStatement ifStatement = (IfStatement) node;
+ checkSourceRange(ifStatement, "if (i == 6) {} else ;", source); //$NON-NLS-1$
+ Statement statement = ifStatement.getElseStatement();
+ assertTrue("Not an empty statement", statement.getNodeType() == ASTNode.EMPTY_STATEMENT); //$NON-NLS-1$
+ checkSourceRange(statement, ";", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23118
+ */
+ public void test0373() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0373", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 1, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a for statement", node.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node;
+ Statement statement = forStatement.getBody();
+ assertTrue("Not a block statement", statement.getNodeType() == ASTNode.BLOCK); //$NON-NLS-1$
+ Block block = (Block) statement;
+ List statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement statement2 = (Statement) statements.get(0);
+ assertTrue("Not a break statement", statement2.getNodeType() == ASTNode.BREAK_STATEMENT); //$NON-NLS-1$
+ BreakStatement breakStatement = (BreakStatement) statement2;
+ checkSourceRange(breakStatement, "break;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23118
+ */
+ public void test0374() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0374", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a for statement", node.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node;
+ Statement statement = forStatement.getBody();
+ assertTrue("Not a block statement", statement.getNodeType() == ASTNode.BLOCK); //$NON-NLS-1$
+ Block block = (Block) statement;
+ List statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement statement2 = (Statement) statements.get(0);
+ assertTrue("Not a break statement", statement2.getNodeType() == ASTNode.CONTINUE_STATEMENT); //$NON-NLS-1$
+ ContinueStatement continueStatement = (ContinueStatement) statement2;
+ checkSourceRange(continueStatement, "continue;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23052
+ */
+ public void test0375() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0375", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("problems found", 1, compilationUnit.getMessages().length); //$NON-NLS-1$
+ List imports = compilationUnit.imports();
+ assertEquals("wrong size", 1, imports.size()); //$NON-NLS-1$
+ ImportDeclaration importDeclaration = (ImportDeclaration) imports.get(0);
+ IBinding binding = importDeclaration.resolveBinding();
+ assertNotNull("no binding", binding); //$NON-NLS-1$
+ assertEquals("Not a type binding", IBinding.TYPE, binding.getKind()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22939
+ */
+ public void test0376() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0376", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a cast expression", expression.getNodeType() == ASTNode.CAST_EXPRESSION); //$NON-NLS-1$
+ Type type = ((CastExpression) expression).getType();
+ checkSourceRange(type, "A", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23050
+ */
+ public void test0377() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0377", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = variableDeclarationFragment.resolveBinding();
+ assertNotNull("No variable binding", variableBinding); //$NON-NLS-1$
+ assertEquals("Wrong modifier", IModifierConstants.ACC_FINAL, variableBinding.getModifiers()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22161
+ */
+ public void test0378() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0378", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ SimpleName name = typeDeclaration.getName();
+ checkSourceRange(name, "B", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22161
+ */
+ public void test0379() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0379", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ assertTrue("Not a class instance creation", expression.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation2 = (ClassInstanceCreation) expression;
+ Type type = classInstanceCreation2.getType();
+ checkSourceRange(type, "Object", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22054
+ */
+ public void test0380() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0380", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a return statement", node.getNodeType() == ASTNode.RETURN_STATEMENT); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertTrue("Not a super method invocation", expression.getNodeType() == ASTNode.SUPER_METHOD_INVOCATION); //$NON-NLS-1$
+ SuperMethodInvocation superMethodInvocation = (SuperMethodInvocation) expression;
+ ITypeBinding typeBinding = superMethodInvocation.resolveTypeBinding();
+ assertNotNull("no type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("wrong declaring class", typeBinding.getSuperclass().getName(), "Object"); //$NON-NLS-1$ //$NON-NLS-2$
+ SimpleName simpleName = superMethodInvocation.getName();
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("no binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.METHOD, binding.getKind()); //$NON-NLS-1$
+ IMethodBinding methodBinding = (IMethodBinding) binding;
+ assertEquals("Wrong declaring class", methodBinding.getDeclaringClass().getName(), "Object"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23054
+ */
+ public void test0381() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0381", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertNotNull(node);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ Javadoc javadoc = typeDeclaration.getJavadoc();
+ assertNull("Javadoc not null", javadoc); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22154
+ */
+ public void test0382() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0382", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertNotNull(node);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertEquals("Wrong fully qualified name", typeBinding.getQualifiedName(), "test0382.A"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22154
+ */
+ public void test0383() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0383", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertEquals("Wrong fully qualified name", typeBinding.getQualifiedName(), "test0383.A.B"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22154
+ */
+ public void test0384() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0384", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertEquals("Wrong fully qualified name", typeBinding.getQualifiedName(), "test0384.A.B.D"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23117
+ */
+ public void test0385() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0385", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 1, compilationUnit.getMessages().length); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23259
+ */
+ public void test0386() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0386", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a switch statement", node.getNodeType() == ASTNode.SWITCH_STATEMENT); //$NON-NLS-1$
+ SwitchStatement switchStatement = (SwitchStatement) node;
+ List statements = switchStatement.statements();
+ assertEquals("Wrong size", 5, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("Not a case statement", statement.getNodeType() == ASTNode.SWITCH_CASE); //$NON-NLS-1$
+ checkSourceRange(statement, "case 1:", source); //$NON-NLS-1$
+ statement = (Statement) statements.get(3);
+ assertTrue("Not a default case statement", statement.getNodeType() == ASTNode.SWITCH_CASE); //$NON-NLS-1$
+ checkSourceRange(statement, "default :", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22939
+ */
+ public void test0387() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0387", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a cast expression", expression.getNodeType() == ASTNode.CAST_EXPRESSION); //$NON-NLS-1$
+ Type type = ((CastExpression) expression).getType();
+ checkSourceRange(type, "A", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22154
+ */
+ public void test0388() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0388", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertNotNull(node);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong qualified name", "test0388.A", typeBinding.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22154
+ */
+ public void test0389() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0389", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong qualified name", "test0389.A.B", typeBinding.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22154
+ */
+ public void test0390() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0390", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Type type = methodDeclaration.getReturnType2();
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong qualified name", "int", typeBinding.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22154
+ */
+ public void test0391() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0391", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Type type = methodDeclaration.getReturnType2();
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong qualified name", "int[]", typeBinding.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22154
+ */
+ public void test0392() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0392", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Type type = methodDeclaration.getReturnType2();
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong qualified name", "java.lang.String[]", typeBinding.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23284
+ */
+ public void test0393() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0393", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Type type = methodDeclaration.getReturnType2();
+ checkSourceRange(type, "String", source); //$NON-NLS-1$
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong dimension", 0, typeBinding.getDimensions()); //$NON-NLS-1$
+ assertEquals("Wrong qualified name", "java.lang.String", typeBinding.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong dimension", 1, methodDeclaration.getExtraDimensions()); //$NON-NLS-1$
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ assertNotNull("No method binding", methodBinding); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = methodBinding.getReturnType();
+ assertNotNull("No type binding", typeBinding2); //$NON-NLS-1$
+ assertEquals("Wrong qualified name", "java.lang.String[]", typeBinding2.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong dimension", 1, typeBinding2.getDimensions()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23284
+ */
+ public void test0394() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0394", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Type type = methodDeclaration.getReturnType2();
+ checkSourceRange(type, "String", source); //$NON-NLS-1$
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong qualified name", "java.lang.String", typeBinding.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong dimension", 0, methodDeclaration.getExtraDimensions()); //$NON-NLS-1$
+ }
+
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23284
+ */
+ public void test0395() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0395", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Type type = methodDeclaration.getReturnType2();
+ checkSourceRange(type, "String[]", source); //$NON-NLS-1$
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong dimension", 1, typeBinding.getDimensions()); //$NON-NLS-1$
+ assertEquals("Wrong qualified name", "java.lang.String[]", typeBinding.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong dimension", 1, methodDeclaration.getExtraDimensions()); //$NON-NLS-1$
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ assertNotNull("No method binding", methodBinding); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = methodBinding.getReturnType();
+ assertNotNull("No type binding", typeBinding2); //$NON-NLS-1$
+ assertEquals("Wrong qualified name", "java.lang.String[][]", typeBinding2.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong dimension", 2, typeBinding2.getDimensions()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23284
+ */
+ public void test0396() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0396", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration method = (MethodDeclaration) node;
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) method.parameters().get(0);
+ assertNotNull("Expression should not be null", singleVariableDeclaration); //$NON-NLS-1$
+ checkSourceRange(singleVariableDeclaration, "final String s[]", source); //$NON-NLS-1$
+ Type type = singleVariableDeclaration.getType();
+ checkSourceRange(type, "String", source); //$NON-NLS-1$
+ assertEquals("Wrong dimension", 1, singleVariableDeclaration.getExtraDimensions()); //$NON-NLS-1$
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertTrue("An array binding", !typeBinding.isArray()); //$NON-NLS-1$
+ assertEquals("Wrong dimension", 0, typeBinding.getDimensions()); //$NON-NLS-1$
+ assertEquals("wrong fully qualified name", "java.lang.String", typeBinding.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IVariableBinding variableBinding = singleVariableDeclaration.resolveBinding();
+ assertNotNull("No variable binding", variableBinding); //$NON-NLS-1$
+ assertTrue("Is a parameter", variableBinding.isParameter());
+ ITypeBinding typeBinding2 = variableBinding.getType();
+ assertNotNull("No type binding", typeBinding2); //$NON-NLS-1$
+ assertTrue("Not an array binding", typeBinding2.isArray()); //$NON-NLS-1$
+ assertEquals("Wrong dimension", 1, typeBinding2.getDimensions()); //$NON-NLS-1$
+ assertEquals("wrong fully qualified name", "java.lang.String[]", typeBinding2.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23284
+ */
+ public void test0397() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0397", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration method = (MethodDeclaration) node;
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) method.parameters().get(0);
+ assertNotNull("Expression should not be null", singleVariableDeclaration); //$NON-NLS-1$
+ checkSourceRange(singleVariableDeclaration, "final String[] \\u0073\\u005B][]", source); //$NON-NLS-1$
+ Type type = singleVariableDeclaration.getType();
+ checkSourceRange(type, "String[]", source); //$NON-NLS-1$
+ assertEquals("Wrong dimension", 2, singleVariableDeclaration.getExtraDimensions()); //$NON-NLS-1$
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertTrue("Not an array binding", typeBinding.isArray()); //$NON-NLS-1$
+ assertEquals("Wrong dimension", 1, typeBinding.getDimensions()); //$NON-NLS-1$
+ assertEquals("wrong fully qualified name", "java.lang.String[]", typeBinding.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IVariableBinding variableBinding = singleVariableDeclaration.resolveBinding();
+ assertNotNull("No variable binding", variableBinding); //$NON-NLS-1$
+ assertTrue("Is a parameter", variableBinding.isParameter());
+ ITypeBinding typeBinding2 = variableBinding.getType();
+ assertNotNull("No type binding", typeBinding2); //$NON-NLS-1$
+ assertTrue("Not an array binding", typeBinding2.isArray()); //$NON-NLS-1$
+ assertEquals("Wrong dimension", 3, typeBinding2.getDimensions()); //$NON-NLS-1$
+ assertEquals("wrong fully qualified name", "java.lang.String[][][]", typeBinding2.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23362
+ */
+ public void test0398() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0398", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not an infix expression", expression.getNodeType() == ASTNode.INFIX_EXPRESSION); //$NON-NLS-1$
+ InfixExpression infixExpression = (InfixExpression) expression;
+ checkSourceRange(infixExpression, "(1 + 2) * 3", source); //$NON-NLS-1$
+ Expression expression2 = infixExpression.getLeftOperand();
+ assertTrue("Not an parenthesis expression", expression2.getNodeType() == ASTNode.PARENTHESIZED_EXPRESSION); //$NON-NLS-1$
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression2;
+ Expression expression3 = parenthesizedExpression.getExpression();
+ assertTrue("Not an infix expression", expression3.getNodeType() == ASTNode.INFIX_EXPRESSION); //$NON-NLS-1$
+ checkSourceRange(expression3, "1 + 2", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22306
+ */
+ public void test0399() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0399", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Not a constructor", methodDeclaration.isConstructor()); //$NON-NLS-1$
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("wrong size", 2, statements.size()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22306
+ */
+ public void test0400() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0400", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Not a constructor", methodDeclaration.isConstructor()); //$NON-NLS-1$
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("wrong size", 3, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("Not an superconstructorinvocation", statement.getNodeType() == ASTNode.SUPER_CONSTRUCTOR_INVOCATION); //$NON-NLS-1$
+ checkSourceRange(statement, "super();", source); //$NON-NLS-1$
+ }
+}
+
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterBindingsTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterBindingsTest.java
new file mode 100644
index 0000000..81e2ce6
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterBindingsTest.java
@@ -0,0 +1,558 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2009 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.dom;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import junit.framework.Test;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.ASTVisitor;
+import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
+import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration;
+import org.eclipse.jdt.core.dom.AnnotationTypeMemberDeclaration;
+import org.eclipse.jdt.core.dom.AnonymousClassDeclaration;
+import org.eclipse.jdt.core.dom.ArrayAccess;
+import org.eclipse.jdt.core.dom.ArrayCreation;
+import org.eclipse.jdt.core.dom.ArrayInitializer;
+import org.eclipse.jdt.core.dom.ArrayType;
+import org.eclipse.jdt.core.dom.Assignment;
+import org.eclipse.jdt.core.dom.BooleanLiteral;
+import org.eclipse.jdt.core.dom.CastExpression;
+import org.eclipse.jdt.core.dom.CharacterLiteral;
+import org.eclipse.jdt.core.dom.ClassInstanceCreation;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.ConditionalExpression;
+import org.eclipse.jdt.core.dom.ConstructorInvocation;
+import org.eclipse.jdt.core.dom.EnumConstantDeclaration;
+import org.eclipse.jdt.core.dom.EnumDeclaration;
+import org.eclipse.jdt.core.dom.FieldAccess;
+import org.eclipse.jdt.core.dom.IBinding;
+import org.eclipse.jdt.core.dom.IMethodBinding;
+import org.eclipse.jdt.core.dom.IPackageBinding;
+import org.eclipse.jdt.core.dom.ITypeBinding;
+import org.eclipse.jdt.core.dom.IVariableBinding;
+import org.eclipse.jdt.core.dom.ImportDeclaration;
+import org.eclipse.jdt.core.dom.InfixExpression;
+import org.eclipse.jdt.core.dom.InstanceofExpression;
+import org.eclipse.jdt.core.dom.MemberRef;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.MethodInvocation;
+import org.eclipse.jdt.core.dom.MethodRef;
+import org.eclipse.jdt.core.dom.NullLiteral;
+import org.eclipse.jdt.core.dom.NumberLiteral;
+import org.eclipse.jdt.core.dom.PackageDeclaration;
+import org.eclipse.jdt.core.dom.ParameterizedType;
+import org.eclipse.jdt.core.dom.ParenthesizedExpression;
+import org.eclipse.jdt.core.dom.PostfixExpression;
+import org.eclipse.jdt.core.dom.PrefixExpression;
+import org.eclipse.jdt.core.dom.PrimitiveType;
+import org.eclipse.jdt.core.dom.QualifiedName;
+import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.dom.SimpleType;
+import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
+import org.eclipse.jdt.core.dom.StringLiteral;
+import org.eclipse.jdt.core.dom.SuperConstructorInvocation;
+import org.eclipse.jdt.core.dom.SuperFieldAccess;
+import org.eclipse.jdt.core.dom.SuperMethodInvocation;
+import org.eclipse.jdt.core.dom.ThisExpression;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
+import org.eclipse.jdt.core.dom.TypeLiteral;
+import org.eclipse.jdt.core.dom.VariableDeclarationExpression;
+import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+
+public class ASTConverterBindingsTest extends ConverterTestSetup {
+ private static final boolean DEBUG = false;
+
+ static class BindingsCollector extends ASTVisitor {
+
+ public ArrayList arrayList;
+
+ BindingsCollector() {
+ // visit Javadoc.tags() as well
+ super(true);
+ this.arrayList = new ArrayList();
+ }
+
+ private void collectBindings(
+ ASTNode node,
+ IBinding binding) {
+
+ if (binding != null) {
+ this.arrayList.add(binding);
+ }
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(AnnotationTypeDeclaration)
+ * @since 3.0
+ */
+ public void endVisit(AnnotationTypeDeclaration node) {
+ ITypeBinding typeBinding = node.resolveBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(AnnotationTypeMemberDeclaration)
+ * @since 3.0
+ */
+ public void endVisit(AnnotationTypeMemberDeclaration node) {
+ IMethodBinding binding = node.resolveBinding();
+ collectBindings(node, binding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(AnonymousClassDeclaration)
+ */
+ public void endVisit(AnonymousClassDeclaration node) {
+ ITypeBinding typeBinding = node.resolveBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(ArrayAccess)
+ */
+ public void endVisit(ArrayAccess node) {
+ ITypeBinding typeBinding = node.resolveTypeBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(ArrayCreation)
+ */
+ public void endVisit(ArrayCreation node) {
+ ITypeBinding typeBinding = node.resolveTypeBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(ArrayInitializer)
+ */
+ public void endVisit(ArrayInitializer node) {
+ ITypeBinding typeBinding = node.resolveTypeBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(ArrayType)
+ */
+ public void endVisit(ArrayType node) {
+ ITypeBinding typeBinding = node.resolveBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(Assignment)
+ */
+ public void endVisit(Assignment node) {
+ ITypeBinding typeBinding = node.resolveTypeBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(BooleanLiteral)
+ */
+ public void endVisit(BooleanLiteral node) {
+ ITypeBinding typeBinding = node.resolveTypeBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(CastExpression)
+ */
+ public void endVisit(CastExpression node) {
+ ITypeBinding typeBinding = node.resolveTypeBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(CharacterLiteral)
+ */
+ public void endVisit(CharacterLiteral node) {
+ ITypeBinding typeBinding = node.resolveTypeBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(ClassInstanceCreation)
+ */
+ public void endVisit(ClassInstanceCreation node) {
+ ITypeBinding typeBinding = node.resolveTypeBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(ConditionalExpression)
+ */
+ public void endVisit(ConditionalExpression node) {
+ ITypeBinding typeBinding = node.resolveTypeBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(ConstructorInvocation)
+ */
+ public void endVisit(ConstructorInvocation node) {
+ IMethodBinding methodBinding = node.resolveConstructorBinding();
+ collectBindings(node, methodBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(EnumConstantDeclaration)
+ * @since 3.0
+ */
+ public void endVisit(EnumConstantDeclaration node) {
+ IVariableBinding binding = node.resolveVariable();
+ collectBindings(node, binding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(EnumDeclaration)
+ * @since 3.0
+ */
+ public void endVisit(EnumDeclaration node) {
+ ITypeBinding typeBinding = node.resolveBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(FieldAccess)
+ */
+ public void endVisit(FieldAccess node) {
+ ITypeBinding typeBinding = node.resolveTypeBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(ImportDeclaration)
+ */
+ public void endVisit(ImportDeclaration node) {
+ IBinding binding = node.resolveBinding();
+ collectBindings(node, binding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(InfixExpression)
+ */
+ public void endVisit(InfixExpression node) {
+ ITypeBinding typeBinding = node.resolveTypeBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(InstanceofExpression)
+ */
+ public void endVisit(InstanceofExpression node) {
+ ITypeBinding typeBinding = node.resolveTypeBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see ASTVisitor#endVisit(MemberRef)
+ * @since 3.0
+ */
+ public void endVisit(MemberRef node) {
+ IBinding binding = node.resolveBinding();
+ collectBindings(node, binding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(MethodDeclaration)
+ */
+ public void endVisit(MethodDeclaration node) {
+ IMethodBinding methodBinding = node.resolveBinding();
+ collectBindings(node, methodBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(MethodInvocation)
+ */
+ public void endVisit(MethodInvocation node) {
+ ITypeBinding typeBinding = node.resolveTypeBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see ASTVisitor#endVisit(MethodRef )
+ * @since 3.0
+ */
+ public void endVisit(MethodRef node) {
+ IBinding binding = node.resolveBinding();
+ collectBindings(node, binding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(NullLiteral)
+ */
+ public void endVisit(NullLiteral node) {
+ ITypeBinding typeBinding = node.resolveTypeBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(NumberLiteral)
+ */
+ public void endVisit(NumberLiteral node) {
+ ITypeBinding typeBinding = node.resolveTypeBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(PackageDeclaration)
+ */
+ public void endVisit(PackageDeclaration node) {
+ IPackageBinding packageBinding = node.resolveBinding();
+ collectBindings(node, packageBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(ParameterizedType)
+ * @since 3.0
+ */
+ public void endVisit(ParameterizedType node) {
+ ITypeBinding typeBinding = node.resolveBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(ParenthesizedExpression)
+ */
+ public void endVisit(ParenthesizedExpression node) {
+ ITypeBinding typeBinding = node.resolveTypeBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(PostfixExpression)
+ */
+ public void endVisit(PostfixExpression node) {
+ ITypeBinding typeBinding = node.resolveTypeBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(PrefixExpression)
+ */
+ public void endVisit(PrefixExpression node) {
+ ITypeBinding typeBinding = node.resolveTypeBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(PrimitiveType)
+ */
+ public void endVisit(PrimitiveType node) {
+ ITypeBinding typeBinding = node.resolveBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(QualifiedName)
+ */
+ public void endVisit(QualifiedName node) {
+ IBinding binding = node.resolveBinding();
+ collectBindings(node, binding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(SimpleName)
+ */
+ public void endVisit(SimpleName node) {
+ IBinding binding = node.resolveBinding();
+ collectBindings(node, binding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(SimpleType)
+ */
+ public void endVisit(SimpleType node) {
+ ITypeBinding typeBinding = node.resolveBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(SingleVariableDeclaration)
+ */
+ public void endVisit(SingleVariableDeclaration node) {
+ IVariableBinding variableBinding = node.resolveBinding();
+ collectBindings(node, variableBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(StringLiteral)
+ */
+ public void endVisit(StringLiteral node) {
+ ITypeBinding typeBinding = node.resolveTypeBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(SuperConstructorInvocation)
+ */
+ public void endVisit(SuperConstructorInvocation node) {
+ IMethodBinding methodBinding = node.resolveConstructorBinding();
+ collectBindings(node, methodBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(SuperFieldAccess)
+ */
+ public void endVisit(SuperFieldAccess node) {
+ ITypeBinding typeBinding = node.resolveTypeBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(SuperMethodInvocation)
+ */
+ public void endVisit(SuperMethodInvocation node) {
+ ITypeBinding typeBinding = node.resolveTypeBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(ThisExpression)
+ */
+ public void endVisit(ThisExpression node) {
+ ITypeBinding typeBinding = node.resolveTypeBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(TypeDeclaration)
+ */
+ public void endVisit(TypeDeclaration node) {
+ ITypeBinding typeBinding = node.resolveBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(TypeLiteral)
+ */
+ public void endVisit(TypeLiteral node) {
+ ITypeBinding typeBinding = node.resolveTypeBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(VariableDeclarationExpression)
+ */
+ public void endVisit(VariableDeclarationExpression node) {
+ ITypeBinding typeBinding = node.resolveTypeBinding();
+ collectBindings(node, typeBinding);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(VariableDeclarationFragment)
+ */
+ public void endVisit(VariableDeclarationFragment node) {
+ IVariableBinding variableBinding = node.resolveBinding();
+ collectBindings(node, variableBinding);
+ }
+
+ public List getBindings() {
+ return this.arrayList;
+ }
+
+ }
+
+
+ public void setUpSuite() throws Exception {
+ super.setUpSuite();
+ this.ast = AST.newAST(AST.JLS3);
+ }
+
+ public ASTConverterBindingsTest(String name) {
+ super(name);
+ }
+
+ public static Test suite() {
+ return buildModelTestSuite(ASTConverterBindingsTest.class);
+ }
+
+ public void test0001() throws JavaModelException {
+ checkBindingEqualityForProject("Converter");
+ checkBindingEqualityForProject("Converter15");
+ }
+
+ /**
+ * @throws JavaModelException
+ */
+ private void checkBindingEqualityForProject(String projectName) throws JavaModelException {
+ IJavaProject javaProject = getJavaProject(projectName);
+ IPackageFragment[] packageFragments = javaProject.getPackageFragments();
+ ArrayList compilationUnitscollector = new ArrayList();
+ for (int j = 0, max2 = packageFragments.length; j < max2; j++) {
+ ICompilationUnit[] units = packageFragments[j].getCompilationUnits();
+ if (units != null) {
+ for (int k = 0, max3 = units.length; k < max3; k++) {
+ compilationUnitscollector.add(units[k]);
+ }
+ }
+ }
+ final int length = compilationUnitscollector.size();
+ ICompilationUnit[] units = new ICompilationUnit[length];
+ compilationUnitscollector.toArray(units);
+ long totalTime = 0;
+ for (int j = 0; j < length; j++) {
+ ICompilationUnit currentUnit = units[j];
+ ASTNode result = runConversion(AST.JLS3, currentUnit, true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType());
+ CompilationUnit unit = (CompilationUnit) result;
+ result = runConversion(AST.JLS3, currentUnit, true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType());
+ if (DEBUG) {
+ if (unit.types().size() > 0 ) {
+ AbstractTypeDeclaration typeDeclaration = (AbstractTypeDeclaration) unit.types().get(0);
+ StringBuffer buffer = new StringBuffer();
+ PackageDeclaration packageDeclaration = unit.getPackage();
+ if (packageDeclaration != null) {
+ buffer.append(unit.getPackage().getName()).append(".").append(typeDeclaration.getName());
+ } else {
+ buffer.append(typeDeclaration.getName());
+ }
+ System.out.println(String.valueOf(buffer));
+ } else {
+ System.out.println(currentUnit.getElementName());
+ }
+ }
+ CompilationUnit unit2 = (CompilationUnit) result;
+ BindingsCollector collector = new BindingsCollector();
+ unit.accept(collector);
+ List bindings1 = collector.getBindings();
+ BindingsCollector collector2 = new BindingsCollector();
+ unit2.accept(collector2);
+ List bindings2 = collector2.getBindings();
+ assertEquals("Wrong size", bindings1.size(), bindings2.size());
+ long time = System.currentTimeMillis();
+ for (int i = 0, max = bindings1.size(); i < max; i++) {
+ final Object object = bindings1.get(i);
+ assertTrue("not a binding", object instanceof IBinding);
+ final IBinding binding = (IBinding) object;
+ final Object object2 = bindings2.get(i);
+ assertTrue("not a binding", object2 instanceof IBinding);
+ final IBinding binding2 = (IBinding) object2;
+ final boolean equalTo = binding.isEqualTo(binding2);
+ assertTrue("not equals", equalTo);
+ }
+ totalTime += (System.currentTimeMillis() - time);
+ }
+ if (DEBUG) {
+ System.out.println("Total time = " + totalTime + "ms");
+ }
+ }
+}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTest.java
new file mode 100644
index 0000000..7a2d63e
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTest.java
@@ -0,0 +1,1295 @@
+/*******************************************************************************
+ * 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.core.tests.dom;
+
+import java.io.IOException;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.Test;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.IClassFile;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.WorkingCopyOwner;
+import org.eclipse.jdt.core.dom.*;
+
+public class ASTConverterBugsTest extends ConverterTestSetup {
+
+public void setUpSuite() throws Exception {
+// PROJECT_SETUP = true; // do not copy Converter* directories
+ super.setUpSuite();
+// setUpJCLClasspathVariables("1.5");
+ waitUntilIndexesReady();
+}
+
+public ASTConverterBugsTest(String name) {
+ super(name);
+}
+
+public static Test suite() {
+ return buildModelTestSuite(ASTConverterBugsTest.class);
+}
+
+protected void checkParameterAnnotations(String message, String expected, IMethodBinding methodBinding) {
+ ITypeBinding[] parameterTypes = methodBinding.getParameterTypes();
+ int size = parameterTypes == null ? 0 : parameterTypes.length;
+ StringBuffer buffer = new StringBuffer();
+ for (int i=0; i<size; i++) {
+ buffer.append("----- param ");
+ buffer.append(i+1);
+ buffer.append("-----\n");
+ IAnnotationBinding[] bindings= methodBinding.getParameterAnnotations(i);
+ int length = bindings.length;
+ for (int j=0; j<length; j++) {
+ buffer.append(bindings[j].getKey());
+ buffer.append('\n');
+ }
+ }
+ assertEquals(message, expected, buffer.toString());
+}
+
+public ASTNode runConversion(ICompilationUnit unit, boolean resolveBindings) {
+ return runConversion(this.testLevel, unit, resolveBindings);
+}
+
+public ASTNode runConversion(ICompilationUnit unit, int position, boolean resolveBindings) {
+ return runConversion(this.testLevel, unit, position, resolveBindings);
+}
+
+public ASTNode runConversion(IClassFile classFile, int position, boolean resolveBindings) {
+ return runConversion(this.testLevel, classFile, position, resolveBindings);
+}
+
+public ASTNode runConversion(char[] source, String unitName, IJavaProject project) {
+ return runConversion(this.testLevel, source, unitName, project);
+}
+
+public ASTNode runConversion(char[] source, String unitName, IJavaProject project, boolean resolveBindings) {
+ return runConversion(this.testLevel, source, unitName, project, resolveBindings);
+}
+
+public ASTNode runConversion(char[] source, String unitName, IJavaProject project, Map options, boolean resolveBindings) {
+ return runConversion(this.testLevel, source, unitName, project, options, resolveBindings);
+}
+public ASTNode runConversion(char[] source, String unitName, IJavaProject project, Map options) {
+ return runConversion(this.testLevel, source, unitName, project, options);
+}
+
+public ASTNode runConversion(
+ ICompilationUnit unit,
+ boolean resolveBindings,
+ boolean statementsRecovery,
+ boolean bindingsRecovery) {
+ ASTParser parser = createASTParser();
+ parser.setSource(unit);
+ parser.setResolveBindings(resolveBindings);
+ parser.setStatementsRecovery(statementsRecovery);
+ parser.setBindingsRecovery(bindingsRecovery);
+ parser.setWorkingCopyOwner(this.wcOwner);
+ return parser.createAST(null);
+}
+
+protected void resolveASTs(ICompilationUnit[] cus, String[] bindingKeys, ASTRequestor requestor, IJavaProject project, WorkingCopyOwner owner) {
+ ASTParser parser = createASTParser();
+ parser.setResolveBindings(true);
+ parser.setProject(project);
+ parser.setWorkingCopyOwner(owner);
+ parser.createASTs(cus, bindingKeys, requestor, null);
+}
+
+/**
+ * @bug 186410: [dom] StackOverflowError due to endless superclass bindings hierarchy
+ * @test Ensures that the superclass of "java.lang.Object" class is null even when it's a recovered binding
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=186410"
+ */
+public void testBug186410() throws CoreException, IOException {
+ try {
+ createJavaProject("P", new String[] { "" }, new String[0], "");
+ createFile("P/A.java",
+ "public class A {\n" +
+ " void method(){}\n" +
+ "}"
+ );
+ ICompilationUnit cuA = getCompilationUnit("P/A.java");
+ CompilationUnit unitA = (CompilationUnit) runConversion(cuA, true, false, true);
+ AbstractTypeDeclaration typeA = (AbstractTypeDeclaration) unitA.types().get(0);
+ ITypeBinding objectType = typeA.resolveBinding().getSuperclass();
+ assertEquals("Unexpected superclass", "Object", objectType.getName());
+ ITypeBinding objectSuperclass = objectType.getSuperclass();
+ assertNull("java.lang.Object should not have any superclass", objectSuperclass);
+ } finally {
+ deleteProject("P");
+ }
+}
+
+public void testBug186410b() throws CoreException, IOException {
+ try {
+ createJavaProject("P", new String[] { "" }, new String[0], "");
+ createFile("P/A.java",
+ "public class A {\n" +
+ " Object field;\n" +
+ "}"
+ );
+ ICompilationUnit cuA = getCompilationUnit("P/A.java");
+ CompilationUnit unitA = (CompilationUnit) runConversion(cuA, true, false, true);
+ AbstractTypeDeclaration type = (AbstractTypeDeclaration) unitA.types().get(0);
+ FieldDeclaration field = (FieldDeclaration) type.bodyDeclarations().get(0);
+ Type fieldType = field.getType();
+ ITypeBinding typeBinding = fieldType.resolveBinding();
+ ITypeBinding objectType = typeBinding.createArrayType(2).getElementType();
+ assertEquals("Unexpected superclass", "Object", objectType.getName());
+ ITypeBinding objectSuperclass = objectType.getSuperclass();
+ assertNull("java.lang.Object should not have any superclass", objectSuperclass);
+ } finally {
+ deleteProject("P");
+ }
+}
+
+/**
+ * @bug 209150: [dom] Recovered type binding for "java.lang.Object" information are not complete
+ * @test Ensures that getPackage() and getQualifiedName() works properly for the "java.lang.Object" recovered binding
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=209150"
+ */
+public void testBug209150a() throws CoreException, IOException {
+ try {
+ createJavaProject("P", new String[] { "" }, new String[0], "");
+ createFile("P/A.java",
+ "public class A {\n" +
+ " void method(){}\n" +
+ "}"
+ );
+ ICompilationUnit cuA = getCompilationUnit("P/A.java");
+ CompilationUnit unitA = (CompilationUnit) runConversion(cuA, true, false, true);
+ AbstractTypeDeclaration typeA = (AbstractTypeDeclaration) unitA.types().get(0);
+ ITypeBinding objectType = typeA.resolveBinding().getSuperclass();
+ assertTrue("'java.lang.Object' should be recovered!", objectType.isRecovered());
+ assertEquals("Unexpected package for recovered 'java.lang.Object'", "java.lang", objectType.getPackage().getName());
+ assertEquals("Unexpected qualified name for recovered 'java.lang.Object'",
+ "java.lang.Object",
+ objectType.getQualifiedName());
+ } finally {
+ deleteProject("P");
+ }
+}
+
+public void testBug209150b() throws CoreException, IOException {
+ try {
+ createJavaProject("P", new String[] { "" }, new String[0], "");
+ createFile("P/A.java",
+ "public class A {\n" +
+ " Object field;\n" +
+ "}"
+ );
+ ICompilationUnit cuA = getCompilationUnit("P/A.java");
+ CompilationUnit unitA = (CompilationUnit) runConversion(cuA, true, false, true);
+ AbstractTypeDeclaration type = (AbstractTypeDeclaration) unitA.types().get(0);
+ FieldDeclaration field = (FieldDeclaration) type.bodyDeclarations().get(0);
+ Type fieldType = field.getType();
+ ITypeBinding typeBinding = fieldType.resolveBinding();
+ ITypeBinding arrayType = typeBinding.createArrayType(2);
+ assertTrue("'java.lang.Object' should be recovered!", arrayType.isRecovered());
+ assertNull("Unexpected package for recovered 'array of java.lang.Object'", arrayType.getPackage());
+ assertEquals("Unexpected qualified name for recovered 'java.lang.Object'",
+ "java.lang.Object[][]",
+ arrayType.getQualifiedName());
+ } finally {
+ deleteProject("P");
+ }
+}
+
+public void testBug209150c() throws CoreException, IOException {
+ try {
+ createJavaProject("P", new String[] { "" }, new String[0], "");
+ createFile("P/A.java",
+ "public class A {\n" +
+ " Object[] array;\n" +
+ "}"
+ );
+ ICompilationUnit cuA = getCompilationUnit("P/A.java");
+ CompilationUnit unitA = (CompilationUnit) runConversion(cuA, true, false, true);
+ AbstractTypeDeclaration type = (AbstractTypeDeclaration) unitA.types().get(0);
+ FieldDeclaration field = (FieldDeclaration) type.bodyDeclarations().get(0);
+ Type fieldType = field.getType();
+ ITypeBinding arrayType = fieldType.resolveBinding();
+ assertTrue("'java.lang.Object' should be recovered!", arrayType.isRecovered());
+ assertNull("Unexpected package for recovered 'array of java.lang.Object'", arrayType.getPackage());
+ assertEquals("Unexpected qualified name for recovered 'java.lang.Object'",
+ "java.lang.Object[]",
+ arrayType.getQualifiedName());
+ } finally {
+ deleteProject("P");
+ }
+}
+
+/**
+ * @bug 212100: [dom] Can't create binding to inner class
+ * @test Verify that the binding is well created for an inner class
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=212100"
+ */
+public void testBug212100a() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public class Y {\n" +
+ " void foo() {}\n" +
+ " }\n" +
+ "}";
+ this.workingCopies[0].getBuffer().setContents(contents);
+ this.workingCopies[0].save(null, true);
+ final IBinding[] bindings = new IBinding[4];
+ final String key = "Ljava/lang/Object;"; // this will make the test fail
+// final String key = "LX;"; // this would make the test pass
+
+ resolveASTs(this.workingCopies,
+ new String[] { key },
+ new ASTRequestor() {
+ public void acceptBinding(String bindingKey, IBinding binding) {
+ if (key.equals(bindingKey)) {
+ bindings[0] = binding;
+ IBinding[] temp = createBindings(new String[] {"LX;", "LX$Y;", "[LX$Y;"});
+ for (int i = 0; i < temp.length; ++i) {
+ bindings[i + 1] = temp[i];
+ }
+ }
+ }
+ },
+ getJavaProject("Converter15"),
+ null);
+ assertNotNull("Binding for java.lang.Object should not be null", bindings[0]);
+ assertNotNull("Binding for X should not be null", bindings[1]);
+ assertNotNull("Binding for X.Y should not be null", bindings[2]);
+ assertNotNull("Binding for X.Y[] should not be null", bindings[3]);
+}
+public void testBug212100b() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[2];
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public class Y {\n" +
+ " void foo() {}\n" +
+ " }\n" +
+ "}";
+ this.workingCopies[0].getBuffer().setContents(contents);
+ this.workingCopies[0].save(null, true);
+
+ this.workingCopies[1] = getWorkingCopy("/Converter15/src/Z.java", true/*resolve*/);
+ String contentsZ =
+ "public class Z {\n" +
+ " public class W {\n" +
+ " void bar() {}\n" +
+ " }\n" +
+ "}";
+ this.workingCopies[1].getBuffer().setContents(contentsZ);
+ this.workingCopies[1].save(null, true);
+
+ final String keyX = "LX;";
+ final String keyXY = "LX$Y;";
+ final String keyZ = "LZ;";
+ final String keyZW = "LZ$W;";
+
+ resolveASTs(this.workingCopies,
+ new String[] { keyX, keyZ },
+ new ASTRequestor() {
+ public void acceptBinding(String bindingKey, IBinding binding) {
+ IBinding[] bindings = createBindings(new String[] {
+ keyX, keyXY, keyZ, keyZW
+ });
+ assertNotNull("When accepting " + bindingKey + ", Binding for X should not be null", bindings[0]);
+ assertNotNull("When accepting " + bindingKey + ", Binding for X.Y should not be null", bindings[1]);
+ assertNotNull("When accepting " + bindingKey + ", Binding for Z should not be null", bindings[2]);
+ assertNotNull("When accepting " + bindingKey + ", Binding for Z.W should not be null", bindings[3]);
+ }
+ },
+ getJavaProject("Converter15"),
+ null);
+}
+
+/**
+ * @bug 212834: [dom] IMethodBinding.getParameterAnnotations does not return annotations
+ * @test Ensures that the method binding get the parameter annotations even on method invocation
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=212834"
+ */
+public void testBug212834() throws CoreException, IOException {
+ this.workingCopies = new ICompilationUnit[3];
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/Baz.java",
+ "public @interface Baz {\n" +
+ "}\n"
+ );
+ this.workingCopies[1] = getWorkingCopy("/Converter15/src/C.java",
+ "public class C {\n" +
+ "public C(D d) {\n" +
+ " foo(5);\n" +
+ " d.bar(7);\n" +
+ "}\n" +
+ "@Baz\n" +
+ "public void foo(@Baz int x) { }\n" +
+ "\n" +
+ "}"
+ );
+ this.workingCopies[2] = getWorkingCopy("/Converter15/src/D.java",
+ "public class D {\n" +
+ "@Baz\n" +
+ "public void bar(@Baz int y) { }\n" +
+ "\n" +
+ "}"
+ );
+
+ CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[1], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
+ MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
+ MethodInvocation methodInvocation = (MethodInvocation) ((ExpressionStatement) methodDeclaration.getBody().statements().get(1)).getExpression();
+ IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();
+ assertBindingsEqual(methodInvocation+" has invalid parameter annotations!",
+ "@LBaz;",
+ methodBinding.getParameterAnnotations(0)
+ );
+}
+
+/**
+ * @bug 212857: [dom] AST has wrong source range after parameter with array-valued annotation
+ * @test Ensures that the method body has the right source range even when there's braces in its header
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=212857"
+ */
+public void testBug212857() throws CoreException, IOException {
+ this.workingCopies = new ICompilationUnit[1];
+ String source = "package xy;\n" +
+ "public class C {\n" +
+ " void m(@SuppressWarnings({\"unused\", \"bla\"}) int arg) {\n" +
+ " int local;\n" +
+ " }\n" +
+ "}\n";
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/xy/C.java", source);
+ CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
+ MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
+ checkSourceRange(methodDeclaration.getBody(),
+ "{\n" +
+ " int local;\n" +
+ " }",
+ source
+ );
+}
+public void testBug212857a() throws CoreException, IOException {
+ this.workingCopies = new ICompilationUnit[1];
+ String source = "package xy;\n" +
+ "public class C {\n" +
+ " @SuppressWarnings({\"unused\", \"bla\"}) void m() {\n" +
+ " int local;\n" +
+ " }\n" +
+ "}\n";
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/xy/C.java", source);
+ CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
+ MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
+ checkSourceRange(methodDeclaration.getBody(),
+ "{\n" +
+ " int local;\n" +
+ " }",
+ source
+ );
+}
+// tests with recovery
+public void testBug212857b() throws CoreException, IOException {
+ this.workingCopies = new ICompilationUnit[1];
+ String source = "package test;\n" +
+ "public class X {\n" +
+ " void m() \n" +
+ " if (arg == 0) {}\n" +
+ " }\n" +
+ "}\n";
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/test/X.java", source);
+ CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
+ MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
+ checkSourceRange(methodDeclaration.getBody(),
+ " \n" +
+ " if (arg == 0) {}\n" +
+ " }",
+ source
+ );
+}
+public void testBug212857c() throws CoreException, IOException {
+ this.workingCopies = new ICompilationUnit[1];
+ String source = "package test;\n" +
+ "public class X {\n" +
+ " void m() \n" +
+ " }\n" +
+ "}\n";
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/test/X.java", source);
+ CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
+ MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
+ checkSourceRange(methodDeclaration.getBody(),
+ " \n" +
+ " }",
+ source
+ );
+}
+public void testBug212857d() throws CoreException, IOException {
+ this.workingCopies = new ICompilationUnit[1];
+ String source = "package test;\n" +
+ "public class X {\n" +
+ " void m(String str) \n" +
+ " if (arg == 0) {}\n" +
+ " }\n" +
+ "}\n";
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/test/X.java", source);
+ CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
+ MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
+ checkSourceRange(methodDeclaration.getBody(),
+ " \n" +
+ " if (arg == 0) {}\n" +
+ " }",
+ source
+ );
+}
+public void testBug212857e() throws CoreException, IOException {
+ this.workingCopies = new ICompilationUnit[1];
+ String source = "package test;\n" +
+ "public class X {\n" +
+ " void m(Object obj, int x) \n" +
+ " }\n" +
+ "}\n";
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/test/X.java", source);
+ CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
+ MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
+ checkSourceRange(methodDeclaration.getBody(),
+ " \n" +
+ " }",
+ source
+ );
+}
+
+/**
+ * @bug 213509: [dom] IMethodBinding.getParameterAnnotations returns annotations for wrong parameter
+ * @test Ensures that all parameter annotations of a the method binding are correctly returned
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=213509"
+ */
+public void testBug213509() throws CoreException, IOException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/Test.java",
+ "public class Test {\n" +
+ " void m(@Foo @Bar @Annot String str, @Bar @Foo Object obj, @Annot int x) {}\n" +
+ "}\n" +
+ "@interface Foo {}\n" +
+ "@interface Bar {}\n" +
+ "@interface Annot {}\n"
+ );
+
+ CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
+ MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
+ checkParameterAnnotations(methodDeclaration+" has invalid parameter annotations!",
+ "----- param 1-----\n" +
+ "@LTest~Foo;\n" +
+ "@LTest~Bar;\n" +
+ "@LTest~Annot;\n" +
+ "----- param 2-----\n" +
+ "@LTest~Bar;\n" +
+ "@LTest~Foo;\n" +
+ "----- param 3-----\n" +
+ "@LTest~Annot;\n",
+ methodDeclaration.resolveBinding()
+ );
+}
+public void testBug213509_invocation() throws CoreException, IOException {
+ this.workingCopies = new ICompilationUnit[2];
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/Test.java",
+ "public class Test {\n" +
+ " void m(@Foo @Bar @Annot String str, @Bar @Foo Object obj, @Annot int x) {}\n" +
+ "}\n" +
+ "@interface Foo {}\n" +
+ "@interface Bar {}\n" +
+ "@interface Annot {}\n"
+ );
+ this.workingCopies[1] = getWorkingCopy("/Converter15/src/X.java",
+ "public class X {\n" +
+ "public X(Test test) {\n" +
+ " test.m(\"\", null, 7);\n" +
+ "}\n" +
+ "}"
+ );
+
+ CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[1], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
+ MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
+ MethodInvocation methodInvocation = (MethodInvocation) ((ExpressionStatement) methodDeclaration.getBody().statements().get(0)).getExpression();
+ checkParameterAnnotations(methodInvocation+" has invalid parameter annotations!",
+ "----- param 1-----\n" +
+ "@LTest~Foo;\n" +
+ "@LTest~Bar;\n" +
+ "@LTest~Annot;\n" +
+ "----- param 2-----\n" +
+ "@LTest~Bar;\n" +
+ "@LTest~Foo;\n" +
+ "----- param 3-----\n" +
+ "@LTest~Annot;\n",
+ methodInvocation.resolveMethodBinding()
+ );
+}
+
+/**
+ * @bug 214002: [dom] NPE in MethodBinding.getParameterAnnotations()
+ * @test Ensures that no NPE occurs when not all method parameters have annotations
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=214002"
+ */
+public void testBug214002() throws CoreException, IOException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/Test.java",
+ "public class Test {\n" +
+ " void m(String str, @Bar @Foo Object obj, @Annot int x) {}\n" +
+ "}\n" +
+ "@interface Foo {}\n" +
+ "@interface Bar {}\n" +
+ "@interface Annot {}\n"
+ );
+
+ CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
+ MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
+ checkParameterAnnotations(methodDeclaration+" has invalid parameter annotations!",
+ "----- param 1-----\n" +
+ "----- param 2-----\n" +
+ "@LTest~Bar;\n" +
+ "@LTest~Foo;\n" +
+ "----- param 3-----\n" +
+ "@LTest~Annot;\n",
+ methodDeclaration.resolveBinding()
+ );
+}
+public void testBug214002b() throws CoreException, IOException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/Test.java",
+ "public class Test {\n" +
+ " void m(@Annot String str, Object obj, @Bar @Foo int x) {}\n" +
+ "}\n" +
+ "@interface Foo {}\n" +
+ "@interface Bar {}\n" +
+ "@interface Annot {}\n"
+ );
+
+ CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
+ MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
+ checkParameterAnnotations(methodDeclaration+" has invalid parameter annotations!",
+ "----- param 1-----\n" +
+ "@LTest~Annot;\n" +
+ "----- param 2-----\n" +
+ "----- param 3-----\n" +
+ "@LTest~Bar;\n" +
+ "@LTest~Foo;\n",
+ methodDeclaration.resolveBinding()
+ );
+}
+ /**
+ * @bug 212434: [dom] IllegalArgumentException during AST Creation
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=212434"
+ */
+ public void testBug212434a() throws CoreException, IOException {
+ try {
+ createJavaProject("P", new String[] {""}, new String[0], "");
+ createFile("P/A.java",
+ "public class A {\n"+
+ "\n"+
+ " public void foo() {\n"+
+ " new Object() { \n"+
+ " public void bar() { \n"+
+ " if (true) {\n"+
+ " final\n"+
+ " }\n"+
+ " }\n"+
+ "\n"+
+ " }; \n"+
+ "\n"+
+ " if (false) {\n"+
+ " Object var = new Object() {\n"+
+ " void toto() {\n"+
+ " \n"+
+ " }\n"+
+ " };\n"+
+ " }\n"+
+ " }\n"+
+ "}"
+ );
+ ICompilationUnit cuA = getCompilationUnit("P/A.java");
+ try {
+ runConversion(AST.JLS3, cuA, true, true, true);
+ } catch(IllegalArgumentException e) {
+ assertTrue("Unexpected IllegalArgumentException", false);
+ }
+ } finally {
+ deleteProject("P");
+ }
+ }
+/**
+ * @bug 214647: [dom] NPE in MethodBinding.getParameterAnnotations(..)
+ * @test Ensures that no NPE occurs when parameters have no annotation
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=214647"
+ */
+public void testBug214647() throws CoreException, IOException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/Test.java",
+ "public class Test {\n" +
+ " void m(String str) {}\n" +
+ "}\n"
+ );
+
+ CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
+ MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
+ checkParameterAnnotations(methodDeclaration+" has invalid parameter annotations!",
+ "----- param 1-----\n",
+ methodDeclaration.resolveBinding()
+ );
+}
+public void testBug214647b() throws CoreException, IOException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/Test.java",
+ "public class Test {\n" +
+ " void m(String str, Object o, int x) {}\n" +
+ "}\n"
+ );
+
+ CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[0], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
+ MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
+ checkParameterAnnotations(methodDeclaration+" has invalid parameter annotations!",
+ "----- param 1-----\n" +
+ "----- param 2-----\n" +
+ "----- param 3-----\n",
+ methodDeclaration.resolveBinding()
+ );
+}
+
+/**
+ * @bug 215759: DOM AST regression tests should be improved
+ * @test these tests test the new DOM AST test framework
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=215759"
+ */
+public void testBug215759a() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter/src/p/Y.java",
+ "package p;\n" +
+ "public class Y {\n" +
+ "}",
+ true/*resolve*/);
+
+ ASTResult result = this.buildMarkedAST(
+ "/Converter/src/p/X.java",
+ "package p;\n" +
+ "public class X extends Y {\n" +
+ " /**\n" +
+ " * blabla1\n" +
+ " * @param [*1*]string[*1*] blabla2\n" +
+ " */\n" +
+ " protected [*2*]String[*2*] foo(String string) {\n" +
+ " return [*3*](\"\" + string + \"\")[*3*] + (\"\");\n" +
+ " }\n" +
+ " /*comment*/[*4*]protected void bar() {}[*4*]\n" +
+ " #\n" +
+ "}");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package p;\n" +
+ "public class X extends Y {\n" +
+ " /** \n" +
+ " * blabla1\n" +
+ " * @param [*1*]string[*1*] blabla2\n" +
+ " */\n" +
+ " protected [*2*]String[*2*] foo( String string){\n" +
+ " return [*3*](\"\" + string + \"\")[*3*] + (\"\");\n" +
+ " }\n" +
+ " [*4*]protected void bar(){\n" +
+ " }[*4*]\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:SIMPLE_NAME,[66,6],,,[VARIABLE,Lp/X;.foo(Ljava/lang/String;)Ljava/lang/String;#string,]\n" +
+ "2:SIMPLE_TYPE,[97,6],,,[TYPE,Ljava/lang/String;,]\n" +
+ "2:SIMPLE_NAME,[97,6],,,[TYPE,Ljava/lang/String;,]\n" +
+ "3:PARENTHESIZED_EXPRESSION,[134,18],,,[N/A]\n" +
+ "4:METHOD_DECLARATION,[176,23],,,[METHOD,Lp/X;.bar()V,]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter/src/p/X.java (at line 11)\n" +
+ " #\n" +
+ " ^\n" +
+ "Syntax error on token \"Invalid Character\", delete this token\n",
+ result);
+}
+
+public void testBug215759b() throws CoreException {
+ this.workingCopies = new ICompilationUnit[1];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter/src/p/Y.java",
+ "package p;\n" +
+ "public class Y {\n" +
+ "}",
+ true/*resolve*/);
+
+ ASTResult result = this.buildMarkedAST(
+ "/Converter/src/p/X.java",
+ "package p;\n" +
+ "public class X extends Y {\n" +
+ " /**\n" +
+ " * blabla1\n" +
+ " * @param [*1*]string[*1*] blabla2\n" +
+ " */\n" +
+ " protected [*2*]String[*2*] foo(String string) {\n" +
+ " return [*3*](\"\" + string + \"\")[*3*] + (\"\");\n" +
+ " }\n" +
+ " /*comment*/[*4*]protected void bar() {}[*4*]\n" +
+ " [*5*]/**@deprecated*/protected void bar2() {}[*5*]\n" +
+ "}");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package p;\n" +
+ "public class X extends Y {\n" +
+ " /** \n" +
+ " * blabla1\n" +
+ " * @param [*1*]string[*1*] blabla2\n" +
+ " */\n" +
+ " protected [*2*]String[*2*] foo( String string){\n" +
+ " return [*3*](\"\" + string + \"\")[*3*] + (\"\");\n" +
+ " }\n" +
+ " [*4*]protected void bar(){\n" +
+ " }[*4*]\n" +
+ " [*5*]/** \n" +
+ " * @deprecated\n" +
+ " */\n" +
+ " protected void bar2(){\n" +
+ " }[*5*]\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:SIMPLE_NAME,[66,6],,,[VARIABLE,Lp/X;.foo(Ljava/lang/String;)Ljava/lang/String;#string,]\n" +
+ "2:SIMPLE_TYPE,[97,6],,,[TYPE,Ljava/lang/String;,]\n" +
+ "2:SIMPLE_NAME,[97,6],,,[TYPE,Ljava/lang/String;,]\n" +
+ "3:PARENTHESIZED_EXPRESSION,[134,18],,,[N/A]\n" +
+ "4:METHOD_DECLARATION,[176,23],[165,34],,[METHOD,Lp/X;.bar()V,]\n" +
+ "5:METHOD_DECLARATION,[201,40],,,[METHOD,Lp/X;.bar2()V,DEPRECATED]\n" +
+ "===== Problems =====\n" +
+ "No problem",
+ result);
+}
+/**
+ * @bug 218824: [DOM/AST] incorrect code leads to IllegalArgumentException during AST creation
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=218824"
+ */
+public void testBug218824a() throws JavaModelException {
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "public class X {\n"+
+ " public void takeParam(int i) {\n"+
+ " // do something\n"+
+ " }\n"+
+ "\n"+
+ " void test() {\n"+
+ " char c = 'a';\n"+
+ " public void takeParam(int i) {\n"+
+ " // do something\n"+
+ " }\n"+
+ "\n"+
+ " void test() {\n"+
+ " char c = 'a';\n"+
+ " takeParam((int) c);\n"+
+ " }[*1*]takeParam([*1*](int) c);\n"+
+ " }\n"+
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "public class X {\n" +
+ " public void takeParam( int i){\n" +
+ " }\n" +
+ " void test(){\n" +
+ " char c=\'a\';\n" +
+ " public void takeParam;\n" +
+ " int i;\n" +
+ " new test(){\n" +
+ " char c=\'a\';\n" +
+ "{\n" +
+ " takeParam((int)c);\n" +
+ " }\n" +
+ " [*1*]void takeParam(){\n" +
+ " }[*1*]\n" +
+ " }\n" +
+ ";\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:METHOD_DECLARATION,[447,10],,MALFORMED,[null]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 9)\n" +
+ " public void takeParam(int i) {\n" +
+ " ^^^^^^^^^\n" +
+ "void is an invalid type for the variable takeParam\n" +
+ "2. ERROR in /Converter15/src/a/X.java (at line 9)\n" +
+ " public void takeParam(int i) {\n" +
+ " ^\n" +
+ "Syntax error on token \"(\", ; expected\n" +
+ "3. ERROR in /Converter15/src/a/X.java (at line 9)\n" +
+ " public void takeParam(int i) {\n" +
+ " ^\n" +
+ "Syntax error on token \")\", ; expected\n" +
+ "4. ERROR in /Converter15/src/a/X.java (at line 13)\n" +
+ " void test() {\n" +
+ " ^^^^\n" +
+ "Syntax error on token \"void\", new expected\n" +
+ "5. ERROR in /Converter15/src/a/X.java (at line 13)\n" +
+ " void test() {\n" +
+ " ^^^^\n" +
+ "test cannot be resolved to a type\n" +
+ "6. ERROR in /Converter15/src/a/X.java (at line 14)\n" +
+ " char c = \'a\';\n" +
+ " ^\n" +
+ "Syntax error on token \";\", { expected after this token\n" +
+ "7. ERROR in /Converter15/src/a/X.java (at line 16)\n" +
+ " }takeParam((int) c);\n" +
+ " ^\n" +
+ "Syntax error, insert \"}\" to complete ClassBody\n" +
+ "8. ERROR in /Converter15/src/a/X.java (at line 16)\n" +
+ " }takeParam((int) c);\n" +
+ " ^\n" +
+ "Syntax error, insert \";\" to complete Statement\n" +
+ "9. ERROR in /Converter15/src/a/X.java (at line 16)\n" +
+ " }takeParam((int) c);\n" +
+ " ^^^^^^^^^^\n" +
+ "Return type for the method is missing\n",
+ result);
+}
+/**
+ * @bug 215137: [AST]Some malformed MethodDeclaration, their Block is null, but they actually have Block
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=215137"
+ */
+public void testBug215137a() throws JavaModelException {
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "public class X {\n"+
+ " public void foo() [*1*]{\n"+
+ " System.out.println(\"hello);\n"+
+ " }[*1*]\n"+
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "public class X {\n" +
+ " public void foo()[*1*]{\n" +
+ " }[*1*]\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:BLOCK,[54,55],,RECOVERED,[N/A]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 4)\n" +
+ " System.out.println(\"hello);\n" +
+ " ^^^^^^^^\n" +
+ "String literal is not properly closed by a double-quote\n",
+ result);
+}
+public void testBug215137b() throws JavaModelException {
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "public class X {\n"+
+ " public void foo() [*1*]{\n"+
+ " System.out.println('a);\n"+
+ " }[*1*]\n"+
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "public class X {\n" +
+ " public void foo()[*1*]{\n" +
+ " }[*1*]\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:BLOCK,[54,51],,RECOVERED,[N/A]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 4)\n" +
+ " System.out.println(\'a);\n" +
+ " ^^\n" +
+ "Invalid character constant\n",
+ result);
+}
+public void testBug215137c() throws JavaModelException {
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "public class X {\n"+
+ " public void foo() [*1*]{\n"+
+ " System.out.println(''a);\n"+
+ " }[*1*]\n"+
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "public class X {\n" +
+ " public void foo()[*1*]{\n" +
+ " }[*1*]\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:BLOCK,[54,52],,RECOVERED,[N/A]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 4)\n" +
+ " System.out.println(\'\'a);\n" +
+ " ^^\n" +
+ "Invalid character constant\n",
+ result);
+}
+public void testBug215137d() throws JavaModelException {
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "public class X {\n"+
+ " public void foo() [*1*]{\n"+
+ " 7eSystem.out.println();\n"+
+ " }[*1*]\n"+
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "public class X {\n" +
+ " public void foo()[*1*]{\n" +
+ " }[*1*]\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:BLOCK,[54,51],,RECOVERED,[N/A]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 4)\n" +
+ " 7eSystem.out.println();\n" +
+ " ^^^\n" +
+ "Invalid float literal number\n",
+ result);
+}
+/**
+ * @bug 223838: [dom] AnnotationBinding.isRecovered() always return false
+ * @test That the annotation binding is well flagged as recovered when the annotation is an unknown type
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=223838"
+ */
+public void testBug223838() throws JavaModelException {
+ String contents =
+ "package b223838;\n" +
+ "@Deprecated\n" +
+ "@Invalid\n" +
+ "public class Test {\n" +
+ "}\n";
+ ICompilationUnit workingCopy = getWorkingCopy(
+ "/Converter15/src/b223838/Test.java",
+ contents,
+ true/*resolve*/
+ );
+ ASTNode node = buildAST(contents, workingCopy, false, false, true);
+ CompilationUnit unit = (CompilationUnit) node;
+ List types = unit.types();
+ TypeDeclaration type = (TypeDeclaration) types.get(0);
+ ITypeBinding typeBinding = type.resolveBinding();
+ IAnnotationBinding[] annotations = typeBinding.getAnnotations();
+ assertTrue("Expected recovered annotation binding!", annotations[1].isRecovered());
+}
+/**
+ * @bug 223838: [dom] AnnotationBinding.isRecovered() always return false
+ * @test That the annotation binding is not reported when the recovery is off
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=223838"
+ */
+public void testBug223838a() throws JavaModelException {
+ String contents =
+ "package b223838;\n" +
+ "@Deprecated\n" +
+ "@Invalid\n" +
+ "public class Test {\n" +
+ "}\n";
+ ICompilationUnit workingCopy = getWorkingCopy(
+ "/Converter15/src/b223838/Test.java",
+ contents,
+ true/*resolve*/
+ );
+ ASTNode node = buildAST(contents, workingCopy, false, false, false);
+ CompilationUnit unit = (CompilationUnit) node;
+ List types = unit.types();
+ TypeDeclaration type = (TypeDeclaration) types.get(0);
+ ITypeBinding typeBinding = type.resolveBinding();
+ IAnnotationBinding[] annotations = typeBinding.getAnnotations();
+ assertEquals("Got more than one annotation binding", 1, annotations.length);
+}
+
+/**
+ * @bug 226357: NPE in MethodBinding.getParameterAnnotations() if some, but not all parameters are annotated
+ * @test Verify that NPE does no longer occur on the given test case
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=226357"
+ */
+public void testBug226357() throws CoreException, IOException {
+ this.workingCopies = new ICompilationUnit[2];
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/ParameterSubsetAnnotated.java",
+ "public class ParameterSubsetAnnotated {\n" +
+ " public @interface NonZero { }\n" +
+ " public static int safeDiv(int a, @NonZero int b) {\n" +
+ " return a / b;\n" +
+ " }\n" +
+ "}"
+ );
+ this.workingCopies[1] = getWorkingCopy("/Converter15/src/ParameterSubsetClient.java",
+ "public class ParameterSubsetClient {\n" +
+ "\n" +
+ " public void client() {\n" +
+ " ParameterSubsetAnnotated.safeDiv(5, 0);\n" +
+ " }\n" +
+ "\n" +
+ "}\n"
+ );
+
+ CompilationUnit unit = (CompilationUnit) runConversion(this.workingCopies[1], true/*bindings*/, false/*no statement recovery*/, true/*bindings recovery*/);
+ MethodDeclaration methodDeclaration = (MethodDeclaration) getASTNode(unit, 0, 0);
+ ExpressionStatement statement = (ExpressionStatement) methodDeclaration.getBody().statements().get(0);
+ MethodInvocation methodInvocation = (MethodInvocation) statement.getExpression();
+ checkParameterAnnotations(methodDeclaration+" has invalid parameter annotations!",
+ "----- param 1-----\n" +
+ "----- param 2-----\n" +
+ "@LParameterSubsetAnnotated$NonZero;\n",
+ methodInvocation.resolveMethodBinding()
+ );
+}
+
+public void testBug274898a() throws JavaModelException {
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "public class X {\n"+
+ " public void foo() {\n"+
+ " [*1*]Object o = new [*1*][*2*]new Object(){}[*2*]; \n"+
+ " }\n"+
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "public class X {\n" +
+ " public void foo(){\n" +
+ " [*1*]Object o;[*1*]\n" +
+ " [*2*]new Object(){\n" +
+ " }\n" +
+ ";[*2*]\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:VARIABLE_DECLARATION_STATEMENT,[72,15],,,[N/A]\n" +
+ "2:EXPRESSION_STATEMENT,[87,14],,,[N/A]\n" +
+ "2:CLASS_INSTANCE_CREATION,[87,14],,RECOVERED,[N/A]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 4)\n" +
+ " Object o = new new Object(){}; \n" +
+ " ^^^\n" +
+ "Syntax error on token \"new\", delete this token\n",
+ result);
+}
+public void testBug274898b() throws JavaModelException {
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "public class X {\n"+
+ " public void foo() {\n"+
+ " [*1*]Object o = new # [*1*][*2*]new Object(){}[*2*]; \n"+
+ " }\n"+
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "public class X {\n" +
+ " public void foo(){\n" +
+ " [*1*]Object o;[*1*]\n" +
+ " [*2*]new Object(){\n" +
+ " }\n" +
+ ";[*2*]\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:VARIABLE_DECLARATION_STATEMENT,[72,17],,,[N/A]\n" +
+ "2:EXPRESSION_STATEMENT,[89,14],,,[N/A]\n" +
+ "2:CLASS_INSTANCE_CREATION,[89,14],,,[N/A]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 4)\n" +
+ " Object o = new # new Object(){}; \n" +
+ " ^^^^^\n" +
+ "Syntax error on tokens, delete these tokens\n",
+ result);
+}
+
+public void testBug277204a() throws JavaModelException {
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "public class X {\n" +
+ " {\n" +
+ " class Local {\n" +
+ " [*1*]Object [*2*]x[*2*], [*3*]Local[*3*];[*1*] \n" +
+ " }\n" +
+ " }\n" +
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "public class X {\n" +
+ "{\n" +
+ "class Local {\n" +
+ " [*1*]Object [*2*]x[*2*], [*3*]Local[*3*];[*1*]\n" +
+ " }\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:FIELD_DECLARATION,[69,16],,,[N/A]\n" +
+ "2:VARIABLE_DECLARATION_FRAGMENT,[76,1],,,[VARIABLE,La/X$45$Local;.x)Ljava/lang/Object;,]\n" +
+ "2:SIMPLE_NAME,[76,1],,,[VARIABLE,La/X$45$Local;.x)Ljava/lang/Object;,]\n" +
+ "3:VARIABLE_DECLARATION_FRAGMENT,[79,5],,,[VARIABLE,La/X$45$Local;.Local)Ljava/lang/Object;,]\n" +
+ "3:SIMPLE_NAME,[79,5],,,[VARIABLE,La/X$45$Local;.Local)Ljava/lang/Object;,]\n" +
+ "===== Problems =====\n" +
+ "No problem",
+ result);
+}
+public void testBug277204b() throws JavaModelException {
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "public class X {\n" +
+ " {\n" +
+ " class Local {\n" +
+ " [*1*]Object [*2*]x[*2*], [*3*]Local[*3*] \n" +
+ " [*1*]}\n" +
+ " }\n" +
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "public class X {\n" +
+ "{\n" +
+ "class Local {\n" +
+ " [*1*]Object [*2*]x[*2*], [*3*]Local[*3*];[*1*]\n" +
+ " }\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:FIELD_DECLARATION,[69,26],,MALFORMED,[N/A]\n" +
+ "2:VARIABLE_DECLARATION_FRAGMENT,[76,1],,,[VARIABLE,La/X$45$Local;.x)Ljava/lang/Object;,]\n" +
+ "2:SIMPLE_NAME,[76,1],,,[VARIABLE,La/X$45$Local;.x)Ljava/lang/Object;,]\n" +
+ "3:VARIABLE_DECLARATION_FRAGMENT,[79,5],,,[VARIABLE,La/X$45$Local;.Local)Ljava/lang/Object;,]\n" +
+ "3:SIMPLE_NAME,[79,5],,,[VARIABLE,La/X$45$Local;.Local)Ljava/lang/Object;,]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 5)\n" +
+ " Object x, Local \n" +
+ " ^^^^^\n" +
+ "Syntax error, insert \";\" to complete ClassBodyDeclarations\n",
+ result);
+}
+public void testBug277204c() throws JavaModelException {
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "public class X {\n" +
+ " [*1*]Object [*2*]x[*2*], [*3*]Local[*3*];[*1*] \n" +
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "public class X {\n" +
+ " [*1*]Object [*2*]x[*2*], [*3*]Local[*3*];[*1*]\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:FIELD_DECLARATION,[32,16],,,[N/A]\n" +
+ "2:VARIABLE_DECLARATION_FRAGMENT,[39,1],,,[VARIABLE,La/X;.x)Ljava/lang/Object;,]\n" +
+ "2:SIMPLE_NAME,[39,1],,,[VARIABLE,La/X;.x)Ljava/lang/Object;,]\n" +
+ "3:VARIABLE_DECLARATION_FRAGMENT,[42,5],,,[VARIABLE,La/X;.Local)Ljava/lang/Object;,]\n" +
+ "3:SIMPLE_NAME,[42,5],,,[VARIABLE,La/X;.Local)Ljava/lang/Object;,]\n" +
+ "===== Problems =====\n" +
+ "No problem",
+ result);
+}
+public void testBug277204d() throws JavaModelException {
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "public class X {\n" +
+ " [*1*]Object [*2*]x[*2*], [*3*]Local[*3*][*1*] \n" +
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "public class X {\n" +
+ " [*1*]Object [*2*]x[*2*], [*3*]Local[*3*];[*1*]\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:FIELD_DECLARATION,[32,15],,MALFORMED|RECOVERED,[N/A]\n" +
+ "2:VARIABLE_DECLARATION_FRAGMENT,[39,1],,,[VARIABLE,La/X;.x)Ljava/lang/Object;,]\n" +
+ "2:SIMPLE_NAME,[39,1],,,[VARIABLE,La/X;.x)Ljava/lang/Object;,]\n" +
+ "3:VARIABLE_DECLARATION_FRAGMENT,[42,5],,,[VARIABLE,La/X;.Local)Ljava/lang/Object;,]\n" +
+ "3:SIMPLE_NAME,[42,5],,,[VARIABLE,La/X;.Local)Ljava/lang/Object;,]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 3)\n" +
+ " Object x, Local \n" +
+ " ^^^^^\n" +
+ "Syntax error, insert \";\" to complete ClassBodyDeclarations\n",
+ result);
+}
+public void testBug277204e() throws JavaModelException {
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "public class X {\n" +
+ " {\n" +
+ " class Local {\n" +
+ " [*1*]Object [*2*]x[*2*],\n" +
+ " [*3*]Local[*3*] \n" +
+ " [*1*]}\n" +
+ " }\n" +
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "public class X {\n" +
+ "{\n" +
+ "class Local {\n" +
+ " [*1*]Object [*2*]x[*2*], [*3*]Local[*3*];[*1*]\n" +
+ " }\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:FIELD_DECLARATION,[69,42],,MALFORMED,[N/A]\n" +
+ "2:VARIABLE_DECLARATION_FRAGMENT,[76,1],,,[VARIABLE,La/X$45$Local;.x)Ljava/lang/Object;,]\n" +
+ "2:SIMPLE_NAME,[76,1],,,[VARIABLE,La/X$45$Local;.x)Ljava/lang/Object;,]\n" +
+ "3:VARIABLE_DECLARATION_FRAGMENT,[95,5],,,[VARIABLE,La/X$45$Local;.Local)Ljava/lang/Object;,]\n" +
+ "3:SIMPLE_NAME,[95,5],,,[VARIABLE,La/X$45$Local;.Local)Ljava/lang/Object;,]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 6)\n" +
+ " Local \n" +
+ " ^^^^^\n" +
+ "Syntax error, insert \";\" to complete ClassBodyDeclarations\n",
+ result);
+}
+}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTestJLS3.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTestJLS3.java
new file mode 100644
index 0000000..36e9184
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterBugsTestJLS3.java
@@ -0,0 +1,1045 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2008 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.dom;
+
+import java.util.List;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.AST;
+
+/**
+ * Test suite to verify that DOM/AST bugs are fixed.
+ *
+ * Note that only specific JLS3 tests are defined in this test suite, but when
+ * running it, all superclass {@link ASTConverterBugsTest} tests will be run
+ * as well.
+ */
+public class ASTConverterBugsTestJLS3 extends ASTConverterBugsTest {
+
+public ASTConverterBugsTestJLS3(String name) {
+ super(name);
+ this.testLevel = AST.JLS3;
+}
+
+public static Test suite() {
+ TestSuite suite = new Suite(ASTConverterBugsTestJLS3.class.getName());
+ List tests = buildTestsList(ASTConverterBugsTestJLS3.class, 1, 0/* do not sort*/);
+ for (int index=0, size=tests.size(); index<size; index++) {
+ suite.addTest((Test)tests.get(index));
+ }
+ return suite;
+}
+
+/**
+ * @bug 130778: Invalid annotation elements cause no annotation to be in the AST
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=130778"
+ */
+public void testBug130778a() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[2];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation.java",
+ "package a;\n" +
+ "public @interface AnAnnotation {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ this.workingCopies[1] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation2.java",
+ "package a;\n" +
+ "public @interface AnAnnotation2 {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "[*1*]public[*1*]\n" +
+ "[*2*]@AnAnnotation(\"a\")[*2*]\n" +
+ "[*3*]final[*3*]\n" +
+ "[*4*]@AnAnnotation2(\"b\")[*4*]\n" +
+ "class X {\n" +
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "[*1*]public[*1*] [*2*]@AnAnnotation(\"a\")[*2*] [*3*]final[*3*] [*4*]@AnAnnotation2(\"b\")[*4*] class X {\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:MODIFIER,[11,6],,,[N/A]\n" +
+ "2:SINGLE_MEMBER_ANNOTATION,[18,18],,,[ANNOTATION,La/X;@La/AnAnnotation;,]\n" +
+ "3:MODIFIER,[37,5],,,[N/A]\n" +
+ "4:SINGLE_MEMBER_ANNOTATION,[43,19],,,[ANNOTATION,La/X;@La/AnAnnotation2;,]\n" +
+ "===== Problems =====\n" +
+ "No problem",
+ result);
+}
+public void testBug130778b() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[2];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation.java",
+ "package a;\n" +
+ "public @interface AnAnnotation {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ this.workingCopies[1] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation2.java",
+ "package a;\n" +
+ "public @interface AnAnnotation2 {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "#\n" +
+ "[*1*]public[*1*]\n" +
+ "[*2*]@AnAnnotation(\"a\")[*2*]\n" +
+ "[*3*]final[*3*]\n" +
+ "[*4*]@AnAnnotation2(\"b\")[*4*]\n" +
+ "class X {\n" +
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "[*1*]public[*1*] [*2*]@AnAnnotation(\"a\")[*2*] [*3*]final[*3*] [*4*]@AnAnnotation2(\"b\")[*4*] class X {\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:MODIFIER,[13,6],,,[N/A]\n" +
+ "2:SINGLE_MEMBER_ANNOTATION,[20,18],,,[ANNOTATION,La/X;@La/AnAnnotation;,]\n" +
+ "3:MODIFIER,[39,5],,,[N/A]\n" +
+ "4:SINGLE_MEMBER_ANNOTATION,[45,19],,,[ANNOTATION,La/X;@La/AnAnnotation2;,]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 2)\n" +
+ " #\n" +
+ " ^\n" +
+ "Syntax error on token \"Invalid Character\", delete this token\n",
+ result);
+}
+public void testBug130778c() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[2];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation.java",
+ "package a;\n" +
+ "public @interface AnAnnotation {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ this.workingCopies[1] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation2.java",
+ "package a;\n" +
+ "public @interface AnAnnotation2 {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "[*1*]public[*1*]\n" +
+ "#\n" +
+ "[*2*]@AnAnnotation(\"a\")[*2*]\n" +
+ "[*3*]final[*3*]\n" +
+ "[*4*]@AnAnnotation2(\"b\")[*4*]\n" +
+ "class X {\n" +
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "[*1*]public[*1*] [*2*]@AnAnnotation(\"a\")[*2*] [*3*]final[*3*] [*4*]@AnAnnotation2(\"b\")[*4*] class X {\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:MODIFIER,[11,6],,,[N/A]\n" +
+ "2:SINGLE_MEMBER_ANNOTATION,[20,18],,,[ANNOTATION,La/X;@La/AnAnnotation;,]\n" +
+ "3:MODIFIER,[39,5],,,[N/A]\n" +
+ "4:SINGLE_MEMBER_ANNOTATION,[45,19],,,[ANNOTATION,La/X;@La/AnAnnotation2;,]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 3)\n" +
+ " #\n" +
+ " ^\n" +
+ "Syntax error on token \"Invalid Character\", delete this token\n",
+ result);
+}
+public void testBug130778d() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[2];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation.java",
+ "package a;\n" +
+ "public @interface AnAnnotation {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ this.workingCopies[1] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation2.java",
+ "package a;\n" +
+ "public @interface AnAnnotation2 {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "[*1*]public[*1*]\n" +
+ "[*2*]@AnAnnotation(\"a\")[*2*]\n" +
+ "#\n" +
+ "[*3*]final[*3*]\n" +
+ "[*4*]@AnAnnotation2(\"b\")[*4*]\n" +
+ "class X {\n" +
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "[*1*]public[*1*] [*2*]@AnAnnotation(\"a\")[*2*] [*3*]final[*3*] [*4*]@AnAnnotation2(\"b\")[*4*] class X {\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:MODIFIER,[11,6],,,[N/A]\n" +
+ "2:SINGLE_MEMBER_ANNOTATION,[18,18],,,[ANNOTATION,La/X;@La/AnAnnotation;,]\n" +
+ "3:MODIFIER,[39,5],,,[N/A]\n" +
+ "4:SINGLE_MEMBER_ANNOTATION,[45,19],,,[ANNOTATION,La/X;@La/AnAnnotation2;,]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 4)\n" +
+ " #\n" +
+ " ^\n" +
+ "Syntax error on token \"Invalid Character\", delete this token\n",
+ result);
+}
+public void testBug130778e() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[2];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation.java",
+ "package a;\n" +
+ "public @interface AnAnnotation {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ this.workingCopies[1] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation2.java",
+ "package a;\n" +
+ "public @interface AnAnnotation2 {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "[*1*]public[*1*]\n" +
+ "[*2*]@AnAnnotation(\"a\")[*2*]\n" +
+ "[*3*]final[*3*]\n" +
+ "#\n" +
+ "[*4*]@AnAnnotation2(\"b\")[*4*]\n" +
+ "class X {\n" +
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "[*1*]public[*1*] [*2*]@AnAnnotation(\"a\")[*2*] [*3*]final[*3*] [*4*]@AnAnnotation2(\"b\")[*4*] class X {\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:MODIFIER,[11,6],,,[N/A]\n" +
+ "2:SINGLE_MEMBER_ANNOTATION,[18,18],,,[ANNOTATION,La/X;@La/AnAnnotation;,]\n" +
+ "3:MODIFIER,[37,5],,,[N/A]\n" +
+ "4:SINGLE_MEMBER_ANNOTATION,[45,19],,,[ANNOTATION,La/X;@La/AnAnnotation2;,]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 5)\n" +
+ " #\n" +
+ " ^\n" +
+ "Syntax error on token \"Invalid Character\", delete this token\n",
+ result);
+}
+public void testBug130778f() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[2];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation.java",
+ "package a;\n" +
+ "public @interface AnAnnotation {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ this.workingCopies[1] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation2.java",
+ "package a;\n" +
+ "public @interface AnAnnotation2 {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "[*1*]public[*1*]\n" +
+ "[*2*]@AnAnnotation(\"a\")[*2*]\n" +
+ "[*3*]final[*3*]\n" +
+ "[*4*]@AnAnnotation2(\"b\")[*4*]\n" +
+ "#\n" +
+ "class X {\n" +
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "[*1*]public[*1*] [*2*]@AnAnnotation(\"a\")[*2*] [*3*]final[*3*] [*4*]@AnAnnotation2(\"b\")[*4*] class X {\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:MODIFIER,[11,6],,,[N/A]\n" +
+ "2:SINGLE_MEMBER_ANNOTATION,[18,18],,,[ANNOTATION,La/X;@La/AnAnnotation;,]\n" +
+ "3:MODIFIER,[37,5],,,[N/A]\n" +
+ "4:SINGLE_MEMBER_ANNOTATION,[43,19],,,[ANNOTATION,La/X;@La/AnAnnotation2;,]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 6)\n" +
+ " #\n" +
+ " ^\n" +
+ "Syntax error on token \"Invalid Character\", delete this token\n",
+ result);
+}
+public void testBug130778g() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[2];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation.java",
+ "package a;\n" +
+ "public @interface AnAnnotation {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ this.workingCopies[1] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation2.java",
+ "package a;\n" +
+ "public @interface AnAnnotation2 {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "[*1*]public[*1*]\n" +
+ "[*2*]@AnAnnotation(\"a\")[*2*]\n" +
+ "[*3*]final[*3*]\n" +
+ "[*4*]@AnAnnotation2(\"b\")[*4*]\n" +
+ "class X {\n" +
+ " #\n" +
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "[*1*]public[*1*] [*2*]@AnAnnotation(\"a\")[*2*] [*3*]final[*3*] [*4*]@AnAnnotation2(\"b\")[*4*] class X {\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:MODIFIER,[11,6],,,[N/A]\n" +
+ "2:SINGLE_MEMBER_ANNOTATION,[18,18],,,[ANNOTATION,La/X;@La/AnAnnotation;,]\n" +
+ "3:MODIFIER,[37,5],,,[N/A]\n" +
+ "4:SINGLE_MEMBER_ANNOTATION,[43,19],,,[ANNOTATION,La/X;@La/AnAnnotation2;,]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 7)\n" +
+ " #\n" +
+ " ^\n" +
+ "Syntax error on token \"Invalid Character\", delete this token\n",
+ result);
+}
+public void testBug130778h() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[2];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation.java",
+ "package a;\n" +
+ "public @interface AnAnnotation {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ this.workingCopies[1] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation2.java",
+ "package a;\n" +
+ "public @interface AnAnnotation2 {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "[*1*]@AnAnnotation(value=\"a\")[*1*]\n" +
+ "[*2*]@AnAnnotation2(value=\"b\")[*2*]\n" +
+ "[*3*]public[*3*] class X {\n" +
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "[*1*]@AnAnnotation(value=\"a\")[*1*] [*2*]@AnAnnotation2(value=\"b\")[*2*] [*3*]public[*3*] class X {\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:NORMAL_ANNOTATION,[11,24],,,[ANNOTATION,La/X;@La/AnAnnotation;,]\n" +
+ "2:NORMAL_ANNOTATION,[36,25],,,[ANNOTATION,La/X;@La/AnAnnotation2;,]\n" +
+ "3:MODIFIER,[62,6],,,[N/A]\n" +
+ "===== Problems =====\n" +
+ "No problem",
+ result);
+}
+public void testBug130778i() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[2];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation.java",
+ "package a;\n" +
+ "public @interface AnAnnotation {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ this.workingCopies[1] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation2.java",
+ "package a;\n" +
+ "public @interface AnAnnotation2 {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "[*1*]@AnAnnotation(value=[*1*])\n" +
+ "[*2*]@AnAnnotation2(value=\"b\")[*2*]\n" +
+ "[*3*]public[*3*] class X {\n" +
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "[*1*]@AnAnnotation(value=$missing$)[*1*] [*2*]@AnAnnotation2(value=\"b\")[*2*] [*3*]public[*3*] class X {\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:NORMAL_ANNOTATION,[11,20],,RECOVERED,[ANNOTATION,La/X;@La/AnAnnotation;,]\n" +
+ "2:NORMAL_ANNOTATION,[33,25],,,[ANNOTATION,La/X;@La/AnAnnotation2;,]\n" +
+ "3:MODIFIER,[59,6],,,[N/A]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 2)\n" +
+ " @AnAnnotation(value=)\n" +
+ " ^\n" +
+ "Syntax error on token \"=\", MemberValue expected after this token\n",
+ result);
+}
+public void testBug130778j() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[2];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation.java",
+ "package a;\n" +
+ "public @interface AnAnnotation {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ this.workingCopies[1] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation2.java",
+ "package a;\n" +
+ "public @interface AnAnnotation2 {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "[*1*]@AnAnnotation(value=\"a\")[*1*]\n" +
+ "[*2*]@AnAnnotation2(value=[*2*])\n" +
+ "[*3*]public[*3*] class X {\n" +
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "[*1*]@AnAnnotation(value=\"a\")[*1*] [*2*]@AnAnnotation2(value=$missing$)[*2*] [*3*]public[*3*] class X {\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:NORMAL_ANNOTATION,[11,24],,,[ANNOTATION,La/X;@La/AnAnnotation;,]\n" +
+ "2:NORMAL_ANNOTATION,[36,21],,RECOVERED,[ANNOTATION,La/X;@La/AnAnnotation2;,]\n" +
+ "3:MODIFIER,[59,6],,,[N/A]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 3)\n" +
+ " @AnAnnotation2(value=)\n" +
+ " ^\n" +
+ "Syntax error on token \"=\", MemberValue expected after this token\n",
+ result);
+}
+public void testBug130778k() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[2];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation.java",
+ "package a;\n" +
+ "public @interface AnAnnotation {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ this.workingCopies[1] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation2.java",
+ "package a;\n" +
+ "public @interface AnAnnotation2 {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "[*1*]@AnAnnotation(value=[*1*])\n" +
+ "[*2*]@AnAnnotation2(value=[*2*])\n" +
+ "[*3*]public[*3*] class X {\n" +
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "[*1*]@AnAnnotation(value=$missing$)[*1*] [*2*]@AnAnnotation2(value=$missing$)[*2*] [*3*]public[*3*] class X {\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:NORMAL_ANNOTATION,[11,20],,RECOVERED,[ANNOTATION,La/X;@La/AnAnnotation;,]\n" +
+ "2:NORMAL_ANNOTATION,[33,21],,RECOVERED,[ANNOTATION,La/X;@La/AnAnnotation2;,]\n" +
+ "3:MODIFIER,[56,6],,,[N/A]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 2)\n" +
+ " @AnAnnotation(value=)\n" +
+ " ^\n" +
+ "Syntax error on token \")\", delete this token\n" +
+ "2. ERROR in /Converter15/src/a/X.java (at line 3)\n" +
+ " @AnAnnotation2(value=)\n" +
+ " ^\n" +
+ "Syntax error on token \"=\", ) expected\n",
+ result);
+}
+public void testBug130778l() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[2];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation.java",
+ "package a;\n" +
+ "public @interface AnAnnotation {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ this.workingCopies[1] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation2.java",
+ "package a;\n" +
+ "public @interface AnAnnotation2 {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "public class X {\n" +
+ " public void foo(){\n" +
+ " [*1*]@AnAnnotation(value=[*1*])\n" +
+ " [*2*]@AnAnnotation2(value=\"b\")[*2*]\n" +
+ " class Y {}\n" +
+ " }\n" +
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "public class X {\n" +
+ " public void foo(){\n" +
+ "[*1*]@AnAnnotation(value=$missing$)[*1*] [*2*]@AnAnnotation2(value=\"b\")[*2*] class Y {\n" +
+ " }\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:NORMAL_ANNOTATION,[53,20],,RECOVERED,[ANNOTATION,La/X$115$Y;@La/AnAnnotation;,]\n" +
+ "2:NORMAL_ANNOTATION,[79,25],,,[ANNOTATION,La/X$115$Y;@La/AnAnnotation2;,]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 4)\n" +
+ " @AnAnnotation(value=)\n" +
+ " ^\n" +
+ "Syntax error on token \"=\", MemberValue expected after this token\n",
+ result);
+}
+public void testBug130778m() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[2];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation.java",
+ "package a;\n" +
+ "public @interface AnAnnotation {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ this.workingCopies[1] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation2.java",
+ "package a;\n" +
+ "public @interface AnAnnotation2 {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "public class X {\n" +
+ " public void foo(){\n" +
+ " [*1*]@AnAnnotation(value=)[*1*]\n" +
+ " [*2*]@AnAnnotation2(value=\"b\")[*2*]\n" +
+ " int i;\n" +
+ " }\n" +
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "public class X {\n" +
+ " public void foo(){\n" +
+ " [*1*]@AnAnnotation(value=$missing$)[*1*] [*2*]@AnAnnotation2(value=\"b\")[*2*] int i;\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:NORMAL_ANNOTATION,[53,21],,,[ANNOTATION,La/X;.foo()V#i@La/AnAnnotation;,]\n" +
+ "2:NORMAL_ANNOTATION,[79,25],,,[ANNOTATION,La/X;.foo()V#i@La/AnAnnotation2;,]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 4)\n" +
+ " @AnAnnotation(value=)\n" +
+ " ^\n" +
+ "Syntax error on token \"=\", MemberValue expected after this token\n",
+ result);
+}
+public void testBug130778n() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation.java",
+ "package a;\n" +
+ "public @interface AnAnnotation {\n" +
+ " String name1();\n" +
+ " String name2();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "[*1*][*2*]@AnAnnotation([*3*]name1=\"a\"[*3*][*2*], name2)\n" +
+ "public class X {\n" +
+ "}[*1*]\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "[*1*][*2*]@AnAnnotation([*3*]name1=\"a\"[*3*])[*2*] public class X {\n" +
+ "}[*1*]\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:TYPE_DECLARATION,[11,50],,MALFORMED|RECOVERED,[TYPE,La/X;,]\n" +
+ "2:NORMAL_ANNOTATION,[11,23],,RECOVERED,[ANNOTATION,La/X;@La/AnAnnotation;,]\n" +
+ "3:MEMBER_VALUE_PAIR,[25,9],,,[N/A]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 2)\n" +
+ " @AnAnnotation(name1=\"a\", name2)\n" +
+ " ^\n" +
+ "Syntax error on token \",\", . expected\n",
+ result);
+}
+public void testBug130778o() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation.java",
+ "package a;\n" +
+ "public @interface AnAnnotation {\n" +
+ " String name1();\n" +
+ " String name2();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "[*1*][*2*]@AnAnnotation([*3*]name1=[*3*][*2*])\n" +
+ "public class X {\n" +
+ "}[*1*]\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "[*1*][*2*]@AnAnnotation([*3*]name1=$missing$[*3*])[*2*] public class X {\n" +
+ "}[*1*]\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:TYPE_DECLARATION,[11,40],,MALFORMED,[TYPE,La/X;,]\n" +
+ "2:NORMAL_ANNOTATION,[11,20],,RECOVERED,[ANNOTATION,La/X;@La/AnAnnotation;,]\n" +
+ "3:MEMBER_VALUE_PAIR,[25,6],,RECOVERED,[N/A]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 2)\n" +
+ " @AnAnnotation(name1=)\n" +
+ " ^\n" +
+ "Syntax error on token \"=\", MemberValue expected after this token\n",
+ result);
+}
+public void testBug130778p() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[2];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation.java",
+ "package a;\n" +
+ "public @interface AnAnnotation {\n" +
+ " AnAnnotation2 value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ this.workingCopies[1] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation2.java",
+ "package a;\n" +
+ "public @interface AnAnnotation2 {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "[*1*]@AnAnnotation([*2*]value=[*3*]@AnAnnotation2(value=\"a\")[*3*][*2*])[*1*]\n" +
+ "public class X {\n" +
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "[*1*]@AnAnnotation([*2*]value=[*3*]@AnAnnotation2(value=\"a\")[*3*][*2*])[*1*] public class X {\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:NORMAL_ANNOTATION,[11,46],,,[ANNOTATION,La/X;@La/AnAnnotation;,]\n" +
+ "2:MEMBER_VALUE_PAIR,[25,31],,,[N/A]\n" +
+ "3:NORMAL_ANNOTATION,[31,25],,,[ANNOTATION,@La/AnAnnotation2;,]\n" +
+ "===== Problems =====\n" +
+ "No problem",
+ result);
+}
+public void testBug130778q() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[2];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation.java",
+ "package a;\n" +
+ "public @interface AnAnnotation {\n" +
+ " AnAnnotation2 value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ this.workingCopies[1] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation2.java",
+ "package a;\n" +
+ "public @interface AnAnnotation2 {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "[*1*]@AnAnnotation([*2*]value=[*3*]@AnAnnotation2(value=\"a\")[*3*][*2*][*1*]\n" +
+ "public class X {\n" +
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "[*1*]@AnAnnotation([*2*]value=[*3*]@AnAnnotation2(value=\"a\")[*3*][*2*])[*1*] public class X {\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:NORMAL_ANNOTATION,[11,45],,RECOVERED,[ANNOTATION,La/X;@La/AnAnnotation;,]\n" +
+ "2:MEMBER_VALUE_PAIR,[25,31],,,[N/A]\n" +
+ "3:NORMAL_ANNOTATION,[31,25],,RECOVERED,[ANNOTATION,@La/AnAnnotation2;,]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 2)\n" +
+ " @AnAnnotation(value=@AnAnnotation2(value=\"a\")\n" +
+ " ^\n" +
+ "Syntax error, insert \")\" to complete Modifiers\n",
+ result);
+}
+public void testBug130778r() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[2];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation.java",
+ "package a;\n" +
+ "public @interface AnAnnotation {\n" +
+ " AnAnnotation2 value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ this.workingCopies[1] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation2.java",
+ "package a;\n" +
+ "public @interface AnAnnotation2 {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "[*1*][*2*]@AnAnnotation(value=[*2*][*3*]@AnAnnotation2(value=[*3*]))\n" +
+ "public class X {\n" +
+ "}[*1*]\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "[*1*][*2*]@AnAnnotation(value=$missing$)[*2*] public class X {\n" +
+ "}[*1*]\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:TYPE_DECLARATION,[11,62],,MALFORMED|RECOVERED,[TYPE,La/X;,]\n" +
+ "2:NORMAL_ANNOTATION,[11,20],,RECOVERED,[ANNOTATION,La/X;@La/AnAnnotation;,]\n" +
+ "3:No corresponding node\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 2)\n" +
+ " @AnAnnotation(value=@AnAnnotation2(value=))\n" +
+ " ^\n" +
+ "Syntax error on token \"=\", MemberValue expected after this token\n",
+ result);
+}
+public void testBug130778s() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[2];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation.java",
+ "package a;\n" +
+ "public @interface AnAnnotation {\n" +
+ " String value1();\n" +
+ " AnAnnotation2 value2();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ this.workingCopies[1] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation2.java",
+ "package a;\n" +
+ "public @interface AnAnnotation2 {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "[*1*][*2*]@AnAnnotation([*3*]value1=[*3*][*2*],[*4*]value=[*5*]@AnAnnotation2(value=\"b\")[*5*][*4*])\n" +
+ "public class X {\n" +
+ "}[*1*]\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "[*1*][*2*]@AnAnnotation([*3*]value1=$missing$[*3*])[*2*] [*5*]@AnAnnotation2(value=\"b\")[*5*] public class X {\n" +
+ "}[*1*]\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:TYPE_DECLARATION,[11,73],,MALFORMED,[TYPE,La/X;,]\n" +
+ "2:NORMAL_ANNOTATION,[11,21],,RECOVERED,[ANNOTATION,La/X;@La/AnAnnotation;,]\n" +
+ "3:MEMBER_VALUE_PAIR,[25,7],,RECOVERED,[N/A]\n" +
+ "5:NORMAL_ANNOTATION,[39,25],,,[ANNOTATION,La/X;@La/AnAnnotation2;,]\n" +
+ "4:No corresponding node\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 2)\n" +
+ " @AnAnnotation(value1=,value=@AnAnnotation2(value=\"b\"))\n" +
+ " ^\n" +
+ "Syntax error on token \"=\", MemberValue expected after this token\n",
+ result);
+}
+public void testBug130778t() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation.java",
+ "package a;\n" +
+ "public @interface AnAnnotation {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "[*1*]@AnAnnotation(\"b\")[*1*]\n" +
+ "public class X {\n" +
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "[*1*]@AnAnnotation(\"b\")[*1*] public class X {\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:SINGLE_MEMBER_ANNOTATION,[11,18],,,[ANNOTATION,La/X;@La/AnAnnotation;,]\n" +
+ "===== Problems =====\n" +
+ "No problem",
+ result);
+}
+public void testBug130778u() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation.java",
+ "package a;\n" +
+ "public @interface AnAnnotation {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "[*1*]@AnAnnotation([*2*]\"b\"[*2*][*1*]\n" +
+ "public class X {\n" +
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "[*1*]@AnAnnotation([*2*]\"b\"[*2*])[*1*] public class X {\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:SINGLE_MEMBER_ANNOTATION,[11,17],,RECOVERED,[ANNOTATION,La/X;@La/AnAnnotation;,]\n" +
+ "2:STRING_LITERAL,[25,3],,,[N/A]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 2)\n" +
+ " @AnAnnotation(\"b\"\n" +
+ " ^^^\n" +
+ "Syntax error, insert \")\" to complete Modifiers\n",
+ result);
+}
+public void testBug130778v() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[2];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation.java",
+ "package a;\n" +
+ "public @interface AnAnnotation {\n" +
+ " AnAnnotation2 value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ this.workingCopies[1] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation2.java",
+ "package a;\n" +
+ "public @interface AnAnnotation2 {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "[*1*]@AnAnnotation[*1*](@AnAnnotation2(\"b\"\n" +
+ "public class X {\n" +
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "[*1*]@AnAnnotation[*1*] public class X {\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:MARKER_ANNOTATION,[11,13],,,[ANNOTATION,La/X;@La/AnAnnotation;,]\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 2)\n" +
+ " @AnAnnotation(@AnAnnotation2(\"b\"\n" +
+ " ^^^\n" +
+ "Syntax error, insert \")\" to complete SingleMemberAnnotation\n" +
+ "2. ERROR in /Converter15/src/a/X.java (at line 2)\n" +
+ " @AnAnnotation(@AnAnnotation2(\"b\"\n" +
+ " ^^^\n" +
+ "Syntax error, insert \")\" to complete Modifiers\n",
+ result);
+}
+public void testBug130778x() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter15/src/a/AnAnnotation.java",
+ "package a;\n" +
+ "public @interface AnAnnotation {\n" +
+ " String value();\n" +
+ "}\n",
+ true/*resolve*/);
+
+ ASTResult result = this.buildMarkedAST(
+ "/Converter15/src/a/X.java",
+ "package a;\n" +
+ "[*1*]@AnAnnotation([*2*]\"a\"[*2*][*1*], [*3*]\"b\"[*3*])\n" +
+ "public class X {\n" +
+ "}\n");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package a;\n" +
+ "[*1*]@AnAnnotation([*2*]\"a\"[*2*])[*1*] public class X {\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:SINGLE_MEMBER_ANNOTATION,[11,17],,RECOVERED,[ANNOTATION,La/X;@La/AnAnnotation;,]\n" +
+ "2:STRING_LITERAL,[25,3],,,[N/A]\n" +
+ "3:No corresponding node\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter15/src/a/X.java (at line 2)\n" +
+ " @AnAnnotation(\"a\", \"b\")\n" +
+ " ^\n" +
+ "Syntax error on token \",\", < expected\n",
+ result);
+}
+}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocFlattener.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocFlattener.java
new file mode 100644
index 0000000..d58dbdc
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocFlattener.java
@@ -0,0 +1,236 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2008 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.dom;
+
+import java.util.Iterator;
+
+import org.eclipse.jdt.core.dom.*;
+
+public class ASTConverterJavadocFlattener extends ASTVisitor {
+
+ /**
+ * The string buffer into which the serialized representation of the AST is
+ * written.
+ */
+ private StringBuffer buffer;
+ private int indent = 0;
+ private String comment;
+
+/**
+ * Creates a new AST printer.
+ */
+ASTConverterJavadocFlattener(String comment) {
+ this.buffer = new StringBuffer();
+ this.comment = comment;
+}
+
+/**
+ * Returns the string accumulated in the visit.
+ *
+ * @return the serialized
+ */
+public String getResult() {
+ return this.buffer.toString();
+}
+
+/**
+ * Resets this printer so that it can be used again.
+ */
+public void reset() {
+ this.buffer.setLength(0);
+}
+
+/*
+ * @see ASTVisitor#visit(ArrayType)
+ */
+public boolean visit(ArrayType node) {
+ node.getComponentType().accept(this);
+ this.buffer.append("[]");//$NON-NLS-1$
+ return false;
+}
+
+/*
+ * @see ASTVisitor#visit(BlockComment)
+ * @since 3.0
+ */
+public boolean visit(BlockComment node) {
+ this.buffer.append(this.comment);
+ return false;
+}
+
+/*
+ * @see ASTVisitor#visit(Javadoc)
+ */
+public boolean visit(Javadoc javadoc) {
+ printIndent();
+ this.buffer.append("/**");//$NON-NLS-1$
+ for (Iterator it = javadoc.tags().iterator(); it.hasNext(); ) {
+ ASTNode e = (ASTNode) it.next();
+ e.accept(this);
+ }
+ this.buffer.append("\n */\n");//$NON-NLS-1$
+ return false;
+}
+
+private void printIndent() {
+ for (int i=0; i<this.indent; i++) {
+ this.buffer.append('\t');
+ }
+}
+
+/*
+private void printNewLine() {
+ buffer.append('\n');
+ printIndent();
+ buffer.append(" * ");
+}
+*/
+
+/*
+ * @see ASTVisitor#visit(LineComment)
+ * @since 3.0
+ */
+public boolean visit(LineComment node) {
+ this.buffer.append(this.comment);
+ return false;
+}
+
+/*
+ * @see ASTVisitor#visit(MemberRef)
+ * @since 3.0
+ */
+public boolean visit(MemberRef node) {
+ if (node.getQualifier() != null) {
+ node.getQualifier().accept(this);
+ }
+ this.buffer.append("#");//$NON-NLS-1$
+ node.getName().accept(this);
+ return true;
+}
+
+/*
+ * @see ASTVisitor#visit(MethodRef)
+ * @since 3.0
+ */
+public boolean visit(MethodRef node) {
+ if (node.getQualifier() != null) {
+ node.getQualifier().accept(this);
+ }
+ this.buffer.append("#");//$NON-NLS-1$
+ node.getName().accept(this);
+ this.buffer.append("(");//$NON-NLS-1$
+ for (Iterator it = node.parameters().iterator(); it.hasNext(); ) {
+ MethodRefParameter e = (MethodRefParameter) it.next();
+ e.accept(this);
+ if (it.hasNext()) {
+ this.buffer.append(",");//$NON-NLS-1$
+ }
+ }
+ this.buffer.append(")");//$NON-NLS-1$
+ return true;
+}
+
+/*
+ * @see ASTVisitor#visit(MethodRefParameter)
+ * @since 3.0
+ */
+public boolean visit(MethodRefParameter node) {
+ node.getType().accept(this);
+ if (node.getName() != null) {
+ this.buffer.append(" ");//$NON-NLS-1$
+ node.getName().accept(this);
+ }
+ return true;
+}
+
+/*
+ * @see ASTVisitor#visit(TagElement)
+ * @since 3.0
+ */
+public boolean visit(TagElement node) {
+ if (node.isNested()) {
+ // nested tags are always enclosed in braces
+ this.buffer.append("{");//$NON-NLS-1$
+ } else {
+ // top-level tags always begin on a new line
+ this.buffer.append("\n * ");//$NON-NLS-1$
+ }
+ boolean previousRequiresWhiteSpace = false;
+ if (node.getTagName() != null) {
+ this.buffer.append(node.getTagName());
+ previousRequiresWhiteSpace = true;
+ }
+ boolean previousRequiresNewLine = false;
+ for (Iterator it = node.fragments().iterator(); it.hasNext(); ) {
+ ASTNode e = (ASTNode) it.next();
+ // assume text elements include necessary leading and trailing whitespace
+ // but Name, MemberRef, MethodRef, and nested TagElement do not include white space
+ boolean currentIncludesWhiteSpace = (e instanceof TextElement);
+ if (previousRequiresNewLine && currentIncludesWhiteSpace) {
+ this.buffer.append("\n * ");//$NON-NLS-1$
+ }
+ previousRequiresNewLine = currentIncludesWhiteSpace;
+ // add space if required to separate
+ if (previousRequiresWhiteSpace && !currentIncludesWhiteSpace) {
+ this.buffer.append(" "); //$NON-NLS-1$
+ }
+ e.accept(this);
+ previousRequiresWhiteSpace = !currentIncludesWhiteSpace && !(e instanceof TagElement);
+ }
+ if (node.isNested()) {
+ this.buffer.append("}");//$NON-NLS-1$
+ }
+ return false;
+}
+
+/*
+ * @see ASTVisitor#visit(TextElement)
+ * @since 3.0
+ */
+public boolean visit(TextElement node) {
+ this.buffer.append(node.getText());
+ return false;
+}
+
+/*
+ * @see ASTVisitor#visit(PrimitiveType)
+ */
+public boolean visit(PrimitiveType node) {
+ this.buffer.append(node.getPrimitiveTypeCode().toString());
+ return false;
+}
+
+/*
+ * @see ASTVisitor#visit(QualifiedName)
+ */
+public boolean visit(QualifiedName node) {
+ node.getQualifier().accept(this);
+ this.buffer.append(".");//$NON-NLS-1$
+ node.getName().accept(this);
+ return false;
+}
+
+/*
+ * @see ASTVisitor#visit(SimpleName)
+ */
+public boolean visit(SimpleName node) {
+ this.buffer.append(node.getIdentifier());
+ return false;
+}
+
+/*
+ * @see ASTVisitor#visit(SimpleName)
+ */
+public boolean visit(SimpleType node) {
+ node.getName().accept(this);
+ return false;
+}
+}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest.java
new file mode 100644
index 0000000..71e5271
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterJavadocTest.java
@@ -0,0 +1,3301 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2008 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.dom;
+
+import java.io.*;
+import java.lang.reflect.Method;
+import java.text.NumberFormat;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IJavaProject;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.compiler.IProblem;
+import org.eclipse.jdt.core.dom.*;
+import org.eclipse.jdt.internal.compiler.parser.ScannerHelper;
+
+/**
+ * Class to test DOM/AST nodes built for Javadoc comments.
+ *
+ * Most of tests are 'automatic'. It means that to add a new tests, you only need to
+ * create one or several CUs and put them in org.eclipse.jdt.core.model.tests/workspace/Converter/src/javadoc/testXXX
+ * folder and add the corresponding test in this class:
+ * <pre>
+ * public void testXXX() throws JavaModelException {
+ * verifyComments("testXXX");
+ * }
+ * </pre>
+ *
+ * Note that when a test fails, the easiest way to debug it is to open
+ * a runtime workbench, create a project 'Converter', delete the default 'src' source folder
+ * and replace it by a linked source to the 'src' folder of org.eclipse.jdt.core.model.tests/workspace/Converter/src
+ * in your workspace.
+ *
+ * Then open the CU on which the test fails in a ASTView and verify the offset/length
+ * of the offending node located at the positions displayed in the console when the test failed...
+ *
+ * Since 3.4, the failing test also provides the comparision between the source of the comment
+ * and the string get from the built DOM/AST nodes in the comment (see {@link ASTConverterJavadocFlattener})
+ * but this may be not enough to see precisely the origin of the problem.
+ */
+public class ASTConverterJavadocTest extends ConverterTestSetup {
+
+ // Flag to know whether Converter directory should be copied from org.eclipse.jdt.core.tests.model project
+ static protected boolean COPY_DIR = true;
+
+ // Test counters
+ protected static int[] TEST_COUNTERS = { 0, 0, 0, 0 };
+ // Unicode tests
+ protected static boolean UNICODE = false;
+ // Unix tests
+ final boolean unix;
+ static final String UNIX_SUPPORT = System.getProperty("unix");
+ // Doc Comment support
+ static final String DOC_COMMENT_SUPPORT = System.getProperty("doc.support");
+ final String docCommentSupport;
+
+ // List of comments read from source of test
+ private static final int LINE_COMMENT = 100;
+ private static final int BLOCK_COMMENT =200;
+ private static final int DOC_COMMENT = 300;
+ List comments = new ArrayList();
+ private String chars;
+ // List of tags contained in each comment read from test source.
+ List allTags = new ArrayList();
+ // Current compilation unit
+ protected ICompilationUnit sourceUnit;
+ // Test package binding
+ protected boolean resolveBinding = true;
+ protected boolean packageBinding = true;
+ // AST Level
+ /** @deprecated using deprecated code */
+ protected int astLevel = AST.JLS2;
+ protected int savedLevel;
+ // Debug
+ protected String prefix = "";
+ protected boolean debug = false;
+ protected StringBuffer problems;
+ protected String compilerOption = JavaCore.IGNORE;
+ protected List failures;
+ protected boolean stopOnFailure = true;
+ // Project
+ protected IJavaProject currentProject;
+ Map savedOptions = null;
+
+ /**
+ * @param name
+ * @param support
+ */
+ public ASTConverterJavadocTest(String name, String support, String unix) {
+ super(name);
+ this.docCommentSupport = support;
+ this.unix = "true".equals(unix);
+ }
+ /**
+ * @param name
+ */
+ public ASTConverterJavadocTest(String name) {
+ this(name, JavaCore.ENABLED, UNIX_SUPPORT);
+ }
+
+ public static Test suite() {
+ TestSuite suite = new Suite(ASTConverterJavadocTest.class.getName());
+// String param = System.getProperty("unicode");
+// if ("true".equals(param)) {
+// unicode = true;
+// }
+// String param = System.getProperty("unix");
+// if ("true".equals(param)) {
+// unix = true;
+// }
+ if (DOC_COMMENT_SUPPORT == null) {
+ buildSuite(suite, JavaCore.ENABLED);
+ buildSuite(suite, JavaCore.DISABLED);
+ } else {
+ String support = DOC_COMMENT_SUPPORT==null ? JavaCore.DISABLED : (DOC_COMMENT_SUPPORT.equals(JavaCore.DISABLED)?JavaCore.DISABLED:JavaCore.ENABLED);
+ buildSuite(suite, support);
+ }
+ return suite;
+
+// Run test cases subset
+// COPY_DIR = false;
+// System.err.println("WARNING: only subset of tests will be executed!!!");
+// suite.addTest(new ASTConverterJavadocTest("testBug165525"));
+// return suite;
+ }
+
+ public static void buildSuite(TestSuite suite, String support) {
+ Class c = ASTConverterJavadocTest.class;
+ Method[] methods = c.getMethods();
+ for (int i = 0, max = methods.length; i < max; i++) {
+ if (methods[i].getName().startsWith("test")) { //$NON-NLS-1$
+ suite.addTest(new ASTConverterJavadocTest(methods[i].getName(), support, UNIX_SUPPORT));
+ }
+ }
+ // when unix support not specified, also run using unix format
+ if (UNIX_SUPPORT == null && JavaCore.ENABLED.equals(support)) {
+ for (int i = 0, max = methods.length; i < max; i++) {
+ if (methods[i].getName().startsWith("test")) { //$NON-NLS-1$
+ suite.addTest(new ASTConverterJavadocTest(methods[i].getName(), support, "true"));
+ }
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.core.tests.model.AbstractJavaModelTests#copyDirectory(java.io.File, java.io.File)
+ */
+ protected void copyDirectory(File sourceDir, File targetDir) throws IOException {
+ if (COPY_DIR) {
+ super.copyDirectory(sourceDir, targetDir);
+ } else {
+ targetDir.mkdirs();
+ File sourceFile = new File(sourceDir, ".project");
+ File targetFile = new File(targetDir, ".project");
+ targetFile.createNewFile();
+ copy(sourceFile, targetFile);
+ sourceFile = new File(sourceDir, ".classpath");
+ targetFile = new File(targetDir, ".classpath");
+ targetFile.createNewFile();
+ copy(sourceFile, targetFile);
+ }
+ }
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#getName()
+ */
+ public String getName() {
+ String strUnix = this.unix ? " - Unix" : "";
+ return "Doc "+this.docCommentSupport+strUnix+" - "+super.getName();
+ }
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ TEST_COUNTERS[0]++;
+ this.failures = new ArrayList();
+ this.problems = new StringBuffer();
+ this.workingCopies = null;
+ this.savedLevel = this.astLevel;
+ }
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ int size = this.failures.size();
+ String title = size+" positions/bindings were incorrect in "+getName();
+ if (size == 0) {
+ TEST_COUNTERS[1]++;
+ } else if (this.problems.length() > 0) {
+ if (this.debug) {
+ System.out.println("Compilation warnings/errors occured:");
+ System.out.println(this.problems.toString());
+ }
+ TEST_COUNTERS[2]++;
+ } else {
+ TEST_COUNTERS[3]++;
+ System.out.println(title+":");
+ for (int i=0; i<size; i++) {
+ System.out.println(" - "+this.failures.get(i));
+ }
+ }
+// if (!stopOnFailure) {
+ assertTrue(title, size==0 || this.problems.length() > 0);
+// }
+ super.tearDown();
+
+ // Restore saved ast level
+ this.astLevel = this.savedLevel;
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ public void tearDownSuite() throws Exception {
+ // put default options on project
+ if (this.currentProject != null && this.savedOptions != null) {
+ this.currentProject.setOptions(this.savedOptions);
+ }
+ super.tearDownSuite();
+ if (TEST_COUNTERS[0] != TEST_COUNTERS[1]) {
+ NumberFormat intFormat = NumberFormat.getInstance();
+ intFormat.setMinimumIntegerDigits(3);
+ intFormat.setMaximumIntegerDigits(3);
+ System.out.println("=====================================");
+ System.out.println(intFormat.format(TEST_COUNTERS[0])+" tests have been executed:");
+ System.out.println(" - "+intFormat.format(TEST_COUNTERS[1])+" tests have been actually executed.");
+ System.out.println(" - "+intFormat.format(TEST_COUNTERS[2])+" tests were skipped due to compilation errors.");
+ System.out.println(" - "+intFormat.format(TEST_COUNTERS[3])+" tests failed.");
+ }
+ }
+
+ public ASTNode runConversion(char[] source, String unitName, IJavaProject project) {
+ ASTParser parser = ASTParser.newParser(this.astLevel);
+ parser.setSource(source);
+ parser.setUnitName(unitName);
+ parser.setProject(project);
+ parser.setResolveBindings(this.resolveBinding);
+ return parser.createAST(null);
+ }
+
+ public ASTNode runConversion(char[] source, String unitName, IJavaProject project, Map options) {
+ if (project == null) {
+ ASTParser parser = ASTParser.newParser(this.astLevel);
+ parser.setSource(source);
+ parser.setUnitName(unitName);
+ parser.setCompilerOptions(options);
+ parser.setResolveBindings(this.resolveBinding);
+ return parser.createAST(null);
+ }
+ return runConversion(source, unitName, project);
+ }
+
+ private char getNextChar(char[] source, int idx) {
+ // get next char
+ char ch = source[idx];
+ int charLength = 1;
+ int pos = idx;
+ this.chars = null;
+ if (ch == '\\' && source[idx+1] == 'u') {
+ //-------------unicode traitement ------------
+ int c1, c2, c3, c4;
+ charLength++;
+ while (source[idx+charLength] == 'u') charLength++;
+ if (((c1 = ScannerHelper.getNumericValue(source[idx+charLength++])) > 15
+ || c1 < 0)
+ || ((c2 = ScannerHelper.getNumericValue(source[idx+charLength++])) > 15 || c2 < 0)
+ || ((c3 = ScannerHelper.getNumericValue(source[idx+charLength++])) > 15 || c3 < 0)
+ || ((c4 = ScannerHelper.getNumericValue(source[idx+charLength++])) > 15 || c4 < 0)) {
+ return ch;
+ }
+ ch = (char) (((c1 * 16 + c2) * 16 + c3) * 16 + c4);
+ this.chars = new String(source, pos, charLength);
+ }
+ return ch;
+ }
+ /*
+ * Convert Javadoc source to match Javadoc.toString().
+ * Store converted comments and their corresponding tags respectively
+ * in comments and allTags fields
+ */
+ protected void setSourceComment(char[] source) throws ArrayIndexOutOfBoundsException {
+ this.comments = new ArrayList();
+ this.allTags = new ArrayList();
+ StringBuffer buffer = null;
+ int comment = 0;
+ boolean end = false, lineStarted = false;
+ String tag = null;
+ List tags = new ArrayList();
+ int length = source.length;
+ char previousChar=0, currentChar=0;
+ for (int i=0; i<length;) {
+ previousChar = currentChar;
+ // get next char
+ currentChar = getNextChar(source, i);
+ i += (this.chars==null) ? 1 : this.chars.length();
+
+ switch (comment) {
+ case 0:
+ switch (currentChar) {
+ case '/':
+ comment = 1; // first char for comments...
+ buffer = new StringBuffer();
+ if (this.chars == null) buffer.append(currentChar);
+ else buffer.append(this.chars);
+ break;
+ case '\'':
+ while (i<length) {
+ // get next char
+ currentChar = getNextChar(source, i);
+ i += (this.chars==null) ? 1 : this.chars.length();
+ if (currentChar == '\\') {
+ // get next char
+ currentChar = getNextChar(source, i);
+ i += (this.chars==null) ? 1 : this.chars.length();
+ } else {
+ if (currentChar == '\'') {
+ break;
+ }
+ }
+ }
+ break;
+ case '"':
+ while (i<length) {
+ // get next char
+ currentChar = getNextChar(source, i);
+ i += (this.chars==null) ? 1 : this.chars.length();
+ if (currentChar == '\\') {
+ // get next char
+ currentChar = getNextChar(source, i);
+ i += (this.chars==null) ? 1 : this.chars.length();
+ } else {
+ if (currentChar == '"') {
+ // get next char
+ currentChar = getNextChar(source, i);
+ if (currentChar == '"') {
+ i += (this.chars==null) ? 1 : this.chars.length();
+ } else {
+ break;
+ }
+ }
+ }
+ }
+ break;
+ }
+ break;
+ case 1: // first '/' has been found...
+ switch (currentChar) {
+ case '/':
+ if (this.chars == null) buffer.append(currentChar);
+ else buffer.append(this.chars);
+ comment = LINE_COMMENT;
+ break;
+ case '*':
+ if (this.chars == null) buffer.append(currentChar);
+ else buffer.append(this.chars);
+ comment = 2; // next step
+ break;
+ default:
+ comment = 0;
+ break;
+ }
+ break;
+ case 2: // '/*' has been found...
+ if (currentChar == '*') {
+ comment = 3; // next step...
+ } else {
+ comment = BLOCK_COMMENT;
+ }
+ if (this.chars == null) buffer.append(currentChar);
+ else buffer.append(this.chars);
+ break;
+ case 3: // '/**' has bee found, verify that's not an empty block comment
+ if (currentChar == '/') { // empty block comment
+ if (this.chars == null) buffer.append(currentChar);
+ else buffer.append(this.chars);
+ this.comments.add(buffer.toString());
+ this.allTags.add(new ArrayList());
+ comment = 0;
+ break;
+ }
+ comment = DOC_COMMENT;
+ // $FALL-THROUGH$ - do not break, directly go to next case...
+ case DOC_COMMENT:
+ if (tag != null) { // a tag name is currently scanned
+ if (currentChar >= 'a' && currentChar <= 'z') {
+ tag += currentChar;
+ } else {
+ tags.add(tag);
+ tag = null;
+ }
+ }
+ // Some characters are special in javadoc comments
+ switch (currentChar) {
+ case '@':
+ if (!lineStarted || previousChar == '{') {
+ tag = "";
+ lineStarted = true;
+ }
+ break;
+ case '\r':
+ case '\n':
+ lineStarted = false;
+ break;
+ case '*':
+ break;
+ default:
+ if (!Character.isWhitespace(currentChar)) {
+ lineStarted = true;
+ }
+ }
+ // $FALL-THROUGH$ - common treatment for block and javadoc comments
+ case BLOCK_COMMENT:
+ if (this.chars == null) buffer.append(currentChar);
+ else buffer.append(this.chars);
+ if (end && currentChar == '/') {
+ comment = 0;
+ lineStarted = false;
+ this.comments.add(buffer.toString());
+ this.allTags.add(tags);
+ tags = new ArrayList();
+ }
+ end = currentChar == '*';
+ break;
+ case LINE_COMMENT:
+ if (currentChar == '\r' || currentChar == '\n') {
+ /*
+ if (currentChar == '\r' && source[i+1] == '\n') {
+ buffer.append(source[++i]);
+ }
+ */
+ comment = 0;
+ this.comments.add(buffer.toString());
+ this.allTags.add(tags);
+ } else {
+ if (this.chars == null) buffer.append(currentChar);
+ else buffer.append(this.chars);
+ }
+ break;
+ default:
+ // do nothing
+ break;
+ }
+ }
+ }
+
+ /*
+ * Convert Javadoc source to match Javadoc.toString().
+ * Store converted comments and their corresponding tags respectively
+ * in comments and allTags fields
+ */
+ char[] getUnicodeSource(char[] source) {
+ int length = source.length;
+ int unicodeLength = length*6;
+ char[] unicodeSource = new char[unicodeLength];
+ int u=0;
+ for (int i=0; i<length; i++) {
+ // get next char
+ if (source[i] == '\\' && source[i+1] == 'u') {
+ //-------------unicode traitement ------------
+ int c1, c2, c3, c4;
+ unicodeSource[u++] = source[i];
+ unicodeSource[u++] = source[++i];
+ if (((c1 = ScannerHelper.getNumericValue(source[i+1])) > 15
+ || c1 < 0)
+ || ((c2 = ScannerHelper.getNumericValue(source[i+2])) > 15 || c2 < 0)
+ || ((c3 = ScannerHelper.getNumericValue(source[i+3])) > 15 || c3 < 0)
+ || ((c4 = ScannerHelper.getNumericValue(source[i+4])) > 15 || c4 < 0)) {
+ throw new RuntimeException("Invalid unicode in source at "+i);
+ }
+ for (int j=0; j<4; j++) unicodeSource[u++] = source[++i];
+ } else {
+ unicodeSource[u++] = '\\';
+ unicodeSource[u++] = 'u';
+ unicodeSource[u++] = '0';
+ unicodeSource[u++] = '0';
+ int val = source[i]/16;
+ unicodeSource[u++] = (char) (val<10 ? val+ 0x30 : val-10+0x61);
+ val = source[i]%16;
+ unicodeSource[u++] = (char) (val<10 ? val+ 0x30 : val-10+0x61);
+ }
+ }
+ // Return one well sized array
+ if (u != unicodeLength) {
+ char[] result = new char[u];
+ System.arraycopy(unicodeSource, 0, result, 0, u);
+ return result;
+ }
+ return unicodeSource;
+ }
+
+ /*
+ * Convert Javadoc source to match Javadoc.toString().
+ * Store converted comments and their corresponding tags respectively
+ * in comments and allTags fields
+ */
+ char[] getUnixSource(char[] source) {
+ int length = source.length;
+ int unixLength = length;
+ char[] unixSource = new char[unixLength];
+ int u=0;
+ for (int i=0; i<length; i++) {
+ // get next char
+ if (source[i] == '\r' && source[i+1] == '\n') {
+ i++;
+ }
+ unixSource[u++] = source[i];
+ }
+ // Return one well sized array
+ if (u != unixLength) {
+ char[] result = new char[u];
+ System.arraycopy(unixSource, 0, result, 0, u);
+ return result;
+ }
+ return unixSource;
+ }
+
+ /*
+ * Return all tags number for a given Javadoc
+ */
+ int allTags(Javadoc docComment) {
+ int all = 0;
+ // Count main tags
+ Iterator tags = docComment.tags().listIterator();
+ while (tags.hasNext()) {
+ TagElement tagElement = (TagElement) tags.next();
+ if (tagElement.getTagName() != null) {
+ all++;
+ }
+ Iterator fragments = tagElement.fragments().listIterator();
+ while (fragments.hasNext()) {
+ ASTNode node = (ASTNode) fragments.next();
+ if (node.getNodeType() == ASTNode.TAG_ELEMENT) {
+ all++;
+ }
+ }
+ }
+ return all;
+ }
+
+ /*
+ * Add a failure to the list. Use only one method as it easier to put breakpoint to
+ * debug failure when it occurs...
+ */
+ private void addFailure(String msg) {
+ this.failures.add(msg);
+ }
+
+ /*
+ * Put the failure message in list instead of throwing exception immediately.
+ * This allow to store several failures per test...
+ * @see tearDown method which finally throws the execption to signal that test fails.
+ */
+ protected void assumeTrue(String msg, boolean cond) {
+ if (!cond) {
+ addFailure(msg);
+ if (this.stopOnFailure) assertTrue(msg, cond);
+ }
+ }
+
+ /*
+ * Put the failure message in list instead of throwing exception immediately.
+ * This allow to store several failures per test...
+ * @see tearDown method which finally throws the execption to signal that test fails.
+ */
+ protected void assumeNull(String msg, Object obj) {
+ if (obj != null) {
+ addFailure(msg);
+ if (this.stopOnFailure) assertNull(msg, obj);
+ }
+ }
+
+ /*
+ * Put the failure message in list instead of throwing exception immediately.
+ * This allow to store several failures per test...
+ * @see tearDown method which finally throws the execption to signal that test fails.
+ */
+ protected void assumeNotNull(String msg, Object obj) {
+ if (obj == null) {
+ addFailure(msg);
+ if (this.stopOnFailure) assertNotNull(msg, obj);
+ }
+ }
+
+ /*
+ * Put the failure message in list instead of throwing exception immediately.
+ * This allow to store several failures per test...
+ * @see tearDown method which finally throws the execption to signal that test fails.
+ */
+ protected void assumeEquals(String msg, int expected, int actual) {
+ if (expected != actual) {
+ addFailure(msg+", expected="+expected+" actual="+actual);
+ if (this.stopOnFailure) assertEquals(msg, expected, actual);
+ }
+ }
+
+ /*
+ * Put the failure message in list instead of throwing exception immediately.
+ * This allow to store several failures per test...
+ * @see tearDown method which finally throws the execption to signal that test fails.
+ */
+ protected void assumeEquals(String msg, Object expected, Object actual) {
+ if (expected == null && actual == null)
+ return;
+ if (expected != null && expected.equals(actual))
+ return;
+ addFailure(msg+", expected:<"+expected+"> actual:<"+actual+'>');
+ if (this.stopOnFailure) assertEquals(msg, expected, actual);
+ }
+
+ /*
+ * Verify positions of tags in source
+ */
+ private void verifyPositions(Javadoc docComment, char[] source) {
+ boolean stop = this.stopOnFailure;
+ this.stopOnFailure = false;
+ // Verify javadoc start and end position
+ int start = docComment.getStartPosition();
+ int end = start+docComment.getLength()-1;
+ assumeTrue(this.prefix+"Misplaced javadoc start at <"+start+">: "+docComment, source[start++] == '/' && source[start++] == '*' && source[start++] == '*');
+ // Get first meaningful character
+ int tagStart = start;
+ // Verify tags
+ Iterator tags = docComment.tags().listIterator();
+ while (tags.hasNext()) {
+ while (source[tagStart] == '*' || Character.isWhitespace(source[tagStart])) {
+ tagStart++; // purge non-stored characters
+ }
+ TagElement tagElement = (TagElement) tags.next();
+ int teStart = tagElement.getStartPosition();
+ assumeEquals(this.prefix+"Wrong start position <"+teStart+"> for tag element: "+tagElement, tagStart, teStart);
+ verifyPositions(tagElement, source);
+ tagStart += tagElement.getLength();
+ }
+ while (source[tagStart] == '*' || Character.isWhitespace(source[tagStart])) {
+ tagStart++; // purge non-stored characters
+ }
+ assumeTrue(this.prefix+"Misplaced javadoc end at <"+tagStart+'>', source[tagStart-1] == '*' && source[tagStart] == '/');
+ assumeEquals(this.prefix+"Wrong javadoc length at <"+end+">: ", tagStart, end);
+ this.stopOnFailure = stop;
+ if (stop && this.failures.size() > 0) {
+ String expected = new String(source, docComment.getStartPosition(), docComment.getLength());
+ ASTConverterJavadocFlattener flattener = new ASTConverterJavadocFlattener(expected);
+ docComment.accept(flattener);
+ assertEquals("Unexpected errors while verifying javadoc comment positions!", expected, flattener.getResult());
+ }
+ }
+
+ /**
+ * Verify positions of fragments in source
+ * @deprecated using deprecated code
+ */
+ private void verifyPositions(TagElement tagElement, char[] source) {
+ String text = null;
+ // Verify tag name
+ String tagName = tagElement.getTagName();
+ int tagStart = tagElement.getStartPosition();
+ if (tagElement.isNested()) {
+ assumeEquals(this.prefix+"Wrong start position <"+tagStart+"> for "+tagElement, '{', source[tagStart++]);
+ }
+ if (tagName != null) {
+ text= new String(source, tagStart, tagName.length());
+ assumeEquals(this.prefix+"Misplaced tag name at <"+tagStart+">: ", tagName, text);
+ tagStart += tagName.length();
+ }
+ // Verify each fragment
+ ASTNode previousFragment = null;
+ Iterator elements = tagElement.fragments().listIterator();
+ while (elements.hasNext()) {
+ ASTNode fragment = (ASTNode) elements.next();
+ if (fragment.getNodeType() == ASTNode.TEXT_ELEMENT) {
+ if (previousFragment == null && TagElement.TAG_PARAM.equals(tagName) && ((TextElement)fragment).getText().equals("<")) { // special case here for @param <E> syntax
+ int start = tagStart;
+ // verify '<'
+ while (source[start] == ' ' || Character.isWhitespace(source[start])) {
+ start++; // purge white characters
+ }
+ text = new String(source, start, fragment.getLength());
+ assumeEquals(this.prefix+"Misplaced text element at <"+fragment.getStartPosition()+">: ", text, ((TextElement) fragment).getText());
+ start += fragment.getLength();
+ // verify simple name
+ assumeTrue(this.prefix+"Unexpected fragment end for "+tagElement, elements.hasNext());
+ fragment = (ASTNode) elements.next();
+ while (source[start] == ' ' || Character.isWhitespace(source[start])) {
+ start++; // purge white characters
+ }
+ assumeEquals(this.prefix+"Unexpected node type for tag element "+tagElement, ASTNode.SIMPLE_NAME, fragment.getNodeType());
+ Name name = (Name) fragment;
+ verifyNamePositions(start, name, source);
+ start += fragment.getLength();
+ // verify simple name
+ assumeTrue(this.prefix+"Unexpected fragment end for "+tagElement, elements.hasNext());
+ fragment = (ASTNode) elements.next();
+ while (source[start] == ' ' || Character.isWhitespace(source[start])) {
+ start++; // purge white characters
+ }
+ text = new String(source, start, fragment.getLength());
+ assumeEquals(this.prefix+"Misplaced text element at <"+fragment.getStartPosition()+">: ", text, ((TextElement) fragment).getText());
+ start += fragment.getLength();
+ // reset fragment as simple name to avoid issue with next text element
+ fragment = name;
+ tagStart += (start- tagStart) - name.getLength();
+ } else {
+ if (previousFragment == null) {
+ if (tagName != null && (source[tagStart] == '\r' || source[tagStart] == '\n')) {
+ while (source[tagStart] == '*' || Character.isWhitespace(source[tagStart])) {
+ tagStart++; // purge non-stored characters
+ }
+ }
+ } else {
+ if (previousFragment.getNodeType() == ASTNode.TEXT_ELEMENT) {
+ assumeTrue(this.prefix+"Wrong length at <"+previousFragment.getStartPosition()+"> for text element "+previousFragment, (source[tagStart] == '\r' /* && source[tagStart+1] == '\n' */ || source[tagStart] == '\n'));
+ while (source[tagStart] == '*' || Character.isWhitespace(source[tagStart])) {
+ tagStart++; // purge non-stored characters
+ }
+ } else if (TagElement.TAG_PARAM.equals(tagName) && previousFragment.getNodeType() == ASTNode.SIMPLE_NAME && ((TextElement)fragment).getText().equals(">")) {
+ while (source[tagStart] == ' ' || Character.isWhitespace(source[tagStart])) {
+ tagStart++; // purge white characters
+ }
+ } else {
+ int start = tagStart;
+ boolean newLine = false;
+ while (source[start] == '*' || Character.isWhitespace(source[start])) {
+ start++; // purge non-stored characters
+ if (source[tagStart] == '\r' || source[tagStart] == '\n') {
+ newLine = true;
+ }
+ }
+ if (newLine) tagStart = start;
+ }
+ }
+ text = new String(source, tagStart, fragment.getLength());
+ assumeEquals(this.prefix+"Misplaced text element at <"+fragment.getStartPosition()+">: ", text, ((TextElement) fragment).getText());
+ }
+ } else {
+ while (source[tagStart] == '*' || Character.isWhitespace(source[tagStart])) {
+ tagStart++; // purge non-stored characters
+ }
+ if (fragment.getNodeType() == ASTNode.SIMPLE_NAME || fragment.getNodeType() == ASTNode.QUALIFIED_NAME) {
+ verifyNamePositions(tagStart, (Name) fragment, source);
+ } else if (fragment.getNodeType() == ASTNode.TAG_ELEMENT) {
+ TagElement inlineTag = (TagElement) fragment;
+ assumeEquals(this.prefix+"Tag element <"+inlineTag+"> has wrong start position", tagStart, inlineTag.getStartPosition());
+ verifyPositions(inlineTag, source);
+ } else if (fragment.getNodeType() == ASTNode.MEMBER_REF) {
+ MemberRef memberRef = (MemberRef) fragment;
+ // Store start position
+ int start = tagStart;
+ // Verify qualifier position
+ Name qualifier = memberRef.getQualifier();
+ if (qualifier != null) {
+ verifyNamePositions(start, qualifier, source);
+ start += qualifier.getLength();
+ while (source[start] == '*' || Character.isWhitespace(source[start])) {
+ start++; // purge non-stored characters
+ }
+ }
+ // Verify member separator position
+ assumeEquals(this.prefix+"Misplaced # separator at <"+start+"> for member ref "+memberRef, '#', source[start]);
+ start++;
+ while (source[start] == '*' || Character.isWhitespace(source[start])) {
+ start++; // purge non-stored characters
+ }
+ // Verify member name position
+ Name name = memberRef.getName();
+ text = new String(source, start, name.getLength());
+ assumeEquals(this.prefix+"Misplaced member ref at <"+start+">: ", text, name.toString());
+ verifyNamePositions(start, name, source);
+ } else if (fragment.getNodeType() == ASTNode.METHOD_REF) {
+ MethodRef methodRef = (MethodRef) fragment;
+ // Store start position
+ int start = tagStart;
+ // Verify qualifier position
+ Name qualifier = methodRef.getQualifier();
+ if (qualifier != null) {
+ verifyNamePositions(start, qualifier, source);
+ start += qualifier.getLength();
+ while (source[start] == '*' || Character.isWhitespace(source[start])) {
+ start++; // purge non-stored characters
+ }
+ }
+ // Verify member separator position
+ assumeEquals(this.prefix+"Misplaced # separator at <"+start+"> for method ref: "+methodRef, '#', source[start]);
+ start++;
+ while (source[start] == '*' || Character.isWhitespace(source[start])) {
+ start++; // purge non-stored characters
+ }
+ // Verify member name position
+ Name name = methodRef.getName();
+ int nameLength = name.getLength();
+ text = new String(source, start, nameLength);
+ if (!text.equals(name.toString())) { // may have qualified constructor reference for inner classes
+ if (methodRef.getQualifier().isQualifiedName()) {
+ text = new String(source, start, methodRef.getQualifier().getLength());
+ assumeEquals(this.prefix+"Misplaced method ref name at <"+start+">: ", text, methodRef.getQualifier().toString());
+ while (source[start] != '.' || Character.isWhitespace(source[start])) {
+ start++; // purge non-stored characters
+ }
+ start++;
+ } else {
+ while (source[start] != '.' || Character.isWhitespace(source[start])) {
+ start++; // purge non-stored characters
+ }
+ start++;
+ text = new String(source, start, nameLength);
+ assumeEquals(this.prefix+"Misplaced method ref name at <"+start+">: ", text, name.toString());
+ }
+ }
+ verifyNamePositions(start, name, source);
+ start += nameLength;
+ // Verify arguments starting open parenthesis
+ while (source[start] == '*' || Character.isWhitespace(source[start])) {
+ start++; // purge non-stored characters
+ }
+// assumeEquals(prefix+"Misplaced ( at <"+start+"> for method ref: "+methodRef, '(', source[start]);
+ if (source[start] == '(') { // now method reference may have no parenthesis...
+ start++;
+ // Verify parameters
+ Iterator parameters = methodRef.parameters().listIterator();
+ while (parameters.hasNext()) {
+ MethodRefParameter param = (MethodRefParameter) parameters.next();
+ boolean lastParam = !parameters.hasNext();
+ // Verify parameter type positions
+ while (source[start] == '*' || Character.isWhitespace(source[start])) {
+ start++; // purge non-stored characters
+ }
+ Type type = param.getType();
+ if (type.isSimpleType()) {
+ verifyNamePositions(start, ((SimpleType)type).getName(), source);
+ } else if (type.isPrimitiveType()) {
+ text = new String(source, start, type.getLength());
+ assumeEquals(this.prefix+"Misplaced method ref parameter type at <"+start+"> for method ref: "+methodRef, text, type.toString());
+ } else if (type.isArrayType()) {
+ Type elementType = ((ArrayType) param.getType()).getElementType();
+ if (elementType.isSimpleType()) {
+ verifyNamePositions(start, ((SimpleType)elementType).getName(), source);
+ } else if (elementType.isPrimitiveType()) {
+ text = new String(source, start, elementType.getLength());
+ assumeEquals(this.prefix+"Misplaced method ref parameter type at <"+start+"> for method ref: "+methodRef, text, elementType.toString());
+ }
+ }
+ start += type.getLength();
+ // if last param then perhaps a varargs
+ while (Character.isWhitespace(source[start])) { // do NOT accept '*' in parameter declaration
+ start++; // purge non-stored characters
+ }
+ if (lastParam && this.astLevel != AST.JLS2 && param.isVarargs()) {
+ for (int p=0;p<3;p++) {
+ assumeTrue(this.prefix+"Missing ellipsis for vararg method ref parameter at <"+start+"> for method ref: "+methodRef, source[start++]=='.');
+ }
+ }
+ // Verify parameter name positions
+ while (Character.isWhitespace(source[start])) { // do NOT accept '*' in parameter declaration
+ start++; // purge non-stored characters
+ }
+ name = param.getName();
+ if (name != null) {
+ text = new String(source, start, name.getLength());
+ assumeEquals(this.prefix+"Misplaced method ref parameter name at <"+start+"> for method ref: "+methodRef, text, name.toString());
+ start += name.getLength();
+ }
+ // Verify end parameter declaration
+ while (source[start] == '*' || Character.isWhitespace(source[start])) {
+ start++;
+ }
+ assumeTrue(this.prefix+"Misplaced parameter end at <"+start+"> for method ref: "+methodRef, source[start] == ',' || source[start] == ')');
+ start++;
+ if (source[start] == ')') {
+ break;
+ }
+ }
+ }
+ }
+ }
+ tagStart += fragment.getLength();
+ previousFragment = fragment;
+ }
+ if (tagElement.isNested()) {
+ assumeEquals(this.prefix+"Wrong end character at <"+tagStart+"> for "+tagElement, '}', source[tagStart++]);
+ }
+ }
+
+ /*
+ * Verify each name component positions.
+ */
+ private void verifyNamePositions(int nameStart, Name name, char[] source) {
+ if (name.isQualifiedName()) {
+ QualifiedName qualified = (QualifiedName) name;
+ int start = qualified.getName().getStartPosition();
+ String str = new String(source, start, qualified.getName().getLength());
+ assumeEquals(this.prefix+"Misplaced or wrong name for qualified name: "+name, str, qualified.getName().toString());
+ verifyNamePositions(nameStart, ((QualifiedName) name).getQualifier(), source);
+ }
+ String str = new String(source, nameStart, name.getLength());
+ if (str.indexOf('\n') < 0) { // cannot compare if text contains new line
+ assumeEquals(this.prefix+"Misplaced name for qualified name: ", str, name.toString());
+ } else if (this.debug) {
+ System.out.println(this.prefix+"Name contains new line for qualified name: "+name);
+ }
+ }
+
+ /*
+ * Verify that bindings of Javadoc comment structure are resolved or not.
+ * For expected unresolved binding, verify that following text starts with 'Unknown'
+ */
+ private void verifyBindings(Javadoc docComment) {
+ boolean stop = this.stopOnFailure;
+// stopOnFailure = false;
+ // Verify tags
+ Iterator tags = docComment.tags().listIterator();
+ while (tags.hasNext()) {
+ verifyBindings((TagElement) tags.next());
+ }
+ this.stopOnFailure = stop;
+ assertTrue(!stop || this.failures.size()==0);
+ }
+
+ /*
+ * Verify that bindings of Javadoc tag structure are resolved or not.
+ * For expected unresolved binding, verify that following text starts with 'Unknown'
+ */
+ private void verifyBindings(TagElement tagElement) {
+ // Verify each fragment
+ Iterator elements = tagElement.fragments().listIterator();
+ IBinding previousBinding = null;
+ ASTNode previousFragment = null;
+ boolean resolvedBinding = false;
+ while (elements.hasNext()) {
+ ASTNode fragment = (ASTNode) elements.next();
+ if (fragment.getNodeType() == ASTNode.TEXT_ELEMENT) {
+ TextElement text = (TextElement) fragment;
+ if (resolvedBinding) {
+ if (previousBinding == null) {
+ assumeTrue(this.prefix+"Reference '"+previousFragment+"' should be bound!", text.getText().trim().indexOf("Unknown")>=0);
+ } else {
+ assumeTrue(this.prefix+"Unknown reference '"+previousFragment+"' should NOT be bound!", text.getText().trim().indexOf("Unknown")<0);
+ }
+ }
+ previousBinding = null;
+ resolvedBinding = false;
+ } else if (fragment.getNodeType() == ASTNode.TAG_ELEMENT) {
+ verifyBindings((TagElement) fragment);
+ previousBinding = null;
+ resolvedBinding = false;
+ } else {
+ resolvedBinding = true;
+ if (fragment.getNodeType() == ASTNode.SIMPLE_NAME) {
+ previousBinding = ((Name)fragment).resolveBinding();
+ } else if (fragment.getNodeType() == ASTNode.QUALIFIED_NAME) {
+ QualifiedName name = (QualifiedName) fragment;
+ previousBinding = name.resolveBinding();
+ verifyNameBindings(name);
+ } else if (fragment.getNodeType() == ASTNode.MEMBER_REF) {
+ MemberRef memberRef = (MemberRef) fragment;
+ previousBinding = memberRef.resolveBinding();
+ if (previousBinding != null) {
+ SimpleName name = memberRef.getName();
+ assumeNotNull(this.prefix+""+name+" binding was not foundfound in "+fragment, name.resolveBinding());
+ verifyNameBindings(memberRef.getQualifier());
+ }
+ } else if (fragment.getNodeType() == ASTNode.METHOD_REF) {
+ MethodRef methodRef = (MethodRef) fragment;
+ previousBinding = methodRef.resolveBinding();
+ if (previousBinding != null) {
+ SimpleName methodName = methodRef.getName();
+ IBinding methNameBinding = methodName.resolveBinding();
+ Name methodQualifier = methodRef.getQualifier();
+ // TODO (frederic) Replace the two following lines by commented block when bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=62650 will be fixed
+ assumeNotNull(this.prefix+""+methodName+" binding was not found in "+fragment, methNameBinding);
+ verifyNameBindings(methodQualifier);
+ /*
+ if (methodQualifier == null) {
+ if (methNameBinding == null) {
+ char firstChar = methodName.getIdentifier().charAt(0);
+ if (Character.isUpperCase(firstChar)) {
+ // assume that selector starting with uppercase is for constructor => signal that binding is null
+ System.out.println(prefix+"Binding for selector of '"+methodRef+"' is null.");
+ }
+ } else {
+ if (methNameBinding.getName().equals(methodName.getIdentifier())) { // binding is not null only for constructor
+ assumeNotNull(prefix+""+methodName+" binding was not found!",methNameBinding);
+ } else {
+ assumeNull(prefix+""+methodName+" binding should be null!", methNameBinding);
+ }
+ }
+ } else {
+ SimpleName methodSimpleType = null;
+ if (methodQualifier.isQualifiedName()) {
+ methodSimpleType = ((QualifiedName)methodQualifier).getName();
+ } else {
+ methodSimpleType = (SimpleName) methodQualifier;
+ }
+ if (methodSimpleType.getIdentifier().equals(methodName.getIdentifier())) { // binding is not null only for constructor
+ assumeNotNull(prefix+""+methodName+" binding was not found!",methNameBinding);
+ } else {
+ assumeNull(prefix+""+methodName+" binding should be null!", methNameBinding);
+ }
+ verifyNameBindings(methodRef.getQualifier());
+ }
+ */
+ Iterator parameters = methodRef.parameters().listIterator();
+ while (parameters.hasNext()) {
+ MethodRefParameter param = (MethodRefParameter) parameters.next();
+ Type type = param.getType();
+ assumeNotNull(this.prefix+""+type+" binding was not found in "+fragment, type.resolveBinding());
+ if (type.isSimpleType()) {
+ verifyNameBindings(((SimpleType)type).getName());
+ } else if (type.isArrayType()) {
+ Type elementType = ((ArrayType) param.getType()).getElementType();
+ assumeNotNull(this.prefix+""+elementType+" binding was not found in "+fragment, elementType.resolveBinding());
+ if (elementType.isSimpleType()) {
+ verifyNameBindings(((SimpleType)elementType).getName());
+ }
+ }
+ // Do not verify parameter name as no binding is expected for them
+ }
+ }
+ }
+ }
+ previousFragment = fragment;
+ }
+ assumeTrue(this.prefix+"Reference '"+(previousFragment==null?tagElement:previousFragment)+"' should be bound!", (!resolvedBinding || previousBinding != null));
+ }
+
+ /*
+ * Verify each name component binding.
+ */
+ private void verifyNameBindings(Name name) {
+ if (name != null) {
+ IBinding binding = name.resolveBinding();
+ if (name.toString().indexOf("Unknown") > 0) {
+ assumeNull(this.prefix+name+" binding should be null!", binding);
+ } else {
+ assumeNotNull(this.prefix+name+" binding was not found!", binding);
+ }
+ SimpleName simpleName = null;
+ int index = 0;
+ while (name.isQualifiedName()) {
+ simpleName = ((QualifiedName) name).getName();
+ binding = simpleName.resolveBinding();
+ if (simpleName.getIdentifier().equalsIgnoreCase("Unknown")) {
+ assumeNull(this.prefix+simpleName+" binding should be null!", binding);
+ } else {
+ assumeNotNull(this.prefix+simpleName+" binding was not found!", binding);
+ }
+ if (index > 0 && this.packageBinding) {
+ assumeEquals(this.prefix+"Wrong binding type!", IBinding.PACKAGE, binding.getKind());
+ }
+ index++;
+ name = ((QualifiedName) name).getQualifier();
+ binding = name.resolveBinding();
+ if (name.toString().indexOf("Unknown") > 0) {
+ assumeNull(this.prefix+name+" binding should be null!", binding);
+ } else {
+ assumeNotNull(this.prefix+name+" binding was not found!", binding);
+ }
+ if (this.packageBinding) {
+ assumeEquals(this.prefix+"Wrong binding type!", IBinding.PACKAGE, binding.getKind());
+ }
+ }
+ }
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void verifyComments(String test) throws JavaModelException {
+ ICompilationUnit[] units = getCompilationUnits("Converter" , "src", "javadoc."+test); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ for (int i=0; i<units.length; i++) {
+ verifyComments(units[i]);
+ }
+ }
+
+ /*
+ * Verify the comments of a compilation unit.
+ */
+ protected void verifyWorkingCopiesComments() throws JavaModelException {
+ assumeNotNull("No working copies to verify!", this.workingCopies);
+ int length = this.workingCopies.length;
+ assumeTrue("We need to have at least one working copy to verify!", length>0);
+ for (int i=0; i<length; i++) {
+ verifyComments(this.workingCopies[i]);
+ }
+ }
+
+ /*
+ * Verify the comments of a compilation unit.
+ */
+ protected CompilationUnit verifyComments(ICompilationUnit unit) throws JavaModelException {
+ // Get test file
+ this.sourceUnit = unit;
+ this.prefix = unit.getElementName()+": ";
+
+ // Get current project
+ String sourceStr = this.sourceUnit.getSource();
+ if (this.savedOptions != null && !this.sourceUnit.getJavaProject().getElementName().equals(this.currentProject.getElementName())) {
+ this.currentProject.setOptions(this.savedOptions);
+ this.savedOptions = null;
+ }
+ this.currentProject = this.sourceUnit.getJavaProject();
+ if (this.savedOptions == null) this.savedOptions = this.currentProject.getOptions(false);
+
+ // set up java project options
+ this.currentProject.setOption(JavaCore.COMPILER_PB_INVALID_JAVADOC, this.compilerOption);
+ this.currentProject.setOption(JavaCore.COMPILER_PB_MISSING_JAVADOC_TAGS, this.compilerOption);
+ this.currentProject.setOption(JavaCore.COMPILER_PB_MISSING_JAVADOC_COMMENTS, this.compilerOption);
+ this.currentProject.setOption(JavaCore.COMPILER_PB_METHOD_WITH_CONSTRUCTOR_NAME, JavaCore.IGNORE);
+ this.currentProject.setOption(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, this.docCommentSupport);
+
+ // Verify source regardings converted comments
+ char[] source = sourceStr.toCharArray();
+ String fileName = unit.getPath().toString();
+ try {
+ return verifyComments(fileName, source);
+ }
+ catch (RuntimeException ex) {
+ TEST_COUNTERS[3]++;
+ throw ex;
+ }
+ }
+
+ protected CompilationUnit verifyComments(String fileName, char[] source) {
+ return verifyComments(fileName, source, null);
+ }
+
+ protected CompilationUnit verifyComments(String fileName, char[] source, Map options) {
+
+ // Verify comments either in unicode or not
+ char[] testedSource = source;
+ if (UNICODE) {
+ testedSource = getUnicodeSource(source);
+ }
+
+ // Verify comments either in unicode or not
+ else if (this.unix) {
+ testedSource = getUnixSource(source);
+ }
+
+ // Get comments infos from test file
+ setSourceComment(testedSource);
+
+ // Create DOM AST nodes hierarchy
+ List unitComments = null;
+ String sourceLevel = null;
+ String complianceLevel = null;
+ if (this.currentProject != null) {
+ if (this.astLevel == AST.JLS3) {
+ complianceLevel = this.currentProject.getOption(JavaCore.COMPILER_COMPLIANCE, true);
+ sourceLevel = this.currentProject.getOption(JavaCore.COMPILER_SOURCE, true);
+ this.currentProject.setOption(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_5);
+ this.currentProject.setOption(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_5);
+ }
+ }
+ CompilationUnit compilUnit = (CompilationUnit) runConversion(testedSource, fileName, this.currentProject, options);
+ if (this.compilerOption.equals(JavaCore.ERROR)) {
+ assumeEquals(this.prefix+"Unexpected problems", 0, compilUnit.getProblems().length); //$NON-NLS-1$
+ } else if (this.compilerOption.equals(JavaCore.WARNING)) {
+ IProblem[] problemsList = compilUnit.getProblems();
+ int length = problemsList.length;
+ if (length > 0) {
+ this.problems.append(" - "+this.prefix+length+" problems:"); //$NON-NLS-1$
+ for (int i = 0; i < problemsList.length; i++) {
+ this.problems.append(" + ");
+ this.problems.append(problemsList[i]);
+ this.problems.append("\n");
+ }
+ }
+ }
+ unitComments = compilUnit.getCommentList();
+ assumeNotNull(this.prefix+"Unexpected problems", unitComments);
+
+ // Basic comments verification
+ int size = unitComments.size();
+ assumeEquals(this.prefix+"Wrong number of comments!", this.comments.size(), size);
+
+ // Verify comments positions and bindings
+ for (int i=0; i<size; i++) {
+ Comment comment = (Comment) unitComments.get(i);
+ List tags = (List) this.allTags.get(i);
+ // Verify flattened content
+ String stringComment = (String) this.comments.get(i);
+// ASTConverterJavadocFlattener printer = new ASTConverterJavadocFlattener(stringComment);
+// comment.accept(printer);
+ String text = new String(testedSource, comment.getStartPosition(), comment.getLength());
+ assumeEquals(this.prefix+"Flattened comment does NOT match source!", stringComment, text);
+ // Verify javdoc tags positions and bindings
+ if (comment.isDocComment()) {
+ Javadoc docComment = (Javadoc)comment;
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ assumeEquals(this.prefix+"Invalid tags number in javadoc:\n"+docComment+"\n", tags.size(), allTags(docComment));
+ verifyPositions(docComment, testedSource);
+ if (this.resolveBinding) {
+ verifyBindings(docComment);
+ }
+ } else {
+ assumeEquals("Javadoc should be flat!", 0, docComment.tags().size());
+ }
+ }
+ }
+
+ /* Verify each javadoc: not implemented yet
+ Iterator types = compilUnit.types().listIterator();
+ while (types.hasNext()) {
+ TypeDeclaration typeDeclaration = (TypeDeclaration) types.next();
+ verifyJavadoc(typeDeclaration.getJavadoc());
+ }
+ */
+
+ if (sourceLevel != null) {
+ this.currentProject.setOption(JavaCore.COMPILER_COMPLIANCE, complianceLevel);
+ this.currentProject.setOption(JavaCore.COMPILER_SOURCE, sourceLevel);
+ }
+ // Return compilation unit for possible further verifications
+ return compilUnit;
+ }
+
+ /*
+ * Verify each javadoc
+ * Not implented yet
+ private void verifyJavadoc(Javadoc docComment) {
+ }
+ */
+
+ /**
+ * Check javadoc for MethodDeclaration
+ */
+ public void test000() throws JavaModelException {
+ verifyComments("test000");
+ }
+
+ /**
+ * Check javadoc for invalid syntax
+ */
+ public void test001() throws JavaModelException {
+ verifyComments("test001");
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=50781"
+ */
+ public void test002() throws JavaModelException {
+ verifyComments("test002");
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=50784"
+ */
+ public void test003() throws JavaModelException {
+ verifyComments("test003");
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=50785"
+ */
+ public void test004() throws JavaModelException {
+ verifyComments("test004");
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=50838"
+ */
+ public void test005() throws JavaModelException {
+ verifyComments("test005");
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=50877"
+ */
+ public void test006() throws JavaModelException {
+ verifyComments("test006");
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=50877"
+ */
+ public void test007() throws JavaModelException {
+ verifyComments("test007");
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=50877"
+ */
+ public void test008() throws JavaModelException {
+ verifyComments("test008");
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=50877"
+ */
+ public void test009() throws JavaModelException {
+ verifyComments("test009");
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=50880"
+ */
+ public void test010() throws JavaModelException {
+ verifyComments("test010");
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=47396"
+ */
+ public void test011() throws JavaModelException {
+ this.problems = new StringBuffer();
+ this.sourceUnit = getCompilationUnit("Converter" , "src", "javadoc.test011", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(this.sourceUnit, true);
+ assumeNotNull("No compilation unit", result);
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=50938"
+ */
+ public void test012() throws JavaModelException {
+ verifyComments("test012");
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=51104"
+ */
+ public void test013() throws JavaModelException {
+ verifyComments("test013");
+ }
+
+ /**
+ * Verify that text on next line following empty tag element
+ * is well positionned.
+ */
+ public void test014() throws JavaModelException {
+ verifyComments("test014");
+ }
+
+ /**
+ * Verify that we do not report failure when types are written on several lines
+ * in Javadoc comments.
+ */
+ public void test015() throws JavaModelException {
+ verifyComments("test015");
+ }
+
+ /**
+ * Verify DefaultCommentMapper heuristic to get leading and trailing comments
+ */
+ protected void verifyMapper(String folder, int count, int[] indexes) throws JavaModelException {
+ ICompilationUnit[] units = getCompilationUnits("Converter" , "src", "javadoc."+folder); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ for (int i=0; i<units.length; i++) {
+ this.sourceUnit = units[i];
+ ASTNode result = runConversion(this.sourceUnit, false);
+ final CompilationUnit compilUnit = (CompilationUnit) result;
+ assumeEquals(this.prefix+"Wrong number of problems", 0, compilUnit.getProblems().length); //$NON-NLS-1$
+ assumeEquals(this.prefix+"Wrong number of comments", count, compilUnit.getCommentList().size());
+ // Verify first method existence
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assumeNotNull("We should get a non-null ast node", node);
+ assumeTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration method = (MethodDeclaration) node;
+ // Verify first method extended positions
+ int commentStart = method.getStartPosition();
+ if (indexes[0]>=0) {
+ Comment comment = (Comment) compilUnit.getCommentList().get(indexes[0]);
+ commentStart = comment.getStartPosition();
+ }
+ int startPosition = compilUnit.getExtendedStartPosition(method);
+ assumeEquals("Method "+node+" does not start at the right position", commentStart, startPosition);
+ int methodEnd = startPosition + compilUnit.getExtendedLength(method) - 1;
+ int commentEnd = method.getStartPosition() + method.getLength() - 1;
+ if (indexes[1]>=0) {
+ Comment comment = (Comment) compilUnit.getCommentList().get(indexes[1]);
+ commentEnd = comment.getStartPosition() + comment.getLength() - 1;
+ }
+ assumeEquals("Method "+node+" does not have the correct length", commentEnd, methodEnd);
+ // Verify second method existence
+ node = getASTNode((CompilationUnit) result, 0, 1);
+ assumeNotNull("We should get a non-null ast node", node);
+ assumeTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ method = (MethodDeclaration) node;
+ // Verify second method extended positions
+ commentStart = method.getStartPosition();
+ if (indexes[2]>=0) {
+ Comment comment = (Comment) compilUnit.getCommentList().get(indexes[2]);
+ commentStart = comment.getStartPosition();
+ }
+ startPosition = compilUnit.getExtendedStartPosition(method);
+ assumeEquals("Method "+node+" does not start at the right position", commentStart, startPosition);
+ methodEnd = startPosition + compilUnit.getExtendedLength(method) - 1;
+ commentEnd = method.getStartPosition() + method.getLength() - 1;
+ if (indexes[3]>=0) {
+ Comment comment = (Comment) compilUnit.getCommentList().get(indexes[3]);
+ commentEnd = comment.getStartPosition() + comment.getLength() - 1;
+ }
+ assumeEquals("Method "+node+" does not have the correct length", commentEnd, methodEnd);
+ }
+ }
+
+ /**
+ * Verify DefaultCommentMapper heuristic to get leading and trailing comments
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=53445"
+ */
+ public void test100() throws JavaModelException {
+ verifyMapper("test100", 16, new int[] {2,7,8,15});
+ }
+ public void test101() throws JavaModelException {
+ verifyMapper("test101", 8, new int[] {1,3,4,7});
+ }
+ public void test102() throws JavaModelException {
+ verifyMapper("test102", 16, new int[] {4,9,10,13});
+ }
+ public void test103() throws JavaModelException {
+ verifyMapper("test103", 8, new int[] {2,4,5,6});
+ }
+ public void test104() throws JavaModelException {
+ verifyMapper("test104", 16, new int[] {2,7,8,15});
+ }
+ public void test105() throws JavaModelException {
+ verifyMapper("test105", 16, new int[] {-1,11,-1,15});
+ }
+ public void test106() throws JavaModelException {
+ verifyMapper("test106", 8, new int[] {-1,5,-1,7});
+ }
+ public void test107() throws JavaModelException {
+ verifyMapper("test107", 16, new int[] {2,7,8,-1});
+ }
+ public void test108() throws JavaModelException {
+ verifyMapper("test108", 8, new int[] {1,3,4,-1});
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=54776"
+ */
+ public void testBug54776() throws JavaModelException {
+ this.sourceUnit = getCompilationUnit("Converter" , "src", "javadoc.testBug54776", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(this.sourceUnit, false);
+ final CompilationUnit compilUnit = (CompilationUnit) result;
+ assumeEquals(this.prefix+"Wrong number of problems", 0, compilUnit.getProblems().length); //$NON-NLS-1$
+ assumeEquals(this.prefix+"Wrong number of comments", 2, compilUnit.getCommentList().size());
+ // get comments range
+ Comment comment = (Comment) compilUnit.getCommentList().get(0);
+ int commentStart = comment.getStartPosition();
+ int extendedLength = ((Comment) compilUnit.getCommentList().get(1)).getStartPosition()-commentStart+comment.getLength();
+ // get method invocation in field initializer
+ ASTNode node = getASTNode((CompilationUnit) result, 0);
+ assumeNotNull("We should get a non-null ast node", node);
+ assumeTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDecl = (TypeDeclaration) node;
+ FieldDeclaration[] fields = typeDecl.getFields();
+ assumeEquals("We should have a field declaration", 1, fields.length);
+ List fragments = fields[0].fragments();
+ assumeEquals("We should have a variable fragment", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assumeTrue("We should get an expression", expression instanceof MethodInvocation);
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ // verify that methodinvocation extended range includes leading and trailing comment
+ int methodStart = compilUnit.getExtendedStartPosition(methodInvocation);
+ assumeEquals("Method invocation "+methodInvocation+" does not start at the right position", commentStart, methodStart);
+ int methodLength = compilUnit.getExtendedLength(methodInvocation);
+ assumeEquals("Method invocation "+methodInvocation+" does not have the correct length", extendedLength, methodLength);
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=55221"
+ */
+ public void testBug55221a() throws JavaModelException {
+ this.sourceUnit = getCompilationUnit("Converter" , "src", "javadoc.testBug55221.a", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(this.sourceUnit, false);
+ final CompilationUnit compilUnit = (CompilationUnit) result;
+ assumeEquals(this.prefix+"Wrong number of problems", 0, compilUnit.getProblems().length); //$NON-NLS-1$
+ assumeEquals(this.prefix+"Wrong number of comments", 1, compilUnit.getCommentList().size());
+ // Get comment range
+ Comment comment = (Comment) compilUnit.getCommentList().get(0);
+ int commentStart = comment.getStartPosition();
+ // get first method
+ ASTNode node = getASTNode(compilUnit, 0, 0);
+ assumeNotNull("We should get a non-null ast node", node);
+ assumeTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration method = (MethodDeclaration) node;
+ // verify that first method does not include comment
+ int methodStart = compilUnit.getExtendedStartPosition(method);
+ assumeEquals("Method "+method+" does not start at the right position", method.getStartPosition(), methodStart);
+ int methodLength = compilUnit.getExtendedLength(method);
+ assumeEquals("Method declaration "+method+" does not end at the right position",method.getLength(), methodLength);
+ // get method body
+ node = method.getBody();
+ assumeNotNull("We should get a non-null ast node", node);
+ assumeTrue("Not a block", node.getNodeType() == ASTNode.BLOCK); //$NON-NLS-1$
+ Block block = (Block) node;
+ // verify that body does not include following comment
+ int blockStart = compilUnit.getExtendedStartPosition(block);
+ assumeEquals("Body block "+block+" does not start at the right position", block.getStartPosition(), blockStart);
+ int blockLength = compilUnit.getExtendedLength(block);
+ assumeEquals("Body block "+block+" does not have the correct length", block.getLength(), blockLength);
+ // get second method
+ node = getASTNode(compilUnit, 0, 1);
+ assumeNotNull("We should get a non-null ast node", node);
+ assumeTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ method = (MethodDeclaration) node;
+ // verify that second method start includes comment
+ assumeEquals("Method declaration "+method+" does not start at the right position", commentStart, method.getStartPosition());
+ }
+ public void testBug55221b() throws JavaModelException {
+ this.sourceUnit = getCompilationUnit("Converter" , "src", "javadoc.testBug55221.b", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(this.sourceUnit, false);
+ final CompilationUnit compilUnit = (CompilationUnit) result;
+ assumeEquals(this.prefix+"Wrong number of problems", 0, compilUnit.getProblems().length); //$NON-NLS-1$
+ assumeEquals(this.prefix+"Wrong number of comments", 1, compilUnit.getCommentList().size());
+ // Get comment range
+ Comment comment = (Comment) compilUnit.getCommentList().get(0);
+ int commentStart = comment.getStartPosition();
+ // get first method
+ ASTNode node = getASTNode(compilUnit, 0, 0);
+ assumeNotNull("We should get a non-null ast node", node);
+ assumeTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration method = (MethodDeclaration) node;
+ // verify that first method does not include comment
+ int methodStart = compilUnit.getExtendedStartPosition(method);
+ assumeEquals("Method "+method+" does not start at the right position", method.getStartPosition(), methodStart);
+ int methodLength = compilUnit.getExtendedLength(method);
+ assumeEquals("Method declaration "+method+" does not end at the right position",method.getLength(), methodLength);
+ // get method body
+ node = method.getBody();
+ assumeNotNull("We should get a non-null ast node", node);
+ assumeTrue("Not a block", node.getNodeType() == ASTNode.BLOCK); //$NON-NLS-1$
+ Block block = (Block) node;
+ // verify that body does not include following comment
+ int blockStart = compilUnit.getExtendedStartPosition(block);
+ assumeEquals("Body block "+block+" does not start at the right position", block.getStartPosition(), blockStart);
+ int blockLength = compilUnit.getExtendedLength(block);
+ assumeEquals("Body block "+block+" does not have the correct length", block.getLength(), blockLength);
+ // get second method
+ node = getASTNode(compilUnit, 0, 1);
+ assumeNotNull("We should get a non-null ast node", node);
+ assumeTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ method = (MethodDeclaration) node;
+ // verify that second method start includes comment
+ assumeEquals("Method declaration "+method+" does not start at the right position", commentStart, method.getStartPosition());
+ }
+ public void testBug55221c() throws JavaModelException {
+ this.sourceUnit = getCompilationUnit("Converter" , "src", "javadoc.testBug55221.c", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(this.sourceUnit, false);
+ final CompilationUnit compilUnit = (CompilationUnit) result;
+ assumeEquals(this.prefix+"Wrong number of problems", 0, compilUnit.getProblems().length); //$NON-NLS-1$
+ assumeEquals(this.prefix+"Wrong number of comments", 1, compilUnit.getCommentList().size());
+ // Get comment range
+ Comment comment = (Comment) compilUnit.getCommentList().get(0);
+ int commentStart = comment.getStartPosition();
+ int commentEnd = commentStart+comment.getLength()-1;
+ // get first method
+ ASTNode node = getASTNode(compilUnit, 0, 0);
+ assumeNotNull("We should get a non-null ast node", node);
+ assumeTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration method = (MethodDeclaration) node;
+ // verify that first method includes comment
+ int methodStart = compilUnit.getExtendedStartPosition(method);
+ assumeEquals("Method "+method+" does not start at the right position", method.getStartPosition(), methodStart);
+ int methodLength = compilUnit.getExtendedLength(method);
+ assumeEquals("Method "+method+" does not end at the right position", commentEnd, methodStart+methodLength-1);
+ // get method body
+ node = method.getBody();
+ assumeNotNull("We should get a non-null ast node", node);
+ assumeTrue("Not a block", node.getNodeType() == ASTNode.BLOCK); //$NON-NLS-1$
+ Block block = (Block) node;
+ // verify that body includes following comment
+ int blockStart = compilUnit.getExtendedStartPosition(block);
+ assumeEquals("Body block "+block+" does not start at the right position", block.getStartPosition(), blockStart);
+ int blockLength = compilUnit.getExtendedLength(block);
+ assumeEquals("Body block "+block+" does not end at the right position", commentEnd, blockStart+blockLength-1);
+ // get second method
+ node = getASTNode(compilUnit, 0, 1);
+ assumeNotNull("We should get a non-null ast node", node);
+ assumeTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ method = (MethodDeclaration) node;
+ // verify that second method does not include comment
+ methodStart = compilUnit.getExtendedStartPosition(method);
+ assumeEquals("Method "+method+" does not start at the right position", method.getStartPosition(), methodStart);
+ methodLength = compilUnit.getExtendedLength(method);
+ assumeEquals("Method declaration "+method+" does not end at the right position",method.getLength(), methodLength);
+ }
+ /** @deprecated using deprecated code */
+ public void testBug55221d() throws JavaModelException {
+ this.sourceUnit = getCompilationUnit("Converter" , "src", "javadoc.testBug55221.d", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(this.sourceUnit, false);
+ final CompilationUnit compilUnit = (CompilationUnit) result;
+ assumeEquals(this.prefix+"Wrong number of problems", 0, compilUnit.getProblems().length); //$NON-NLS-1$
+ assumeEquals(this.prefix+"Wrong number of comments", 2, compilUnit.getCommentList().size());
+ // get first method
+ ASTNode node = getASTNode(compilUnit, 0, 0);
+ assumeNotNull("We should get a non-null ast node", node);
+ assumeTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration method = (MethodDeclaration) node;
+ // verify that first method includes comment
+ int methodStart = compilUnit.getExtendedStartPosition(method);
+ assumeEquals("Method "+method+" does not start at the right position", method.getStartPosition(), methodStart);
+ int methodLength = compilUnit.getExtendedLength(method);
+ assumeEquals("Method "+method+" does not have the right length", methodLength, method.getLength());
+ // get return type
+ node = method.getReturnType();
+ assumeNotNull("We should get a non-null ast node", node);
+ assumeTrue("Not return type", node.getNodeType() == ASTNode.PRIMITIVE_TYPE); //$NON-NLS-1$
+ PrimitiveType returnType = (PrimitiveType) node;
+ // verify that return type includes following comment
+ int returnStart = compilUnit.getExtendedStartPosition(returnType);
+ assumeEquals("Return type "+returnType+" does not start at the right position", returnType.getStartPosition(), returnStart);
+ int returnLength = compilUnit.getExtendedLength(returnType);
+ assumeEquals("Return type "+returnType+" does not have the right length", returnType.getLength(), returnLength);
+ }
+ public void testBug55223a() throws JavaModelException {
+// stopOnFailure = false;
+ this.sourceUnit = getCompilationUnit("Converter" , "src", "javadoc.testBug55223", "TestA.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(this.sourceUnit, false);
+ final CompilationUnit compilUnit = (CompilationUnit) result;
+ assumeEquals(this.prefix+"Wrong number of problems", 0, compilUnit.getProblems().length); //$NON-NLS-1$
+ assumeEquals(this.prefix+"Wrong number of comments", 2, compilUnit.getCommentList().size());
+ // get method
+ ASTNode node = getASTNode(compilUnit, 0, 0);
+ assumeNotNull("We should get a non-null ast node", node);
+ assumeEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType()); //$NON-NLS-1$
+ MethodDeclaration method = (MethodDeclaration) node;
+ // get method body
+ node = method.getBody();
+ assumeNotNull("We should get a non-null ast node", node);
+ assumeEquals("Not a block", ASTNode.BLOCK, node.getNodeType()); //$NON-NLS-1$
+ Block block = (Block) node;
+ // verify block statements start/end positions
+ Iterator statements = block.statements().iterator();
+ int idx = 0;
+ while (statements.hasNext()) {
+ node = (ExpressionStatement) statements.next();
+ assumeEquals("Not a block", ASTNode.EXPRESSION_STATEMENT, node.getNodeType()); //$NON-NLS-1$
+ ExpressionStatement statement = (ExpressionStatement) node;
+ int statementStart = statement.getStartPosition();
+ int statementEnd = statementStart + statement.getLength() - 1;
+ if (idx < 2) {
+ // Get comment range
+ Comment comment = (Comment) compilUnit.getCommentList().get(idx);
+ int commentStart = comment.getStartPosition();
+ statementEnd = commentStart+comment.getLength()-1;
+ }
+ int extendedStart = compilUnit.getExtendedStartPosition(statement);
+ assumeEquals("Statement "+statement+" does not start at the right position", statementStart, extendedStart);
+ int extendedEnd = extendedStart + compilUnit.getExtendedLength(statement) - 1;
+ assumeEquals("Statement "+statement+" does not end at the right position", statementEnd, extendedEnd);
+ idx++;
+ }
+ }
+ /** @deprecated using deprecated code */
+ public void testBug55223b() throws JavaModelException {
+ this.sourceUnit = getCompilationUnit("Converter" , "src", "javadoc.testBug55223", "TestB.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(this.sourceUnit, false);
+ final CompilationUnit compilUnit = (CompilationUnit) result;
+ assumeEquals(this.prefix+"Wrong number of problems", 0, compilUnit.getProblems().length); //$NON-NLS-1$
+ assumeEquals(this.prefix+"Wrong number of comments", 2, compilUnit.getCommentList().size());
+ // Get comment range
+ Comment comment = (Comment) compilUnit.getCommentList().get(1);
+ int commentStart = comment.getStartPosition();
+ // get method
+ ASTNode node = getASTNode(compilUnit, 0, 0);
+ assumeNotNull("We should get a non-null ast node", node);
+ assumeEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType()); //$NON-NLS-1$
+ MethodDeclaration method = (MethodDeclaration) node;
+ // get return type
+ node = method.getReturnType();
+ assumeNotNull("We should get a non-null ast node", node);
+ assumeTrue("Not return type", node.getNodeType() == ASTNode.SIMPLE_TYPE); //$NON-NLS-1$
+ SimpleType returnType = (SimpleType) node;
+ // verify that return type includes following comment
+ int returnStart = compilUnit.getExtendedStartPosition(returnType);
+ assumeEquals("Return type "+returnType+" does not start at the right position", commentStart, returnStart);
+ int returnEnd = returnStart + compilUnit.getExtendedLength(returnType) - 1;
+ assumeEquals("Return type "+returnType+" does not end at the right length", returnType.getStartPosition()+returnType.getLength()-1, returnEnd);
+ }
+ /*
+ * End DefaultCommentMapper verifications
+ */
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=48489"
+ */
+ public void testBug48489() throws JavaModelException {
+ verifyComments("testBug48489");
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=50898"
+ */
+ public void testBug50898() throws JavaModelException {
+ ICompilationUnit unit = getCompilationUnit("Converter" , "src", "javadoc.testBug50898", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ this.packageBinding = false;
+ verifyComments(unit);
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=51226"
+ */
+ public void testBug51226() throws JavaModelException {
+ ICompilationUnit[] units = getCompilationUnits("Converter" , "src", "javadoc.testBug51226"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ for (int i=0; i<units.length; i++) {
+ ASTNode result = runConversion(units[i], false);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assumeEquals(this.prefix+"Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ assumeEquals(this.prefix+"Wrong number of comments", 1, unit.getCommentList().size());
+ Comment comment = (Comment) unit.getCommentList().get(0);
+ assumeTrue(this.prefix+"Comment should be a Javadoc one", comment.isDocComment());
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ Javadoc docComment = (Javadoc) comment;
+ assumeEquals(this.prefix+"Wrong number of tags", 1, docComment.tags().size());
+ TagElement tagElement = (TagElement) docComment.tags().get(0);
+ assumeNull(this.prefix+"Wrong type of tag ["+tagElement+"]", tagElement.getTagName());
+ assumeEquals(this.prefix+"Wrong number of fragments in tag ["+tagElement+"]", 1, tagElement.fragments().size());
+ ASTNode fragment = (ASTNode) tagElement.fragments().get(0);
+ assumeEquals(this.prefix+"Invalid type for fragment ["+fragment+"]", ASTNode.TEXT_ELEMENT, fragment.getNodeType());
+ TextElement textElement = (TextElement) fragment;
+ assumeEquals(this.prefix+"Invalid content for text element ", "Test", textElement.getText());
+ if (this.debug) System.out.println(docComment+"\nsuccessfully verified.");
+ }
+ }
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=51241"
+ */
+ public void testBug51241() throws JavaModelException {
+ verifyComments("testBug51241");
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=51363"
+ */
+ public void testBug51363() throws JavaModelException {
+ this.sourceUnit = getCompilationUnit("Converter" , "src", "javadoc.testBug51363", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(this.sourceUnit, false);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assumeEquals(this.prefix+"Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ assumeEquals(this.prefix+"Wrong number of comments", 2, unit.getCommentList().size());
+ // verify first comment
+ Comment comment = (Comment) unit.getCommentList().get(0);
+ assumeTrue(this.prefix+"Comment should be a line comment ", comment.isLineComment());
+ String sourceStr = this.sourceUnit.getSource();
+ int startPos = comment.getStartPosition()+comment.getLength();
+ assumeEquals("Wrong length for line comment "+comment, "\\u000D\\u000A", sourceStr.substring(startPos, startPos+12));
+ if (this.debug) System.out.println(comment+"\nsuccessfully verified.");
+ // verify second comment
+ comment = (Comment) unit.getCommentList().get(1);
+ assumeTrue(this.prefix+"Comment should be a line comment", comment.isLineComment());
+ sourceStr = this.sourceUnit.getSource();
+ startPos = comment.getStartPosition()+comment.getLength();
+ assumeEquals("Wrong length for line comment "+comment, "\\u000Dvoid", sourceStr.substring(startPos, startPos+10));
+ if (this.debug) System.out.println(comment+"\nsuccessfully verified.");
+// verifyComments("testBug51363");
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=51476"
+ */
+ public void testBug51476() throws JavaModelException {
+ verifyComments("testBug51476");
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=51478"
+ */
+ public void testBug51478() throws JavaModelException {
+ verifyComments("testBug51478");
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=51508"
+ */
+ public void testBug51508() throws JavaModelException {
+ verifyComments("testBug51508");
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=51650"
+ */
+ public void testBug51650() throws JavaModelException {
+ verifyComments("testBug51650");
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=51770"
+ */
+ public void testBug51770() throws JavaModelException {
+ verifyComments("testBug51770");
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=52908"
+ */
+ public void testBug52908() throws JavaModelException {
+ verifyComments("testBug52908");
+ }
+ public void testBug52908a() throws JavaModelException {
+ verifyComments("testBug52908a");
+ }
+ public void testBug52908unicode() throws JavaModelException {
+ verifyComments("testBug52908unicode");
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=53276"
+ */
+ public void testBug53276() throws JavaModelException {
+ verifyComments("testBug53276");
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=53075"
+ */
+ public void testBug53075() throws JavaModelException {
+ ICompilationUnit unit = getCompilationUnit("Converter" , "src", "javadoc.testBug53075", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ boolean pb = this.packageBinding;
+ this.packageBinding = false;
+ CompilationUnit compilUnit = verifyComments(unit);
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ Comment comment = (Comment) compilUnit.getCommentList().get(0);
+ assumeTrue(this.prefix+"Comment should be a javadoc comment ", comment.isDocComment());
+ Javadoc docComment = (Javadoc) comment;
+ TagElement tagElement = (TagElement) docComment.tags().get(0);
+ assumeEquals("Wrong tag type!", TagElement.TAG_LINK, tagElement.getTagName());
+ tagElement = (TagElement) docComment.tags().get(1);
+ assumeEquals("Wrong tag type!", TagElement.TAG_LINKPLAIN, tagElement.getTagName());
+ }
+ this.packageBinding = pb;
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=53757"
+ */
+ public void testBug53757() throws JavaModelException {
+ verifyComments("testBug53757");
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=51600"
+ */
+ public void testBug51600() throws JavaModelException {
+ verifyComments("testBug51600");
+ }
+ public void testBug51617() throws JavaModelException {
+ this.stopOnFailure = false;
+ String [] unbound = { "e" };
+ verifyComments("testBug51617");
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ int size = unbound.length;
+ for (int i=0, f=0; i<size; i++) {
+ assertTrue("Invalid number of failures!", this.failures.size()>f);
+ String failure = (String) this.failures.get(f);
+ String expected = "Reference '"+unbound[i]+"' should be bound!";
+ if (expected.equals(failure.substring(failure.indexOf(' ')+1))) {
+ this.failures.remove(f);
+ } else {
+ f++; // skip offending failure
+ i--; // stay on expected string
+ }
+ }
+ }
+ this.stopOnFailure = true;
+ }
+ public void testBug54424() throws JavaModelException {
+ this.stopOnFailure = false;
+ String [] unbound = { "tho",
+ "A#getList(int,long,boolean)",
+ "#getList(Object,java.util.AbstractList)",
+ };
+ verifyComments("testBug54424");
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ int size = unbound.length;
+ for (int i=0, f=0; i<size; i++) {
+ assertTrue("Invalid number of failures!", this.failures.size()>f);
+ String failure = (String) this.failures.get(f);
+ String expected = "Reference '"+unbound[i]+"' should be bound!";
+ if (expected.equals(failure.substring(failure.indexOf(' ')+1))) {
+ this.failures.remove(f);
+ } else {
+ f++; // skip offending failure
+ i--; // stay on expected string
+ }
+ }
+ }
+ this.stopOnFailure = true;
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=63044"
+ */
+ public void testBug63044() throws JavaModelException {
+ verifyComments("testBug63044");
+ }
+
+ /**
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=51660"
+ */
+ public void testBug51660() throws JavaModelException {
+ this.stopOnFailure = false;
+ ICompilationUnit unit = getCompilationUnit("Converter" , "src", "javadoc.testBug51660", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit compilUnit = verifyComments(unit);
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ String[] tagNames = {
+ "@ejb",
+ "@ejb",
+ "@ejb",
+ "@ejb",
+ "@ejb",
+ "@ejb",
+ "@ejb(bean",
+ "@ejb)bean",
+ "@ejb",
+ "@ejb+bean",
+ "@ejb,bean",
+ "@ejb-bean",
+ "@ejb.bean",
+ "@ejb/bean",
+ "@ejb",
+ "@ejb;bean",
+ "@ejb",
+ "@ejb=bean",
+ "@ejb",
+ "@ejb?bean",
+ "@ejb@bean",
+ "@ejb[bean",
+ "@ejb\\bean",
+ "@ejb]bean",
+ "@ejb^bean",
+ "@ejb`bean",
+ "@ejb{bean",
+ "@ejb|bean",
+ "@ejb",
+ "@ejb~bean",
+ "@unknown"
+ };
+ String[] tagTexts = {
+ "!bean test non-java id character '!' (val=33) in tag name",
+ "\"bean test non-java id character '\"' (val=34) in tag name",
+ "#bean test non-java id character '#' (val=35) in tag name",
+ "%bean test non-java id character '%' (val=37) in tag name",
+ "&bean test non-java id character '&' (val=38) in tag name",
+ "'bean test non-java id character ''' (val=39) in tag name",
+ " test non-java id character '(' (val=40) in tag name",
+ " test non-java id character ')' (val=41) in tag name",
+ "*bean test non-java id character '*' (val=42) in tag name",
+ " test non-java id character '+' (val=43) in tag name",
+ " test non-java id character ',' (val=44) in tag name",
+ " test non-java id character '-' (val=45) in tag name",
+ " test non-java id character '.' (val=46) in tag name",
+ " test non-java id character '/' (val=47) in tag name",
+ ":bean test non-java id character ':' (val=58) in tag name",
+ " test non-java id character ';' (val=59) in tag name",
+ "<bean test non-java id character '<' (val=60) in tag name",
+ " test non-java id character '=' (val=61) in tag name",
+ ">bean test non-java id character '>' (val=62) in tag name",
+ " test non-java id character '?' (val=63) in tag name",
+ " test non-java id character '@' (val=64) in tag name",
+ " test non-java id character '[' (val=91) in tag name",
+ " test non-java id character '\\' (val=92) in tag name",
+ " test non-java id character ']' (val=93) in tag name",
+ " test non-java id character '^' (val=94) in tag name",
+ " test non-java id character '`' (val=96) in tag name",
+ " test non-java id character '{' (val=123) in tag name",
+ " test non-java id character '|' (val=124) in tag name",
+ "}bean test non-java id character '}' (val=125) in tag name",
+ " test non-java id character '~' (val=126) in tag name",
+ " test java id"
+ };
+ Comment comment = (Comment) compilUnit.getCommentList().get(0);
+ assumeTrue(this.prefix+"Comment should be a javadoc comment ", comment.isDocComment());
+ Javadoc docComment = (Javadoc) comment;
+ int size = docComment.tags().size();
+ for (int i=0; i<size; i++) {
+ TagElement tagElement = (TagElement) docComment.tags().get(i);
+ assumeEquals("Wrong tag name for:"+tagElement, tagNames[i], tagElement.getTagName());
+ assumeEquals("Wrong fragments size for :"+tagElement, 1, tagElement.fragments().size());
+ ASTNode fragment = (ASTNode) tagElement.fragments().get(0);
+ assumeEquals("Wrong fragments type for :"+tagElement, ASTNode.TEXT_ELEMENT, fragment.getNodeType());
+ TextElement textElement = (TextElement) fragment;
+ assumeEquals("Wrong text for tag!", tagTexts[i], textElement.getText());
+ }
+ }
+ this.stopOnFailure = true;
+ }
+
+ /**
+ * Bug 65174: Spurious "Javadoc: Missing reference" error
+ * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=65174"
+ */
+ public void testBug65174() throws JavaModelException {
+ verifyComments("testBug65174");
+ }
+
+ /**
+ * Bug 65253: [Javadoc] @@tag is wrongly parsed as @tag
+ * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=65253"
+ */
+ public void testBug65253() throws JavaModelException {
+ verifyComments("testBug65253");
+ }
+
+ /**
+ * Bug 65288: Javadoc: tag gets mangled when javadoc closing on same line without whitespace
+ * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=65288"
+ */
+ public void testBug65288() throws JavaModelException {
+ verifyComments("testBug65288");
+ }
+
+ /**
+ * Bug 68017: Javadoc processing does not detect missing argument to @return
+ * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=68017"
+ */
+ public void testBug68017() throws JavaModelException {
+ verifyComments("testBug68017");
+ }
+
+ /**
+ * Bug 68025: Javadoc processing does not detect some wrong links
+ * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=68025"
+ */
+ public void testBug68025() throws JavaModelException {
+ verifyComments("testBug68025");
+ }
+
+ /**
+ * Bug 69272: [Javadoc] Invalid malformed reference (missing separator)
+ * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=69272"
+ */
+ public void testBug69272() throws JavaModelException {
+ verifyComments("testBug69272");
+ }
+
+ /**
+ * Bug 69275: [Javadoc] Invalid warning on @see link
+ * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=69275"
+ */
+ public void testBug69275() throws JavaModelException {
+ verifyComments("testBug69275");
+ }
+
+ /**
+ * Bug 69302: [Javadoc] Invalid reference warning inconsistent with javadoc tool
+ * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=69302"
+ */
+ public void testBug69302() throws JavaModelException {
+ verifyComments("testBug69302");
+ }
+
+ /**
+ * Bug 68726: [Javadoc] Target attribute in @see link triggers warning
+ * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=68726"
+ */
+ public void testBug68726() throws JavaModelException {
+ verifyComments("testBug68726");
+ }
+
+ /**
+ * Bug 70892: [1.5][Javadoc] Compiler should parse reference for inline tag @value
+ * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=70892"
+ * @deprecated using deprecated code
+ */
+ public void testBug70892_JLS2() throws JavaModelException {
+ int level = this.astLevel;
+ this.astLevel = AST.JLS2;
+ verifyComments("testBug70892");
+ this.astLevel = level;
+ }
+ public void testBug70892_JLS3() throws JavaModelException {
+ int level = this.astLevel;
+ this.astLevel = AST.JLS3;
+ verifyComments("testBug70892");
+ this.astLevel = level;
+ }
+
+ /**
+ * Bug 51911: [Javadoc] @see method w/out ()
+ * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=51911"
+ */
+ public void testBug51911() throws JavaModelException {
+ verifyComments("testBug51911");
+ }
+
+ /**
+ * Bug 73348: [Javadoc] Missing description for return tag is not always warned
+ * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=73348"
+ */
+ public void testBug73348() throws JavaModelException {
+ verifyComments("testBug73348");
+ }
+
+ /**
+ * Bug 77644: [dom] AST node extended positions may be wrong while moving
+ * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=77644"
+ */
+ public void testBug77644() throws JavaModelException {
+ verifyComments("testBug77644");
+ }
+
+ /**
+ * Bug 79809: [1.5][dom][javadoc] Need better support for type parameter Javadoc tags
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=79809"
+ */
+ public void testBug79809() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.astLevel = AST.JLS3;
+ this.workingCopies[0] = getWorkingCopy("/Converter/src/javadoc/b79809/Test.java",
+ "package javadoc.b79809;\n" +
+ "/**\n" +
+ " * @param <E> Class type parameter\n" +
+ " * @see Object\n" +
+ " */\n" +
+ "public class Test<E> {\n" +
+ " /**\n" +
+ " * @param t\n" +
+ " * @param <T> Method type parameter\n" +
+ " */\n" +
+ " <T> void foo(T t) {}\n" +
+ "}\n");
+ verifyWorkingCopiesComments();
+ }
+ public void testBug79809b() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.astLevel = AST.JLS3;
+ this.workingCopies[0] = getWorkingCopy("/Converter/src/javadoc/b79809/Test.java",
+ "package javadoc.b79809;\n" +
+ "\n" +
+ "/**\n" +
+ " * New tags for 5.0\n" +
+ " * - literal: {@literal a<B>c}\n" +
+ " * - code: {@code abc}\n" +
+ " * - value: {@value System#out}\n" +
+ " */\n" +
+ "public class Test {\n" +
+ "\n" +
+ "}\n");
+ verifyWorkingCopiesComments();
+ }
+
+ /**
+ * Bug 79904: [1.5][dom][javadoc] TagElement range not complete for type parameter tags
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=79904"
+ */
+ public void testBug79904() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.astLevel = AST.JLS3;
+ this.workingCopies[0] = getWorkingCopy("/Converter/src/javadoc/b79904/Test.java",
+ "package javadoc.b79904;\n" +
+ "/**\n" +
+ " * @param <E>\n" +
+ " * @see Object\n" +
+ " */\n" +
+ "public class Test<E> {\n" +
+ " /**\n" +
+ " * @param t\n" +
+ " * @param <T>\n" +
+ " */\n" +
+ " <T> void foo(T t) {}\n" +
+ "}\n");
+ verifyWorkingCopiesComments();
+ }
+
+ /**
+ * Bug 80221: [1.5][dom][javadoc] Need better support for type parameter Javadoc tags
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=80221"
+ */
+ public void testBug80221() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.astLevel = AST.JLS3;
+ this.workingCopies[0] = getWorkingCopy("/Converter/src/javadoc/b80221/Test.java",
+ "package javadoc.b80221;\n" +
+ "public class Test {\n" +
+ " /**\n" +
+ " * @see Object Unknown: ref is not resolved due to compile error...\n" +
+ " */\n" +
+ " public foo() {\n" +
+ " return 1;\n" +
+ " }\n" +
+ "}\n"
+ );
+ verifyWorkingCopiesComments();
+ }
+
+ /**
+ * Bug 80257: [1.5][javadoc][dom] Type references in javadocs should have generic binding, not raw
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=80257"
+ */
+ public void testBug80257() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.astLevel = AST.JLS3;
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b80257/Test.java",
+ "package javadoc.b80257;\n" +
+ "import java.util.*;\n" +
+ "public class Test {\n" +
+ " /**\n" +
+ " * @see ArrayList\n" +
+ " * @return {@link java.util.List}\n" +
+ " */\n" +
+ " List<String> getList() {\n" +
+ " return new ArrayList<String>();\n" +
+ " }\n" +
+ "}\n"
+ );
+ CompilationUnit compilUnit = verifyComments(this.workingCopies[0]);
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Do not need to verify following statement as we know it's ok as verifyComments did not fail
+ Javadoc docComment = (Javadoc) compilUnit.getCommentList().get(0); // get javadoc comment
+ TagElement firstTag = (TagElement) docComment.tags().get(0); // get first tag
+ TagElement secondTag = (TagElement) docComment.tags().get(1); // get second tag
+ TagElement inlineTag = (TagElement) secondTag.fragments().get(1); // get inline tag
+ // Get tag simple name reference in first tag
+ assertEquals("Invalid number of fragments for tag element: "+firstTag, 1, firstTag.fragments().size());
+ ASTNode node = (ASTNode) firstTag.fragments().get(0);
+ assertEquals("Invalid kind of name reference for tag element: "+firstTag, ASTNode.SIMPLE_NAME, node.getNodeType());
+ SimpleName seeRef = (SimpleName) node;
+ // Verify binding for simple name
+ IBinding binding = seeRef.resolveBinding();
+ assertTrue("Wrong kind of binding", binding instanceof ITypeBinding);
+ ITypeBinding typeBinding = (ITypeBinding)binding;
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=209936
+ // only have RawTypeBinding in Javadocs
+ assertFalse(seeRef.toString()+" should NOT have a generic type binding", typeBinding.isGenericType());
+ assertFalse(seeRef.toString()+" should NOT have a parameterized type binding", typeBinding.isParameterizedType());
+ assertTrue(seeRef.toString()+" should have a raw type binding", typeBinding.isRawType());
+ // Get inline tag simple name reference in second tag
+ assertEquals("Invalid number of fragments for inline tag element: "+inlineTag, 1, inlineTag.fragments().size());
+ node = (ASTNode) inlineTag.fragments().get(0);
+ assertEquals("Invalid kind of name reference for tag element: "+inlineTag, ASTNode.QUALIFIED_NAME, node.getNodeType());
+ QualifiedName linkRef = (QualifiedName) node;
+ // Verify binding for qualified name
+ binding = linkRef.resolveBinding();
+ assertTrue("Wrong kind of binding", binding instanceof ITypeBinding);
+ typeBinding = (ITypeBinding)binding;
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=209936
+ // only have RawTypeBinding in Javadocs
+ assertFalse(linkRef.toString()+" should NOT have a generic type binding", typeBinding.isGenericType());
+ assertFalse(linkRef.toString()+" should NOT have a parameterized type binding", typeBinding.isParameterizedType());
+ assertTrue(linkRef.toString()+" should have a raw type binding", typeBinding.isRawType());
+ }
+ }
+
+ /**
+ * Bug 83804: [1.5][javadoc] Missing Javadoc node for package declaration
+ * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=83804"
+ */
+ public void testBug83804() throws CoreException, JavaModelException {
+ this.astLevel = AST.JLS3;
+ this.workingCopies = new ICompilationUnit[2];
+ this.workingCopies[0] = getCompilationUnit("Converter15", "src", "javadoc.b83804", "package-info.java");
+ this.workingCopies[1] = getCompilationUnit("Converter15", "src", "javadoc.b83804", "Test.java");
+ verifyWorkingCopiesComments();
+ }
+ public void testBug83804a() throws CoreException, JavaModelException {
+ this.astLevel = AST.JLS3;
+ this.workingCopies = new ICompilationUnit[2];
+ this.workingCopies[0] = getCompilationUnit("Converter15", "src", "javadoc.b83804a", "package-info.java");
+ this.workingCopies[1] = getCompilationUnit("Converter15", "src", "javadoc.b83804a", "Test.java");
+ verifyWorkingCopiesComments();
+ }
+
+ /**
+ * Bug 84049: [javadoc][dom] Extended ranges wrong for method name without return type
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=84049"
+ */
+ public void testBug84049() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.astLevel = AST.JLS3;
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b84049/Test.java",
+ "package javadoc.b84049;\n" +
+ "public class Test {\n" +
+ " /**\n" +
+ " * @see Object\n" +
+ " */\n" +
+ " foo() {\n" +
+ " }\n" +
+ "}\n"
+ );
+ CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ ASTNode node = getASTNode(compilUnit, 0, 0);
+ assertEquals("Invalid type for node: "+node, ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Javadoc methodJavadoc = methodDeclaration.getJavadoc();
+ assertNotNull("MethodDeclaration have a javadoc comment", methodJavadoc);
+ int javadocStart = methodJavadoc.getStartPosition();
+ assertEquals("Method declaration should include javadoc comment", methodDeclaration.getStartPosition(), javadocStart);
+ SimpleName methodName = methodDeclaration.getName();
+ int nameStart = methodName.getStartPosition();
+ assertTrue("Method simple name should not include javadoc comment", nameStart > javadocStart+methodJavadoc.getLength());
+ int extendedStart = compilUnit.getExtendedStartPosition(methodName);
+ assertEquals("Method simple name start position should not be extended!", nameStart, extendedStart);
+ int extendedLength = compilUnit.getExtendedLength(methodName);
+ assertEquals("Method simple name length should not be extended!", methodName.getLength(), extendedLength);
+ }
+ }
+
+ /**
+ * Bug 87845: [1.5][javadoc][dom] Type references in javadocs should have generic binding, not raw
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=87845"
+ */
+ public void testBug87845() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.astLevel = AST.JLS3;
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b87845/Test.java",
+ "package javadoc.b87845;\n" +
+ "public class Test {\n" +
+ " public void foo(int a, int b) {} \n" +
+ " public void foo(int a, int... args) {}\n" +
+ " public void foo(String... args) {}\n" +
+ " public void foo(Exception str, boolean... args) {}\n" +
+ " /**\n" +
+ " * @see Test#foo(int, int)\n" +
+ " * @see Test#foo(int, int[])\n" +
+ " * @see Test#foo(int, int...)\n" +
+ " * @see Test#foo(String[])\n" +
+ " * @see Test#foo(String...)\n" +
+ " * @see Test#foo(Exception, boolean[])\n" +
+ " * @see Test#foo(Exception, boolean...)\n" +
+ " */\n" +
+ " public void valid() {}\n" +
+ " /**\n" +
+ " * @see Test#foo(int)\n" +
+ " * @see Test#foo(int, int, int)\n" +
+ " * @see Test#foo()\n" +
+ " * @see Test#foo(String)\n" +
+ " * @see Test#foo(String, String)\n" +
+ " * @see Test#foo(Exception)\n" +
+ " * @see Test#foo(Exception, boolean)\n" +
+ " * @see Test#foo(Exception, boolean, boolean)\n" +
+ " */\n" +
+ " public void invalid() {}\n" +
+ "}\n"
+ );
+ CompilationUnit compilUnit = verifyComments(this.workingCopies[0]);
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Do not need to verify following statement as we know it's ok as verifyComments did not fail
+ Javadoc docComment = (Javadoc) compilUnit.getCommentList().get(0); // get first javadoc comment
+ // Verify last parameter for all methods reference in javadoc comment
+ List tags = docComment.tags();
+ int size = tags.size();
+ for (int i=0; i<size; i++) {
+ TagElement tag = (TagElement) docComment.tags().get(i);
+ assertEquals("Invalid number of fragment for see reference: "+tag, 1, tag.fragments().size());
+ ASTNode node = (ASTNode) tag.fragments().get(0);
+ assertEquals("Invalid kind of name reference for tag element: "+tag, ASTNode.METHOD_REF, node.getNodeType());
+ MethodRef methodRef = (MethodRef) node;
+ List parameters = methodRef.parameters();
+ int paramSize = parameters.size();
+ for (int j=0; j<paramSize; j++) {
+ node = (ASTNode) parameters.get(j);
+ assertEquals("Invalid kind of method parameter: "+node, ASTNode.METHOD_REF_PARAMETER, node.getNodeType());
+ MethodRefParameter parameter = (MethodRefParameter) node;
+ if (j==(paramSize-1)) {
+ switch (i) {
+ case 2:
+ case 4:
+ case 6:
+ assertTrue("Method parameter \""+parameter+"\" should be varargs!", parameter.isVarargs());
+ break;
+ default:
+ assertFalse("Method parameter \""+parameter+"\" should not be varargs!", parameter.isVarargs());
+ break;
+ }
+ } else {
+ assertFalse("Method parameter \""+parameter+"\" should not be varargs!", parameter.isVarargs());
+ }
+ }
+ }
+ }
+ }
+
+ /**
+ * Bug 93880: [1.5][javadoc] Source range of PackageDeclaration does not include Javadoc child
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=93880"
+ */
+ public void testBug93880_15a() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.astLevel = AST.JLS3;
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b93880/Test.java",
+ "/**\n" +
+ " * Javadoc\n" +
+ " */\n" +
+ "package javadoc.b93880;\n" +
+ "public class Test {\n" +
+ "}\n"
+ );
+ CompilationUnit compilUnit = verifyComments(this.workingCopies[0]);
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Get package declaration declaration and javadoc
+ PackageDeclaration packDecl = compilUnit.getPackage();
+ Javadoc docComment = (Javadoc) compilUnit.getCommentList().get(0); // Do not need to verify following statement as we know it's ok as verifyComments did not fail
+
+ // Verify package declaration javadoc
+ assertTrue("Javadoc should be set on package declaration", docComment == packDecl.getJavadoc());
+
+ // Verify package declaration declaration source start
+ assertEquals("Source range of PackageDeclaration should include Javadoc child", docComment.getStartPosition(), packDecl.getStartPosition());
+ }
+ }
+ public void testBug93880_15b() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.astLevel = AST.JLS3;
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b93880/package-info.java",
+ "/**\n" +
+ " * Javadoc for all package\n" +
+ " */\n" +
+ "package javadoc.b93880;"
+ );
+ CompilationUnit compilUnit = verifyComments(this.workingCopies[0]);
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Get package declaration declaration and javadoc
+ PackageDeclaration packDecl = compilUnit.getPackage();
+ Javadoc docComment = (Javadoc) compilUnit.getCommentList().get(0); // Do not need to verify following statement as we know it's ok as verifyComments did not fail
+
+ // Verify package declaration javadoc
+ assertTrue("Javadoc should be set on package declaration", docComment == packDecl.getJavadoc());
+
+ // Verify package declaration declaration source start
+ assertEquals("Source range of PackageDeclaration should include Javadoc child", docComment.getStartPosition(), packDecl.getStartPosition());
+ }
+ }
+ public void testBug93880_15c() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.astLevel = AST.JLS3;
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b93880/package-info.java",
+ "/**\n" +
+ " * Javadoc for all package\n" +
+ " */\n" +
+ "private package javadoc.b93880;"
+ );
+ CompilationUnit compilUnit = verifyComments(this.workingCopies[0]);
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Get package declaration declaration and javadoc
+ PackageDeclaration packDecl = compilUnit.getPackage();
+ Javadoc docComment = (Javadoc) compilUnit.getCommentList().get(0); // Do not need to verify following statement as we know it's ok as verifyComments did not fail
+
+ // Verify package declaration javadoc
+ assertTrue("Javadoc should be set on package declaration", docComment == packDecl.getJavadoc());
+
+ // Verify package declaration declaration source start
+ assertEquals("Source range of PackageDeclaration should include Javadoc child", docComment.getStartPosition(), packDecl.getStartPosition());
+ }
+ }
+ public void testBug93880_15d() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.astLevel = AST.JLS3;
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b93880/package-info.java",
+ "/**\n" +
+ " * Javadoc for all package\n" +
+ " */\n" +
+ "@Deprecated\n" +
+ "package javadoc.b93880;"
+ );
+ CompilationUnit compilUnit = verifyComments(this.workingCopies[0]);
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Get package declaration declaration and javadoc
+ PackageDeclaration packDecl = compilUnit.getPackage();
+ assertNotNull("Compilation unit should have a package declaration", packDecl);
+ Javadoc docComment = (Javadoc) compilUnit.getCommentList().get(0); // Do not need to verify following statement as we know it's ok as verifyComments did not fail
+
+ // Verify package declaration javadoc
+ assertTrue("Javadoc should be set on package declaration", docComment == packDecl.getJavadoc());
+
+ // Verify package declaration declaration source start
+ assertEquals("Source range of PackageDeclaration should include Javadoc child", docComment.getStartPosition(), packDecl.getStartPosition());
+ }
+ }
+ public void testBug93880_15e() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.astLevel = AST.JLS3;
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b93880/package-info.java",
+ "/* (non-javadoc)\n" +
+ " * No comment\n" +
+ " */\n" +
+ "package javadoc.b93880;"
+ );
+ CompilationUnit compilUnit = verifyComments(this.workingCopies[0]);
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Get package declaration declaration and javadoc
+ PackageDeclaration packDecl = compilUnit.getPackage();
+ List unitComments = compilUnit.getCommentList();
+ assertEquals("Wrong number of comments", 1, unitComments.size());
+ Comment comment = (Comment) unitComments.get(0);
+
+ // Verify package declaration javadoc
+ assertNull("Package declaration should not have any javadoc", packDecl.getJavadoc());
+
+ // Verify package declaration declaration source start
+ assertTrue("Source range of PackageDeclaration should NOT include Javadoc child", packDecl.getStartPosition() > comment.getStartPosition()+comment.getLength());
+ }
+ }
+ public void testBug93880_14a() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.astLevel = AST.JLS3;
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b93880/Test.java",
+ "/**\n" +
+ " * Javadoc\n" +
+ " */\n" +
+ "package javadoc.b93880;\n" +
+ "public class Test {\n" +
+ "}\n"
+ );
+ CompilationUnit compilUnit = verifyComments(this.workingCopies[0]);
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Get package declaration declaration and javadoc
+ PackageDeclaration packDecl = compilUnit.getPackage();
+ Javadoc docComment = (Javadoc) compilUnit.getCommentList().get(0); // Do not need to verify following statement as we know it's ok as verifyComments did not fail
+
+ // Verify package declaration declaration source start
+ assertEquals("Source range of PackageDeclaration should include Javadoc child", docComment.getStartPosition(), packDecl.getStartPosition());
+ }
+ }
+ public void testBug93880_14b() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.astLevel = AST.JLS3;
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b93880/package-info.java",
+ "/**\n" +
+ " * Javadoc for all package\n" +
+ " */\n" +
+ "package javadoc.b93880;"
+ );
+ CompilationUnit compilUnit = verifyComments(this.workingCopies[0]);
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Get package declaration declaration and javadoc
+ PackageDeclaration packDecl = compilUnit.getPackage();
+ Javadoc docComment = (Javadoc) compilUnit.getCommentList().get(0); // Do not need to verify following statement as we know it's ok as verifyComments did not fail
+
+ // Verify package declaration declaration source start
+ assertEquals("Source range of PackageDeclaration should include Javadoc child", docComment.getStartPosition(), packDecl.getStartPosition());
+ }
+ }
+ public void testBug93880_14c() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.astLevel = AST.JLS3;
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b93880/package-info.java",
+ "/**\n" +
+ " * Javadoc for all package\n" +
+ " */\n" +
+ "private package javadoc.b93880;"
+ );
+ CompilationUnit compilUnit = verifyComments(this.workingCopies[0]);
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Get package declaration declaration and javadoc
+ PackageDeclaration packDecl = compilUnit.getPackage();
+ Javadoc docComment = (Javadoc) compilUnit.getCommentList().get(0); // Do not need to verify following statement as we know it's ok as verifyComments did not fail
+
+ // Verify package declaration declaration source start
+ assertEquals("Source range of PackageDeclaration should include Javadoc child", docComment.getStartPosition(), packDecl.getStartPosition());
+ }
+ }
+ public void testBug93880_14d() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.astLevel = AST.JLS3;
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b93880/package-info.java",
+ "/**\n" +
+ " * Javadoc for all package\n" +
+ " */\n" +
+ "@Deprecated\n" +
+ "package javadoc.b93880;"
+ );
+ CompilationUnit compilUnit = verifyComments(this.workingCopies[0]);
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Get package declaration declaration and javadoc
+ PackageDeclaration packDecl = compilUnit.getPackage();
+ assertNotNull("Compilation unit should have a package declaration", packDecl);
+ Javadoc docComment = (Javadoc) compilUnit.getCommentList().get(0); // Do not need to verify following statement as we know it's ok as verifyComments did not fail
+
+ // Verify package declaration declaration source start
+ assertEquals("Source range of PackageDeclaration should include Javadoc child", docComment.getStartPosition(), packDecl.getStartPosition());
+ }
+ }
+ public void testBug93880_14e() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.astLevel = AST.JLS3;
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b93880/package-info.java",
+ "/* (non-javadoc)\n" +
+ " * No comment\n" +
+ " */\n" +
+ "package javadoc.b93880;"
+ );
+ CompilationUnit compilUnit = verifyComments(this.workingCopies[0]);
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Get package declaration declaration and javadoc
+ PackageDeclaration packDecl = compilUnit.getPackage();
+ List unitComments = compilUnit.getCommentList();
+ assertEquals("Wrong number of comments", 1, unitComments.size());
+ Comment comment = (Comment) unitComments.get(0);
+
+ // Verify package declaration declaration source start
+ assertTrue("Source range of PackageDeclaration should NOT not include Javadoc child", packDecl.getStartPosition() > comment.getStartPosition()+comment.getLength());
+ }
+ }
+
+ /**
+ * Bug 94150: [javadoc][dom] Extended ranges wrong for method name without return type
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=94150"
+ */
+ public void testBug94150() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.astLevel = AST.JLS3;
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b94150/Category.java",
+ "package javadoc.b94150;\n" +
+ "public enum Category {\n" +
+ " /**\n" +
+ " * history style\n" +
+ " * @see Object\n" +
+ " */ \n" +
+ " HISTORY,\n" +
+ "\n" +
+ " /**\n" +
+ " * war style\n" +
+ " */ \n" +
+ " WAR;\n" +
+ "}\n"
+ );
+ CompilationUnit compilUnit = verifyComments(this.workingCopies[0]);
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Get enum declaration
+ ASTNode node = getASTNode(compilUnit, 0);
+ assertEquals("Expected enum declaration.", ASTNode.ENUM_DECLARATION, node.getNodeType());
+ EnumDeclaration enumDeclaration = (EnumDeclaration) node;
+
+ // Verify each enum constant javadoc
+ List constants = enumDeclaration.enumConstants();
+ int size = constants.size();
+ assertEquals("Wrong number of constants", 2, size);
+ for (int i=0; i<size; i++) {
+ EnumConstantDeclaration constant = (EnumConstantDeclaration) constants.get(i);
+ Javadoc docComment = (Javadoc) compilUnit.getCommentList().get(i); // Do not need to verify following statement as we know it's ok as verifyComments did not fail
+ assertTrue("Javadoc should be set on first enum constant", docComment == constant.getJavadoc());
+ }
+ }
+ }
+
+ /**
+ * Bug 99507: [javadoc] Infinit loop in DocCommentParser
+ * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=99507"
+ */
+ public void testBug99507() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b99507/X.java",
+ "package javadoc.b99507;\n" +
+ "public class X {\n" +
+ "}\n" +
+ "/** @param test*/"
+ );
+ verifyComments(this.workingCopies[0]);
+ }
+ public void testBug99507b() throws JavaModelException {
+ String source = "/**\n@param country*/";
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_COMPILATION_UNIT);
+ parser.setSource(source.toCharArray());
+ parser.createAST(null);
+ }
+
+ /**
+ * Bug 100041: [javadoc] Infinit loop in DocCommentParser
+ * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=100041"
+ */
+ public void testBug100041() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b100041/X.java",
+ "package javadoc.b100041;\n" +
+ "class X {\n" +
+ " static Object object;\n" +
+ " static void foo() {\n" +
+ " /**\n" +
+ " * javadoc comment.\n" +
+ " */\n" +
+ " if (object instanceof String) {\n" +
+ " final String clr = null;\n" +
+ " }\n" +
+ " }\n" +
+ "}"
+ );
+ CompilationUnit compilUnit = verifyComments(this.workingCopies[0]);
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Get comment
+ List unitComments = compilUnit.getCommentList();
+ assertEquals("Wrong number of comments", 1, unitComments.size());
+ Comment comment = (Comment) unitComments.get(0);
+ int commentStart = comment.getStartPosition();
+ int commentEnd = commentStart+comment.getLength();
+
+ // Get local variable declaration
+ ASTNode node = getASTNode(compilUnit, 0, 1, 0);
+ assertEquals("Expected if statement for node: "+node, ASTNode.IF_STATEMENT, node.getNodeType());
+ IfStatement ifStatement = (IfStatement) node;
+ assertTrue("Invalid start position for IfStatement: "+ifStatement, ifStatement.getStartPosition() > commentEnd);
+ Statement statement = ifStatement.getThenStatement();
+ assertEquals("Expected block for node: "+statement, ASTNode.BLOCK, statement.getNodeType());
+ Block block = (Block) statement;
+ assertTrue("Invalid start position for Block: "+block, block.getStartPosition() > commentEnd);
+ List statements = block.statements();
+ assertEquals("Invalid number of statements for block: "+block, 1, statements.size());
+ statement = (Statement) statements.get(0);
+ assertEquals("Expected variable declaration statement for node: "+statement, ASTNode.VARIABLE_DECLARATION_STATEMENT, statement.getNodeType());
+ VariableDeclarationStatement varDecl = (VariableDeclarationStatement) statement;
+ assertTrue("Invalid start position for : VariableDeclarationStatement"+varDecl, varDecl.getStartPosition() > commentEnd);
+ }
+ }
+ public void testBug100041b() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b100041/X.java",
+ "package javadoc.b100041;\n" +
+ "class X {\n" +
+ " static Object object;\n" +
+ " static void foo() {\n" +
+ " /**\n" +
+ " * javadoc comment.\n" +
+ " */\n" +
+ " if (object instanceof String)\n" +
+ " return;\n" +
+ " }\n" +
+ "}"
+ );
+ CompilationUnit compilUnit = verifyComments(this.workingCopies[0]);
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Get comment
+ List unitComments = compilUnit.getCommentList();
+ assertEquals("Wrong number of comments", 1, unitComments.size());
+ Comment comment = (Comment) unitComments.get(0);
+ int commentStart = comment.getStartPosition();
+ int commentEnd = commentStart+comment.getLength();
+
+ // Get local variable declaration
+ ASTNode node = getASTNode(compilUnit, 0, 1, 0);
+ assertEquals("Expected if statement for node: "+node, ASTNode.IF_STATEMENT, node.getNodeType());
+ IfStatement ifStatement = (IfStatement) node;
+ assertTrue("Invalid start position for IfStatement: "+ifStatement, ifStatement.getStartPosition() > commentEnd);
+ Statement statement = ifStatement.getThenStatement();
+ assertEquals("Expected block for node: "+statement, ASTNode.RETURN_STATEMENT, statement.getNodeType());
+ ReturnStatement returnStatement = (ReturnStatement) statement;
+ assertTrue("Invalid start position for Block: "+returnStatement, returnStatement.getStartPosition() > commentEnd);
+ }
+ }
+ public void testBug100041c() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b100041/Z.java",
+ "package javadoc.b100041;\n" +
+ "public class Z {\n" +
+ " /** C1 */\n" +
+ " class Z1 {}\n" +
+ " /** C2 */\n" +
+ " Z1 z1;\n" +
+ " /** C3 */\n" +
+ " public static void foo(Object object) {\n" +
+ " /** C4 */\n" +
+ " class ZZ {\n" +
+ " /** C5 */\n" +
+ " ZZ zz;\n" +
+ " /** C6 */\n" +
+ " public void bar() {}\n" +
+ " }\n" +
+ " }\n" +
+ "}\n"
+ );
+ CompilationUnit compilUnit = verifyComments(this.workingCopies[0]);
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Get comments
+ List unitComments = compilUnit.getCommentList();
+ int size = unitComments.size();
+ assertEquals("Wrong number of comments", 6, size);
+ Javadoc[] javadocs = new Javadoc[size];
+ Iterator iterator = unitComments.iterator();
+ for (int i=0; i<size; i++) {
+ Comment comment = (Comment) iterator.next();
+ assertEquals("Expect javadoc for comment: "+comment, ASTNode.JAVADOC, comment.getNodeType());
+ javadocs[i] = (Javadoc) comment;
+ }
+
+ // Verify member type declaration start
+ ASTNode node = getASTNode(compilUnit, 0, 0);
+ assertEquals("Expected type declaration for node: "+node, ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ int javadocStart = javadocs[0].getStartPosition();
+ assertEquals("Invalid start position for TypeDeclaration: "+typeDeclaration, typeDeclaration.getStartPosition(), javadocStart);
+
+ // Verify field declaration start
+ node = getASTNode(compilUnit, 0, 1);
+ assertEquals("Expected field declaration for node: "+node, ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ javadocStart = javadocs[1].getStartPosition();
+ assertEquals("Invalid start position for FieldDeclaration: "+fieldDeclaration, fieldDeclaration.getStartPosition(), javadocStart);
+
+ // Verify method declaration start
+ node = getASTNode(compilUnit, 0, 2);
+ assertEquals("Expected method declaration for node: "+node, ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ javadocStart = javadocs[2].getStartPosition();
+ assertEquals("Invalid start position for MethodDeclaration: "+methodDeclaration, methodDeclaration.getStartPosition(), javadocStart);
+
+ // Verify local type declaration start
+ node = getASTNode(compilUnit, 0, 2, 0);
+ assertEquals("Expected type declaration for node: "+node, ASTNode.TYPE_DECLARATION_STATEMENT, node.getNodeType());
+ typeDeclaration = (TypeDeclaration) ((TypeDeclarationStatement) node).getDeclaration();
+ javadocStart = javadocs[3].getStartPosition();
+ assertEquals("Invalid start position for TypeDeclaration: "+typeDeclaration, typeDeclaration.getStartPosition(), javadocStart);
+
+ // Verify field declaration start
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ node = (ASTNode) bodyDeclarations.get(0);
+ assertEquals("Expected field declaration for node: "+node, ASTNode.FIELD_DECLARATION, node.getNodeType());
+ fieldDeclaration = (FieldDeclaration) node;
+ javadocStart = javadocs[4].getStartPosition();
+ assertEquals("Invalid start position for FieldDeclaration: "+fieldDeclaration, fieldDeclaration.getStartPosition(), javadocStart);
+
+ // Verify method declaration start
+ node = (ASTNode) bodyDeclarations.get(1);
+ assertEquals("Expected method declaration for node: "+node, ASTNode.METHOD_DECLARATION, node.getNodeType());
+ methodDeclaration = (MethodDeclaration) node;
+ javadocStart = javadocs[5].getStartPosition();
+ assertEquals("Invalid start position for MethodDeclaration: "+methodDeclaration, methodDeclaration.getStartPosition(), javadocStart);
+ }
+ }
+
+ /**
+ * @bug 103304: [Javadoc] Wrong reference proposal for inner classes.
+ * @see "http://bugs.eclipse.org/bugs/show_bug.cgi?id=103304"
+ */
+ public void testBug103304() throws JavaModelException {
+ this.packageBinding = false; // do NOT verify that qualification only can be package name
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b103304/Test.java",
+ "package javadoc.b103304;\n" +
+ "interface IAFAState {\n" +
+ " public class ValidationException extends Exception {\n" +
+ " public ValidationException(String variableName, IAFAState subformula) {\n" +
+ " super(\"Variable \'\"+variableName+\"\' may be unbound in \'\"+subformula+\"\'\");\n" +
+ " }\n" +
+ " }\n" +
+ "}\n" +
+ "public class Test {\n" +
+ " /**\n" +
+ " * @see IAFAState.ValidationException#IAFAState.ValidationException(String, IAFAState)\n" +
+ " */\n" +
+ " IAFAState.ValidationException valid;\n" +
+ "}\n"
+ );
+ CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
+ verifyWorkingCopiesComments();
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Verify comment type
+ Iterator unitComments = compilUnit.getCommentList().iterator();
+ while (unitComments.hasNext()) {
+ Comment comment = (Comment) unitComments.next();
+ assertEquals("Comment should be javadoc", comment.getNodeType(), ASTNode.JAVADOC);
+ Javadoc javadoc = (Javadoc) comment;
+
+ // Verify that there's always a method reference in tags
+ List tags = javadoc.tags();
+ int size = tags.size();
+ for (int i=0; i<size; i++) {
+ TagElement tag = (TagElement) javadoc.tags().get(i);
+ assertEquals("Invalid number of fragment for see reference: "+tag, 1, tag.fragments().size());
+ ASTNode node = (ASTNode) tag.fragments().get(0);
+ assertEquals("Invalid kind of name reference for tag element: "+tag, ASTNode.METHOD_REF, node.getNodeType());
+ }
+ }
+ }
+ }
+
+ /**
+ * Bug 106581: [javadoc] null type binding for parameter in javadoc
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=106581"
+ */
+ public void testBug106581() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.astLevel = AST.JLS3;
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b106581/A.java",
+ "package javadoc.b106581;\n" +
+ "public class A {\n" +
+ " /**\n" +
+ " * @param x\n" +
+ " */ \n" +
+ " public void foo(int x) {},\n" +
+ "}\n"
+ );
+ CompilationUnit compilUnit = verifyComments(this.workingCopies[0]);
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Get comment
+ List unitComments = compilUnit.getCommentList();
+ assertEquals("Wrong number of comments", 1, unitComments.size());
+ Comment comment = (Comment) unitComments.get(0);
+ assertEquals("Comment should be javadoc", comment.getNodeType(), ASTNode.JAVADOC);
+
+ // Get local variable declaration
+ Javadoc docComment = (Javadoc) comment;
+ TagElement tag = (TagElement) docComment.tags().get(0);
+ assertEquals("Invalid number of fragment for tag: "+tag, 1, tag.fragments().size());
+ ASTNode node = (ASTNode) tag.fragments().get(0);
+ assertEquals("Invalid kind of name reference for tag element: "+tag, ASTNode.SIMPLE_NAME, node.getNodeType());
+ SimpleName simpleName = (SimpleName) node;
+ assertNotNull("We should have a type binding for simple name: "+simpleName, simpleName.resolveTypeBinding());
+ }
+ }
+
+ /**
+ * Bug 108622: [javadoc][dom] ASTNode not including javadoc
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=108622"
+ */
+ public void testBug108622() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.astLevel = AST.JLS3;
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b108622/Test.java",
+ "package javadoc.b108622;\n" +
+ "/**\n" +
+ " * \n" +
+ " */\n" +
+ "public abstract class Test {\n" +
+ "\n" +
+ " /**\n" +
+ " * \n" +
+ " */\n" +
+ " public abstract Zork getFoo();\n" +
+ "\n" +
+ " /**\n" +
+ " * \n" +
+ " */\n" +
+ " public abstract void setFoo(Zork dept);\n" +
+ "\n" +
+ "}"
+ );
+ CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Verify first method
+ ASTNode node = getASTNode(compilUnit, 0, 0);
+ assertEquals("Invalid type for node: "+node, ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("Invalid method name", "getFoo", methodDeclaration.getName().toString());
+ Javadoc methodJavadoc = methodDeclaration.getJavadoc();
+ assertNotNull("MethodDeclaration have a javadoc comment", methodJavadoc);
+ int javadocStart = methodJavadoc.getStartPosition();
+ assertEquals("Method declaration should include javadoc comment", methodDeclaration.getStartPosition(), javadocStart);
+ // Verify second method
+ node = getASTNode(compilUnit, 0, 1);
+ assertEquals("Invalid type for node: "+node, ASTNode.METHOD_DECLARATION, node.getNodeType());
+ methodDeclaration = (MethodDeclaration) node;
+ assertEquals("Invalid method name", "setFoo", methodDeclaration.getName().toString());
+ methodJavadoc = methodDeclaration.getJavadoc();
+ assertNotNull("MethodDeclaration have a javadoc comment", methodJavadoc);
+ javadocStart = methodJavadoc.getStartPosition();
+ assertEquals("Method declaration should include javadoc comment", methodDeclaration.getStartPosition(), javadocStart);
+ }
+ }
+
+ /**
+ * Bug 113108: [API][comments] CompilationUnit.getNodeComments(ASTNode)
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=113108"
+ */
+ public void testBug113108a() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.astLevel = AST.JLS3;
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b113108/Test.java",
+ "package javadoc.b113108;\n" +
+ "/** C0 */\n" +
+ "public class Test {\n" +
+ " /* C1 */\n" +
+ " /** C2 */\n" +
+ " // C3\n" +
+ " public void foo() {\n" +
+ " /* C4 */\n" +
+ " }\n" +
+ " /* C5 */\n" +
+ " /** C6 */\n" +
+ " // C7\n" +
+ "}"
+ );
+ CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
+ verifyWorkingCopiesComments();
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Verify method javadoc
+ ASTNode node = getASTNode(compilUnit, 0, 0);
+ assertEquals("Invalid type for node: "+node, ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("Invalid method name", "foo", methodDeclaration.getName().toString());
+ Javadoc methodJavadoc = methodDeclaration.getJavadoc();
+ assertNotNull("MethodDeclaration have a javadoc comment", methodJavadoc);
+ int javadocStart = methodJavadoc.getStartPosition();
+ assertEquals("Method declaration should include javadoc comment", methodDeclaration.getStartPosition(), javadocStart);
+ // Verify method first leading and last trailing comment
+ int index = compilUnit.firstLeadingCommentIndex(methodDeclaration);
+ assertEquals("Invalid first leading comment for "+methodDeclaration, 1, index);
+ index = compilUnit.lastTrailingCommentIndex(methodDeclaration);
+ assertEquals("Invalid last trailing comment for "+methodDeclaration, 7, index);
+ }
+ }
+ public void testBug113108b() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.astLevel = AST.JLS3;
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b113108/Test.java",
+ "package javadoc.b113108;\n" +
+ "/** C0 */\n" +
+ "public class Test {\n" +
+ " /** C1 */\n" +
+ " // C2\n" +
+ " /* C3 */\n" +
+ " public void foo() {\n" +
+ " // C4\n" +
+ " }\n" +
+ " /** C5 */\n" +
+ " /// C6\n" +
+ " /* C7 */\n" +
+ "}"
+ );
+ CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
+ verifyWorkingCopiesComments();
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Verify method javadoc
+ ASTNode node = getASTNode(compilUnit, 0, 0);
+ assertEquals("Invalid type for node: "+node, ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("Invalid method name", "foo", methodDeclaration.getName().toString());
+ Javadoc methodJavadoc = methodDeclaration.getJavadoc();
+ assertNotNull("MethodDeclaration have a javadoc comment", methodJavadoc);
+ int javadocStart = methodJavadoc.getStartPosition();
+ assertEquals("Method declaration should include javadoc comment", methodDeclaration.getStartPosition(), javadocStart);
+ // Verify method first leading and last trailing comment
+ int index = compilUnit.firstLeadingCommentIndex(methodDeclaration);
+ assertEquals("Invalid first leading comment for "+methodDeclaration, 1, index);
+ index = compilUnit.lastTrailingCommentIndex(methodDeclaration);
+ assertEquals("Invalid last trailing comment for "+methodDeclaration, 7, index);
+ }
+ }
+ public void testBug113108c() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.astLevel = AST.JLS3;
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b113108/Test.java",
+ "package javadoc.b113108;\n" +
+ "/** C0 */\n" +
+ "public class Test {\n" +
+ " // C1\n" +
+ " /* C2 */\n" +
+ " /** C3 */\n" +
+ " public void foo() {\n" +
+ " /** C4 */\n" +
+ " }\n" +
+ " // C5\n" +
+ " /* C6 */\n" +
+ " /** C7 */\n" +
+ "}"
+ );
+ CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
+ verifyWorkingCopiesComments();
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Verify method javadoc
+ ASTNode node = getASTNode(compilUnit, 0, 0);
+ assertEquals("Invalid type for node: "+node, ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("Invalid method name", "foo", methodDeclaration.getName().toString());
+ Javadoc methodJavadoc = methodDeclaration.getJavadoc();
+ assertNotNull("MethodDeclaration have a javadoc comment", methodJavadoc);
+ int javadocStart = methodJavadoc.getStartPosition();
+ assertEquals("Method declaration should include javadoc comment", methodDeclaration.getStartPosition(), javadocStart);
+ // Verify method first leading and last trailing comment
+ int index = compilUnit.firstLeadingCommentIndex(methodDeclaration);
+ assertEquals("Invalid first leading comment for "+methodDeclaration, 1, index);
+ index = compilUnit.lastTrailingCommentIndex(methodDeclaration);
+ assertEquals("Invalid last trailing comment for "+methodDeclaration, 7, index);
+ }
+ }
+
+ /**
+ * @bug 125676: [javadoc] @category should not read beyond end of line
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=125676"
+ */
+ public void testBug125676() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[3];
+ this.astLevel = AST.JLS3;
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b125676/A.java",
+ "package javadoc.b125676;\n" +
+ "public class A {\n" +
+ " /**\n" +
+ " * @category \n" +
+ " * When searching for field matches, it will exclusively find read accesses, as\n" +
+ " * opposed to write accesses. Note that some expressions are considered both\n" +
+ " * as field read/write accesses: for example, x++; x+= 1;\n" +
+ " * \n" +
+ " * @since 2.0\n" +
+ " */\n" +
+ " int READ_ACCESSES = 4;\n" +
+ "}\n"
+ );
+ this.workingCopies[1] = getWorkingCopy("/Converter15/src/javadoc/b125676/B.java",
+ "package javadoc.b125676;\n" +
+ "public class B {\n" +
+ " /**\n" +
+ " * @category test\n" +
+ " */\n" +
+ " int field1;\n" +
+ " /**\n" +
+ " * @category test\n" +
+ " */\n" +
+ " int field2;\n" +
+ " /**\n" +
+ " * @category test \n" +
+ " */\n" +
+ " int field3;\n" +
+ " /**\n" +
+ " * @category test \n" +
+ " */\n" +
+ " int field4;\n" +
+ " /** @category test */\n" +
+ " int field5;\n" +
+ "\n" +
+ "}\n"
+ );
+ this.workingCopies[2] = getWorkingCopy("/Converter15/src/javadoc/b125676/C.java",
+ "package javadoc.b125676;\n" +
+ "public class C { \n" +
+ " /**\n" +
+ " * @category test mutli ids\n" +
+ " */\n" +
+ " int field1;\n" +
+ " /**\n" +
+ " * @category test mutli ids \n" +
+ " */\n" +
+ " int field2;\n" +
+ " /** @category test mutli ids*/\n" +
+ " int field3;\n" +
+ "}\n"
+ );
+ verifyWorkingCopiesComments();
+ }
+
+ /**
+ * @bug 125903: [javadoc] Treat whitespace in javadoc tags as invalid tags
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=125903"
+ */
+ public void testBug125903() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.astLevel = AST.JLS3;
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b125903/Test.java",
+ "package javadoc.b125903;\n" +
+ "/**\n" +
+ " * {@ link java.lang.String}\n" +
+ " * @ since 2.1\n" +
+ " */\n" +
+ "public class Test {\n" +
+ "\n" +
+ "}\n"
+ );
+ CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
+ verifyWorkingCopiesComments();
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Verify method javadoc
+ ASTNode node = getASTNode(compilUnit, 0);
+ assertEquals("Invalid type for node: "+node, ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ Javadoc javadoc = typeDeclaration.getJavadoc();
+ assertNotNull("TypeDeclaration should have a javadoc comment", javadoc);
+ List tags = javadoc.tags();
+ TagElement tag = (TagElement) tags.get(0);
+ tag = (TagElement) tag.fragments().get(0);
+ assertEquals("Tag name should be empty", tag.getTagName(), "@");
+ tag = (TagElement) tags.get(1);
+ assertEquals("Tag name should be empty", tag.getTagName(), "@");
+ }
+ }
+
+ /**
+ * @bug 130752: [comments] first BlockComment parsed as LineComment
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=130752"
+ */
+ public void testBug130752() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b130752/Test.java",
+ "/* Ceci n'est pas\n" +
+ " * une ligne. */\n" +
+ "package javadoc.b130752;\n" +
+ "public class Test {\n" +
+ "}\n"
+ );
+ CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
+ verifyWorkingCopiesComments();
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Verify comment type
+ List unitComments = compilUnit.getCommentList();
+ assertEquals("Wrong number of comments", 1, unitComments.size());
+ Comment comment = (Comment) unitComments.get(0);
+ assertEquals("Comment should be javadoc", comment.getNodeType(), ASTNode.BLOCK_COMMENT);
+ }
+ }
+ public void testBug130752b() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b130752/Test.java",
+ "// Line comment\n" +
+ "package javadoc.b130752;\n" +
+ "public class Test {\n" +
+ "}\n"
+ );
+ CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
+ verifyWorkingCopiesComments();
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Verify comment type
+ List unitComments = compilUnit.getCommentList();
+ assertEquals("Wrong number of comments", 1, unitComments.size());
+ Comment comment = (Comment) unitComments.get(0);
+ assertEquals("Comment should be javadoc", comment.getNodeType(), ASTNode.LINE_COMMENT);
+ }
+ }
+ public void testBug130752c() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b130752/Test.java",
+ "/** Javadoc comment */\n" +
+ "package javadoc.b130752;\n" +
+ "public class Test {\n" +
+ "}\n"
+ );
+ CompilationUnit compilUnit = (CompilationUnit) runConversion(this.workingCopies[0], true);
+ verifyWorkingCopiesComments();
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Verify comment type
+ List unitComments = compilUnit.getCommentList();
+ assertEquals("Wrong number of comments", 1, unitComments.size());
+ Comment comment = (Comment) unitComments.get(0);
+ assertEquals("Comment should be javadoc", comment.getNodeType(), ASTNode.JAVADOC);
+ }
+ }
+
+ /**
+ * @bug 165525: [comments] ASTParser excludes trailing line comments from extended range of fields in enums
+ * @test Ensure that extended ranges are correct for enum constants and last comments of enum declaration
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=165525"
+ */
+ public void testBug165525() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy("/Converter15/src/javadoc/b165525/Test.java",
+ "package javadoc.b165525;\n" +
+ "public enum Test {\n" +
+ " ENUM_CONST_1(\"String constant 1\") //$NON-NLS-1$\n" +
+ " , ENUM_CONST_2(\"String constant 2\") //$NON-NLS-1$\n" +
+ " ;\n" +
+ " Test(String x) {\n" +
+ " }\n" +
+ " String a = \"a\"; //$NON-NLS-1$\n" +
+ " String b = \"b\"; //$NON-NLS-1$\n" +
+ "}\n"
+ );
+ CompilationUnit compilUnit = (CompilationUnit) runConversion(AST.JLS3, this.workingCopies[0], true);
+ verifyWorkingCopiesComments();
+ if (this.docCommentSupport.equals(JavaCore.ENABLED)) {
+ // Verify comment type
+ List unitComments = compilUnit.getCommentList();
+ assertEquals("Wrong number of comments", 4, unitComments.size());
+
+ // Verify extension of first enum declaration constant
+ Comment comment = (Comment) unitComments.get(0);
+ EnumDeclaration enumDeclaration = (EnumDeclaration) compilUnit.types().get(0);
+ EnumConstantDeclaration constantDeclaration = (EnumConstantDeclaration) enumDeclaration.enumConstants().get(0);
+ int declarationEnd = constantDeclaration.getStartPosition() + compilUnit.getExtendedLength(constantDeclaration) - 1;
+ int commentEnd = comment.getStartPosition() + comment.getLength() - 1;
+ assumeEquals("Enum constant declaration "+constantDeclaration+" does not have the correct length", commentEnd, declarationEnd);
+
+ // Verify extension of second enum declaration constant
+ comment = (Comment) unitComments.get(1);
+ constantDeclaration = (EnumConstantDeclaration) enumDeclaration.enumConstants().get(1);
+ declarationEnd = constantDeclaration.getStartPosition() + compilUnit.getExtendedLength(constantDeclaration) - 1;
+ commentEnd = comment.getStartPosition() + comment.getLength() - 1;
+ assumeEquals("Enum constant declaration "+constantDeclaration+" does not have the correct length", commentEnd, declarationEnd);
+
+ // Verify extension of first field declaration
+ comment = (Comment) unitComments.get(2);
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) enumDeclaration.bodyDeclarations().get(1);
+ declarationEnd = fieldDeclaration.getStartPosition() + compilUnit.getExtendedLength(fieldDeclaration) - 1;
+ commentEnd = comment.getStartPosition() + comment.getLength() - 1;
+ assumeEquals("Enum constant declaration "+constantDeclaration+" does not have the correct length", commentEnd, declarationEnd);
+
+ // Verify extension of second field declaration
+ comment = (Comment) unitComments.get(3);
+ fieldDeclaration = (FieldDeclaration) enumDeclaration.bodyDeclarations().get(2);
+ declarationEnd = fieldDeclaration.getStartPosition() + compilUnit.getExtendedLength(fieldDeclaration) - 1;
+ commentEnd = comment.getStartPosition() + comment.getLength() - 1;
+ assumeEquals("Enum constant declaration "+constantDeclaration+" does not have the correct length", commentEnd, declarationEnd);
+ }
+ }
+
+ /**
+ * @bug 228648: AST: no binding for Javadoc reference to inner class
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=228648"
+ */
+ public void testBug228648() throws JavaModelException {
+ ICompilationUnit unit = getCompilationUnit("Converter" , "src", "javadoc.testBug228648", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ verifyComments(unit);
+ }
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=196714
+ public void test109() throws JavaModelException {
+ verifyComments("test109");
+ }
+}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterRecoveryTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterRecoveryTest.java
new file mode 100644
index 0000000..e676111
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterRecoveryTest.java
@@ -0,0 +1,995 @@
+/*******************************************************************************
+ * Copyright (c) 2006, 2009 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.dom;
+
+import java.util.List;
+
+import junit.framework.Test;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.ArrayInitializer;
+import org.eclipse.jdt.core.dom.AssertStatement;
+import org.eclipse.jdt.core.dom.Assignment;
+import org.eclipse.jdt.core.dom.Block;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.EmptyStatement;
+import org.eclipse.jdt.core.dom.Expression;
+import org.eclipse.jdt.core.dom.ExpressionStatement;
+import org.eclipse.jdt.core.dom.ForStatement;
+import org.eclipse.jdt.core.dom.ITypeBinding;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.MethodInvocation;
+import org.eclipse.jdt.core.dom.NumberLiteral;
+import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.dom.Statement;
+import org.eclipse.jdt.core.dom.StringLiteral;
+import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
+import org.eclipse.jdt.core.dom.VariableDeclarationExpression;
+
+public class ASTConverterRecoveryTest extends ConverterTestSetup {
+ public ASTConverterRecoveryTest(String name) {
+ super(name);
+ }
+
+ static {
+// TESTS_NAMES = new String[] {"test0003"};
+// TESTS_NUMBERS = new int[] { 624 };
+ }
+ public static Test suite() {
+ return buildModelTestSuite(ASTConverterRecoveryTest.class);
+ }
+
+ public void setUpSuite() throws Exception {
+ super.setUpSuite();
+ this.ast = AST.newAST(AST.JLS3);
+ }
+
+ public void test0001() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter/src/test/X.java",
+ "package test;\n"+
+ "\n"+
+ "public class X {\n"+
+ " void foo() {\n"+
+ " bar(0)\n"+
+ " baz(1);\n"+
+ " }\n"+
+ "}\n");
+
+ char[] source = this.workingCopies[0].getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, this.workingCopies[0], true, true);
+
+ assertASTNodeEquals(
+ "package test;\n" +
+ "public class X {\n" +
+ " void foo(){\n" +
+ " bar(0);\n" +
+ " baz(1);\n" +
+ " }\n" +
+ "}\n",
+ result);
+
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("wrong size", 2, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("Not an expression statement", statement.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) statement;
+ checkSourceRange(expressionStatement, "bar(0)", source); //$NON-NLS-1$
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ checkSourceRange(methodInvocation, "bar(0)", source); //$NON-NLS-1$
+ List list = methodInvocation.arguments();
+ assertTrue("Parameter list is empty", list.size() == 1); //$NON-NLS-1$
+ Expression parameter = (Expression) list.get(0);
+ assertTrue("Not a number", parameter instanceof NumberLiteral); //$NON-NLS-1$
+ ITypeBinding typeBinding = parameter.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not int", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(parameter, "0", source); //$NON-NLS-1$
+ Statement statement2 = (Statement) statements.get(1);
+ assertTrue("Not an expression statement", statement2.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement2 = (ExpressionStatement) statement2;
+ checkSourceRange(expressionStatement2, "baz(1);", source); //$NON-NLS-1$
+ Expression expression2 = expressionStatement2.getExpression();
+ assertTrue("Not a method invocation", expression2.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation2 = (MethodInvocation) expression2;
+ checkSourceRange(methodInvocation2, "baz(1)", source); //$NON-NLS-1$
+ List list2 = methodInvocation2.arguments();
+ assertTrue("Parameter list is empty", list2.size() == 1); //$NON-NLS-1$
+ Expression parameter2 = (Expression) list2.get(0);
+ assertTrue("Not a number", parameter2 instanceof NumberLiteral); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = parameter2.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding2); //$NON-NLS-1$
+ assertEquals("Not int", "int", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(parameter2, "1", source); //$NON-NLS-1$
+ }
+
+ public void test0002() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter/src/test/X.java",
+ "package test;\n"+
+ "\n"+
+ "public class X {\n"+
+ " void foo() {\n"+
+ " baz(0);\n"+
+ " bar(1,\n"+
+ " }\n"+
+ "}\n");
+
+ char[] source = this.workingCopies[0].getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, this.workingCopies[0], true, true);
+
+ assertASTNodeEquals(
+ "package test;\n" +
+ "public class X {\n" +
+ " void foo(){\n" +
+ " baz(0);\n" +
+ " bar(1);\n" +
+ " }\n" +
+ "}\n",
+ result);
+
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("wrong size", 2, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("Not an expression statement", statement.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) statement;
+ checkSourceRange(expressionStatement, "baz(0);", source); //$NON-NLS-1$
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ checkSourceRange(methodInvocation, "baz(0)", source); //$NON-NLS-1$
+ List list = methodInvocation.arguments();
+ assertTrue("Parameter list is empty", list.size() == 1); //$NON-NLS-1$
+ Expression parameter = (Expression) list.get(0);
+ assertTrue("Not a number", parameter instanceof NumberLiteral); //$NON-NLS-1$
+ ITypeBinding typeBinding = parameter.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not int", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(parameter, "0", source); //$NON-NLS-1$
+ Statement statement2 = (Statement) statements.get(1);
+ assertTrue("Not an expression statement", statement2.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement2 = (ExpressionStatement) statement2;
+ checkSourceRange(expressionStatement2, "bar(1", source); //$NON-NLS-1$
+ Expression expression2 = expressionStatement2.getExpression();
+ assertTrue("Not a method invocation", expression2.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation2 = (MethodInvocation) expression2;
+ checkSourceRange(methodInvocation2, "bar(1", source); //$NON-NLS-1$
+ List list2 = methodInvocation2.arguments();
+ assertTrue("Parameter list is empty", list2.size() == 1); //$NON-NLS-1$
+ Expression parameter2 = (Expression) list2.get(0);
+ assertTrue("Not a number", parameter2 instanceof NumberLiteral); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = parameter2.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding2); //$NON-NLS-1$
+ assertEquals("Not int", "int", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(parameter2, "1", source); //$NON-NLS-1$
+ }
+
+ public void test0003() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter/src/test/X.java",
+ "package test;\n"+
+ "\n"+
+ "public class X {\n"+
+ " void foo() {\n"+
+ " baz(0);\n"+
+ " bar(1,\n"+
+ " foo(3);\n"+
+ " }\n"+
+ "}\n");
+
+ char[] source = this.workingCopies[0].getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, this.workingCopies[0], true, true);
+
+ assertASTNodeEquals(
+ "package test;\n" +
+ "public class X {\n" +
+ " void foo(){\n" +
+ " baz(0);\n" +
+ " bar(1,foo(3));\n" +
+ " }\n" +
+ "}\n",
+ result);
+
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("wrong size", 2, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("Not an expression statement", statement.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) statement;
+ checkSourceRange(expressionStatement, "baz(0);", source); //$NON-NLS-1$
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ checkSourceRange(methodInvocation, "baz(0)", source); //$NON-NLS-1$
+ List list = methodInvocation.arguments();
+ assertTrue("Parameter list is empty", list.size() == 1); //$NON-NLS-1$
+ Expression parameter = (Expression) list.get(0);
+ assertTrue("Not a number", parameter instanceof NumberLiteral); //$NON-NLS-1$
+ ITypeBinding typeBinding = parameter.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not int", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(parameter, "0", source); //$NON-NLS-1$
+ Statement statement2 = (Statement) statements.get(1);
+ assertTrue("Not an expression statement", statement2.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement2 = (ExpressionStatement) statement2;
+ checkSourceRange(expressionStatement2, "bar(1,\n\t foo(3);", source); //$NON-NLS-1$
+ Expression expression2 = expressionStatement2.getExpression();
+ assertTrue("Not a method invocation", expression2.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation2 = (MethodInvocation) expression2;
+ checkSourceRange(methodInvocation2, "bar(1,\n\t foo(3)", source); //$NON-NLS-1$
+ List list2 = methodInvocation2.arguments();
+ assertTrue("Parameter list is empty", list2.size() == 2); //$NON-NLS-1$
+ Expression parameter2 = (Expression) list2.get(0);
+ assertTrue("Not a Number", parameter2 instanceof NumberLiteral); //$NON-NLS-1$
+ parameter2 = (Expression) list2.get(1);
+ assertTrue("Not a method invocation", parameter2 instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation3 = (MethodInvocation) parameter2;
+ checkSourceRange(methodInvocation3, "foo(3)", source); //$NON-NLS-1$
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=124296
+ public void test0004() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter/src/test/X.java",
+ "package test;\n"+
+ "\n"+
+ "public class X {\n"+
+ " void foo() {\n"+
+ " int var= 123\n"+
+ " System.out.println(var);\n"+
+ " }\n"+
+ "}\n");
+
+ char[] source = this.workingCopies[0].getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, this.workingCopies[0], true, true);
+
+ assertASTNodeEquals(
+ "package test;\n" +
+ "public class X {\n" +
+ " void foo(){\n" +
+ " int var=123;\n" +
+ " System.out.println(var);\n" +
+ " }\n" +
+ "}\n",
+ result);
+
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("wrong size", 2, statements.size()); //$NON-NLS-1$
+ Statement statement1 = (Statement) statements.get(0);
+ assertTrue("Not an expression statement", statement1.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) statement1;
+ checkSourceRange(variableDeclarationStatement, "int var= 123", source); //$NON-NLS-1$
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment)fragments.get(0);
+ checkSourceRange(variableDeclarationFragment, "var= 123", source); //$NON-NLS-1$
+ }
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=126148
+ public void test0005() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter/src/test/X.java",
+ "package test;\n"+
+ "\n"+
+ "public class X {\n"+
+ " void foo() {\n"+
+ " String[] s = {\"\",,,};\n"+
+ " }\n"+
+ "}\n");
+
+ char[] source = this.workingCopies[0].getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, this.workingCopies[0], true, true);
+
+ assertASTNodeEquals(
+ "package test;\n" +
+ "public class X {\n" +
+ " void foo(){\n" +
+ " String[] s={\"\",$missing$};\n" +
+ " }\n" +
+ "}\n",
+ result);
+
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement statement1 = (Statement) statements.get(0);
+ assertTrue("Not an expression variable declaration statement", statement1.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) statement1;
+ checkSourceRange(variableDeclarationStatement, "String[] s = {\"\",,,};", source); //$NON-NLS-1$
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment)fragments.get(0);
+ checkSourceRange(variableDeclarationFragment, "s = {\"\",,,}", source); //$NON-NLS-1$
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not an array initializer", expression.getNodeType() == ASTNode.ARRAY_INITIALIZER); //$NON-NLS-1$
+ ArrayInitializer arrayInitializer = (ArrayInitializer) expression;
+ checkSourceRange(arrayInitializer, "{\"\",,,}", source); //$NON-NLS-1$
+ List expressions = arrayInitializer.expressions();
+ assertEquals("wrong size", 2, expressions.size()); //$NON-NLS-1$
+ Expression expression1 = (Expression) expressions.get(0);
+ assertTrue("Not a string literal", expression1.getNodeType() == ASTNode.STRING_LITERAL); //$NON-NLS-1$
+ StringLiteral stringLiteral = (StringLiteral) expression1;
+ checkSourceRange(stringLiteral, "\"\"", source); //$NON-NLS-1$
+ Expression expression2 = (Expression) expressions.get(1);
+ assertTrue("Not a string literal", expression2.getNodeType() == ASTNode.SIMPLE_NAME); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) expression2;
+ checkSourceRange(simpleName, ",", source); //$NON-NLS-1$
+
+ }
+
+ // check RECOVERED flag (insert tokens)
+ public void test0006() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter/src/test/X.java",
+ "package test;\n"+
+ "\n"+
+ "public class X {\n"+
+ " void foo() {\n"+
+ " bar()\n"+
+ " }\n"+
+ "}\n");
+
+ char[] source = this.workingCopies[0].getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, this.workingCopies[0], true, true);
+
+ assertASTNodeEquals(
+ "package test;\n" +
+ "public class X {\n" +
+ " void foo(){\n" +
+ " bar();\n" +
+ " }\n" +
+ "}\n",
+ result);
+
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Flag as RECOVERED", (methodDeclaration.getFlags() & ASTNode.RECOVERED) == 0);
+ Block block = methodDeclaration.getBody();
+ assertTrue("Flag as RECOVERED", (block.getFlags() & ASTNode.RECOVERED) == 0);
+ List statements = block.statements();
+ assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("Not an expression statement", statement.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) statement;
+ checkSourceRange(expressionStatement, "bar()", source); //$NON-NLS-1$
+ assertTrue("Not flag as RECOVERED", (expressionStatement.getFlags() & ASTNode.RECOVERED) != 0);
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation)expression;
+ checkSourceRange(methodInvocation, "bar()", source); //$NON-NLS-1$
+ assertTrue("Flag as RECOVERED", (methodInvocation.getFlags() & ASTNode.RECOVERED) == 0);
+ }
+
+ // check RECOVERED flag (insert tokens)
+ public void test0007() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter/src/test/X.java",
+ "package test;\n"+
+ "\n"+
+ "public class X {\n"+
+ " void foo() {\n"+
+ " bar(baz()\n"+
+ " }\n"+
+ "}\n");
+
+ char[] source = this.workingCopies[0].getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, this.workingCopies[0], true, true);
+
+ assertASTNodeEquals(
+ "package test;\n" +
+ "public class X {\n" +
+ " void foo(){\n" +
+ " bar(baz());\n" +
+ " }\n" +
+ "}\n",
+ result);
+
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Flag as RECOVERED", (methodDeclaration.getFlags() & ASTNode.RECOVERED) == 0);
+ Block block = methodDeclaration.getBody();
+ assertTrue("Flag as RECOVERED", (block.getFlags() & ASTNode.RECOVERED) == 0);
+ List statements = block.statements();
+ assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("Not an expression statement", statement.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) statement;
+ checkSourceRange(expressionStatement, "bar(baz()", source); //$NON-NLS-1$
+ assertTrue("Not flag as RECOVERED", (expressionStatement.getFlags() & ASTNode.RECOVERED) != 0);
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation)expression;
+ checkSourceRange(methodInvocation, "bar(baz()", source); //$NON-NLS-1$
+ assertTrue("Not flag as RECOVERED", (methodInvocation.getFlags() & ASTNode.RECOVERED) != 0);
+ List arguments = methodInvocation.arguments();
+ assertEquals("wrong size", 1, arguments.size()); //$NON-NLS-1$
+ Expression argument = (Expression) arguments.get(0);
+ assertTrue("Not a method invocation", argument.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation2 = (MethodInvocation) argument;
+ checkSourceRange(methodInvocation2, "baz()", source); //$NON-NLS-1$
+ assertTrue("Flag as RECOVERED", (methodInvocation2.getFlags() & ASTNode.RECOVERED) == 0);
+ }
+
+ // check RECOVERED flag (insert tokens)
+ public void test0008() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter/src/test/X.java",
+ "package test;\n"+
+ "\n"+
+ "public class X {\n"+
+ " void foo() {\n"+
+ " for(int i\n"+
+ " }\n"+
+ "}\n");
+
+ char[] source = this.workingCopies[0].getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, this.workingCopies[0], true, true);
+
+ assertASTNodeEquals(
+ "package test;\n" +
+ "public class X {\n" +
+ " void foo(){\n" +
+ " for (int i; ; ) ;\n" +
+ " }\n" +
+ "}\n",
+ result);
+
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Flag as RECOVERED", (methodDeclaration.getFlags() & ASTNode.RECOVERED) == 0);
+ Block block = methodDeclaration.getBody();
+ assertTrue("Not flag as RECOVERED", (block.getFlags() & ASTNode.RECOVERED) != 0);
+ List statements = block.statements();
+ assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("Not a for statement", statement.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) statement;
+ checkSourceRange(forStatement, "for(int i", source); //$NON-NLS-1$
+ assertTrue("Not flag as RECOVERED", (forStatement.getFlags() & ASTNode.RECOVERED) != 0);
+ List initializers = forStatement.initializers();
+ assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$
+ Expression expression = (Expression)initializers.get(0);
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.VARIABLE_DECLARATION_EXPRESSION); //$NON-NLS-1$
+ VariableDeclarationExpression variableDeclarationExpression = (VariableDeclarationExpression)expression;
+ checkSourceRange(variableDeclarationExpression, "int i", source); //$NON-NLS-1$
+ assertTrue("Not flag as RECOVERED", (variableDeclarationExpression.getFlags() & ASTNode.RECOVERED) != 0);
+ List fragments = variableDeclarationExpression.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment)fragments.get(0);
+ checkSourceRange(fragment, "i", source); //$NON-NLS-1$
+ assertTrue("Not flag as RECOVERED", (fragment.getFlags() & ASTNode.RECOVERED) != 0);
+ SimpleName name = fragment.getName();
+ checkSourceRange(name, "i", source); //$NON-NLS-1$
+ assertTrue("Flag as RECOVERED", (name.getFlags() & ASTNode.RECOVERED) == 0);
+ Statement statement2 = forStatement.getBody();
+ assertTrue("Not an empty statement", statement2.getNodeType() == ASTNode.EMPTY_STATEMENT); //$NON-NLS-1$
+ EmptyStatement emptyStatement = (EmptyStatement)statement2;
+ assertEquals("Wrong start position", fragment.getStartPosition() + fragment.getLength(), emptyStatement.getStartPosition());
+ assertEquals("Wrong length", 0, emptyStatement.getLength());
+ assertTrue("Not flag as RECOVERED", (emptyStatement.getFlags() & ASTNode.RECOVERED) != 0);
+ }
+
+ // check RECOVERED flag (remove tokens)
+ public void test0009() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter/src/test/X.java",
+ "package test;\n"+
+ "\n"+
+ "public class X {\n"+
+ " void foo() {\n"+
+ " bar(baz());#\n"+
+ " }\n"+
+ "}\n");
+
+ char[] source = this.workingCopies[0].getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, this.workingCopies[0], true, true);
+
+ assertASTNodeEquals(
+ "package test;\n" +
+ "public class X {\n" +
+ " void foo(){\n" +
+ " bar(baz());\n" +
+ " }\n" +
+ "}\n",
+ result);
+
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Flag as RECOVERED", (methodDeclaration.getFlags() & ASTNode.RECOVERED) == 0);
+ Block block = methodDeclaration.getBody();
+ assertTrue("Not flag as RECOVERED", (block.getFlags() & ASTNode.RECOVERED) != 0);
+ List statements = block.statements();
+ assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("Not an expression statement", statement.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) statement;
+ checkSourceRange(expressionStatement, "bar(baz());", source); //$NON-NLS-1$
+ assertTrue("Flag as RECOVERED", (expressionStatement.getFlags() & ASTNode.RECOVERED) == 0);
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation)expression;
+ checkSourceRange(methodInvocation, "bar(baz())", source); //$NON-NLS-1$
+ assertTrue("Flag as RECOVERED", (methodInvocation.getFlags() & ASTNode.RECOVERED) == 0);
+ List arguments = methodInvocation.arguments();
+ assertEquals("wrong size", 1, arguments.size()); //$NON-NLS-1$
+ Expression argument = (Expression) arguments.get(0);
+ assertTrue("Not a method invocation", argument.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation2 = (MethodInvocation) argument;
+ checkSourceRange(methodInvocation2, "baz()", source); //$NON-NLS-1$
+ assertTrue("Flag as RECOVERED", (methodInvocation2.getFlags() & ASTNode.RECOVERED) == 0);
+ }
+
+ // check RECOVERED flag (remove tokens)
+ public void test0010() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter/src/test/X.java",
+ "package test;\n"+
+ "\n"+
+ "public class X {\n"+
+ " void foo() {\n"+
+ " bar(baz())#;\n"+
+ " }\n"+
+ "}\n");
+
+ char[] source = this.workingCopies[0].getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, this.workingCopies[0], true, true);
+
+ assertASTNodeEquals(
+ "package test;\n" +
+ "public class X {\n" +
+ " void foo(){\n" +
+ " bar(baz());\n" +
+ " }\n" +
+ "}\n",
+ result);
+
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Flag as RECOVERED", (methodDeclaration.getFlags() & ASTNode.RECOVERED) == 0);
+ Block block = methodDeclaration.getBody();
+ assertTrue("Flag as RECOVERED", (block.getFlags() & ASTNode.RECOVERED) == 0);
+ List statements = block.statements();
+ assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("Not an expression statement", statement.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) statement;
+ checkSourceRange(expressionStatement, "bar(baz())#;", source); //$NON-NLS-1$
+ assertTrue("Not flag as RECOVERED", (expressionStatement.getFlags() & ASTNode.RECOVERED) != 0);
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation)expression;
+ checkSourceRange(methodInvocation, "bar(baz())", source); //$NON-NLS-1$
+ assertTrue("Flag as RECOVERED", (methodInvocation.getFlags() & ASTNode.RECOVERED) == 0);
+ List arguments = methodInvocation.arguments();
+ assertEquals("wrong size", 1, arguments.size()); //$NON-NLS-1$
+ Expression argument = (Expression) arguments.get(0);
+ assertTrue("Not a method invocation", argument.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation2 = (MethodInvocation) argument;
+ checkSourceRange(methodInvocation2, "baz()", source); //$NON-NLS-1$
+ assertTrue("Flag as RECOVERED", (methodInvocation2.getFlags() & ASTNode.RECOVERED) == 0);
+ }
+
+ // check RECOVERED flag (remove tokens)
+ public void test0011() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter/src/test/X.java",
+ "package test;\n"+
+ "\n"+
+ "public class X {\n"+
+ " void foo() {\n"+
+ " bar(baz()#);\n"+
+ " }\n"+
+ "}\n");
+
+ char[] source = this.workingCopies[0].getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, this.workingCopies[0], true, true);
+
+ assertASTNodeEquals(
+ "package test;\n" +
+ "public class X {\n" +
+ " void foo(){\n" +
+ " bar(baz());\n" +
+ " }\n" +
+ "}\n",
+ result);
+
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Flag as RECOVERED", (methodDeclaration.getFlags() & ASTNode.RECOVERED) == 0);
+ Block block = methodDeclaration.getBody();
+ assertTrue("Flag as RECOVERED", (block.getFlags() & ASTNode.RECOVERED) == 0);
+ List statements = block.statements();
+ assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("Not an expression statement", statement.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) statement;
+ checkSourceRange(expressionStatement, "bar(baz()#);", source); //$NON-NLS-1$
+ assertTrue("Flag as RECOVERED", (expressionStatement.getFlags() & ASTNode.RECOVERED) == 0);
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation)expression;
+ checkSourceRange(methodInvocation, "bar(baz()#)", source); //$NON-NLS-1$
+ assertTrue("Not flag as RECOVERED", (methodInvocation.getFlags() & ASTNode.RECOVERED) != 0);
+ List arguments = methodInvocation.arguments();
+ assertEquals("wrong size", 1, arguments.size()); //$NON-NLS-1$
+ Expression argument = (Expression) arguments.get(0);
+ assertTrue("Not a method invocation", argument.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation2 = (MethodInvocation) argument;
+ checkSourceRange(methodInvocation2, "baz()", source); //$NON-NLS-1$
+ assertTrue("Flag as RECOVERED", (methodInvocation2.getFlags() & ASTNode.RECOVERED) == 0);
+ }
+
+ // check RECOVERED flag (insert tokens)
+ public void test0012() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter/src/test/X.java",
+ "package test;\n"+
+ "\n"+
+ "public class X {\n"+
+ " void foo() {\n"+
+ " bar()#\n"+
+ " }\n"+
+ "}\n");
+
+ char[] source = this.workingCopies[0].getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, this.workingCopies[0], true, true);
+
+ assertASTNodeEquals(
+ "package test;\n" +
+ "public class X {\n" +
+ " void foo(){\n" +
+ " bar();\n" +
+ " }\n" +
+ "}\n",
+ result);
+
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Flag as RECOVERED", (methodDeclaration.getFlags() & ASTNode.RECOVERED) == 0);
+ Block block = methodDeclaration.getBody();
+ assertTrue("Flag as RECOVERED", (block.getFlags() & ASTNode.RECOVERED) == 0);
+ List statements = block.statements();
+ assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("Not an expression statement", statement.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) statement;
+ checkSourceRange(expressionStatement, "bar()#", source); //$NON-NLS-1$
+ assertTrue("Not flag as RECOVERED", (expressionStatement.getFlags() & ASTNode.RECOVERED) != 0);
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation)expression;
+ checkSourceRange(methodInvocation, "bar()", source); //$NON-NLS-1$
+ assertTrue("Flag as RECOVERED", (methodInvocation.getFlags() & ASTNode.RECOVERED) == 0);
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=129555
+ public void test0013() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter/src/test/X.java",
+ "package test;\n"+
+ "\n"+
+ "public class X {\n"+
+ " void foo() {\n"+
+ " a[0]\n"+
+ " }\n"+
+ "}\n");
+
+ char[] source = this.workingCopies[0].getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, this.workingCopies[0], true, true);
+
+ assertASTNodeEquals(
+ "package test;\n" +
+ "public class X {\n" +
+ " void foo(){\n" +
+ " a[0]=$missing$;\n" +
+ " }\n" +
+ "}\n",
+ result);
+
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Flag as RECOVERED", (methodDeclaration.getFlags() & ASTNode.RECOVERED) == 0);
+ Block block = methodDeclaration.getBody();
+ assertTrue("Flag as RECOVERED", (block.getFlags() & ASTNode.RECOVERED) != 0);
+ List statements = block.statements();
+ assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("Not an expression statement", statement.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) statement;
+ checkSourceRange(expressionStatement, "a[0]", source); //$NON-NLS-1$
+ assertTrue("Not flag as RECOVERED", (expressionStatement.getFlags() & ASTNode.RECOVERED) != 0);
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not an assigment", expression.getNodeType() == ASTNode.ASSIGNMENT); //$NON-NLS-1$
+ Assignment assignment = (Assignment)expression;
+ checkSourceRange(assignment, "a[0]", source); //$NON-NLS-1$
+ assertTrue("Flag as RECOVERED", (assignment.getFlags() & ASTNode.RECOVERED) != 0);
+ Expression rhs = assignment.getRightHandSide();
+ assertTrue("Not a simple name", rhs.getNodeType() == ASTNode.SIMPLE_NAME); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) rhs;
+ assertEquals("Not length isn't correct", 0, simpleName.getLength()); //$NON-NLS-1$
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=129909
+ public void test0014() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter/src/test/X.java",
+ "package test;\n"+
+ "\n"+
+ "public class X {\n"+
+ " void foo() {\n"+
+ " int[] = a[0];\n"+
+ " }\n"+
+ "}\n");
+
+ char[] source = this.workingCopies[0].getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, this.workingCopies[0], true, true);
+
+ assertASTNodeEquals(
+ "package test;\n" +
+ "public class X {\n" +
+ " void foo(){\n" +
+ " int[] $missing$=a[0];\n" +
+ " }\n" +
+ "}\n",
+ result);
+
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Flag as RECOVERED", (methodDeclaration.getFlags() & ASTNode.RECOVERED) == 0);
+ Block block = methodDeclaration.getBody();
+ assertTrue("Flag as RECOVERED", (block.getFlags() & ASTNode.RECOVERED) == 0);
+ List statements = block.statements();
+ assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("Not a variable declaration statement", statement.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) statement;
+ checkSourceRange(variableDeclarationStatement, "int[] = a[0];", source); //$NON-NLS-1$
+ assertTrue("Not flag as RECOVERED", (variableDeclarationStatement.getFlags() & ASTNode.RECOVERED) != 0);
+ List fragments = variableDeclarationStatement.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ SimpleName simpleName = fragment.getName();
+ assertEquals("Not length isn't correct", 0, simpleName.getLength()); //$NON-NLS-1$
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=143212
+ public void test0015() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter/src/test/X.java",
+ "package test;\n"+
+ "\n"+
+ "public class X {\n"+
+ " void foo() {\n"+
+ " assert 0 == 0 : a[0;\n"+
+ " }\n"+
+ "}\n");
+
+ char[] source = this.workingCopies[0].getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, this.workingCopies[0], true, true);
+
+ assertASTNodeEquals(
+ "package test;\n" +
+ "public class X {\n" +
+ " void foo(){\n" +
+ " assert 0 == 0 : a[0];\n" +
+ " }\n" +
+ "}\n",
+ result);
+
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Flag as RECOVERED", (methodDeclaration.getFlags() & ASTNode.RECOVERED) == 0);
+ Block block = methodDeclaration.getBody();
+ assertTrue("Flag as RECOVERED", (block.getFlags() & ASTNode.RECOVERED) == 0);
+ List statements = block.statements();
+ assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("Not an assert statement", statement.getNodeType() == ASTNode.ASSERT_STATEMENT); //$NON-NLS-1$
+ AssertStatement assertStatement = (AssertStatement) statement;
+ checkSourceRange(assertStatement, "assert 0 == 0 : a[0;", source); //$NON-NLS-1$
+ assertTrue("Flag as RECOVERED", (assertStatement.getFlags() & ASTNode.RECOVERED) == 0);
+ Expression message = assertStatement.getMessage();
+ assertTrue("No message expression", message != null); //$NON-NLS-1$
+ checkSourceRange(message, "a[0", source); //$NON-NLS-1$
+ assertTrue("Not flag as RECOVERED", (message.getFlags() & ASTNode.RECOVERED) != 0);
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=143212
+ public void test0016() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter/src/test/X.java",
+ "package test;\n"+
+ "\n"+
+ "public class X {\n"+
+ " void foo() {\n"+
+ " assert 0 == 0 : foo(;\n"+
+ " }\n"+
+ "}\n");
+
+ char[] source = this.workingCopies[0].getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, this.workingCopies[0], true, true);
+
+ assertASTNodeEquals(
+ "package test;\n" +
+ "public class X {\n" +
+ " void foo(){\n" +
+ " assert 0 == 0 : foo();\n" +
+ " }\n" +
+ "}\n",
+ result);
+
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Flag as RECOVERED", (methodDeclaration.getFlags() & ASTNode.RECOVERED) == 0);
+ Block block = methodDeclaration.getBody();
+ assertTrue("Flag as RECOVERED", (block.getFlags() & ASTNode.RECOVERED) == 0);
+ List statements = block.statements();
+ assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("Not an assert statement", statement.getNodeType() == ASTNode.ASSERT_STATEMENT); //$NON-NLS-1$
+ AssertStatement assertStatement = (AssertStatement) statement;
+ checkSourceRange(assertStatement, "assert 0 == 0 : foo(;", source); //$NON-NLS-1$
+ assertTrue("Flag as RECOVERED", (assertStatement.getFlags() & ASTNode.RECOVERED) == 0);
+ Expression message = assertStatement.getMessage();
+ assertTrue("No message expression", message != null); //$NON-NLS-1$
+ checkSourceRange(message, "foo(", source); //$NON-NLS-1$
+ assertTrue("Not flag as RECOVERED", (message.getFlags() & ASTNode.RECOVERED) != 0);
+ }
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=143212
+ public void test0017() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[1];
+ this.workingCopies[0] = getWorkingCopy(
+ "/Converter/src/test/X.java",
+ "package test;\n"+
+ "\n"+
+ "public class X {\n"+
+ " void foo() {\n"+
+ " assert 0 == 0 : (\"aa\";\n"+
+ " }\n"+
+ "}\n");
+
+ char[] source = this.workingCopies[0].getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, this.workingCopies[0], true, true);
+
+ assertASTNodeEquals(
+ "package test;\n" +
+ "public class X {\n" +
+ " void foo(){\n" +
+ " assert 0 == 0 : (\"aa\");\n" +
+ " }\n" +
+ "}\n",
+ result);
+
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Flag as RECOVERED", (methodDeclaration.getFlags() & ASTNode.RECOVERED) == 0);
+ Block block = methodDeclaration.getBody();
+ assertTrue("Flag as RECOVERED", (block.getFlags() & ASTNode.RECOVERED) == 0);
+ List statements = block.statements();
+ assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("Not an assert statement", statement.getNodeType() == ASTNode.ASSERT_STATEMENT); //$NON-NLS-1$
+ AssertStatement assertStatement = (AssertStatement) statement;
+ checkSourceRange(assertStatement, "assert 0 == 0 : (\"aa\";", source); //$NON-NLS-1$
+ assertTrue("Flag as RECOVERED", (assertStatement.getFlags() & ASTNode.RECOVERED) == 0);
+ Expression message = assertStatement.getMessage();
+ assertTrue("No message expression", message != null); //$NON-NLS-1$
+ checkSourceRange(message, "(\"aa\"", source); //$NON-NLS-1$
+ assertTrue("Not flag as RECOVERED", (message.getFlags() & ASTNode.RECOVERED) != 0);
+ }
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=239117
+ public void test0018() throws JavaModelException {
+ this.workingCopies = new ICompilationUnit[0];
+
+ ASTResult result = this.buildMarkedAST(
+ "/Converter/src/p/X.java",
+ "package p;\n" +
+ "public class X {\n" +
+ " void m(Object var) {\n" +
+ " if (1==1 && var.equals(1)[*1*][*1*] {\n" +
+ " }\n" +
+ " }\n" +
+ "}");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "package p;\n" +
+ "public class X {\n" +
+ " void m( Object var){\n" +
+ " if (1 == 1 && var.equals(1)) [*1*];[*1*]\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "1:EMPTY_STATEMENT,[77,0],,RECOVERED,[N/A]\n" +
+ "===== Problems =====\n" +
+ "1. WARNING in /Converter/src/p/X.java (at line 4)\n" +
+ " if (1==1 && var.equals(1) {\n" +
+ " ^^^^\n" +
+ "Comparing identical expressions\n" +
+ "2. ERROR in /Converter/src/p/X.java (at line 4)\n" +
+ " if (1==1 && var.equals(1) {\n" +
+ " ^^^^^^\n" +
+ "The method equals(Object) in the type Object is not applicable for the arguments (int)\n" +
+ "3. ERROR in /Converter/src/p/X.java (at line 4)\n" +
+ " if (1==1 && var.equals(1) {\n" +
+ " ^\n" +
+ "Syntax error, insert \") Statement\" to complete BlockStatements\n",
+ result);
+ }
+}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest.java
new file mode 100644
index 0000000..c23f585
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest.java
@@ -0,0 +1,9928 @@
+/*******************************************************************************
+ * 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.jdt.core.tests.dom;
+
+import java.util.*;
+
+import junit.framework.Test;
+
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.core.runtime.preferences.InstanceScope;
+import org.eclipse.jdt.core.*;
+import org.eclipse.jdt.core.dom.*;
+import org.eclipse.jdt.core.jdom.*;
+import org.eclipse.jdt.core.util.IModifierConstants;
+
+public class ASTConverterTest extends ConverterTestSetup {
+
+ /** @deprecated using deprecated code */
+ public void setUpSuite() throws Exception {
+ super.setUpSuite();
+ this.ast = AST.newAST(AST.JLS2);
+ }
+
+ public ASTConverterTest(String name) {
+ super(name);
+ }
+
+ static {
+// TESTS_NUMBERS = new int[] { 305 };
+ }
+ public static Test suite() {
+ return buildModelTestSuite(ASTConverterTest.class);
+ }
+
+ /** @deprecated using deprecated code */
+ public void test0001() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0001", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+
+ // check that we have the right tree
+ CompilationUnit unit = this.ast.newCompilationUnit();
+ PackageDeclaration packageDeclaration = this.ast.newPackageDeclaration();
+ packageDeclaration.setName(this.ast.newSimpleName("test0001"));//$NON-NLS-1$
+ unit.setPackage(packageDeclaration);
+ ImportDeclaration importDeclaration = this.ast.newImportDeclaration();
+ QualifiedName name =
+ this.ast.newQualifiedName(
+ this.ast.newSimpleName("java"),//$NON-NLS-1$
+ this.ast.newSimpleName("util"));//$NON-NLS-1$
+ importDeclaration.setName(name);
+ importDeclaration.setOnDemand(true);
+ unit.imports().add(importDeclaration);
+ TypeDeclaration type = this.ast.newTypeDeclaration();
+ type.setInterface(false);
+ type.setModifiers(Modifier.PUBLIC);
+ type.setName(this.ast.newSimpleName("Test"));//$NON-NLS-1$
+ MethodDeclaration methodDeclaration = this.ast.newMethodDeclaration();
+ methodDeclaration.setConstructor(false);
+ methodDeclaration.setModifiers(Modifier.PUBLIC | Modifier.STATIC);
+ methodDeclaration.setName(this.ast.newSimpleName("main"));//$NON-NLS-1$
+ methodDeclaration.setReturnType(this.ast.newPrimitiveType(PrimitiveType.VOID));
+ SingleVariableDeclaration variableDeclaration = this.ast.newSingleVariableDeclaration();
+ variableDeclaration.setModifiers(Modifier.NONE);
+ variableDeclaration.setType(this.ast.newArrayType(this.ast.newSimpleType(this.ast.newSimpleName("String"))));//$NON-NLS-1$
+ variableDeclaration.setName(this.ast.newSimpleName("args"));//$NON-NLS-1$
+ methodDeclaration.parameters().add(variableDeclaration);
+ org.eclipse.jdt.core.dom.Block block = this.ast.newBlock();
+ MethodInvocation methodInvocation = this.ast.newMethodInvocation();
+ name =
+ this.ast.newQualifiedName(
+ this.ast.newSimpleName("System"),//$NON-NLS-1$
+ this.ast.newSimpleName("out"));//$NON-NLS-1$
+ methodInvocation.setExpression(name);
+ methodInvocation.setName(this.ast.newSimpleName("println")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setOperator(InfixExpression.Operator.PLUS);
+ StringLiteral literal = this.ast.newStringLiteral();
+ literal.setLiteralValue("Hello");//$NON-NLS-1$
+ infixExpression.setLeftOperand(literal);
+ literal = this.ast.newStringLiteral();
+ literal.setLiteralValue(" world");//$NON-NLS-1$
+ infixExpression.setRightOperand(literal);//$NON-NLS-1$
+ methodInvocation.arguments().add(infixExpression);
+ ExpressionStatement expressionStatement = this.ast.newExpressionStatement(methodInvocation);
+ block.statements().add(expressionStatement);
+ methodDeclaration.setBody(block);
+ type.bodyDeclarations().add(methodDeclaration);
+ unit.types().add(type);
+ assertTrue("Both AST trees should be identical", result.subtreeMatch(new ASTMatcher(), unit));//$NON-NLS-1$
+ String expected =
+ "package test0001;\n" +
+ "import java.util.*;\n" +
+ "public class Test {\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(\"Hello\" + \" world\");\n" +
+ " }\n" +
+ "}";
+ checkSourceRange(result, expected, source);
+ }
+
+ /**
+ * Test allocation expression: new Object() ==> ClassInstanceCreation
+ * @deprecated using deprecated code
+ */
+ public void test0002() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0002", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = this.ast.newClassInstanceCreation();
+ classInstanceCreation.setName(this.ast.newSimpleName("Object")); //$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", classInstanceCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "new Object()", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Test allocation expression: new java.lang.Object() ==> ClassInstanceCreation
+ * @deprecated using deprecated code
+ */
+ public void test0003() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0003", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = this.ast.newClassInstanceCreation();
+ QualifiedName name =
+ this.ast.newQualifiedName(
+ this.ast.newQualifiedName(
+ this.ast.newSimpleName("java"), //$NON-NLS-1$
+ this.ast.newSimpleName("lang")), //$NON-NLS-1$
+ this.ast.newSimpleName("Object"));//$NON-NLS-1$
+ classInstanceCreation.setName(name);
+ assertTrue("Both AST trees should be identical", classInstanceCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "new java.lang.Object()", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Test allocation expression: new java.lang.Exception("ERROR") ==> ClassInstanceCreation
+ * @deprecated using deprecated code
+ */
+ public void test0004() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0004", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = this.ast.newClassInstanceCreation();
+ QualifiedName name =
+ this.ast.newQualifiedName(
+ this.ast.newQualifiedName(
+ this.ast.newSimpleName("java"), //$NON-NLS-1$
+ this.ast.newSimpleName("lang")), //$NON-NLS-1$
+ this.ast.newSimpleName("Exception"));//$NON-NLS-1$
+ classInstanceCreation.setName(name);
+ StringLiteral literal = this.ast.newStringLiteral();
+ literal.setLiteralValue("ERROR"); //$NON-NLS-1$
+ classInstanceCreation.arguments().add(literal);
+ assertTrue("Both AST trees should be identical", classInstanceCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "new java.lang.Exception(\"ERROR\")", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Test allocation expression: new java.lang.Object() {} ==> ClassInstanceCreation
+ * @deprecated using deprecated code
+ */
+ public void test0005() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0005", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = this.ast.newClassInstanceCreation();
+ QualifiedName name =
+ this.ast.newQualifiedName(
+ this.ast.newQualifiedName(
+ this.ast.newSimpleName("java"), //$NON-NLS-1$
+ this.ast.newSimpleName("lang")), //$NON-NLS-1$
+ this.ast.newSimpleName("Object"));//$NON-NLS-1$
+ classInstanceCreation.setName(name);
+ AnonymousClassDeclaration anonymousClassDeclaration = this.ast.newAnonymousClassDeclaration();
+ classInstanceCreation.setAnonymousClassDeclaration(anonymousClassDeclaration);
+ assertTrue("Both AST trees should be identical", classInstanceCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "new java.lang.Object() {}", source); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation2 = (ClassInstanceCreation) expression;
+ Name name2 = classInstanceCreation2.getName();
+ checkSourceRange(name2, "java.lang.Object", source); //$NON-NLS-1$
+ }
+
+
+ /**
+ * Test allocation expression: new java.lang.Runnable() { public void run() {}} ==> ClassInstanceCreation
+ * @deprecated using deprecated code
+ */
+ public void test0006() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0006", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = this.ast.newClassInstanceCreation();
+ QualifiedName name =
+ this.ast.newQualifiedName(
+ this.ast.newQualifiedName(
+ this.ast.newSimpleName("java"), //$NON-NLS-1$
+ this.ast.newSimpleName("lang")), //$NON-NLS-1$
+ this.ast.newSimpleName("Runnable"));//$NON-NLS-1$
+ classInstanceCreation.setName(name);
+ MethodDeclaration methodDeclaration = this.ast.newMethodDeclaration();
+ methodDeclaration.setBody(this.ast.newBlock());
+ methodDeclaration.setConstructor(false);
+ methodDeclaration.setModifiers(Modifier.PUBLIC);
+ methodDeclaration.setName(this.ast.newSimpleName("run"));//$NON-NLS-1$
+ methodDeclaration.setReturnType(this.ast.newPrimitiveType(PrimitiveType.VOID));
+ AnonymousClassDeclaration anonymousClassDeclaration = this.ast.newAnonymousClassDeclaration();
+ anonymousClassDeclaration.bodyDeclarations().add(methodDeclaration);
+ classInstanceCreation.setAnonymousClassDeclaration(anonymousClassDeclaration);
+ assertTrue("Both AST trees should be identical", classInstanceCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "new java.lang.Runnable() { public void run() {}}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Test allocation expression: new Test().new D() ==> ClassInstanceCreation
+ * @deprecated using deprecated code
+ */
+ public void test0007() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0007", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ ASTNode expression = (ASTNode) ((MethodInvocation) expressionStatement.getExpression()).arguments().get(0);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = this.ast.newClassInstanceCreation();
+ classInstanceCreation.setName(this.ast.newSimpleName("D")); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreationExpression = this.ast.newClassInstanceCreation();
+ classInstanceCreationExpression.setName(this.ast.newSimpleName("Test")); //$NON-NLS-1$
+ classInstanceCreation.setExpression(classInstanceCreationExpression);
+ assertTrue("Both AST trees should be identical", classInstanceCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "new Test().new D()", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Test allocation expression: new int[] {1, 2, 3, 4} ==> ArrayCreation
+ */
+ public void test0008() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0008", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ ArrayCreation arrayCreation = this.ast.newArrayCreation();
+ arrayCreation.setType(this.ast.newArrayType(this.ast.newPrimitiveType(PrimitiveType.INT), 1));
+ ArrayInitializer arrayInitializer = this.ast.newArrayInitializer();
+ arrayInitializer.expressions().add(this.ast.newNumberLiteral("1"));//$NON-NLS-1$
+ arrayInitializer.expressions().add(this.ast.newNumberLiteral("2"));//$NON-NLS-1$
+ arrayInitializer.expressions().add(this.ast.newNumberLiteral("3"));//$NON-NLS-1$
+ arrayInitializer.expressions().add(this.ast.newNumberLiteral("4"));//$NON-NLS-1$
+ arrayCreation.setInitializer(arrayInitializer);
+ assertTrue("Both AST trees should be identical", arrayCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "new int[] {1, 2, 3, 4}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Test allocation expression: new int[][] {{1}, {2}} ==> ArrayCreation
+ */
+ public void test0009() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0009", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ ArrayCreation arrayCreation = this.ast.newArrayCreation();
+ arrayCreation.setType(this.ast.newArrayType(this.ast.newPrimitiveType(PrimitiveType.INT), 2));
+ ArrayInitializer arrayInitializer = this.ast.newArrayInitializer();
+ ArrayInitializer innerArrayInitializer = this.ast.newArrayInitializer();
+ innerArrayInitializer.expressions().add(this.ast.newNumberLiteral("1"));//$NON-NLS-1$
+ arrayInitializer.expressions().add(innerArrayInitializer);
+ innerArrayInitializer = this.ast.newArrayInitializer();
+ innerArrayInitializer.expressions().add(this.ast.newNumberLiteral("2"));//$NON-NLS-1$
+ arrayInitializer.expressions().add(innerArrayInitializer);
+ arrayCreation.setInitializer(arrayInitializer);
+ assertTrue("Both AST trees should be identical", arrayCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "new int[][] {{1}, {2}}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Test allocation expression: new int[3] ==> ArrayCreation
+ */
+ public void test0010() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0010", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ ArrayCreation arrayCreation = this.ast.newArrayCreation();
+ arrayCreation.setType(this.ast.newArrayType(this.ast.newPrimitiveType(PrimitiveType.INT), 1));
+ arrayCreation.dimensions().add(this.ast.newNumberLiteral("3")); //$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", arrayCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "new int[3]", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Test allocation expression: new int[3][] ==> ArrayCreation
+ */
+ public void test0011() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0011", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ ArrayCreation arrayCreation = this.ast.newArrayCreation();
+ arrayCreation.setType(this.ast.newArrayType(this.ast.newPrimitiveType(PrimitiveType.INT), 2));
+ arrayCreation.dimensions().add(this.ast.newNumberLiteral("3")); //$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", arrayCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "new int[3][]", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Test allocation expression: new int[][] {{},{}} ==> ArrayCreation
+ */
+ public void test0012() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0012", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ ArrayCreation arrayCreation = this.ast.newArrayCreation();
+ arrayCreation.setType(this.ast.newArrayType(this.ast.newPrimitiveType(PrimitiveType.INT), 2));
+ ArrayInitializer arrayInitializer = this.ast.newArrayInitializer();
+ ArrayInitializer innerArrayInitializer = this.ast.newArrayInitializer();
+ arrayInitializer.expressions().add(innerArrayInitializer);
+ innerArrayInitializer = this.ast.newArrayInitializer();
+ arrayInitializer.expressions().add(innerArrayInitializer);
+ arrayCreation.setInitializer(arrayInitializer);
+ assertTrue("Both AST trees should be identical", arrayCreation.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "new int[][] {{}, {}}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * int i; ==> VariableDeclarationFragment
+ * @deprecated using deprecated code
+ */
+ public void test0013() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0013", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int i;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * int i = 0; ==> VariableDeclarationFragment
+ * @deprecated using deprecated code
+ */
+ public void test0014() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0014", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(this.ast.newNumberLiteral("0"));//$NON-NLS-1$
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int i = 0;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i = 1; ==> ExpressionStatement(Assignment)
+ */
+ public void test0015() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0015", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Assignment assignment = this.ast.newAssignment();
+ assignment.setLeftHandSide(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ assignment.setRightHandSide(this.ast.newNumberLiteral("1")); //$NON-NLS-1$
+ assignment.setOperator(Assignment.Operator.ASSIGN);
+ ExpressionStatement statement = this.ast.newExpressionStatement(assignment);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i = 1;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i += 2; ==> ExpressionStatement(Assignment)
+ */
+ public void test0016() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0016", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Assignment assignment = this.ast.newAssignment();
+ assignment.setLeftHandSide(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$
+ assignment.setOperator(Assignment.Operator.PLUS_ASSIGN);
+ ExpressionStatement statement = this.ast.newExpressionStatement(assignment);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i += 2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i -= 2; ==> ExpressionStatement(Assignment)
+ */
+ public void test0017() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0017", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Assignment assignment = this.ast.newAssignment();
+ assignment.setLeftHandSide(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$
+ assignment.setOperator(Assignment.Operator.MINUS_ASSIGN);
+ ExpressionStatement statement = this.ast.newExpressionStatement(assignment);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i -= 2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i *= 2; ==> ExpressionStatement(Assignment)
+ */
+ public void test0018() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0018", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Assignment assignment = this.ast.newAssignment();
+ assignment.setLeftHandSide(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$
+ assignment.setOperator(Assignment.Operator.TIMES_ASSIGN);
+ ExpressionStatement statement = this.ast.newExpressionStatement(assignment);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i *= 2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i /= 2; ==> ExpressionStatement(Assignment)
+ */
+ public void test0019() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0019", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Assignment assignment = this.ast.newAssignment();
+ assignment.setLeftHandSide(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$
+ assignment.setOperator(Assignment.Operator.DIVIDE_ASSIGN);
+ ExpressionStatement statement = this.ast.newExpressionStatement(assignment);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i /= 2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i &= 2 ==> ExpressionStatement(Assignment)
+ */
+ public void test0020() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0020", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Assignment assignment = this.ast.newAssignment();
+ assignment.setLeftHandSide(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$
+ assignment.setOperator(Assignment.Operator.BIT_AND_ASSIGN);
+ ExpressionStatement statement = this.ast.newExpressionStatement(assignment);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i &= 2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i |= 2; ==> ExpressionStatement(Assignment)
+ */
+ public void test0021() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0021", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Assignment assignment = this.ast.newAssignment();
+ assignment.setLeftHandSide(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$
+ assignment.setOperator(Assignment.Operator.BIT_OR_ASSIGN);
+ ExpressionStatement statement = this.ast.newExpressionStatement(assignment);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i |= 2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i ^= 2; ==> ExpressionStatement(Assignment)
+ */
+ public void test0022() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0022", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Assignment assignment = this.ast.newAssignment();
+ assignment.setLeftHandSide(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$
+ assignment.setOperator(Assignment.Operator.BIT_XOR_ASSIGN);
+ ExpressionStatement statement = this.ast.newExpressionStatement(assignment);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i ^= 2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i %= 2; ==> ExpressionStatement(Assignment)
+ */
+ public void test0023() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0023", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Assignment assignment = this.ast.newAssignment();
+ assignment.setLeftHandSide(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$
+ assignment.setOperator(Assignment.Operator.REMAINDER_ASSIGN);
+ ExpressionStatement statement = this.ast.newExpressionStatement(assignment);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i %= 2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i <<= 2; ==> ExpressionStatement(Assignment)
+ */
+ public void test0024() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0024", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Assignment assignment = this.ast.newAssignment();
+ assignment.setLeftHandSide(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$
+ assignment.setOperator(Assignment.Operator.LEFT_SHIFT_ASSIGN);
+ ExpressionStatement statement = this.ast.newExpressionStatement(assignment);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i <<= 2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i >>= 2; ==> ExpressionStatement(Assignment)
+ */
+ public void test0025() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0025", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Assignment assignment = this.ast.newAssignment();
+ assignment.setLeftHandSide(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$
+ assignment.setOperator(Assignment.Operator.RIGHT_SHIFT_SIGNED_ASSIGN);
+ ExpressionStatement statement = this.ast.newExpressionStatement(assignment);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i >>= 2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i >>>= 2; ==> ExpressionStatement(Assignment)
+ */
+ public void test0026() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0026", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Assignment assignment = this.ast.newAssignment();
+ assignment.setLeftHandSide(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ assignment.setRightHandSide(this.ast.newNumberLiteral("2")); //$NON-NLS-1$
+ assignment.setOperator(Assignment.Operator.RIGHT_SHIFT_UNSIGNED_ASSIGN);
+ ExpressionStatement statement = this.ast.newExpressionStatement(assignment);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i >>>= 2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * --i; ==> ExpressionStatement(PrefixExpression)
+ */
+ public void test0027() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0027", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ PrefixExpression prefixExpression = this.ast.newPrefixExpression();
+ prefixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ prefixExpression.setOperator(PrefixExpression.Operator.DECREMENT);//$NON-NLS-1$
+ ExpressionStatement statement = this.ast.newExpressionStatement(prefixExpression);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "--i;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * --i; ==> ExpressionStatement(PrefixExpression)
+ */
+ public void test0028() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0028", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ PrefixExpression prefixExpression = this.ast.newPrefixExpression();
+ prefixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ prefixExpression.setOperator(PrefixExpression.Operator.INCREMENT);//$NON-NLS-1$
+ ExpressionStatement statement = this.ast.newExpressionStatement(prefixExpression);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "++i;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i--; ==> ExpressionStatement(PostfixExpression)
+ */
+ public void test0029() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0029", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ PostfixExpression postfixExpression = this.ast.newPostfixExpression();
+ postfixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ postfixExpression.setOperator(PostfixExpression.Operator.DECREMENT);//$NON-NLS-1$
+ ExpressionStatement statement = this.ast.newExpressionStatement(postfixExpression);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i--;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * i++; ==> ExpressionStatement(PostfixExpression)
+ */
+ public void test0030() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0030", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ PostfixExpression postfixExpression = this.ast.newPostfixExpression();
+ postfixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ postfixExpression.setOperator(PostfixExpression.Operator.INCREMENT);//$NON-NLS-1$
+ ExpressionStatement statement = this.ast.newExpressionStatement(postfixExpression);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "i++;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * (String) o; ==> ExpressionStatement(CastExpression)
+ * @deprecated using deprecated code
+ */
+ public void test0031() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0031", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("s")); //$NON-NLS-1$
+ CastExpression castExpression = this.ast.newCastExpression();
+ castExpression.setExpression(this.ast.newSimpleName("o"));//$NON-NLS-1$
+ castExpression.setType(this.ast.newSimpleType(this.ast.newSimpleName("String")));//$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(castExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newSimpleType(this.ast.newSimpleName("String")));//$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "String s = (String) o;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * (int) d; ==> ExpressionStatement(CastExpression)
+ * @deprecated using deprecated code
+ */
+ public void test0032() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0032", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ CastExpression castExpression = this.ast.newCastExpression();
+ castExpression.setExpression(this.ast.newSimpleName("d"));//$NON-NLS-1$
+ castExpression.setType(this.ast.newPrimitiveType(PrimitiveType.INT));//$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(castExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));//$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int i = (int) d;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * (float) d; ==> ExpressionStatement(CastExpression)
+ * @deprecated using deprecated code
+ */
+ public void test0033() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0033", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("f")); //$NON-NLS-1$
+ CastExpression castExpression = this.ast.newCastExpression();
+ castExpression.setExpression(this.ast.newSimpleName("d"));//$NON-NLS-1$
+ castExpression.setType(this.ast.newPrimitiveType(PrimitiveType.FLOAT));//$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(castExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.FLOAT));//$NON-NLS-1$
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "float f = (float) d;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * (byte) d; ==> ExpressionStatement(CastExpression)
+ * @deprecated using deprecated code
+ */
+ public void test0034() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0034", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("b")); //$NON-NLS-1$
+ CastExpression castExpression = this.ast.newCastExpression();
+ castExpression.setExpression(this.ast.newSimpleName("d"));//$NON-NLS-1$
+ castExpression.setType(this.ast.newPrimitiveType(PrimitiveType.BYTE));//$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(castExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.BYTE));//$NON-NLS-1$
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "byte b = (byte) d;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * (short) d; ==> ExpressionStatement(CastExpression)
+ * @deprecated using deprecated code
+ */
+ public void test0035() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0035", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("s")); //$NON-NLS-1$
+ CastExpression castExpression = this.ast.newCastExpression();
+ castExpression.setExpression(this.ast.newSimpleName("d"));//$NON-NLS-1$
+ castExpression.setType(this.ast.newPrimitiveType(PrimitiveType.SHORT));//$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(castExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.SHORT));//$NON-NLS-1$
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "short s = (short) d;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * (long) d; ==> ExpressionStatement(CastExpression)
+ * @deprecated using deprecated code
+ */
+ public void test0036() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0036", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("l")); //$NON-NLS-1$
+ CastExpression castExpression = this.ast.newCastExpression();
+ castExpression.setExpression(this.ast.newSimpleName("d"));//$NON-NLS-1$
+ castExpression.setType(this.ast.newPrimitiveType(PrimitiveType.LONG));//$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(castExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.LONG));//$NON-NLS-1$
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "long l = (long) d;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * (char) i; ==> ExpressionStatement(CastExpression)
+ * @deprecated using deprecated code
+ */
+ public void test0037() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0037", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("c")); //$NON-NLS-1$
+ CastExpression castExpression = this.ast.newCastExpression();
+ castExpression.setExpression(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ castExpression.setType(this.ast.newPrimitiveType(PrimitiveType.CHAR));//$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(castExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.CHAR));//$NON-NLS-1$
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "char c = (char) i;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * int.class; ==> ExpressionStatement(TypeLiteral)
+ * @deprecated using deprecated code
+ */
+ public void test0038() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0038", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("c")); //$NON-NLS-1$
+ TypeLiteral typeLiteral = this.ast.newTypeLiteral();
+ typeLiteral.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+ variableDeclarationFragment.setInitializer(typeLiteral);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newSimpleType(this.ast.newSimpleName("Class")));//$NON-NLS-1$
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(((VariableDeclarationFragment)((VariableDeclarationStatement)node).fragments().get(0)).getInitializer(), "int.class", source); //$NON-NLS-1$
+ }
+
+ /**
+ * void.class; ==> ExpressionStatement(TypeLiteral)
+ * @deprecated using deprecated code
+ */
+ public void test0039() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0039", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("c")); //$NON-NLS-1$
+ TypeLiteral typeLiteral = this.ast.newTypeLiteral();
+ typeLiteral.setType(this.ast.newPrimitiveType(PrimitiveType.VOID));
+ variableDeclarationFragment.setInitializer(typeLiteral);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newSimpleType(this.ast.newSimpleName("Class")));//$NON-NLS-1$
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(((VariableDeclarationFragment)((VariableDeclarationStatement)node).fragments().get(0)).getInitializer(), "void.class", source); //$NON-NLS-1$
+ }
+
+ /**
+ * double.class; ==> ExpressionStatement(TypeLiteral)
+ * @deprecated using deprecated code
+ */
+ public void test0040() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0040", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("c")); //$NON-NLS-1$
+ TypeLiteral typeLiteral = this.ast.newTypeLiteral();
+ typeLiteral.setType(this.ast.newPrimitiveType(PrimitiveType.DOUBLE));
+ variableDeclarationFragment.setInitializer(typeLiteral);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newSimpleType(this.ast.newSimpleName("Class")));//$NON-NLS-1$
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(((VariableDeclarationFragment)((VariableDeclarationStatement)node).fragments().get(0)).getInitializer(), "double.class", source); //$NON-NLS-1$
+ }
+
+ /**
+ * long.class; ==> ExpressionStatement(TypeLiteral)
+ * @deprecated using deprecated code
+ */
+ public void test0041() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0041", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("c")); //$NON-NLS-1$
+ TypeLiteral typeLiteral = this.ast.newTypeLiteral();
+ typeLiteral.setType(this.ast.newPrimitiveType(PrimitiveType.LONG));
+ variableDeclarationFragment.setInitializer(typeLiteral);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newSimpleType(this.ast.newSimpleName("Class")));//$NON-NLS-1$
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(((VariableDeclarationFragment)((VariableDeclarationStatement)node).fragments().get(0)).getInitializer(), "long.class", source); //$NON-NLS-1$
+ }
+
+ /**
+ * false ==> BooleanLiteral
+ */
+ public void test0042() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0042", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ BooleanLiteral literal = this.ast.newBooleanLiteral(false);
+ assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "false", source); //$NON-NLS-1$
+ }
+
+ /**
+ * true ==> BooleanLiteral
+ */
+ public void test0043() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0043", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ BooleanLiteral literal = this.ast.newBooleanLiteral(true);
+ assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "true", source); //$NON-NLS-1$
+ }
+
+ /**
+ * null ==> NullLiteral
+ */
+ public void test0044() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0044", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ NullLiteral literal = this.ast.newNullLiteral();
+ assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "null", source); //$NON-NLS-1$
+ }
+
+ /**
+ * CharLiteral ==> CharacterLiteral
+ */
+ public void test0045() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0045", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ CharacterLiteral literal = this.ast.newCharacterLiteral();
+ literal.setEscapedValue("'c'"); //$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "'c'", source); //$NON-NLS-1$
+ }
+
+ /**
+ * DoubleLiteral ==> NumberLiteral
+ */
+ public void test0046() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0046", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ NumberLiteral literal = this.ast.newNumberLiteral("1.00001");//$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "1.00001", source); //$NON-NLS-1$
+ }
+
+ /**
+ * FloatLiteral ==> NumberLiteral
+ */
+ public void test0047() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0047", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ NumberLiteral literal = this.ast.newNumberLiteral("1.00001f");//$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "1.00001f", source); //$NON-NLS-1$
+ }
+
+ /**
+ * IntLiteral ==> NumberLiteral
+ */
+ public void test0048() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0048", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ NumberLiteral literal = this.ast.newNumberLiteral("30000");//$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "30000", source); //$NON-NLS-1$
+ }
+
+ /**
+ * IntLiteralMinValue ==> NumberLiteral
+ */
+ public void test0049() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0049", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ NumberLiteral literal = this.ast.newNumberLiteral("-2147483648");//$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "-2147483648", source); //$NON-NLS-1$
+ }
+
+ /**
+ * LongLiteral ==> NumberLiteral
+ */
+ public void test0050() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0050", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ NumberLiteral literal = this.ast.newNumberLiteral("2147483648L");//$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "2147483648L", source); //$NON-NLS-1$
+ }
+
+ /**
+ * LongLiteral ==> NumberLiteral (negative value)
+ */
+ public void test0051() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0051", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ NumberLiteral literal = this.ast.newNumberLiteral("2147483648L");//$NON-NLS-1$
+ PrefixExpression prefixExpression = this.ast.newPrefixExpression();
+ prefixExpression.setOperand(literal);
+ prefixExpression.setOperator(PrefixExpression.Operator.MINUS);
+ assertTrue("Both AST trees should be identical", prefixExpression.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "-2147483648L", source); //$NON-NLS-1$
+ }
+
+ /**
+ * LongLiteralMinValue ==> NumberLiteral
+ */
+ public void test0052() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0052", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ NumberLiteral literal = this.ast.newNumberLiteral("-9223372036854775808L");//$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", literal.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "-9223372036854775808L", source); //$NON-NLS-1$
+ }
+
+ /**
+ * ExtendedStringLiteral ==> StringLiteral
+ */
+ public void test0053() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0053", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ /*
+ StringLiteral literal = this.ast.newStringLiteral();//$NON-NLS-1$
+ literal.setLiteralValue("Hello World");*/
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setOperator(InfixExpression.Operator.PLUS);
+ StringLiteral literal = this.ast.newStringLiteral();
+ literal.setLiteralValue("Hello");//$NON-NLS-1$
+ infixExpression.setLeftOperand(literal);
+ literal = this.ast.newStringLiteral();
+ literal.setLiteralValue(" World");//$NON-NLS-1$
+ infixExpression.setRightOperand(literal);//$NON-NLS-1$
+
+ assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "\"Hello\" + \" World\"", source); //$NON-NLS-1$
+ }
+
+ /**
+ * AND_AND_Expression ==> InfixExpression
+ * @deprecated using deprecated code
+ */
+ public void test0054() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0054", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("b3")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("b")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("b2")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.CONDITIONAL_AND);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "boolean b3 = b && b2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * OR_OR_Expression ==> InfixExpression
+ * @deprecated using deprecated code
+ */
+ public void test0055() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0055", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("b3")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("b")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("b2")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.CONDITIONAL_OR);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "boolean b3 = b || b2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * EqualExpression ==> InfixExpression
+ * @deprecated using deprecated code
+ */
+ public void test0056() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0056", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("b3")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("b")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("b2")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.EQUALS);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "boolean b3 = b == b2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression (+) ==> InfixExpression
+ * @deprecated using deprecated code
+ */
+ public void test0057() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0057", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("n")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("j")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.PLUS);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int n = i + j;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression (-) ==> InfixExpression
+ * @deprecated using deprecated code
+ */
+ public void test0058() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0058", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("n")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("j")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.MINUS);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int n = i - j;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression (*) ==> InfixExpression
+ * @deprecated using deprecated code
+ */
+ public void test0059() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0059", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("n")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("j")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.TIMES);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int n = i * j;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression (/) ==> InfixExpression
+ * @deprecated using deprecated code
+ */
+ public void test0060() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0060", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("n")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("j")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.DIVIDE);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int n = i / j;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression (%) ==> InfixExpression
+ * @deprecated using deprecated code
+ */
+ public void test0061() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0061", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("n")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("j")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.REMAINDER);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int n = i % j;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression (^) ==> InfixExpression
+ * @deprecated using deprecated code
+ */
+ public void test0062() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0062", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("n")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("j")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.XOR);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int n = i ^ j;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression (&) ==> InfixExpression
+ * @deprecated using deprecated code
+ */
+ public void test0063() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0063", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("n")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("j")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.AND);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int n = i & j;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression (|) ==> InfixExpression
+ * @deprecated using deprecated code
+ */
+ public void test0064() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0064", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("n")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("j")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.OR);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int n = i | j;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression (<) ==> InfixExpression
+ * @deprecated using deprecated code
+ */
+ public void test0065() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0065", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("b2")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("b")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("b1")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.LESS);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "boolean b2 = b < b1;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression (<=) ==> InfixExpression
+ * @deprecated using deprecated code
+ */
+ public void test0066() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0066", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("b2")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("b")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("b1")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.LESS_EQUALS);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "boolean b2 = b <= b1;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression (>) ==> InfixExpression
+ * @deprecated using deprecated code
+ */
+ public void test0067() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0067", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("b2")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("b")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("b1")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.GREATER);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "boolean b2 = b > b1;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression (>=) ==> InfixExpression
+ * @deprecated using deprecated code
+ */
+ public void test0068() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0068", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("b2")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("b")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("b1")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.GREATER_EQUALS);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "boolean b2 = b >= b1;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression (!=) ==> InfixExpression
+ * @deprecated using deprecated code
+ */
+ public void test0069() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0069", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("b2")); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("b")); //$NON-NLS-1$
+ infixExpression.setRightOperand(this.ast.newSimpleName("b1")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.NOT_EQUALS);
+ variableDeclarationFragment.setInitializer(infixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "boolean b2 = b != b1;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * InstanceofExpression ==> InfixExpression
+ * @deprecated using deprecated code
+ */
+ public void test0070() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0070", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("b")); //$NON-NLS-1$
+ InstanceofExpression instanceOfExpression = this.ast.newInstanceofExpression();
+ instanceOfExpression.setLeftOperand(this.ast.newSimpleName("o"));//$NON-NLS-1$
+ SimpleType simpleType = this.ast.newSimpleType(this.ast.newSimpleName("Integer"));//$NON-NLS-1$
+ instanceOfExpression.setRightOperand(simpleType);
+ variableDeclarationFragment.setInitializer(instanceOfExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "boolean b = o instanceof Integer;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * InstanceofExpression ==> InfixExpression
+ * @deprecated using deprecated code
+ */
+ public void test0071() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0071", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("b")); //$NON-NLS-1$
+ InstanceofExpression instanceOfExpression = this.ast.newInstanceofExpression();
+ instanceOfExpression.setLeftOperand(this.ast.newSimpleName("o")); //$NON-NLS-1$
+ QualifiedName name =
+ this.ast.newQualifiedName(
+ this.ast.newQualifiedName(
+ this.ast.newSimpleName("java"), //$NON-NLS-1$
+ this.ast.newSimpleName("lang")), //$NON-NLS-1$
+ this.ast.newSimpleName("Integer")); //$NON-NLS-1$
+ Type type = this.ast.newSimpleType(name);
+ instanceOfExpression.setRightOperand(type);
+ variableDeclarationFragment.setInitializer(instanceOfExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "boolean b = o instanceof java.lang.Integer;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * UnaryExpression (!) ==> PrefixExpression
+ * @deprecated using deprecated code
+ */
+ public void test0072() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0072", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("b1")); //$NON-NLS-1$
+ PrefixExpression prefixExpression = this.ast.newPrefixExpression();
+ prefixExpression.setOperator(PrefixExpression.Operator.NOT);
+ prefixExpression.setOperand(this.ast.newSimpleName("b"));//$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(prefixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "boolean b1 = !b;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * UnaryExpression (~) ==> PrefixExpression
+ * @deprecated using deprecated code
+ */
+ public void test0073() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0073", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("n")); //$NON-NLS-1$
+ PrefixExpression prefixExpression = this.ast.newPrefixExpression();
+ prefixExpression.setOperator(PrefixExpression.Operator.COMPLEMENT);
+ prefixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(prefixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int n = ~i;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * UnaryExpression (+) ==> PrefixExpression
+ * @deprecated using deprecated code
+ */
+ public void test0074() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0074", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ PrefixExpression prefixExpression = this.ast.newPrefixExpression();
+ prefixExpression.setOperator(PrefixExpression.Operator.PLUS);
+ prefixExpression.setOperand(this.ast.newNumberLiteral("2"));//$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(prefixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int i = +2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * UnaryExpression (-) ==> PrefixExpression
+ * @deprecated using deprecated code
+ */
+ public void test0075() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0075", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ PrefixExpression prefixExpression = this.ast.newPrefixExpression();
+ prefixExpression.setOperator(PrefixExpression.Operator.MINUS);
+ prefixExpression.setOperand(this.ast.newNumberLiteral("2"));//$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(prefixExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int i = -2;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * ConditionalExpression ==> ConditionalExpression
+ * @deprecated using deprecated code
+ */
+ public void test0076() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0076", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("b")); //$NON-NLS-1$
+ ConditionalExpression conditionalExpression = this.ast.newConditionalExpression();
+ InfixExpression condition = this.ast.newInfixExpression();
+ condition.setLeftOperand(this.ast.newSimpleName("args")); //$NON-NLS-1$
+ condition.setRightOperand(this.ast.newNullLiteral()); //$NON-NLS-1$
+ condition.setOperator(InfixExpression.Operator.NOT_EQUALS);
+ conditionalExpression.setExpression(condition);
+ conditionalExpression.setThenExpression(this.ast.newBooleanLiteral(true));
+ conditionalExpression.setElseExpression(this.ast.newBooleanLiteral(false));
+ variableDeclarationFragment.setInitializer(conditionalExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.BOOLEAN));
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "boolean b = args != null ? true : false;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * ConditionalExpression ==> ConditionalExpression
+ * @deprecated using deprecated code
+ */
+ public void test0077() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0077", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ ConditionalExpression conditionalExpression = this.ast.newConditionalExpression();
+ conditionalExpression.setExpression(this.ast.newBooleanLiteral(true));
+ QualifiedName name =
+ this.ast.newQualifiedName(
+ this.ast.newSimpleName("args"), //$NON-NLS-1$
+ this.ast.newSimpleName("length")); //$NON-NLS-1$
+ conditionalExpression.setThenExpression(name);
+ conditionalExpression.setElseExpression(this.ast.newNumberLiteral("0"));//$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(conditionalExpression);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setModifiers(Modifier.NONE);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int i = true ? args.length: 0;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * MessageSend ==> SuperMethodInvocation
+ */
+ public void test0078() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0078", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ SuperMethodInvocation superMethodInvocation = this.ast.newSuperMethodInvocation();
+ superMethodInvocation.setName(this.ast.newSimpleName("bar")); //$NON-NLS-1$
+ ExpressionStatement statement = this.ast.newExpressionStatement(superMethodInvocation);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "super.bar();", source); //$NON-NLS-1$
+ }
+
+ /**
+ * MessageSend ==> SuperMethodInvocation
+ */
+ public void test0079() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0079", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ SuperMethodInvocation superMethodInvocation = this.ast.newSuperMethodInvocation();
+ superMethodInvocation.setName(this.ast.newSimpleName("bar")); //$NON-NLS-1$
+ superMethodInvocation.arguments().add(this.ast.newNumberLiteral("4"));//$NON-NLS-1$
+ ExpressionStatement statement = this.ast.newExpressionStatement(superMethodInvocation);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "super.bar(4);", source); //$NON-NLS-1$
+ }
+
+ /**
+ * MessageSend ==> MethodInvocation
+ */
+ public void test0080() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0080", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ MethodInvocation methodInvocation = this.ast.newMethodInvocation();
+ methodInvocation.setName(this.ast.newSimpleName("bar")); //$NON-NLS-1$
+ methodInvocation.arguments().add(this.ast.newNumberLiteral("4"));//$NON-NLS-1$
+ ExpressionStatement statement = this.ast.newExpressionStatement(methodInvocation);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "bar(4);", source); //$NON-NLS-1$
+ }
+
+ /**
+ * MessageSend ==> MethodInvocation
+ */
+ public void test0081() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0081", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ MethodInvocation methodInvocation = this.ast.newMethodInvocation();
+ methodInvocation.setName(this.ast.newSimpleName("bar")); //$NON-NLS-1$
+ methodInvocation.setExpression(this.ast.newThisExpression());
+ methodInvocation.arguments().add(this.ast.newNumberLiteral("4"));//$NON-NLS-1$
+ ExpressionStatement statement = this.ast.newExpressionStatement(methodInvocation);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "this.bar(4);", source); //$NON-NLS-1$
+ }
+
+ /**
+ * ForStatement ==> ForStatement
+ */
+ public void test0082() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0082", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ForStatement forStatement = this.ast.newForStatement();
+ forStatement.setBody(this.ast.newEmptyStatement());
+ assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "for (;;);", source); //$NON-NLS-1$
+ }
+
+ /**
+ * ForStatement ==> ForStatement
+ * @deprecated using deprecated code
+ */
+ public void test0083() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0083", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ForStatement forStatement = this.ast.newForStatement();
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(this.ast.newNumberLiteral("0"));//$NON-NLS-1$
+ VariableDeclarationExpression variableDeclarationExpression = this.ast.newVariableDeclarationExpression(variableDeclarationFragment);
+ variableDeclarationExpression.setModifiers(Modifier.NONE);
+ variableDeclarationExpression.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+ forStatement.initializers().add(variableDeclarationExpression);
+ PostfixExpression postfixExpression = this.ast.newPostfixExpression();
+ postfixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ postfixExpression.setOperator(PostfixExpression.Operator.INCREMENT);
+ forStatement.updaters().add(postfixExpression);
+ forStatement.setBody(this.ast.newBlock());
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.LESS);
+ infixExpression.setRightOperand(this.ast.newNumberLiteral("10")); //$NON-NLS-1$
+ forStatement.setExpression(infixExpression);
+ assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "for (int i = 0; i < 10; i++) {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * ForStatement ==> ForStatement
+ * @deprecated using deprecated code
+ */
+ public void test0084() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0084", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ForStatement forStatement = this.ast.newForStatement();
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(this.ast.newNumberLiteral("0"));//$NON-NLS-1$
+
+ VariableDeclarationExpression variableDeclarationExpression = this.ast.newVariableDeclarationExpression(variableDeclarationFragment);
+ variableDeclarationExpression.setModifiers(Modifier.NONE);
+ variableDeclarationExpression.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ forStatement.initializers().add(variableDeclarationExpression);
+ PostfixExpression postfixExpression = this.ast.newPostfixExpression();
+ postfixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ postfixExpression.setOperator(PostfixExpression.Operator.INCREMENT);
+ forStatement.updaters().add(postfixExpression);
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.LESS);
+ infixExpression.setRightOperand(this.ast.newNumberLiteral("10")); //$NON-NLS-1$
+ forStatement.setExpression(infixExpression);
+ forStatement.setBody(this.ast.newEmptyStatement());
+ assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "for (int i = 0; i < 10; i++);", source); //$NON-NLS-1$
+ }
+
+ /**
+ * ForStatement ==> ForStatement
+ * @deprecated using deprecated code
+ */
+ public void test0085() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0085", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ForStatement forStatement = this.ast.newForStatement();
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(this.ast.newNumberLiteral("0"));//$NON-NLS-1$
+
+ VariableDeclarationExpression variableDeclarationExpression = this.ast.newVariableDeclarationExpression(variableDeclarationFragment);
+ variableDeclarationExpression.setModifiers(Modifier.NONE);
+ variableDeclarationExpression.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+
+ forStatement.initializers().add(variableDeclarationExpression);
+ PostfixExpression postfixExpression = this.ast.newPostfixExpression();
+ postfixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ postfixExpression.setOperator(PostfixExpression.Operator.INCREMENT);
+ forStatement.updaters().add(postfixExpression);
+ forStatement.setBody(this.ast.newEmptyStatement());
+ assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "for (int i = 0;; i++);", source); //$NON-NLS-1$
+ }
+
+ /**
+ * ForStatement ==> ForStatement
+ */
+ public void test0086() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0086", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ForStatement forStatement = this.ast.newForStatement();
+ PostfixExpression postfixExpression = this.ast.newPostfixExpression();
+ postfixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ postfixExpression.setOperator(PostfixExpression.Operator.INCREMENT);
+ forStatement.updaters().add(postfixExpression);
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.LESS);
+ infixExpression.setRightOperand(this.ast.newNumberLiteral("10")); //$NON-NLS-1$
+ forStatement.setExpression(infixExpression);
+ forStatement.setBody(this.ast.newEmptyStatement());
+ assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "for (; i < 10; i++);", source); //$NON-NLS-1$
+ }
+
+ /**
+ * ForStatement ==> ForStatement
+ */
+ public void test0087() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0087", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ForStatement forStatement = this.ast.newForStatement();
+ PostfixExpression postfixExpression = this.ast.newPostfixExpression();
+ postfixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ postfixExpression.setOperator(PostfixExpression.Operator.INCREMENT);
+ forStatement.updaters().add(postfixExpression);
+ forStatement.setBody(this.ast.newEmptyStatement());
+ assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "for (;;i++);", source); //$NON-NLS-1$
+ }
+
+ /**
+ * LocalDeclaration ==> VariableDeclarationStatement
+ * @deprecated using deprecated code
+ */
+ public void test0088() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0088", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+ statement.setModifiers(Modifier.NONE);
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int i;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * LocalDeclaration ==> VariableDeclarationStatement
+ * @deprecated using deprecated code
+ */
+ public void test0089() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0089", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("s")); //$NON-NLS-1$
+
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ QualifiedName name =
+ this.ast.newQualifiedName(
+ this.ast.newQualifiedName(
+ this.ast.newSimpleName("java"),//$NON-NLS-1$
+ this.ast.newSimpleName("lang")//$NON-NLS-1$
+ ),
+ this.ast.newSimpleName("String") //$NON-NLS-1$
+ );
+ statement.setType(this.ast.newSimpleType(name));
+ statement.setModifiers(Modifier.NONE);
+
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "java.lang.String s;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * LocalDeclaration ==> VariableDeclarationStatement
+ * @deprecated using deprecated code
+ */
+ public void test0090() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0090", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ ArrayInitializer initializer = this.ast.newArrayInitializer();
+ initializer.expressions().add(this.ast.newNumberLiteral("1"));//$NON-NLS-1$
+ initializer.expressions().add(this.ast.newNumberLiteral("2"));//$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(initializer);
+ variableDeclarationFragment.setName(this.ast.newSimpleName("tab")); //$NON-NLS-1$
+
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(variableDeclarationFragment);
+ statement.setType(this.ast.newArrayType(this.ast.newPrimitiveType(PrimitiveType.INT), 1));
+ statement.setModifiers(Modifier.NONE);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int[] tab = {1, 2};", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Argument ==> SingleVariableDeclaration
+ * @deprecated using deprecated code
+ */
+ public void test0091() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0091", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ MethodDeclaration method = (MethodDeclaration)((TypeDeclaration) ((CompilationUnit) result).types().get(0)).bodyDeclarations().get(0);
+ SingleVariableDeclaration node = (SingleVariableDeclaration) method.parameters().get(0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ SingleVariableDeclaration variableDeclaration = this.ast.newSingleVariableDeclaration();
+ variableDeclaration.setModifiers(Modifier.NONE);
+ variableDeclaration.setType(this.ast.newSimpleType(this.ast.newSimpleName("String")));//$NON-NLS-1$
+ variableDeclaration.setName(this.ast.newSimpleName("s")); //$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", variableDeclaration.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "String s", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Argument ==> SingleVariableDeclaration
+ * @deprecated using deprecated code
+ */
+ public void test0092() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0092", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ MethodDeclaration method = (MethodDeclaration)((TypeDeclaration) ((CompilationUnit) result).types().get(0)).bodyDeclarations().get(0);
+ SingleVariableDeclaration node = (SingleVariableDeclaration) method.parameters().get(0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ SingleVariableDeclaration variableDeclaration = this.ast.newSingleVariableDeclaration();
+ variableDeclaration.setModifiers(Modifier.FINAL);
+ variableDeclaration.setType(this.ast.newSimpleType(this.ast.newSimpleName("String")));//$NON-NLS-1$
+ variableDeclaration.setName(this.ast.newSimpleName("s")); //$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", variableDeclaration.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "final String s", source); //$NON-NLS-1$
+ assertEquals("Wrong dimension", 0, node.getExtraDimensions()); //$NON-NLS-1$
+ }
+
+ /**
+ * Break ==> BreakStatement
+ */
+ public void test0093() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0093", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ ForStatement forStatement = (ForStatement) node;
+ BreakStatement statement = (BreakStatement) ((Block) forStatement.getBody()).statements().get(0);
+ assertNotNull("Expression should not be null", statement); //$NON-NLS-1$
+ BreakStatement breakStatement = this.ast.newBreakStatement();
+ assertTrue("Both AST trees should be identical", breakStatement.subtreeMatch(new ASTMatcher(), statement)); //$NON-NLS-1$
+ checkSourceRange(statement, "break;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Continue ==> ContinueStatement
+ */
+ public void test0094() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0094", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ ForStatement forStatement = (ForStatement) node;
+ ContinueStatement statement = (ContinueStatement) ((Block) forStatement.getBody()).statements().get(0);
+ assertNotNull("Expression should not be null", statement); //$NON-NLS-1$
+ ContinueStatement continueStatement = this.ast.newContinueStatement();
+ assertTrue("Both AST trees should be identical", continueStatement.subtreeMatch(new ASTMatcher(), statement)); //$NON-NLS-1$
+ checkSourceRange(statement, "continue;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Continue with Label ==> ContinueStatement
+ */
+ public void test0095() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0095", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ LabeledStatement labeledStatement = (LabeledStatement) getASTNode((CompilationUnit) result, 0, 0, 0);
+ ForStatement forStatement = (ForStatement) labeledStatement.getBody();
+ ContinueStatement statement = (ContinueStatement) ((Block) forStatement.getBody()).statements().get(0);
+ assertNotNull("Expression should not be null", statement); //$NON-NLS-1$
+ ContinueStatement continueStatement = this.ast.newContinueStatement();
+ continueStatement.setLabel(this.ast.newSimpleName("label")); //$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", continueStatement.subtreeMatch(new ASTMatcher(), statement)); //$NON-NLS-1$
+ checkSourceRange(statement, "continue label;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Break + label ==> BreakStatement
+ */
+ public void test0096() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0096", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ LabeledStatement labeledStatement = (LabeledStatement) getASTNode((CompilationUnit) result, 0, 0, 0);
+ ForStatement forStatement = (ForStatement) labeledStatement.getBody();
+ BreakStatement statement = (BreakStatement) ((Block) forStatement.getBody()).statements().get(0);
+ assertNotNull("Expression should not be null", statement); //$NON-NLS-1$
+ BreakStatement breakStatement = this.ast.newBreakStatement();
+ breakStatement.setLabel(this.ast.newSimpleName("label")); //$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", breakStatement.subtreeMatch(new ASTMatcher(), statement)); //$NON-NLS-1$
+ checkSourceRange(statement, "break label;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * SwitchStatement ==> SwitchStatement
+ */
+ public void test0097() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0097", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ SwitchStatement switchStatement = this.ast.newSwitchStatement();
+ switchStatement.setExpression(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ SwitchCase _case = this.ast.newSwitchCase();
+ _case.setExpression(this.ast.newNumberLiteral("1"));//$NON-NLS-1$
+ switchStatement.statements().add(_case);
+ switchStatement.statements().add(this.ast.newBreakStatement());
+ _case = this.ast.newSwitchCase();
+ _case.setExpression(this.ast.newNumberLiteral("2"));//$NON-NLS-1$
+ switchStatement.statements().add(_case);
+ MethodInvocation methodInvocation = this.ast.newMethodInvocation();
+ QualifiedName name =
+ this.ast.newQualifiedName(
+ this.ast.newSimpleName("System"),//$NON-NLS-1$
+ this.ast.newSimpleName("out"));//$NON-NLS-1$
+ methodInvocation.setExpression(name);
+ methodInvocation.setName(this.ast.newSimpleName("println")); //$NON-NLS-1$
+ methodInvocation.arguments().add(this.ast.newNumberLiteral("2"));//$NON-NLS-1$
+ ExpressionStatement expressionStatement = this.ast.newExpressionStatement(methodInvocation);
+ switchStatement.statements().add(expressionStatement);
+ switchStatement.statements().add(this.ast.newBreakStatement());
+ _case = this.ast.newSwitchCase();
+ _case.setExpression(null);
+ switchStatement.statements().add(_case);
+ methodInvocation = this.ast.newMethodInvocation();
+ name =
+ this.ast.newQualifiedName(
+ this.ast.newSimpleName("System"),//$NON-NLS-1$
+ this.ast.newSimpleName("out"));//$NON-NLS-1$
+ methodInvocation.setExpression(name);
+ methodInvocation.setName(this.ast.newSimpleName("println")); //$NON-NLS-1$
+ StringLiteral literal = this.ast.newStringLiteral();
+ literal.setLiteralValue("default"); //$NON-NLS-1$
+ methodInvocation.arguments().add(literal);
+ expressionStatement = this.ast.newExpressionStatement(methodInvocation);
+ switchStatement.statements().add(expressionStatement);
+ assertTrue("Both AST trees should be identical", switchStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ String expectedSource = "switch(i) {\n" +//$NON-NLS-1$
+ " case 1: \n" +//$NON-NLS-1$
+ " break;\n" +//$NON-NLS-1$
+ " case 2:\n" +//$NON-NLS-1$
+ " System.out.println(2);\n" +//$NON-NLS-1$
+ " break;\n" +//$NON-NLS-1$
+ " default:\n" +//$NON-NLS-1$
+ " System.out.println(\"default\");\n" +//$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(node, expectedSource, source);
+ SwitchStatement switchStatement2 = (SwitchStatement) node;
+ List statements = switchStatement2.statements();
+ assertEquals("wrong size", 7, statements.size()); //$NON-NLS-1$
+ Statement stmt = (Statement) statements.get(5);
+ assertTrue("Not a case statement", stmt instanceof SwitchCase); //$NON-NLS-1$
+ SwitchCase switchCase = (SwitchCase) stmt;
+ assertTrue("Not the default case", switchCase.isDefault()); //$NON-NLS-1$
+ }
+
+ /**
+ * EmptyStatement ==> EmptyStatement
+ */
+ public void test0098() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0098", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ EmptyStatement emptyStatement = this.ast.newEmptyStatement();
+ assertTrue("Both AST trees should be identical", emptyStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, ";", source); //$NON-NLS-1$
+ }
+
+ /**
+ * DoStatement ==> DoStatement
+ */
+ public void test0099() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0099", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ DoStatement doStatement = this.ast.newDoStatement();
+ Block block = this.ast.newBlock();
+ block.statements().add(this.ast.newEmptyStatement());
+ doStatement.setBody(block);
+ doStatement.setExpression(this.ast.newBooleanLiteral(true));
+ assertTrue("Both AST trees should be identical", doStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ String expectedSource = "do {;\n" +//$NON-NLS-1$
+ " } while(true);";//$NON-NLS-1$
+ checkSourceRange(node, expectedSource, source);
+ }
+
+ /**
+ * WhileStatement ==> WhileStatement
+ */
+ public void test0100() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0100", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ WhileStatement whileStatement = this.ast.newWhileStatement();
+ whileStatement.setExpression(this.ast.newBooleanLiteral(true));
+ whileStatement.setBody(this.ast.newEmptyStatement());
+ assertTrue("Both AST trees should be identical", whileStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "while(true);", source);//$NON-NLS-1$
+ }
+
+ /**
+ * WhileStatement ==> WhileStatement
+ */
+ public void test0101() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0101", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ WhileStatement whileStatement = this.ast.newWhileStatement();
+ whileStatement.setExpression(this.ast.newBooleanLiteral(true));
+ whileStatement.setBody(this.ast.newBlock());
+ assertTrue("Both AST trees should be identical", whileStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "while(true) {}", source);//$NON-NLS-1$
+ }
+
+ /**
+ * ExtendedStringLiteral ==> StringLiteral
+ */
+ public void test0102() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0102", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setOperator(InfixExpression.Operator.PLUS);
+ StringLiteral literal = this.ast.newStringLiteral();//$NON-NLS-1$
+ literal.setLiteralValue("Hello"); //$NON-NLS-1$
+ infixExpression.setLeftOperand(literal);
+ literal = this.ast.newStringLiteral();//$NON-NLS-1$
+ literal.setLiteralValue(" World"); //$NON-NLS-1$
+ infixExpression.setRightOperand(literal);
+ literal = this.ast.newStringLiteral();//$NON-NLS-1$
+ literal.setLiteralValue("!"); //$NON-NLS-1$
+ infixExpression.extendedOperands().add(literal);
+ assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "\"Hello\" + \" World\" + \"!\"", source);//$NON-NLS-1$
+ }
+
+ /**
+ * ExtendedStringLiteral ==> StringLiteral
+ */
+ public void test0103() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0103", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setOperator(InfixExpression.Operator.PLUS);
+ StringLiteral literal = this.ast.newStringLiteral();//$NON-NLS-1$
+ literal.setLiteralValue("Hello"); //$NON-NLS-1$
+ infixExpression.setLeftOperand(literal);
+ literal = this.ast.newStringLiteral();//$NON-NLS-1$
+ literal.setLiteralValue(" World"); //$NON-NLS-1$
+ infixExpression.setRightOperand(literal);
+ literal = this.ast.newStringLiteral();//$NON-NLS-1$
+ literal.setLiteralValue("!"); //$NON-NLS-1$
+ infixExpression.extendedOperands().add(literal);
+ literal = this.ast.newStringLiteral();//$NON-NLS-1$
+ literal.setLiteralValue("!"); //$NON-NLS-1$
+ infixExpression.extendedOperands().add(literal);
+ assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "\"Hello\" + \" World\" + \"!\" + \"!\"", source);//$NON-NLS-1$
+ }
+
+ /**
+ * ExtendedStringLiteral ==> StringLiteral
+ */
+ public void test0104() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0104", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setOperator(InfixExpression.Operator.PLUS);
+ StringLiteral literal = this.ast.newStringLiteral();//$NON-NLS-1$
+ literal.setLiteralValue("Hello"); //$NON-NLS-1$
+ infixExpression.setLeftOperand(literal);
+ literal = this.ast.newStringLiteral();//$NON-NLS-1$
+ literal.setLiteralValue(" World"); //$NON-NLS-1$
+ infixExpression.setRightOperand(literal);
+ literal = this.ast.newStringLiteral();//$NON-NLS-1$
+ literal.setLiteralValue("!"); //$NON-NLS-1$
+ infixExpression.extendedOperands().add(literal);
+ NumberLiteral numberLiteral = this.ast.newNumberLiteral();//$NON-NLS-1$
+ numberLiteral.setToken("4"); //$NON-NLS-1$
+ infixExpression.extendedOperands().add(numberLiteral);
+ assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "\"Hello\" + \" World\" + \"!\" + 4", source);//$NON-NLS-1$
+ }
+
+ /**
+ * NumberLiteral ==> InfixExpression
+ */
+ public void test0105() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0105", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setOperator(InfixExpression.Operator.PLUS);
+ NumberLiteral literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("4"); //$NON-NLS-1$
+ infixExpression.setLeftOperand(literal);
+ literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("5"); //$NON-NLS-1$
+ infixExpression.setRightOperand(literal);
+ literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("6"); //$NON-NLS-1$
+ infixExpression.extendedOperands().add(literal);
+ literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("4"); //$NON-NLS-1$
+ infixExpression.extendedOperands().add(literal);
+ assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "4 + 5 + 6 + 4", source);//$NON-NLS-1$
+ }
+
+ /**
+ * NumberLiteral ==> InfixExpression
+ */
+ public void test0106() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0106", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setOperator(InfixExpression.Operator.MINUS);
+ NumberLiteral literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("4"); //$NON-NLS-1$
+ infixExpression.setLeftOperand(literal);
+ literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("5"); //$NON-NLS-1$
+ infixExpression.setRightOperand(literal);
+
+ InfixExpression infixExpression2 = this.ast.newInfixExpression();
+ infixExpression2.setOperator(InfixExpression.Operator.PLUS);
+ infixExpression2.setLeftOperand(infixExpression);
+ literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("6"); //$NON-NLS-1$
+ infixExpression2.setRightOperand(literal);
+
+ InfixExpression infixExpression3 = this.ast.newInfixExpression();
+ infixExpression3.setOperator(InfixExpression.Operator.PLUS);
+ infixExpression3.setLeftOperand(infixExpression2);
+ literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("4"); //$NON-NLS-1$
+ infixExpression3.setRightOperand(literal);
+
+ assertTrue("Both AST trees should be identical", infixExpression3.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "4 - 5 + 6 + 4", source);//$NON-NLS-1$
+ }
+
+ /**
+ * NumberLiteral ==> InfixExpression
+ */
+ public void test0107() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0107", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setOperator(InfixExpression.Operator.MINUS);
+ NumberLiteral literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("4"); //$NON-NLS-1$
+ infixExpression.setLeftOperand(literal);
+ literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("5"); //$NON-NLS-1$
+ infixExpression.setRightOperand(literal);
+ literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("6"); //$NON-NLS-1$
+ infixExpression.extendedOperands().add(literal);
+ literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("4"); //$NON-NLS-1$
+ infixExpression.extendedOperands().add(literal);
+ assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "4 - 5 - 6 - 4", source);//$NON-NLS-1$
+ }
+
+ /**
+ * NumberLiteral ==> InfixExpression
+ */
+ public void test0108() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0108", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setOperator(InfixExpression.Operator.PLUS);
+ StringLiteral stringLiteral = this.ast.newStringLiteral();//$NON-NLS-1$
+ stringLiteral.setLiteralValue("4"); //$NON-NLS-1$
+ infixExpression.setLeftOperand(stringLiteral);
+ NumberLiteral literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("5"); //$NON-NLS-1$
+ infixExpression.setRightOperand(literal);
+ literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("6"); //$NON-NLS-1$
+ infixExpression.extendedOperands().add(literal);
+ literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("4"); //$NON-NLS-1$
+ infixExpression.extendedOperands().add(literal);
+ assertTrue("Both AST trees should be identical", infixExpression.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "\"4\" + 5 + 6 + 4", source);//$NON-NLS-1$
+ }
+
+ /**
+ * NumberLiteral ==> InfixExpression
+ */
+ public void test0109() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0109", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setOperator(InfixExpression.Operator.MINUS);
+ StringLiteral stringLiteral = this.ast.newStringLiteral();//$NON-NLS-1$
+ stringLiteral.setLiteralValue("4"); //$NON-NLS-1$
+ infixExpression.setLeftOperand(stringLiteral);
+ NumberLiteral literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("5"); //$NON-NLS-1$
+ infixExpression.setRightOperand(literal);
+
+ InfixExpression infixExpression2 = this.ast.newInfixExpression();
+ infixExpression2.setOperator(InfixExpression.Operator.PLUS);
+ infixExpression2.setLeftOperand(infixExpression);
+ literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("6"); //$NON-NLS-1$
+ infixExpression2.setRightOperand(literal);
+
+ InfixExpression infixExpression3 = this.ast.newInfixExpression();
+ infixExpression3.setOperator(InfixExpression.Operator.PLUS);
+ infixExpression3.setLeftOperand(infixExpression2);
+ literal = this.ast.newNumberLiteral();//$NON-NLS-1$
+ literal.setToken("4"); //$NON-NLS-1$
+ infixExpression3.setRightOperand(literal);
+
+ assertTrue("Both AST trees should be identical", infixExpression3.subtreeMatch(new ASTMatcher(), expression)); //$NON-NLS-1$
+ checkSourceRange(expression, "\"4\" - 5 + 6 + 4", source);//$NON-NLS-1$
+ }
+
+ /**
+ * ReturnStatement ==> ReturnStatement
+ */
+ public void test0110() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0110", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ReturnStatement returnStatement = this.ast.newReturnStatement();
+ NumberLiteral literal = this.ast.newNumberLiteral();
+ literal.setToken("2");//$NON-NLS-1$
+ returnStatement.setExpression(literal);
+ assertTrue("Both AST trees should be identical", returnStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "return 2;", source);//$NON-NLS-1$
+ }
+
+ /**
+ * ReturnStatement ==> ReturnStatement
+ */
+ public void test0111() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0111", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ReturnStatement returnStatement = this.ast.newReturnStatement();
+ NumberLiteral literal = this.ast.newNumberLiteral();
+ literal.setToken("2");//$NON-NLS-1$
+ returnStatement.setExpression(literal);
+ assertTrue("Both AST trees should be identical", returnStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "return 2\\u003B", source);//$NON-NLS-1$
+ }
+
+ /**
+ * SynchronizedStatement ==> SynchronizedStatement
+ */
+ public void test0112() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0112", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ SynchronizedStatement synchronizedStatement = this.ast.newSynchronizedStatement();
+ synchronizedStatement.setExpression(this.ast.newThisExpression());
+ synchronizedStatement.setBody(this.ast.newBlock());
+ assertTrue("Both AST trees should be identical", synchronizedStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ String expectedSource = "synchronized(this) {\n" +//$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(node, expectedSource, source);
+ }
+
+ /**
+ * TryStatement ==> TryStatement
+ * @deprecated using deprecated code
+ */
+ public void test0113() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0113", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ TryStatement tryStatement = this.ast.newTryStatement();
+ tryStatement.setBody(this.ast.newBlock());
+ tryStatement.setFinally(this.ast.newBlock());
+ CatchClause catchBlock = this.ast.newCatchClause();
+ catchBlock.setBody(this.ast.newBlock());
+ SingleVariableDeclaration exceptionVariable = this.ast.newSingleVariableDeclaration();
+ exceptionVariable.setModifiers(Modifier.NONE);
+ exceptionVariable.setName(this.ast.newSimpleName("e"));//$NON-NLS-1$
+ exceptionVariable.setType(this.ast.newSimpleType(this.ast.newSimpleName("Exception")));//$NON-NLS-1$
+ catchBlock.setException(exceptionVariable);
+ tryStatement.catchClauses().add(catchBlock);
+ assertTrue("Both AST trees should be identical", tryStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ String expectedSource = "try {\n" +//$NON-NLS-1$
+ " } catch(Exception e) {\n" +//$NON-NLS-1$
+ " } finally {\n" +//$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(node, expectedSource, source);
+ }
+
+ /**
+ * TryStatement ==> TryStatement
+ * @deprecated using deprecated code
+ */
+ public void test0114() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0114", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ TryStatement tryStatement = this.ast.newTryStatement();
+ tryStatement.setBody(this.ast.newBlock());
+ CatchClause catchBlock = this.ast.newCatchClause();
+ catchBlock.setBody(this.ast.newBlock());
+ SingleVariableDeclaration exceptionVariable = this.ast.newSingleVariableDeclaration();
+ exceptionVariable.setModifiers(Modifier.NONE);
+ exceptionVariable.setName(this.ast.newSimpleName("e"));//$NON-NLS-1$
+ exceptionVariable.setType(this.ast.newSimpleType(this.ast.newSimpleName("Exception")));//$NON-NLS-1$
+ catchBlock.setException(exceptionVariable);
+ tryStatement.catchClauses().add(catchBlock);
+ assertTrue("Both AST trees should be identical", tryStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ String expectedSource = "try {\n" +//$NON-NLS-1$
+ " } catch(Exception e) {\n" +//$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(node, expectedSource, source);
+ }
+
+ /**
+ * TryStatement ==> TryStatement
+ * @deprecated using deprecated code
+ */
+ public void test0115() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0115", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ TryStatement tryStatement = this.ast.newTryStatement();
+ Block block = this.ast.newBlock();
+ ReturnStatement returnStatement = this.ast.newReturnStatement();
+ NumberLiteral literal = this.ast.newNumberLiteral();
+ literal.setToken("2");//$NON-NLS-1$
+ returnStatement.setExpression(literal);
+ block.statements().add(returnStatement);
+ tryStatement.setBody(block);
+ CatchClause catchBlock = this.ast.newCatchClause();
+ catchBlock.setBody(this.ast.newBlock());
+ SingleVariableDeclaration exceptionVariable = this.ast.newSingleVariableDeclaration();
+ exceptionVariable.setModifiers(Modifier.NONE);
+ exceptionVariable.setName(this.ast.newSimpleName("e"));//$NON-NLS-1$
+ exceptionVariable.setType(this.ast.newSimpleType(this.ast.newSimpleName("Exception")));//$NON-NLS-1$
+ catchBlock.setException(exceptionVariable);
+ tryStatement.catchClauses().add(catchBlock);
+ assertTrue("Both AST trees should be identical", tryStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ String expectedSource = "try {\n" +//$NON-NLS-1$
+ " return 2;\n" +//$NON-NLS-1$
+ " } catch(Exception e) {\n" +//$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(node, expectedSource, source);
+ }
+
+ /**
+ * ThrowStatement ==> ThrowStatement
+ */
+ public void test0116() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0116", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ThrowStatement throwStatement = this.ast.newThrowStatement();
+ throwStatement.setExpression(this.ast.newSimpleName("e")); //$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", throwStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "throw e \\u003B", source);//$NON-NLS-1$
+ }
+
+ /**
+ * ThrowStatement ==> ThrowStatement
+ */
+ public void test0117() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0117", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ThrowStatement throwStatement = this.ast.newThrowStatement();
+ throwStatement.setExpression(this.ast.newSimpleName("e")); //$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", throwStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "throw e /* comment in the middle of a throw */ \\u003B", source);//$NON-NLS-1$
+ }
+
+ /**
+ * ThrowStatement ==> ThrowStatement
+ */
+ public void test0118() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0118", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ThrowStatement throwStatement = this.ast.newThrowStatement();
+ throwStatement.setExpression(this.ast.newSimpleName("e")); //$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", throwStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "throw e /* comment in the middle of a throw */ \\u003B", source);//$NON-NLS-1$
+ }
+
+ /**
+ * IfStatement ==> IfStatement
+ */
+ public void test0119() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0119", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ IfStatement ifStatement = this.ast.newIfStatement();
+ ifStatement.setExpression(this.ast.newBooleanLiteral(true));
+ ifStatement.setThenStatement(this.ast.newEmptyStatement());
+ assertTrue("Both AST trees should be identical", ifStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "if (true)\\u003B", source);//$NON-NLS-1$
+ }
+
+ /**
+ * IfStatement ==> IfStatement
+ */
+ public void test0120() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0120", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ IfStatement ifStatement = this.ast.newIfStatement();
+ ifStatement.setExpression(this.ast.newBooleanLiteral(true));
+ ifStatement.setThenStatement(this.ast.newEmptyStatement());
+ ifStatement.setElseStatement(this.ast.newEmptyStatement());
+ assertTrue("Both AST trees should be identical", ifStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ String expectedSource = "if (true)\\u003B\n" +//$NON-NLS-1$
+ "\t\telse ;"; //$NON-NLS-1$
+ checkSourceRange(node, expectedSource, source);
+ }
+
+ /**
+ * IfStatement ==> IfStatement
+ */
+ public void test0121() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0121", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ IfStatement ifStatement = this.ast.newIfStatement();
+ ifStatement.setExpression(this.ast.newBooleanLiteral(true));
+ ifStatement.setThenStatement(this.ast.newBlock());
+ ifStatement.setElseStatement(this.ast.newEmptyStatement());
+ assertTrue("Both AST trees should be identical", ifStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ String expectedSource = "if (true) {}\n" +//$NON-NLS-1$
+ " else ;"; //$NON-NLS-1$
+ checkSourceRange(node, expectedSource, source);
+ }
+
+ /**
+ * IfStatement ==> IfStatement
+ */
+ public void test0122() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0122", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ IfStatement ifStatement = this.ast.newIfStatement();
+ ifStatement.setExpression(this.ast.newBooleanLiteral(true));
+ ReturnStatement returnStatement = this.ast.newReturnStatement();
+ NumberLiteral literal = this.ast.newNumberLiteral();
+ literal.setToken("2");//$NON-NLS-1$
+ returnStatement.setExpression(literal);
+ ifStatement.setThenStatement(returnStatement);
+ assertTrue("Both AST trees should be identical", ifStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "if (true) return 2\\u003B", source);//$NON-NLS-1$
+ }
+
+ /**
+ * IfStatement ==> IfStatement
+ */
+ public void test0123() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0123", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ IfStatement ifStatement = this.ast.newIfStatement();
+ ifStatement.setExpression(this.ast.newBooleanLiteral(true));
+ ReturnStatement returnStatement = this.ast.newReturnStatement();
+ NumberLiteral literal = this.ast.newNumberLiteral();
+ literal.setToken("2");//$NON-NLS-1$
+ returnStatement.setExpression(literal);
+ ifStatement.setThenStatement(returnStatement);
+ returnStatement = this.ast.newReturnStatement();
+ literal = this.ast.newNumberLiteral();
+ literal.setToken("3");//$NON-NLS-1$
+ returnStatement.setExpression(literal);
+ ifStatement.setElseStatement(returnStatement);
+ assertTrue("Both AST trees should be identical", ifStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ String expectedSource = "if (true) return 2;\n" +//$NON-NLS-1$
+ " else return 3;"; //$NON-NLS-1$
+ checkSourceRange(node, expectedSource, source);
+ }
+
+ /**
+ * Multiple local declaration => VariabledeclarationStatement
+ * @deprecated using deprecated code
+ */
+ public void test0124() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0124", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = this.ast.newVariableDeclarationFragment();
+ fragment.setName(this.ast.newSimpleName("x"));//$NON-NLS-1$
+ NumberLiteral literal = this.ast.newNumberLiteral();
+ literal.setToken("10");//$NON-NLS-1$
+ fragment.setInitializer(literal);
+ fragment.setExtraDimensions(0);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(fragment);
+ fragment = this.ast.newVariableDeclarationFragment();
+ fragment.setName(this.ast.newSimpleName("z"));//$NON-NLS-1$
+ fragment.setInitializer(this.ast.newNullLiteral());
+ fragment.setExtraDimensions(1);
+ statement.fragments().add(fragment);
+ fragment = this.ast.newVariableDeclarationFragment();
+ fragment.setName(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ fragment.setExtraDimensions(0);
+ statement.fragments().add(fragment);
+ fragment = this.ast.newVariableDeclarationFragment();
+ fragment.setName(this.ast.newSimpleName("j"));//$NON-NLS-1$
+ fragment.setExtraDimensions(2);
+ statement.fragments().add(fragment);
+ statement.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+ statement.setModifiers(Modifier.NONE);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ VariableDeclarationFragment[] fragments = (VariableDeclarationFragment[])((VariableDeclarationStatement) node).fragments().toArray(new VariableDeclarationFragment[4]);
+ assertTrue("fragments.length != 4", fragments.length == 4); //$NON-NLS-1$
+ checkSourceRange(fragments[0], "x= 10", source);//$NON-NLS-1$
+ checkSourceRange(fragments[1], "z[] = null", source);//$NON-NLS-1$
+ checkSourceRange(fragments[2], "i", source);//$NON-NLS-1$
+ checkSourceRange(fragments[3], "j[][]", source);//$NON-NLS-1$
+ checkSourceRange(node, "int x= 10, z[] = null, i, j[][];", source);//$NON-NLS-1$
+ }
+
+ /**
+ * Multiple local declaration => VariabledeclarationStatement
+ * @deprecated using deprecated code
+ */
+ public void test0125() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0125", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = this.ast.newVariableDeclarationFragment();
+ fragment.setName(this.ast.newSimpleName("x"));//$NON-NLS-1$
+ NumberLiteral literal = this.ast.newNumberLiteral();
+ literal.setToken("10");//$NON-NLS-1$
+ fragment.setInitializer(literal);
+ fragment.setExtraDimensions(0);
+ VariableDeclarationStatement statement = this.ast.newVariableDeclarationStatement(fragment);
+ fragment = this.ast.newVariableDeclarationFragment();
+ fragment.setName(this.ast.newSimpleName("z"));//$NON-NLS-1$
+ fragment.setInitializer(this.ast.newNullLiteral());
+ fragment.setExtraDimensions(1);
+ statement.fragments().add(fragment);
+ fragment = this.ast.newVariableDeclarationFragment();
+ fragment.setName(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ fragment.setExtraDimensions(0);
+ statement.fragments().add(fragment);
+ fragment = this.ast.newVariableDeclarationFragment();
+ fragment.setName(this.ast.newSimpleName("j"));//$NON-NLS-1$
+ fragment.setExtraDimensions(2);
+ statement.fragments().add(fragment);
+ statement.setType(this.ast.newArrayType(this.ast.newPrimitiveType(PrimitiveType.INT), 1));
+ statement.setModifiers(Modifier.NONE);
+ assertTrue("Both AST trees should be identical", statement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int[] x= 10, z[] = null, i, j[][];", source); //$NON-NLS-1$
+ VariableDeclarationFragment[] fragments = (VariableDeclarationFragment[])((VariableDeclarationStatement) node).fragments().toArray(new VariableDeclarationFragment[4]);
+ assertTrue("fragments.length != 4", fragments.length == 4); //$NON-NLS-1$
+ checkSourceRange(fragments[0], "x= 10", source);//$NON-NLS-1$
+ checkSourceRange(fragments[1], "z[] = null", source);//$NON-NLS-1$
+ checkSourceRange(fragments[2], "i", source);//$NON-NLS-1$
+ checkSourceRange(fragments[3], "j[][]", source);//$NON-NLS-1$
+ }
+
+ /**
+ * ForStatement
+ * @deprecated using deprecated code
+ */
+ public void test0126() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0126", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ForStatement forStatement = this.ast.newForStatement();
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("tab")); //$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(this.ast.newNullLiteral());//$NON-NLS-1$
+ variableDeclarationFragment.setExtraDimensions(1);
+ VariableDeclarationExpression variableDeclarationExpression = this.ast.newVariableDeclarationExpression(variableDeclarationFragment);
+ variableDeclarationExpression.setModifiers(Modifier.NONE);
+ variableDeclarationExpression.setType(this.ast.newArrayType(this.ast.newSimpleType(this.ast.newSimpleName("String")), 1));//$NON-NLS-1$
+ forStatement.initializers().add(variableDeclarationExpression);
+ PrefixExpression prefixExpression = this.ast.newPrefixExpression();
+ prefixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ prefixExpression.setOperator(PrefixExpression.Operator.INCREMENT);
+ forStatement.updaters().add(prefixExpression);
+ forStatement.setBody(this.ast.newBlock());
+ assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "for (String[] tab[] = null;; ++i) {}", source); //$NON-NLS-1$
+ checkSourceRange((ASTNode) ((ForStatement) node).updaters().get(0), "++i", source); //$NON-NLS-1$
+ checkSourceRange((ASTNode) ((ForStatement) node).initializers().get(0), "String[] tab[] = null", source); //$NON-NLS-1$
+ }
+
+ /**
+ * ForStatement
+ * @deprecated using deprecated code
+ */
+ public void test0127() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0127", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ForStatement forStatement = this.ast.newForStatement();
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("tab")); //$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(this.ast.newNullLiteral());//$NON-NLS-1$
+ variableDeclarationFragment.setExtraDimensions(1);
+ VariableDeclarationExpression variableDeclarationExpression = this.ast.newVariableDeclarationExpression(variableDeclarationFragment);
+ variableDeclarationExpression.setModifiers(Modifier.NONE);
+ variableDeclarationExpression.setType(this.ast.newSimpleType(this.ast.newSimpleName("String")));//$NON-NLS-1$
+ forStatement.initializers().add(variableDeclarationExpression);
+ PrefixExpression prefixExpression = this.ast.newPrefixExpression();
+ prefixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ prefixExpression.setOperator(PrefixExpression.Operator.INCREMENT);
+ forStatement.updaters().add(prefixExpression);
+ forStatement.setBody(this.ast.newBlock());
+ assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "for (String tab[] = null;; ++i) {}", source); //$NON-NLS-1$
+ checkSourceRange((ASTNode) ((ForStatement) node).updaters().get(0), "++i", source); //$NON-NLS-1$
+ checkSourceRange((ASTNode) ((ForStatement) node).initializers().get(0), "String tab[] = null", source); //$NON-NLS-1$
+ }
+
+ /**
+ * ForStatement
+ * @deprecated using deprecated code
+ */
+ public void test0128() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0128", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ForStatement forStatement = this.ast.newForStatement();
+ VariableDeclarationFragment variableDeclarationFragment = this.ast.newVariableDeclarationFragment();
+ variableDeclarationFragment.setName(this.ast.newSimpleName("tab")); //$NON-NLS-1$
+ variableDeclarationFragment.setInitializer(this.ast.newNullLiteral());//$NON-NLS-1$
+ variableDeclarationFragment.setExtraDimensions(1);
+ VariableDeclarationExpression variableDeclarationExpression = this.ast.newVariableDeclarationExpression(variableDeclarationFragment);
+ variableDeclarationExpression.setModifiers(Modifier.NONE);
+ variableDeclarationExpression.setType(this.ast.newSimpleType(this.ast.newSimpleName("String")));//$NON-NLS-1$
+ forStatement.initializers().add(variableDeclarationExpression);
+ PostfixExpression postfixExpression = this.ast.newPostfixExpression();
+ postfixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ postfixExpression.setOperator(PostfixExpression.Operator.INCREMENT);
+ forStatement.updaters().add(postfixExpression);
+ forStatement.setBody(this.ast.newBlock());
+ assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "for (String tab[] = null;; i++/**/) {}", source); //$NON-NLS-1$
+ checkSourceRange((ASTNode) ((ForStatement) node).updaters().get(0), "i++", source); //$NON-NLS-1$
+ checkSourceRange((ASTNode) ((ForStatement) node).initializers().get(0), "String tab[] = null", source); //$NON-NLS-1$
+ }
+
+ /**
+ * FieldDeclaration
+ * @deprecated using deprecated code
+ */
+ public void test0129() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0129", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a FieldDeclaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ VariableDeclarationFragment frag = (VariableDeclarationFragment) ((FieldDeclaration) node).fragments().get(0);
+ assertTrue("Not a declaration", frag.getName().isDeclaration()); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = this.ast.newVariableDeclarationFragment();
+ fragment.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ fragment.setExtraDimensions(0);
+ FieldDeclaration fieldDeclaration = this.ast.newFieldDeclaration(fragment);
+ fieldDeclaration.setModifiers(Modifier.NONE);
+ fieldDeclaration.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+ assertTrue("Both AST trees should be identical", fieldDeclaration.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "int i;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * FieldDeclaration
+ * @deprecated using deprecated code
+ */
+ public void test0130() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0130", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a FieldDeclaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = this.ast.newVariableDeclarationFragment();
+ fragment.setName(this.ast.newSimpleName("x")); //$NON-NLS-1$
+ NumberLiteral literal = this.ast.newNumberLiteral();
+ literal.setToken("10"); //$NON-NLS-1$
+ fragment.setInitializer(literal);
+ fragment.setExtraDimensions(0);
+ FieldDeclaration fieldDeclaration = this.ast.newFieldDeclaration(fragment);
+ fieldDeclaration.setModifiers(Modifier.PUBLIC);
+ fieldDeclaration.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+ fragment = this.ast.newVariableDeclarationFragment();
+ fragment.setName(this.ast.newSimpleName("y"));//$NON-NLS-1$
+ fragment.setExtraDimensions(1);
+ fragment.setInitializer(this.ast.newNullLiteral());
+ fieldDeclaration.fragments().add(fragment);
+ fragment = this.ast.newVariableDeclarationFragment();
+ fragment.setName(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ fragment.setExtraDimensions(0);
+ fieldDeclaration.fragments().add(fragment);
+ fragment = this.ast.newVariableDeclarationFragment();
+ fragment.setName(this.ast.newSimpleName("j"));//$NON-NLS-1$
+ fragment.setExtraDimensions(2);
+ fieldDeclaration.fragments().add(fragment);
+ assertTrue("Both AST trees should be identical", fieldDeclaration.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "public int x= 10, y[] = null, i, j[][];", source); //$NON-NLS-1$
+ VariableDeclarationFragment[] fragments = (VariableDeclarationFragment[])((FieldDeclaration) node).fragments().toArray(new VariableDeclarationFragment[4]);
+ assertTrue("fragments.length != 4", fragments.length == 4); //$NON-NLS-1$
+ checkSourceRange(fragments[0], "x= 10", source);//$NON-NLS-1$
+ checkSourceRange(fragments[1], "y[] = null", source);//$NON-NLS-1$
+ checkSourceRange(fragments[2], "i", source);//$NON-NLS-1$
+ checkSourceRange(fragments[3], "j[][]", source);//$NON-NLS-1$
+ }
+
+ /**
+ * Argument with final modifier
+ * @deprecated using deprecated code
+ */
+ public void test0131() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0131", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a MethodDeclaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ assertTrue("Not a declaration", ((MethodDeclaration) node).getName().isDeclaration()); //$NON-NLS-1$
+ List parameters = ((MethodDeclaration) node).parameters();
+ assertTrue("Parameters.length != 1", parameters.size() == 1); //$NON-NLS-1$
+ SingleVariableDeclaration arg = (SingleVariableDeclaration) ((MethodDeclaration) node).parameters().get(0);
+ SingleVariableDeclaration singleVariableDeclaration = this.ast.newSingleVariableDeclaration();
+ singleVariableDeclaration.setModifiers(Modifier.FINAL);
+ singleVariableDeclaration.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ singleVariableDeclaration.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+ assertTrue("Both AST trees should be identical", singleVariableDeclaration.subtreeMatch(new ASTMatcher(), arg)); //$NON-NLS-1$
+ checkSourceRange(node, "void foo(final int i) {}", source); //$NON-NLS-1$
+ checkSourceRange(arg, "final int i", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for MethodDeclaration
+ * @deprecated marking deprecated since using deprecated code
+ */
+ public void test0132() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0132", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a MethodDeclaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((MethodDeclaration) node).getJavadoc();
+ Javadoc javadoc = this.ast.newJavadoc();
+ javadoc.setComment("/** JavaDoc Comment*/");//$NON-NLS-1$*/
+ assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(new ASTMatcher(), actualJavadoc));//$NON-NLS-1$
+ checkSourceRange(node, "/** JavaDoc Comment*/\n void foo(final int i) {}", source); //$NON-NLS-1$
+ checkSourceRange(actualJavadoc, "/** JavaDoc Comment*/", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for MethodDeclaration
+ */
+ public void test0133() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0133", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a MethodDeclaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((MethodDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "void foo(final int i) {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for MethodDeclaration
+ */
+ public void test0134() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0134", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a MethodDeclaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((MethodDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "void foo(final int i) {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for FieldDeclaration
+ * @deprecated marking deprecated since using deprecated code
+ */
+ public void test0135() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0135", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a FieldDeclaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((FieldDeclaration) node).getJavadoc();
+ Javadoc javadoc = this.ast.newJavadoc();
+ javadoc.setComment("/** JavaDoc Comment*/");//$NON-NLS-1$*/
+ assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(new ASTMatcher(), actualJavadoc));//$NON-NLS-1$
+ checkSourceRange(node, "/** JavaDoc Comment*/\n int i;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for FieldDeclaration
+ */
+ public void test0136() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0136", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a FieldDeclaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((FieldDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "int i;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for FieldDeclaration
+ */
+ public void test0137() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0137", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a FieldDeclaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((FieldDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "int i;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for TypeDeclaration
+ */
+ public void test0138() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0138", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ String expectedContents = "public class Test {\n" +//$NON-NLS-1$
+ " int i;\n" +//$NON-NLS-1$
+ "}";//$NON-NLS-1$
+ checkSourceRange(node, expectedContents, source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for TypeDeclaration
+ */
+ public void test0139() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0139", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ String expectedContents = "public class Test {\n" +//$NON-NLS-1$
+ " int i;\n" +//$NON-NLS-1$
+ "}";//$NON-NLS-1$
+ checkSourceRange(node, expectedContents, source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for TypeDeclaration
+ * @deprecated marking deprecated since using deprecated code
+ */
+ public void test0140() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0140", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ Javadoc javadoc = this.ast.newJavadoc();
+ javadoc.setComment("/** JavaDoc Comment*/");//$NON-NLS-1$*/
+ assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(new ASTMatcher(), actualJavadoc));//$NON-NLS-1$
+ String expectedContents =
+ "/** JavaDoc Comment*/\n" + //$NON-NLS-1$
+ "public class Test {\n" +//$NON-NLS-1$
+ " int i;\n" +//$NON-NLS-1$
+ "}";//$NON-NLS-1$
+ checkSourceRange(node, expectedContents, source); //$NON-NLS-1$
+ checkSourceRange(actualJavadoc, "/** JavaDoc Comment*/", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for MemberTypeDeclaration
+ * @deprecated marking deprecated since using deprecated code
+ */
+ public void test0141() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0141", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ Javadoc javadoc = this.ast.newJavadoc();
+ javadoc.setComment("/** JavaDoc Comment*/");//$NON-NLS-1$*/
+ assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(new ASTMatcher(), actualJavadoc));//$NON-NLS-1$
+ String expectedContents =
+ "/** JavaDoc Comment*/\n" + //$NON-NLS-1$
+ " class B {}";//$NON-NLS-1$
+ checkSourceRange(node, expectedContents, source); //$NON-NLS-1$
+ checkSourceRange(actualJavadoc, "/** JavaDoc Comment*/", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for MemberTypeDeclaration
+ */
+ public void test0142() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0142", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "class B {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for MemberTypeDeclaration
+ */
+ public void test0143() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0143", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "public static class B {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for MemberTypeDeclaration
+ */
+ public void test0144() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0144", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "public static class B {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking initializers
+ */
+ public void test0145() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0145", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ checkSourceRange(node, "{}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking initializers
+ */
+ public void test0146() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0146", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ checkSourceRange(node, "static {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking initializers
+ * @deprecated marking deprecated since using deprecated code
+ */
+ public void test0147() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0147", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((Initializer) node).getJavadoc();
+ assertNotNull("Javadoc comment should no be null", actualJavadoc); //$NON-NLS-1$
+ Javadoc javadoc = this.ast.newJavadoc();
+ javadoc.setComment("/** JavaDoc Comment*/");//$NON-NLS-1$*/
+ assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(new ASTMatcher(), actualJavadoc));//$NON-NLS-1$
+ String expectedContents =
+ "/** JavaDoc Comment*/\n" + //$NON-NLS-1$
+ " static {}";//$NON-NLS-1$
+ checkSourceRange(node, expectedContents, source); //$NON-NLS-1$
+ checkSourceRange(actualJavadoc, "/** JavaDoc Comment*/", source); //$NON-NLS-1$
+
+ }
+
+ /**
+ * Checking initializers
+ * @deprecated marking deprecated since using deprecated code
+ */
+ public void test0148() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0148", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((Initializer) node).getJavadoc();
+ assertNotNull("Javadoc comment should not be null", actualJavadoc); //$NON-NLS-1$
+ Javadoc javadoc = this.ast.newJavadoc();
+ javadoc.setComment("/** JavaDoc Comment*/");//$NON-NLS-1$*/
+ assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(new ASTMatcher(), actualJavadoc));//$NON-NLS-1$
+ String expectedContents =
+ "/** JavaDoc Comment*/\n" + //$NON-NLS-1$
+ " {}";//$NON-NLS-1$
+ checkSourceRange(node, expectedContents, source); //$NON-NLS-1$
+ checkSourceRange(actualJavadoc, "/** JavaDoc Comment*/", source); //$NON-NLS-1$
+
+ }
+
+ /**
+ * Checking initializers
+ */
+ public void test0149() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0149", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((Initializer) node).getJavadoc();
+ assertNull("Javadoc comment should be null", actualJavadoc); //$NON-NLS-1$
+ checkSourceRange(node, "{}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking syntax error
+ */
+ public void test0150() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0150", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, false);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertTrue("The compilation unit is malformed", !isMalformed(unit)); //$NON-NLS-1$
+ assertTrue("The package declaration is not malformed", isMalformed(unit.getPackage())); //$NON-NLS-1$
+ List imports = unit.imports();
+ assertTrue("The imports list size is not one", imports.size() == 1); //$NON-NLS-1$
+ assertTrue("The first import is malformed", !isMalformed((ASTNode) imports.get(0))); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking syntax error
+ */
+ public void test0151() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0151", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, false);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The compilation unit is malformed", !isMalformed(result)); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking syntax error
+ */
+ public void test0152() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0152", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, false);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The compilation unit is malformed", !isMalformed(result)); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The type is malformed", !isMalformed(node)); //$NON-NLS-1$
+ node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The field is not malformed", isMalformed(node)); //$NON-NLS-1$
+ node = getASTNode((CompilationUnit) result, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The method is not malformed", isMalformed(node)); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking syntax error
+ */
+ public void test0153() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0153", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, false);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The compilation unit is malformed", !isMalformed(result)); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The method is not original", isOriginal(node)); //$NON-NLS-1$
+ assertTrue("The method is not malformed", isMalformed(node)); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking binding of package declaration
+ */
+ public void test0154() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0154", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ IBinding binding = compilationUnit.getPackage().getName().resolveBinding();
+ assertNotNull("The package binding is null", binding); //$NON-NLS-1$
+ assertTrue("The binding is not a package binding", binding instanceof IPackageBinding); //$NON-NLS-1$
+ IPackageBinding packageBinding = (IPackageBinding) binding;
+ assertEquals("The package name is incorrect", "test0154", packageBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding2 = compilationUnit.getPackage().getName().resolveBinding();
+ assertTrue("The package binding is not canonical", binding == binding2); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking arguments positions
+ */
+ public void test0155() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0155", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("The result is not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDecl = (MethodDeclaration) node;
+ List parameters = methodDecl.parameters();
+ assertTrue("The parameters size is different from 2", parameters.size() == 2); //$NON-NLS-1$
+ Object parameter = parameters.get(0);
+ assertTrue("The parameter is not a SingleVariableDeclaration", parameter instanceof SingleVariableDeclaration); //$NON-NLS-1$
+ checkSourceRange((ASTNode) parameter, "int i", source); //$NON-NLS-1$
+ parameter = parameters.get(1);
+ assertTrue("The parameter is not a SingleVariableDeclaration", parameter instanceof SingleVariableDeclaration); //$NON-NLS-1$
+ checkSourceRange((ASTNode) parameter, "final boolean b", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking arguments positions
+ */
+ public void test0156() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0156", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("The result is not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDecl = (MethodDeclaration) node;
+ List parameters = methodDecl.parameters();
+ assertTrue("The parameters size is different from 1", parameters.size() == 1); //$NON-NLS-1$
+ Object parameter = parameters.get(0);
+ assertTrue("The parameter is not a SingleVariableDeclaration", parameter instanceof SingleVariableDeclaration); //$NON-NLS-1$
+ checkSourceRange((ASTNode) parameter, "int i", source); //$NON-NLS-1$
+ Block block = methodDecl.getBody();
+ List statements = block.statements();
+ assertTrue("The statements size is different from 2", statements.size() == 2); //$NON-NLS-1$
+ ASTNode statement = (ASTNode) statements.get(0);
+ assertTrue("The statements[0] is a postfixExpression statement", statement instanceof ExpressionStatement); //$NON-NLS-1$
+ }
+
+ /**
+ * Check canonic binding for fields
+ */
+ public void test0157() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "", "Test0157.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ List types = compilationUnit.types();
+ assertTrue("The types list is empty", types.size() != 0); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) types.get(0);
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("Type binding is null", typeBinding); //$NON-NLS-1$
+ assertTrue("The type binding is canonical", typeBinding == typeDeclaration.resolveBinding()); //$NON-NLS-1$
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertTrue("The body declaration list is empty", bodyDeclarations.size() != 0); //$NON-NLS-1$
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue("This is not a field", bodyDeclaration instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) bodyDeclaration;
+ List variableFragments = fieldDeclaration.fragments();
+ assertTrue("The fragment list is empty", variableFragments.size() != 0); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) variableFragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNotNull("the field binding is null", variableBinding); //$NON-NLS-1$
+ assertTrue("The field binding is not canonical", variableBinding == fragment.resolveBinding()); //$NON-NLS-1$
+ typeBinding = variableBinding.getType();
+ assertTrue("The type is not an array type", typeBinding.isArray()); //$NON-NLS-1$
+ assertTrue("The type binding for the field is not canonical", typeBinding == variableBinding.getType()); //$NON-NLS-1$
+ SimpleName name = fragment.getName();
+ assertTrue("is a declaration", name.isDeclaration()); //$NON-NLS-1$
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("wrong type", IBinding.VARIABLE, binding.getKind()); //$NON-NLS-1$
+ assertTrue("not a field", ((IVariableBinding) binding).isField()); //$NON-NLS-1$
+ }
+
+ /**
+ * Check canonic bindings for fields
+ */
+ public void test0158() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "", "Test0158.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ List types = compilationUnit.types();
+ assertTrue("The types list is empty", types.size() != 0); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) types.get(0);
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("Type binding is null", typeBinding); //$NON-NLS-1$
+ assertTrue("The type binding is canonical", typeBinding == typeDeclaration.resolveBinding()); //$NON-NLS-1$
+ SimpleName simpleName = typeDeclaration.getName();
+ assertTrue("is a declaration", simpleName.isDeclaration()); //$NON-NLS-1$
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("wrong type", IBinding.TYPE, binding.getKind()); //$NON-NLS-1$
+ assertEquals("wrong name", simpleName.getIdentifier(), binding.getName()); //$NON-NLS-1$
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertTrue("The body declaration list is empty", bodyDeclarations.size() != 0); //$NON-NLS-1$
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue("This is not a field", bodyDeclaration instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) bodyDeclaration;
+ List variableFragments = fieldDeclaration.fragments();
+ assertTrue("The fragment list is empty", variableFragments.size() != 0); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) variableFragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNotNull("the field binding is null", variableBinding); //$NON-NLS-1$
+ assertTrue("The field binding is not canonical", variableBinding == fragment.resolveBinding()); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = variableBinding.getType();
+ assertTrue("The type is not an array type", typeBinding2.isArray()); //$NON-NLS-1$
+ assertTrue("The type binding for the field is not canonical", typeBinding2 == variableBinding.getType()); //$NON-NLS-1$
+ assertTrue("The type binding for the field is not canonical with the declaration type binding", typeBinding == typeBinding2.getElementType()); //$NON-NLS-1$
+ }
+
+ /**
+ * Define an anonymous type
+ */
+ public void test0159() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0159", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ }
+
+ /**
+ * Check bindings for multiple field declarations
+ */
+ public void test0160() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0160", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ List types = compilationUnit.types();
+ assertTrue("The types list is empty", types.size() != 0); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) types.get(0);
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("Type binding is null", typeBinding); //$NON-NLS-1$
+ assertTrue("The type binding is canonical", typeBinding == typeDeclaration.resolveBinding()); //$NON-NLS-1$
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertTrue("The body declaration list is empty", bodyDeclarations.size() != 0); //$NON-NLS-1$
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue("This is not a field", bodyDeclaration instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) bodyDeclaration;
+ List variableFragments = fieldDeclaration.fragments();
+ assertTrue("The fragment list size is not 2", variableFragments.size() == 2); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) variableFragments.get(0);
+ IVariableBinding variableBinding1 = fragment.resolveBinding();
+ assertNotNull("the field binding is null", variableBinding1); //$NON-NLS-1$
+ assertTrue("The field binding is not canonical", variableBinding1 == fragment.resolveBinding()); //$NON-NLS-1$
+ ITypeBinding type1 = variableBinding1.getType();
+ assertNotNull("The type is null", type1); //$NON-NLS-1$
+ assertTrue("The field type is canonical", type1 == variableBinding1.getType()); //$NON-NLS-1$
+ assertTrue("The type is not an array type",type1.isArray()); //$NON-NLS-1$
+ assertTrue("The type dimension is 1", type1.getDimensions() == 1); //$NON-NLS-1$
+ fragment = (VariableDeclarationFragment) variableFragments.get(1);
+ IVariableBinding variableBinding2 = fragment.resolveBinding();
+ assertNotNull("the field binding is null", variableBinding2); //$NON-NLS-1$
+ assertTrue("The field binding is not canonical", variableBinding2 == fragment.resolveBinding()); //$NON-NLS-1$
+ ITypeBinding type2 = variableBinding2.getType();
+ type2 = variableBinding2.getType();
+ assertNotNull("The type is null", type2); //$NON-NLS-1$
+ assertTrue("The field type is canonical", type2 == variableBinding2.getType()); //$NON-NLS-1$
+ assertTrue("The type is not an array type",type2.isArray()); //$NON-NLS-1$
+ assertTrue("The type dimension is 2", type2.getDimensions() == 2); //$NON-NLS-1$
+ assertTrue("Element type is canonical", type1.getElementType() == type2.getElementType()); //$NON-NLS-1$
+ assertTrue("type1.id < type2.id", variableBinding1.getVariableId() < variableBinding2.getVariableId()); //$NON-NLS-1$
+
+ }
+
+ /**
+ * Check ITypeBinding APIs:
+ * - getModifiers()
+ * - getElementType() when it is not an array type
+ * - getDimensions() when it is not an array type
+ * - getDeclaringClass()
+ * - getDeclaringName()
+ * - getName()
+ * - isNested()
+ * - isAnonymous()
+ * - isLocal()
+ * - isMember()
+ * - isArray()
+ * - getDeclaredMethods() => returns binding for default constructor
+ * - isPrimitive()
+ * - isTopLevel()
+ * - getSuperclass()
+ */
+ public void test0161() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0161", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ List types = compilationUnit.types();
+ assertTrue("The types list is empty", types.size() != 0); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) types.get(0);
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("The type binding should not be null", typeBinding); //$NON-NLS-1$
+ assertEquals("The modifier is PUBLIC", Modifier.PUBLIC, typeBinding.getModifiers()); //$NON-NLS-1$
+ assertNull("There is no element type", typeBinding.getElementType()); //$NON-NLS-1$
+ assertEquals("There is no dimension", 0, typeBinding.getDimensions()); //$NON-NLS-1$
+ assertNull("This is not a member type", typeBinding.getDeclaringClass()); //$NON-NLS-1$
+ IMethodBinding[] methods = typeBinding.getDeclaredMethods();
+ assertEquals("Contains the default constructor", 1, methods.length); //$NON-NLS-1$
+ assertEquals("The name is not Test", "Test", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("An anonymous class", !typeBinding.isAnonymous()); //$NON-NLS-1$
+ assertTrue("A local class", !typeBinding.isLocal()); //$NON-NLS-1$
+ assertTrue("A nested class", !typeBinding.isNested()); //$NON-NLS-1$
+ assertTrue("A member class", !typeBinding.isMember()); //$NON-NLS-1$
+ assertTrue("An array", !typeBinding.isArray()); //$NON-NLS-1$
+ assertTrue("Not a class", typeBinding.isClass()); //$NON-NLS-1$
+ assertTrue("An interface", !typeBinding.isInterface()); //$NON-NLS-1$
+ assertTrue("Not from source", typeBinding.isFromSource()); //$NON-NLS-1$
+ assertTrue("Is nested", typeBinding.isTopLevel()); //$NON-NLS-1$
+ assertTrue("A primitive type", !typeBinding.isPrimitive()); //$NON-NLS-1$
+ ITypeBinding superclass = typeBinding.getSuperclass();
+ assertNotNull("No superclass", superclass); //$NON-NLS-1$
+ assertTrue("From source", !superclass.isFromSource()); //$NON-NLS-1$
+ ITypeBinding supersuperclass = superclass.getSuperclass();
+ assertNull("No superclass for java.lang.Object", supersuperclass); //$NON-NLS-1$
+ ITypeBinding[] interfaces = typeBinding.getInterfaces();
+ assertNotNull("No interfaces", interfaces); //$NON-NLS-1$
+ assertEquals("More then one super interface", 1, interfaces.length); //$NON-NLS-1$
+ assertTrue("is not an interface", interfaces[0].isInterface()); //$NON-NLS-1$
+ assertTrue("From source", !interfaces[0].isFromSource()); //$NON-NLS-1$
+ assertEquals("Has fields", 0, typeBinding.getDeclaredFields().length); //$NON-NLS-1$
+ }
+
+ /**
+ * Check ITypeBinding APIs:
+ * - getModifiers()
+ * - getElementType() when it is not an array type
+ * - getDimensions() when it is not an array type
+ * - getDeclaringClass()
+ * - getDeclaringName()
+ * - getName()
+ * - isNested()
+ * - isAnonymous()
+ * - isLocal()
+ * - isMember()
+ * - isArray()
+ * - getDeclaredMethods() => returns binding for default constructor
+ * - isPrimitive()
+ * - isTopLevel()
+ * - getSuperclass()
+ */
+ public void test0162() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0162", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ List types = compilationUnit.types();
+ assertTrue("The types list is empty", types.size() != 0); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) types.get(0);
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("The type binding should not be null", typeBinding); //$NON-NLS-1$
+ assertEquals("The modifier is PUBLIC", Modifier.PUBLIC, typeBinding.getModifiers()); //$NON-NLS-1$
+ assertNull("There is no element type", typeBinding.getElementType()); //$NON-NLS-1$
+ assertEquals("There is no dimension", 0, typeBinding.getDimensions()); //$NON-NLS-1$
+ assertNull("This is not a member type", typeBinding.getDeclaringClass()); //$NON-NLS-1$
+ IMethodBinding[] methods = typeBinding.getDeclaredMethods();
+ assertEquals("Contains no methos", 0, methods.length); //$NON-NLS-1$
+ assertEquals("The name is not Test", "Test", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("An anonymous class", !typeBinding.isAnonymous()); //$NON-NLS-1$
+ assertTrue("A local class", !typeBinding.isLocal()); //$NON-NLS-1$
+ assertTrue("A nested class", !typeBinding.isNested()); //$NON-NLS-1$
+ assertTrue("A member class", !typeBinding.isMember()); //$NON-NLS-1$
+ assertTrue("An array", !typeBinding.isArray()); //$NON-NLS-1$
+ assertTrue("A class", !typeBinding.isClass()); //$NON-NLS-1$
+ assertTrue("Not an interface", typeBinding.isInterface()); //$NON-NLS-1$
+ assertTrue("Not from source", typeBinding.isFromSource()); //$NON-NLS-1$
+ assertTrue("Is nested", typeBinding.isTopLevel()); //$NON-NLS-1$
+ assertTrue("A primitive type", !typeBinding.isPrimitive()); //$NON-NLS-1$
+ ITypeBinding superclass = typeBinding.getSuperclass();
+ assertNull("No superclass", superclass); //$NON-NLS-1$
+ assertEquals("Has fields", 0, typeBinding.getDeclaredFields().length); //$NON-NLS-1$
+ }
+
+ /**
+ * Test binding for anonymous declaration: new java.lang.Object() {}
+ */
+ public void test0163() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0163", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ assertTrue("Not an anonymous type declaration", expression instanceof ClassInstanceCreation); //$NON-NLS-1$
+ ClassInstanceCreation anonymousClass = (ClassInstanceCreation) expression;
+ ITypeBinding typeBinding = anonymousClass.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertTrue("Not an anonymous class", typeBinding.isAnonymous()); //$NON-NLS-1$
+ assertEquals("The modifier is not default", Modifier.NONE, typeBinding.getModifiers()); //$NON-NLS-1$
+ assertNull("There is no element type", typeBinding.getElementType()); //$NON-NLS-1$
+ assertEquals("There is no dimension", 0, typeBinding.getDimensions()); //$NON-NLS-1$
+ assertNotNull("This is a member type", typeBinding.getDeclaringClass()); //$NON-NLS-1$
+ assertEquals("The name is not empty", "", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IMethodBinding[] methods = typeBinding.getDeclaredMethods();
+ assertEquals("Contains the default constructor", 1, methods.length); //$NON-NLS-1$
+ assertTrue("Not a local class", typeBinding.isLocal()); //$NON-NLS-1$
+ assertTrue("Not a nested class", typeBinding.isNested()); //$NON-NLS-1$
+ assertTrue("A member class", !typeBinding.isMember()); //$NON-NLS-1$
+ assertTrue("An array", !typeBinding.isArray()); //$NON-NLS-1$
+ assertTrue("Not a class", typeBinding.isClass()); //$NON-NLS-1$
+ assertTrue("An interface", !typeBinding.isInterface()); //$NON-NLS-1$
+ assertTrue("Not from source", typeBinding.isFromSource()); //$NON-NLS-1$
+ assertTrue("Is a top level", !typeBinding.isTopLevel()); //$NON-NLS-1$
+ assertTrue("A primitive type", !typeBinding.isPrimitive()); //$NON-NLS-1$
+ assertEquals("wrong qualified name", "", typeBinding.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ITypeBinding superclass = typeBinding.getSuperclass();
+ assertNotNull("No superclass", superclass); //$NON-NLS-1$
+ assertEquals("Has fields", 0, typeBinding.getDeclaredFields().length); //$NON-NLS-1$
+ }
+
+ /**
+ * Test binding for member type declaration
+ */
+ public void test0164() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0164", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("Not an type declaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertTrue("An anonymous class", !typeBinding.isAnonymous()); //$NON-NLS-1$
+ assertEquals("The modifier is not default", Modifier.PRIVATE, typeBinding.getModifiers()); //$NON-NLS-1$
+ assertNull("There is no element type", typeBinding.getElementType()); //$NON-NLS-1$
+ assertEquals("There is no dimension", 0, typeBinding.getDimensions()); //$NON-NLS-1$
+ assertNotNull("This is not a member type", typeBinding.getDeclaringClass()); //$NON-NLS-1$
+ assertEquals("The name is not 'B'", "B", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IMethodBinding[] methods = typeBinding.getDeclaredMethods();
+ assertEquals("Contains the default constructor", 1, methods.length); //$NON-NLS-1$
+ assertTrue("A local class", !typeBinding.isLocal()); //$NON-NLS-1$
+ assertTrue("Not a nested class", typeBinding.isNested()); //$NON-NLS-1$
+ assertTrue("Not a member class", typeBinding.isMember()); //$NON-NLS-1$
+ assertTrue("An array", !typeBinding.isArray()); //$NON-NLS-1$
+ assertTrue("Not a class", typeBinding.isClass()); //$NON-NLS-1$
+ assertTrue("An interface", !typeBinding.isInterface()); //$NON-NLS-1$
+ assertTrue("Not from source", typeBinding.isFromSource()); //$NON-NLS-1$
+ assertTrue("Is a top level", !typeBinding.isTopLevel()); //$NON-NLS-1$
+ assertTrue("A primitive type", !typeBinding.isPrimitive()); //$NON-NLS-1$
+ ITypeBinding superclass = typeBinding.getSuperclass();
+ assertNotNull("No superclass", superclass); //$NON-NLS-1$
+ assertEquals("Has fields", 0, typeBinding.getDeclaredFields().length); //$NON-NLS-1$
+ }
+
+ /**
+ * Test binding for local type declaration
+ * @deprecated using deprecated code
+ */
+ public void test0165() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0165", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("Not an type declaration", node instanceof TypeDeclarationStatement); //$NON-NLS-1$
+ TypeDeclarationStatement statement = (TypeDeclarationStatement) node;
+ TypeDeclaration typeDeclaration = statement.getTypeDeclaration();
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertTrue("An anonymous class", !typeBinding.isAnonymous()); //$NON-NLS-1$
+ assertEquals("The modifier is not default", Modifier.NONE, typeBinding.getModifiers()); //$NON-NLS-1$
+ assertNull("There is no element type", typeBinding.getElementType()); //$NON-NLS-1$
+ assertEquals("There is no dimension", 0, typeBinding.getDimensions()); //$NON-NLS-1$
+ assertNotNull("This is not a member type", typeBinding.getDeclaringClass()); //$NON-NLS-1$
+ assertEquals("The name is not 'C'", "C", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IMethodBinding[] methods = typeBinding.getDeclaredMethods();
+ assertEquals("Contains the default constructor", 1, methods.length); //$NON-NLS-1$
+ assertTrue("Not a local class", typeBinding.isLocal()); //$NON-NLS-1$
+ assertTrue("Not a nested class", typeBinding.isNested()); //$NON-NLS-1$
+ assertTrue("A member class", !typeBinding.isMember()); //$NON-NLS-1$
+ assertTrue("An array", !typeBinding.isArray()); //$NON-NLS-1$
+ assertTrue("Not a class", typeBinding.isClass()); //$NON-NLS-1$
+ assertTrue("An interface", !typeBinding.isInterface()); //$NON-NLS-1$
+ assertTrue("Not from source", typeBinding.isFromSource()); //$NON-NLS-1$
+ assertTrue("Is a top level", !typeBinding.isTopLevel()); //$NON-NLS-1$
+ assertTrue("A primitive type", !typeBinding.isPrimitive()); //$NON-NLS-1$
+ assertEquals("wrong qualified name", "", typeBinding.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ITypeBinding superclass = typeBinding.getSuperclass();
+ assertNotNull("No superclass", superclass); //$NON-NLS-1$
+ assertEquals("Has fields", 0, typeBinding.getDeclaredFields().length); //$NON-NLS-1$
+ }
+
+ /**
+ * Multiple local declaration => VariabledeclarationStatement
+ */
+ public void test0166() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0166", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertTrue("Fragment list is not 4 ", fragments.size() == 4); //$NON-NLS-1$
+ VariableDeclarationFragment fragment1 = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding binding1 = fragment1.resolveBinding();
+ assertNotNull("Binding is null", binding1); //$NON-NLS-1$
+ assertEquals("wrong name for binding1", "x", binding1.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong modifier for binding1", 0, binding1.getModifiers()); //$NON-NLS-1$
+ assertTrue("a field", !binding1.isField()); //$NON-NLS-1$
+ assertNull("declaring class is not null", binding1.getDeclaringClass()); //$NON-NLS-1$
+ ITypeBinding typeBinding1 = binding1.getType();
+ assertNotNull("typeBinding1 is null", typeBinding1); //$NON-NLS-1$
+ assertTrue("typeBinding1 is not a primitive type", typeBinding1.isPrimitive()); //$NON-NLS-1$
+ assertTrue("typeBinding1 is not canonical", typeBinding1 == binding1.getType()); //$NON-NLS-1$
+ VariableDeclarationFragment fragment2 = (VariableDeclarationFragment) fragments.get(1);
+ IVariableBinding binding2 = fragment2.resolveBinding();
+ assertNotNull("Binding is null", binding2); //$NON-NLS-1$
+ assertEquals("wrong name for binding2", "z", binding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong modifier for binding2", 0, binding2.getModifiers()); //$NON-NLS-1$
+ assertTrue("a field", !binding2.isField()); //$NON-NLS-1$
+ assertNull("declaring class is not null", binding2.getDeclaringClass()); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = binding2.getType();
+ assertNotNull("typeBinding2 is null", typeBinding2); //$NON-NLS-1$
+ assertTrue("typeBinding2 is not an array type", typeBinding2.isArray()); //$NON-NLS-1$
+ assertTrue("typeBinding2 is not canonical", typeBinding2 == binding2.getType()); //$NON-NLS-1$
+ assertTrue("primitive type is not canonical", typeBinding1 == typeBinding2.getElementType()); //$NON-NLS-1$
+ assertEquals("dimension is 1", 1, typeBinding2.getDimensions()); //$NON-NLS-1$
+ assertEquals("it is not int[]", "int[]", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ VariableDeclarationFragment fragment3 = (VariableDeclarationFragment) fragments.get(2);
+ IVariableBinding binding3 = fragment3.resolveBinding();
+ assertNotNull("Binding is null", binding3); //$NON-NLS-1$
+ assertEquals("wrong name for binding3", "i", binding3.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong modifier for binding3", 0, binding3.getModifiers()); //$NON-NLS-1$
+ assertTrue("a field", !binding3.isField()); //$NON-NLS-1$
+ assertNull("declaring class is not null", binding3.getDeclaringClass()); //$NON-NLS-1$
+ ITypeBinding typeBinding3 = binding3.getType();
+ assertNotNull("typeBinding3 is null", typeBinding3); //$NON-NLS-1$
+ assertTrue("typeBinding3 is not an primitive type", typeBinding3.isPrimitive()); //$NON-NLS-1$
+ assertTrue("typeBinding3 is not canonical", typeBinding3 == binding3.getType()); //$NON-NLS-1$
+ assertTrue("primitive type is not canonical", typeBinding1 == typeBinding3); //$NON-NLS-1$
+ assertEquals("dimension is 0", 0, typeBinding3.getDimensions()); //$NON-NLS-1$
+ assertEquals("it is not the primitive type int", "int", typeBinding3.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ VariableDeclarationFragment fragment4 = (VariableDeclarationFragment) fragments.get(3);
+ IVariableBinding binding4 = fragment4.resolveBinding();
+ assertNotNull("Binding is null", binding4); //$NON-NLS-1$
+ assertEquals("wrong name for binding4", "j", binding4.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong modifier for binding4", 0, binding4.getModifiers()); //$NON-NLS-1$
+ assertTrue("a field", !binding4.isField()); //$NON-NLS-1$
+ assertNull("declaring class is not null", binding4.getDeclaringClass()); //$NON-NLS-1$
+ ITypeBinding typeBinding4 = binding4.getType();
+ assertNotNull("typeBinding4 is null", typeBinding4); //$NON-NLS-1$
+ assertTrue("typeBinding4 is not an array type", typeBinding4.isArray()); //$NON-NLS-1$
+ assertTrue("typeBinding4 is not canonical", typeBinding4 == binding4.getType()); //$NON-NLS-1$
+ assertTrue("primitive type is not canonical", typeBinding1 == typeBinding4.getElementType()); //$NON-NLS-1$
+ assertEquals("dimension is 2", 2, typeBinding4.getDimensions()); //$NON-NLS-1$
+ assertEquals("it is not int[][]", "int[][]", typeBinding4.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("ids in the wrong order", binding1.getVariableId() < binding2.getVariableId()); //$NON-NLS-1$
+ assertTrue("ids in the wrong order", binding2.getVariableId() < binding3.getVariableId()); //$NON-NLS-1$
+ assertTrue("ids in the wrong order", binding3.getVariableId() < binding4.getVariableId()); //$NON-NLS-1$
+ }
+
+ /**
+ * Check source position for new Test[1+2].length.
+ */
+ public void test0167() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0167", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("Instance of VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertTrue("fragment list size is not 1", fragments.size() == 1); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression initialization = fragment.getInitializer();
+ assertNotNull("No initialization", initialization); //$NON-NLS-1$
+ assertTrue("Not a FieldAccess", initialization instanceof FieldAccess); //$NON-NLS-1$
+ checkSourceRange(initialization, "new Test[1+2].length", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check package binding: test0168.test
+ */
+ public void test0168() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0168.test1", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ List types = compilationUnit.types();
+ assertTrue("The types list is empty", types.size() != 0); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) types.get(0);
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("Binding not null", typeBinding); //$NON-NLS-1$
+ IPackageBinding packageBinding = typeBinding.getPackage();
+ assertNotNull("No package binding", packageBinding); //$NON-NLS-1$
+ assertEquals("wrong name", "test0168.test1", packageBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ String[] components = packageBinding.getNameComponents();
+ assertNotNull("no components", components); //$NON-NLS-1$
+ assertTrue("components size != 2", components.length == 2); //$NON-NLS-1$
+ assertEquals("wrong component name", "test0168", components[0]); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong component name", "test1", components[1]); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong type", IBinding.PACKAGE, packageBinding.getKind()); //$NON-NLS-1$
+ assertTrue("Unnamed package", !packageBinding.isUnnamed()); //$NON-NLS-1$
+ assertTrue("Package binding is not canonical", packageBinding == typeBinding.getPackage()); //$NON-NLS-1$
+ }
+
+ /**
+ * Check package binding: test0169
+ */
+ public void test0169() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0169", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ List types = compilationUnit.types();
+ assertTrue("The types list is empty", types.size() != 0); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) types.get(0);
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("Binding not null", typeBinding); //$NON-NLS-1$
+ IPackageBinding packageBinding = typeBinding.getPackage();
+ assertNotNull("No package binding", packageBinding); //$NON-NLS-1$
+ assertEquals("wrong name", "test0169", packageBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ String[] components = packageBinding.getNameComponents();
+ assertNotNull("no components", components); //$NON-NLS-1$
+ assertTrue("components size != 1", components.length == 1); //$NON-NLS-1$
+ assertEquals("wrong component name", "test0169", components[0]); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong type", IBinding.PACKAGE, packageBinding.getKind()); //$NON-NLS-1$
+ assertTrue("Unnamed package", !packageBinding.isUnnamed()); //$NON-NLS-1$
+ assertTrue("Package binding is not canonical", packageBinding == typeBinding.getPackage()); //$NON-NLS-1$
+ }
+
+ /**
+ * Check package binding: test0170
+ */
+ public void test0170() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "", "Test0170.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ List types = compilationUnit.types();
+ assertTrue("The types list is empty", types.size() != 0); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) types.get(0);
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("Binding not null", typeBinding); //$NON-NLS-1$
+ IPackageBinding packageBinding = typeBinding.getPackage();
+ assertNotNull("No package binding", packageBinding); //$NON-NLS-1$
+ assertEquals("wrong name", "", packageBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ String[] components = packageBinding.getNameComponents();
+ assertNotNull("no components", components); //$NON-NLS-1$
+ assertTrue("components size != 0", components.length == 0); //$NON-NLS-1$
+ assertEquals("wrong type", IBinding.PACKAGE, packageBinding.getKind()); //$NON-NLS-1$
+ assertTrue("Not an unnamed package", packageBinding.isUnnamed()); //$NON-NLS-1$
+ assertTrue("Package binding is not canonical", packageBinding == typeBinding.getPackage()); //$NON-NLS-1$
+ }
+
+ /**
+ * Check package binding: test0171
+ */
+ public void test0171() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0171", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ List types = compilationUnit.types();
+ assertTrue("The types list is empty", types.size() == 2); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) types.get(0);
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("Binding not null", typeBinding); //$NON-NLS-1$
+ IPackageBinding packageBinding = typeBinding.getPackage();
+ assertNotNull("No package binding", packageBinding); //$NON-NLS-1$
+ assertEquals("wrong name", "test0171", packageBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ String[] components = packageBinding.getNameComponents();
+ assertNotNull("no components", components); //$NON-NLS-1$
+ assertTrue("components size != 1", components.length == 1); //$NON-NLS-1$
+ assertEquals("wrong component name", "test0171", components[0]); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong type", IBinding.PACKAGE, packageBinding.getKind()); //$NON-NLS-1$
+ assertTrue("Unnamed package", !packageBinding.isUnnamed()); //$NON-NLS-1$
+ assertTrue("Package binding is not canonical", packageBinding == typeBinding.getPackage()); //$NON-NLS-1$
+
+ typeDeclaration = (TypeDeclaration) types.get(1);
+ typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("Binding not null", typeBinding); //$NON-NLS-1$
+ IPackageBinding packageBinding2 = typeBinding.getPackage();
+ assertNotNull("No package binding", packageBinding); //$NON-NLS-1$
+ assertTrue("Package binding is not canonical", packageBinding == packageBinding2); //$NON-NLS-1$
+ }
+
+ /**
+ * Check method binding
+ */
+ public void test0172() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0172", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ List types = compilationUnit.types();
+ assertTrue("The types list is empty", types.size() != 0); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) types.get(0);
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("Binding not null", typeBinding); //$NON-NLS-1$
+ IMethodBinding[] methods = typeBinding.getDeclaredMethods();
+ assertNotNull("No methods", methods);
+ assertEquals("methods.length != 4", 4, methods.length); //$NON-NLS-1$
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("body declaration size != 3", 3, bodyDeclarations.size()); //$NON-NLS-1$
+ MethodDeclaration method1 = (MethodDeclaration) bodyDeclarations.get(0);
+ IMethodBinding methodBinding1 = method1.resolveBinding();
+ assertNotNull("No method binding for foo", methodBinding1); //$NON-NLS-1$
+ SimpleName simpleName = method1.getName();
+ assertTrue("not a declaration", simpleName.isDeclaration()); //$NON-NLS-1$
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("wrong name", binding.getName(), simpleName.getIdentifier()); //$NON-NLS-1$
+ // search method foo
+ IMethodBinding methodBinding = null;
+ loop: for (int i = 0, max = methods.length; i < max; i++) {
+ IMethodBinding currentMethod = methods[i];
+ if ("foo".equals(currentMethod.getName())) {
+ methodBinding = currentMethod;
+ break loop;
+ }
+ }
+ assertNotNull("Cannot be null", methodBinding);
+ assertTrue("Canonical method binding", methodBinding1 == methodBinding); //$NON-NLS-1$
+ assertTrue("declaring class is canonical", typeBinding == methodBinding1.getDeclaringClass()); //$NON-NLS-1$
+ ITypeBinding[] exceptionTypes = methodBinding1.getExceptionTypes();
+ assertNotNull("No exception types", exceptionTypes); //$NON-NLS-1$
+ assertEquals("One exception", 1, exceptionTypes.length); //$NON-NLS-1$
+ assertEquals("wrong name for exception", "IOException", exceptionTypes[0].getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong modifier", Modifier.NONE, methodBinding1.getModifiers()); //$NON-NLS-1$
+ assertEquals("wrong name for method", "foo", methodBinding1.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ITypeBinding[] parameters = methodBinding1.getParameterTypes();
+ assertNotNull("No parameters", parameters); //$NON-NLS-1$
+ assertEquals("wrong size", 1, parameters.length); //$NON-NLS-1$
+ assertEquals("wrong type", "int[]", parameters[0].getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong return type", "void", methodBinding1.getReturnType().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("A constructor", !methodBinding1.isConstructor()); //$NON-NLS-1$
+
+ MethodDeclaration method2 = (MethodDeclaration) bodyDeclarations.get(1);
+ IMethodBinding methodBinding2 = method2.resolveBinding();
+ assertNotNull("No method binding for main", methodBinding2); //$NON-NLS-1$
+ methodBinding = null;
+ loop: for (int i = 0, max = methods.length; i < max; i++) {
+ IMethodBinding currentMethod = methods[i];
+ if ("main".equals(currentMethod.getName())) {
+ methodBinding = currentMethod;
+ break loop;
+ }
+ }
+ assertNotNull("Cannot be null", methodBinding);
+ assertTrue("Canonical method binding", methodBinding2 == methodBinding); //$NON-NLS-1$
+ assertTrue("declaring class is canonical", typeBinding == methodBinding2.getDeclaringClass()); //$NON-NLS-1$
+ ITypeBinding[] exceptionTypes2 = methodBinding2.getExceptionTypes();
+ assertNotNull("No exception types", exceptionTypes2); //$NON-NLS-1$
+ assertEquals("No exception", 0, exceptionTypes2.length); //$NON-NLS-1$
+ assertEquals("wrong modifier", Modifier.PUBLIC | Modifier.STATIC, methodBinding2.getModifiers()); //$NON-NLS-1$
+ assertEquals("wrong name for method", "main", methodBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ITypeBinding[] parameters2 = methodBinding2.getParameterTypes();
+ assertNotNull("No parameters", parameters2); //$NON-NLS-1$
+ assertEquals("wrong size", 1, parameters2.length); //$NON-NLS-1$
+ assertEquals("wrong type for parameter2[0]", "String[]", parameters2[0].getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong return type", "void", methodBinding2.getReturnType().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("A constructor", !methodBinding2.isConstructor()); //$NON-NLS-1$
+
+ MethodDeclaration method3 = (MethodDeclaration) bodyDeclarations.get(2);
+ IMethodBinding methodBinding3 = method3.resolveBinding();
+ assertNotNull("No method binding for main", methodBinding3); //$NON-NLS-1$
+ methodBinding = null;
+ loop: for (int i = 0, max = methods.length; i < max; i++) {
+ IMethodBinding currentMethod = methods[i];
+ if ("bar".equals(currentMethod.getName())) {
+ methodBinding = currentMethod;
+ break loop;
+ }
+ }
+ assertNotNull("Cannot be null", methodBinding);
+ assertTrue("Canonical method binding", methodBinding3 == methodBinding); //$NON-NLS-1$
+ assertTrue("declaring class is canonical", typeBinding == methodBinding3.getDeclaringClass()); //$NON-NLS-1$
+ ITypeBinding[] exceptionTypes3 = methodBinding3.getExceptionTypes();
+ assertNotNull("No exception types", exceptionTypes3); //$NON-NLS-1$
+ assertEquals("No exception", 1, exceptionTypes3.length); //$NON-NLS-1$
+ assertEquals("wrong modifier", Modifier.PRIVATE, methodBinding3.getModifiers()); //$NON-NLS-1$
+ assertEquals("wrong name for method", "bar", methodBinding3.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ITypeBinding[] parameters3 = methodBinding3.getParameterTypes();
+ assertNotNull("No parameters", parameters3); //$NON-NLS-1$
+ assertEquals("wrong size", 1, parameters3.length); //$NON-NLS-1$
+ assertEquals("wrong type", "String", parameters3[0].getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong return type", "String", methodBinding3.getReturnType().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("A constructor", !methodBinding3.isConstructor()); //$NON-NLS-1$
+ assertTrue("The binding is not canonical", parameters3[0] == methodBinding3.getReturnType()); //$NON-NLS-1$
+ }
+
+ /**
+ * i++; IVariableBinding
+ */
+ public void test0173() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0173", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("Not an expressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression ex = expressionStatement.getExpression();
+ assertTrue("Not a postfixexpression", ex instanceof PostfixExpression); //$NON-NLS-1$
+ PostfixExpression postfixExpression = (PostfixExpression) ex;
+ Expression expr = postfixExpression.getOperand();
+ assertTrue("Not a simpleName", expr instanceof SimpleName); //$NON-NLS-1$
+ SimpleName name = (SimpleName) expr;
+ assertTrue("a declaration", !name.isDeclaration()); //$NON-NLS-1$
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("VariableDeclarationStatement", node2 instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node2;
+ List fragments = variableDeclarationStatement.fragments();
+ assertTrue("No fragment", fragments.size() == 1); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertTrue(variableBinding == binding);
+ }
+
+ /**
+ * i++; IVariableBinding (field)
+ */
+ public void test0174() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0174", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 1, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("Not an expressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression ex = expressionStatement.getExpression();
+ assertTrue("Not a postfixexpression", ex instanceof PostfixExpression); //$NON-NLS-1$
+ PostfixExpression postfixExpression = (PostfixExpression) ex;
+ Expression expr = postfixExpression.getOperand();
+ assertTrue("Not a simpleName", expr instanceof SimpleName); //$NON-NLS-1$
+ SimpleName name = (SimpleName) expr;
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("FieldDeclaration", node2 instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node2;
+ List fragments = fieldDeclaration.fragments();
+ assertTrue("No fragment", fragments.size() == 1); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertTrue(variableBinding == binding);
+ }
+
+ /**
+ * int i = 0; Test IntBinding for the field declaration and the 0 literal
+ */
+ public void test0175() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0175", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("VariableDeclarationStatement", node2 instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node2;
+ List fragments = fieldDeclaration.fragments();
+ assertTrue("No fragment", fragments.size() == 1); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ ITypeBinding typeBinding = fragment.getInitializer().resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertTrue("Not a primitive type", typeBinding.isPrimitive()); //$NON-NLS-1$
+ assertEquals("Not int", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue(variableBinding.getType() == typeBinding);
+ }
+
+ /**
+ * ThisReference
+ */
+ public void test0176() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0176", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 1, 0);
+ assertTrue("Return statement", node2 instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node2;
+ assertTrue("Not a field access", returnStatement.getExpression() instanceof FieldAccess); //$NON-NLS-1$
+ FieldAccess fieldAccess = (FieldAccess) returnStatement.getExpression();
+ ITypeBinding typeBinding = fieldAccess.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertTrue("Not a primitive type", typeBinding.isPrimitive()); //$NON-NLS-1$
+ assertEquals("Not int", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Expression expr = fieldAccess.getExpression();
+ assertTrue("Not a this expression", expr instanceof ThisExpression); //$NON-NLS-1$
+ ThisExpression thisExpression = (ThisExpression) expr;
+ ITypeBinding typeBinding2 = thisExpression.resolveTypeBinding();
+ assertNotNull("No type binding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("Not Test", "Test", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * i++; IVariableBinding
+ */
+ public void test0177() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0177", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 1, 1);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("Not an expressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression ex = expressionStatement.getExpression();
+ assertTrue("Not a postfixexpression", ex instanceof PostfixExpression); //$NON-NLS-1$
+ PostfixExpression postfixExpression = (PostfixExpression) ex;
+ Expression expr = postfixExpression.getOperand();
+ assertTrue("Not a simpleName", expr instanceof SimpleName); //$NON-NLS-1$
+ SimpleName name = (SimpleName) expr;
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 1, 0);
+ assertTrue("VariableDeclarationStatement", node2 instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node2;
+ List fragments = variableDeclarationStatement.fragments();
+ assertTrue("No fragment", fragments.size() == 1); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertEquals("return type is not int", "int", variableBinding.getType().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue(variableBinding == binding);
+ }
+
+ /**
+ * SuperReference
+ */
+ public void test0178() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0178", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 1, 0, 0);
+ assertTrue("Return statement", node2 instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node2;
+ Expression expr = returnStatement.getExpression();
+ assertTrue("Not a field access", expr instanceof SuperFieldAccess); //$NON-NLS-1$
+ SuperFieldAccess fieldAccess = (SuperFieldAccess) expr;
+ ITypeBinding typeBinding = fieldAccess.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertTrue("Not a primitive type", typeBinding.isPrimitive()); //$NON-NLS-1$
+ assertEquals("Not int", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Allocation expression
+ */
+ public void test0179() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0179", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("VariableDeclarationStatement", node2 instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node2;
+ List fragments = variableDeclarationStatement.fragments();
+ assertTrue("No fragment", fragments.size() == 1); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ Expression initialization = fragment.getInitializer();
+ ITypeBinding typeBinding = initialization.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertTrue(variableBinding.getType() == typeBinding);
+ }
+
+ /**
+ * Allocation expression
+ */
+ public void test0180() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0180", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("VariableDeclarationStatement", node2 instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node2;
+ List fragments = variableDeclarationStatement.fragments();
+ assertTrue("No fragment", fragments.size() == 1); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ Expression initialization = fragment.getInitializer();
+ assertTrue("No an array creation", initialization instanceof ArrayCreation); //$NON-NLS-1$
+ ITypeBinding typeBinding = initialization.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertTrue("Not an array", typeBinding.isArray()); //$NON-NLS-1$
+ assertTrue(variableBinding.getType() == typeBinding);
+ }
+
+ /**
+ * Allocation expression
+ */
+ public void test0181() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0181", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("VariableDeclarationStatement", node2 instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node2;
+ List fragments = variableDeclarationStatement.fragments();
+ assertTrue("No fragment", fragments.size() == 1); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ Expression initialization = fragment.getInitializer();
+ ITypeBinding typeBinding = initialization.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertTrue("Not an array", typeBinding.isArray()); //$NON-NLS-1$
+ assertTrue(variableBinding.getType() == typeBinding);
+ }
+
+ /**
+ * BinaryExpression
+ */
+ public void test0182() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0182", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertTrue("IfStatement", node2 instanceof IfStatement); //$NON-NLS-1$
+ IfStatement ifStatement = (IfStatement) node2;
+ Expression expr = ifStatement.getExpression();
+ assertNotNull("No condition", expr); //$NON-NLS-1$
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not a boolean", "boolean", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(expr, "i < 10", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression
+ */
+ public void test0183() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0183", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertTrue("IfStatement", node2 instanceof IfStatement); //$NON-NLS-1$
+ IfStatement ifStatement = (IfStatement) node2;
+ Expression expr = ifStatement.getExpression();
+ assertNotNull("No condition", expr); //$NON-NLS-1$
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not a boolean", "boolean", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(expr, "i < 10 && i < 20", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression
+ */
+ public void test0184() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0184", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertTrue("IfStatement", node2 instanceof IfStatement); //$NON-NLS-1$
+ IfStatement ifStatement = (IfStatement) node2;
+ Expression expr = ifStatement.getExpression();
+ assertNotNull("No condition", expr); //$NON-NLS-1$
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not a boolean", "boolean", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(expr, "i < 10 || i < 20", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression
+ */
+ public void test0185() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0185", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertTrue("IfStatement", node2 instanceof IfStatement); //$NON-NLS-1$
+ IfStatement ifStatement = (IfStatement) node2;
+ Expression expr = ifStatement.getExpression();
+ assertNotNull("No condition", expr); //$NON-NLS-1$
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not a boolean", "boolean", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(expr, "i == 10", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression
+ */
+ public void test0186() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0186", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertTrue("IfStatement", node2 instanceof IfStatement); //$NON-NLS-1$
+ IfStatement ifStatement = (IfStatement) node2;
+ Expression expr = ifStatement.getExpression();
+ assertNotNull("No condition", expr); //$NON-NLS-1$
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not a boolean", "boolean", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(expr, "o == o", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression
+ */
+ public void test0187() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0187", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertTrue("IfStatement", node2 instanceof WhileStatement); //$NON-NLS-1$
+ WhileStatement whileStatement = (WhileStatement) node2;
+ Expression expr = whileStatement.getExpression();
+ assertNotNull("No condition", expr); //$NON-NLS-1$
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not a boolean", "boolean", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(expr, "i <= 10", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression
+ */
+ public void test0188() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0188", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 2);
+ assertTrue("DoStatement", node2 instanceof DoStatement); //$NON-NLS-1$
+ DoStatement statement = (DoStatement) node2;
+ Expression expr = statement.getExpression();
+ assertNotNull("No condition", expr); //$NON-NLS-1$
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not a boolean", "boolean", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(expr, "i <= 10", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression
+ */
+ public void test0189() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0189", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("ForStatement", node2 instanceof ForStatement); //$NON-NLS-1$
+ ForStatement statement = (ForStatement) node2;
+ Expression expr = statement.getExpression();
+ assertNotNull("No condition", expr); //$NON-NLS-1$
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not a boolean", "boolean", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(expr, "i < 10", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression
+ */
+ public void test0190() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0190", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 2, 1);
+ assertTrue("IfStatement", node2 instanceof IfStatement); //$NON-NLS-1$
+ IfStatement statement = (IfStatement) node2;
+ Expression expr = statement.getExpression();
+ assertNotNull("No condition", expr); //$NON-NLS-1$
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not a boolean", "boolean", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(expr, "scanner.x < selection.start && selection.start < scanner.y", source); //$NON-NLS-1$
+ }
+
+ /**
+ * BinaryExpression
+ */
+ public void test0191() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0191", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertTrue("ExpressionStatement", node2 instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node2;
+ Expression ex = expressionStatement.getExpression();
+ assertTrue("Assignment", ex instanceof Assignment); //$NON-NLS-1$
+ Assignment statement = (Assignment) ex;
+ Expression rightExpr = statement.getRightHandSide();
+ assertTrue("Not an infix expression", rightExpr instanceof InfixExpression); //$NON-NLS-1$
+ InfixExpression infixExpression = (InfixExpression) rightExpr;
+ Expression expr = infixExpression.getRightOperand();
+ assertNotNull("No right hand side expression", expr); //$NON-NLS-1$
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not a boolean", "boolean", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(expr, "2 < 20", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Initializer
+ */
+ public void test0192() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0192", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("VariableDeclarationStatement", node2 instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node2;
+ List fragments = variableDeclarationStatement.fragments();
+ assertTrue("No fragment", fragments.size() == 1); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ Expression initialization = fragment.getInitializer();
+ ITypeBinding typeBinding = initialization.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertTrue(variableBinding.getType() == typeBinding);
+ checkSourceRange(initialization, "0", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Initializer
+ */
+ public void test0193() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0193", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 1, 0);
+ assertTrue("VariableDeclarationStatement", node2 instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node2;
+ List fragments = variableDeclarationStatement.fragments();
+ assertTrue("No fragment", fragments.size() == 1); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ Expression initialization = fragment.getInitializer();
+ ITypeBinding typeBinding = initialization.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertTrue(variableBinding.getType() == typeBinding);
+ checkSourceRange(initialization, "new Inner()", source); //$NON-NLS-1$
+ assertEquals("Wrong type", "Inner", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Initializer
+ */
+ public void test0194() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0194", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 1, 0);
+ assertTrue("VariableDeclarationStatement", node2 instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node2;
+ List fragments = variableDeclarationStatement.fragments();
+ assertTrue("No fragment", fragments.size() == 1); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ Expression initialization = fragment.getInitializer();
+ ITypeBinding typeBinding = initialization.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertTrue(variableBinding.getType() == typeBinding);
+ checkSourceRange(initialization, "new Inner[10]", source); //$NON-NLS-1$
+ assertTrue("Not an array", typeBinding.isArray()); //$NON-NLS-1$
+ assertEquals("Wrong type", "Inner[]", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Initializer
+ */
+ public void test0195() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0195", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 1, 0, 1);
+ assertTrue("ExpressionStatement", node2 instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node2;
+ Expression ex = expressionStatement.getExpression();
+ assertTrue("MethodInvocation", ex instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) ex;
+ checkSourceRange(methodInvocation, "a.useFile(/*]*/a.getFile()/*[*/)", source); //$NON-NLS-1$
+ List list = methodInvocation.arguments();
+ assertTrue("Parameter list not empty", list.size() == 1); //$NON-NLS-1$
+ Expression parameter = (Expression) list.get(0);
+ assertTrue("Not a method invocation", parameter instanceof MethodInvocation); //$NON-NLS-1$
+ ITypeBinding typeBinding = parameter.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not a boolean", "File", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(parameter, "a.getFile()", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Initializer
+ */
+ public void test0196() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0196", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 1, 2);
+ assertTrue("ExpressionStatement", node2 instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node2;
+ Expression ex = expressionStatement.getExpression();
+ assertTrue("Assignment", ex instanceof Assignment); //$NON-NLS-1$
+ Assignment statement = (Assignment) ex;
+ Expression rightExpr = statement.getRightHandSide();
+ assertTrue("Not an instanceof expression", rightExpr instanceof InstanceofExpression); //$NON-NLS-1$
+ ITypeBinding typeBinding = rightExpr.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("wrong type", "boolean", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(rightExpr, "inner instanceof Inner", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Initializer
+ */
+ public void test0197() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0197", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType());
+ CompilationUnit unit = (CompilationUnit) result;
+ assertProblemsSize(unit, 0);
+ ASTNode node2 = getASTNode(unit, 1, 0, 1);
+ assertTrue("ExpressionStatement", node2 instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node2;
+ Expression ex = expressionStatement.getExpression();
+ assertTrue("MethodInvocation", ex instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) ex;
+ checkSourceRange(methodInvocation, "a.getFile()/*[*/.getName()", source); //$NON-NLS-1$
+ Expression receiver = methodInvocation.getExpression();
+ assertTrue("Not a method invocation", receiver instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation2 = (MethodInvocation) receiver;
+ ITypeBinding typeBinding = methodInvocation2.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "File", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(methodInvocation2, "a.getFile()", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Initializer
+ */
+ public void test0198() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0198", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("ReturnStatement", node2 instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node2;
+ Expression expr = returnStatement.getExpression();
+ assertTrue("Not an infixExpression", expr instanceof InfixExpression); //$NON-NLS-1$
+ InfixExpression infixExpression = (InfixExpression) expr;
+ Expression left = infixExpression.getLeftOperand();
+ assertTrue("Not an InfixExpression", left instanceof InfixExpression); //$NON-NLS-1$
+ InfixExpression infixExpression2 = (InfixExpression) left;
+ Expression right = infixExpression2.getRightOperand();
+ assertTrue("Not an InfixExpression", right instanceof InfixExpression); //$NON-NLS-1$
+ InfixExpression infixExpression3 = (InfixExpression) right;
+ assertEquals("A multiplication", InfixExpression.Operator.TIMES, infixExpression3.getOperator()); //$NON-NLS-1$
+ ITypeBinding typeBinding = infixExpression3.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not int", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(infixExpression3, "20 * 30", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Initializer
+ */
+ public void test0199() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0199", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("VariableDeclarationStatement", node2 instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node2;
+ List fragments = variableDeclarationStatement.fragments();
+ assertTrue("No fragment", fragments.size() == 1); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression initialization = fragment.getInitializer();
+ assertTrue("Not an infixExpression", initialization instanceof InfixExpression); //$NON-NLS-1$
+ InfixExpression infixExpression = (InfixExpression) initialization;
+ Expression left = infixExpression.getLeftOperand();
+ assertTrue("Not an InfixExpression", left instanceof InfixExpression); //$NON-NLS-1$
+ InfixExpression infixExpression2 = (InfixExpression) left;
+ Expression right = infixExpression2.getRightOperand();
+ assertTrue("Not an InfixExpression", right instanceof InfixExpression); //$NON-NLS-1$
+ InfixExpression infixExpression3 = (InfixExpression) right;
+ assertEquals("A multiplication", InfixExpression.Operator.TIMES, infixExpression3.getOperator()); //$NON-NLS-1$
+ ITypeBinding typeBinding = infixExpression3.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not int", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(infixExpression3, "10 * 30", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Initializer
+ */
+ public void test0200() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0200", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 1, 0, 0);
+ assertTrue("VariableDeclarationStatement", node2 instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node2;
+ List fragments = variableDeclarationStatement.fragments();
+ assertTrue("No fragment", fragments.size() == 1); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression initialization = fragment.getInitializer();
+ assertTrue("Not an infixExpression", initialization instanceof FieldAccess); //$NON-NLS-1$
+ FieldAccess fieldAccess = (FieldAccess) initialization;
+ Expression receiver = fieldAccess.getExpression();
+ assertTrue("ArrayCreation", receiver instanceof ArrayCreation); //$NON-NLS-1$
+ ArrayCreation arrayCreation = (ArrayCreation) receiver;
+ List dimensions = arrayCreation.dimensions();
+ assertEquals("Wrong dimension", 1, dimensions.size()); //$NON-NLS-1$
+ Expression dim = (Expression) dimensions.get(0);
+ assertTrue("InfixExpression", dim instanceof InfixExpression); //$NON-NLS-1$
+ InfixExpression infixExpression = (InfixExpression) dim;
+ ITypeBinding typeBinding = infixExpression.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not int", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(infixExpression, "1 + 2", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Position inside for statement: PR 3300
+ */
+ public void test0201() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0201", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertTrue("ForStatement", node2 instanceof ForStatement); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node2;
+ List initializers = forStatement.initializers();
+ assertTrue("wrong size", initializers.size() == 1); //$NON-NLS-1$
+ Expression init = (Expression) initializers.get(0);
+ checkSourceRange(init, "int i= 0", source); //$NON-NLS-1$
+ }
+
+ /**
+ * PR 7386
+ */
+ public void test0202() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0202", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("FieldDeclaration", node2 instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node2;
+ checkSourceRange(fieldDeclaration, "int f= (2);", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression initialization = fragment.getInitializer();
+ assertTrue("Not a parenthesized expression", initialization instanceof ParenthesizedExpression); //$NON-NLS-1$
+ checkSourceRange(initialization, "(2)", source); //$NON-NLS-1$
+ ITypeBinding typeBinding = initialization.resolveTypeBinding();
+ assertNotNull("no binding", typeBinding); //$NON-NLS-1$
+ assertEquals("not int", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * PR 7386
+ */
+ public void test0203() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0203", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("FieldDeclaration", node2 instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node2;
+ checkSourceRange(fieldDeclaration, "int f= (2);", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression initialization = fragment.getInitializer();
+ assertTrue("Not a parenthesized expression", initialization instanceof ParenthesizedExpression); //$NON-NLS-1$
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) initialization;
+ checkSourceRange(parenthesizedExpression, "(2)", source); //$NON-NLS-1$
+ Expression expr = parenthesizedExpression.getExpression();
+ checkSourceRange(expr, "2", source); //$NON-NLS-1$
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("no binding", typeBinding); //$NON-NLS-1$
+ assertEquals("not int", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("type binding is canonical", typeBinding == parenthesizedExpression.resolveTypeBinding()); //$NON-NLS-1$
+ }
+
+ /**
+ * PR 7386
+ */
+ public void test0204() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0204", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("FieldDeclaration", node2 instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node2;
+ checkSourceRange(fieldDeclaration, "int f= ((2));", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression initialization = fragment.getInitializer();
+ assertTrue("Not a parenthesized expression", initialization instanceof ParenthesizedExpression); //$NON-NLS-1$
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) initialization;
+ checkSourceRange(parenthesizedExpression, "((2))", source); //$NON-NLS-1$
+ Expression expr = parenthesizedExpression.getExpression();
+ assertTrue("Not a parenthesized expression", expr instanceof ParenthesizedExpression); //$NON-NLS-1$
+ ParenthesizedExpression parenthesizedExpression2 = (ParenthesizedExpression) expr;
+ checkSourceRange(parenthesizedExpression2, "(2)", source); //$NON-NLS-1$
+ expr = parenthesizedExpression2.getExpression();
+ checkSourceRange(expr, "2", source); //$NON-NLS-1$
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("no binding", typeBinding); //$NON-NLS-1$
+ assertEquals("not int", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = parenthesizedExpression.resolveTypeBinding();
+ assertNotNull("no binding", typeBinding); //$NON-NLS-1$
+ assertEquals("not int", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("type binding is canonical", typeBinding == parenthesizedExpression2.resolveTypeBinding()); //$NON-NLS-1$
+ }
+
+
+ /**
+ * Local class end position when trailing comment
+ * @deprecated using deprecated code
+ */
+ public void test0205() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0205", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("TypeDeclarationStatement", node2 instanceof TypeDeclarationStatement); //$NON-NLS-1$
+ TypeDeclarationStatement typeDeclarationStatement = (TypeDeclarationStatement) node2;
+ TypeDeclaration typeDeclaration = typeDeclarationStatement.getTypeDeclaration();
+ assertEquals("wrong name", "AA", typeDeclaration.getName().getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(typeDeclaration, "class AA extends Test {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * QualifiedName
+ */
+ public void test0206() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0206", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 5, 0);
+ assertTrue("ReturnStatement", node2 instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node2;
+ Expression expr = returnStatement.getExpression();
+ assertTrue("Not a qualifiedName", expr instanceof QualifiedName); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) expr;
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not an int (typeBinding)", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(qualifiedName, "field1.field2.field3.field4.i", source); //$NON-NLS-1$
+ assertTrue("Not a simple name", qualifiedName.getName().isSimpleName()); //$NON-NLS-1$
+ SimpleName simpleName = qualifiedName.getName();
+ assertTrue("a declaration", !simpleName.isDeclaration()); //$NON-NLS-1$
+ checkSourceRange(simpleName, "i", source); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = simpleName.resolveTypeBinding();
+ assertNotNull("No typebinding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("Not an int (typeBinding2)", "int", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("VariableBinding", binding instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Not Test", "Test", variableBinding.getDeclaringClass().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Not default", Modifier.PUBLIC, variableBinding.getModifiers()); //$NON-NLS-1$
+ Name qualifierName = qualifiedName.getQualifier();
+ assertTrue("Not a qualified name", qualifierName.isQualifiedName()); //$NON-NLS-1$
+ checkSourceRange(qualifierName, "field1.field2.field3.field4", source); //$NON-NLS-1$
+ ITypeBinding typeBinding5 = qualifierName.resolveTypeBinding();
+ assertNotNull("No binding5", typeBinding5); //$NON-NLS-1$
+ assertEquals("Not Test", "Test", typeBinding5.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+
+ qualifiedName = (QualifiedName) qualifierName;
+ simpleName = qualifiedName.getName();
+ checkSourceRange(simpleName, "field4", source); //$NON-NLS-1$
+ ITypeBinding typeBinding6 = simpleName.resolveTypeBinding();
+ assertNotNull("No binding6", typeBinding6); //$NON-NLS-1$
+ assertEquals("Not Test", "Test", typeBinding6.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+
+ qualifierName = qualifiedName.getQualifier();
+ assertTrue("Not a qualified name", qualifierName.isQualifiedName()); //$NON-NLS-1$
+ checkSourceRange(qualifierName, "field1.field2.field3", source); //$NON-NLS-1$
+ ITypeBinding typeBinding7 = qualifierName.resolveTypeBinding();
+ assertNotNull("No binding7", typeBinding7); //$NON-NLS-1$
+ assertEquals("Not Test", "Test", typeBinding7.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+
+ qualifiedName = (QualifiedName) qualifierName;
+ simpleName = qualifiedName.getName();
+ checkSourceRange(simpleName, "field3", source); //$NON-NLS-1$
+ qualifierName = qualifiedName.getQualifier();
+ assertTrue("Not a qualified name", qualifierName.isQualifiedName()); //$NON-NLS-1$
+ checkSourceRange(qualifierName, "field1.field2", source); //$NON-NLS-1$
+ ITypeBinding typeBinding3 = qualifierName.resolveTypeBinding();
+ assertNotNull("No binding3", typeBinding3); //$NON-NLS-1$
+ assertEquals("Not Test", "Test", typeBinding3.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ qualifiedName = (QualifiedName) qualifierName;
+ simpleName = qualifiedName.getName();
+ checkSourceRange(simpleName, "field2", source); //$NON-NLS-1$
+ qualifierName = qualifiedName.getQualifier();
+ assertTrue("Not a simple name", qualifierName.isSimpleName()); //$NON-NLS-1$
+ assertTrue("a declaration", !((SimpleName)qualifierName).isDeclaration()); //$NON-NLS-1$
+ checkSourceRange(qualifierName, "field1", source); //$NON-NLS-1$
+ ITypeBinding typeBinding4 = qualifierName.resolveTypeBinding();
+ assertNotNull("No binding4", typeBinding4); //$NON-NLS-1$
+ assertEquals("Not Test", "Test", typeBinding4.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Check javadoc for MethodDeclaration
+ * @deprecated marking deprecated since using deprecated code
+ */
+ public void test0207() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0207", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a MethodDeclaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((MethodDeclaration) node).getJavadoc();
+ Javadoc javadoc = this.ast.newJavadoc();
+ javadoc.setComment("/** JavaDoc Comment*/");//$NON-NLS-1$*/
+ assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(new ASTMatcher(), actualJavadoc));//$NON-NLS-1$
+ checkSourceRange(node, "/** JavaDoc Comment*/\n void foo(final int i) {}", source); //$NON-NLS-1$
+ checkSourceRange(actualJavadoc, "/** JavaDoc Comment*/", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for MethodDeclaration
+ */
+ public void test0208() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0208", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a MethodDeclaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((MethodDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "void foo(final int i) {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for MethodDeclaration
+ */
+ public void test0209() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0209", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a MethodDeclaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((MethodDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "void foo(final int i) {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for FieldDeclaration
+ * @deprecated marking deprecated since using deprecated code
+ */
+ public void test0210() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0210", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a FieldDeclaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((FieldDeclaration) node).getJavadoc();
+ Javadoc javadoc = this.ast.newJavadoc();
+ javadoc.setComment("/** JavaDoc Comment*/");//$NON-NLS-1$*/
+ assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(new ASTMatcher(), actualJavadoc));//$NON-NLS-1$
+ checkSourceRange(node, "/** JavaDoc Comment*/\n int i;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for FieldDeclaration
+ */
+ public void test0211() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0211", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a FieldDeclaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((FieldDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "int i;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for FieldDeclaration
+ */
+ public void test0212() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0212", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a FieldDeclaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((FieldDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "int i;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for TypeDeclaration
+ */
+ public void test0213() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0213", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ String expectedContents = "public class Test {\n" +//$NON-NLS-1$
+ " int i;\n" +//$NON-NLS-1$
+ "}";//$NON-NLS-1$
+ checkSourceRange(node, expectedContents, source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for TypeDeclaration
+ */
+ public void test0214() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0214", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ String expectedContents = "public class Test {\n" +//$NON-NLS-1$
+ " int i;\n" +//$NON-NLS-1$
+ "}";//$NON-NLS-1$
+ checkSourceRange(node, expectedContents, source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for TypeDeclaration
+ * @deprecated marking deprecated since using deprecated code
+ */
+ public void test0215() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0215", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ Javadoc javadoc = this.ast.newJavadoc();
+ javadoc.setComment("/** JavaDoc Comment*/");//$NON-NLS-1$*/
+ assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(new ASTMatcher(), actualJavadoc));//$NON-NLS-1$
+ String expectedContents =
+ "/** JavaDoc Comment*/\n" + //$NON-NLS-1$
+ "public class Test {\n" +//$NON-NLS-1$
+ " int i;\n" +//$NON-NLS-1$
+ "}";//$NON-NLS-1$
+ checkSourceRange(node, expectedContents, source); //$NON-NLS-1$
+ checkSourceRange(actualJavadoc, "/** JavaDoc Comment*/", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for MemberTypeDeclaration
+ * @deprecated marking deprecated since using deprecated code
+ */
+ public void test0216() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0216", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ Javadoc javadoc = this.ast.newJavadoc();
+ javadoc.setComment("/** JavaDoc Comment*/");//$NON-NLS-1$*/
+ assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(new ASTMatcher(), actualJavadoc));//$NON-NLS-1$
+ String expectedContents =
+ "/** JavaDoc Comment*/\n" + //$NON-NLS-1$
+ " class B {}";//$NON-NLS-1$
+ checkSourceRange(node, expectedContents, source); //$NON-NLS-1$
+ checkSourceRange(actualJavadoc, "/** JavaDoc Comment*/", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for MemberTypeDeclaration
+ */
+ public void test0217() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0217", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "class B {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for MemberTypeDeclaration
+ */
+ public void test0218() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0218", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "public static class B {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check javadoc for MemberTypeDeclaration
+ */
+ public void test0219() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0219", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ assertTrue("The node is not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((TypeDeclaration) node).getJavadoc();
+ assertTrue("Javadoc must be null", actualJavadoc == null);//$NON-NLS-1$
+ checkSourceRange(node, "public static class B {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking initializers
+ */
+ public void test0220() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0220", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ checkSourceRange(node, "{}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking initializers
+ */
+ public void test0221() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0221", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ checkSourceRange(node, "static {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking initializers
+ * @deprecated marking deprecated since using deprecated code
+ */
+ public void test0222() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0222", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((Initializer) node).getJavadoc();
+ assertNotNull("Javadoc comment should no be null", actualJavadoc); //$NON-NLS-1$
+ Javadoc javadoc = this.ast.newJavadoc();
+ javadoc.setComment("/** JavaDoc Comment*/");//$NON-NLS-1$*/
+ assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(new ASTMatcher(), actualJavadoc));//$NON-NLS-1$
+ String expectedContents =
+ "/** JavaDoc Comment*/\n" + //$NON-NLS-1$
+ " static {}";//$NON-NLS-1$
+ checkSourceRange(node, expectedContents, source); //$NON-NLS-1$
+ checkSourceRange(actualJavadoc, "/** JavaDoc Comment*/", source); //$NON-NLS-1$
+
+ }
+
+ /**
+ * Checking initializers
+ * @deprecated marking deprecated since using deprecated code
+ */
+ public void test0223() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0223", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((Initializer) node).getJavadoc();
+ assertNotNull("Javadoc comment should not be null", actualJavadoc); //$NON-NLS-1$
+ Javadoc javadoc = this.ast.newJavadoc();
+ javadoc.setComment("/** JavaDoc Comment*/");//$NON-NLS-1$*/
+ assertTrue("Both AST trees should be identical", javadoc.subtreeMatch(new ASTMatcher(), actualJavadoc));//$NON-NLS-1$
+ String expectedContents =
+ "/** JavaDoc Comment*/\n" + //$NON-NLS-1$
+ " {}";//$NON-NLS-1$
+ checkSourceRange(node, expectedContents, source); //$NON-NLS-1$
+ checkSourceRange(actualJavadoc, "/** JavaDoc Comment*/", source); //$NON-NLS-1$
+
+ }
+
+ /**
+ * Checking initializers
+ */
+ public void test0224() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0224", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ Javadoc actualJavadoc = ((Initializer) node).getJavadoc();
+ assertNull("Javadoc comment should be null", actualJavadoc); //$NON-NLS-1$
+ checkSourceRange(node, "{}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Continue ==> ContinueStatement
+ */
+ public void test0225() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0225", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ LabeledStatement labeledStatement = (LabeledStatement) getASTNode((CompilationUnit) result, 0, 0, 0);
+ checkSourceRange(labeledStatement.getLabel(), "label", source); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) labeledStatement.getBody();
+ ContinueStatement statement = (ContinueStatement) ((Block) forStatement.getBody()).statements().get(0);
+ assertNotNull("Expression should not be null", statement); //$NON-NLS-1$
+ ContinueStatement continueStatement = this.ast.newContinueStatement();
+ continueStatement.setLabel(this.ast.newSimpleName("label")); //$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", continueStatement.subtreeMatch(new ASTMatcher(), statement)); //$NON-NLS-1$
+ checkSourceRange(statement, "continue label;", source); //$NON-NLS-1$
+ checkSourceRange(statement.getLabel(), "label", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Break + label ==> BreakStatement
+ */
+ public void test0226() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0226", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ LabeledStatement labeledStatement = (LabeledStatement) getASTNode((CompilationUnit) result, 0, 0, 0);
+ checkSourceRange(labeledStatement.getLabel(), "label", source); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) labeledStatement.getBody();
+ BreakStatement statement = (BreakStatement) ((Block) forStatement.getBody()).statements().get(0);
+ assertNotNull("Expression should not be null", statement); //$NON-NLS-1$
+ BreakStatement breakStatement = this.ast.newBreakStatement();
+ breakStatement.setLabel(this.ast.newSimpleName("label")); //$NON-NLS-1$
+ assertTrue("Both AST trees should be identical", breakStatement.subtreeMatch(new ASTMatcher(), statement)); //$NON-NLS-1$
+ checkSourceRange(statement, "break label;", source); //$NON-NLS-1$
+ checkSourceRange(statement.getLabel(), "label", source); //$NON-NLS-1$
+ }
+
+ /**
+ * QualifiedName
+ */
+ public void test0227() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0227", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 3, 2, 0);
+ assertTrue("ReturnStatement", node2 instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node2;
+ Expression expr = returnStatement.getExpression();
+ assertTrue("Not a qualifiedName", expr instanceof QualifiedName); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) expr;
+ ITypeBinding typeBinding = expr.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not an long (typeBinding)", "long", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(qualifiedName, "field.fB.fA.j", source); //$NON-NLS-1$
+
+ SimpleName simpleName = qualifiedName.getName();
+ checkSourceRange(simpleName, "j", source); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = simpleName.resolveTypeBinding();
+ assertEquals("Not an long (typeBinding2)", "long", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("VariableBinding", binding instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Not A", "A", variableBinding.getDeclaringClass().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Not default", Modifier.NONE, variableBinding.getModifiers()); //$NON-NLS-1$
+ assertEquals("wrong name", "j", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+
+ Name qualifierName = qualifiedName.getQualifier();
+ assertTrue("Not a qualified name", qualifierName.isQualifiedName()); //$NON-NLS-1$
+ checkSourceRange(qualifierName, "field.fB.fA", source); //$NON-NLS-1$
+ qualifiedName = (QualifiedName) qualifierName;
+ ITypeBinding typeBinding3 = qualifiedName.resolveTypeBinding();
+ assertNotNull("No type binding3", typeBinding3); //$NON-NLS-1$
+ assertEquals("Not an A", "A", typeBinding3.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ simpleName = qualifiedName.getName();
+ checkSourceRange(simpleName, "fA", source); //$NON-NLS-1$
+ ITypeBinding typeBinding4 = simpleName.resolveTypeBinding();
+ assertNotNull("No typeBinding4", typeBinding4); //$NON-NLS-1$
+ assertEquals("Not an A", "A", typeBinding4.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding2 = qualifiedName.resolveBinding();
+ assertNotNull("No binding2", binding2); //$NON-NLS-1$
+ assertTrue("VariableBinding", binding2 instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding2 = (IVariableBinding) binding2;
+ assertEquals("Not B", "B", variableBinding2.getDeclaringClass().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Not default", Modifier.NONE, variableBinding2.getModifiers()); //$NON-NLS-1$
+ assertEquals("wrong name", "fA", variableBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+
+ qualifierName = qualifiedName.getQualifier();
+ assertTrue("Not a qualified name", qualifierName.isQualifiedName()); //$NON-NLS-1$
+ checkSourceRange(qualifierName, "field.fB", source); //$NON-NLS-1$
+ qualifiedName = (QualifiedName) qualifierName;
+ ITypeBinding typeBinding5 = qualifiedName.resolveTypeBinding();
+ assertNotNull("No typeBinding5", typeBinding5); //$NON-NLS-1$
+ assertEquals("Not a B", "B", typeBinding5.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ simpleName = qualifiedName.getName();
+ checkSourceRange(simpleName, "fB", source); //$NON-NLS-1$
+ ITypeBinding typeBinding6 = simpleName.resolveTypeBinding();
+ assertNotNull("No typebinding6", typeBinding6); //$NON-NLS-1$
+ assertEquals("not a B", "B", typeBinding6.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding3 = qualifiedName.resolveBinding();
+ assertNotNull("No binding2", binding3); //$NON-NLS-1$
+ assertTrue("VariableBinding", binding3 instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding3 = (IVariableBinding) binding3;
+ assertEquals("Not C", "C", variableBinding3.getDeclaringClass().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Not default", Modifier.NONE, variableBinding3.getModifiers()); //$NON-NLS-1$
+ assertEquals("wrong name", "fB", variableBinding3.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+
+ qualifierName = qualifiedName.getQualifier();
+ assertTrue("Not a simple name", qualifierName.isSimpleName()); //$NON-NLS-1$
+ checkSourceRange(qualifierName, "field", source); //$NON-NLS-1$
+ simpleName = (SimpleName) qualifierName;
+ ITypeBinding typeBinding7 = simpleName.resolveTypeBinding();
+ assertNotNull("No typeBinding7", typeBinding7); //$NON-NLS-1$
+ assertEquals("Not a C", "C", typeBinding7.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding4 = simpleName.resolveBinding();
+ assertNotNull("No binding4", binding4); //$NON-NLS-1$
+ assertTrue("VariableBinding", binding4 instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding4 = (IVariableBinding) binding4;
+ assertEquals("Not Test", "Test", variableBinding4.getDeclaringClass().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Not public", Modifier.PUBLIC, variableBinding4.getModifiers()); //$NON-NLS-1$
+ assertEquals("wrong name", "field", variableBinding4.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong return type", "C", variableBinding4.getType().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * QualifiedName as TypeReference
+ */
+ public void test0228() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0228", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 1, 0);
+ assertTrue("ReturnStatement", node2 instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node2;
+ Expression expr = returnStatement.getExpression();
+ checkSourceRange(expr, "test0228.Test.foo()", source); //$NON-NLS-1$
+ assertTrue("MethodInvocation", expr instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expr;
+ Expression qualifier = methodInvocation.getExpression();
+ assertNotNull("no qualifier", qualifier); //$NON-NLS-1$
+ assertTrue("QualifiedName", qualifier instanceof QualifiedName); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) qualifier;
+ checkSourceRange(qualifiedName, "test0228.Test", source); //$NON-NLS-1$
+ ITypeBinding typeBinding = qualifiedName.resolveTypeBinding();
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong type", "Test", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding = qualifiedName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("Not a type", IBinding.TYPE, binding.getKind()); //$NON-NLS-1$
+
+ }
+
+ /**
+ * MethodInvocation
+ */
+ public void test0229() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0229", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("ExpressionStatement", node2 instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node2;
+ Expression expr = expressionStatement.getExpression();
+ assertTrue("MethodInvocation", expr instanceof MethodInvocation); //$NON-NLS-1$
+ checkSourceRange(expr, "System.err.println()", source); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expr;
+ Expression qualifier = methodInvocation.getExpression();
+ assertTrue("QualifiedName", qualifier instanceof QualifiedName); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) qualifier;
+ ITypeBinding typeBinding = qualifier.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "PrintStream", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding = qualifiedName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("VariableBinding", binding instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("wrong name", "err", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ SimpleName methodName = methodInvocation.getName();
+ IBinding binding2 = methodName.resolveBinding();
+ assertNotNull("No binding2", binding2); //$NON-NLS-1$
+ }
+
+ /**
+ * MethodInvocation
+ */
+ public void test0230() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0230", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 1, 0);
+ assertTrue("ExpressionStatement", node2 instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node2;
+ Expression expr = expressionStatement.getExpression();
+ assertTrue("MethodInvocation", expr instanceof MethodInvocation); //$NON-NLS-1$
+ checkSourceRange(expr, "err.println()", source); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expr;
+ Expression qualifier = methodInvocation.getExpression();
+ assertTrue("SimpleName", qualifier instanceof SimpleName); //$NON-NLS-1$
+ SimpleName name = (SimpleName) qualifier;
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong name", "err", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ITypeBinding typeBinding = name.resolveTypeBinding();
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wron type name", "PrintStream", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * MethodInvocation
+ */
+ public void test0231() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0231", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("ExpressionStatement", node2 instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node2;
+ Expression expr = expressionStatement.getExpression();
+ assertTrue("MethodInvocation", expr instanceof MethodInvocation); //$NON-NLS-1$
+ checkSourceRange(expr, "System.err.println()", source); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expr;
+ Expression qualifier = methodInvocation.getExpression();
+ assertTrue("QualifiedName", qualifier instanceof QualifiedName); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) qualifier;
+ ITypeBinding typeBinding = qualifier.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "PrintStream", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding = qualifiedName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("VariableBinding", binding instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("wrong name", "err", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ SimpleName methodName = methodInvocation.getName();
+ IBinding binding2 = methodName.resolveBinding();
+ assertNotNull("No binding2", binding2); //$NON-NLS-1$
+ Name name = qualifiedName.getQualifier();
+ assertTrue("SimpleName", name.isSimpleName()); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) name;
+ ITypeBinding typeBinding2 = simpleName.resolveTypeBinding();
+ assertNotNull("No typeBinding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("wrong type name", "System", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * MethodInvocation
+ */
+ public void test0232() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0232", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node2 = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("VariableDeclarationStatement", node2 instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node2;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression initialization = variableDeclarationFragment.getInitializer();
+ ITypeBinding typeBinding = initialization.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertTrue("Not a primitive type", typeBinding.isPrimitive()); //$NON-NLS-1$
+ assertEquals("wrong name", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("QualifiedName", initialization instanceof QualifiedName); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) initialization;
+ SimpleName simpleName = qualifiedName.getName();
+ ITypeBinding typeBinding2 = simpleName.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding2); //$NON-NLS-1$
+ assertTrue("Not a primitive type", typeBinding2.isPrimitive()); //$NON-NLS-1$
+ assertEquals("wrong name", "int", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("IVariableBinding", binding instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertNull("No declaring class", variableBinding.getDeclaringClass()); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking that only syntax errors are reported for the MALFORMED tag
+ */
+ public void test0233() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0233", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("Expression should not be null", result); //$NON-NLS-1$
+ assertTrue("The compilation unit is malformed", !isMalformed(result)); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("The fiels is not malformed", !isMalformed(node)); //$NON-NLS-1$
+ assertEquals("No problem found", 1, unit.getMessages().length); //$NON-NLS-1$
+ assertEquals("No problem found", 1, unit.getProblems().length); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking that null is returned for a resolveBinding if the type is unknown
+ */
+ public void test0234() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0234", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true, true);
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("The fiels is not malformed", !isMalformed(node)); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("No problem found", 1, unit.getMessages().length); //$NON-NLS-1$
+ assertEquals("No problem found", 1, unit.getProblems().length); //$NON-NLS-1$
+ assertTrue("FieldDeclaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding); //$NON-NLS-1$
+ assertEquals("Ltest0234/Test;.field)LList;", variableBinding.getKey()); //$NON-NLS-1$
+ }
+
+ /**
+ * Checking that null is returned for a resolveBinding if the type is unknown
+ */
+ public void test0234_2() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0234", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true, false);
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("The fiels is not malformed", !isMalformed(node)); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("No problem found", 1, unit.getMessages().length); //$NON-NLS-1$
+ assertEquals("No problem found", 1, unit.getProblems().length); //$NON-NLS-1$
+ assertTrue("FieldDeclaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNull("Got a binding", variableBinding); //$NON-NLS-1$
+ }
+
+
+ /**
+ * Checking that null is returned for a resolveBinding if the type is unknown
+ */
+ public void test0235() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0235", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("The fiels is not malformed", !isMalformed(node)); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("problems found", 0, unit.getMessages().length); //$NON-NLS-1$
+ assertEquals("problems found", 0, unit.getProblems().length); //$NON-NLS-1$
+ assertTrue("FieldDeclaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding); //$NON-NLS-1$
+ }
+
+ /**
+ * Test the removal of a IField inside a CU that has an initializer
+ */
+ public void test0236() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0236", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType type = sourceUnit.getType("Test"); //$NON-NLS-1$
+ assertNotNull("No type", type); //$NON-NLS-1$
+ IField field = type.getField("i"); //$NON-NLS-1$
+ assertNotNull("No field", field); //$NON-NLS-1$
+ field.delete(true, null);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=9452
+ */
+ public void test0237() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "junit.framework", "TestCase.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ }
+
+ /**
+ * Check ThisExpression
+ * @deprecated using deprecated code
+ */
+ public void test0238() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0238", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ char[] source = sourceUnit.getSource().toCharArray();
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not a type declaration statement", node instanceof TypeDeclarationStatement); //$NON-NLS-1$
+ TypeDeclarationStatement typeDeclarationStatement = (TypeDeclarationStatement) node;
+ TypeDeclaration typeDecl = typeDeclarationStatement.getTypeDeclaration();
+ Object o = typeDecl.bodyDeclarations().get(0);
+ assertTrue("Not a method", o instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDecl = (MethodDeclaration) o;
+ Block block = methodDecl.getBody();
+ List statements = block.statements();
+ assertEquals("Not 1", 1, statements.size()); //$NON-NLS-1$
+ Statement stmt = (Statement) statements.get(0);
+ assertTrue("Not a return statement", stmt instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) stmt;
+ Expression expr = returnStatement.getExpression();
+ assertTrue("Not a method invocation", expr instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expr;
+ checkSourceRange(methodInvocation, "Test.this.bar()", source); //$NON-NLS-1$
+ Expression qualifier = methodInvocation.getExpression();
+ assertTrue("Not a ThisExpression", qualifier instanceof ThisExpression); //$NON-NLS-1$
+ ThisExpression thisExpression = (ThisExpression) qualifier;
+ Name name = thisExpression.getQualifier();
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("wrong name", "Test", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Check ThisExpression
+ * @deprecated using deprecated code
+ */
+ public void test0239() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0239", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 1, 0, 0);
+ assertTrue("Not a type declaration statement", node instanceof TypeDeclarationStatement); //$NON-NLS-1$
+ TypeDeclarationStatement typeDeclarationStatement = (TypeDeclarationStatement) node;
+ TypeDeclaration typeDecl = typeDeclarationStatement.getTypeDeclaration();
+ Object o = typeDecl.bodyDeclarations().get(0);
+ assertTrue("Not a method", o instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDecl = (MethodDeclaration) o;
+ Block block = methodDecl.getBody();
+ List statements = block.statements();
+ assertEquals("Not 1", 1, statements.size()); //$NON-NLS-1$
+ Statement stmt = (Statement) statements.get(0);
+ assertTrue("Not a return statement", stmt instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) stmt;
+ Expression expr = returnStatement.getExpression();
+ assertTrue("Not a SuperMethodInvocation", expr instanceof SuperMethodInvocation); //$NON-NLS-1$
+ SuperMethodInvocation superMethodInvocation = (SuperMethodInvocation) expr;
+ Name name = superMethodInvocation.getQualifier();
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("A type binding", binding instanceof ITypeBinding); //$NON-NLS-1$
+ assertEquals("Not Test", "Test", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Name methodName = superMethodInvocation.getName();
+ IBinding binding2 = methodName.resolveBinding();
+ assertNotNull("No binding2", binding2); //$NON-NLS-1$
+ assertTrue("No an IMethodBinding", binding2 instanceof IMethodBinding); //$NON-NLS-1$
+ IMethodBinding methodBinding = (IMethodBinding) binding2;
+ assertEquals("Not bar", "bar", methodBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Not T", "T", methodBinding.getDeclaringClass().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Check FieldAccess
+ * @deprecated using deprecated code
+ */
+ public void test0240() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0240", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not a type declaration statement", node instanceof TypeDeclarationStatement); //$NON-NLS-1$
+ TypeDeclarationStatement typeDeclarationStatement = (TypeDeclarationStatement) node;
+ TypeDeclaration typeDecl = typeDeclarationStatement.getTypeDeclaration();
+ Object o = typeDecl.bodyDeclarations().get(0);
+ assertTrue("Not a method", o instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDecl = (MethodDeclaration) o;
+ Block block = methodDecl.getBody();
+ List statements = block.statements();
+ assertEquals("Not 1", 1, statements.size()); //$NON-NLS-1$
+ Statement stmt = (Statement) statements.get(0);
+ assertTrue("Not a return statement", stmt instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) stmt;
+ Expression expr = returnStatement.getExpression();
+ assertTrue("Not a field access", expr instanceof FieldAccess); //$NON-NLS-1$
+ FieldAccess fieldAccess = (FieldAccess) expr;
+ Expression qualifier = fieldAccess.getExpression();
+ assertTrue("Not a ThisExpression", qualifier instanceof ThisExpression); //$NON-NLS-1$
+ ThisExpression thisExpression = (ThisExpression) qualifier;
+ Name name = thisExpression.getQualifier();
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("Not Test", "Test", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Name fieldName = fieldAccess.getName();
+ IBinding binding2 = fieldName.resolveBinding();
+ assertNotNull("No binding2", binding2); //$NON-NLS-1$
+ assertEquals("Wrong name", "f", binding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong modifier", Modifier.PUBLIC, binding2.getModifiers()); //$NON-NLS-1$
+ ITypeBinding typeBinding = fieldName.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Not int", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Check order of body declarations
+ */
+ public void test0241() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0241", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0);
+ assertTrue("Not a type declaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ assertTrue("Not a declaration", ((TypeDeclaration) node).getName().isDeclaration()); //$NON-NLS-1$
+ assertEquals("Wrong size", 11, ((TypeDeclaration)node).bodyDeclarations().size()); //$NON-NLS-1$
+ node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ node = getASTNode((CompilationUnit) result, 0, 1);
+ assertTrue("Not a MethodDeclaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ node = getASTNode((CompilationUnit) result, 0, 2);
+ assertTrue("Not a Type declaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ node = getASTNode((CompilationUnit) result, 0, 3);
+ assertTrue("Not a Type declaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ node = getASTNode((CompilationUnit) result, 0, 4);
+ assertTrue("Not a MethodDeclaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ node = getASTNode((CompilationUnit) result, 0, 5);
+ assertTrue("Not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ node = getASTNode((CompilationUnit) result, 0, 6);
+ assertTrue("Not a MethodDeclaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ node = getASTNode((CompilationUnit) result, 0, 7);
+ assertTrue("Not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ node = getASTNode((CompilationUnit) result, 0, 8);
+ assertTrue("Not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ node = getASTNode((CompilationUnit) result, 0, 9);
+ assertTrue("Not a MethodDeclaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ node = getASTNode((CompilationUnit) result, 0, 10);
+ assertTrue("Not a Type declaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ }
+
+ /**
+ * Check ThisExpression
+ * @deprecated using deprecated code
+ */
+ public void test0242() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0242", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 1, 0, 0);
+ assertTrue("Not a type declaration statement", node instanceof TypeDeclarationStatement); //$NON-NLS-1$
+ TypeDeclarationStatement typeDeclarationStatement = (TypeDeclarationStatement) node;
+ TypeDeclaration typeDecl = typeDeclarationStatement.getTypeDeclaration();
+ Object o = typeDecl.bodyDeclarations().get(0);
+ assertTrue("Not a method", o instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDecl = (MethodDeclaration) o;
+ Block block = methodDecl.getBody();
+ List statements = block.statements();
+ assertEquals("Not 1", 1, statements.size()); //$NON-NLS-1$
+ Statement stmt = (Statement) statements.get(0);
+ assertTrue("Not a return statement", stmt instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) stmt;
+ Expression expr = returnStatement.getExpression();
+ assertTrue("Not a SuperFieldAccess", expr instanceof SuperFieldAccess); //$NON-NLS-1$
+ SuperFieldAccess superFieldAccess = (SuperFieldAccess) expr;
+ Name name = superFieldAccess.getQualifier();
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("A type binding", binding instanceof ITypeBinding); //$NON-NLS-1$
+ assertEquals("Not Test", "Test", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Name fieldName = superFieldAccess.getName();
+ IBinding binding2 = fieldName.resolveBinding();
+ assertNotNull("No binding2", binding2); //$NON-NLS-1$
+ assertTrue("No an IVariableBinding", binding2 instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding2;
+ assertEquals("Not f", "f", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Not T", "T", variableBinding.getDeclaringClass().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ITypeBinding typeBinding2 = fieldName.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding2); //$NON-NLS-1$
+ assertEquals("Not int", "int", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Check catch clause positions:
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10570
+ */
+ public void test0243() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0243", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not a try statement", node instanceof TryStatement); //$NON-NLS-1$
+ TryStatement tryStatement = (TryStatement) node;
+ List catchClauses = tryStatement.catchClauses();
+ assertEquals("wrong size", 1, catchClauses.size()); //$NON-NLS-1$
+ CatchClause catchClause = (CatchClause) catchClauses.get(0);
+ checkSourceRange(catchClause, "catch (Exception e){m();}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * Check catch clause positions:
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10570
+ */
+ public void test0244() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0244", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not a try statement", node instanceof TryStatement); //$NON-NLS-1$
+ TryStatement tryStatement = (TryStatement) node;
+ List catchClauses = tryStatement.catchClauses();
+ assertEquals("wrong size", 2, catchClauses.size()); //$NON-NLS-1$
+ CatchClause catchClause = (CatchClause) catchClauses.get(0);
+ checkSourceRange(catchClause, "catch (RuntimeException e){m();}", source); //$NON-NLS-1$
+ catchClause = (CatchClause) catchClauses.get(1);
+ checkSourceRange(catchClause, "catch(Exception e) {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=10587
+ */
+ public void test0245() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0245", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertTrue("Not a return statement", node instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expr = returnStatement.getExpression();
+ assertTrue("not a name", expr instanceof Name); //$NON-NLS-1$
+ Name name = (Name) expr;
+ IBinding binding = name.resolveBinding();
+ assertTrue("Not a variable binding", binding instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Not i", "i", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Not int", "int", variableBinding.getType().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ASTNode declaringNode = unit.findDeclaringNode(variableBinding);
+ assertNotNull("No declaring node", declaringNode); //$NON-NLS-1$
+ assertTrue("Not a VariableDeclarationFragment", declaringNode instanceof VariableDeclarationFragment); //$NON-NLS-1$
+ }
+
+ /**
+ * Test binding resolution for import declaration
+ */
+ public void test0246() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0246", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ List imports = unit.imports();
+ assertEquals("wrong imports size", 2, imports.size()); //$NON-NLS-1$
+ ImportDeclaration importDeclaration = (ImportDeclaration) imports.get(0);
+ assertTrue("Not on demand", importDeclaration.isOnDemand()); //$NON-NLS-1$
+ checkSourceRange(importDeclaration, "import java.util.*;", source); //$NON-NLS-1$
+ IBinding binding = importDeclaration.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.PACKAGE, binding.getKind()); //$NON-NLS-1$
+ assertEquals("Wrong name", "java.util", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ importDeclaration = (ImportDeclaration) imports.get(1);
+ assertTrue("On demand", !importDeclaration.isOnDemand()); //$NON-NLS-1$
+ checkSourceRange(importDeclaration, "import java.io.IOException;", source); //$NON-NLS-1$
+ binding = importDeclaration.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.TYPE, binding.getKind()); //$NON-NLS-1$
+ assertEquals("Wrong name", "IOException", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Test binding resolution for import declaration
+ */
+ public void test0247() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0247", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ PackageDeclaration packageDeclaration = unit.getPackage();
+ checkSourceRange(packageDeclaration, "package test0247;", source); //$NON-NLS-1$
+ IPackageBinding binding = packageDeclaration.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.PACKAGE, binding.getKind()); //$NON-NLS-1$
+ assertEquals("Wrong name", "test0247", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong modifier", Modifier.NONE, binding.getModifiers());
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10592
+ */
+ public void test0248() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0248", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ assertEquals("wrong size", 1, parameters.size()); //$NON-NLS-1$
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ Name name = singleVariableDeclaration.getName();
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("Not a variable binding", binding instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Wrong name", "i", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong type", "int", variableBinding.getType().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10592
+ */
+ public void test0249() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0249", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 2, 1);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not an assignment", expression instanceof Assignment); //$NON-NLS-1$
+ Assignment assignment = (Assignment) expression;
+ Expression leftHandSide = assignment.getLeftHandSide();
+ assertTrue("Not a qualified name", leftHandSide instanceof QualifiedName); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) leftHandSide;
+ Name simpleName = qualifiedName.getName();
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("no binding", binding); //$NON-NLS-1$
+ assertTrue("Not a IVariableBinding", binding instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Wrong name", "k", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong modifier", Modifier.STATIC, variableBinding.getModifiers()); //$NON-NLS-1$
+ assertEquals("Wrong type", "int", variableBinding.getType().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong declaring class name", "j", variableBinding.getDeclaringClass().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10592
+ */
+ public void test0250() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0250", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ assertEquals("wrong size", 2, parameters.size()); //$NON-NLS-1$
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ Name name = singleVariableDeclaration.getName();
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("Not a variable binding", binding instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Wrong name", "i", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong type", "int", variableBinding.getType().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Check qualified name resolution for static fields
+ */
+ public void test0251() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0251", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not a ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ checkSourceRange(methodInvocation, "java.lang.System.out.println()", source); //$NON-NLS-1$
+ Expression qualifier = methodInvocation.getExpression();
+ assertTrue("Not a qualified name", qualifier instanceof QualifiedName); //$NON-NLS-1$
+ checkSourceRange(qualifier, "java.lang.System.out", source); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) qualifier;
+ Name typeName = qualifiedName.getQualifier();
+ assertTrue("Not a QualifiedName", typeName instanceof QualifiedName); //$NON-NLS-1$
+ QualifiedName qualifiedTypeName = (QualifiedName) typeName;
+ IBinding binding = qualifiedTypeName.getName().resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong name", "System", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ binding = qualifiedTypeName.getQualifier().resolveBinding();
+ assertNotNull("No binding2", binding); //$NON-NLS-1$
+ assertEquals("Wrong type binding", IBinding.PACKAGE, binding.getKind()); //$NON-NLS-1$
+ }
+
+ /**
+ * Check binding for anonymous class
+ */
+ public void test0252() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0252", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertTrue("Not a return statement", node instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertTrue("Not a classinstancecreation", expression instanceof ClassInstanceCreation); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ IMethodBinding methodBinding = classInstanceCreation.resolveConstructorBinding();
+ assertNotNull("No methodBinding", methodBinding); //$NON-NLS-1$
+ assertTrue("Not a constructor", methodBinding.isConstructor()); //$NON-NLS-1$
+ assertTrue("Not an anonymous class", methodBinding.getDeclaringClass().isAnonymous()); //$NON-NLS-1$
+ assertEquals("Not an anonymous class of java.lang.Object", "Object", methodBinding.getDeclaringClass().getSuperclass().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Not an anonymous class of java.lang.Object", "java.lang", methodBinding.getDeclaringClass().getSuperclass().getPackage().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Check binding for allocation expression
+ */
+ public void test0253() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0253", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not a return statement", node instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertTrue("Not a classinstancecreation", expression instanceof ClassInstanceCreation); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ IMethodBinding methodBinding = classInstanceCreation.resolveConstructorBinding();
+ assertNotNull("No methodBinding", methodBinding); //$NON-NLS-1$
+ assertTrue("Not a constructor", methodBinding.isConstructor()); //$NON-NLS-1$
+ assertEquals("Wrong size", 1, methodBinding.getParameterTypes().length); //$NON-NLS-1$
+ assertEquals("Wrong type", "String", methodBinding.getParameterTypes()[0].getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Check binding for allocation expression
+ */
+ public void test0254() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0254", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 1, 0);
+ assertTrue("Not a return statement", node instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertTrue("Not a class instance creation", expression instanceof ClassInstanceCreation); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ IMethodBinding binding = classInstanceCreation.resolveConstructorBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("wrong type", "C", binding.getDeclaringClass().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+
+ /**
+ * Check binding for allocation expression
+ */
+ public void test0255() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0255", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a MethodInvocation", expression instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ List arguments = methodInvocation.arguments();
+ assertEquals("wrong size", 1, arguments.size()); //$NON-NLS-1$
+ Expression expression2 = (Expression) arguments.get(0);
+ assertTrue("Not a CastExpression", expression2 instanceof CastExpression); //$NON-NLS-1$
+ CastExpression castExpression = (CastExpression) expression2;
+ Type type = castExpression.getType();
+ ITypeBinding binding = type.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("Not an array type", binding.isArray()); //$NON-NLS-1$
+ }
+
+ /**
+ * Check binding for allocation expression
+ */
+ public void test0256() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0256", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a MethodInvocation", expression instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ List arguments = methodInvocation.arguments();
+ assertEquals("wrong size", 1, arguments.size()); //$NON-NLS-1$
+ Expression expression2 = (Expression) arguments.get(0);
+ assertTrue("Not a CastExpression", expression2 instanceof CastExpression); //$NON-NLS-1$
+ CastExpression castExpression = (CastExpression) expression2;
+ Type type = castExpression.getType();
+ assertTrue("Not a simple type", type.isSimpleType()); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type;
+ ITypeBinding binding = type.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("Not a class", binding.isClass()); //$NON-NLS-1$
+ Name name = simpleType.getName();
+ IBinding binding2 = name.resolveBinding();
+ assertNotNull("No binding2", binding2); //$NON-NLS-1$
+ assertEquals("Wrong type", "Object", binding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * Check binding for allocation expression
+ */
+ public void test0257() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0257", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a MethodInvocation", expression instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ List arguments = methodInvocation.arguments();
+ assertEquals("wrong size", 1, arguments.size()); //$NON-NLS-1$
+ Expression expression2 = (Expression) arguments.get(0);
+ assertTrue("Not a CastExpression", expression2 instanceof CastExpression); //$NON-NLS-1$
+ CastExpression castExpression = (CastExpression) expression2;
+ Type type = castExpression.getType();
+ assertTrue("Not a primitive type", type.isPrimitiveType()); //$NON-NLS-1$
+ PrimitiveType primitiveType = (PrimitiveType) type;
+ assertEquals("Not int", PrimitiveType.INT, primitiveType.getPrimitiveTypeCode()); //$NON-NLS-1$
+ }
+
+ /**
+ * Check binding for allocation expression
+ */
+ public void test0258() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0258", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a MethodInvocation", expression instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ List arguments = methodInvocation.arguments();
+ assertEquals("wrong size", 1, arguments.size()); //$NON-NLS-1$
+ Expression expression2 = (Expression) arguments.get(0);
+ assertTrue("Not a CastExpression", expression2 instanceof CastExpression); //$NON-NLS-1$
+ CastExpression castExpression = (CastExpression) expression2;
+ Type type = castExpression.getType();
+ assertTrue("Not a simple type", type.isSimpleType()); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type;
+ ITypeBinding binding = type.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("Not a class", binding.isClass()); //$NON-NLS-1$
+ Name name = simpleType.getName();
+ IBinding binding2 = name.resolveBinding();
+ assertNotNull("No binding2", binding2); //$NON-NLS-1$
+ assertEquals("Wrong type", "Object", binding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10663
+ */
+ public void test0259() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0259", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10592
+ */
+ public void test0260() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0260", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ assertEquals("wrong size", 2, parameters.size()); //$NON-NLS-1$
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ IBinding binding = singleVariableDeclaration.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ Name name = singleVariableDeclaration.getName();
+ assertTrue("Not a simple name", name instanceof SimpleName); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) name;
+ assertEquals("Wrong name", "i", simpleName.getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding2 = name.resolveBinding();
+ assertNotNull("No binding", binding2); //$NON-NLS-1$
+ assertTrue("binding == binding2", binding == binding2); //$NON-NLS-1$
+ assertTrue("Not a variable binding", binding2 instanceof IVariableBinding); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding2;
+ assertEquals("Wrong name", "i", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong type", "int", variableBinding.getType().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10679
+ */
+ public void test0261() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0261", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("Wrong msg size", 1, compilationUnit.getMessages().length); //$NON-NLS-1$
+ assertEquals("Wrong pb size", 1, compilationUnit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a return statement", node instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ ITypeBinding binding = expression.resolveTypeBinding();
+ assertNull("got a binding", binding); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10676
+ */
+ public void test0262() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0262", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expr = expressionStatement.getExpression();
+ assertTrue("Not a MethodInvocation", expr instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expr;
+ List arguments = methodInvocation.arguments();
+ assertEquals("Wrong argument list size", 1, arguments.size()); //$NON-NLS-1$
+ Expression expr2 = (Expression) arguments.get(0);
+ assertTrue("Not a class instance creation", expr2 instanceof ClassInstanceCreation); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expr2;
+ arguments = classInstanceCreation.arguments();
+ assertEquals("Wrong size", 1, arguments.size()); //$NON-NLS-1$
+ Expression expression2 = (Expression) arguments.get(0);
+ assertTrue("Not a string literal", expression2 instanceof StringLiteral); //$NON-NLS-1$
+ StringLiteral stringLiteral = (StringLiteral) expression2;
+ ITypeBinding typeBinding = stringLiteral.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "String", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10700
+ */
+ public void test0263() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0263", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expr = expressionStatement.getExpression();
+ assertTrue("Not a MethodInvocation", expr instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expr;
+ List arguments = methodInvocation.arguments();
+ assertEquals("Wrong argument list size", 1, arguments.size()); //$NON-NLS-1$
+ Expression expr2 = (Expression) arguments.get(0);
+ assertTrue("Not a simple name", expr2 instanceof SimpleName); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) expr2;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10699
+ */
+ public void test0264() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0264", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("Wrong fragment size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a classinstancecreation", expression instanceof ClassInstanceCreation); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ assertNotNull("No anonymousclassdeclaration", anonymousClassDeclaration); //$NON-NLS-1$
+ String expectedSourceRange =
+ "{\n"+ //$NON-NLS-1$
+ " void m(int k){\n"+ //$NON-NLS-1$
+ " k= i;\n"+ //$NON-NLS-1$
+ " }\n"+ //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(anonymousClassDeclaration, expectedSourceRange, source);
+ List bodyDeclarations = anonymousClassDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size()); //$NON-NLS-1$
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue("Not a method declaration", bodyDeclaration instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ assertEquals("Wrong name", "m", methodDeclaration.getName().getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10698
+ */
+ public void test0265() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0265", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10759
+ */
+ public void test0266() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0266", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ checkSourceRange(type, "Inner\\u005b]", source); //$NON-NLS-1$
+ assertTrue("Not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ Type type2 = arrayType.getElementType();
+ assertTrue("Not a simple type", type2.isSimpleType()); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type2;
+ checkSourceRange(simpleType, "Inner", source); //$NON-NLS-1$
+ Name name = simpleType.getName();
+ assertTrue("not a simple name", name.isSimpleName()); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) name;
+ checkSourceRange(simpleName, "Inner", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10759
+ */
+ public void test0267() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0267", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ checkSourceRange(type, "Inner[]", source); //$NON-NLS-1$
+ assertTrue("Not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ Type type2 = arrayType.getElementType();
+ assertTrue("Not a simple type", type2.isSimpleType()); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type2;
+ checkSourceRange(simpleType, "Inner", source); //$NON-NLS-1$
+ Name name = simpleType.getName();
+ assertTrue("not a simple name", name.isSimpleName()); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) name;
+ checkSourceRange(simpleName, "Inner", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10759
+ */
+ public void test0268() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0268", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ checkSourceRange(type, "test0268.Test.Inner[]", source); //$NON-NLS-1$
+ assertTrue("Not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ Type type2 = arrayType.getElementType();
+ assertTrue("Not a simple type", type2.isSimpleType()); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type2;
+ checkSourceRange(simpleType, "test0268.Test.Inner", source); //$NON-NLS-1$
+ Name name = simpleType.getName();
+ assertTrue("not a qualified name", name.isQualifiedName()); //$NON-NLS-1$
+ checkSourceRange(name, "test0268.Test.Inner", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10759
+ */
+ public void test0269() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0269", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ checkSourceRange(type, "test0269.Test.Inner[/**/]", source); //$NON-NLS-1$
+ assertTrue("Not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ Type type2 = arrayType.getElementType();
+ assertTrue("Not a simple type", type2.isSimpleType()); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type2;
+ checkSourceRange(simpleType, "test0269.Test.Inner", source); //$NON-NLS-1$
+ Name name = simpleType.getName();
+ assertTrue("not a qualified name", name.isQualifiedName()); //$NON-NLS-1$
+ checkSourceRange(name, "test0269.Test.Inner", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10759
+ */
+ public void test0270() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0270", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ checkSourceRange(type, "test0270.Test.Inner", source); //$NON-NLS-1$
+ assertTrue("Not a simple type", type.isSimpleType()); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type;
+ Name name = simpleType.getName();
+ assertTrue("not a qualified name", name.isQualifiedName()); //$NON-NLS-1$
+ checkSourceRange(name, "test0270.Test.Inner", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10759
+ */
+ public void test0271() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0271", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ checkSourceRange(type, "test0271.Test.Inner[]", source); //$NON-NLS-1$
+ assertTrue("Not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ Type type2 = arrayType.getElementType();
+ assertTrue("Not a simple type", type2.isSimpleType()); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type2;
+ checkSourceRange(simpleType, "test0271.Test.Inner", source); //$NON-NLS-1$
+ Name name = simpleType.getName();
+ assertTrue("not a qualified name", name.isQualifiedName()); //$NON-NLS-1$
+ checkSourceRange(name, "test0271.Test.Inner", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10843
+ */
+ public void test0272() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0272", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a For statement", node instanceof ForStatement); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node;
+ checkSourceRange(forStatement, "for (int i= 0; i < 10; i++) foo();", source); //$NON-NLS-1$
+ Statement action = forStatement.getBody();
+ checkSourceRange(action, "foo();", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10843
+ */
+ public void test0273() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0273", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a For statement", node instanceof ForStatement); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node;
+ checkSourceRange(forStatement, "for (int i= 0; i < 10; i++) { foo(); }", source); //$NON-NLS-1$
+ Statement action = forStatement.getBody();
+ checkSourceRange(action, "{ foo(); }", source); //$NON-NLS-1$
+ assertTrue("Not a block", action instanceof Block); //$NON-NLS-1$
+ Block block = (Block) action;
+ List statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement stmt = (Statement) statements.get(0);
+ checkSourceRange(stmt, "foo();", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10843
+ */
+ public void test0274() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0274", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 1);
+ assertTrue("Not a While statement", node instanceof WhileStatement); //$NON-NLS-1$
+ WhileStatement whileStatement = (WhileStatement) node;
+ checkSourceRange(whileStatement, "while (i < 10) { foo(i++); }", source); //$NON-NLS-1$
+ Statement action = whileStatement.getBody();
+ checkSourceRange(action, "{ foo(i++); }", source); //$NON-NLS-1$
+ assertTrue("Not a block", action instanceof Block); //$NON-NLS-1$
+ Block block = (Block) action;
+ List statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement stmt = (Statement) statements.get(0);
+ checkSourceRange(stmt, "foo(i++);", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10843
+ */
+ public void test0275() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0275", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 1);
+ assertTrue("Not a While statement", node instanceof WhileStatement); //$NON-NLS-1$
+ WhileStatement whileStatement = (WhileStatement) node;
+ checkSourceRange(whileStatement, "while (i < 10) foo(i++);", source); //$NON-NLS-1$
+ Statement action = whileStatement.getBody();
+ checkSourceRange(action, "foo(i++);", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10798
+ */
+ public void test0276() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0276", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ String expectedSource =
+ "public void foo() {\n" + //$NON-NLS-1$
+ " foo();\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(methodDeclaration, expectedSource, source);
+ expectedSource =
+ "{\n" + //$NON-NLS-1$
+ " foo();\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(methodDeclaration.getBody(), expectedSource, source);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10798
+ */
+ public void test0277() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0277", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ String expectedSource =
+ "public void foo() {\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(methodDeclaration, expectedSource, source);
+ expectedSource =
+ "{\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(methodDeclaration.getBody(), expectedSource, source);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10861
+ */
+ public void test0278() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0278", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "Class c = java.lang.String.class;", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a type literal", expression instanceof TypeLiteral); //$NON-NLS-1$
+ ITypeBinding typeBinding = expression.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Class", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10861
+ */
+ public void test0279() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0279", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0,0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ checkSourceRange(variableDeclarationStatement, "Class c = java.lang.String.class;", source); //$NON-NLS-1$
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a type literal", expression instanceof TypeLiteral); //$NON-NLS-1$
+ ITypeBinding typeBinding = expression.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Class", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10865
+ * Check well known types
+ */
+ public void test0280() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0280", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ AST newAst = result.getAST();
+ ITypeBinding typeBinding = newAst.resolveWellKnownType("boolean"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "boolean", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("char"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "char", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("byte"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "byte", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("short"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "short", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("int"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("long"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "long", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("float"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "float", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("double"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "double", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("void"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "void", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Object", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("java.lang.String"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "String", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("java.lang.StringBuffer"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "StringBuffer", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Throwable"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Throwable", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Exception"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Exception", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("java.lang.RuntimeException"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "RuntimeException", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Error"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Error", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Class"); //$NON-NLS-1$
+ assertNotNull("No typeBinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Class", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Runnable"); //$NON-NLS-1$
+ assertNull("typeBinding not null", typeBinding); //$NON-NLS-1$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Cloneable"); //$NON-NLS-1$
+ assertNotNull("typeBinding not null", typeBinding); //$NON-NLS-1$
+ typeBinding = newAst.resolveWellKnownType("java.io.Serializable"); //$NON-NLS-1$
+ assertNotNull("typeBinding not null", typeBinding); //$NON-NLS-1$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Boolean"); //$NON-NLS-1$
+ assertNotNull("typeBinding not null", typeBinding); //$NON-NLS-1$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Byte"); //$NON-NLS-1$
+ assertNotNull("typeBinding not null", typeBinding); //$NON-NLS-1$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Character"); //$NON-NLS-1$
+ assertNotNull("typeBinding not null", typeBinding); //$NON-NLS-1$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Double"); //$NON-NLS-1$
+ assertNotNull("typeBinding not null", typeBinding); //$NON-NLS-1$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Float"); //$NON-NLS-1$
+ assertNotNull("typeBinding not null", typeBinding); //$NON-NLS-1$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Integer"); //$NON-NLS-1$
+ assertNotNull("typeBinding not null", typeBinding); //$NON-NLS-1$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Long"); //$NON-NLS-1$
+ assertNotNull("typeBinding not null", typeBinding); //$NON-NLS-1$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Short"); //$NON-NLS-1$
+ assertNotNull("typeBinding not null", typeBinding); //$NON-NLS-1$
+ typeBinding = newAst.resolveWellKnownType("java.lang.Void"); //$NON-NLS-1$
+ assertNotNull("typeBinding not null", typeBinding); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10874
+ */
+ public void test0281() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0281", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "Object o= /*]*/new Object()/*[*/;", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ checkSourceRange(expression, "new Object()", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10874
+ */
+ public void test0282() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0282", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "boolean b = /*]*/true/*[*/;", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ checkSourceRange(expression, "true", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10874
+ */
+ public void test0283() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0283", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "char c = /*]*/'c'/*[*/;", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ checkSourceRange(expression, "'c'", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10874
+ */
+ public void test0284() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0284", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "Object o = /*]*/null/*[*/;", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ checkSourceRange(expression, "null", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10874
+ */
+ public void test0285() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0285", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "Object o = /*]*/Object.class/*[*/;", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ checkSourceRange(expression, "Object.class", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10874
+ */
+ public void test0286() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0286", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "int i = /**/(2)/**/;", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ checkSourceRange(expression, "(2)", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10874
+ */
+ public void test0287() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0287", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "String[] tab = /**/new String[3]/**/;", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ checkSourceRange(expression, "new String[3]", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10874
+ */
+ public void test0288() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0288", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "String[] tab = /**/{ }/**/;", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ checkSourceRange(expression, "{ }", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10874
+ */
+ public void test0289() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0289", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 1);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "String s = /**/tab1[0]/**/;", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ checkSourceRange(expression, "tab1[0]", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10874
+ */
+ public void test0290() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0290", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "Object o = /*]*/new java.lang.Object()/*[*/;", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ checkSourceRange(expression, "new java.lang.Object()", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10898
+ */
+ public void test0291() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0291", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("no errors", 1, unit.getMessages().length); //$NON-NLS-1$
+ assertEquals("no errors", 1, unit.getProblems().length); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10913
+ */
+ public void test0292() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0292", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a return statement", node instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertTrue("Not a qualifiedName", expression instanceof QualifiedName); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) expression;
+ SimpleName simpleName = qualifiedName.getName();
+ assertEquals("Wrong name", "x", simpleName.getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("NO binding", binding); //$NON-NLS-1$
+ assertTrue("Not a variable binding", binding instanceof IVariableBinding); //$NON-NLS-1$
+ assertEquals("wrong name", "x", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Name name = qualifiedName.getQualifier();
+ assertTrue("Not a simpleName", name instanceof SimpleName); //$NON-NLS-1$
+ SimpleName simpleName2 = (SimpleName) name;
+ IBinding binding2 = simpleName2.resolveBinding();
+ assertNotNull("No binding2", binding2); //$NON-NLS-1$
+ assertTrue("Not a type binding", binding2 instanceof ITypeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Test", binding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10933
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10935
+ */
+ public void test0293() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0293", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a class instance creation", expression instanceof ClassInstanceCreation); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ assertNotNull("No body", anonymousClassDeclaration); //$NON-NLS-1$
+ String expectedSource =
+ "{\n" + //$NON-NLS-1$
+ " public void run() {\n" + //$NON-NLS-1$
+ " /*]*/foo();/*[*/\n" + //$NON-NLS-1$
+ " }\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(anonymousClassDeclaration, expectedSource, source);
+ expectedSource =
+ "run= new Runnable() {\n" + //$NON-NLS-1$
+ " public void run() {\n" + //$NON-NLS-1$
+ " /*]*/foo();/*[*/\n" + //$NON-NLS-1$
+ " }\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(variableDeclarationFragment, expectedSource, source);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10984
+ */
+ public void test0294() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0294", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ String expectedSource =
+ "public void fails() {\n" + //$NON-NLS-1$
+ " foo()\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(methodDeclaration, expectedSource, source);
+ Block block = methodDeclaration.getBody();
+ expectedSource =
+ "{\n" + //$NON-NLS-1$
+ " foo()\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(block, expectedSource, source);
+ node = getASTNode(compilationUnit, 0, 1);
+ assertTrue("Not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10986
+ */
+ public void test0295() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0295", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("Wrong size", 2, compilationUnit.getMessages().length); //$NON-NLS-1$
+ assertEquals("Wrong size", 2, compilationUnit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("not a method invocation", expression instanceof MethodInvocation); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ ITypeBinding typeBinding = methodInvocation.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("LList;", typeBinding.getKey());
+ }
+
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10984
+ */
+ public void test0296() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0296", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ String expectedSource =
+ "public void fails() {\n" + //$NON-NLS-1$
+ " foo()\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(methodDeclaration, expectedSource, source);
+ Block block = methodDeclaration.getBody();
+ expectedSource =
+ "{\n" + //$NON-NLS-1$
+ " foo()\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(block, expectedSource, source);
+ node = getASTNode(compilationUnit, 0, 1);
+ assertTrue("Not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11037
+ */
+ public void test0297() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0297", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ runConversion(sourceUnit, false);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10984
+ */
+ public void test0298() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0298", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a ReturnStatement", node instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ checkSourceRange(expression, "a().length != 3", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10874
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11104
+ */
+ public void test0299() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0299", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "int i = (/**/2/**/);", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a parenthesized expression", expression instanceof ParenthesizedExpression); //$NON-NLS-1$
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression;
+ Expression expression2 = parenthesizedExpression.getExpression();
+ checkSourceRange(expression2, "2", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10874
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11104
+ */
+ public void test0300() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0300", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "boolean b = /**/true/**/;", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ checkSourceRange(expression, "true", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=10874
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11104
+ */
+ public void test0301() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0301", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a Field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "Object o = /**/null/**/;", source); //$NON-NLS-1$
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ checkSourceRange(expression, "null", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11106
+ */
+ public void test0302() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0302", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a DoStatement", node instanceof DoStatement); //$NON-NLS-1$
+ DoStatement doStatement = (DoStatement) node;
+ String expectedSource =
+ "do\n" + //$NON-NLS-1$
+ " foo();\n" + //$NON-NLS-1$
+ " while(1 < 10);"; //$NON-NLS-1$
+ checkSourceRange(doStatement, expectedSource, source);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11129
+ */
+ public void test0303() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0303", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 1);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression2 = expressionStatement.getExpression();
+ assertTrue("Not an Assignement", expression2 instanceof Assignment); //$NON-NLS-1$
+ Assignment assignment = (Assignment) expression2;
+ Expression expression = assignment.getRightHandSide();
+ assertTrue("Not a CastExpression", expression instanceof CastExpression); //$NON-NLS-1$
+ CastExpression castExpression = (CastExpression) expression;
+ ITypeBinding typeBinding = castExpression.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "char", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Type type = castExpression.getType();
+ ITypeBinding typeBinding2 = type.resolveBinding();
+ assertNotNull("No binding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("Wrong name", "char", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11151
+ */
+ public void test0304() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0304", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ checkSourceRange(node, "public void foo(int arg);", source); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block block = methodDeclaration.getBody();
+ assertNull("Has a body", block); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11125
+ */
+ public void test0305() {
+ char[] source =
+ ("package test0305;\n" + //$NON-NLS-1$
+ "\n" + //$NON-NLS-1$
+ "class Test {\n" + //$NON-NLS-1$
+ " public void foo(int arg) {}\n" + //$NON-NLS-1$
+ "}").toCharArray(); //$NON-NLS-1$
+ IJavaProject project = getJavaProject("Converter"); //$NON-NLS-1$
+ ASTNode result = runConversion(source, "Test.java", project, true); //$NON-NLS-1$
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertTrue("not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Test", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong package", "test0305", typeBinding.getPackage().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("Not an interface", typeBinding.isClass()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11125
+ */
+ public void test0306() {
+ char[] source =
+ ("package java.lang;\n" + //$NON-NLS-1$
+ "\n" + //$NON-NLS-1$
+ "class Object {\n" + //$NON-NLS-1$
+ " public void foo(int arg) {}\n" + //$NON-NLS-1$
+ "}").toCharArray(); //$NON-NLS-1$
+ IJavaProject project = getJavaProject("Converter"); //$NON-NLS-1$
+ ASTNode result = runConversion(source, "Object.java", project, true); //$NON-NLS-1$
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertTrue("not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Object", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong package", "java.lang", typeBinding.getPackage().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("Not an interface", typeBinding.isClass()); //$NON-NLS-1$
+ assertEquals("Wrong size", 2, typeBinding.getDeclaredMethods().length); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11371
+ */
+ public void test0307() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0307", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertTrue("not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block block = methodDeclaration.getBody();
+ assertNotNull("No body", block); //$NON-NLS-1$
+ List statements = block.statements();
+ assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("Not a super constructor invocation", statement instanceof SuperConstructorInvocation); //$NON-NLS-1$
+ checkSourceRange(statement, "super(10);", source);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11371
+ */
+ public void test0308() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0308", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertTrue("not a method declaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block block = methodDeclaration.getBody();
+ assertNotNull("No body", block); //$NON-NLS-1$
+ List statements = block.statements();
+ assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("Not a super constructor invocation", statement instanceof SuperConstructorInvocation); //$NON-NLS-1$
+ SuperConstructorInvocation superConstructorInvocation = (SuperConstructorInvocation) statement;
+ IMethodBinding methodBinding = superConstructorInvocation.resolveConstructorBinding();
+ assertNotNull("No methodBinding", methodBinding); //$NON-NLS-1$
+ IMethodBinding methodBinding2 = methodDeclaration.resolveBinding();
+ assertNotNull("No methodBinding2", methodBinding2); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11380
+ */
+ public void test0309() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0309", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a conditional expression", expression instanceof ConditionalExpression); //$NON-NLS-1$
+ ConditionalExpression conditionalExpression = (ConditionalExpression) expression;
+ ITypeBinding typeBinding = conditionalExpression.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("wrong name", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11380
+ */
+ public void test0310() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0310", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("not a FieldDeclaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a qualified name", expression instanceof QualifiedName); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) expression;
+ Name qualifier = qualifiedName.getQualifier();
+ IBinding binding = qualifier.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("wrong name", "I", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11638
+ */
+ public void test0311() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0311", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 1);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("not a class instance creation", expression instanceof ClassInstanceCreation); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ assertNotNull("No body", anonymousClassDeclaration); //$NON-NLS-1$
+ List bodyDeclarations = anonymousClassDeclaration.bodyDeclarations();
+ assertEquals("wrong size for body declarations", 1, bodyDeclarations.size()); //$NON-NLS-1$
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue("Not a method declaration", bodyDeclaration instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ Block block = methodDeclaration.getBody();
+ assertNotNull("no body", block); //$NON-NLS-1$
+ List statements = block.statements();
+ assertEquals("Wrong size for statements", 1, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("not a variable declaration statement", statement instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement2 = (VariableDeclarationStatement) statement;
+ List fragments2 = variableDeclarationStatement2.fragments();
+ assertEquals("wrong size for fragments2", 1, fragments2.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment2 = (VariableDeclarationFragment) fragments2.get(0);
+ Expression expression2 = variableDeclarationFragment2.getInitializer();
+ assertTrue("Not a name", expression2 instanceof Name); //$NON-NLS-1$
+ Name name = (Name) expression2;
+ checkSourceRange(name, "j", source); //$NON-NLS-1$
+ IBinding binding = name.resolveBinding();
+ ASTNode declaringNode = compilationUnit.findDeclaringNode(binding);
+ assertNotNull("No declaring node", declaringNode); //$NON-NLS-1$
+ checkSourceRange(declaringNode, "int j", source); //$NON-NLS-1$
+ assertTrue("Not a single variable declaration", declaringNode instanceof SingleVariableDeclaration); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11638
+ * There is a error in this source. A is unresolved. Then there is no
+ * declaring node.
+ */
+ public void test0312() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0312", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 1);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("not a class instance creation", expression instanceof ClassInstanceCreation); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ assertNotNull("No body", anonymousClassDeclaration); //$NON-NLS-1$
+ List bodyDeclarations = anonymousClassDeclaration.bodyDeclarations();
+ assertEquals("wrong size for body declarations", 1, bodyDeclarations.size()); //$NON-NLS-1$
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue("Not a method declaration", bodyDeclaration instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ Block block = methodDeclaration.getBody();
+ assertNotNull("no body", block); //$NON-NLS-1$
+ List statements = block.statements();
+ assertEquals("Wrong size for statements", 1, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("not a variable declaration statement", statement instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement2 = (VariableDeclarationStatement) statement;
+ List fragments2 = variableDeclarationStatement2.fragments();
+ assertEquals("wrong size for fragments2", 1, fragments2.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment2 = (VariableDeclarationFragment) fragments2.get(0);
+ Expression expression2 = variableDeclarationFragment2.getInitializer();
+ assertTrue("Not a name", expression2 instanceof Name); //$NON-NLS-1$
+ Name name = (Name) expression2;
+ checkSourceRange(name, "j", source); //$NON-NLS-1$
+ IBinding binding = name.resolveBinding();
+ ASTNode declaringNode = compilationUnit.findDeclaringNode(binding);
+ assertNotNull("No declaring node is available", declaringNode); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11659
+ */
+ public void test0313() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0313", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not an InfixExpression", expression instanceof InfixExpression); //$NON-NLS-1$
+ InfixExpression infixExpression = (InfixExpression) expression;
+ checkSourceRange(infixExpression, "i+j", source); //$NON-NLS-1$
+ Expression expression2 = infixExpression.getLeftOperand();
+ checkSourceRange(expression2, "i", source); //$NON-NLS-1$
+ assertTrue("Not a name", expression2 instanceof Name); //$NON-NLS-1$
+ Name name = (Name) expression2;
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ ASTNode astNode = compilationUnit.findDeclaringNode(binding);
+ assertNotNull("No declaring node", astNode); //$NON-NLS-1$
+ checkSourceRange(astNode, "int i", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=12326
+ */
+ public void test0314() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0314", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ assertNotNull("No result", result); //$NON-NLS-1$
+ assertTrue("Not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("Wrong line number", 1, compilationUnit.getLineNumber(0)); //$NON-NLS-1$
+ // ensure that last character is on the last line
+ assertEquals("Wrong line number", 3, compilationUnit.getLineNumber(source.length - 1)); //$NON-NLS-1$
+ // source.length is beyond the size of the compilation unit source
+ assertEquals("Wrong line number", -1, compilationUnit.getLineNumber(source.length)); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=12326
+ */
+ public void test0315() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0315", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a Return statement", node instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertTrue("Not an instanceof expression", expression instanceof InstanceofExpression); //$NON-NLS-1$
+ InstanceofExpression instanceOfExpression = (InstanceofExpression) expression;
+ Type rightOperand = instanceOfExpression.getRightOperand();
+ assertTrue("Not a simpleType", rightOperand instanceof SimpleType); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) rightOperand;
+ Name n = simpleType.getName();
+ assertTrue("Not a qualified name", n instanceof QualifiedName); //$NON-NLS-1$
+ QualifiedName name = (QualifiedName) n;
+ checkSourceRange(name, "java.io.Serializable", source); //$NON-NLS-1$
+ ITypeBinding typeBinding = name.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Serializable", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Name qualifier = name.getQualifier();
+ assertTrue("Not a qualified name", qualifier instanceof QualifiedName); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = qualifier.resolveTypeBinding();
+ assertNull("typebinding2 is not null", typeBinding2); //$NON-NLS-1$
+ IBinding binding = qualifier.resolveBinding();
+ assertNotNull("no binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.PACKAGE, binding.getKind()); //$NON-NLS-1$
+ IPackageBinding pBinding = (IPackageBinding) binding;
+ assertEquals("Wrong name", "java.io", pBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=12454
+ */
+ public void test0316() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "", "Hello.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No result", result); //$NON-NLS-1$
+ assertTrue("Not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("Wrong size", 1, compilationUnit.getMessages().length); //$NON-NLS-1$
+ assertEquals("Wrong size", 1, compilationUnit.getProblems().length); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=12781
+ */
+ public void test0317() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0317", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a return statement", node instanceof ReturnStatement); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertTrue("not an instanceof expression", expression instanceof InstanceofExpression); //$NON-NLS-1$
+ InstanceofExpression instanceOfExpression = (InstanceofExpression) expression;
+ Expression left = instanceOfExpression.getLeftOperand();
+ assertTrue("Not a Name", left instanceof Name); //$NON-NLS-1$
+ Name name = (Name) left;
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("wrong name", "x", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ITypeBinding typeBinding = name.resolveTypeBinding();
+ assertNotNull("No typebinding", typeBinding); //$NON-NLS-1$
+ assertEquals("wrong type", "Object", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Type right = instanceOfExpression.getRightOperand();
+ assertTrue("Not a simpleType", right instanceof SimpleType); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) right;
+ name = simpleType.getName();
+ assertTrue("Not a simpleName", name instanceof SimpleName); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) name;
+ IBinding binding2 = simpleName.resolveBinding();
+ assertNotNull("No binding2", binding2); //$NON-NLS-1$
+ assertEquals("Wrong name", "Vector", binding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ITypeBinding typeBinding2 = simpleName.resolveTypeBinding();
+ assertNotNull("No typeBinding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("Wrong name", "Vector", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=13233
+ */
+ public void test0318() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0318", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("No error", 1, unit.getMessages().length); //$NON-NLS-1$
+ assertEquals("No error", 1, unit.getProblems().length); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=13807
+ */
+ public void test0319() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0319", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not an array creation", expression instanceof ArrayCreation); //$NON-NLS-1$
+ ArrayCreation arrayCreation = (ArrayCreation) expression;
+ ITypeBinding typeBinding = arrayCreation.resolveTypeBinding();
+ assertNotNull("no type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[]", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ArrayType arrayType = arrayCreation.getType();
+ ITypeBinding typeBinding2 = arrayType.resolveBinding();
+ assertNotNull("no type binding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[]", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Type type = arrayType.getElementType();
+ assertTrue("Not a simple type", type instanceof SimpleType); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type;
+ ITypeBinding typeBinding3 = simpleType.resolveBinding();
+ assertNotNull("no type binding3", typeBinding3); //$NON-NLS-1$
+ assertEquals("wrong name", "Object", typeBinding3.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=13807
+ */
+ public void test0320() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0320", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ checkSourceRange(type, "int[]", source); //$NON-NLS-1$
+ assertTrue("Not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ ITypeBinding typeBinding = arrayType.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ Type elementType = arrayType.getElementType();
+ assertTrue("Not a simple type", elementType.isPrimitiveType()); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = elementType.resolveBinding();
+ assertNotNull("No type binding2", typeBinding2); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=13807
+ */
+ public void test0321() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0321", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ assertTrue("Not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ ITypeBinding typeBinding = arrayType.resolveBinding();
+ checkSourceRange(type, "java.lang.Object[][]", source); //$NON-NLS-1$
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ Type elementType = arrayType.getComponentType();
+ ITypeBinding typeBinding2 = elementType.resolveBinding();
+ assertNotNull("No type binding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("wrong dimension", 1, typeBinding2.getDimensions()); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[]", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("Not an array type", elementType.isArrayType()); //$NON-NLS-1$
+ Type elementType2 = ((ArrayType) elementType).getComponentType();
+ assertTrue("Not a simple type", elementType2.isSimpleType()); //$NON-NLS-1$
+ ITypeBinding typeBinding3 = elementType2.resolveBinding();
+ assertNotNull("No type binding3", typeBinding3); //$NON-NLS-1$
+ assertEquals("wrong dimension", 0, typeBinding3.getDimensions()); //$NON-NLS-1$
+ assertEquals("wrong name", "Object", typeBinding3.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=13231
+ */
+ public void test0322() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0322", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a FieldDeclaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a null literal", expression instanceof NullLiteral); //$NON-NLS-1$
+ NullLiteral nullLiteral = (NullLiteral) expression;
+ ITypeBinding typeBinding = nullLiteral.resolveTypeBinding();
+ assertNotNull("no type binding", typeBinding); //$NON-NLS-1$
+ assertTrue("Not the null type", typeBinding.isNullType()); //$NON-NLS-1$
+ assertEquals("Wrong qualified name", typeBinding.getQualifiedName(), "null"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=14198
+ */
+ public void test0323() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0323", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 1);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression2 = expressionStatement.getExpression();
+ assertTrue("Not an Assignement", expression2 instanceof Assignment); //$NON-NLS-1$
+ Assignment assignment = (Assignment) expression2;
+ Expression expression = assignment.getRightHandSide();
+ assertTrue("Not a CastExpression", expression instanceof CastExpression); //$NON-NLS-1$
+ CastExpression castExpression = (CastExpression) expression;
+ ITypeBinding typeBinding = castExpression.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Object", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Type type = castExpression.getType();
+ ITypeBinding typeBinding2 = type.resolveBinding();
+ assertNotNull("No binding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("Wrong name", "Object", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=14198
+ */
+ public void test0324() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0324", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 1);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression2 = expressionStatement.getExpression();
+ assertTrue("Not an Assignement", expression2 instanceof Assignment); //$NON-NLS-1$
+ Assignment assignment = (Assignment) expression2;
+ Expression expression = assignment.getRightHandSide();
+ assertTrue("Not a CastExpression", expression instanceof CastExpression); //$NON-NLS-1$
+ CastExpression castExpression = (CastExpression) expression;
+ ITypeBinding typeBinding = castExpression.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Object[]", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Type type = castExpression.getType();
+ ITypeBinding typeBinding2 = type.resolveBinding();
+ assertNotNull("No binding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("Wrong name", "Object[]", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=14198
+ */
+ public void test0325() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0325", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 1);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression2 = expressionStatement.getExpression();
+ assertTrue("Not an Assignement", expression2 instanceof Assignment); //$NON-NLS-1$
+ Assignment assignment = (Assignment) expression2;
+ Expression expression = assignment.getRightHandSide();
+ assertTrue("Not a CastExpression", expression instanceof CastExpression); //$NON-NLS-1$
+ CastExpression castExpression = (CastExpression) expression;
+ ITypeBinding typeBinding = castExpression.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "int[]", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Type type = castExpression.getType();
+ ITypeBinding typeBinding2 = type.resolveBinding();
+ assertNotNull("No binding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("Wrong name", "int[]", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=14217
+ */
+ public void test0326() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0326", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ char[] source = sourceUnit.getSource().toCharArray();
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertTrue("Not an ExpressionStatement", node instanceof ExpressionStatement); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ checkSourceRange(expressionStatement.getExpression(), "a().f= a()", source); //$NON-NLS-1$
+ checkSourceRange(expressionStatement, "a().f= a();", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=14198
+ */
+ public void test0327() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0327", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("Wrong number of errors", 2, compilationUnit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not an VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a CastExpression", expression instanceof CastExpression); //$NON-NLS-1$
+ CastExpression castExpression = (CastExpression) expression;
+ ITypeBinding typeBinding = castExpression.resolveTypeBinding();
+ assertNotNull("No typebinding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "String", typeBinding.getName());
+ Type type = castExpression.getType();
+ ITypeBinding typeBinding2 = type.resolveBinding();
+ assertNotNull("No binding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("Wrong name", "String", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=13807
+ */
+ public void test0328() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0328", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ checkSourceRange(type, "java.lang.Object[]", source); //$NON-NLS-1$
+ assertTrue("Not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ ITypeBinding typeBinding = arrayType.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[]", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Type elementType = arrayType.getElementType();
+ assertTrue("Not a simple type", elementType.isSimpleType()); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = elementType.resolveBinding();
+ assertNotNull("No type binding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("wrong name", "Object", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a array creation", expression instanceof ArrayCreation); //$NON-NLS-1$
+ ITypeBinding typeBinding3 = expression.resolveTypeBinding();
+ assertNotNull("No typeBinding3", typeBinding3); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[]", typeBinding3.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ArrayCreation arrayCreation = (ArrayCreation) expression;
+ ArrayInitializer arrayInitializer = arrayCreation.getInitializer();
+ assertNotNull("not array initializer", arrayInitializer); //$NON-NLS-1$
+ ITypeBinding typeBinding4 = arrayInitializer.resolveTypeBinding();
+ assertNotNull("No typeBinding4", typeBinding3); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[]", typeBinding4.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=13807
+ */
+ public void test0329() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0329", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ checkSourceRange(type, "java.lang.Object[]", source); //$NON-NLS-1$
+ assertTrue("Not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ ITypeBinding typeBinding = arrayType.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[]", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Type elementType = arrayType.getElementType();
+ assertTrue("Not a simple type", elementType.isSimpleType()); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = elementType.resolveBinding();
+ assertNotNull("No type binding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("wrong name", "Object", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a array creation", expression instanceof ArrayCreation); //$NON-NLS-1$
+ ITypeBinding typeBinding3 = expression.resolveTypeBinding();
+ assertNotNull("No typeBinding3", typeBinding3); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[]", typeBinding3.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ArrayCreation arrayCreation = (ArrayCreation) expression;
+ ArrayInitializer arrayInitializer = arrayCreation.getInitializer();
+ assertNotNull("not array initializer", arrayInitializer); //$NON-NLS-1$
+ ITypeBinding typeBinding4 = arrayInitializer.resolveTypeBinding();
+ assertNotNull("No typeBinding4", typeBinding3); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[]", typeBinding4.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=14313
+ */
+ public void test0330() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0330", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("wrong size", 2, compilationUnit.getMessages().length); //$NON-NLS-1$
+ assertEquals("wrong size", 2, compilationUnit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("no type binding", typeBinding); //$NON-NLS-1$
+ IMethodBinding[] methods = typeBinding.getDeclaredMethods();
+ assertEquals("wrong size", 1, methods.length); //$NON-NLS-1$
+ assertTrue("not a constructor", methods[0].isConstructor()); //$NON-NLS-1$
+ assertTrue("wrong name", !methods[0].getName().equals("foo")); //$NON-NLS-1$ //$NON-NLS-2$
+ node = getASTNode(compilationUnit, 0, 0);
+ assertTrue("Not a methodDeclaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ assertNull("method binding not null", methodBinding); //$NON-NLS-1$
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a return statement", node.getNodeType() == ASTNode.RETURN_STATEMENT); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ ITypeBinding typeBinding2 = expression.resolveTypeBinding();
+ assertNotNull("no type binding2", typeBinding2); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=14322
+ */
+ public void test0331() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0331", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not an VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a QualifiedName", expression instanceof QualifiedName); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) expression;
+ IBinding binding = qualifiedName.getName().resolveBinding();
+ assertNotNull("no binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.VARIABLE, binding.getKind()); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertTrue("Not a field", variableBinding.isField()); //$NON-NLS-1$
+ assertNull("Got a declaring class", variableBinding.getDeclaringClass()); //$NON-NLS-1$
+ assertEquals("wrong name", "length", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=14403
+ */
+ public void test0332() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0332", "LocalSelectionTransfer.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=13807
+ */
+ public void test0333() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0333", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not an array creation", expression instanceof ArrayCreation); //$NON-NLS-1$
+ ArrayCreation arrayCreation = (ArrayCreation) expression;
+ ITypeBinding typeBinding = arrayCreation.resolveTypeBinding();
+ assertNotNull("no type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[][]", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ArrayType arrayType = arrayCreation.getType();
+ ITypeBinding typeBinding2 = arrayType.resolveBinding();
+ assertNotNull("no type binding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[][]", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Type type = arrayType.getElementType();
+ assertTrue("Not a simple type", type instanceof SimpleType); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type;
+ ITypeBinding typeBinding3 = simpleType.resolveBinding();
+ assertNotNull("no type binding3", typeBinding3); //$NON-NLS-1$
+ assertEquals("wrong name", "Object", typeBinding3.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ type = arrayType.getComponentType();
+ assertTrue("Not an array type", type instanceof ArrayType); //$NON-NLS-1$
+ ArrayType arrayType2 = (ArrayType) type;
+ ITypeBinding typeBinding4 = arrayType2.resolveBinding();
+ assertNotNull("no type binding4", typeBinding4); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[]", typeBinding4.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=13807
+ */
+ public void test0334() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0334", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertTrue("Not a VariableDeclarationStatement", node instanceof VariableDeclarationStatement); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not an array creation", expression instanceof ArrayCreation); //$NON-NLS-1$
+ ArrayCreation arrayCreation = (ArrayCreation) expression;
+ ITypeBinding typeBinding = arrayCreation.resolveTypeBinding();
+ assertNotNull("no type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[][][]", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ArrayType arrayType = arrayCreation.getType();
+ checkSourceRange(arrayType, "Object[10][][]", source); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = arrayType.resolveBinding();
+ assertNotNull("no type binding2", typeBinding2); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[][][]", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Type type = arrayType.getElementType();
+ assertTrue("Not a simple type", type instanceof SimpleType); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type;
+ checkSourceRange(simpleType, "Object", source); //$NON-NLS-1$
+ ITypeBinding typeBinding3 = simpleType.resolveBinding();
+ assertNotNull("no type binding3", typeBinding3); //$NON-NLS-1$
+ assertEquals("wrong name", "Object", typeBinding3.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ type = arrayType.getComponentType();
+ assertTrue("Not an array type", type instanceof ArrayType); //$NON-NLS-1$
+ ArrayType arrayType2 = (ArrayType) type;
+ checkSourceRange(arrayType2, "Object[10][]", source); //$NON-NLS-1$
+ ITypeBinding typeBinding4 = arrayType2.resolveBinding();
+ assertNotNull("no type binding4", typeBinding4); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[][]", typeBinding4.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ type = arrayType2.getComponentType();
+ assertTrue("Not an array type", type instanceof ArrayType); //$NON-NLS-1$
+ ArrayType arrayType3 = (ArrayType) type;
+ ITypeBinding typeBinding5 = arrayType3.resolveBinding();
+ assertNotNull("no type binding5", typeBinding5); //$NON-NLS-1$
+ assertEquals("wrong name", "Object[]", typeBinding5.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ checkSourceRange(arrayType3, "Object[10]", source); //$NON-NLS-1$
+ }
+
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=14526
+ * @deprecated using deprecated code
+ */
+ public void test0335() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0335", "ExceptionTestCaseTest.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ assertEquals("errors found", 0, compilationUnit.getProblems().length); //$NON-NLS-1$
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("not a type declaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ Name name = typeDeclaration.getSuperclass();
+ assertNotNull("no super class", name); //$NON-NLS-1$
+ assertTrue("not a qualified name", name.isQualifiedName()); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) name;
+ name = qualifiedName.getQualifier();
+ assertTrue("not a qualified name", name.isQualifiedName()); //$NON-NLS-1$
+ qualifiedName = (QualifiedName) name;
+ name = qualifiedName.getQualifier();
+ assertTrue("not a simple name", name.isSimpleName()); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) name;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("no binding", binding); //$NON-NLS-1$
+ assertEquals("wrong type", IBinding.PACKAGE, binding.getKind()); //$NON-NLS-1$
+ assertEquals("wrong name", "junit", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=14526
+ * @deprecated using deprecated code
+ */
+ public void test0336() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0336", "SorterTest.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ assertEquals("errors found", 0, compilationUnit.getProblems().length); //$NON-NLS-1$
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("not a type declaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ List superInterfaces = typeDeclaration.superInterfaces();
+ assertEquals("wrong size", 1, superInterfaces.size()); //$NON-NLS-1$
+ Name name = (Name) superInterfaces.get(0);
+ assertTrue("not a qualified name", name.isQualifiedName()); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) name;
+ name = qualifiedName.getQualifier();
+ assertTrue("not a simple name", name.isSimpleName()); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) name;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("no binding", binding); //$NON-NLS-1$
+ assertEquals("wrong type", IBinding.TYPE, binding.getKind()); //$NON-NLS-1$
+ assertEquals("wrong name", "Sorter", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=14602
+ */
+ public void test0337() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0337", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ checkSourceRange(variableDeclarationFragment, "message= Test.m(\"s\", new String[]{\"g\"})", source); //$NON-NLS-1$
+ checkSourceRange(fieldDeclaration, "String message= Test.m(\"s\", new String[]{\"g\"});", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=14852
+ */
+ public void test0338() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0338", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("not a MethodDeclaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List thrownExceptions = methodDeclaration.thrownExceptions();
+ assertEquals("Wrong size", 1, thrownExceptions.size()); //$NON-NLS-1$
+ Name name = (Name) thrownExceptions.get(0);
+ IBinding binding = name.resolveBinding();
+ assertEquals("wrong type", IBinding.TYPE, binding.getKind()); //$NON-NLS-1$
+ assertEquals("wrong name", "IOException", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=15061
+ */
+ public void test0339() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0339", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("No errors found", 3, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("not a Type declaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("wrong size", 1, bodyDeclarations.size()); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclarations.get(0);
+ checkSourceRange(methodDeclaration, "int doQuery(boolean x);", source); //$NON-NLS-1$
+ node = getASTNode(compilationUnit, 0, 1);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("not a MethodDeclaration", node instanceof MethodDeclaration); //$NON-NLS-1$
+ String expectedSource =
+ "public void setX(boolean x) {\n" + //$NON-NLS-1$
+ " {\n" + //$NON-NLS-1$
+ " z\n" + //$NON-NLS-1$
+ " }\n" + //$NON-NLS-1$
+ "}"; //$NON-NLS-1$
+ checkSourceRange(node, expectedSource, source);
+ int methodEndPosition = node.getStartPosition() + node.getLength();
+ node = getASTNode(compilationUnit, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ int typeEndPosition = node.getStartPosition() + node.getLength();
+ assertEquals("different positions", methodEndPosition, typeEndPosition); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=14852
+ */
+ public void test0340() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "p3", "B.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not an method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ assertNotNull("No receiver", expression2); //$NON-NLS-1$
+ ITypeBinding binding = expression2.resolveTypeBinding();
+ assertNotNull("No type binding", binding); //$NON-NLS-1$
+ assertEquals("wrong name", "A", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong name", "p2", binding.getPackage().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("Not a qualified name", expression2.getNodeType() == ASTNode.QUALIFIED_NAME); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) expression2;
+ SimpleName simpleName = qualifiedName.getName();
+ assertEquals("wrong name", "A", simpleName.getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ ITypeBinding typeBinding = simpleName.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("wrong name", "A", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong name", "p2", typeBinding.getPackage().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ Name name = qualifiedName.getQualifier();
+ assertTrue("Not a simple name", name.getNodeType() == ASTNode.SIMPLE_NAME); //$NON-NLS-1$
+ SimpleName simpleName2 = (SimpleName) name;
+ assertEquals("wrong name", "p2", simpleName2.getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding2 = simpleName2.resolveBinding();
+ assertNotNull("No binding", binding2); //$NON-NLS-1$
+ assertEquals("wrong type", IBinding.PACKAGE, binding2.getKind()); //$NON-NLS-1$
+ assertEquals("wrong name", "p2", binding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ node = getASTNode(compilationUnit, 0, 1, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement2 = (ExpressionStatement) node;
+ Expression expression3 = expressionStatement2.getExpression();
+ assertTrue("Not an method invocation", expression3.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation2 = (MethodInvocation) expression3;
+ Expression expression4 = methodInvocation2.getExpression();
+ assertNotNull("No receiver", expression4); //$NON-NLS-1$
+ ITypeBinding binding3 = expression4.resolveTypeBinding();
+ assertNotNull("No type binding", binding3); //$NON-NLS-1$
+ assertEquals("wrong name", "A", binding3.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("wrong name", "p1", binding3.getPackage().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=15804
+ */
+ public void test0341() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0341", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an if statement", node.getNodeType() == ASTNode.IF_STATEMENT); //$NON-NLS-1$
+ String expectedSource =
+ "if (field != null) {\n" + //$NON-NLS-1$
+ " throw new IOException();\n" + //$NON-NLS-1$
+ " } else if (field == null) {\n" + //$NON-NLS-1$
+ " throw new MalformedURLException();\n" + //$NON-NLS-1$
+ " } else if (field == null) {\n" + //$NON-NLS-1$
+ " throw new InterruptedIOException();\n" + //$NON-NLS-1$
+ " } else {\n" + //$NON-NLS-1$
+ " throw new UnsupportedEncodingException();\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(node, expectedSource, source);
+ IfStatement ifStatement = (IfStatement) node;
+ Statement thenStatement = ifStatement.getThenStatement();
+ expectedSource =
+ "{\n" + //$NON-NLS-1$
+ " throw new IOException();\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(thenStatement, expectedSource, source);
+ Statement elseStatement = ifStatement.getElseStatement();
+ expectedSource =
+ "if (field == null) {\n" + //$NON-NLS-1$
+ " throw new MalformedURLException();\n" + //$NON-NLS-1$
+ " } else if (field == null) {\n" + //$NON-NLS-1$
+ " throw new InterruptedIOException();\n" + //$NON-NLS-1$
+ " } else {\n" + //$NON-NLS-1$
+ " throw new UnsupportedEncodingException();\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(elseStatement, expectedSource, source);
+ assertTrue("Not a if statement", elseStatement.getNodeType() == ASTNode.IF_STATEMENT); //$NON-NLS-1$
+ ifStatement = (IfStatement) elseStatement;
+ thenStatement = ifStatement.getThenStatement();
+ expectedSource =
+ "{\n" + //$NON-NLS-1$
+ " throw new MalformedURLException();\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(thenStatement, expectedSource, source);
+ elseStatement = ifStatement.getElseStatement();
+ expectedSource =
+ "if (field == null) {\n" + //$NON-NLS-1$
+ " throw new InterruptedIOException();\n" + //$NON-NLS-1$
+ " } else {\n" + //$NON-NLS-1$
+ " throw new UnsupportedEncodingException();\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(elseStatement, expectedSource, source);
+ assertTrue("Not a if statement", elseStatement.getNodeType() == ASTNode.IF_STATEMENT); //$NON-NLS-1$
+ ifStatement = (IfStatement) elseStatement;
+ thenStatement = ifStatement.getThenStatement();
+ expectedSource =
+ "{\n" + //$NON-NLS-1$
+ " throw new InterruptedIOException();\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(thenStatement, expectedSource, source);
+ elseStatement = ifStatement.getElseStatement();
+ expectedSource =
+ "{\n" + //$NON-NLS-1$
+ " throw new UnsupportedEncodingException();\n" + //$NON-NLS-1$
+ " }"; //$NON-NLS-1$
+ checkSourceRange(elseStatement, expectedSource, source);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=15657
+ * @deprecated marked deprecated to suppress JDOM-related deprecation warnings
+ */
+ public void test0342() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0342", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IDOMCompilationUnit dcompUnit = new DOMFactory().createCompilationUnit(sourceUnit.getSource(), sourceUnit.getElementName());
+ assertNotNull("dcompUnit is null", dcompUnit); //$NON-NLS-1$
+
+ // searching class
+ IDOMType classNode = null;
+ Enumeration children = dcompUnit.getChildren();
+ assertNotNull("dcompUnit has no children", children); //$NON-NLS-1$
+
+ while (children.hasMoreElements()) {
+ IDOMNode child = (IDOMNode) children.nextElement();
+ if (child.getNodeType() == IDOMNode.TYPE) {
+ classNode = (IDOMType) child;
+ break;
+ }
+ }
+ assertNotNull("classNode is null", classNode); //$NON-NLS-1$
+
+ // searching for methods
+ children = classNode.getChildren();
+
+ assertNotNull("classNode has no children", children); //$NON-NLS-1$
+
+ while (children.hasMoreElements()) {
+ IDOMNode child = (IDOMNode) children.nextElement();
+ if (child.getNodeType() == IDOMNode.METHOD) {
+ IDOMMethod childMethod = (IDOMMethod) child;
+
+ // returnType is always null;
+ String returnType = childMethod.getReturnType();
+ if (childMethod.isConstructor()) {
+ assertNull(returnType);
+ } else {
+ assertNotNull("no return type", returnType); //$NON-NLS-1$
+ }
+ }
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=16051
+ */
+ public void test0343() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0343", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 1);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an if statement", node.getNodeType() == ASTNode.IF_STATEMENT); //$NON-NLS-1$
+ String expectedSource =
+ "if (flag)\n" + //$NON-NLS-1$
+ " i= 10;"; //$NON-NLS-1$
+ checkSourceRange(node, expectedSource, source);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=16132
+ */
+ public void test0344() throws JavaModelException {
+ IEclipsePreferences preferences = null;
+ String pb_assert = null;
+ String compiler_source = null;
+ String compiler_compliance = null;
+ try {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0344", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ preferences = new InstanceScope().getNode(JavaCore.PLUGIN_ID);
+ pb_assert = preferences.get(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, "");
+ compiler_source = preferences.get(JavaCore.COMPILER_SOURCE, "");
+ compiler_compliance = preferences.get(JavaCore.COMPILER_COMPLIANCE, "");
+
+ preferences.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR);
+ preferences.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4);
+ preferences.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4);
+
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ } finally {
+ if (preferences != null) {
+ preferences.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, pb_assert);
+ preferences.put(JavaCore.COMPILER_SOURCE, compiler_source);
+ preferences.put(JavaCore.COMPILER_COMPLIANCE, compiler_compliance);
+ }
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=17922
+ */
+ public void test0345() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0345", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not an ArrayCreation", expression.getNodeType() == ASTNode.ARRAY_CREATION); //$NON-NLS-1$
+ ArrayCreation arrayCreation = (ArrayCreation) expression;
+ ArrayType arrayType = arrayCreation.getType();
+ IBinding binding2 = arrayType.resolveBinding();
+ assertNotNull("no binding2", binding2); //$NON-NLS-1$
+ assertEquals("not a type", binding2.getKind(), IBinding.TYPE); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = (ITypeBinding) binding2;
+ assertTrue("Not an array type binding2", typeBinding2.isArray()); //$NON-NLS-1$
+ Type type = arrayType.getElementType();
+ assertTrue("Not a simple type", type.isSimpleType()); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type;
+ Name name = simpleType.getName();
+ assertTrue("QualifiedName", name.getNodeType() == ASTNode.QUALIFIED_NAME); //$NON-NLS-1$
+ SimpleName simpleName = ((QualifiedName) name).getName();
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("no binding", binding); //$NON-NLS-1$
+ assertEquals("not a type", binding.getKind(), IBinding.TYPE); //$NON-NLS-1$
+ ITypeBinding typeBinding = (ITypeBinding) binding;
+ assertTrue("An array type binding", !typeBinding.isArray()); //$NON-NLS-1$
+ Type type2 = fieldDeclaration.getType();
+ assertTrue("Not a array type", type2.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType2 = (ArrayType) type2;
+ Type type3 = arrayType2.getElementType();
+ assertTrue("Not a simple type", type3.isSimpleType()); //$NON-NLS-1$
+ SimpleType simpleType2 = (SimpleType) type3;
+ Name name2 = simpleType2.getName();
+ assertTrue("Not a qualified name", name2.getNodeType() == ASTNode.QUALIFIED_NAME); //$NON-NLS-1$
+ SimpleName simpleName2 = ((QualifiedName) name2).getName();
+ IBinding binding3 = simpleName2.resolveBinding();
+ assertNotNull("no binding", binding3); //$NON-NLS-1$
+ assertEquals("not a type", binding3.getKind(), IBinding.TYPE); //$NON-NLS-1$
+ ITypeBinding typeBinding3 = (ITypeBinding) binding3;
+ assertTrue("An array type binding", !typeBinding3.isArray()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=18138
+ */
+ public void test0346() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0346", "Test2.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an variable declaration", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ checkSourceRange(type, "Vector", source); //$NON-NLS-1$
+ assertTrue("not an array type", !type.isArrayType()); //$NON-NLS-1$
+ assertTrue("Not a simple type", type.isSimpleType()); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type;
+ Name name = simpleType.getName();
+ assertTrue("Not a simpleName", name.isSimpleName()); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) name;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.TYPE, binding.getKind()); //$NON-NLS-1$
+ ITypeBinding typeBinding = (ITypeBinding) binding;
+ assertTrue("An array", !typeBinding.isArray()); //$NON-NLS-1$
+ assertEquals("Wrong name", "Vector", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ ITypeBinding typeBinding2 = simpleType.resolveBinding();
+ assertNotNull("No binding", typeBinding2); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.TYPE, typeBinding2.getKind()); //$NON-NLS-1$
+ assertTrue("An array", !typeBinding2.isArray()); //$NON-NLS-1$
+ assertEquals("Wrong name", "Vector", typeBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=18138
+ */
+ public void test0347() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0347", "Test2.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an variable declaration", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ checkSourceRange(type, "Vector[]", source); //$NON-NLS-1$
+ assertTrue("not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ ITypeBinding binding = arrayType.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.TYPE, binding.getKind()); //$NON-NLS-1$
+ assertTrue("Not an array type", binding.isArray()); //$NON-NLS-1$
+ assertEquals("Wrong name", "Vector[]", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=18138
+ */
+ public void test0348() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0348", "Test2.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an variable declaration", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ checkSourceRange(type, "Vector[][]", source); //$NON-NLS-1$
+ assertTrue("not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ ITypeBinding binding = arrayType.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.TYPE, binding.getKind()); //$NON-NLS-1$
+ assertTrue("Not an array type", binding.isArray()); //$NON-NLS-1$
+ assertEquals("Wrong name", "Vector[][]", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=18138
+ */
+ public void test0349() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0349", "Test2.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ Type type = fieldDeclaration.getType();
+ checkSourceRange(type, "Vector[][]", source); //$NON-NLS-1$
+ assertTrue("not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ ITypeBinding binding = arrayType.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.TYPE, binding.getKind()); //$NON-NLS-1$
+ assertTrue("Not an array type", binding.isArray()); //$NON-NLS-1$
+ assertEquals("Wrong name", "Vector[][]", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=18138
+ */
+ public void test0350() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0350", "Test2.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ Type type = fieldDeclaration.getType();
+ checkSourceRange(type, "Vector", source); //$NON-NLS-1$
+ assertTrue("not a simple type", type.isSimpleType()); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type;
+ ITypeBinding binding = simpleType.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.TYPE, binding.getKind()); //$NON-NLS-1$
+ assertTrue("An array type", binding.isClass()); //$NON-NLS-1$
+ assertEquals("Wrong name", "Vector", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=18169
+ */
+ public void test0351() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0351", "Test2.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ assertEquals("wrong size", 2, parameters.size()); //$NON-NLS-1$
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ checkSourceRange(singleVariableDeclaration, "int a", source); //$NON-NLS-1$
+ singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(1);
+ checkSourceRange(singleVariableDeclaration, "int[] b", source); //$NON-NLS-1$
+ node = getASTNode(compilationUnit, 0, 1);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ parameters = methodDeclaration.parameters();
+ assertEquals("wrong size", 2, parameters.size()); //$NON-NLS-1$
+ singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ checkSourceRange(singleVariableDeclaration, "int a", source); //$NON-NLS-1$
+ singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(1);
+ checkSourceRange(singleVariableDeclaration, "int b[]", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=18169
+ */
+ public void test0352() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0352", "Test2.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ assertEquals("wrong size", 2, parameters.size()); //$NON-NLS-1$
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ checkSourceRange(singleVariableDeclaration, "final int a", source); //$NON-NLS-1$
+ singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(1);
+ checkSourceRange(singleVariableDeclaration, "final int[] b", source); //$NON-NLS-1$
+ node = getASTNode(compilationUnit, 0, 1);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ parameters = methodDeclaration.parameters();
+ assertEquals("wrong size", 2, parameters.size()); //$NON-NLS-1$
+ singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ checkSourceRange(singleVariableDeclaration, "final int a", source); //$NON-NLS-1$
+ singleVariableDeclaration = (SingleVariableDeclaration) parameters.get(1);
+ checkSourceRange(singleVariableDeclaration, "final int b[]", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=18042
+ */
+ public void test0353() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0353", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("not null", node); //$NON-NLS-1$
+ assertTrue("Not an variable declaration", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ checkSourceRange(type, "InputStream", source); //$NON-NLS-1$
+ assertTrue("not a simple type", type.isSimpleType()); //$NON-NLS-1$
+ ITypeBinding binding = type.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.TYPE, binding.getKind()); //$NON-NLS-1$
+ assertTrue("Not a class", binding.isClass()); //$NON-NLS-1$
+ assertEquals("Wrong name", "InputStream", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong package", "java.io", binding.getPackage().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ SimpleType simpleType = (SimpleType) type;
+ Name name = simpleType.getName();
+ IBinding binding2 = name.resolveBinding();
+ assertNotNull("No binding", binding2); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.TYPE, binding2.getKind()); //$NON-NLS-1$
+ ITypeBinding typeBinding = (ITypeBinding) binding2;
+ assertTrue("Not a class", typeBinding.isClass()); //$NON-NLS-1$
+ assertEquals("Wrong name", "InputStream", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong package", "java.io", typeBinding.getPackage().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=19851
+ */
+ public void test0354() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0354", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 2, compilationUnit.getMessages().length); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=20520
+ */
+ public void test0355() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0355", "Foo.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not an if statement", node.getNodeType() == ASTNode.IF_STATEMENT); //$NON-NLS-1$
+ IfStatement ifStatement = (IfStatement) node;
+ Expression condition = ifStatement.getExpression();
+ assertTrue("Not an infixExpression", condition.getNodeType() == ASTNode.INFIX_EXPRESSION); //$NON-NLS-1$
+ InfixExpression infixExpression = (InfixExpression) condition;
+ Expression expression = infixExpression.getLeftOperand();
+ assertTrue("Not a method invocation expression", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ assertTrue("Not a parenthesis expression", expression2.getNodeType() == ASTNode.PARENTHESIZED_EXPRESSION); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=20865
+ */
+ public void test0356() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0356", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 1, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ Type type = variableDeclarationStatement.getType();
+ ITypeBinding binding = type.resolveBinding();
+ assertNotNull("Binding should NOT be null for type: "+type, binding);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=21757
+ */
+ public void test0357() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0357", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertNotNull(node);
+ assertTrue("Not a type declaration statement", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ SimpleName name = typeDeclaration.getName();
+ checkSourceRange(name, "A", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=21768
+ */
+ public void test0358() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0358", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0,0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration statement", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ SimpleName name = methodDeclaration.getName();
+ checkSourceRange(name, "mdd", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=21768
+ */
+ public void test0359() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0359", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0,0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration statement", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ SimpleName name = methodDeclaration.getName();
+ checkSourceRange(name, "mdd", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=21916
+ */
+ public void test0360() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0360", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0,0, 0);
+ assertNotNull(node);
+ assertTrue("Not a for statement", node.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node;
+ List initializers = forStatement.initializers();
+ assertEquals("Wrong size", 1, initializers.size()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=21916
+ */
+ public void test0361() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0361", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0,0, 0);
+ assertNotNull(node);
+ assertTrue("Not a for statement", node.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node;
+ List initializers = forStatement.initializers();
+ assertEquals("Wrong size", 1, initializers.size()); //$NON-NLS-1$
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=21916
+ * @deprecated using deprecated code
+ */
+ public void test0362() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0362", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ ForStatement forStatement = this.ast.newForStatement();
+
+ VariableDeclarationFragment iFragment = this.ast.newVariableDeclarationFragment();
+ iFragment.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ iFragment.setInitializer(this.ast.newNumberLiteral("0"));//$NON-NLS-1$
+ VariableDeclarationFragment jFragment = this.ast.newVariableDeclarationFragment();
+ jFragment.setName(this.ast.newSimpleName("j")); //$NON-NLS-1$
+ jFragment.setInitializer(this.ast.newNumberLiteral("0"));//$NON-NLS-1$
+ VariableDeclarationFragment kFragment = this.ast.newVariableDeclarationFragment();
+ kFragment.setName(this.ast.newSimpleName("k")); //$NON-NLS-1$
+ kFragment.setInitializer(this.ast.newNumberLiteral("0"));//$NON-NLS-1$
+
+ VariableDeclarationExpression variableDeclarationExpression = this.ast.newVariableDeclarationExpression(iFragment);
+ variableDeclarationExpression.setModifiers(Modifier.NONE);
+ variableDeclarationExpression.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+ variableDeclarationExpression.fragments().add(jFragment);
+ variableDeclarationExpression.fragments().add(kFragment);
+ forStatement.initializers().add(variableDeclarationExpression);
+
+ PostfixExpression iPostfixExpression = this.ast.newPostfixExpression();
+ iPostfixExpression.setOperand(this.ast.newSimpleName("i"));//$NON-NLS-1$
+ iPostfixExpression.setOperator(PostfixExpression.Operator.INCREMENT);
+ forStatement.updaters().add(iPostfixExpression);
+
+ PostfixExpression jPostfixExpression = this.ast.newPostfixExpression();
+ jPostfixExpression.setOperand(this.ast.newSimpleName("j"));//$NON-NLS-1$
+ jPostfixExpression.setOperator(PostfixExpression.Operator.INCREMENT);
+ forStatement.updaters().add(jPostfixExpression);
+
+ PostfixExpression kPostfixExpression = this.ast.newPostfixExpression();
+ kPostfixExpression.setOperand(this.ast.newSimpleName("k"));//$NON-NLS-1$
+ kPostfixExpression.setOperator(PostfixExpression.Operator.INCREMENT);
+ forStatement.updaters().add(kPostfixExpression);
+
+ forStatement.setBody(this.ast.newBlock());
+
+ InfixExpression infixExpression = this.ast.newInfixExpression();
+ infixExpression.setLeftOperand(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ infixExpression.setOperator(InfixExpression.Operator.LESS);
+ infixExpression.setRightOperand(this.ast.newNumberLiteral("10")); //$NON-NLS-1$
+ forStatement.setExpression(infixExpression);
+
+ assertTrue("Both AST trees should be identical", forStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ checkSourceRange(node, "for (int i=0, j=0, k=0; i<10 ; i++, j++, k++) {}", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22939
+ */
+ public void test0363() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0363", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 1);
+ assertNotNull(node);
+ assertTrue("Not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a parenthesized expression", expression.getNodeType() == ASTNode.PARENTHESIZED_EXPRESSION); //$NON-NLS-1$
+ Expression expression2 = ((ParenthesizedExpression) expression).getExpression();
+ checkSourceRange(expression2, "xxxx", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11529
+ */
+ public void test0364() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0364", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ checkSourceRange(variableDeclarationStatement, "int local;", source); //$NON-NLS-1$
+ SimpleName simpleName = variableDeclarationFragment.getName();
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=11529
+ */
+ public void test0365() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0365", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a for statement", node.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node;
+ List initializers = forStatement.initializers();
+ assertEquals("Wrong size", 1, initializers.size()); //$NON-NLS-1$
+ VariableDeclarationExpression variableDeclarationExpression = (VariableDeclarationExpression) initializers.get(0);
+ List fragments = variableDeclarationExpression.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ SimpleName simpleName = variableDeclarationFragment.getName();
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23048
+ */
+ public void test0366() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0366", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a for statement", node.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node;
+ checkSourceRange(forStatement, "for (int i = 0; i < 5; ++i);", source); //$NON-NLS-1$
+ Statement statement = forStatement.getBody();
+ assertTrue("Not an empty statement", statement.getNodeType() == ASTNode.EMPTY_STATEMENT); //$NON-NLS-1$
+ checkSourceRange(statement, ";", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23048
+ */
+ public void test0367() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0367", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a while statement", node.getNodeType() == ASTNode.WHILE_STATEMENT); //$NON-NLS-1$
+ WhileStatement whileStatement = (WhileStatement) node;
+ checkSourceRange(whileStatement, "while(i == 2);", source); //$NON-NLS-1$
+ Statement statement = whileStatement.getBody();
+ assertTrue("Not an empty statement", statement.getNodeType() == ASTNode.EMPTY_STATEMENT); //$NON-NLS-1$
+ checkSourceRange(statement, ";", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23048
+ */
+ public void test0368() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0368", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 1, "The label test is never explicitly referenced"); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a labeled statement", node.getNodeType() == ASTNode.LABELED_STATEMENT); //$NON-NLS-1$
+ LabeledStatement labeledStatement = (LabeledStatement) node;
+ checkSourceRange(labeledStatement, "test:;", source); //$NON-NLS-1$
+ Statement statement = labeledStatement.getBody();
+ assertTrue("Not an empty statement", statement.getNodeType() == ASTNode.EMPTY_STATEMENT); //$NON-NLS-1$
+ checkSourceRange(statement, ";", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23048
+ */
+ public void test0369() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0369", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 1, "The label test is never explicitly referenced"); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a labeled statement", node.getNodeType() == ASTNode.LABELED_STATEMENT); //$NON-NLS-1$
+ LabeledStatement labeledStatement = (LabeledStatement) node;
+ checkSourceRange(labeledStatement, "test:\\u003B", source); //$NON-NLS-1$
+ Statement statement = labeledStatement.getBody();
+ assertTrue("Not an empty statement", statement.getNodeType() == ASTNode.EMPTY_STATEMENT); //$NON-NLS-1$
+ checkSourceRange(statement, "\\u003B", source); //$NON-NLS-1$
+ }
+
+ /**
+ * DoStatement ==> DoStatement
+ */
+ public void test0370() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0370", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull("Expression should not be null", node); //$NON-NLS-1$
+ DoStatement doStatement = this.ast.newDoStatement();
+ doStatement.setBody(this.ast.newEmptyStatement());
+ doStatement.setExpression(this.ast.newBooleanLiteral(true));
+ assertTrue("Both AST trees should be identical", doStatement.subtreeMatch(new ASTMatcher(), node)); //$NON-NLS-1$
+ String expectedSource = "do ; while(true);";//$NON-NLS-1$
+ checkSourceRange(node, expectedSource, source);
+ DoStatement doStatement2 = (DoStatement) node;
+ Statement statement = doStatement2.getBody();
+ assertTrue("Not an empty statement", statement.getNodeType() == ASTNode.EMPTY_STATEMENT); //$NON-NLS-1$
+ checkSourceRange(statement, ";", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23048
+ */
+ public void test0371() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0371", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a labeled statement", node.getNodeType() == ASTNode.IF_STATEMENT); //$NON-NLS-1$
+ IfStatement ifStatement = (IfStatement) node;
+ checkSourceRange(ifStatement, "if (i == 6);", source); //$NON-NLS-1$
+ Statement statement = ifStatement.getThenStatement();
+ assertTrue("Not an empty statement", statement.getNodeType() == ASTNode.EMPTY_STATEMENT); //$NON-NLS-1$
+ checkSourceRange(statement, ";", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23048
+ */
+ public void test0372() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0372", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a labeled statement", node.getNodeType() == ASTNode.IF_STATEMENT); //$NON-NLS-1$
+ IfStatement ifStatement = (IfStatement) node;
+ checkSourceRange(ifStatement, "if (i == 6) {} else ;", source); //$NON-NLS-1$
+ Statement statement = ifStatement.getElseStatement();
+ assertTrue("Not an empty statement", statement.getNodeType() == ASTNode.EMPTY_STATEMENT); //$NON-NLS-1$
+ checkSourceRange(statement, ";", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23118
+ */
+ public void test0373() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0373", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 1, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a for statement", node.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node;
+ Statement statement = forStatement.getBody();
+ assertTrue("Not a block statement", statement.getNodeType() == ASTNode.BLOCK); //$NON-NLS-1$
+ Block block = (Block) statement;
+ List statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement statement2 = (Statement) statements.get(0);
+ assertTrue("Not a break statement", statement2.getNodeType() == ASTNode.BREAK_STATEMENT); //$NON-NLS-1$
+ BreakStatement breakStatement = (BreakStatement) statement2;
+ checkSourceRange(breakStatement, "break;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23118
+ */
+ public void test0374() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0374", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a for statement", node.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node;
+ Statement statement = forStatement.getBody();
+ assertTrue("Not a block statement", statement.getNodeType() == ASTNode.BLOCK); //$NON-NLS-1$
+ Block block = (Block) statement;
+ List statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement statement2 = (Statement) statements.get(0);
+ assertTrue("Not a break statement", statement2.getNodeType() == ASTNode.CONTINUE_STATEMENT); //$NON-NLS-1$
+ ContinueStatement continueStatement = (ContinueStatement) statement2;
+ checkSourceRange(continueStatement, "continue;", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23052
+ */
+ public void test0375() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0375", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("problems found", 1, compilationUnit.getMessages().length); //$NON-NLS-1$
+ List imports = compilationUnit.imports();
+ assertEquals("wrong size", 1, imports.size()); //$NON-NLS-1$
+ ImportDeclaration importDeclaration = (ImportDeclaration) imports.get(0);
+ IBinding binding = importDeclaration.resolveBinding();
+ assertNotNull("no binding", binding); //$NON-NLS-1$
+ assertEquals("Not a type binding", IBinding.TYPE, binding.getKind()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22939
+ */
+ public void test0376() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0376", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a cast expression", expression.getNodeType() == ASTNode.CAST_EXPRESSION); //$NON-NLS-1$
+ Type type = ((CastExpression) expression).getType();
+ checkSourceRange(type, "A", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23050
+ */
+ public void test0377() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0377", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = variableDeclarationFragment.resolveBinding();
+ assertNotNull("No variable binding", variableBinding); //$NON-NLS-1$
+ assertEquals("Wrong modifier", IModifierConstants.ACC_FINAL, variableBinding.getModifiers()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22161
+ */
+ public void test0378() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0378", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ SimpleName name = typeDeclaration.getName();
+ checkSourceRange(name, "B", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22161
+ * @deprecated using deprecated code
+ */
+ public void test0379() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0379", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode expression = getASTNodeToCompare((CompilationUnit) result);
+ assertNotNull("Expression should not be null", expression); //$NON-NLS-1$
+ assertTrue("Not a class instance creation", expression.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation2 = (ClassInstanceCreation) expression;
+ Name name2 = classInstanceCreation2.getName();
+ checkSourceRange(name2, "Object", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22054
+ */
+ public void test0380() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0380", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a return statement", node.getNodeType() == ASTNode.RETURN_STATEMENT); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertTrue("Not a super method invocation", expression.getNodeType() == ASTNode.SUPER_METHOD_INVOCATION); //$NON-NLS-1$
+ SuperMethodInvocation superMethodInvocation = (SuperMethodInvocation) expression;
+ ITypeBinding typeBinding = superMethodInvocation.resolveTypeBinding();
+ assertNotNull("no type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("wrong declaring class", typeBinding.getSuperclass().getName(), "Object"); //$NON-NLS-1$ //$NON-NLS-2$
+ SimpleName simpleName = superMethodInvocation.getName();
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("no binding", binding); //$NON-NLS-1$
+ assertEquals("Wrong type", IBinding.METHOD, binding.getKind()); //$NON-NLS-1$
+ IMethodBinding methodBinding = (IMethodBinding) binding;
+ assertEquals("Wrong declaring class", methodBinding.getDeclaringClass().getName(), "Object"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23054
+ */
+ public void test0381() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0381", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertNotNull(node);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ Javadoc javadoc = typeDeclaration.getJavadoc();
+ assertNull("Javadoc not null", javadoc); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22154
+ */
+ public void test0382() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0382", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertNotNull(node);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertEquals("Wrong fully qualified name", typeBinding.getQualifiedName(), "test0382.A"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22154
+ */
+ public void test0383() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0383", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertEquals("Wrong fully qualified name", typeBinding.getQualifiedName(), "test0383.A.B"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22154
+ */
+ public void test0384() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0384", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertEquals("Wrong fully qualified name", typeBinding.getQualifiedName(), "test0384.A.B.D"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23117
+ */
+ public void test0385() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0385", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 1, compilationUnit.getMessages().length); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23259
+ */
+ public void test0386() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0386", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a switch statement", node.getNodeType() == ASTNode.SWITCH_STATEMENT); //$NON-NLS-1$
+ SwitchStatement switchStatement = (SwitchStatement) node;
+ List statements = switchStatement.statements();
+ assertEquals("Wrong size", 5, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("Not a case statement", statement.getNodeType() == ASTNode.SWITCH_CASE); //$NON-NLS-1$
+ checkSourceRange(statement, "case 1:", source); //$NON-NLS-1$
+ statement = (Statement) statements.get(3);
+ assertTrue("Not a default case statement", statement.getNodeType() == ASTNode.SWITCH_CASE); //$NON-NLS-1$
+ checkSourceRange(statement, "default :", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22939
+ */
+ public void test0387() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0387", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("Wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not a cast expression", expression.getNodeType() == ASTNode.CAST_EXPRESSION); //$NON-NLS-1$
+ Type type = ((CastExpression) expression).getType();
+ checkSourceRange(type, "A", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22154
+ */
+ public void test0388() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0388", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertNotNull(node);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong qualified name", "test0388.A", typeBinding.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22154
+ */
+ public void test0389() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0389", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong qualified name", "test0389.A.B", typeBinding.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22154
+ * @deprecated using deprecated code
+ */
+ public void test0390() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0390", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Type type = methodDeclaration.getReturnType();
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong qualified name", "int", typeBinding.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22154
+ * @deprecated using deprecated code
+ */
+ public void test0391() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0391", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Type type = methodDeclaration.getReturnType();
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong qualified name", "int[]", typeBinding.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22154
+ * @deprecated using deprecated code
+ */
+ public void test0392() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0392", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Type type = methodDeclaration.getReturnType();
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong qualified name", "java.lang.String[]", typeBinding.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23284
+ * @deprecated using deprecated code
+ */
+ public void test0393() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0393", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Type type = methodDeclaration.getReturnType();
+ checkSourceRange(type, "String", source); //$NON-NLS-1$
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong dimension", 0, typeBinding.getDimensions()); //$NON-NLS-1$
+ assertEquals("Wrong qualified name", "java.lang.String", typeBinding.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong dimension", 1, methodDeclaration.getExtraDimensions()); //$NON-NLS-1$
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ assertNotNull("No method binding", methodBinding); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = methodBinding.getReturnType();
+ assertNotNull("No type binding", typeBinding2); //$NON-NLS-1$
+ assertEquals("Wrong qualified name", "java.lang.String[]", typeBinding2.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong dimension", 1, typeBinding2.getDimensions()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23284
+ * @deprecated using deprecated code
+ */
+ public void test0394() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0394", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Type type = methodDeclaration.getReturnType();
+ checkSourceRange(type, "String", source); //$NON-NLS-1$
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong qualified name", "java.lang.String", typeBinding.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong dimension", 0, methodDeclaration.getExtraDimensions()); //$NON-NLS-1$
+ }
+
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23284
+ * @deprecated using deprecated code
+ */
+ public void test0395() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0395", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("errors found", 0, compilationUnit.getMessages().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Type type = methodDeclaration.getReturnType();
+ checkSourceRange(type, "String[]", source); //$NON-NLS-1$
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong dimension", 1, typeBinding.getDimensions()); //$NON-NLS-1$
+ assertEquals("Wrong qualified name", "java.lang.String[]", typeBinding.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong dimension", 1, methodDeclaration.getExtraDimensions()); //$NON-NLS-1$
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ assertNotNull("No method binding", methodBinding); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = methodBinding.getReturnType();
+ assertNotNull("No type binding", typeBinding2); //$NON-NLS-1$
+ assertEquals("Wrong qualified name", "java.lang.String[][]", typeBinding2.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong dimension", 2, typeBinding2.getDimensions()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23284
+ */
+ public void test0396() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0396", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration method = (MethodDeclaration) node;
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) method.parameters().get(0);
+ assertNotNull("Expression should not be null", singleVariableDeclaration); //$NON-NLS-1$
+ checkSourceRange(singleVariableDeclaration, "final String s[]", source); //$NON-NLS-1$
+ Type type = singleVariableDeclaration.getType();
+ checkSourceRange(type, "String", source); //$NON-NLS-1$
+ assertEquals("Wrong dimension", 1, singleVariableDeclaration.getExtraDimensions()); //$NON-NLS-1$
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertTrue("An array binding", !typeBinding.isArray()); //$NON-NLS-1$
+ assertEquals("Wrong dimension", 0, typeBinding.getDimensions()); //$NON-NLS-1$
+ assertEquals("wrong fully qualified name", "java.lang.String", typeBinding.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IVariableBinding variableBinding = singleVariableDeclaration.resolveBinding();
+ assertNotNull("No variable binding", variableBinding); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = variableBinding.getType();
+ assertNotNull("No type binding", typeBinding2); //$NON-NLS-1$
+ assertTrue("Not an array binding", typeBinding2.isArray()); //$NON-NLS-1$
+ assertEquals("Wrong dimension", 1, typeBinding2.getDimensions()); //$NON-NLS-1$
+ assertEquals("wrong fully qualified name", "java.lang.String[]", typeBinding2.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23284
+ */
+ public void test0397() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0397", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration method = (MethodDeclaration) node;
+ SingleVariableDeclaration singleVariableDeclaration = (SingleVariableDeclaration) method.parameters().get(0);
+ assertNotNull("Expression should not be null", singleVariableDeclaration); //$NON-NLS-1$
+ checkSourceRange(singleVariableDeclaration, "final String[] \\u0073\\u005B][]", source); //$NON-NLS-1$
+ Type type = singleVariableDeclaration.getType();
+ checkSourceRange(type, "String[]", source); //$NON-NLS-1$
+ assertEquals("Wrong dimension", 2, singleVariableDeclaration.getExtraDimensions()); //$NON-NLS-1$
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertTrue("Not an array binding", typeBinding.isArray()); //$NON-NLS-1$
+ assertEquals("Wrong dimension", 1, typeBinding.getDimensions()); //$NON-NLS-1$
+ assertEquals("wrong fully qualified name", "java.lang.String[]", typeBinding.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IVariableBinding variableBinding = singleVariableDeclaration.resolveBinding();
+ assertNotNull("No variable binding", variableBinding); //$NON-NLS-1$
+ ITypeBinding typeBinding2 = variableBinding.getType();
+ assertNotNull("No type binding", typeBinding2); //$NON-NLS-1$
+ assertTrue("Not an array binding", typeBinding2.isArray()); //$NON-NLS-1$
+ assertEquals("Wrong dimension", 3, typeBinding2.getDimensions()); //$NON-NLS-1$
+ assertEquals("wrong fully qualified name", "java.lang.String[][][]", typeBinding2.getQualifiedName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23362
+ */
+ public void test0398() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0398", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("wrong size", 1, fragments.size()); //$NON-NLS-1$
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = variableDeclarationFragment.getInitializer();
+ assertTrue("Not an infix expression", expression.getNodeType() == ASTNode.INFIX_EXPRESSION); //$NON-NLS-1$
+ InfixExpression infixExpression = (InfixExpression) expression;
+ checkSourceRange(infixExpression, "(1 + 2) * 3", source); //$NON-NLS-1$
+ Expression expression2 = infixExpression.getLeftOperand();
+ assertTrue("Not an parenthesis expression", expression2.getNodeType() == ASTNode.PARENTHESIZED_EXPRESSION); //$NON-NLS-1$
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression2;
+ Expression expression3 = parenthesizedExpression.getExpression();
+ assertTrue("Not an infix expression", expression3.getNodeType() == ASTNode.INFIX_EXPRESSION); //$NON-NLS-1$
+ checkSourceRange(expression3, "1 + 2", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22306
+ */
+ public void test0399() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0399", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Not a constructor", methodDeclaration.isConstructor()); //$NON-NLS-1$
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("wrong size", 2, statements.size()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22306
+ */
+ public void test0400() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0400", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Not a constructor", methodDeclaration.isConstructor()); //$NON-NLS-1$
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("wrong size", 3, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("Not an superconstructorinvocation", statement.getNodeType() == ASTNode.SUPER_CONSTRUCTOR_INVOCATION); //$NON-NLS-1$
+ checkSourceRange(statement, "super();", source); //$NON-NLS-1$
+ }
+}
+
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest2.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest2.java
new file mode 100644
index 0000000..2c779ff
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTest2.java
@@ -0,0 +1,5573 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2009 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.dom;
+
+import java.io.IOException;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.Test;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.jdt.core.*;
+import org.eclipse.jdt.core.compiler.IProblem;
+import org.eclipse.jdt.core.dom.*;
+import org.eclipse.jdt.core.tests.model.CancelCounter;
+import org.eclipse.jdt.core.tests.model.Canceler;
+import org.eclipse.jdt.core.tests.model.ReconcilerTests;
+import org.eclipse.jdt.core.tests.util.Util;
+
+public class ASTConverterTest2 extends ConverterTestSetup {
+
+ /** @deprecated using deprecated code */
+ public void setUpSuite() throws Exception {
+ super.setUpSuite();
+ this.ast = AST.newAST(AST.JLS2);
+ }
+
+ public ASTConverterTest2(String name) {
+ super(name);
+ }
+
+ static {
+// TESTS_NAMES = new String[] {"test0578"};
+// TESTS_NUMBERS = new int[] { 608 };
+ }
+ public static Test suite() {
+ return buildModelTestSuite(ASTConverterTest2.class);
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22560
+ * @deprecated using deprecated code
+ */
+ public void test0401() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0401", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("Not a return statement", statement.getNodeType() == ASTNode.RETURN_STATEMENT); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) statement;
+ Expression expression = returnStatement.getExpression();
+ assertNotNull("there is no expression", expression); //$NON-NLS-1$
+ // call the default initialization
+ methodDeclaration.getReturnType();
+ ITypeBinding typeBinding = expression.resolveTypeBinding();
+ assertNotNull("No typebinding", typeBinding); //$NON-NLS-1$
+ assertEquals("wrong name", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23464
+ */
+ public void test0402() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0402", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 1, 0, 0);
+ assertEquals("Wrong number of problems", 0, ((CompilationUnit) result).getProblems().length); //$NON-NLS-1$
+ assertNotNull(node);
+ assertTrue("Not a super method invocation", node.getNodeType() == ASTNode.SUPER_CONSTRUCTOR_INVOCATION); //$NON-NLS-1$
+ checkSourceRange(node, "new A().super();", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23597
+ */
+ public void test0403() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0403", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 1, 0, 1);
+ assertEquals("Wrong number of problems", 1, ((CompilationUnit) result).getProblems().length); //$NON-NLS-1$
+ assertNotNull(node);
+ assertTrue("Not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ assertTrue("Not a simple name", expression2.getNodeType() == ASTNode.SIMPLE_NAME); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) expression2;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("wrong type", binding.getKind() == IBinding.VARIABLE); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Wrong name", "test", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ SimpleName simpleName2 = methodInvocation.getName();
+ assertEquals("Wrong name", "clone", simpleName2.getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding2 = simpleName2.resolveBinding();
+ assertNotNull("no binding2", binding2); //$NON-NLS-1$
+ assertTrue("Wrong type", binding2.getKind() == IBinding.METHOD); //$NON-NLS-1$
+ IMethodBinding methodBinding = (IMethodBinding) binding2;
+ assertEquals("Wrong name", "clone", methodBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IMethodBinding methodBinding2 = methodInvocation.resolveMethodBinding();
+ assertNotNull("No method binding2", methodBinding2);
+ assertTrue("Wrong binding", methodBinding == methodBinding2);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23597
+ */
+ public void test0404() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0404", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertEquals("Wrong number of problems", 1, ((CompilationUnit) result).getProblems().length); //$NON-NLS-1$
+ assertNotNull(node);
+ assertTrue("Not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ assertTrue("Not a simple name", expression2.getNodeType() == ASTNode.SIMPLE_NAME); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) expression2;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("wrong type", binding.getKind() == IBinding.VARIABLE); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Wrong name", "a", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ SimpleName simpleName2 = methodInvocation.getName();
+ assertEquals("Wrong name", "clone", simpleName2.getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding2 = simpleName2.resolveBinding();
+ assertNotNull("no binding2", binding2); //$NON-NLS-1$
+ assertTrue("Wrong type", binding2.getKind() == IBinding.METHOD); //$NON-NLS-1$
+ IMethodBinding methodBinding = (IMethodBinding) binding2;
+ assertEquals("Wrong name", "clone", methodBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23597
+ */
+ public void test0405() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0405", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 1, 0, 1);
+ assertEquals("Wrong number of problems", 1, ((CompilationUnit) result).getProblems().length); //$NON-NLS-1$
+ assertNotNull(node);
+ assertTrue("Not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ assertTrue("Not a simple name", expression2.getNodeType() == ASTNode.SIMPLE_NAME); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) expression2;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("wrong type", binding.getKind() == IBinding.VARIABLE); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Wrong name", "a", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ SimpleName simpleName2 = methodInvocation.getName();
+ assertEquals("Wrong name", "clone", simpleName2.getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding2 = simpleName2.resolveBinding();
+ assertNotNull("no binding2", binding2); //$NON-NLS-1$
+ assertTrue("Wrong type", binding2.getKind() == IBinding.METHOD); //$NON-NLS-1$
+ IMethodBinding methodBinding = (IMethodBinding) binding2;
+ assertEquals("Wrong name", "clone", methodBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23597
+ */
+ public void test0406() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0406", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ CompilationUnit unit = (CompilationUnit) result;
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertEquals("Wrong number of problems", 1, ((CompilationUnit) result).getProblems().length); //$NON-NLS-1$
+ assertNotNull(node);
+ assertTrue("Not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ assertTrue("Not a simple name", expression2.getNodeType() == ASTNode.SIMPLE_NAME); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) expression2;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("wrong type", binding.getKind() == IBinding.VARIABLE); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Wrong name", "a", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ SimpleName simpleName2 = methodInvocation.getName();
+ assertEquals("Wrong name", "foo", simpleName2.getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding2 = simpleName2.resolveBinding();
+ assertNotNull("no binding2", binding2); //$NON-NLS-1$
+ assertTrue("Wrong type", binding2.getKind() == IBinding.METHOD); //$NON-NLS-1$
+ IMethodBinding methodBinding = (IMethodBinding) binding2;
+ assertEquals("Wrong name", "foo", methodBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertNull("Got a declaring node in the unit", unit.findDeclaringNode(methodBinding));
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23162
+ */
+ public void test0407() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0407", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertEquals("Wrong number of problems", 0, ((CompilationUnit) result).getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ CompilationUnit unit = (CompilationUnit) result;
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ SimpleName simpleName = methodDeclaration.getName();
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("Not a method binding", binding.getKind() == IBinding.METHOD); //$NON-NLS-1$
+ IMethodBinding methodBinding = (IMethodBinding) binding;
+ assertEquals("wrong name", "foo", methodBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ methodDeclaration.setName(methodDeclaration.getAST().newSimpleName("foo2")); //$NON-NLS-1$
+ IMethodBinding methodBinding2 = methodDeclaration.resolveBinding();
+ assertNotNull("No methodbinding2", methodBinding2); //$NON-NLS-1$
+ assertEquals("wrong name", "foo", methodBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ simpleName = methodDeclaration.getName();
+ IBinding binding2 = simpleName.resolveBinding();
+ assertNull("Got a binding2", binding2); //$NON-NLS-1$
+
+ ASTNode astNode = unit.findDeclaringNode(methodBinding);
+ assertNotNull("No declaring node", astNode);
+ assertEquals("wrong declaring node", methodDeclaration, astNode);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23162
+ * @deprecated using deprecated code
+ */
+ public void test0408() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0408", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertEquals("Wrong number of problems", 0, ((CompilationUnit) result).getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Type type = methodDeclaration.getReturnType();
+ assertTrue("Not a simple type", type.isSimpleType()); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type;
+ Name name = simpleType.getName();
+ assertTrue("Not a qualified name", name.isQualifiedName()); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) name;
+ name = qualifiedName.getQualifier();
+ assertTrue("Not a qualified name", name.isQualifiedName()); //$NON-NLS-1$
+ qualifiedName = (QualifiedName) name;
+ name = qualifiedName.getQualifier();
+ assertTrue("Not a simple name", name.isSimpleName()); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) name;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("Not a package binding", binding.getKind() == IBinding.PACKAGE); //$NON-NLS-1$
+ assertEquals("Wrong name", "java", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23162
+ */
+ public void test0409() throws JavaModelException {
+ Hashtable options = JavaCore.getOptions();
+ Hashtable newOptions = JavaCore.getOptions();
+ try {
+ newOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4);
+ JavaCore.setOptions(newOptions);
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0409", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ BindingsCollectorVisitor bindingsCollectorVisitor = new BindingsCollectorVisitor();
+ compilationUnit.accept(bindingsCollectorVisitor);
+ assertEquals("wrong number", 3, bindingsCollectorVisitor.getUnresolvedNodesSet().size()); //$NON-NLS-1$
+ Map bindingsMap = bindingsCollectorVisitor.getBindingsMap();
+ assertEquals("wrong number", 205, bindingsMap.size()); //$NON-NLS-1$
+ ASTNodesCollectorVisitor nodesCollector = new ASTNodesCollectorVisitor();
+ compilationUnit.accept(nodesCollector);
+ Set detachedNodes = nodesCollector.getDetachedAstNodes();
+ int counter = 0;
+ for (Iterator iterator = detachedNodes.iterator(); iterator.hasNext(); ) {
+ ASTNode detachedNode = (ASTNode) iterator.next();
+ counter++;
+ IBinding binding = (IBinding) bindingsMap.get(detachedNode);
+ assertNotNull(binding);
+ switch(detachedNode.getNodeType()) {
+ case ASTNode.ARRAY_ACCESS :
+ case ASTNode.ARRAY_CREATION :
+ case ASTNode.ARRAY_INITIALIZER :
+ case ASTNode.ASSIGNMENT :
+ case ASTNode.BOOLEAN_LITERAL :
+ case ASTNode.CAST_EXPRESSION :
+ case ASTNode.CHARACTER_LITERAL :
+ case ASTNode.CLASS_INSTANCE_CREATION :
+ case ASTNode.CONDITIONAL_EXPRESSION :
+ case ASTNode.FIELD_ACCESS :
+ case ASTNode.INFIX_EXPRESSION :
+ case ASTNode.INSTANCEOF_EXPRESSION :
+ case ASTNode.METHOD_INVOCATION :
+ case ASTNode.NULL_LITERAL :
+ case ASTNode.NUMBER_LITERAL :
+ case ASTNode.POSTFIX_EXPRESSION :
+ case ASTNode.PREFIX_EXPRESSION :
+ case ASTNode.THIS_EXPRESSION :
+ case ASTNode.TYPE_LITERAL :
+ case ASTNode.VARIABLE_DECLARATION_EXPRESSION :
+ ITypeBinding typeBinding = ((Expression) detachedNode).resolveTypeBinding();
+ if (!binding.equals(typeBinding)) {
+ System.out.println(detachedNode);
+ }
+ assertTrue("binding not equals", binding.equals(typeBinding)); //$NON-NLS-1$
+ break;
+ case ASTNode.VARIABLE_DECLARATION_FRAGMENT :
+ assertTrue("binding not equals", binding.equals(((VariableDeclarationFragment) detachedNode).resolveBinding())); //$NON-NLS-1$
+ break;
+ case ASTNode.ANONYMOUS_CLASS_DECLARATION :
+ assertTrue("binding not equals", binding.equals(((AnonymousClassDeclaration) detachedNode).resolveBinding())); //$NON-NLS-1$
+ break;
+ case ASTNode.QUALIFIED_NAME :
+ case ASTNode.SIMPLE_NAME :
+ IBinding newBinding = ((Name) detachedNode).resolveBinding();
+ assertTrue("binding not equals", binding.equals(newBinding)); //$NON-NLS-1$
+ break;
+ case ASTNode.ARRAY_TYPE :
+ case ASTNode.SIMPLE_TYPE :
+ case ASTNode.PRIMITIVE_TYPE :
+ assertTrue("binding not equals", binding.equals(((Type) detachedNode).resolveBinding())); //$NON-NLS-1$
+ break;
+ case ASTNode.CONSTRUCTOR_INVOCATION :
+ assertTrue("binding not equals", binding.equals(((ConstructorInvocation) detachedNode).resolveConstructorBinding())); //$NON-NLS-1$
+ break;
+ case ASTNode.IMPORT_DECLARATION :
+ assertTrue("binding not equals", binding.equals(((ImportDeclaration) detachedNode).resolveBinding())); //$NON-NLS-1$
+ break;
+ case ASTNode.METHOD_DECLARATION :
+ assertTrue("binding not equals", binding.equals(((MethodDeclaration) detachedNode).resolveBinding())); //$NON-NLS-1$
+ break;
+ case ASTNode.PACKAGE_DECLARATION :
+ assertTrue("binding not equals", binding.equals(((PackageDeclaration) detachedNode).resolveBinding())); //$NON-NLS-1$
+ break;
+ case ASTNode.TYPE_DECLARATION :
+ assertTrue("binding not equals", binding.equals(((TypeDeclaration) detachedNode).resolveBinding())); //$NON-NLS-1$
+ break;
+ }
+ }
+ } finally {
+ JavaCore.setOptions(options);
+ }
+ }
+
+ /**
+ * Test for message on jdt-core-dev
+ */
+ public void test0410() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0410", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertEquals("Wrong number of problems", 0, ((CompilationUnit) result).getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a return statement", node.getNodeType() == ASTNode.RETURN_STATEMENT); //$NON-NLS-1$
+ Expression expression = ((ReturnStatement) node).getExpression();
+ assertTrue("Not an infix expression", expression.getNodeType() == ASTNode.INFIX_EXPRESSION); //$NON-NLS-1$
+ InfixExpression infixExpression = (InfixExpression) expression;
+ List extendedOperands = infixExpression.extendedOperands();
+ assertEquals("wrong size", 3, extendedOperands.size()); //$NON-NLS-1$
+ }
+
+ /**
+ * Test for message on jdt-core-dev
+ */
+ public void test0411() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0411", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertEquals("Wrong number of problems", 0, ((CompilationUnit) result).getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a return statement", node.getNodeType() == ASTNode.RETURN_STATEMENT); //$NON-NLS-1$
+ Expression expression = ((ReturnStatement) node).getExpression();
+ assertTrue("Not an infix expression", expression.getNodeType() == ASTNode.INFIX_EXPRESSION); //$NON-NLS-1$
+ InfixExpression infixExpression = (InfixExpression) expression;
+ List extendedOperands = infixExpression.extendedOperands();
+ assertEquals("wrong size", 0, extendedOperands.size()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=23901
+ */
+ public void test0412() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0412", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0);
+ assertNotNull(node);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ assertTrue("Not an interface", typeDeclaration.isInterface()); //$NON-NLS-1$
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertNotNull("No declaring node", unit.findDeclaringNode(typeBinding)); //$NON-NLS-1$
+ Name name = typeDeclaration.getName();
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ ASTNode declaringNode = unit.findDeclaringNode(binding);
+ assertNotNull("No declaring node", declaringNode); //$NON-NLS-1$
+ assertEquals("Wrong node", typeDeclaration, declaringNode); //$NON-NLS-1$
+ typeBinding = name.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ declaringNode = unit.findDeclaringNode(typeBinding);
+ assertNotNull("No declaring node", declaringNode); //$NON-NLS-1$
+ assertEquals("Wrong node", typeDeclaration, declaringNode); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=20881
+ */
+ public void test0413() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0413", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 1, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List throwsException = methodDeclaration.thrownExceptions();
+ assertEquals("wrong size", 2, throwsException.size()); //$NON-NLS-1$
+ Name name = (Name) throwsException.get(0);
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("LIOException;", binding.getKey());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=23734
+ * @deprecated using deprecated code
+ */
+ public void test0414() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0414", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Type type = methodDeclaration.getReturnType();
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ ASTNode declaringNode = unit.findDeclaringNode(typeBinding);
+ assertNull("Got a declaring node", declaringNode); //$NON-NLS-1$
+
+ node = getASTNode(unit, 0, 1);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration2 = (MethodDeclaration) node;
+ Type type2 = methodDeclaration2.getReturnType();
+ ITypeBinding typeBinding2 = type2.resolveBinding();
+ assertNotNull("No type binding", typeBinding2); //$NON-NLS-1$
+ ASTNode declaringNode2 = unit.findDeclaringNode(typeBinding2);
+ assertNotNull("No declaring node", declaringNode2); //$NON-NLS-1$
+
+ ICompilationUnit sourceUnit2 = getCompilationUnit("Converter" , "src", "test0414", "B.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+
+ result = runConversion(sourceUnit2, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit2 = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit2.getProblems().length); //$NON-NLS-1$
+ ASTNode declaringNode3 = unit2.findDeclaringNode(typeBinding);
+ assertNull("Got a declaring node", declaringNode3); //$NON-NLS-1$
+
+ ASTNode declaringNode4 = unit2.findDeclaringNode(typeBinding.getKey());
+ assertNotNull("No declaring node", declaringNode4); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24268
+ */
+ public void test0415() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0415", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a switch statement", node.getNodeType() == ASTNode.SWITCH_STATEMENT); //$NON-NLS-1$
+ SwitchStatement switchStatement = (SwitchStatement) node;
+ List statements = switchStatement.statements();
+ assertEquals("wrong size", statements.size(), 5); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(3);
+ assertTrue("not a switch case (default)", statement.getNodeType() == ASTNode.SWITCH_CASE); //$NON-NLS-1$
+ SwitchCase defaultCase = (SwitchCase) statement;
+ assertTrue("not a default case", defaultCase.isDefault());
+ checkSourceRange(defaultCase, "default:", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24324
+ */
+ public void test0416() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0416", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 1, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", fragments.size(), 1);
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression init = fragment.getInitializer();
+ assertTrue("not a qualified name", init.getNodeType() == ASTNode.QUALIFIED_NAME); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) init;
+ SimpleName simpleName = qualifiedName.getName();
+ assertEquals("Wrong name", "CONST", simpleName.getIdentifier());
+ IBinding binding = simpleName.resolveBinding();
+ assertEquals("Wrong type", IBinding.VARIABLE, binding.getKind());
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Wrong modifier", variableBinding.getModifiers(), Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL);
+ ASTNode declaringNode = unit.findDeclaringNode(variableBinding);
+ assertNotNull("No declaring node", declaringNode);
+ assertTrue("not a variable declaration fragment", declaringNode.getNodeType() == ASTNode.VARIABLE_DECLARATION_FRAGMENT);
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) declaringNode;
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) variableDeclarationFragment.getParent();
+ assertEquals("Wrong modifier", fieldDeclaration.getModifiers(), Modifier.NONE);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24347
+ */
+ public void test0417() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0417", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ Type type = statement.getType();
+ assertTrue("not a simple type", type.getNodeType() == ASTNode.SIMPLE_TYPE); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type;
+ Name name = simpleType.getName();
+ assertTrue("Not a qualified name", name.isQualifiedName());
+ QualifiedName qualifiedName = (QualifiedName) name;
+ Name qualifier = qualifiedName.getQualifier();
+ assertTrue("Not a simple name", qualifier.isSimpleName());
+ IBinding binding = qualifier.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24406
+ */
+ public void test0418() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0418", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 1, 0);
+ assertNotNull("No node", node);
+ assertTrue("not an expression statement ", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("not an method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Name name = methodInvocation.getName();
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24449
+ */
+ public void test0419() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0419", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 1, 0, 0);
+ assertEquals("Not an expression statement", node.getNodeType(), ASTNode.EXPRESSION_STATEMENT);
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertEquals("Not an assignment", expression.getNodeType(), ASTNode.ASSIGNMENT);
+ Assignment assignment = (Assignment) expression;
+ Expression expression2 = assignment.getLeftHandSide();
+ assertEquals("Not a name", expression2.getNodeType(), ASTNode.SIMPLE_NAME);
+ SimpleName simpleName = (SimpleName) expression2;
+ IBinding binding = simpleName.resolveBinding();
+ assertNull(binding);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24453
+ */
+ public void test0420() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0420", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not an infix expression", expression.getNodeType(), ASTNode.INFIX_EXPRESSION);
+ InfixExpression infixExpression = (InfixExpression) expression;
+ Expression expression2 = infixExpression.getRightOperand();
+ assertEquals("Not a parenthesized expression", expression2.getNodeType(), ASTNode.PARENTHESIZED_EXPRESSION);
+ checkSourceRange(expression2, "(2 + 3)", source);
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression2;
+ Expression expression3 = parenthesizedExpression.getExpression();
+ checkSourceRange(expression3, "2 + 3", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24453
+ */
+ public void test0421() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0421", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not an infix expression", expression.getNodeType(), ASTNode.INFIX_EXPRESSION);
+ InfixExpression infixExpression = (InfixExpression) expression;
+ checkSourceRange(infixExpression, "(1 + 2) + 3", source);
+ Expression expression2 = infixExpression.getLeftOperand();
+ assertEquals("Not a parenthesized expression", expression2.getNodeType(), ASTNode.PARENTHESIZED_EXPRESSION);
+ checkSourceRange(expression2, "(1 + 2)", source);
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression2;
+ Expression expression3 = parenthesizedExpression.getExpression();
+ checkSourceRange(expression3, "1 + 2", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24453
+ */
+ public void test0422() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0422", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not an infix expression", expression.getNodeType(), ASTNode.INFIX_EXPRESSION);
+ InfixExpression infixExpression = (InfixExpression) expression;
+ checkSourceRange(infixExpression, "( 1 + 2 ) + 3", source);
+ Expression expression2 = infixExpression.getLeftOperand();
+ assertEquals("Not a parenthesized expression", expression2.getNodeType(), ASTNode.PARENTHESIZED_EXPRESSION);
+ checkSourceRange(expression2, "( 1 + 2 )", source);
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression2;
+ Expression expression3 = parenthesizedExpression.getExpression();
+ checkSourceRange(expression3, "1 + 2", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24453
+ */
+ public void test0423() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0423", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not an infix expression", expression.getNodeType(), ASTNode.INFIX_EXPRESSION);
+ InfixExpression infixExpression = (InfixExpression) expression;
+ Expression expression2 = infixExpression.getRightOperand();
+ assertEquals("Not a parenthesized expression", expression2.getNodeType(), ASTNode.PARENTHESIZED_EXPRESSION);
+ checkSourceRange(expression2, "( 2 + 3 )", source);
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression2;
+ Expression expression3 = parenthesizedExpression.getExpression();
+ checkSourceRange(expression3, "2 + 3", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24453
+ */
+ public void test0424() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0424", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not an infix expression", expression.getNodeType(), ASTNode.INFIX_EXPRESSION);
+ InfixExpression infixExpression = (InfixExpression) expression;
+ assertEquals("Wrong size", 1, infixExpression.extendedOperands().size());
+ Expression expression2 = (Expression) infixExpression.extendedOperands().get(0);
+ checkSourceRange(expression2, "( 2 + 3 )", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24453
+ */
+ public void test0425() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0425", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not an infix expression", expression.getNodeType(), ASTNode.INFIX_EXPRESSION);
+ InfixExpression infixExpression = (InfixExpression) expression;
+ assertEquals("Wrong size", 0, infixExpression.extendedOperands().size());
+ Expression expression2 = infixExpression.getRightOperand();
+ assertTrue("not an infix expression", expression2.getNodeType() == ASTNode.INFIX_EXPRESSION); //$NON-NLS-1$
+ InfixExpression infixExpression2 = (InfixExpression) expression2;
+ Expression expression3 = infixExpression2.getRightOperand();
+ assertTrue("not a parenthesized expression", expression3.getNodeType() == ASTNode.PARENTHESIZED_EXPRESSION); //$NON-NLS-1$
+ checkSourceRange(expression3, "( 2 + 3 )", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24449
+ */
+ public void test0426() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0426", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 1, 0, 0);
+ assertEquals("Not a variable declaration statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ Type type = statement.getType();
+ assertTrue("not a simple type", type.getNodeType() == ASTNode.SIMPLE_TYPE);
+ SimpleType simpleType = (SimpleType) type;
+ Name name = simpleType.getName();
+ assertNotNull("No name", name);
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24449
+ */
+ public void test0427() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0427", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 1, 0, 0);
+ assertEquals("Not an expression statement", node.getNodeType(), ASTNode.EXPRESSION_STATEMENT);
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertEquals("Not an assignment", expression.getNodeType(), ASTNode.ASSIGNMENT);
+ Assignment assignment = (Assignment) expression;
+ Expression expression2 = assignment.getLeftHandSide();
+ assertEquals("Not a super field access", expression2.getNodeType(), ASTNode.SUPER_FIELD_ACCESS);
+ SuperFieldAccess superFieldAccess = (SuperFieldAccess) expression2;
+ Name name = superFieldAccess.getName();
+ assertNotNull("No name", name);
+ IBinding binding = name.resolveBinding();
+ assertNull("Got a binding", binding);
+ assertNull("Got a binding", superFieldAccess.resolveFieldBinding());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24449
+ */
+ public void test0428() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0428", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 1, 0, 0);
+ assertEquals("Not an expression statement", node.getNodeType(), ASTNode.EXPRESSION_STATEMENT);
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertEquals("Not an assignment", expression.getNodeType(), ASTNode.ASSIGNMENT);
+ Assignment assignment = (Assignment) expression;
+ Expression expression2 = assignment.getLeftHandSide();
+ assertEquals("Not a qualified name", expression2.getNodeType(), ASTNode.QUALIFIED_NAME);
+ QualifiedName name = (QualifiedName) expression2;
+ SimpleName simpleName = name.getName();
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding);
+ IBinding binding2 = name.resolveBinding();
+ assertNotNull("No binding2", binding2);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24449
+ */
+ public void test0429() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0429", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 1, 0, 0);
+ assertEquals("Not an expression statement", node.getNodeType(), ASTNode.EXPRESSION_STATEMENT);
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertEquals("Not an assignment", expression.getNodeType(), ASTNode.ASSIGNMENT);
+ Assignment assignment = (Assignment) expression;
+ Expression expression2 = assignment.getLeftHandSide();
+ assertEquals("Not a qualified name", expression2.getNodeType(), ASTNode.QUALIFIED_NAME);
+ QualifiedName name = (QualifiedName) expression2;
+ SimpleName simpleName = name.getName();
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding);
+ IBinding binding2 = name.resolveBinding();
+ assertNotNull("No binding2", binding2);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24499
+ */
+ public void test0430() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0430", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertTrue("Not a constructor invocation", node.getNodeType() == ASTNode.CONSTRUCTOR_INVOCATION);
+ ConstructorInvocation constructorInvocation = (ConstructorInvocation) node;
+ checkSourceRange(constructorInvocation, "this(coo2());", source);
+ List arguments = constructorInvocation.arguments();
+ assertEquals("Wrong size", 1, arguments.size());
+ Expression expression = (Expression) arguments.get(0);
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION);
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ SimpleName simpleName = methodInvocation.getName();
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24500
+ */
+ public void test0431() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0431", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertTrue("Not a constructor invocation", node.getNodeType() == ASTNode.CONSTRUCTOR_INVOCATION);
+ ConstructorInvocation constructorInvocation = (ConstructorInvocation) node;
+ List arguments = constructorInvocation.arguments();
+ assertEquals("Wrong size", 1, arguments.size());
+ Expression expression = (Expression) arguments.get(0);
+ assertTrue("Not a simple name", expression.getNodeType() == ASTNode.SIMPLE_NAME);
+ SimpleName simpleName = (SimpleName) expression;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24501
+ */
+ public void test0432() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0432", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 1, 0, 0);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertEquals("Not an assignment", ASTNode.ASSIGNMENT, expression.getNodeType());
+ Assignment assignment = (Assignment) expression;
+ Expression expression2 = assignment.getLeftHandSide();
+ assertEquals("Not a simple name", ASTNode.SIMPLE_NAME, expression2.getNodeType());
+ SimpleName simpleName = (SimpleName) expression2;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24501
+ */
+ public void test0433() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0433", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 1, 0, 0);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertEquals("Not an assignment", ASTNode.ASSIGNMENT, expression.getNodeType());
+ Assignment assignment = (Assignment) expression;
+ Expression expression2 = assignment.getLeftHandSide();
+ assertEquals("Not a super field access", ASTNode.SUPER_FIELD_ACCESS, expression2.getNodeType());
+ SuperFieldAccess superFieldAccess = (SuperFieldAccess) expression2;
+ SimpleName simpleName = superFieldAccess.getName();
+ assertEquals("wrong name", "fCoo", simpleName.getIdentifier());
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong binding", IBinding.VARIABLE, binding.getKind());
+ IVariableBinding variableBinding = superFieldAccess.resolveFieldBinding();
+ assertTrue("Different binding", binding == variableBinding);
+ ASTNode astNode = unit.findDeclaringNode(variableBinding);
+ assertTrue("Wrong type", astNode.getNodeType() == ASTNode.SINGLE_VARIABLE_DECLARATION || astNode.getNodeType() == ASTNode.VARIABLE_DECLARATION_FRAGMENT || astNode.getNodeType() == ASTNode.VARIABLE_DECLARATION_EXPRESSION);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24501
+ */
+ public void test0434() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0434", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 1, 0, 0);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertEquals("Not an assignment", ASTNode.ASSIGNMENT, expression.getNodeType());
+ Assignment assignment = (Assignment) expression;
+ Expression expression2 = assignment.getLeftHandSide();
+ assertEquals("Not a qualified name", ASTNode.QUALIFIED_NAME, expression2.getNodeType());
+ QualifiedName qualifiedName = (QualifiedName) expression2;
+ SimpleName simpleName = qualifiedName.getName();
+ assertEquals("wrong name", "fCoo", simpleName.getIdentifier());
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24501
+ */
+ public void test0435() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0435", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 1, 0, 0);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertEquals("Not an assignment", ASTNode.ASSIGNMENT, expression.getNodeType());
+ Assignment assignment = (Assignment) expression;
+ Expression expression2 = assignment.getLeftHandSide();
+ assertEquals("Not a qualified name", ASTNode.QUALIFIED_NAME, expression2.getNodeType());
+ QualifiedName qualifiedName = (QualifiedName) expression2;
+ SimpleName simpleName = qualifiedName.getName();
+ assertEquals("wrong name", "fCoo", simpleName.getIdentifier());
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24502
+ */
+ public void test0436() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0436", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertProblemsSize(unit, 1, "The type A.CInner is not visible"); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 1, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ Type type = statement.getType();
+ assertEquals("Not a simple type", ASTNode.SIMPLE_TYPE, type.getNodeType());
+ SimpleType simpleType = (SimpleType) type;
+ Name name = simpleType.getName();
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Not a qualified name", ASTNode.QUALIFIED_NAME, name.getNodeType());
+ QualifiedName qualifiedName = (QualifiedName) name;
+ SimpleName simpleName = qualifiedName.getName();
+ assertEquals("wrong name", "CInner", simpleName.getIdentifier());
+ IBinding binding2 = simpleName.resolveBinding();
+ assertNotNull("No binding", binding2);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24502
+ */
+ public void test0437() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0437", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertProblemsSize(unit, 1, "The type CInner is not visible"); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 1, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ Type type = statement.getType();
+ assertEquals("Not a simple type", ASTNode.SIMPLE_TYPE, type.getNodeType());
+ SimpleType simpleType = (SimpleType) type;
+ Name name = simpleType.getName();
+ assertEquals("Not a simple name", ASTNode.SIMPLE_NAME, name.getNodeType());
+ SimpleName simpleName = (SimpleName) name;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24511
+ */
+ public void test0438() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0438", "D.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ List imports = unit.imports();
+ assertEquals("Wrong size", 1, imports.size()); //$NON-NLS-1$<
+ ImportDeclaration importDeclaration = (ImportDeclaration) imports.get(0);
+ IBinding binding = importDeclaration.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24502
+ */
+ public void test0439() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0439", "E.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ Type type = statement.getType();
+ assertEquals("Not a simple type", ASTNode.SIMPLE_TYPE, type.getNodeType());
+ SimpleType simpleType = (SimpleType) type;
+ Name name = simpleType.getName();
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24622
+ */
+ public void test0440() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0440", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not an infix expression", ASTNode.INFIX_EXPRESSION, expression.getNodeType());
+ // 2 * 3 + "" + (true)
+ InfixExpression infixExpression = (InfixExpression) expression;
+ checkSourceRange(infixExpression, "2 * 3 + \"\" + (true)", source);
+ Expression leftOperand = infixExpression.getLeftOperand();
+ checkSourceRange(leftOperand, "2 * 3 + \"\"", source);
+ checkSourceRange(infixExpression.getRightOperand(), "(true)", source);
+ assertEquals("wrong operator", infixExpression.getOperator(), InfixExpression.Operator.PLUS);
+ assertEquals("wrong type", ASTNode.INFIX_EXPRESSION, leftOperand.getNodeType());
+ infixExpression = (InfixExpression) leftOperand;
+ checkSourceRange(infixExpression, "2 * 3 + \"\"", source);
+ leftOperand = infixExpression.getLeftOperand();
+ checkSourceRange(leftOperand, "2 * 3", source);
+ checkSourceRange(infixExpression.getRightOperand(), "\"\"", source);
+ assertEquals("wrong operator", infixExpression.getOperator(), InfixExpression.Operator.PLUS);
+ assertEquals("wrong type", ASTNode.INFIX_EXPRESSION, leftOperand.getNodeType());
+ infixExpression = (InfixExpression) leftOperand;
+ checkSourceRange(infixExpression, "2 * 3", source);
+ leftOperand = infixExpression.getLeftOperand();
+ checkSourceRange(leftOperand, "2", source);
+ checkSourceRange(infixExpression.getRightOperand(), "3", source);
+ assertEquals("wrong operator", infixExpression.getOperator(), InfixExpression.Operator.TIMES);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24622
+ */
+ public void test0441() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0441", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not an infix expression", ASTNode.INFIX_EXPRESSION, expression.getNodeType());
+ InfixExpression infixExpression = (InfixExpression) expression;
+ checkSourceRange(infixExpression, "(2 + 2) * 3 * 1", source);
+ Expression leftOperand = infixExpression.getLeftOperand();
+ checkSourceRange(leftOperand, "(2 + 2)", source);
+ checkSourceRange(infixExpression.getRightOperand(), "3", source);
+ List extendedOperands = infixExpression.extendedOperands();
+ assertEquals("wrong size", 1, extendedOperands.size());
+ checkSourceRange((Expression) extendedOperands.get(0), "1", source);
+ assertEquals("wrong operator", InfixExpression.Operator.TIMES, infixExpression.getOperator());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24622
+ */
+ public void test0442() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0442", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not an infix expression", ASTNode.INFIX_EXPRESSION, expression.getNodeType());
+ InfixExpression infixExpression = (InfixExpression) expression;
+ checkSourceRange(infixExpression, "2 + (2 * 3) + 1", source);
+ Expression leftOperand = infixExpression.getLeftOperand();
+ checkSourceRange(leftOperand, "2", source);
+ Expression rightOperand = infixExpression.getRightOperand();
+ checkSourceRange(rightOperand, "(2 * 3)", source);
+ assertEquals("wrong type", ASTNode.PARENTHESIZED_EXPRESSION, rightOperand.getNodeType());
+ List extendedOperands = infixExpression.extendedOperands();
+ assertEquals("wrong size", 1, extendedOperands.size());
+ checkSourceRange((Expression) extendedOperands.get(0), "1", source);
+ assertEquals("wrong operator", InfixExpression.Operator.PLUS, infixExpression.getOperator());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24623
+ */
+ public void test0443() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0443", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 3, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertEquals("Wrong type", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertNotNull("No body", methodDeclaration.getBody());
+ assertNotNull("No binding", methodDeclaration.resolveBinding());
+ assertTrue("Not an abstract method", Modifier.isAbstract(methodDeclaration.getModifiers()));
+ assertTrue("Not malformed", isMalformed(methodDeclaration));
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24623
+ */
+ public void test0444() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0444", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 2, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0);
+ assertEquals("Wrong type", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 2, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration)bodyDeclarations.get(0);
+ assertEquals("Wrong type", ASTNode.METHOD_DECLARATION, bodyDeclaration.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ assertEquals("Wrong name", "foo", methodDeclaration.getName().getIdentifier());
+ bodyDeclaration = (BodyDeclaration)bodyDeclarations.get(1);
+ assertEquals("Wrong type", ASTNode.METHOD_DECLARATION, bodyDeclaration.getNodeType());
+ assertEquals("Wrong name", "foo", ((MethodDeclaration) bodyDeclaration).getName().getIdentifier());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24773
+ */
+ public void test0445() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0445", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=25018
+ */
+ public void test0446() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0446", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 2, unit.getProblems().length); //$NON-NLS-1$<
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=25124
+ */
+ public void test0447() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0447", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 3, unit.getProblems().length); //$NON-NLS-1$<
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=25330
+ * @deprecated using deprecated code
+ */
+ public void test0448() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0448", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", node.getNodeType(), ASTNode.METHOD_DECLARATION);
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Not a constructor", methodDeclaration.isConstructor());
+ ITypeBinding returnTypeBinding = methodDeclaration.getReturnType().resolveBinding();
+ assertNotNull("No return type binding", returnTypeBinding);
+ Block block = methodDeclaration.getBody();
+ assertNotNull("No method body", block);
+ assertEquals("wrong size", 0, block.statements().size());
+ }
+
+ /**
+ * Check that the implicit super constructor call is not there
+ */
+ public void test0449() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0449", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", node.getNodeType(), ASTNode.METHOD_DECLARATION);
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Not a constructor", methodDeclaration.isConstructor());
+ Block block = methodDeclaration.getBody();
+ assertNotNull("No method body", block);
+ assertEquals("wrong size", 1, block.statements().size());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26452
+ */
+ public void test0450() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0450", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0);
+ assertEquals("Not a type declaration", node.getNodeType(), ASTNode.TYPE_DECLARATION);
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No type binding", typeBinding);
+ assertTrue("not a class", typeBinding.isClass());
+ assertTrue("not a toplevel type", typeBinding.isTopLevel());
+ assertTrue("a local type", !typeBinding.isLocal());
+ assertTrue("an anonymous type", !typeBinding.isAnonymous());
+ assertTrue("a member type", !typeBinding.isMember());
+ assertTrue("a nested type", !typeBinding.isNested());
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not an expression statement", node.getNodeType(), ASTNode.EXPRESSION_STATEMENT);
+ Expression expression = ((ExpressionStatement) node).getExpression();
+ assertEquals("Not a class instance creation", expression.getNodeType(), ASTNode.CLASS_INSTANCE_CREATION);
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ typeBinding = anonymousClassDeclaration.resolveBinding();
+ assertNotNull("No type binding", typeBinding);
+ assertTrue("not a class", typeBinding.isClass());
+ assertTrue("a toplevel type", !typeBinding.isTopLevel());
+ assertTrue("not a local type", typeBinding.isLocal());
+ assertTrue("not an anonymous type", typeBinding.isAnonymous());
+ assertTrue("a member type", !typeBinding.isMember());
+ assertTrue("not a nested type", typeBinding.isNested());
+ ASTNode astNode = unit.findDeclaringNode(typeBinding);
+ assertEquals("Wrong type", ASTNode.ANONYMOUS_CLASS_DECLARATION, astNode.getNodeType());
+ assertNotNull("Didn't get a key", typeBinding.getKey());
+ astNode = unit.findDeclaringNode(typeBinding.getKey());
+ assertNotNull("Didn't get a declaring node", astNode);
+
+ ITypeBinding typeBinding3 = classInstanceCreation.resolveTypeBinding();
+ assertEquals("wrong binding", typeBinding, typeBinding3);
+
+ List bodyDeclarations = anonymousClassDeclaration.bodyDeclarations();
+ assertEquals("wrong size", 2, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue("not a type declaration", bodyDeclaration.getNodeType() == ASTNode.TYPE_DECLARATION);
+ typeDeclaration = (TypeDeclaration) bodyDeclaration;
+
+ bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(1);
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ Block block = methodDeclaration.getBody();
+ assertNotNull("No body", block);
+ List statements = block.statements();
+ assertEquals("wrong size", 2, statements.size());
+ Statement statement = (Statement) statements.get(1);
+ assertEquals("Not a variable declaration statement", statement.getNodeType(), ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) statement;
+ Type type = variableDeclarationStatement.getType();
+ assertNotNull("No type", type);
+
+ ITypeBinding typeBinding2 = type.resolveBinding();
+ typeBinding = typeDeclaration.resolveBinding();
+ assertTrue("not equals", typeBinding == typeBinding2);
+ assertNotNull("No type binding", typeBinding);
+ assertTrue("not a class", typeBinding.isClass());
+ assertTrue("a toplevel type", !typeBinding.isTopLevel());
+ assertTrue("an anonymous type", !typeBinding.isAnonymous());
+ assertTrue("not a member type", typeBinding.isMember());
+ assertTrue("not a nested type", typeBinding.isNested());
+ assertTrue("a local type", !typeBinding.isLocal());
+
+ bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("wrong size", 1, bodyDeclarations.size());
+ bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue("not a type declaration", bodyDeclaration.getNodeType() == ASTNode.TYPE_DECLARATION);
+ typeDeclaration = (TypeDeclaration) bodyDeclaration;
+ typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No type binding", typeBinding);
+ assertTrue("not a class", typeBinding.isClass());
+ assertTrue("a toplevel type", !typeBinding.isTopLevel());
+ assertTrue("an anonymous type", !typeBinding.isAnonymous());
+ assertTrue("not a member type", typeBinding.isMember());
+ assertTrue("not a nested type", typeBinding.isNested());
+ assertTrue("a local type", !typeBinding.isLocal());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24916
+ * @deprecated using deprecated code
+ */
+ public void test0451() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0451", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 2, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Type type = methodDeclaration.getReturnType();
+ checkSourceRange(type, "int", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=27204
+ */
+ public void test0452() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "", "NO_WORKING.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, false);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ SimpleName name = methodDeclaration.getName();
+ assertEquals("wrong line number", 3, compilationUnit.getLineNumber(name.getStartPosition()));
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=27173
+ */
+ public void test0453() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0453", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0,0);
+ assertNotNull("No node", node);
+ assertTrue("not a return statement", node.getNodeType() == ASTNode.RETURN_STATEMENT); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertTrue("not a super method invocation", expression.getNodeType() == ASTNode.SUPER_METHOD_INVOCATION); //$NON-NLS-1$
+ SuperMethodInvocation methodInvocation = (SuperMethodInvocation) expression;
+ IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();
+ assertNotNull("No method binding", methodBinding);
+ assertEquals("Wrong binding", "toString", methodBinding.getName());
+ }
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=28296
+ */
+ public void test0454() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0454", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0,1);
+ assertNotNull("No node", node);
+ assertTrue("not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertTrue("not a cast expression", expression.getNodeType() == ASTNode.CAST_EXPRESSION); //$NON-NLS-1$
+ checkSourceRange(expression, "(int) (3.14f * a)", source);
+ CastExpression castExpression = (CastExpression) expression;
+ checkSourceRange(castExpression.getType(), "int", source);
+ Expression expression2 = castExpression.getExpression();
+ checkSourceRange(expression2, "(3.14f * a)", source);
+ assertTrue("not a parenthesized expression", expression2.getNodeType() == ASTNode.PARENTHESIZED_EXPRESSION); //$NON-NLS-1$
+ }
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=28682
+ */
+ public void test0455() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0455", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a for statement", node.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node; // first for loop
+ String expectedSource = "for (int i = 0; i < 10; i++) // for 1\n" +
+ " for (int j = 0; j < 10; j++) // for 2\n" +
+ " if (true) { }";
+ checkSourceRange(forStatement, expectedSource, source);
+ Statement body = forStatement.getBody();
+ expectedSource = "for (int j = 0; j < 10; j++) // for 2\n" +
+ " if (true) { }";
+ checkSourceRange(body, expectedSource, source);
+ assertTrue("not a for statement", body.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement2 = (ForStatement) body;
+ body = forStatement2.getBody();
+ expectedSource = "if (true) { }";
+ checkSourceRange(body, expectedSource, source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=28682
+ */
+ public void test0456() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0456", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a for statement", node.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node; // first for loop
+ String expectedSource = "for (int x= 10; x < 20; x++)\n" +
+ " main();";
+ checkSourceRange(forStatement, expectedSource, source);
+ Statement body = forStatement.getBody();
+ expectedSource = "main();";
+ checkSourceRange(body, expectedSource, source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=28682
+ */
+ public void test0457() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0457", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a for statement", node.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node; // first for loop
+ String expectedSource = "for (int i= 10; i < 10; i++)/*[*/\n"+
+ " for (int z= 10; z < 10; z++)\n" +
+ " foo();";
+ checkSourceRange(forStatement, expectedSource, source);
+ Statement body = forStatement.getBody();
+ expectedSource = "for (int z= 10; z < 10; z++)\n" +
+ " foo();";
+ checkSourceRange(body, expectedSource, source);
+ assertTrue("not a for statement", body.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement2 = (ForStatement) body;
+ body = forStatement2.getBody();
+ expectedSource = "foo();";
+ checkSourceRange(body, expectedSource, source);
+ }
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=28682
+ */
+ public void test0458() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0458", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a for statement", node.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node; // first for loop
+ String expectedSource = "for (int i= 10; i < 10; i++)/*[*/\n"+
+ " for (int z= 10; z < 10; z++)\n" +
+ " ;";
+ checkSourceRange(forStatement, expectedSource, source);
+ Statement body = forStatement.getBody();
+ expectedSource = "for (int z= 10; z < 10; z++)\n" +
+ " ;";
+ checkSourceRange(body, expectedSource, source);
+ assertTrue("not a for statement", body.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement2 = (ForStatement) body;
+ body = forStatement2.getBody();
+ expectedSource = ";";
+ checkSourceRange(body, expectedSource, source);
+ assertTrue("not an empty statement", body.getNodeType() == ASTNode.EMPTY_STATEMENT); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=28682
+ */
+ public void test0459() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0459", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a for statement", node.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node; // first for loop
+ String expectedSource = "for (int i= 10; i < 10; i++)/*[*/\n"+
+ " for (int z= 10; z < 10; z++)\n" +
+ " { }";
+ checkSourceRange(forStatement, expectedSource, source);
+ Statement body = forStatement.getBody();
+ expectedSource = "for (int z= 10; z < 10; z++)\n" +
+ " { }";
+ checkSourceRange(body, expectedSource, source);
+ assertTrue("not a for statement", body.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement2 = (ForStatement) body;
+ body = forStatement2.getBody();
+ expectedSource = "{ }";
+ checkSourceRange(body, expectedSource, source);
+ assertTrue("not a block", body.getNodeType() == ASTNode.BLOCK); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=28869
+ */
+ public void test0460() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0460", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertTrue("Has error", compilationUnit.getProblems().length == 0); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("Malformed", !isMalformed(node));
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=28824
+ */
+ public void test0461() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0461", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, false);
+ char[] source = sourceUnit.getSource().toCharArray();
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertTrue("Has error", compilationUnit.getProblems().length == 0); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("Malformed", !isMalformed(node));
+ assertTrue("not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("not an assignment", expression.getNodeType() == ASTNode.ASSIGNMENT); //$NON-NLS-1$
+ Assignment assignment = (Assignment) expression;
+ checkSourceRange(assignment, "z= foo().y.toList()", source);
+ Expression expression2 = assignment.getRightHandSide();
+ checkSourceRange(expression2, "foo().y.toList()", source);
+ assertTrue("not a method invocation", expression2.getNodeType() == ASTNode.METHOD_INVOCATION);
+ MethodInvocation methodInvocation = (MethodInvocation) expression2;
+ Expression expression3 = methodInvocation.getExpression();
+ checkSourceRange(expression3, "foo().y", source);
+ checkSourceRange(methodInvocation.getName(), "toList", source);
+ assertTrue("not a field access", expression3.getNodeType() == ASTNode.FIELD_ACCESS);
+ FieldAccess fieldAccess = (FieldAccess) expression3;
+ checkSourceRange(fieldAccess.getName(), "y", source);
+ Expression expression4 = fieldAccess.getExpression();
+ checkSourceRange(expression4, "foo()", source);
+ assertTrue("not a method invocation", expression4.getNodeType() == ASTNode.METHOD_INVOCATION);
+ MethodInvocation methodInvocation2 = (MethodInvocation) expression4;
+ checkSourceRange(methodInvocation2.getName(), "foo", source);
+ assertNull("no null", methodInvocation2.getExpression());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=32338
+ */
+ public void test0462() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "", "Test462.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertTrue("Has error", compilationUnit.getProblems().length == 0); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION);
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ assertEquals("Wrong name", "Test462", typeDeclaration.getName().getIdentifier());
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertEquals("Wrong name", "Test462", typeBinding.getQualifiedName());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=33450
+ */
+ public void test0463() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0463", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, false);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a return statement", node.getNodeType() == ASTNode.RETURN_STATEMENT); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertNotNull("No expression", expression);
+ assertTrue("not a string literal", expression.getNodeType() == ASTNode.STRING_LITERAL); //$NON-NLS-1$
+ StringLiteral stringLiteral = (StringLiteral) expression;
+ checkSourceRange(stringLiteral, "\"\\012\\015\\u0061\"", source);
+ assertEquals("wrong value", "\012\015a", stringLiteral.getLiteralValue());
+ assertEquals("wrong value", "\"\\012\\015\\u0061\"", stringLiteral.getEscapedValue());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=33039
+ */
+ public void test0464() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0464", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("No error", 1, compilationUnit.getProblems().length); //$NON-NLS-1$
+ assertNotNull("No node", node);
+ assertTrue("not a return statement", node.getNodeType() == ASTNode.RETURN_STATEMENT); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertNotNull("No expression", expression);
+ assertTrue("not a null literal", expression.getNodeType() == ASTNode.NULL_LITERAL); //$NON-NLS-1$
+ NullLiteral nullLiteral = (NullLiteral) expression;
+ ITypeBinding typeBinding = nullLiteral.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding);
+ assertFalse("A primitive type", typeBinding.isPrimitive());
+ assertTrue("Null type", typeBinding.isNullType());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=33831
+ */
+ public void test0465() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0465", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertEquals("No error", 0, compilationUnit.getProblems().length); //$NON-NLS-1$
+ assertNotNull("No node", node);
+ assertTrue("not a return statement", node.getNodeType() == ASTNode.RETURN_STATEMENT); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertNotNull("No expression", expression);
+ assertTrue("not a field access", expression.getNodeType() == ASTNode.FIELD_ACCESS); //$NON-NLS-1$
+ FieldAccess fieldAccess = (FieldAccess) expression;
+ Name name = fieldAccess.getName();
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong type", IBinding.VARIABLE, binding.getKind());
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Wrong name", "i", variableBinding.getName());
+ assertEquals("Wrong type", "int", variableBinding.getType().getName());
+ IVariableBinding variableBinding2 = fieldAccess.resolveFieldBinding();
+ assertTrue("different binding", variableBinding == variableBinding2);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=33949
+ */
+ public void test0466() throws JavaModelException {
+ Hashtable options = JavaCore.getOptions();
+ Hashtable newOptions = JavaCore.getOptions();
+ try {
+ newOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4);
+ JavaCore.setOptions(newOptions);
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0466", "Assert.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ checkSourceRange(node, "assert ref != null : message;", source);
+ assertTrue("not an assert statement", node.getNodeType() == ASTNode.ASSERT_STATEMENT); //$NON-NLS-1$
+ AssertStatement statement = (AssertStatement) node;
+ checkSourceRange(statement.getExpression(), "ref != null", source);
+ checkSourceRange(statement.getMessage(), "message", source);
+ } finally {
+ JavaCore.setOptions(options);
+ }
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=33949
+ */
+ public void test0467() throws JavaModelException {
+ Hashtable options = JavaCore.getOptions();
+ Hashtable newOptions = JavaCore.getOptions();
+ try {
+ newOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4);
+ JavaCore.setOptions(newOptions);
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0467", "Assert.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ checkSourceRange(node, "assert ref != null : message\\u003B", source);
+ assertTrue("not an assert statement", node.getNodeType() == ASTNode.ASSERT_STATEMENT); //$NON-NLS-1$
+ AssertStatement statement = (AssertStatement) node;
+ checkSourceRange(statement.getExpression(), "ref != null", source);
+ checkSourceRange(statement.getMessage(), "message", source);
+
+ node = getASTNode(compilationUnit, 0, 0, 1);
+ checkSourceRange(node, "assert ref != null\\u003B", source);
+ assertTrue("not an assert statement", node.getNodeType() == ASTNode.ASSERT_STATEMENT); //$NON-NLS-1$
+ statement = (AssertStatement) node;
+ checkSourceRange(statement.getExpression(), "ref != null", source);
+ } finally {
+ JavaCore.setOptions(options);
+ }
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=36772
+ */
+ public void test0468() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0468", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertEquals("No error", 0, compilationUnit.getProblems().length); //$NON-NLS-1$
+ assertNotNull("No node", node);
+ assertTrue("not a return statement", node.getNodeType() == ASTNode.RETURN_STATEMENT); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertNotNull("No expression", expression);
+ assertTrue("not a field access", expression.getNodeType() == ASTNode.FIELD_ACCESS); //$NON-NLS-1$
+ FieldAccess fieldAccess = (FieldAccess) expression;
+ Name name = fieldAccess.getName();
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong type", IBinding.VARIABLE, binding.getKind());
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Wrong name", "i", variableBinding.getName());
+ assertEquals("Wrong type", "int", variableBinding.getType().getName());
+ IVariableBinding variableBinding2 = fieldAccess.resolveFieldBinding();
+ assertTrue("different binding", variableBinding == variableBinding2);
+
+ node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull("No node", node);
+ assertEquals("Wrong type", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+
+ ASTNode foundNode = compilationUnit.findDeclaringNode(variableBinding);
+ assertNotNull("No found node", foundNode);
+ assertEquals("wrong node", fragment, foundNode);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=36895
+ */
+ public void test0469() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "codeManipulation", "bug.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 2, 0);
+ assertEquals("No error", 0, compilationUnit.getProblems().length); //$NON-NLS-1$
+ assertNotNull("No node", node);
+ assertTrue("not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ ASTNode parent = node.getParent();
+ assertNotNull(parent);
+ assertTrue("not a block", parent.getNodeType() == ASTNode.BLOCK); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=37381
+ */
+ public void test0470() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0470", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("No error", 0, compilationUnit.getProblems().length); //$NON-NLS-1$
+ assertNotNull("No node", node);
+ assertTrue("not a for statement", node.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node;
+ List initializers = forStatement.initializers();
+ assertEquals("wrong size", 1, initializers.size());
+ Expression initializer = (Expression) initializers.get(0);
+ assertTrue("not a variable declaration expression", initializer.getNodeType() == ASTNode.VARIABLE_DECLARATION_EXPRESSION); //$NON-NLS-1$
+ VariableDeclarationExpression variableDeclarationExpression = (VariableDeclarationExpression) initializer;
+ List fragments = variableDeclarationExpression.fragments();
+ assertEquals("wrong size", 2, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ checkSourceRange(fragment, "i= 0", source);
+ fragment = (VariableDeclarationFragment) fragments.get(1);
+ checkSourceRange(fragment, "j= goo(3)", source);
+ checkSourceRange(variableDeclarationExpression, "int i= 0, j= goo(3)", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=38447
+ */
+ public void test0471() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0471", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("No error", 1, compilationUnit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Is a constructor", !methodDeclaration.isConstructor());
+ checkSourceRange(methodDeclaration, "private void foo(){", source);
+ node = getASTNode(compilationUnit, 0, 1);
+ assertNotNull("No node", node);
+ assertTrue("not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Is a constructor", !methodDeclaration.isConstructor());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=38447
+ */
+ public void test0472() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "junit.textui", "ResultPrinter.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("No error", 2, compilationUnit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 2);
+ assertNotNull("No node", node);
+ assertTrue("not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Not a constructor", methodDeclaration.isConstructor());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=38732
+ */
+ public void test0473() throws JavaModelException {
+ Hashtable options = JavaCore.getOptions();
+ Hashtable newOptions = JavaCore.getOptions();
+ try {
+ newOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4);
+ newOptions.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR);
+ JavaCore.setOptions(newOptions);
+
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0473", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("No error", 2, compilationUnit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not an assert statement", node.getNodeType() == ASTNode.ASSERT_STATEMENT); //$NON-NLS-1$
+ AssertStatement assertStatement = (AssertStatement) node;
+ checkSourceRange(assertStatement, "assert(true);", source);
+ Expression expression = assertStatement.getExpression();
+ checkSourceRange(expression, "(true)", source);
+ } finally {
+ JavaCore.setOptions(options);
+ }
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=39259
+ */
+ public void test0474() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0474", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("No error", 0, compilationUnit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertNotNull("No node", node);
+ assertEquals("Not a while statement", node.getNodeType(), ASTNode.WHILE_STATEMENT);
+ WhileStatement whileStatement = (WhileStatement) node;
+ Statement statement = whileStatement.getBody();
+ assertEquals("Not a while statement", statement.getNodeType(), ASTNode.WHILE_STATEMENT);
+ WhileStatement whileStatement2 = (WhileStatement) statement;
+ String expectedSource =
+ "while(b())\n" +
+ " foo();";
+ checkSourceRange(whileStatement2, expectedSource, source);
+ Statement statement2 = whileStatement2.getBody();
+ checkSourceRange(statement2, "foo();", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=39259
+ */
+ public void test0475() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0475", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("No error", 0, compilationUnit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertNotNull("No node", node);
+ assertEquals("Not an if statement", node.getNodeType(), ASTNode.IF_STATEMENT);
+ IfStatement statement = (IfStatement) node;
+ Statement statement2 = statement.getThenStatement();
+ assertEquals("Not an if statement", statement2.getNodeType(), ASTNode.IF_STATEMENT);
+ IfStatement statement3 = (IfStatement) statement2;
+ String expectedSource =
+ "if(b())\n" +
+ " foo();";
+ checkSourceRange(statement3, expectedSource, source);
+ Statement statement4 = statement3.getThenStatement();
+ checkSourceRange(statement4, "foo();", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=39259
+ */
+ public void test0476() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0476", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("No error", 0, compilationUnit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertNotNull("No node", node);
+ assertEquals("Not a for statement", node.getNodeType(), ASTNode.FOR_STATEMENT);
+ ForStatement statement = (ForStatement) node;
+ Statement statement2 = statement.getBody();
+ assertEquals("Not a for statement", statement2.getNodeType(), ASTNode.FOR_STATEMENT);
+ ForStatement statement3 = (ForStatement) statement2;
+ String expectedSource =
+ "for(;b();)\n" +
+ " foo();";
+ checkSourceRange(statement3, expectedSource, source);
+ Statement statement4 = statement3.getBody();
+ checkSourceRange(statement4, "foo();", source);
+ }
+
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=39327
+ */
+ public void test0477() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0477", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("No error", 1, compilationUnit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertNotNull("No node", node);
+
+ checkSourceRange(node, "this(undef());", source);
+ assertEquals("Not a constructor invocation", node.getNodeType(), ASTNode.CONSTRUCTOR_INVOCATION);
+ ConstructorInvocation constructorInvocation = (ConstructorInvocation) node;
+ List arguments = constructorInvocation.arguments();
+ assertEquals("Wrong size", 1, arguments.size());
+ IMethodBinding binding = constructorInvocation.resolveConstructorBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=40474
+ */
+ public void test0478() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0478", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType[] types = sourceUnit.getTypes();
+ assertNotNull(types);
+ assertEquals("wrong size", 2, types.length);
+ IType type = types[1];
+ IMethod[] methods = type.getMethods();
+ assertNotNull(methods);
+ assertEquals("wrong size", 1, methods.length);
+ IMethod method = methods[0];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(sourceUnit, sourceRange.getOffset() + sourceRange.getLength() / 2, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 1, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("wrong name", "test", methodDeclaration.getName().getIdentifier());
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ assertNotNull(methodBinding);
+ List statements = ((MethodDeclaration) node).getBody().statements();
+ assertEquals("wrong size", 2, statements.size());
+ ASTNode node2 = (ASTNode) statements.get(1);
+ assertNotNull(node2);
+ assertTrue("Not an expression statement", node2.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node2;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ assertTrue("Not a simple name", expression2.getNodeType() == ASTNode.SIMPLE_NAME); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) expression2;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("wrong type", binding.getKind() == IBinding.VARIABLE); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Wrong name", "a", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ SimpleName simpleName2 = methodInvocation.getName();
+ assertEquals("Wrong name", "clone", simpleName2.getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding2 = simpleName2.resolveBinding();
+ assertNotNull("no binding2", binding2); //$NON-NLS-1$
+ assertTrue("Wrong type", binding2.getKind() == IBinding.METHOD); //$NON-NLS-1$
+ IMethodBinding methodBinding2 = (IMethodBinding) binding2;
+ assertEquals("Wrong name", "clone", methodBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=40474
+ */
+ public void test0479() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0479", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType[] types = sourceUnit.getTypes();
+ assertNotNull(types);
+ assertEquals("wrong size", 2, types.length);
+ IType type = types[1];
+ IMethod[] methods = type.getMethods();
+ assertNotNull(methods);
+ assertEquals("wrong size", 1, methods.length);
+ IMethod method = methods[0];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(sourceUnit, sourceRange.getOffset() + sourceRange.getLength() / 2, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 1, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("wrong name", "test", methodDeclaration.getName().getIdentifier());
+ List statements = ((MethodDeclaration) node).getBody().statements();
+ assertEquals("wrong size", 2, statements.size());
+ ASTNode node2 = (ASTNode) statements.get(1);
+ assertNotNull(node2);
+ assertTrue("Not an expression statement", node2.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node2;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ assertTrue("Not a simple name", expression2.getNodeType() == ASTNode.SIMPLE_NAME); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) expression2;
+ IBinding binding = simpleName.resolveBinding();
+ assertNull("No binding", binding); //$NON-NLS-1$
+ SimpleName simpleName2 = methodInvocation.getName();
+ assertEquals("Wrong name", "clone", simpleName2.getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=40474
+ */
+ public void test0480() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0480", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType[] types = sourceUnit.getTypes();
+ assertNotNull(types);
+ assertEquals("wrong size", 1, types.length);
+ IType type = types[0];
+ IMethod[] methods = type.getMethods();
+ assertNotNull(methods);
+ assertEquals("wrong size", 1, methods.length);
+ IMethod method = methods[0];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(sourceUnit, sourceRange.getOffset() + sourceRange.getLength() / 2, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("wrong name", "test", methodDeclaration.getName().getIdentifier());
+ List statements = ((MethodDeclaration) node).getBody().statements();
+ assertEquals("wrong size", 1, statements.size());
+ ASTNode node2 = (ASTNode) statements.get(0);
+ assertNotNull(node2);
+ assertTrue("Not an variable declaration statement", node2.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=40474
+ */
+ public void test0481() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0481", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType[] types = sourceUnit.getTypes();
+ assertNotNull(types);
+ assertEquals("wrong size", 1, types.length);
+ IType type = types[0];
+ IMethod[] methods = type.getMethods();
+ assertNotNull(methods);
+ assertEquals("wrong size", 1, methods.length);
+ IMethod method = methods[0];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(sourceUnit, sourceRange.getOffset() + sourceRange.getLength() / 2, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("wrong name", "test", methodDeclaration.getName().getIdentifier());
+ List statements = ((MethodDeclaration) node).getBody().statements();
+ assertEquals("wrong size", 1, statements.size());
+ ASTNode node2 = (ASTNode) statements.get(0);
+ assertNotNull(node2);
+ assertTrue("Not an variable declaration statement", node2.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node2;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertTrue("Not a class instance creation", expression.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ ITypeBinding typeBinding = classInstanceCreation.resolveTypeBinding();
+ assertNotNull(typeBinding);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=40474
+ */
+ public void test0482() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0482", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType[] types = sourceUnit.getTypes();
+ assertNotNull(types);
+ assertEquals("wrong size", 1, types.length);
+ IType type = types[0];
+ IType[] memberTypes = type.getTypes();
+ assertNotNull(memberTypes);
+ assertEquals("wrong size", 1, memberTypes.length);
+ IType memberType = memberTypes[0];
+ IMethod[] methods = memberType.getMethods();
+ assertEquals("wrong size", 1, methods.length);
+ IMethod method = methods[0];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(sourceUnit, sourceRange.getOffset() + sourceRange.getLength() / 2, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("wrong name", "test", methodDeclaration.getName().getIdentifier());
+ List statements = ((MethodDeclaration) node).getBody().statements();
+ assertEquals("wrong size", 1, statements.size());
+ ASTNode node2 = (ASTNode) statements.get(0);
+ assertNotNull(node2);
+ assertTrue("Not an variable declaration statement", node2.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node2;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertTrue("Not a class instance creation", expression.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ ITypeBinding typeBinding = classInstanceCreation.resolveTypeBinding();
+ assertNotNull(typeBinding);
+ assertTrue(typeBinding.isAnonymous());
+ assertEquals("Wrong name", "", typeBinding.getName());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=40474
+ */
+ public void test0483() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0483", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType[] types = sourceUnit.getTypes();
+ assertNotNull(types);
+ assertEquals("wrong size", 1, types.length);
+ IType type = types[0];
+ IMethod[] methods = type.getMethods();
+ assertEquals("wrong size", 1, methods.length);
+ IMethod method = methods[0];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(sourceUnit, sourceRange.getOffset() + sourceRange.getLength() / 2, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("wrong name", "A", methodDeclaration.getName().getIdentifier());
+ assertTrue("Not a constructor", methodDeclaration.isConstructor());
+ IBinding binding = methodDeclaration.getName().resolveBinding();
+ assertNotNull(binding);
+ assertEquals("Wrong type", IBinding.METHOD, binding.getKind());
+ List statements = ((MethodDeclaration) node).getBody().statements();
+ assertEquals("wrong size", 1, statements.size());
+ ASTNode node2 = (ASTNode) statements.get(0);
+ assertNotNull(node2);
+ assertTrue("Not an variable declaration statement", node2.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node2;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertTrue("Not a class instance creation", expression.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ ITypeBinding typeBinding = classInstanceCreation.resolveTypeBinding();
+ assertNotNull(typeBinding);
+ assertTrue(typeBinding.isAnonymous());
+ assertEquals("Wrong name", "", typeBinding.getName());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=40474
+ */
+ public void test0484() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0482", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType[] types = sourceUnit.getTypes();
+ assertNotNull(types);
+ assertEquals("wrong size", 1, types.length);
+ IType type = types[0];
+ IType[] memberTypes = type.getTypes();
+ assertNotNull(memberTypes);
+ assertEquals("wrong size", 1, memberTypes.length);
+ IType memberType = memberTypes[0];
+ ISourceRange sourceRange = memberType.getSourceRange();
+ ASTNode result = runConversion(sourceUnit, sourceRange.getOffset() + sourceRange.getLength() / 2, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ assertEquals("wrong name", "B", typeDeclaration.getName().getIdentifier());
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue("Not a method declaration", bodyDeclaration.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=40474
+ */
+ public void test0485() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0482", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType[] types = sourceUnit.getTypes();
+ assertNotNull(types);
+ assertEquals("wrong size", 1, types.length);
+ IType type = types[0];
+ IType[] memberTypes = type.getTypes();
+ assertNotNull(memberTypes);
+ assertEquals("wrong size", 1, memberTypes.length);
+ IType memberType = memberTypes[0];
+ ISourceRange sourceRange = memberType.getSourceRange();
+ ASTNode result = runConversion(sourceUnit, sourceRange.getOffset() + sourceRange.getLength() / 2, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ assertEquals("wrong name", "B", typeDeclaration.getName().getIdentifier());
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue("Not a method declaration", bodyDeclaration.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=40474
+ */
+ public void test0486() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0486", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType[] types = sourceUnit.getTypes();
+ assertNotNull(types);
+ assertEquals("wrong size", 1, types.length);
+ IType type = types[0];
+ IMethod[] methods = type.getMethods();
+ assertEquals("wrong size", 2, methods.length);
+ IMethod method = methods[1];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(sourceUnit, sourceRange.getOffset() + sourceRange.getLength() / 2, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 2);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("Wrong size", 2, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 1);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ block = methodDeclaration.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=40474
+ */
+ public void test0487() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0487", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType[] types = sourceUnit.getTypes();
+ assertNotNull(types);
+ assertEquals("wrong size", 1, types.length);
+ IType type = types[0];
+ IMethod[] methods = type.getMethods();
+ assertEquals("wrong size", 3, methods.length);
+ IMethod method = methods[1];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(sourceUnit, sourceRange.getOffset() + sourceRange.getLength() / 2, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 5);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("Wrong size", 2, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 4);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ block = methodDeclaration.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Wrong name", "field", fragment.getName().getIdentifier());
+ assertNotNull("No initializer", expression);
+
+ node = getASTNode((CompilationUnit) result, 0, 1);
+ assertTrue("Not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ expression = fragment.getInitializer();
+ assertEquals("Wrong name", "i", fragment.getName().getIdentifier());
+ assertNotNull("No initializer", expression);
+
+ node = getASTNode((CompilationUnit) result, 0, 2);
+ assertTrue("Not an initializer", node.getNodeType() == ASTNode.INITIALIZER); //$NON-NLS-1$
+ Initializer initializer = (Initializer) node;
+ assertEquals("Not static", Modifier.NONE, initializer.getModifiers());
+ block = initializer.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 3);
+ assertTrue("Not an initializer", node.getNodeType() == ASTNode.INITIALIZER); //$NON-NLS-1$
+ initializer = (Initializer) node;
+ assertEquals("Not static", Modifier.STATIC, initializer.getModifiers());
+ block = initializer.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 6);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ block = methodDeclaration.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=40474
+ */
+ public void test0488() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0488", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType[] types = sourceUnit.getTypes();
+ assertNotNull(types);
+ assertEquals("wrong size", 1, types.length);
+ IType type = types[0];
+ IInitializer[] initializers = type.getInitializers();
+ assertEquals("wrong size", 2, initializers.length);
+ IInitializer init = initializers[1];
+ ISourceRange sourceRange = init.getSourceRange();
+ ASTNode result = runConversion(sourceUnit, sourceRange.getOffset() + sourceRange.getLength() / 2, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 5);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 4);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ block = methodDeclaration.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Wrong name", "field", fragment.getName().getIdentifier());
+ assertNotNull("No initializer", expression);
+
+ node = getASTNode((CompilationUnit) result, 0, 1);
+ assertTrue("Not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ expression = fragment.getInitializer();
+ assertEquals("Wrong name", "i", fragment.getName().getIdentifier());
+ assertNotNull("No initializer", expression);
+
+ node = getASTNode((CompilationUnit) result, 0, 2);
+ assertTrue("Not an initializer", node.getNodeType() == ASTNode.INITIALIZER); //$NON-NLS-1$
+ Initializer initializer = (Initializer) node;
+ assertEquals("Not static", Modifier.NONE, initializer.getModifiers());
+ block = initializer.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 3);
+ assertTrue("Not an initializer", node.getNodeType() == ASTNode.INITIALIZER); //$NON-NLS-1$
+ initializer = (Initializer) node;
+ assertEquals("Not static", Modifier.STATIC, initializer.getModifiers());
+ block = initializer.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 6);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ block = methodDeclaration.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+ }
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=40804
+ */
+ public void test0489() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0489", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ assertNull("Got a type binding", typeDeclaration.resolveBinding());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=40804
+ */
+ public void test0490() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0490", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=42647
+ */
+ public void test0491() throws JavaModelException {
+ Hashtable options = JavaCore.getOptions();
+ Hashtable newOptions = JavaCore.getOptions();
+ try {
+ newOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4);
+ JavaCore.setOptions(newOptions);
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0491", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertTrue("not an assert statement", node.getNodeType() == ASTNode.ASSERT_STATEMENT); //$NON-NLS-1$
+ AssertStatement assertStatement = (AssertStatement) node;
+ Expression expression = assertStatement.getExpression();
+ assertTrue("not a parenthesized expression", expression.getNodeType() == ASTNode.PARENTHESIZED_EXPRESSION); //$NON-NLS-1$
+ checkSourceRange(expression, "(loginName != null)", source);
+ } finally {
+ JavaCore.setOptions(options);
+ }
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=42647
+ */
+ public void test0492() throws JavaModelException {
+ Hashtable options = JavaCore.getOptions();
+ Hashtable newOptions = JavaCore.getOptions();
+ try {
+ newOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4);
+ JavaCore.setOptions(newOptions);
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0492", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertTrue("not an assert statement", node.getNodeType() == ASTNode.ASSERT_STATEMENT); //$NON-NLS-1$
+ AssertStatement assertStatement = (AssertStatement) node;
+ Expression expression = assertStatement.getExpression();
+ checkSourceRange(expression, "loginName != null", source);
+ } finally {
+ JavaCore.setOptions(options);
+ }
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=42839
+ */
+ public void test0493() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0493", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertTrue("not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ Type type = fieldDeclaration.getType();
+ checkSourceRange(type, "Class[][]", source);
+ assertTrue("not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ Type componentType = arrayType.getComponentType();
+ assertTrue("not an array type", componentType.isArrayType()); //$NON-NLS-1$
+ checkSourceRange(componentType, "Class[]", source);
+ arrayType = (ArrayType) componentType;
+ componentType = arrayType.getComponentType();
+ assertTrue("is an array type", !componentType.isArrayType()); //$NON-NLS-1$
+ checkSourceRange(componentType, "Class", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=42839
+ */
+ public void test0494() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0494", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertTrue("not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ Type type = fieldDeclaration.getType();
+ checkSourceRange(type, "Class[][][]", source);
+ assertTrue("not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ Type componentType = arrayType.getComponentType();
+ assertTrue("not an array type", componentType.isArrayType()); //$NON-NLS-1$
+ checkSourceRange(componentType, "Class[][]", source);
+ arrayType = (ArrayType) componentType;
+ componentType = arrayType.getComponentType();
+ assertTrue("not an array type", componentType.isArrayType()); //$NON-NLS-1$
+ checkSourceRange(componentType, "Class[]", source);
+ arrayType = (ArrayType) componentType;
+ componentType = arrayType.getComponentType();
+ assertTrue("is an array type", !componentType.isArrayType()); //$NON-NLS-1$
+ checkSourceRange(componentType, "Class", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=42839
+ */
+ public void test0495() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0495", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertTrue("not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ Type type = fieldDeclaration.getType();
+ checkSourceRange(type, "Class[][]", source);
+ assertTrue("not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ Type componentType = arrayType.getComponentType();
+ assertTrue("not an array type", componentType.isArrayType()); //$NON-NLS-1$
+ checkSourceRange(componentType, "Class[]", source);
+ arrayType = (ArrayType) componentType;
+ componentType = arrayType.getComponentType();
+ assertTrue("is an array type", !componentType.isArrayType()); //$NON-NLS-1$
+ checkSourceRange(componentType, "Class", source);
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ assertEquals("wrong extra dimension", 1, fragment.getExtraDimensions());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=42839
+ */
+ public void test0496() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0496", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertTrue("not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ Type type = fieldDeclaration.getType();
+ checkSourceRange(type, "Class[][][][]", source);
+ assertTrue("not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ Type componentType = arrayType.getComponentType();
+ assertTrue("not an array type", componentType.isArrayType()); //$NON-NLS-1$
+ checkSourceRange(componentType, "Class[][][]", source);
+ arrayType = (ArrayType) componentType;
+ componentType = arrayType.getComponentType();
+ assertTrue("not an array type", componentType.isArrayType()); //$NON-NLS-1$
+ checkSourceRange(componentType, "Class[][]", source);
+ arrayType = (ArrayType) componentType;
+ componentType = arrayType.getComponentType();
+ assertTrue("not an array type", componentType.isArrayType()); //$NON-NLS-1$
+ checkSourceRange(componentType, "Class[]", source);
+ arrayType = (ArrayType) componentType;
+ componentType = arrayType.getComponentType();
+ assertTrue("is an array type", !componentType.isArrayType()); //$NON-NLS-1$
+ checkSourceRange(componentType, "Class", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=42839
+ */
+ public void test0497() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0497", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertTrue("not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ Type type = fieldDeclaration.getType();
+ checkSourceRange(type, "Class[]", source);
+ assertTrue("not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ Type componentType = arrayType.getComponentType();
+ assertTrue("is an array type", !componentType.isArrayType()); //$NON-NLS-1$
+ checkSourceRange(componentType, "Class", source);
+ }
+
+ /**
+ */
+ public void test0498() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0498", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=45199
+ */
+ public void test0499() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0499", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0, 1);
+ assertNotNull(node);
+ assertTrue("Not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ Expression expression = ((ExpressionStatement) node).getExpression();
+ assertTrue("Not an assignment", expression.getNodeType() == ASTNode.ASSIGNMENT); //$NON-NLS-1$
+ Assignment assignment = (Assignment) expression;
+ Expression expression2 = assignment.getRightHandSide();
+ assertTrue("Not an infix expression", expression2.getNodeType() == ASTNode.INFIX_EXPRESSION); //$NON-NLS-1$
+ InfixExpression infixExpression = (InfixExpression) expression2;
+ Expression expression3 = infixExpression.getLeftOperand();
+ assertTrue("Not a simple name", expression3.getNodeType() == ASTNode.SIMPLE_NAME); //$NON-NLS-1$
+ ITypeBinding binding = expression3.resolveTypeBinding();
+ assertNotNull("No binding", binding);
+ Expression expression4 = assignment.getLeftHandSide();
+ assertTrue("Not a simple name", expression4.getNodeType() == ASTNode.SIMPLE_NAME); //$NON-NLS-1$
+ ITypeBinding binding2 = expression4.resolveTypeBinding();
+ assertNotNull("No binding", binding2);
+ assertTrue("Should be the same", binding == binding2);
+ }
+
+ /**
+ * Test for bug 45436 fix.
+ * When this bug happened, the first assertion was false (2 problems found).
+ * @see <a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=45436">bug 45436</a>
+ * @throws JavaModelException
+ */
+ public void test0500() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0500", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IJavaProject project = sourceUnit.getJavaProject();
+ Map originalOptions = project.getOptions(false);
+ try {
+ project.setOption(JavaCore.COMPILER_PB_INVALID_JAVADOC, JavaCore.ERROR);
+ project.setOption(JavaCore.COMPILER_PB_MISSING_JAVADOC_TAGS, JavaCore.ERROR);
+ project.setOption(JavaCore.COMPILER_PB_MISSING_JAVADOC_COMMENTS, JavaCore.ERROR);
+ CompilationUnit result = (CompilationUnit)runConversion(sourceUnit, true);
+ IProblem[] problems= result.getProblems();
+ assertTrue(problems.length == 1);
+ assertEquals("Invalid warning", "Javadoc: Missing tag for parameter a", problems[0].getMessage());
+ } finally {
+ project.setOptions(originalOptions);
+ }
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46012
+ */
+ public void test0501() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0501", "JavaEditor.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, false);
+ assertNotNull(result);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46013
+ */
+ public void test0502a() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0502", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(sourceUnit, true);
+
+ // 'i' in initializer
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement)getASTNode(unit, 0, 0, 0);
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) variableDeclarationStatement.fragments().get(0);
+ IVariableBinding localBinding = fragment.resolveBinding();
+ assertEquals("Unexpected key", "Ltest0502/A;#0#i", localBinding.getKey()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46013
+ */
+ public void test0502b() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0502", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(sourceUnit, true);
+
+ // 'j' in 'then' block in initializer
+ IfStatement ifStatement = (IfStatement) getASTNode(unit, 0, 0, 1);
+ Block block = (Block)ifStatement.getThenStatement();
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) block.statements().get(0);
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) variableDeclarationStatement.fragments().get(0);
+ IVariableBinding localBinding = fragment.resolveBinding();
+ assertEquals("Unexpected key", "Ltest0502/A;#0#0#j", localBinding.getKey()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46013
+ */
+ public void test0502c() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0502", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(sourceUnit, true);
+
+ // 'i' in 'foo()'
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement)getASTNode(unit, 0, 1, 0);
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) variableDeclarationStatement.fragments().get(0);
+ IVariableBinding localBinding = fragment.resolveBinding();
+ assertEquals("Unexpected key", "Ltest0502/A;.foo()V#i", localBinding.getKey()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46013
+ */
+ public void test0502d() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0502", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(sourceUnit, true);
+
+ // 'j' in 'then' block in 'foo()'
+ IfStatement ifStatement = (IfStatement) getASTNode(unit, 0, 1, 1);
+ Block block = (Block)ifStatement.getThenStatement();
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) block.statements().get(0);
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) variableDeclarationStatement.fragments().get(0);
+ IVariableBinding localBinding = fragment.resolveBinding();
+ assertEquals("Unexpected key", "Ltest0502/A;.foo()V#0#j", localBinding.getKey()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46013
+ */
+ public void test0502e() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0502", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(sourceUnit, true);
+
+ // 'j' in 'else' block in 'foo()'
+ IfStatement ifStatement = (IfStatement) getASTNode(unit, 0, 1, 1);
+ Block block = (Block)ifStatement.getElseStatement();
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) block.statements().get(0);
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) variableDeclarationStatement.fragments().get(0);
+ IVariableBinding localBinding = fragment.resolveBinding();
+ assertEquals("Unexpected key", "Ltest0502/A;.foo()V#1#j", localBinding.getKey()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46013
+ */
+ public void test0502f() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0502", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(sourceUnit, true);
+
+ // first 'new Object(){...}' in 'foo()'
+ ExpressionStatement expressionStatement = (ExpressionStatement) getASTNode(unit, 0, 1, 2);
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expressionStatement.getExpression();
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ ITypeBinding typeBinding = anonymousClassDeclaration.resolveBinding();
+ assertEquals("Unexpected key", "Ltest0502/A$182;", typeBinding.getKey()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46013
+ * @deprecated using deprecated code
+ */
+ public void test0502g() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0502", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(sourceUnit, true);
+
+ // 'B' in 'foo()'
+ TypeDeclarationStatement typeDeclarationStatement = (TypeDeclarationStatement) getASTNode(unit, 0, 1, 3);
+ TypeDeclaration typeDeclaration = typeDeclarationStatement.getTypeDeclaration();
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertEquals("Unexpected key", "Ltest0502/A$206$B;", typeBinding.getKey()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46013
+ */
+ public void test0502h() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0502", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(sourceUnit, true);
+
+ // second 'new Object(){...}' in 'foo()'
+ ExpressionStatement expressionStatement = (ExpressionStatement) getASTNode(unit, 0, 1, 4);
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expressionStatement.getExpression();
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ ITypeBinding typeBinding = anonymousClassDeclaration.resolveBinding();
+ assertEquals("Unexpected key", "Ltest0502/A$255;", typeBinding.getKey()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46013
+ * @deprecated using deprecated code
+ */
+ public void test0502i() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0502", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(sourceUnit, true);
+
+ // 'field' in 'B' in 'foo()'
+ TypeDeclarationStatement typeDeclarationStatement = (TypeDeclarationStatement) getASTNode(unit, 0, 1, 3);
+ TypeDeclaration typeDeclaration = typeDeclarationStatement.getTypeDeclaration();
+ FieldDeclaration fieldDeclaration = typeDeclaration.getFields()[0];
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fieldDeclaration.fragments().get(0);
+ IVariableBinding fieldBinding = fragment.resolveBinding();
+ assertEquals("Unexpected key", "Ltest0502/A$206$B;.field)I", fieldBinding.getKey()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46013
+ * @deprecated using deprecated code
+ */
+ public void test0502j() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0502", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(sourceUnit, true);
+
+ // 'bar()' in 'B' in 'foo()'
+ TypeDeclarationStatement typeDeclarationStatement = (TypeDeclarationStatement) getASTNode(unit, 0, 1, 3);
+ TypeDeclaration typeDeclaration = typeDeclarationStatement.getTypeDeclaration();
+ MethodDeclaration methodDeclaration = typeDeclaration.getMethods()[0];
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ assertEquals("Unexpected key", "Ltest0502/A$206$B;.bar()V", methodBinding.getKey()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46057
+ */
+ public void test0503a() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0503", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(sourceUnit, true);
+
+ // top level type A
+ TypeDeclaration type = (TypeDeclaration)getASTNode(unit, 0);
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertEquals("Unexpected binary name", "test0503.A", typeBinding.getBinaryName()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46057
+ */
+ public void test0503b() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0503", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(sourceUnit, true);
+
+ // member type B in A
+ TypeDeclaration type = (TypeDeclaration)getASTNode(unit, 0, 0);
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertEquals("Unexpected binary name", "test0503.A$B", typeBinding.getBinaryName()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46057
+ * @deprecated using deprecated code
+ */
+ public void test0503c() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0503", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(sourceUnit, true);
+
+ // local type E in foo() in A
+ TypeDeclarationStatement typeDeclarationStatement = (TypeDeclarationStatement) getASTNode(unit, 0, 1, 0);
+ TypeDeclaration typeDeclaration = typeDeclarationStatement.getTypeDeclaration();
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertEquals("Unexpected binary name", "test0503.A$1$E", typeBinding.getBinaryName()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46057
+ */
+ public void test0503d() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0503", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(sourceUnit, true);
+
+ // anonymous type new Object() {...} in foo() in A
+ ExpressionStatement expressionStatement = (ExpressionStatement) getASTNode(unit, 0, 1, 1);
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expressionStatement.getExpression();
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ ITypeBinding typeBinding = anonymousClassDeclaration.resolveBinding();
+ assertEquals("Unexpected binary name", "test0503.A$2", typeBinding.getBinaryName()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46057
+ */
+ public void test0503e() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0503", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(sourceUnit, true);
+
+ // type F in anonymous type new Object() {...} in foo() in A
+ ExpressionStatement expressionStatement = (ExpressionStatement) getASTNode(unit, 0, 1, 1);
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expressionStatement.getExpression();
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ TypeDeclaration type = (TypeDeclaration) anonymousClassDeclaration.bodyDeclarations().get(0);
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertEquals("Unexpected binary name", "test0503.A$2$F", typeBinding.getBinaryName()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46057
+ * @deprecated using deprecated code
+ */
+ public void test0503f() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0503", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(sourceUnit, true);
+
+ // local type C in bar() in B in A
+ MethodDeclaration method = (MethodDeclaration) getASTNode(unit, 0, 0, 0);
+ TypeDeclarationStatement typeDeclarationStatement = (TypeDeclarationStatement) method.getBody().statements().get(0);
+ TypeDeclaration typeDeclaration = typeDeclarationStatement.getTypeDeclaration();
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertEquals("Unexpected binary name", "test0503.A$1$C", typeBinding.getBinaryName()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46057
+ */
+ public void test0503g() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0503", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(sourceUnit, true);
+
+ // anonymous type new Object() {...} in bar() in B in A
+ MethodDeclaration method = (MethodDeclaration) getASTNode(unit, 0, 0, 0);
+ ExpressionStatement expressionStatement = (ExpressionStatement) method.getBody().statements().get(1);
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expressionStatement.getExpression();
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ ITypeBinding typeBinding = anonymousClassDeclaration.resolveBinding();
+ assertEquals("Unexpected binary name", "test0503.A$1", typeBinding.getBinaryName()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46057
+ */
+ public void test0503h() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0503", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(sourceUnit, true);
+
+ // type D in anonymous type new Object() {...} in bar() in B in A
+ MethodDeclaration method = (MethodDeclaration) getASTNode(unit, 0, 0, 0);
+ ExpressionStatement expressionStatement = (ExpressionStatement) method.getBody().statements().get(1);
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expressionStatement.getExpression();
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ TypeDeclaration type = (TypeDeclaration) anonymousClassDeclaration.bodyDeclarations().get(0);
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertEquals("Unexpected binary name", "test0503.A$1$D", typeBinding.getBinaryName()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46057
+ * @deprecated using deprecated code
+ */
+ public void test0503i() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0503", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(sourceUnit, true);
+
+ // unreachable type G in foo() in A
+ IfStatement ifStatement = (IfStatement) getASTNode(unit, 0, 1, 2);
+ Block block = (Block)ifStatement.getThenStatement();
+ TypeDeclarationStatement typeDeclarationStatement = (TypeDeclarationStatement) block.statements().get(0);
+ TypeDeclaration typeDeclaration = typeDeclarationStatement.getTypeDeclaration();
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertEquals("Unexpected binary name", null, typeBinding.getBinaryName()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=47396
+ */
+ public void test0504() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0504", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 1, 0);
+ assertNotNull(node);
+ assertTrue("Not a constructor declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration declaration = (MethodDeclaration) node;
+ assertTrue("A constructor", !declaration.isConstructor());
+ checkSourceRange(declaration, "public method(final int parameter);", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=47396
+ */
+ public void test0505() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0505", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 1, 0);
+ assertNotNull(node);
+ assertTrue("Not a constructor declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration declaration = (MethodDeclaration) node;
+ assertTrue("A constructor", !declaration.isConstructor());
+ checkSourceRange(declaration, "public method(final int parameter) { }", source);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=46699
+ */
+ public void test0506() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0506", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Wrong number of problems", 0, (unit).getProblems().length); //$NON-NLS-1$
+ assertNotNull(node);
+ assertTrue("Not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ assertTrue("Not a class instance creation", expressionStatement.getExpression().getNodeType() == ASTNode.CLASS_INSTANCE_CREATION); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expressionStatement.getExpression();
+ IMethodBinding binding = classInstanceCreation.resolveConstructorBinding();
+ assertFalse("is synthetic", binding.isSynthetic());
+ assertTrue("is default constructor", binding.isDefaultConstructor());
+ assertNull("Has a declaring node", unit.findDeclaringNode(binding));
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=46699
+ */
+ public void test0507() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0507", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Wrong number of problems", 0, (unit).getProblems().length); //$NON-NLS-1$
+ assertNotNull(node);
+ assertTrue("Not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ assertTrue("Not a class instance creation", expressionStatement.getExpression().getNodeType() == ASTNode.CLASS_INSTANCE_CREATION); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expressionStatement.getExpression();
+ IMethodBinding binding = classInstanceCreation.resolveConstructorBinding();
+ assertFalse("is synthetic", binding.isSynthetic());
+ assertTrue("is default constructor", binding.isDefaultConstructor());
+ assertNull("Has a declaring node", unit.findDeclaringNode(binding));
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=46699
+ */
+ public void test0508() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0508", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ ASTNode node = getASTNode(unit, 0, 1, 0);
+ assertEquals("Wrong number of problems", 0, (unit).getProblems().length); //$NON-NLS-1$
+ assertNotNull(node);
+ assertTrue("Not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ assertTrue("Not a class instance creation", expressionStatement.getExpression().getNodeType() == ASTNode.CLASS_INSTANCE_CREATION); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expressionStatement.getExpression();
+ IMethodBinding binding = classInstanceCreation.resolveConstructorBinding();
+ assertFalse("is synthetic", binding.isSynthetic());
+ assertTrue("not a default constructor", !binding.isDefaultConstructor());
+ assertNotNull("Has no declaring node", unit.findDeclaringNode(binding));
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=46699
+ */
+ public void test0509() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0509", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Wrong number of problems", 0, (unit).getProblems().length); //$NON-NLS-1$
+ assertNotNull(node);
+ assertTrue("Not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ assertTrue("Not a class instance creation", expressionStatement.getExpression().getNodeType() == ASTNode.CLASS_INSTANCE_CREATION); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expressionStatement.getExpression();
+ IMethodBinding binding = classInstanceCreation.resolveConstructorBinding();
+ assertFalse("is synthetic", binding.isSynthetic());
+ assertTrue("not a default constructor", !binding.isDefaultConstructor());
+ assertNull("Has a declaring node", unit.findDeclaringNode(binding));
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=46699
+ */
+ public void test0510() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0510", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Wrong number of problems", 0, (unit).getProblems().length); //$NON-NLS-1$
+ assertNotNull(node);
+ assertTrue("Not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ assertTrue("Not a class instance creation", expressionStatement.getExpression().getNodeType() == ASTNode.CLASS_INSTANCE_CREATION); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expressionStatement.getExpression();
+ IMethodBinding binding = classInstanceCreation.resolveConstructorBinding();
+ assertFalse("is synthetic", binding.isSynthetic());
+ assertFalse("is default constructor", binding.isDefaultConstructor());
+ assertNull("Has a declaring node", unit.findDeclaringNode(binding));
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=46699
+ */
+ public void test0511() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0511", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Wrong number of problems", 0, (unit).getProblems().length); //$NON-NLS-1$
+ assertNotNull(node);
+ assertTrue("Not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ assertTrue("Not a class instance creation", expressionStatement.getExpression().getNodeType() == ASTNode.CLASS_INSTANCE_CREATION); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expressionStatement.getExpression();
+ IMethodBinding binding = classInstanceCreation.resolveConstructorBinding();
+ assertFalse("is synthetic", binding.isSynthetic());
+ assertFalse("is default constructor", binding.isDefaultConstructor());
+ assertNull("Has a declaring node", unit.findDeclaringNode(binding));
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=47326
+ */
+ public void test0512() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0512", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertEquals("Wrong number of problems", 2, unit.getProblems().length); //$NON-NLS-1$
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration declaration = (MethodDeclaration) node;
+ assertTrue("Not a constructor", declaration.isConstructor());
+ checkSourceRange(declaration, "public A();", source);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=49429
+ */
+ public void test0513() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0513", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=48502
+ */
+ public void test0514() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0514", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=49204
+ */
+ public void test0515() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0515", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a if statement", node.getNodeType() == ASTNode.IF_STATEMENT);
+ IfStatement ifStatement = (IfStatement) node;
+ assertTrue("not an empty statement", ifStatement.getThenStatement().getNodeType() == ASTNode.EMPTY_STATEMENT);
+ checkSourceRange(ifStatement.getThenStatement(), ";", source);
+ Statement statement = ifStatement.getElseStatement();
+ assertTrue("not a if statement", statement.getNodeType() == ASTNode.IF_STATEMENT);
+ ifStatement = (IfStatement) statement;
+ assertTrue("not an empty statement", ifStatement.getThenStatement().getNodeType() == ASTNode.EMPTY_STATEMENT);
+ checkSourceRange(ifStatement.getThenStatement(), ";", source);
+ Statement statement2 = ifStatement.getElseStatement();
+ assertTrue("not an empty statement", statement2.getNodeType() == ASTNode.EMPTY_STATEMENT);
+ checkSourceRange(statement2, ";", source);
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=48489
+ * @deprecated using deprecated code
+ */
+ public void test0516() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0516", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION);
+ MethodDeclaration declaration = (MethodDeclaration) node;
+ ASTParser parser = ASTParser.newParser(AST.JLS2);
+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
+ parser.setSource(source);
+ parser.setSourceRange(declaration.getStartPosition(), declaration.getLength());
+ parser.setCompilerOptions(JavaCore.getOptions());
+ ASTNode result2 = parser.createAST(null);
+ assertNotNull("No node", result2);
+ assertTrue("not a type declaration", result2.getNodeType() == ASTNode.TYPE_DECLARATION);
+ TypeDeclaration typeDeclaration = (TypeDeclaration) result2;
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("wrong size", 1, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue(declaration.subtreeMatch(new ASTMatcher(), bodyDeclaration));
+ ASTNode root = bodyDeclaration.getRoot();
+ assertNotNull("No root", root);
+ assertTrue("not a compilation unit", root.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) root;
+ assertEquals("wrong problem size", 0, compilationUnit.getProblems().length);
+ assertNotNull("No comments", compilationUnit.getCommentList());
+ assertEquals("Wrong size", 3, compilationUnit.getCommentList().size());
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=48489
+ * @deprecated using deprecated code
+ */
+ public void test0517() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0517", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ assertNotNull("No comments", unit.getCommentList());
+ assertEquals("Wrong size", 3, unit.getCommentList().size());
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION);
+ FieldDeclaration declaration = (FieldDeclaration) node;
+ ASTParser parser = ASTParser.newParser(AST.JLS2);
+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
+ parser.setSource(source);
+ parser.setSourceRange(declaration.getStartPosition(), declaration.getLength());
+ parser.setCompilerOptions(JavaCore.getOptions());
+ ASTNode result2 = parser.createAST(null);
+ assertNotNull("No node", result2);
+ assertTrue("not a type declaration", result2.getNodeType() == ASTNode.TYPE_DECLARATION);
+ TypeDeclaration typeDeclaration = (TypeDeclaration) result2;
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("wrong size", 1, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue(declaration.subtreeMatch(new ASTMatcher(), bodyDeclaration));
+ ASTNode root = bodyDeclaration.getRoot();
+ assertNotNull("No root", root);
+ assertTrue("not a compilation unit", root.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) root;
+ assertEquals("wrong problem size", 0, compilationUnit.getProblems().length);
+ assertNotNull("No comments", compilationUnit.getCommentList());
+ assertEquals("Wrong size", 2, compilationUnit.getCommentList().size());
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=48489
+ * @deprecated using deprecated code
+ */
+ public void test0518() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0518", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not an initializer", node.getNodeType() == ASTNode.INITIALIZER);
+ Initializer declaration = (Initializer) node;
+ ASTParser parser = ASTParser.newParser(AST.JLS2);
+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
+ parser.setSource(source);
+ parser.setSourceRange(declaration.getStartPosition(), declaration.getLength());
+ parser.setCompilerOptions(JavaCore.getOptions());
+ ASTNode result2 = parser.createAST(null);
+ assertNotNull("No node", result2);
+ assertTrue("not a type declaration", result2.getNodeType() == ASTNode.TYPE_DECLARATION);
+ TypeDeclaration typeDeclaration = (TypeDeclaration) result2;
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("wrong size", 1, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue(declaration.subtreeMatch(new ASTMatcher(), bodyDeclaration));
+ ASTNode root = bodyDeclaration.getRoot();
+ assertNotNull("No root", root);
+ assertTrue("not a compilation unit", root.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) root;
+ assertEquals("wrong problem size", 0, compilationUnit.getProblems().length);
+ assertNotNull("No comments", compilationUnit.getCommentList());
+ assertEquals("Wrong size", 3, compilationUnit.getCommentList().size());
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=48489
+ * @deprecated using deprecated code
+ */
+ public void test0519() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0519", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ assertNotNull("No comments", unit.getCommentList());
+ assertEquals("Wrong size", 2, unit.getCommentList().size());
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertNotNull("No node", node);
+ ASTNode statement = node;
+ ASTParser parser = ASTParser.newParser(AST.JLS2);
+ parser.setKind(ASTParser.K_STATEMENTS);
+ parser.setSource(source);
+ parser.setSourceRange(statement.getStartPosition(), statement.getLength());
+ parser.setCompilerOptions(JavaCore.getOptions());
+ ASTNode result2 = parser.createAST(null);
+ assertNotNull("No node", result2);
+ assertTrue("not a block", result2.getNodeType() == ASTNode.BLOCK);
+ Block block = (Block) result2;
+ List statements = block.statements();
+ assertEquals("wrong size", 1, statements.size());
+ Statement statement2 = (Statement) statements.get(0);
+ assertTrue(statement.subtreeMatch(new ASTMatcher(), statement2));
+ ASTNode root = statement2.getRoot();
+ assertNotNull("No root", root);
+ assertTrue("not a compilation unit", root.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) root;
+ assertEquals("wrong problem size", 0, compilationUnit.getProblems().length);
+ assertNotNull("No comments", compilationUnit.getCommentList());
+ assertEquals("Wrong size", 1, compilationUnit.getCommentList().size());
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=48489
+ * @deprecated using deprecated code
+ */
+ public void test0520() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0520", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ assertNotNull("No comments", unit.getCommentList());
+ assertEquals("Wrong size", 2, unit.getCommentList().size());
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a block", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT);
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ ASTParser parser = ASTParser.newParser(AST.JLS2);
+ parser.setKind(ASTParser.K_EXPRESSION);
+ parser.setSource(source);
+ parser.setSourceRange(expression.getStartPosition(), expression.getLength());
+ parser.setCompilerOptions(JavaCore.getOptions());
+ ASTNode result2 = parser.createAST(null);
+ assertNotNull("No node", result2);
+ assertTrue("not a method invocation", result2.getNodeType() == ASTNode.METHOD_INVOCATION);
+ assertTrue(expression.subtreeMatch(new ASTMatcher(), result2));
+ ASTNode root = result2.getRoot();
+ assertNotNull("No root", root);
+ assertTrue("not a compilation unit", root.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) root;
+ assertEquals("wrong problem size", 0, compilationUnit.getProblems().length);
+ assertNotNull("No comments", compilationUnit.getCommentList());
+ assertEquals("Wrong size", 1, compilationUnit.getCommentList().size());
+ }
+ /**
+ * Ensure an OperationCanceledException is correcly thrown when progress monitor is canceled
+ * @deprecated using deprecated code
+ */
+ public void test0521() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0521", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+
+ // count the number of time isCanceled() is called when converting this source unit
+ WorkingCopyOwner owner = new WorkingCopyOwner() {};
+ CancelCounter counter = new CancelCounter();
+ ASTParser parser = ASTParser.newParser(AST.JLS2);
+ parser.setSource(sourceUnit);
+ parser.setResolveBindings(true);
+ parser.setWorkingCopyOwner(owner);
+ parser.createAST(counter);
+
+ // throw an OperatonCanceledException at each point isCanceled() is called
+ for (int i = 0; i < counter.count; i++) {
+ boolean gotException = false;
+ try {
+ parser = ASTParser.newParser(AST.JLS2);
+ parser.setSource(sourceUnit);
+ parser.setResolveBindings(true);
+ parser.setWorkingCopyOwner(owner);
+ parser.createAST(new Canceler(i));
+ } catch (OperationCanceledException e) {
+ gotException = true;
+ }
+ assertTrue("Should get an OperationCanceledException (" + i + ")", gotException);
+ }
+
+ // last should not throw an OperationCanceledException
+ parser = ASTParser.newParser(AST.JLS2);
+ parser.setSource(sourceUnit);
+ parser.setResolveBindings(true);
+ parser.setWorkingCopyOwner(owner);
+ parser.createAST(new Canceler(counter.count));
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=48292
+ */
+ public void test0522() throws JavaModelException {
+ IClassFile classFile = getClassFile("Converter" , "bins", "test0522", "Test.class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertNotNull("No bytes", classFile.getBytes());
+ assertNotNull(classFile);
+ assertNotNull(classFile.getSource());
+ IType type = classFile.getType();
+ assertNotNull(type);
+ IMethod[] methods = type.getMethods();
+ assertNotNull(methods);
+ assertEquals("wrong size", 2, methods.length);
+ IMethod method = methods[1];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(classFile, sourceRange.getOffset() + sourceRange.getLength() / 2, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 1, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("wrong name", "test", methodDeclaration.getName().getIdentifier());
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ assertNotNull(methodBinding);
+ List statements = ((MethodDeclaration) node).getBody().statements();
+ assertEquals("wrong size", 2, statements.size());
+ ASTNode node2 = (ASTNode) statements.get(1);
+ assertNotNull(node2);
+ assertTrue("Not an expression statement", node2.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node2;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ assertTrue("Not a simple name", expression2.getNodeType() == ASTNode.SIMPLE_NAME); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) expression2;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("wrong type", binding.getKind() == IBinding.VARIABLE); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Wrong name", "a", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ SimpleName simpleName2 = methodInvocation.getName();
+ assertEquals("Wrong name", "clone", simpleName2.getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding2 = simpleName2.resolveBinding();
+ assertNotNull("no binding2", binding2); //$NON-NLS-1$
+ assertTrue("Wrong type", binding2.getKind() == IBinding.METHOD); //$NON-NLS-1$
+ IMethodBinding methodBinding2 = (IMethodBinding) binding2;
+ assertEquals("Wrong name", "clone", methodBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=48292
+ */
+ public void test0523() throws JavaModelException {
+ IClassFile classFile = getClassFile("Converter" , "bins", "test0523", "Test.class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertNotNull(classFile);
+ assertNotNull(classFile.getSource());
+ IType type = classFile.getType();
+ assertNotNull(type);
+ IMethod[] methods = type.getMethods();
+ assertNotNull(methods);
+ assertEquals("wrong size", 2, methods.length);
+ IMethod method = methods[1];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(classFile, sourceRange.getOffset() + sourceRange.getLength() / 2, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 1, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("wrong name", "test", methodDeclaration.getName().getIdentifier());
+ List statements = ((MethodDeclaration) node).getBody().statements();
+ assertEquals("wrong size", 2, statements.size());
+ ASTNode node2 = (ASTNode) statements.get(1);
+ assertNotNull(node2);
+ assertTrue("Not an expression statement", node2.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node2;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ assertTrue("Not a simple name", expression2.getNodeType() == ASTNode.SIMPLE_NAME); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) expression2;
+ IBinding binding = simpleName.resolveBinding();
+ assertNull("No binding", binding); //$NON-NLS-1$
+ SimpleName simpleName2 = methodInvocation.getName();
+ assertEquals("Wrong name", "clone", simpleName2.getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=48292
+ */
+ public void test0524() throws JavaModelException {
+ IClassFile classFile = getClassFile("Converter" , "bins", "test0524", "A.class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertNotNull(classFile);
+ assertNotNull(classFile.getSource());
+ IType type = classFile.getType();
+ assertNotNull(type);
+ IMethod[] methods = type.getMethods();
+ assertNotNull(methods);
+ assertEquals("wrong size", 2, methods.length);
+ IMethod method = methods[1];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(classFile, sourceRange.getOffset() + sourceRange.getLength() / 2, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("wrong name", "test", methodDeclaration.getName().getIdentifier());
+ List statements = ((MethodDeclaration) node).getBody().statements();
+ assertEquals("wrong size", 1, statements.size());
+ ASTNode node2 = (ASTNode) statements.get(0);
+ assertNotNull(node2);
+ assertTrue("Not an variable declaration statement", node2.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=48292
+ */
+ public void test0525() throws JavaModelException {
+ IClassFile classFile = getClassFile("Converter" , "bins", "test0525", "A.class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertNotNull(classFile);
+ assertNotNull(classFile.getSource());
+ IType type = classFile.getType();
+ assertNotNull(type);
+ IMethod[] methods = type.getMethods();
+ assertNotNull(methods);
+ assertEquals("wrong size", 2, methods.length);
+ IMethod method = methods[1];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(classFile, sourceRange.getOffset() + sourceRange.getLength() / 2, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("wrong name", "test", methodDeclaration.getName().getIdentifier());
+ List statements = ((MethodDeclaration) node).getBody().statements();
+ assertEquals("wrong size", 1, statements.size());
+ ASTNode node2 = (ASTNode) statements.get(0);
+ assertNotNull(node2);
+ assertTrue("Not an variable declaration statement", node2.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node2;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertTrue("Not a class instance creation", expression.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ ITypeBinding typeBinding = classInstanceCreation.resolveTypeBinding();
+ assertNotNull(typeBinding);
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=48292
+ */
+ public void test0526() throws JavaModelException {
+ IClassFile classFile = getClassFile("Converter" , "bins", "test0526", "A.class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertNotNull(classFile);
+ assertNotNull(classFile.getSource());
+ IType type = classFile.getType();
+ assertNotNull(type);
+ IType[] memberTypes = type.getTypes();
+ assertNotNull(memberTypes);
+ assertEquals("wrong size", 1, memberTypes.length);
+ IType memberType = memberTypes[0];
+ IMethod[] methods = memberType.getMethods();
+ assertEquals("wrong size", 2, methods.length);
+ IMethod method = methods[1];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(classFile, sourceRange.getOffset() + sourceRange.getLength() / 2, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("wrong name", "test", methodDeclaration.getName().getIdentifier());
+ List statements = ((MethodDeclaration) node).getBody().statements();
+ assertEquals("wrong size", 1, statements.size());
+ ASTNode node2 = (ASTNode) statements.get(0);
+ assertNotNull(node2);
+ assertTrue("Not an variable declaration statement", node2.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node2;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertTrue("Not a class instance creation", expression.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ ITypeBinding typeBinding = classInstanceCreation.resolveTypeBinding();
+ assertNotNull(typeBinding);
+ assertTrue(typeBinding.isAnonymous());
+ assertEquals("Wrong name", "", typeBinding.getName());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=48292
+ */
+ public void test0527() throws JavaModelException {
+ IClassFile classFile = getClassFile("Converter" , "bins", "test0527", "A.class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertNotNull(classFile);
+ assertNotNull(classFile.getSource());
+ IType type = classFile.getType();
+ assertNotNull(type);
+ IMethod[] methods = type.getMethods();
+ assertEquals("wrong size", 1, methods.length);
+ IMethod method = methods[0];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(classFile, sourceRange.getOffset() + sourceRange.getLength() / 2, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("wrong name", "A", methodDeclaration.getName().getIdentifier());
+ assertTrue("Not a constructor", methodDeclaration.isConstructor());
+ IBinding binding = methodDeclaration.getName().resolveBinding();
+ assertNotNull(binding);
+ assertEquals("Wrong type", IBinding.METHOD, binding.getKind());
+ List statements = ((MethodDeclaration) node).getBody().statements();
+ assertEquals("wrong size", 1, statements.size());
+ ASTNode node2 = (ASTNode) statements.get(0);
+ assertNotNull(node2);
+ assertTrue("Not an variable declaration statement", node2.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node2;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertTrue("Not a class instance creation", expression.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ ITypeBinding typeBinding = classInstanceCreation.resolveTypeBinding();
+ assertNotNull(typeBinding);
+ assertTrue(typeBinding.isAnonymous());
+ assertEquals("Wrong name", "", typeBinding.getName());
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=48292
+ */
+ public void test0528() throws JavaModelException {
+ IClassFile classFile = getClassFile("Converter" , "bins", "test0528", "A.class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertNotNull(classFile);
+ assertNotNull(classFile.getSource());
+ IType type = classFile.getType();
+ IType[] memberTypes = type.getTypes();
+ assertNotNull(memberTypes);
+ assertEquals("wrong size", 1, memberTypes.length);
+ IType memberType = memberTypes[0];
+ ISourceRange sourceRange = memberType.getSourceRange();
+ ASTNode result = runConversion(classFile, sourceRange.getOffset() + sourceRange.getLength() / 2, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ assertEquals("wrong name", "B", typeDeclaration.getName().getIdentifier());
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue("Not a method declaration", bodyDeclaration.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size());
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=48292
+ */
+ public void test0529() throws JavaModelException {
+ IClassFile classFile = getClassFile("Converter" , "bins", "test0529", "A.class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertNotNull(classFile);
+ assertNotNull(classFile.getSource());
+ IType type = classFile.getType();
+ IType[] memberTypes = type.getTypes();
+ assertNotNull(memberTypes);
+ assertEquals("wrong size", 1, memberTypes.length);
+ IType memberType = memberTypes[0];
+ ISourceRange sourceRange = memberType.getSourceRange();
+ ASTNode result = runConversion(classFile, sourceRange.getOffset() + sourceRange.getLength() / 2, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ assertEquals("wrong name", "B", typeDeclaration.getName().getIdentifier());
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue("Not a method declaration", bodyDeclaration.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=48292
+ */
+ public void test0530() throws JavaModelException {
+ IClassFile classFile = getClassFile("Converter" , "bins", "test0530", "A.class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertNotNull(classFile);
+ assertNotNull(classFile.getSource());
+ IType type = classFile.getType();
+ IMethod[] methods = type.getMethods();
+ assertEquals("wrong size", 3, methods.length);
+ IMethod method = methods[2];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(classFile, sourceRange.getOffset() + sourceRange.getLength() / 2, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 2);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("Wrong size", 2, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 1);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ block = methodDeclaration.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=48292
+ */
+ public void test0531() throws JavaModelException {
+ IClassFile classFile = getClassFile("Converter" , "bins", "test0531", "A.class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertNotNull(classFile);
+ assertNotNull(classFile.getSource());
+ IType type = classFile.getType();
+ IMethod[] methods = type.getMethods();
+ assertEquals("wrong size", 5, methods.length);
+ IMethod method = methods[3];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(classFile, sourceRange.getOffset() + sourceRange.getLength() / 2, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 5);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("Wrong size", 2, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 4);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ block = methodDeclaration.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Wrong name", "field", fragment.getName().getIdentifier());
+ assertNotNull("No initializer", expression);
+
+ node = getASTNode((CompilationUnit) result, 0, 1);
+ assertTrue("Not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ expression = fragment.getInitializer();
+ assertEquals("Wrong name", "i", fragment.getName().getIdentifier());
+ assertNotNull("No initializer", expression);
+
+ node = getASTNode((CompilationUnit) result, 0, 2);
+ assertTrue("Not an initializer", node.getNodeType() == ASTNode.INITIALIZER); //$NON-NLS-1$
+ Initializer initializer = (Initializer) node;
+ assertEquals("Not static", Modifier.NONE, initializer.getModifiers());
+ block = initializer.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 3);
+ assertTrue("Not an initializer", node.getNodeType() == ASTNode.INITIALIZER); //$NON-NLS-1$
+ initializer = (Initializer) node;
+ assertEquals("Not static", Modifier.STATIC, initializer.getModifiers());
+ block = initializer.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 6);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ block = methodDeclaration.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=48292
+ */
+ public void test0532() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0488", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType[] types = sourceUnit.getTypes();
+ assertNotNull(types);
+ assertEquals("wrong size", 1, types.length);
+ IType type = types[0];
+ IInitializer[] initializers = type.getInitializers();
+ assertEquals("wrong size", 2, initializers.length);
+ IInitializer init = initializers[1];
+ ISourceRange sourceRange = init.getSourceRange();
+ int position = sourceRange.getOffset() + sourceRange.getLength() / 2;
+
+ IClassFile classFile = getClassFile("Converter" , "bins", "test0532", "A.class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertNotNull(classFile);
+ assertNotNull(classFile.getSource());
+ type = classFile.getType();
+ initializers = type.getInitializers();
+ assertEquals("wrong size", 0, initializers.length);
+ ASTNode result = runConversion(classFile, position, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 5);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 4);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ block = methodDeclaration.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Wrong name", "field", fragment.getName().getIdentifier());
+ assertNotNull("No initializer", expression);
+
+ node = getASTNode((CompilationUnit) result, 0, 1);
+ assertTrue("Not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ expression = fragment.getInitializer();
+ assertEquals("Wrong name", "i", fragment.getName().getIdentifier());
+ assertNotNull("No initializer", expression);
+
+ node = getASTNode((CompilationUnit) result, 0, 2);
+ assertTrue("Not an initializer", node.getNodeType() == ASTNode.INITIALIZER); //$NON-NLS-1$
+ Initializer initializer = (Initializer) node;
+ assertEquals("Not static", Modifier.NONE, initializer.getModifiers());
+ block = initializer.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 3);
+ assertTrue("Not an initializer", node.getNodeType() == ASTNode.INITIALIZER); //$NON-NLS-1$
+ initializer = (Initializer) node;
+ assertEquals("Not static", Modifier.STATIC, initializer.getModifiers());
+ block = initializer.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 6);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ block = methodDeclaration.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=48489
+ * @deprecated using deprecated code
+ */
+ public void test0533() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0533", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION);
+ MethodDeclaration declaration = (MethodDeclaration) node;
+ ASTParser parser = ASTParser.newParser(AST.JLS2);
+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
+ parser.setSource(source);
+ parser.setSourceRange(declaration.getStartPosition(), declaration.getLength());
+ parser.setCompilerOptions(JavaCore.getOptions());
+ ASTNode result2 = parser.createAST(null);
+ assertNotNull("No node", result2);
+ assertTrue("not a compilation unit", result2.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result2;
+ assertEquals("wrong problem size", 1, compilationUnit.getProblems().length);
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=48489
+ * @deprecated using deprecated code
+ */
+ public void test0534() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0534", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION);
+ FieldDeclaration declaration = (FieldDeclaration) node;
+ ASTParser parser = ASTParser.newParser(AST.JLS2);
+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
+ parser.setSource(source);
+ parser.setSourceRange(declaration.getStartPosition(), declaration.getLength());
+ parser.setCompilerOptions(JavaCore.getOptions());
+ ASTNode result2 = parser.createAST(null);
+ assertNotNull("No node", result2);
+ assertTrue("not a compilation unit", result2.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result2;
+ assertEquals("wrong problem size", 1, compilationUnit.getProblems().length);
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=48489
+ * @deprecated using deprecated code
+ */
+ public void test0535() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0535", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not an initializer", node.getNodeType() == ASTNode.INITIALIZER);
+ Initializer declaration = (Initializer) node;
+ ASTParser parser = ASTParser.newParser(AST.JLS2);
+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
+ parser.setSource(source);
+ parser.setSourceRange(declaration.getStartPosition(), declaration.getLength());
+ parser.setCompilerOptions(JavaCore.getOptions());
+ ASTNode result2 = parser.createAST(null);
+ assertNotNull("No node", result2);
+ assertTrue("not a compilation unit", result2.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result2;
+ assertEquals("wrong problem size", 1, compilationUnit.getProblems().length);
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=47396
+ */
+ public void test0536() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0536", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, false);
+ assertNotNull("No compilation unit", result);
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=51089
+ */
+ public void test0537a() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0537", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, false);
+ assertNotNull("No compilation unit", result);
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=51089
+ */
+ public void test0537b() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0537", "B.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, false);
+ assertNotNull("No compilation unit", result);
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=51089
+ */
+ public void test0537c() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0537", "C.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, false);
+ assertNotNull("No compilation unit", result);
+ }
+ /**
+ * Ensures that an AST can be created during reconcile.
+ * @deprecated using deprecated code
+ */
+ public void test0538a() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0538", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ try {
+ sourceUnit.becomeWorkingCopy(null, null);
+ sourceUnit.getBuffer().setContents(
+ "package test0538;\n" +
+ "public class A {\n" +
+ " int i;\n" +
+ "}"
+ );
+ CompilationUnit unit = sourceUnit.reconcile(AST.JLS2, false, null, null);
+ assertNotNull("No level 2 compilation unit", unit);
+ assertEquals("Compilation unit has wrong AST level (2)", AST.JLS2, unit.getAST().apiLevel());
+ // TODO improve test for AST.JLS3
+ } finally {
+ sourceUnit.discardWorkingCopy();
+ }
+ }
+ /*
+ * Ensures that no AST is created during reconcile if not requested.
+ */
+ public void test0538b() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0538", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ try {
+ sourceUnit.becomeWorkingCopy(null);
+ sourceUnit.getBuffer().setContents(
+ "package test0538;\n" +
+ "public class A {\n" +
+ " int i;\n" +
+ "}"
+ );
+ CompilationUnit unit = sourceUnit.reconcile(0, false, null, null);
+ assertNull("Unexpected compilation unit", unit);
+ } finally {
+ sourceUnit.discardWorkingCopy();
+ }
+ }
+ /**
+ * Ensures that no AST is created during reconcile if consistent.
+ * @deprecated using deprecated code
+ */
+ public void test0538c() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0538", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ try {
+ sourceUnit.becomeWorkingCopy(null, null);
+ CompilationUnit unit = sourceUnit.reconcile(AST.JLS2, false, null, null);
+ assertNull("Unexpected compilation unit", unit);
+ // TODO improve test for AST.JLS3
+ } finally {
+ sourceUnit.discardWorkingCopy();
+ }
+ }
+ /**
+ * Ensures that bindings are created during reconcile if the problem requestor is active.
+ * @deprecated using deprecated code
+ */
+ public void test0538d() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0538", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ try {
+ ReconcilerTests.ProblemRequestor pbRequestor = new ReconcilerTests.ProblemRequestor();
+ sourceUnit.becomeWorkingCopy(pbRequestor, null);
+ sourceUnit.getBuffer().setContents(
+ "package test0538;\n" +
+ "public class A {\n" +
+ " Object field;\n" +
+ "}"
+ );
+ // TODO improve test for AST.JLS3
+ CompilationUnit unit = sourceUnit.reconcile(AST.JLS2, false, null, null);
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("Not original", isOriginal(node));
+ assertTrue("not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION);
+ FieldDeclaration declaration = (FieldDeclaration) node;
+ Type type = declaration.getType();
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No type binding", typeBinding);
+ assertEquals("Wrong name", "Object", typeBinding.getName());
+ } finally {
+ sourceUnit.discardWorkingCopy();
+ }
+ }
+ /**
+ * Ensures that bindings are created during reconcile if force problem detection is turned on.
+ * @deprecated using deprecated code
+ */
+ public void test0538e() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0538", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ try {
+ ReconcilerTests.ProblemRequestor pbRequestor = new ReconcilerTests.ProblemRequestor();
+ sourceUnit.becomeWorkingCopy(pbRequestor, null);
+ // TODO improve test for AST.JLS3
+ CompilationUnit unit = sourceUnit.reconcile(AST.JLS2, true/*force pb detection*/, null, null);
+ ASTNode node = getASTNode(unit, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION);
+ TypeDeclaration declaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = declaration.resolveBinding();
+ assertNotNull("No type binding", typeBinding);
+ assertEquals("Wrong name", "A", typeBinding.getName());
+ } finally {
+ sourceUnit.discardWorkingCopy();
+ }
+ }
+ /**
+ * Ensures that bindings are created during reconcile if force problem detection is turned on.
+ * Case of a unit containing an anonymous type.
+ * (regression test for bug 55102 NPE when using ICU.reconcile(GET_AST_TRUE, ...))
+ * @deprecated using deprecated code
+ */
+ public void test0538f() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0538", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ try {
+ ReconcilerTests.ProblemRequestor pbRequestor = new ReconcilerTests.ProblemRequestor();
+ sourceUnit.becomeWorkingCopy(pbRequestor, null);
+ sourceUnit.getBuffer().setContents(
+ "package test0538;\n" +
+ "public class A {\n" +
+ " void foo() {\n" +
+ " new Object() {\n" +
+ " void bar() {\n" +
+ " }\n" +
+ " };\n" +
+ " }\n" +
+ "}"
+ );
+ // TODO improve test for AST.JLS3
+ CompilationUnit unit = sourceUnit.reconcile(AST.JLS2, true/*force pb detection*/, null, null);
+ ASTNode node = getASTNode(unit, 0);
+ assertNotNull("No node", node);
+ } finally {
+ sourceUnit.discardWorkingCopy();
+ }
+ }
+ /**
+ * Ensures that bindings are created during reconcile if force problem detection is turned on.
+ * Case of a unit containing an anonymous type.
+ * (regression test for bug 55102 NPE when using ICU.reconcile(GET_AST_TRUE, ...))
+ * @deprecated using deprecated code
+ */
+ public void test0538g() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0538", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ try {
+ ReconcilerTests.ProblemRequestor pbRequestor = new ReconcilerTests.ProblemRequestor();
+ sourceUnit.becomeWorkingCopy(pbRequestor, null);
+ sourceUnit.getBuffer().setContents(
+ "package test0538;\n" +
+ "public class A {\n" +
+ " void foo() {\n" +
+ " new Object() {\n" +
+ " void bar() {\n" +
+ " }\n" +
+ " };\n" +
+ " }\n" +
+ "}"
+ );
+ sourceUnit.reconcile(ICompilationUnit.NO_AST, false/* don't force pb detection*/, null, null);
+ // TODO improve test for AST.JLS3
+ CompilationUnit unit = sourceUnit.reconcile(AST.JLS2, true/*force pb detection*/, null, null);
+ ASTNode node = getASTNode(unit, 0);
+ assertNotNull("No node", node);
+ } finally {
+ sourceUnit.discardWorkingCopy();
+ }
+ }
+ /**
+ * Ensures that asking for well known type doesn't throw a NPE if the problem requestor is not active.
+ * (regression test for bug 64750 NPE in Java AST Creation - editing some random file)
+ * @deprecated using deprecated code
+ */
+ public void test0538h() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0538", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ try {
+ ReconcilerTests.ProblemRequestor pbRequestor = new ReconcilerTests.ProblemRequestor() {
+ public boolean isActive() {
+ return false;
+ }
+ };
+ sourceUnit.becomeWorkingCopy(pbRequestor, null);
+ sourceUnit.getBuffer().setContents(
+ "package test0538;\n" +
+ "public class A {\n" +
+ " Object field;\n" +
+ "}"
+ );
+ // TODO improve test for AST.JLS3
+ CompilationUnit unit = sourceUnit.reconcile(AST.JLS2, false, null, null);
+ assertEquals("Unexpected well known type", null, unit.getAST().resolveWellKnownType("void"));
+ } finally {
+ sourceUnit.discardWorkingCopy();
+ }
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=53477
+ */
+ public void test0539() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0539", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 1, 0);
+ assertNotNull("No node", node);
+ assertTrue("not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT);
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("not a class instance creation", expression.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION);
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ checkSourceRange(classInstanceCreation, "new A(){}.new Inner(){/*x*/}", source);
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ Expression expression2 = classInstanceCreation.getExpression();
+ assertTrue("not a class instance creation", expression2.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION);
+ ClassInstanceCreation classInstanceCreation2 = (ClassInstanceCreation) expression2;
+ AnonymousClassDeclaration anonymousClassDeclaration2 = classInstanceCreation2.getAnonymousClassDeclaration();
+ assertNotNull("No anonymous class declaration", anonymousClassDeclaration2);
+ checkSourceRange(anonymousClassDeclaration2, "{}", source);
+ assertNotNull("No anonymous class declaration", anonymousClassDeclaration);
+ checkSourceRange(anonymousClassDeclaration, "{/*x*/}", source);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=54431
+ */
+ public void test0540() {
+ char[] source =
+ ("package test0540;\n" + //$NON-NLS-1$
+ "\n" + //$NON-NLS-1$
+ "class Test {\n" + //$NON-NLS-1$
+ " public void foo(int arg) {\n" +//$NON-NLS-1$
+ " assert true;\n" +//$NON-NLS-1$
+ " }\n" + //$NON-NLS-1$
+ "}").toCharArray(); //$NON-NLS-1$
+ IJavaProject project = getJavaProject("Converter"); //$NON-NLS-1$
+ Map options = project.getOptions(true);
+ options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4);
+ options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_4);
+ options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4);
+ ASTNode result = runConversion(source, "Test.java", project, options, true); //$NON-NLS-1$
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("Problems found", 0, compilationUnit.getProblems().length);
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertTrue("not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Test", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong package", "test0540", typeBinding.getPackage().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("Not an interface", typeBinding.isClass()); //$NON-NLS-1$
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=56697
+ */
+ public void test0541() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0541", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertEquals("not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ class Change14FieldAccessASTVisitor extends ASTVisitor {
+ int counter;
+ Change14FieldAccessASTVisitor() {
+ this.counter = 0;
+ }
+ public void endVisit(QualifiedName qualifiedName) {
+ IBinding i_binding = qualifiedName.getQualifier().resolveBinding();
+ ITypeBinding type_binding = qualifiedName.getQualifier().resolveTypeBinding();
+ if (i_binding == null || type_binding == null) {
+ this.counter++;
+ }
+ }
+ }
+ Change14FieldAccessASTVisitor visitor = new Change14FieldAccessASTVisitor();
+ unit.accept(visitor);
+ assertEquals("Missing binding", 0, visitor.counter);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=55004
+ */
+ public void test0542() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0542", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertTrue("not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "STRING_FIELD", variableBinding.getName());
+ Object constantValue = variableBinding.getConstantValue();
+ assertNotNull("No constant", constantValue);
+ assertEquals("Wrong value", "Hello world!", constantValue);
+ Expression initializer = fragment.getInitializer();
+ assertNotNull("No initializer", initializer);
+ checkSourceRange(initializer, "\"Hello world!\"", source);
+
+ node = getASTNode(unit, 0, 1);
+ assertTrue("not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "BOOLEAN_FIELD", variableBinding.getName());
+ constantValue = variableBinding.getConstantValue();
+ assertNotNull("No constant", constantValue);
+ assertEquals("Wrong value", new Boolean(true), constantValue);
+ initializer = fragment.getInitializer();
+ assertNotNull("No initializer", initializer);
+ checkSourceRange(initializer, "true", source);
+
+ node = getASTNode(unit, 0, 2);
+ assertTrue("not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "BYTE_FIELD", variableBinding.getName());
+ constantValue = variableBinding.getConstantValue();
+ assertNotNull("No constant", constantValue);
+ assertEquals("Wrong value", new Byte((byte)1), constantValue);
+ initializer = fragment.getInitializer();
+ assertNotNull("No initializer", initializer);
+ checkSourceRange(initializer, "1", source);
+
+ node = getASTNode(unit, 0, 3);
+ assertTrue("not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "CHAR_FIELD", variableBinding.getName());
+ constantValue = variableBinding.getConstantValue();
+ assertNotNull("No constant", constantValue);
+ assertEquals("Wrong value", new Character('{'), constantValue);
+ initializer = fragment.getInitializer();
+ assertNotNull("No initializer", initializer);
+ checkSourceRange(initializer, "\'{\'", source);
+
+ node = getASTNode(unit, 0, 4);
+ assertTrue("not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "DOUBLE_FIELD", variableBinding.getName());
+ constantValue = variableBinding.getConstantValue();
+ assertNotNull("No constant", constantValue);
+ assertEquals("Wrong value", new Double("3.1415"), constantValue);
+ initializer = fragment.getInitializer();
+ assertNotNull("No initializer", initializer);
+ checkSourceRange(initializer, "3.1415", source);
+
+ node = getASTNode(unit, 0, 5);
+ assertTrue("not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "FLOAT_FIELD", variableBinding.getName());
+ constantValue = variableBinding.getConstantValue();
+ assertNotNull("No constant", constantValue);
+ assertEquals("Wrong value", new Float("3.14159f"), constantValue);
+ initializer = fragment.getInitializer();
+ assertNotNull("No initializer", initializer);
+ checkSourceRange(initializer, "3.14159f", source);
+
+ node = getASTNode(unit, 0, 6);
+ assertTrue("not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "INT_FIELD", variableBinding.getName());
+ constantValue = variableBinding.getConstantValue();
+ assertNotNull("No constant", constantValue);
+ assertEquals("Wrong value", Integer.valueOf("7fffffff", 16), constantValue);
+ initializer = fragment.getInitializer();
+ assertNotNull("No initializer", initializer);
+ checkSourceRange(initializer, "Integer.MAX_VALUE", source);
+
+ node = getASTNode(unit, 0, 7);
+ assertTrue("not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "LONG_FIELD", variableBinding.getName());
+ constantValue = variableBinding.getConstantValue();
+ assertNotNull("No constant", constantValue);
+ assertEquals("Wrong value", new Long("34"), constantValue);
+ initializer = fragment.getInitializer();
+ assertNotNull("No initializer", initializer);
+ checkSourceRange(initializer, "34L", source);
+
+ node = getASTNode(unit, 0, 8);
+ assertTrue("not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "SHORT_FIELD", variableBinding.getName());
+ constantValue = variableBinding.getConstantValue();
+ assertNotNull("No constant", constantValue);
+ assertEquals("Wrong value", new Short("130"), constantValue);
+ initializer = fragment.getInitializer();
+ assertNotNull("No initializer", initializer);
+ checkSourceRange(initializer, "130", source);
+
+ node = getASTNode(unit, 0, 9);
+ assertTrue("not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "int_field", variableBinding.getName());
+ constantValue = variableBinding.getConstantValue();
+ assertNull("Got a constant", constantValue);
+ initializer = fragment.getInitializer();
+ assertNotNull("No initializer", initializer);
+ checkSourceRange(initializer, "Integer.MAX_VALUE", source);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=58436
+ */
+ public void test0543() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0543", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ unit.accept(new GetKeyVisitor());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=51500
+ */
+ public void test0544() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0544", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertEquals("not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType()); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Not an abstract method", (methodDeclaration.getModifiers() & Modifier.ABSTRACT) != 0);
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ assertNotNull("No binding", methodBinding);
+ assertTrue("Not an abstract method binding", (methodBinding.getModifiers() & Modifier.ABSTRACT) != 0);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=59843
+ */
+ public void test0545() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0545", "First.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertEquals("not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType()); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertEquals("Wrong key", "Ltest0545/First$Test;", typeBinding.getKey());
+
+ sourceUnit = getCompilationUnit("Converter", "src", "test0545", "Second.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ result = runConversion(sourceUnit, true);
+ unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ node = getASTNode(unit, 0, 0);
+ assertEquals("not a method declaration", ASTNode.TYPE_DECLARATION, node.getNodeType()); //$NON-NLS-1$
+ typeDeclaration = (TypeDeclaration) node;
+ typeBinding = typeDeclaration.resolveBinding();
+ assertEquals("Wrong key", "Ltest0545/Second$Test;", typeBinding.getKey());
+
+ sourceUnit = getCompilationUnit("Converter", "src", "test0545", "Third.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ result = runConversion(sourceUnit, true);
+ unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ node = getASTNode(unit, 0, 0);
+ assertEquals("not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType()); //$NON-NLS-1$
+ typeDeclaration = (TypeDeclaration) node;
+ typeBinding = typeDeclaration.resolveBinding();
+ assertEquals("Wrong key", "Ltest0545/Third$Test;", typeBinding.getKey());
+
+
+ sourceUnit = getCompilationUnit("Converter", "src", "test0545", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ result = runConversion(sourceUnit, true);
+ unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ node = getASTNode(unit, 0);
+ assertEquals("not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType()); //$NON-NLS-1$
+ typeDeclaration = (TypeDeclaration) node;
+ typeBinding = typeDeclaration.resolveBinding();
+ assertEquals("Wrong key", "Ltest0545/Test;", typeBinding.getKey());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=59848
+ * @deprecated using deprecated code
+ */
+ public void test0546() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0546", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 1, 0, 0);
+ assertEquals("not a variable declaration", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType()); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ ITypeBinding typeBinding = variableBinding.getType();
+ assertTrue("An anonymous type binding", !typeBinding.isAnonymous());
+ Expression initializer = fragment.getInitializer();
+ assertEquals("not a class instance creation", ASTNode.CLASS_INSTANCE_CREATION, initializer.getNodeType()); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) initializer;
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ ITypeBinding typeBinding2 = anonymousClassDeclaration.resolveBinding();
+ assertTrue("Not an anonymous type binding", typeBinding2.isAnonymous());
+ ITypeBinding typeBinding3 = classInstanceCreation.resolveTypeBinding();
+ assertTrue("Not an anonymous type binding", typeBinding3.isAnonymous());
+ node = getASTNode(unit, 1, 0, 1);
+ assertEquals("not a expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType()); //$NON-NLS-1$
+ ExpressionStatement statement = (ExpressionStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType()); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ assertEquals("not a simple name", ASTNode.SIMPLE_NAME, expression2.getNodeType()); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) expression2;
+ ITypeBinding typeBinding4 = simpleName.resolveTypeBinding();
+ assertTrue("An anonymous type binding", !typeBinding4.isAnonymous());
+ Name name = classInstanceCreation.getName();
+ IBinding binding = name.resolveBinding();
+ assertEquals("Wrong type", IBinding.TYPE, binding.getKind());
+ ITypeBinding typeBinding5 = (ITypeBinding) binding;
+ assertTrue("An anonymous type binding", !typeBinding5.isAnonymous());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=60078
+ * @deprecated using deprecated code
+ */
+ public void test0547() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0547", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("not a type declaration statement", ASTNode.TYPE_DECLARATION_STATEMENT, node.getNodeType()); //$NON-NLS-1$
+ TypeDeclarationStatement typeDeclarationStatement = (TypeDeclarationStatement) node;
+ TypeDeclaration typeDeclaration = typeDeclarationStatement.getTypeDeclaration();
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertEquals("Wrong key", "Ltest0547/A$74$Local;", typeBinding.getKey());
+
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("wrong size", 3, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertEquals("not a type declaration statement", ASTNode.TYPE_DECLARATION, bodyDeclaration.getNodeType()); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration2 = (TypeDeclaration) bodyDeclaration;
+
+ typeBinding = typeDeclaration2.resolveBinding();
+ assertEquals("Wrong key", "Ltest0547/A$100$LocalMember;", typeBinding.getKey());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=60581
+ */
+ public void test0548() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0548", "PaletteStackEditPart.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, false);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=48502
+ */
+ public void test0549() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0549", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, false);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=48502
+ */
+ public void test0550() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0550", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, false);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=60848
+ */
+ public void test0551() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0551", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, false);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 1, problems.length); //$NON-NLS-1$
+ IProblem problem = problems[0];
+ assertEquals("wrong end position", source.length - 1, problem.getSourceEnd());
+ }
+
+ public void test0552() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0552", "Test.java");
+ char[] source = sourceUnit.getSource().toCharArray();
+ CompilationUnit result = (CompilationUnit) runConversion(sourceUnit, true);
+ assertEquals("Got errors", 0, result.getProblems().length);
+ TypeDeclaration declaration = (TypeDeclaration) result.types().get(0);
+ Block body = declaration.getMethods()[0].getBody();
+ ExpressionStatement expr = (ExpressionStatement) body.statements().get(0);
+ MethodInvocation invocation = (MethodInvocation) expr.getExpression();
+ InfixExpression node = (InfixExpression) invocation.arguments().get(0);
+ ITypeBinding typeBinding = node.resolveTypeBinding();
+ assertEquals("wrong type", "java.lang.String", typeBinding.getQualifiedName());
+ checkSourceRange(node, "\"a\" + \"a\" + \"a\"", source);
+ List extendedOperands = node.extendedOperands();
+ assertEquals("Wrong size", 1, extendedOperands.size());
+ Expression leftOperand = node.getLeftOperand();
+ checkSourceRange(leftOperand, "\"a\"", source);
+ typeBinding = leftOperand.resolveTypeBinding();
+ assertEquals("wrong type", "java.lang.String", typeBinding.getQualifiedName());
+ Expression rightOperand = node.getRightOperand();
+ checkSourceRange(rightOperand, "\"a\"", source);
+ typeBinding = rightOperand.resolveTypeBinding();
+ assertEquals("wrong type", "java.lang.String", typeBinding.getQualifiedName());
+ Expression expression = (Expression) extendedOperands.get(0);
+ checkSourceRange(expression, "\"a\"", source);
+ typeBinding = expression.resolveTypeBinding();
+ assertEquals("wrong type", "java.lang.String", typeBinding.getQualifiedName());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=61946
+ */
+ public void test0553() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0553", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ Object constantValue = variableBinding.getConstantValue();
+ assertNull("Got a constant value", constantValue);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=61946
+ */
+ public void test0554() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0554", "B.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a return statement", ASTNode.RETURN_STATEMENT, node.getNodeType());
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertNotNull("No expression", expression);
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ checkSourceRange(expression2, "A", source);
+ ITypeBinding typeBinding = expression2.resolveTypeBinding();
+ assertEquals("wrong type", "test0554.A", typeBinding.getQualifiedName());
+ IVariableBinding[] fields = typeBinding.getDeclaredFields();
+ assertEquals("Wrong size", 1, fields.length);
+ IVariableBinding variableBinding = fields[0];
+ Object constantValue = variableBinding.getConstantValue();
+ assertNotNull("Missing constant", constantValue);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=61946
+ */
+ public void test0555() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0555", "B.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a return statement", ASTNode.RETURN_STATEMENT, node.getNodeType());
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertNotNull("No expression", expression);
+ assertEquals("Not a qualified name", ASTNode.QUALIFIED_NAME, expression.getNodeType());
+ QualifiedName qualifiedName = (QualifiedName) expression;
+ Name name = qualifiedName.getQualifier();
+ checkSourceRange(name, "A", source);
+ ITypeBinding typeBinding = name.resolveTypeBinding();
+ assertEquals("wrong type", "test0555.A", typeBinding.getQualifiedName());
+ IVariableBinding[] fields = typeBinding.getDeclaredFields();
+ assertEquals("Wrong size", 1, fields.length);
+ IVariableBinding variableBinding = fields[0];
+ Object constantValue = variableBinding.getConstantValue();
+ assertNotNull("No constant value", constantValue);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=62463
+ */
+ public void test0556() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0556", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 1, 0);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertEquals("Not an method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ checkSourceRange(expression2, "(aa.bar())", source);
+ SimpleName simpleName = methodInvocation.getName();
+ checkSourceRange(simpleName, "size", source);
+ checkSourceRange(expression, "(aa.bar()).size()", source);
+ checkSourceRange(expressionStatement, "(aa.bar()).size();", source);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=62463
+ */
+ public void test0557() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0557", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 1, 0);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertEquals("Not an method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ checkSourceRange(expression2, "(aa.bar())", source);
+ SimpleName simpleName = methodInvocation.getName();
+ checkSourceRange(simpleName, "get", source);
+ checkSourceRange(expression, "(aa.bar()).get(0)", source);
+ checkSourceRange(expressionStatement, "(aa.bar()).get(0);", source);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=65090
+ * @deprecated using deprecated code
+ */
+ public void test0558() {
+ String src = "\tSystem.out.println(\"Hello\");\n\tSystem.out.println(\"World\");\n";
+ char[] source = src.toCharArray();
+ ASTParser parser = ASTParser.newParser(AST.JLS2);
+ parser.setKind (ASTParser.K_STATEMENTS);
+ parser.setSource (source);
+ ASTNode result = parser.createAST (null);
+ assertNotNull("no result", result);
+ assertEquals("Wrong type", ASTNode.BLOCK, result.getNodeType());
+ Block block = (Block) result;
+ List statements = block.statements();
+ assertNotNull("No statements", statements);
+ assertEquals("Wrong size", 2, statements.size());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=65562
+ */
+ public void test0559() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0559", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Wrong type", ASTNode.IF_STATEMENT, node.getNodeType());
+ IfStatement ifStatement = (IfStatement) node;
+ Expression expression = ifStatement.getExpression();
+ assertEquals("Wrong type", ASTNode.INFIX_EXPRESSION, expression.getNodeType());
+ InfixExpression infixExpression = (InfixExpression) expression;
+ Expression expression2 = infixExpression.getLeftOperand();
+ assertEquals("Wrong type", ASTNode.METHOD_INVOCATION, expression2.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression2;
+ Expression expression3 = methodInvocation.getExpression();
+ assertEquals("Wrong type", ASTNode.PARENTHESIZED_EXPRESSION, expression3.getNodeType());
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression3;
+ Expression expression4 = parenthesizedExpression.getExpression();
+ assertEquals("Wrong type", ASTNode.STRING_LITERAL, expression4.getNodeType());
+ checkSourceRange(expression4, "\" \"", source);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=65562
+ */
+ public void test0560() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0560", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Wrong type", ASTNode.IF_STATEMENT, node.getNodeType());
+ IfStatement ifStatement = (IfStatement) node;
+ Expression expression = ifStatement.getExpression();
+ assertEquals("Wrong type", ASTNode.INFIX_EXPRESSION, expression.getNodeType());
+ InfixExpression infixExpression = (InfixExpression) expression;
+ Expression expression2 = infixExpression.getLeftOperand();
+ assertEquals("Wrong type", ASTNode.METHOD_INVOCATION, expression2.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression2;
+ Expression expression3 = methodInvocation.getExpression();
+ assertEquals("Wrong type", ASTNode.PARENTHESIZED_EXPRESSION, expression3.getNodeType());
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression3;
+ Expression expression4 = parenthesizedExpression.getExpression();
+ assertEquals("Wrong type", ASTNode.STRING_LITERAL, expression4.getNodeType());
+ checkSourceRange(expression4, "\" \"", source);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=65562
+ */
+ public void test0561() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0561", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Wrong type", ASTNode.IF_STATEMENT, node.getNodeType());
+ IfStatement ifStatement = (IfStatement) node;
+ Expression expression = ifStatement.getExpression();
+ assertEquals("Wrong type", ASTNode.INFIX_EXPRESSION, expression.getNodeType());
+ InfixExpression infixExpression = (InfixExpression) expression;
+ Expression expression2 = infixExpression.getLeftOperand();
+ assertEquals("Wrong type", ASTNode.METHOD_INVOCATION, expression2.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression2;
+ Expression expression3 = methodInvocation.getExpression();
+ assertEquals("Wrong type", ASTNode.PARENTHESIZED_EXPRESSION, expression3.getNodeType());
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression3;
+ Expression expression4 = parenthesizedExpression.getExpression();
+ assertEquals("Wrong type", ASTNode.STRING_LITERAL, expression4.getNodeType());
+ checkSourceRange(expression4, "\" \"", source);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=65562
+ */
+ public void test0562() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0562", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Wrong type", ASTNode.IF_STATEMENT, node.getNodeType());
+ IfStatement ifStatement = (IfStatement) node;
+ Expression expression = ifStatement.getExpression();
+ assertEquals("Wrong type", ASTNode.INFIX_EXPRESSION, expression.getNodeType());
+ InfixExpression infixExpression = (InfixExpression) expression;
+ Expression expression2 = infixExpression.getLeftOperand();
+ assertEquals("Wrong type", ASTNode.METHOD_INVOCATION, expression2.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression2;
+ Expression expression3 = methodInvocation.getExpression();
+ assertEquals("Wrong type", ASTNode.PARENTHESIZED_EXPRESSION, expression3.getNodeType());
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression3;
+ Expression expression4 = parenthesizedExpression.getExpression();
+ assertEquals("Wrong type", ASTNode.STRING_LITERAL, expression4.getNodeType());
+ checkSourceRange(expression4, "\" \"", source);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=65562
+ */
+ public void test0563() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0563", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Wrong type", ASTNode.IF_STATEMENT, node.getNodeType());
+ IfStatement ifStatement = (IfStatement) node;
+ Expression expression = ifStatement.getExpression();
+ assertEquals("Wrong type", ASTNode.INFIX_EXPRESSION, expression.getNodeType());
+ InfixExpression infixExpression = (InfixExpression) expression;
+ Expression expression2 = infixExpression.getLeftOperand();
+ assertEquals("Wrong type", ASTNode.METHOD_INVOCATION, expression2.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression2;
+ Expression expression3 = methodInvocation.getExpression();
+ assertEquals("Wrong type", ASTNode.PARENTHESIZED_EXPRESSION, expression3.getNodeType());
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression3;
+ Expression expression4 = parenthesizedExpression.getExpression();
+ checkSourceRange(expression4, "new String()", source);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=65562
+ */
+ public void test0564() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0564", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Wrong type", ASTNode.IF_STATEMENT, node.getNodeType());
+ IfStatement ifStatement = (IfStatement) node;
+ Expression expression = ifStatement.getExpression();
+ assertEquals("Wrong type", ASTNode.INFIX_EXPRESSION, expression.getNodeType());
+ InfixExpression infixExpression = (InfixExpression) expression;
+ Expression expression2 = infixExpression.getLeftOperand();
+ assertEquals("Wrong type", ASTNode.METHOD_INVOCATION, expression2.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression2;
+ Expression expression3 = methodInvocation.getExpression();
+ assertEquals("Wrong type", ASTNode.PARENTHESIZED_EXPRESSION, expression3.getNodeType());
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression3;
+ Expression expression4 = parenthesizedExpression.getExpression();
+ checkSourceRange(expression4, "new String()", source);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=65562
+ */
+ public void test0565() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0565", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Wrong type", ASTNode.IF_STATEMENT, node.getNodeType());
+ IfStatement ifStatement = (IfStatement) node;
+ Expression expression = ifStatement.getExpression();
+ assertEquals("Wrong type", ASTNode.INFIX_EXPRESSION, expression.getNodeType());
+ InfixExpression infixExpression = (InfixExpression) expression;
+ Expression expression2 = infixExpression.getLeftOperand();
+ assertEquals("Wrong type", ASTNode.METHOD_INVOCATION, expression2.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression2;
+ Expression expression3 = methodInvocation.getExpression();
+ assertEquals("Wrong type", ASTNode.PARENTHESIZED_EXPRESSION, expression3.getNodeType());
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression3;
+ Expression expression4 = parenthesizedExpression.getExpression();
+ checkSourceRange(expression4, "(/**/ String /**/) new String()", source);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=69349
+ */
+ public void test0566() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0566", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertEquals("Wrong type", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ assertEquals("Wrong character", '}', source[node.getStartPosition() + node.getLength() - 1]);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=69349
+ */
+ public void test0567() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0567", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertEquals("Wrong type", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ assertEquals("Wrong character", '}', source[node.getStartPosition() + node.getLength() - 1]);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=74369
+ * @deprecated using deprecated code
+ */
+ public void test0569() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0569", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0, 1);
+ assertEquals("not a type declaration statement", ASTNode.TYPE_DECLARATION_STATEMENT, node.getNodeType()); //$NON-NLS-1$
+ TypeDeclarationStatement typeDeclarationStatement = (TypeDeclarationStatement) node;
+ TypeDeclaration typeDeclaration = typeDeclarationStatement.getTypeDeclaration();
+ assertEquals("wrong name", "Local", typeDeclaration.getName().getIdentifier());
+ assertNull("Got a javadoc", typeDeclaration.getJavadoc());
+ node = getASTNode(unit, 0);
+ assertEquals("not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType()); //$NON-NLS-1$
+ typeDeclaration = (TypeDeclaration) node;
+ assertEquals("wrong name", "A", typeDeclaration.getName().getIdentifier());
+ assertNotNull("No javadoc", typeDeclaration.getJavadoc());
+ node = getASTNode(unit, 0, 0);
+ assertEquals("not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType()); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("wrong name", "method", methodDeclaration.getName().getIdentifier());
+ assertNotNull("No javadoc", methodDeclaration.getJavadoc());
+ }
+
+ /*
+ * Ensures that the type binding from an import and the type binding from a type ref are equals
+ * when the AST is computed using ICompilationUnit#reconcile(...)
+ * (regression test for bug 83210 Unidentical ITypeBindings for same type from same AST from reconcile)
+ */
+ public void test0570() throws CoreException {
+ ICompilationUnit workingCopy = null;
+ try {
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true);
+ CompilationUnit unit = (CompilationUnit) buildAST(
+ "import java.util.List;\n" +
+ "public class X{\n" +
+ " List field;\n" +
+ "}",
+ workingCopy
+ );
+ ImportDeclaration importDeclaration = (ImportDeclaration) unit.imports().iterator().next();
+ TypeDeclaration typeDeclaration = (TypeDeclaration) unit.types().iterator().next();
+ FieldDeclaration fieldDeclaration = typeDeclaration.getFields()[0];
+ Type type = fieldDeclaration.getType();
+ IBinding importBinding = importDeclaration.resolveBinding();
+ IBinding typeBinding = type.resolveBinding();
+ assertEquals(importBinding,typeBinding);
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * Ensures that the bindings for a member type in a .class file can be created.
+ */
+ public void test0571() throws CoreException, IOException {
+ try {
+ IJavaProject p = createJavaProject("P", new String[] {""}, new String[] {"CONVERTER_JCL_LIB"}, "");
+ String source =
+ "public class X {\n" +
+ " public class Y {\n" +
+ " }\n" +
+ "}";
+ addLibrary(p, "test0571.jar", "test0571.zip", new String[] {"X.java", source }, "1.4");
+ IClassFile classFile = getClassFile("P", "/P/test0571.jar", "", "X$Y.class");
+ CompilationUnit unit = (CompilationUnit) runConversion(AST.JLS3, classFile, 0, true);
+ IProblem[] problems = unit.getProblems();
+ StringBuffer buffer = new StringBuffer();
+ for (int i = 0, length = problems.length; i < length; i++)
+ Util.appendProblem(buffer, problems[i], source.toCharArray(), i);
+ assertEquals("Unexpected problems", "", buffer.toString());
+ } finally {
+ deleteProject("P");
+ }
+ }
+
+ /*
+ * Ensures that the method bindings of an anonymous type are correct.
+ */
+ public void test0572() throws CoreException {
+ ICompilationUnit workingCopy = null;
+ try {
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ AnonymousClassDeclaration type = (AnonymousClassDeclaration) buildAST(
+ "public class X {\n" +
+ " void foo() {\n" +
+ " new X() /*start*/{\n" +
+ " void bar() {}\n" +
+ " }/*end*/;\n" +
+ " }\n" +
+ "}",
+ workingCopy);
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertBindingsEqual(
+ "LX$40;.(LX;)V\n" +
+ "LX$40;.bar()V",
+ typeBinding.getDeclaredMethods());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * Ensures that the Java element of a compilation is correct.
+ */
+ public void test0573() throws CoreException {
+ ICompilationUnit workingCopy = null;
+ try {
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ CompilationUnit cu = (CompilationUnit) buildAST(
+ "public class X {\n" +
+ "}",
+ workingCopy);
+ assertElementEquals("Unexpected Java element", "[Working copy] X.java [in <default> [in src [in Converter]]]", cu.getJavaElement());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+ /*
+ * Ensures that strings are not optimized when creating the AST through a reconcile.
+ * (regression test for bug 82830 AST: String concatenation represented as single node)
+ */
+ public void test0574() throws CoreException {
+ ICompilationUnit workingCopy = null;
+ try {
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode string = buildAST(
+ "public class X {\n" +
+ " String s = /*start*/\"a\" + \"b\"/*end*/;\n" +
+ "}",
+ workingCopy);
+ assertEquals("Unexpected node type", ASTNode.INFIX_EXPRESSION, string.getNodeType());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * Ensures that 2 different method bindings with the same return type are not "isEqualTo(...)".
+ * (regression test for bug 99978 MalformedTreeException on Inline Method)
+ */
+ public void test0575() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " /*start1*/String foo(String o) {return null;}/*end1*/\n" +
+ " /*start2*/String foo(Object o) {return null;}/*end2*/\n" +
+ "}";
+ IBinding[] firstBatch = resolveBindings(contents, workingCopy);
+ IBinding[] secondBatch = resolveBindings(contents, workingCopy);
+ assertTrue("2 different method type bindings should not be equals", !firstBatch[0].isEqualTo(secondBatch[1]));
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * Ensures that the binding key of a raw member type is correct.
+ * (regression test for bug 100549 Strange binding keys from AST on class file of nested type)
+ */
+ public void test0576() throws CoreException, IOException {
+ try {
+ IJavaProject project = createJavaProject("P1", new String[] {""}, new String[] {"CONVERTER_JCL15_LIB"}, "", "1.5");
+ addLibrary(project, "lib.jar", "src.zip", new String[] {
+ "/P1/p/X.java",
+ "package p;\n" +
+ "public class X<T> {\n" +
+ " /*start*/public class Member {\n" +
+ " }/*end*/\n" +
+ "}",
+ }, "1.5");
+ IClassFile classFile = getClassFile("P1", "/P1/lib.jar", "p", "X$Member.class");
+ ASTNode node = buildAST(classFile);
+ ITypeBinding binding = ((TypeDeclaration) node).resolveBinding();
+ assertBindingKeyEquals("Lp/X<TT;>.Member;", binding.getKey());
+ } finally {
+ deleteProject("P1");
+ }
+ }
+
+ /*
+ * Ensures that strings are not optimized when creating the AST through a reconcile
+ * even if the working copy was consistent.
+ * (regression test for bug 114909 AST: String concatenation represented as single node)
+ */
+ public void test0577() throws CoreException {
+ ICompilationUnit workingCopy = null;
+ try {
+ workingCopy = getWorkingCopy(
+ "/Converter/src/X.java",
+ "public class X {\n" +
+ " String s = /*start*/\"a\" + \"b\"/*end*/;\n" +
+ "}",
+ true/*resolve*/);
+ ASTNode string = buildAST(workingCopy);
+ assertEquals("Unexpected node type", ASTNode.INFIX_EXPRESSION, string.getNodeType());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * Ensures that bindings are created when reconciling an external working copy.
+ */
+ public void test0578() throws CoreException {
+ ICompilationUnit workingCopy = null;
+ try {
+ IClasspathEntry[] classpath = new IClasspathEntry[] {JavaCore.newLibraryEntry(getConverterJCLPath(), null, null)};
+ workingCopy = newExternalWorkingCopy("External.java", classpath, new ProblemRequestor(), "");
+
+ String contents =
+ "public class External {\n"+
+ " /*start*/String foo(){\n"+
+ " return \"\";\n" +
+ " }/*end*/\n"+
+ "}\n";
+ IBinding methodBinding = resolveBindings(contents, workingCopy)[0];
+ assertBindingEquals(
+ "LExternal;.foo()Ljava/lang/String;",
+ methodBinding);
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * Ensures that the start position of an argument that has a previous sibbling with a comment is correct
+ * (regression test for bug 80904 Quick Fix "Assign parameter to new field" doesn't appear with commented type)
+ */
+ public void test0579() throws CoreException {
+ ICompilationUnit workingCopy = null;
+ try {
+ workingCopy = getWorkingCopy(
+ "/Converter/src/X.java",
+ "public class X {\n" +
+ " /*start*/void foo(Object/*first arg*/ arg1, Object arg2) {\n" +
+ " }/*end*/\n" +
+ "}",
+ true/*resolve*/);
+ MethodDeclaration method = (MethodDeclaration) buildAST(workingCopy);
+ SingleVariableDeclaration arg2 = (SingleVariableDeclaration) method.parameters().get(1);
+ int start = arg2.getStartPosition();
+ assertEquals("Unexpected range for arg2", "Object arg2", workingCopy.getSource().substring(start, start+arg2.getLength()));
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ public void test0606() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0606", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertProblemsSize(unit, 0);
+ unit.accept(new ASTVisitor() {
+ public boolean visit(MethodDeclaration methodDeclaration) {
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ IJavaElement javaElement = methodBinding.getJavaElement();
+ assertNotNull("No java element", javaElement);
+ return false;
+ }
+ });
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=173853
+ */
+ public void test0607() throws CoreException {
+ ICompilationUnit workingCopy = null;
+ try {
+ workingCopy = getWorkingCopy(
+ "/Converter/src/X.java",
+ "public class X {\n" +
+ " void foo() {\n" +
+ " #\n" +
+ " /*start*/new Object() {\n" +
+ " }/*end*/;\n" +
+ " }\n" +
+ "}",
+ true/*resolve*/);
+ ASTNode string = buildAST(null, workingCopy, false, true);
+ assertEquals("Unexpected node type", ASTNode.CLASS_INSTANCE_CREATION, string.getNodeType());
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) string;
+ ITypeBinding resolveTypeBinding = classInstanceCreation.resolveTypeBinding();
+ assertNotNull("Binding is null", resolveTypeBinding);
+ IMethodBinding[] declaredMethods = resolveTypeBinding.getDeclaredMethods();
+ assertNotNull("Should have one method", declaredMethods);
+ assertEquals("Should have one method", 1, declaredMethods.length);
+ assertTrue("The method should be a default constructor", declaredMethods[0].isDefaultConstructor());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+
+ /*
+ * Ensures that no exception is thrown in case of a syntax error in a for statement
+ * (regression test for bug 199668 IAE in ASTNode.setSourceRange while editing a class)
+ */
+ public void test0608() throws CoreException {
+ ICompilationUnit workingCopy = null;
+ try {
+ workingCopy = getWorkingCopy(
+ "/Converter/src/X.java",
+ "public class X {\n" +
+ " void foo() {\n" +
+ " for (int i=0,; i<10; i++) {\n" +
+ " }\n" +
+ " }\n" +
+ "}"
+ );
+ ASTNode node = buildAST(null, workingCopy, false, true);
+ assertNotNull("Should get an AST", node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ node = getASTNode((CompilationUnit) node, 0, 0, 0);
+ assertEquals("Not a for statement", ASTNode.FOR_STATEMENT, node.getNodeType());
+ ForStatement forStatement = (ForStatement) node;
+ List initializers = forStatement.initializers();
+ assertEquals("Wrong size", 1, initializers.size());
+ VariableDeclarationExpression expression = (VariableDeclarationExpression) initializers.get(0);
+ List fragments = expression.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ assertEquals("Wrong name", "i", fragment.getName().getIdentifier());
+ assertTrue("Should be a recovered fragment", isRecovered(expression));
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * Ensures that no exception is thrown in case of a syntax error in method parameter declarations
+ * (regression test for bug 200080 Endless illegal arg exceptions from java editor's ASTProvider)
+ */
+ public void test0609() throws CoreException {
+ ICompilationUnit workingCopy = null;
+ try {
+ workingCopy = getWorkingCopy(
+ "/Converter/src/X.java",
+ "public class X {\n" +
+ " void foo(a, b, ) {\n" +
+ " if\n" +
+ " }\n" +
+ "}"
+ );
+ ASTNode cu = workingCopy.reconcile(AST.JLS3, true, true, null, null);
+ assertNotNull("Should get an AST", cu);
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=270446. NPE while building abridged AST
+ public void test0610() throws CoreException {
+ ICompilationUnit workingCopy = null;
+ try {
+ workingCopy = getWorkingCopy(
+ "/Converter/src/X.java",
+ "public class X {\n" +
+ " private class B {\n" +
+ " public B() {\n" +
+ " }\n" +
+ " }\n" +
+ " public X() {\n" +
+ " }\n" +
+ " }\n"
+ );
+
+ // Create parser
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setSource(workingCopy);
+ parser.setFocalPosition(0);
+ parser.setResolveBindings(true);
+
+ ASTNode result = parser.createAST(null);
+ assertNotNull("Should get an AST", result);
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+}
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
new file mode 100644
index 0000000..9237c91
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTConverterTestAST3_2.java
@@ -0,0 +1,10499 @@
+/*******************************************************************************
+ * 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.jdt.core.tests.dom;
+
+import java.util.ArrayList;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import junit.framework.Test;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.jdt.core.Flags;
+import org.eclipse.jdt.core.IClassFile;
+import org.eclipse.jdt.core.IClasspathEntry;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IField;
+import org.eclipse.jdt.core.IInitializer;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IJavaProject;
+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;
+import org.eclipse.jdt.core.compiler.IProblem;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTMatcher;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.ASTParser;
+import org.eclipse.jdt.core.dom.ASTRequestor;
+import org.eclipse.jdt.core.dom.ASTVisitor;
+import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
+import org.eclipse.jdt.core.dom.AnnotationTypeDeclaration;
+import org.eclipse.jdt.core.dom.AnonymousClassDeclaration;
+import org.eclipse.jdt.core.dom.ArrayCreation;
+import org.eclipse.jdt.core.dom.ArrayInitializer;
+import org.eclipse.jdt.core.dom.ArrayType;
+import org.eclipse.jdt.core.dom.AssertStatement;
+import org.eclipse.jdt.core.dom.Assignment;
+import org.eclipse.jdt.core.dom.Block;
+import org.eclipse.jdt.core.dom.BodyDeclaration;
+import org.eclipse.jdt.core.dom.CastExpression;
+import org.eclipse.jdt.core.dom.CatchClause;
+import org.eclipse.jdt.core.dom.CharacterLiteral;
+import org.eclipse.jdt.core.dom.ClassInstanceCreation;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.ConditionalExpression;
+import org.eclipse.jdt.core.dom.ConstructorInvocation;
+import org.eclipse.jdt.core.dom.EnumDeclaration;
+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.FieldDeclaration;
+import org.eclipse.jdt.core.dom.ForStatement;
+import org.eclipse.jdt.core.dom.IBinding;
+import org.eclipse.jdt.core.dom.IMethodBinding;
+import org.eclipse.jdt.core.dom.IPackageBinding;
+import org.eclipse.jdt.core.dom.ITypeBinding;
+import org.eclipse.jdt.core.dom.IVariableBinding;
+import org.eclipse.jdt.core.dom.IfStatement;
+import org.eclipse.jdt.core.dom.ImportDeclaration;
+import org.eclipse.jdt.core.dom.InfixExpression;
+import org.eclipse.jdt.core.dom.Initializer;
+import org.eclipse.jdt.core.dom.InstanceofExpression;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.MethodInvocation;
+import org.eclipse.jdt.core.dom.Modifier;
+import org.eclipse.jdt.core.dom.Name;
+import org.eclipse.jdt.core.dom.NullLiteral;
+import org.eclipse.jdt.core.dom.NumberLiteral;
+import org.eclipse.jdt.core.dom.PackageDeclaration;
+import org.eclipse.jdt.core.dom.ParenthesizedExpression;
+import org.eclipse.jdt.core.dom.PrimitiveType;
+import org.eclipse.jdt.core.dom.QualifiedName;
+import org.eclipse.jdt.core.dom.ReturnStatement;
+import org.eclipse.jdt.core.dom.SimpleName;
+import org.eclipse.jdt.core.dom.SimpleType;
+import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
+import org.eclipse.jdt.core.dom.Statement;
+import org.eclipse.jdt.core.dom.StringLiteral;
+import org.eclipse.jdt.core.dom.SuperFieldAccess;
+import org.eclipse.jdt.core.dom.SuperMethodInvocation;
+import org.eclipse.jdt.core.dom.SwitchCase;
+import org.eclipse.jdt.core.dom.SwitchStatement;
+import org.eclipse.jdt.core.dom.TryStatement;
+import org.eclipse.jdt.core.dom.Type;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
+import org.eclipse.jdt.core.dom.TypeDeclarationStatement;
+import org.eclipse.jdt.core.dom.VariableDeclarationExpression;
+import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
+import org.eclipse.jdt.core.dom.VariableDeclarationStatement;
+import org.eclipse.jdt.core.dom.WhileStatement;
+import org.eclipse.jdt.core.tests.model.CancelCounter;
+import org.eclipse.jdt.core.tests.model.Canceler;
+import org.eclipse.jdt.core.tests.model.ReconcilerTests;
+import org.eclipse.jdt.core.tests.util.Util;
+
+public class ASTConverterTestAST3_2 extends ConverterTestSetup {
+
+ public void setUpSuite() throws Exception {
+ super.setUpSuite();
+ this.ast = AST.newAST(AST.JLS3);
+ }
+
+ public ASTConverterTestAST3_2(String name) {
+ super(name);
+ }
+
+ static {
+// TESTS_NAMES = new String[] {"test0602"};
+// TESTS_RANGE = new int[] { 713, -1 };
+// TESTS_NUMBERS = new int[] { 718 };
+ }
+ public static Test suite() {
+ return buildModelTestSuite(ASTConverterTestAST3_2.class);
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=22560
+ */
+ public void test0401() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0401", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("wrong size", 1, statements.size()); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(0);
+ assertTrue("Not a return statement", statement.getNodeType() == ASTNode.RETURN_STATEMENT); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) statement;
+ Expression expression = returnStatement.getExpression();
+ assertNotNull("there is no expression", expression); //$NON-NLS-1$
+ // call the default initialization
+ methodDeclaration.getReturnType2();
+ ITypeBinding typeBinding = expression.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("wrong name", "int", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23464
+ */
+ public void test0402() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0402", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 1, 0, 0);
+ assertEquals("Wrong number of problems", 0, ((CompilationUnit) result).getProblems().length); //$NON-NLS-1$
+ assertNotNull(node);
+ assertTrue("Not a super method invocation", node.getNodeType() == ASTNode.SUPER_CONSTRUCTOR_INVOCATION); //$NON-NLS-1$
+ checkSourceRange(node, "new A().super();", source); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23597
+ */
+ public void test0403() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0403", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 1, 0, 1);
+ assertEquals("Wrong number of problems", 1, ((CompilationUnit) result).getProblems().length); //$NON-NLS-1$
+ assertNotNull(node);
+ assertTrue("Not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ assertTrue("Not a simple name", expression2.getNodeType() == ASTNode.SIMPLE_NAME); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) expression2;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("wrong type", binding.getKind() == IBinding.VARIABLE); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Wrong name", "test", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ SimpleName simpleName2 = methodInvocation.getName();
+ assertEquals("Wrong name", "clone", simpleName2.getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding2 = simpleName2.resolveBinding();
+ assertNotNull("no binding2", binding2); //$NON-NLS-1$
+ assertTrue("Wrong type", binding2.getKind() == IBinding.METHOD); //$NON-NLS-1$
+ IMethodBinding methodBinding = (IMethodBinding) binding2;
+ assertEquals("Wrong name", "clone", methodBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ IMethodBinding methodBinding2 = methodInvocation.resolveMethodBinding();
+ assertNotNull("No method binding2", methodBinding2);
+ assertTrue("Wrong binding", methodBinding == methodBinding2);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23597
+ */
+ public void test0404() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0404", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertEquals("Wrong number of problems", 1, ((CompilationUnit) result).getProblems().length); //$NON-NLS-1$
+ assertNotNull(node);
+ assertTrue("Not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ assertTrue("Not a simple name", expression2.getNodeType() == ASTNode.SIMPLE_NAME); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) expression2;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("wrong type", binding.getKind() == IBinding.VARIABLE); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Wrong name", "a", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ SimpleName simpleName2 = methodInvocation.getName();
+ assertEquals("Wrong name", "clone", simpleName2.getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding2 = simpleName2.resolveBinding();
+ assertNotNull("no binding2", binding2); //$NON-NLS-1$
+ assertTrue("Wrong type", binding2.getKind() == IBinding.METHOD); //$NON-NLS-1$
+ IMethodBinding methodBinding = (IMethodBinding) binding2;
+ assertEquals("Wrong name", "clone", methodBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23597
+ */
+ public void test0405() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0405", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ ASTNode node = getASTNode((CompilationUnit) result, 1, 0, 1);
+ assertEquals("Wrong number of problems", 1, ((CompilationUnit) result).getProblems().length); //$NON-NLS-1$
+ assertNotNull(node);
+ assertTrue("Not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ assertTrue("Not a simple name", expression2.getNodeType() == ASTNode.SIMPLE_NAME); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) expression2;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("wrong type", binding.getKind() == IBinding.VARIABLE); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Wrong name", "a", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ SimpleName simpleName2 = methodInvocation.getName();
+ assertEquals("Wrong name", "clone", simpleName2.getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding2 = simpleName2.resolveBinding();
+ assertNotNull("no binding2", binding2); //$NON-NLS-1$
+ assertTrue("Wrong type", binding2.getKind() == IBinding.METHOD); //$NON-NLS-1$
+ IMethodBinding methodBinding = (IMethodBinding) binding2;
+ assertEquals("Wrong name", "clone", methodBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23597
+ */
+ public void test0406() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0406", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ CompilationUnit unit = (CompilationUnit) result;
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 1);
+ assertEquals("Wrong number of problems", 1, ((CompilationUnit) result).getProblems().length); //$NON-NLS-1$
+ assertNotNull(node);
+ assertTrue("Not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ assertTrue("Not a simple name", expression2.getNodeType() == ASTNode.SIMPLE_NAME); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) expression2;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("wrong type", binding.getKind() == IBinding.VARIABLE); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Wrong name", "a", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ SimpleName simpleName2 = methodInvocation.getName();
+ assertEquals("Wrong name", "foo", simpleName2.getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding2 = simpleName2.resolveBinding();
+ assertNotNull("no binding2", binding2); //$NON-NLS-1$
+ assertTrue("Wrong type", binding2.getKind() == IBinding.METHOD); //$NON-NLS-1$
+ IMethodBinding methodBinding = (IMethodBinding) binding2;
+ assertEquals("Wrong name", "foo", methodBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertNull("Got a declaring node in the unit", unit.findDeclaringNode(methodBinding));
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23162
+ */
+ public void test0407() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0407", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("Wrong number of problems", 0, ((CompilationUnit) result).getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ CompilationUnit unit = (CompilationUnit) result;
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ SimpleName simpleName = methodDeclaration.getName();
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("Not a method binding", binding.getKind() == IBinding.METHOD); //$NON-NLS-1$
+ IMethodBinding methodBinding = (IMethodBinding) binding;
+ assertEquals("wrong name", "foo", methodBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ methodDeclaration.setName(methodDeclaration.getAST().newSimpleName("foo2")); //$NON-NLS-1$
+ IMethodBinding methodBinding2 = methodDeclaration.resolveBinding();
+ assertNotNull("No methodbinding2", methodBinding2); //$NON-NLS-1$
+ assertEquals("wrong name", "foo", methodBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ simpleName = methodDeclaration.getName();
+ IBinding binding2 = simpleName.resolveBinding();
+ assertNull("Got a binding2", binding2); //$NON-NLS-1$
+
+ ASTNode astNode = unit.findDeclaringNode(methodBinding);
+ assertNotNull("No declaring node", astNode);
+ assertEquals("wrong declaring node", methodDeclaration, astNode);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23162
+ */
+ public void test0408() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0408", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("Wrong number of problems", 0, ((CompilationUnit) result).getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Type type = methodDeclaration.getReturnType2();
+ assertTrue("Not a simple type", type.isSimpleType()); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type;
+ Name name = simpleType.getName();
+ assertTrue("Not a qualified name", name.isQualifiedName()); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) name;
+ name = qualifiedName.getQualifier();
+ assertTrue("Not a qualified name", name.isQualifiedName()); //$NON-NLS-1$
+ qualifiedName = (QualifiedName) name;
+ name = qualifiedName.getQualifier();
+ assertTrue("Not a simple name", name.isSimpleName()); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) name;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("Not a package binding", binding.getKind() == IBinding.PACKAGE); //$NON-NLS-1$
+ assertEquals("Wrong name", "java", binding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=23162
+ */
+ public void test0409() throws JavaModelException {
+ Hashtable options = JavaCore.getOptions();
+ Hashtable newOptions = JavaCore.getOptions();
+ try {
+ newOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4);
+ JavaCore.setOptions(newOptions);
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0409", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ BindingsCollectorVisitor bindingsCollectorVisitor = new BindingsCollectorVisitor();
+ compilationUnit.accept(bindingsCollectorVisitor);
+ assertEquals("wrong number", 3, bindingsCollectorVisitor.getUnresolvedNodesSet().size()); //$NON-NLS-1$
+ Map bindingsMap = bindingsCollectorVisitor.getBindingsMap();
+ assertEquals("wrong number", 211, bindingsMap.size()); //$NON-NLS-1$
+ ASTNodesCollectorVisitor nodesCollector = new ASTNodesCollectorVisitor();
+ compilationUnit.accept(nodesCollector);
+ Set detachedNodes = nodesCollector.getDetachedAstNodes();
+ int counter = 0;
+ for (Iterator iterator = detachedNodes.iterator(); iterator.hasNext(); ) {
+ ASTNode detachedNode = (ASTNode) iterator.next();
+ counter++;
+ IBinding binding = (IBinding) bindingsMap.get(detachedNode);
+ assertNotNull(binding);
+ switch(detachedNode.getNodeType()) {
+ case ASTNode.ARRAY_ACCESS :
+ case ASTNode.ARRAY_CREATION :
+ case ASTNode.ARRAY_INITIALIZER :
+ case ASTNode.ASSIGNMENT :
+ case ASTNode.BOOLEAN_LITERAL :
+ case ASTNode.CAST_EXPRESSION :
+ case ASTNode.CHARACTER_LITERAL :
+ case ASTNode.CLASS_INSTANCE_CREATION :
+ case ASTNode.CONDITIONAL_EXPRESSION :
+ case ASTNode.FIELD_ACCESS :
+ case ASTNode.INFIX_EXPRESSION :
+ case ASTNode.INSTANCEOF_EXPRESSION :
+ case ASTNode.METHOD_INVOCATION :
+ case ASTNode.NULL_LITERAL :
+ case ASTNode.NUMBER_LITERAL :
+ case ASTNode.POSTFIX_EXPRESSION :
+ case ASTNode.PREFIX_EXPRESSION :
+ case ASTNode.THIS_EXPRESSION :
+ case ASTNode.TYPE_LITERAL :
+ case ASTNode.VARIABLE_DECLARATION_EXPRESSION :
+ ITypeBinding typeBinding = ((Expression) detachedNode).resolveTypeBinding();
+ if (!binding.equals(typeBinding)) {
+ System.out.println(detachedNode);
+ }
+ assertTrue("binding not equals", binding.equals(typeBinding)); //$NON-NLS-1$
+ break;
+ case ASTNode.VARIABLE_DECLARATION_FRAGMENT :
+ assertTrue("binding not equals", binding.equals(((VariableDeclarationFragment) detachedNode).resolveBinding())); //$NON-NLS-1$
+ break;
+ case ASTNode.ANONYMOUS_CLASS_DECLARATION :
+ assertTrue("binding not equals", binding.equals(((AnonymousClassDeclaration) detachedNode).resolveBinding())); //$NON-NLS-1$
+ break;
+ case ASTNode.QUALIFIED_NAME :
+ case ASTNode.SIMPLE_NAME :
+ IBinding newBinding = ((Name) detachedNode).resolveBinding();
+ assertTrue("binding not equals", binding.equals(newBinding)); //$NON-NLS-1$
+ break;
+ case ASTNode.ARRAY_TYPE :
+ case ASTNode.SIMPLE_TYPE :
+ case ASTNode.PRIMITIVE_TYPE :
+ assertTrue("binding not equals", binding.equals(((Type) detachedNode).resolveBinding())); //$NON-NLS-1$
+ break;
+ case ASTNode.CONSTRUCTOR_INVOCATION :
+ assertTrue("binding not equals", binding.equals(((ConstructorInvocation) detachedNode).resolveConstructorBinding())); //$NON-NLS-1$
+ break;
+ case ASTNode.IMPORT_DECLARATION :
+ assertTrue("binding not equals", binding.equals(((ImportDeclaration) detachedNode).resolveBinding())); //$NON-NLS-1$
+ break;
+ case ASTNode.METHOD_DECLARATION :
+ assertTrue("binding not equals", binding.equals(((MethodDeclaration) detachedNode).resolveBinding())); //$NON-NLS-1$
+ break;
+ case ASTNode.PACKAGE_DECLARATION :
+ assertTrue("binding not equals", binding.equals(((PackageDeclaration) detachedNode).resolveBinding())); //$NON-NLS-1$
+ break;
+ case ASTNode.TYPE_DECLARATION :
+ assertTrue("binding not equals", binding.equals(((TypeDeclaration) detachedNode).resolveBinding())); //$NON-NLS-1$
+ break;
+ }
+ }
+ } finally {
+ JavaCore.setOptions(options);
+ }
+ }
+
+ /**
+ * Test for message on jdt-core-dev
+ */
+ public void test0410() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0410", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("Wrong number of problems", 0, ((CompilationUnit) result).getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a return statement", node.getNodeType() == ASTNode.RETURN_STATEMENT); //$NON-NLS-1$
+ Expression expression = ((ReturnStatement) node).getExpression();
+ assertTrue("Not an infix expression", expression.getNodeType() == ASTNode.INFIX_EXPRESSION); //$NON-NLS-1$
+ InfixExpression infixExpression = (InfixExpression) expression;
+ List extendedOperands = infixExpression.extendedOperands();
+ assertEquals("wrong size", 3, extendedOperands.size()); //$NON-NLS-1$
+ }
+
+ /**
+ * Test for message on jdt-core-dev
+ */
+ public void test0411() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0411", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("Wrong number of problems", 0, ((CompilationUnit) result).getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a return statement", node.getNodeType() == ASTNode.RETURN_STATEMENT); //$NON-NLS-1$
+ Expression expression = ((ReturnStatement) node).getExpression();
+ assertTrue("Not an infix expression", expression.getNodeType() == ASTNode.INFIX_EXPRESSION); //$NON-NLS-1$
+ InfixExpression infixExpression = (InfixExpression) expression;
+ List extendedOperands = infixExpression.extendedOperands();
+ assertEquals("wrong size", 0, extendedOperands.size()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=23901
+ */
+ public void test0412() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0412", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0);
+ assertNotNull(node);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ assertTrue("Not an interface", typeDeclaration.isInterface()); //$NON-NLS-1$
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertNotNull("No declaring node", unit.findDeclaringNode(typeBinding)); //$NON-NLS-1$
+ Name name = typeDeclaration.getName();
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ ASTNode declaringNode = unit.findDeclaringNode(binding);
+ assertNotNull("No declaring node", declaringNode); //$NON-NLS-1$
+ assertEquals("Wrong node", typeDeclaration, declaringNode); //$NON-NLS-1$
+ typeBinding = name.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ declaringNode = unit.findDeclaringNode(typeBinding);
+ assertNotNull("No declaring node", declaringNode); //$NON-NLS-1$
+ assertEquals("Wrong node", typeDeclaration, declaringNode); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=20881
+ */
+ public void test0413() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0413", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true, false, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 1, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List throwsException = methodDeclaration.thrownExceptions();
+ assertEquals("wrong size", 2, throwsException.size()); //$NON-NLS-1$
+ Name name = (Name) throwsException.get(0);
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertEquals("LIOException;", binding.getKey());
+ assertTrue("Binding should be marked as recovered", binding.isRecovered());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=23734
+ */
+ public void test0414() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0414", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Type type = methodDeclaration.getReturnType2();
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ ASTNode declaringNode = unit.findDeclaringNode(typeBinding);
+ assertNull("Got a declaring node", declaringNode); //$NON-NLS-1$
+
+ node = getASTNode(unit, 0, 1);
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration2 = (MethodDeclaration) node;
+ Type type2 = methodDeclaration2.getReturnType2();
+ ITypeBinding typeBinding2 = type2.resolveBinding();
+ assertNotNull("No type binding", typeBinding2); //$NON-NLS-1$
+ ASTNode declaringNode2 = unit.findDeclaringNode(typeBinding2);
+ assertNotNull("No declaring node", declaringNode2); //$NON-NLS-1$
+
+ ICompilationUnit sourceUnit2 = getCompilationUnit("Converter" , "src", "test0414", "B.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+
+ result = runConversion(AST.JLS3, sourceUnit2, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit2 = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit2.getProblems().length); //$NON-NLS-1$
+ ASTNode declaringNode3 = unit2.findDeclaringNode(typeBinding);
+ assertNull("Got a declaring node", declaringNode3); //$NON-NLS-1$
+
+ ASTNode declaringNode4 = unit2.findDeclaringNode(typeBinding.getKey());
+ assertNotNull("No declaring node", declaringNode4); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24268
+ */
+ public void test0415() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0415", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a switch statement", node.getNodeType() == ASTNode.SWITCH_STATEMENT); //$NON-NLS-1$
+ SwitchStatement switchStatement = (SwitchStatement) node;
+ List statements = switchStatement.statements();
+ assertEquals("wrong size", statements.size(), 5); //$NON-NLS-1$
+ Statement statement = (Statement) statements.get(3);
+ assertTrue("not a switch case (default)", statement.getNodeType() == ASTNode.SWITCH_CASE); //$NON-NLS-1$
+ SwitchCase defaultCase = (SwitchCase) statement;
+ assertTrue("not a default case", defaultCase.isDefault());
+ checkSourceRange(defaultCase, "default:", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24324
+ */
+ public void test0416() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0416", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 1, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", fragments.size(), 1);
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression init = fragment.getInitializer();
+ assertTrue("not a qualified name", init.getNodeType() == ASTNode.QUALIFIED_NAME); //$NON-NLS-1$
+ QualifiedName qualifiedName = (QualifiedName) init;
+ SimpleName simpleName = qualifiedName.getName();
+ assertEquals("Wrong name", "CONST", simpleName.getIdentifier());
+ IBinding binding = simpleName.resolveBinding();
+ assertEquals("Wrong type", IBinding.VARIABLE, binding.getKind());
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Wrong modifier", variableBinding.getModifiers(), Modifier.PUBLIC | Modifier.STATIC | Modifier.FINAL);
+ ASTNode declaringNode = unit.findDeclaringNode(variableBinding);
+ assertNotNull("No declaring node", declaringNode);
+ assertTrue("not a variable declaration fragment", declaringNode.getNodeType() == ASTNode.VARIABLE_DECLARATION_FRAGMENT);
+ VariableDeclarationFragment variableDeclarationFragment = (VariableDeclarationFragment) declaringNode;
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) variableDeclarationFragment.getParent();
+ assertEquals("Wrong modifier", fieldDeclaration.getModifiers(), Modifier.NONE);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24347
+ */
+ public void test0417() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0417", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ Type type = statement.getType();
+ assertTrue("not a simple type", type.getNodeType() == ASTNode.SIMPLE_TYPE); //$NON-NLS-1$
+ SimpleType simpleType = (SimpleType) type;
+ Name name = simpleType.getName();
+ assertTrue("Not a qualified name", name.isQualifiedName());
+ QualifiedName qualifiedName = (QualifiedName) name;
+ Name qualifier = qualifiedName.getQualifier();
+ assertTrue("Not a simple name", qualifier.isSimpleName());
+ IBinding binding = qualifier.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24406
+ */
+ public void test0418() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0418", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 1, 0);
+ assertNotNull("No node", node);
+ assertTrue("not an expression statement ", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("not an method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Name name = methodInvocation.getName();
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24449
+ */
+ public void test0419() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0419", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 1, 0, 0);
+ assertEquals("Not an expression statement", node.getNodeType(), ASTNode.EXPRESSION_STATEMENT);
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertEquals("Not an assignment", expression.getNodeType(), ASTNode.ASSIGNMENT);
+ Assignment assignment = (Assignment) expression;
+ Expression expression2 = assignment.getLeftHandSide();
+ assertEquals("Not a name", expression2.getNodeType(), ASTNode.SIMPLE_NAME);
+ SimpleName simpleName = (SimpleName) expression2;
+ IBinding binding = simpleName.resolveBinding();
+ assertNull(binding);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24453
+ */
+ public void test0420() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0420", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not an infix expression", expression.getNodeType(), ASTNode.INFIX_EXPRESSION);
+ InfixExpression infixExpression = (InfixExpression) expression;
+ Expression expression2 = infixExpression.getRightOperand();
+ assertEquals("Not a parenthesized expression", expression2.getNodeType(), ASTNode.PARENTHESIZED_EXPRESSION);
+ checkSourceRange(expression2, "(2 + 3)", source);
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression2;
+ Expression expression3 = parenthesizedExpression.getExpression();
+ checkSourceRange(expression3, "2 + 3", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24453
+ */
+ public void test0421() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0421", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not an infix expression", expression.getNodeType(), ASTNode.INFIX_EXPRESSION);
+ InfixExpression infixExpression = (InfixExpression) expression;
+ checkSourceRange(infixExpression, "(1 + 2) + 3", source);
+ Expression expression2 = infixExpression.getLeftOperand();
+ assertEquals("Not a parenthesized expression", expression2.getNodeType(), ASTNode.PARENTHESIZED_EXPRESSION);
+ checkSourceRange(expression2, "(1 + 2)", source);
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression2;
+ Expression expression3 = parenthesizedExpression.getExpression();
+ checkSourceRange(expression3, "1 + 2", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24453
+ */
+ public void test0422() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0422", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not an infix expression", expression.getNodeType(), ASTNode.INFIX_EXPRESSION);
+ InfixExpression infixExpression = (InfixExpression) expression;
+ checkSourceRange(infixExpression, "( 1 + 2 ) + 3", source);
+ Expression expression2 = infixExpression.getLeftOperand();
+ assertEquals("Not a parenthesized expression", expression2.getNodeType(), ASTNode.PARENTHESIZED_EXPRESSION);
+ checkSourceRange(expression2, "( 1 + 2 )", source);
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression2;
+ Expression expression3 = parenthesizedExpression.getExpression();
+ checkSourceRange(expression3, "1 + 2", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24453
+ */
+ public void test0423() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0423", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not an infix expression", expression.getNodeType(), ASTNode.INFIX_EXPRESSION);
+ InfixExpression infixExpression = (InfixExpression) expression;
+ Expression expression2 = infixExpression.getRightOperand();
+ assertEquals("Not a parenthesized expression", expression2.getNodeType(), ASTNode.PARENTHESIZED_EXPRESSION);
+ checkSourceRange(expression2, "( 2 + 3 )", source);
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression2;
+ Expression expression3 = parenthesizedExpression.getExpression();
+ checkSourceRange(expression3, "2 + 3", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24453
+ */
+ public void test0424() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0424", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not an infix expression", expression.getNodeType(), ASTNode.INFIX_EXPRESSION);
+ InfixExpression infixExpression = (InfixExpression) expression;
+ assertEquals("Wrong size", 1, infixExpression.extendedOperands().size());
+ Expression expression2 = (Expression) infixExpression.extendedOperands().get(0);
+ checkSourceRange(expression2, "( 2 + 3 )", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24453
+ */
+ public void test0425() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0425", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not an infix expression", expression.getNodeType(), ASTNode.INFIX_EXPRESSION);
+ InfixExpression infixExpression = (InfixExpression) expression;
+ assertEquals("Wrong size", 0, infixExpression.extendedOperands().size());
+ Expression expression2 = infixExpression.getRightOperand();
+ assertTrue("not an infix expression", expression2.getNodeType() == ASTNode.INFIX_EXPRESSION); //$NON-NLS-1$
+ InfixExpression infixExpression2 = (InfixExpression) expression2;
+ Expression expression3 = infixExpression2.getRightOperand();
+ assertTrue("not a parenthesized expression", expression3.getNodeType() == ASTNode.PARENTHESIZED_EXPRESSION); //$NON-NLS-1$
+ checkSourceRange(expression3, "( 2 + 3 )", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24449
+ */
+ public void test0426() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0426", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true, false, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 1, 0, 0);
+ assertEquals("Not a variable declaration statement", node.getNodeType(), ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ Type type = statement.getType();
+ assertTrue("not a simple type", type.getNodeType() == ASTNode.SIMPLE_TYPE);
+ SimpleType simpleType = (SimpleType) type;
+ Name name = simpleType.getName();
+ assertNotNull("No name", name);
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24449
+ */
+ public void test0427() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0427", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 1, 0, 0);
+ assertEquals("Not an expression statement", node.getNodeType(), ASTNode.EXPRESSION_STATEMENT);
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertEquals("Not an assignment", expression.getNodeType(), ASTNode.ASSIGNMENT);
+ Assignment assignment = (Assignment) expression;
+ Expression expression2 = assignment.getLeftHandSide();
+ assertEquals("Not a super field access", expression2.getNodeType(), ASTNode.SUPER_FIELD_ACCESS);
+ SuperFieldAccess superFieldAccess = (SuperFieldAccess) expression2;
+ Name name = superFieldAccess.getName();
+ assertNotNull("No name", name);
+ IBinding binding = name.resolveBinding();
+ assertNull("Got a binding", binding);
+ assertNull("Got a binding", superFieldAccess.resolveFieldBinding());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24449
+ */
+ public void test0428() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0428", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 1, 0, 0);
+ assertEquals("Not an expression statement", node.getNodeType(), ASTNode.EXPRESSION_STATEMENT);
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertEquals("Not an assignment", expression.getNodeType(), ASTNode.ASSIGNMENT);
+ Assignment assignment = (Assignment) expression;
+ Expression expression2 = assignment.getLeftHandSide();
+ assertEquals("Not a qualified name", expression2.getNodeType(), ASTNode.QUALIFIED_NAME);
+ QualifiedName name = (QualifiedName) expression2;
+ SimpleName simpleName = name.getName();
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding);
+ IBinding binding2 = name.resolveBinding();
+ assertNotNull("No binding2", binding2);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24449
+ */
+ public void test0429() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0429", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 1, 0, 0);
+ assertEquals("Not an expression statement", node.getNodeType(), ASTNode.EXPRESSION_STATEMENT);
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertEquals("Not an assignment", expression.getNodeType(), ASTNode.ASSIGNMENT);
+ Assignment assignment = (Assignment) expression;
+ Expression expression2 = assignment.getLeftHandSide();
+ assertEquals("Not a qualified name", expression2.getNodeType(), ASTNode.QUALIFIED_NAME);
+ QualifiedName name = (QualifiedName) expression2;
+ SimpleName simpleName = name.getName();
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding);
+ IBinding binding2 = name.resolveBinding();
+ assertNotNull("No binding2", binding2);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24499
+ */
+ public void test0430() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0430", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertTrue("Not a constructor invocation", node.getNodeType() == ASTNode.CONSTRUCTOR_INVOCATION);
+ ConstructorInvocation constructorInvocation = (ConstructorInvocation) node;
+ checkSourceRange(constructorInvocation, "this(coo2());", source);
+ List arguments = constructorInvocation.arguments();
+ assertEquals("Wrong size", 1, arguments.size());
+ Expression expression = (Expression) arguments.get(0);
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION);
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ SimpleName simpleName = methodInvocation.getName();
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24500
+ */
+ public void test0431() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0431", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertTrue("Not a constructor invocation", node.getNodeType() == ASTNode.CONSTRUCTOR_INVOCATION);
+ ConstructorInvocation constructorInvocation = (ConstructorInvocation) node;
+ List arguments = constructorInvocation.arguments();
+ assertEquals("Wrong size", 1, arguments.size());
+ Expression expression = (Expression) arguments.get(0);
+ assertTrue("Not a simple name", expression.getNodeType() == ASTNode.SIMPLE_NAME);
+ SimpleName simpleName = (SimpleName) expression;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24501
+ */
+ public void test0432() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0432", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 1, 0, 0);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertEquals("Not an assignment", ASTNode.ASSIGNMENT, expression.getNodeType());
+ Assignment assignment = (Assignment) expression;
+ Expression expression2 = assignment.getLeftHandSide();
+ assertEquals("Not a simple name", ASTNode.SIMPLE_NAME, expression2.getNodeType());
+ SimpleName simpleName = (SimpleName) expression2;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24501
+ */
+ public void test0433() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0433", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 1, 0, 0);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertEquals("Not an assignment", ASTNode.ASSIGNMENT, expression.getNodeType());
+ Assignment assignment = (Assignment) expression;
+ Expression expression2 = assignment.getLeftHandSide();
+ assertEquals("Not a super field access", ASTNode.SUPER_FIELD_ACCESS, expression2.getNodeType());
+ SuperFieldAccess superFieldAccess = (SuperFieldAccess) expression2;
+ SimpleName simpleName = superFieldAccess.getName();
+ assertEquals("wrong name", "fCoo", simpleName.getIdentifier());
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong binding", IBinding.VARIABLE, binding.getKind());
+ IVariableBinding variableBinding = superFieldAccess.resolveFieldBinding();
+ assertTrue("Different binding", binding == variableBinding);
+ ASTNode astNode = unit.findDeclaringNode(variableBinding);
+ assertTrue("Wrong type", astNode.getNodeType() == ASTNode.SINGLE_VARIABLE_DECLARATION || astNode.getNodeType() == ASTNode.VARIABLE_DECLARATION_FRAGMENT || astNode.getNodeType() == ASTNode.VARIABLE_DECLARATION_EXPRESSION);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24501
+ */
+ public void test0434() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0434", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 1, 0, 0);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertEquals("Not an assignment", ASTNode.ASSIGNMENT, expression.getNodeType());
+ Assignment assignment = (Assignment) expression;
+ Expression expression2 = assignment.getLeftHandSide();
+ assertEquals("Not a qualified name", ASTNode.QUALIFIED_NAME, expression2.getNodeType());
+ QualifiedName qualifiedName = (QualifiedName) expression2;
+ SimpleName simpleName = qualifiedName.getName();
+ assertEquals("wrong name", "fCoo", simpleName.getIdentifier());
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24501
+ */
+ public void test0435() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0435", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 1, 0, 0);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertEquals("Not an assignment", ASTNode.ASSIGNMENT, expression.getNodeType());
+ Assignment assignment = (Assignment) expression;
+ Expression expression2 = assignment.getLeftHandSide();
+ assertEquals("Not a qualified name", ASTNode.QUALIFIED_NAME, expression2.getNodeType());
+ QualifiedName qualifiedName = (QualifiedName) expression2;
+ SimpleName simpleName = qualifiedName.getName();
+ assertEquals("wrong name", "fCoo", simpleName.getIdentifier());
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24502
+ */
+ public void test0436() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0436", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true, false, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertProblemsSize(unit, 1, "The type A.CInner is not visible"); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 1, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ Type type = statement.getType();
+ assertEquals("Not a simple type", ASTNode.SIMPLE_TYPE, type.getNodeType());
+ SimpleType simpleType = (SimpleType) type;
+ Name name = simpleType.getName();
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Not a qualified name", ASTNode.QUALIFIED_NAME, name.getNodeType());
+ QualifiedName qualifiedName = (QualifiedName) name;
+ SimpleName simpleName = qualifiedName.getName();
+ assertEquals("wrong name", "CInner", simpleName.getIdentifier());
+ IBinding binding2 = simpleName.resolveBinding();
+ assertNotNull("No binding", binding2);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24502
+ */
+ public void test0437() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0437", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true, false, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertProblemsSize(unit, 1, "The type CInner is not visible"); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 1, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ Type type = statement.getType();
+ assertEquals("Not a simple type", ASTNode.SIMPLE_TYPE, type.getNodeType());
+ SimpleType simpleType = (SimpleType) type;
+ Name name = simpleType.getName();
+ assertEquals("Not a simple name", ASTNode.SIMPLE_NAME, name.getNodeType());
+ SimpleName simpleName = (SimpleName) name;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24511
+ */
+ public void test0438() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0438", "D.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true, false, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ List imports = unit.imports();
+ assertEquals("Wrong size", 1, imports.size()); //$NON-NLS-1$<
+ ImportDeclaration importDeclaration = (ImportDeclaration) imports.get(0);
+ IBinding binding = importDeclaration.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24502
+ */
+ public void test0439() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0439", "E.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true, false, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ Type type = statement.getType();
+ assertEquals("Not a simple type", ASTNode.SIMPLE_TYPE, type.getNodeType());
+ SimpleType simpleType = (SimpleType) type;
+ Name name = simpleType.getName();
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24622
+ */
+ public void test0440() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0440", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not an infix expression", ASTNode.INFIX_EXPRESSION, expression.getNodeType());
+ // 2 * 3 + "" + (true)
+ InfixExpression infixExpression = (InfixExpression) expression;
+ checkSourceRange(infixExpression, "2 * 3 + \"\" + (true)", source);
+ Expression leftOperand = infixExpression.getLeftOperand();
+ checkSourceRange(leftOperand, "2 * 3 + \"\"", source);
+ checkSourceRange(infixExpression.getRightOperand(), "(true)", source);
+ assertEquals("wrong operator", infixExpression.getOperator(), InfixExpression.Operator.PLUS);
+ assertEquals("wrong type", ASTNode.INFIX_EXPRESSION, leftOperand.getNodeType());
+ infixExpression = (InfixExpression) leftOperand;
+ checkSourceRange(infixExpression, "2 * 3 + \"\"", source);
+ leftOperand = infixExpression.getLeftOperand();
+ checkSourceRange(leftOperand, "2 * 3", source);
+ checkSourceRange(infixExpression.getRightOperand(), "\"\"", source);
+ assertEquals("wrong operator", infixExpression.getOperator(), InfixExpression.Operator.PLUS);
+ assertEquals("wrong type", ASTNode.INFIX_EXPRESSION, leftOperand.getNodeType());
+ infixExpression = (InfixExpression) leftOperand;
+ checkSourceRange(infixExpression, "2 * 3", source);
+ leftOperand = infixExpression.getLeftOperand();
+ checkSourceRange(leftOperand, "2", source);
+ checkSourceRange(infixExpression.getRightOperand(), "3", source);
+ assertEquals("wrong operator", infixExpression.getOperator(), InfixExpression.Operator.TIMES);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24622
+ */
+ public void test0441() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0441", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not an infix expression", ASTNode.INFIX_EXPRESSION, expression.getNodeType());
+ InfixExpression infixExpression = (InfixExpression) expression;
+ checkSourceRange(infixExpression, "(2 + 2) * 3 * 1", source);
+ Expression leftOperand = infixExpression.getLeftOperand();
+ checkSourceRange(leftOperand, "(2 + 2)", source);
+ checkSourceRange(infixExpression.getRightOperand(), "3", source);
+ List extendedOperands = infixExpression.extendedOperands();
+ assertEquals("wrong size", 1, extendedOperands.size());
+ checkSourceRange((Expression) extendedOperands.get(0), "1", source);
+ assertEquals("wrong operator", InfixExpression.Operator.TIMES, infixExpression.getOperator());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24622
+ */
+ public void test0442() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0442", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not an infix expression", ASTNode.INFIX_EXPRESSION, expression.getNodeType());
+ InfixExpression infixExpression = (InfixExpression) expression;
+ checkSourceRange(infixExpression, "2 + (2 * 3) + 1", source);
+ Expression leftOperand = infixExpression.getLeftOperand();
+ checkSourceRange(leftOperand, "2", source);
+ Expression rightOperand = infixExpression.getRightOperand();
+ checkSourceRange(rightOperand, "(2 * 3)", source);
+ assertEquals("wrong type", ASTNode.PARENTHESIZED_EXPRESSION, rightOperand.getNodeType());
+ List extendedOperands = infixExpression.extendedOperands();
+ assertEquals("wrong size", 1, extendedOperands.size());
+ checkSourceRange((Expression) extendedOperands.get(0), "1", source);
+ assertEquals("wrong operator", InfixExpression.Operator.PLUS, infixExpression.getOperator());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24623
+ */
+ public void test0443() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0443", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 3, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertEquals("Wrong type", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertNotNull("No body", methodDeclaration.getBody());
+ assertNotNull("No binding", methodDeclaration.resolveBinding());
+ assertTrue("Not an abstract method", Modifier.isAbstract(methodDeclaration.getModifiers()));
+ List modifiers = methodDeclaration.modifiers();
+ assertEquals("Wrong size", 2, modifiers.size());
+ Modifier modifier1 = (Modifier) modifiers.get(0);
+ assertTrue("Not a public modifier", modifier1.isPublic());
+ Modifier modifier2 = (Modifier) modifiers.get(1);
+ assertTrue("Not an abstract modifier", modifier2.isAbstract());
+ assertTrue("Not malformed", isMalformed(methodDeclaration));
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24623
+ */
+ public void test0444() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0444", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 2, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0);
+ assertEquals("Wrong type", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 2, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration)bodyDeclarations.get(0);
+ assertEquals("Wrong type", ASTNode.METHOD_DECLARATION, bodyDeclaration.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ assertEquals("Wrong name", "foo", methodDeclaration.getName().getIdentifier());
+ bodyDeclaration = (BodyDeclaration)bodyDeclarations.get(1);
+ assertEquals("Wrong type", ASTNode.METHOD_DECLARATION, bodyDeclaration.getNodeType());
+ assertEquals("Wrong name", "foo", ((MethodDeclaration) bodyDeclaration).getName().getIdentifier());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24773
+ */
+ public void test0445() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0445", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=25018
+ */
+ public void test0446() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0446", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 2, unit.getProblems().length); //$NON-NLS-1$<
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=25124
+ */
+ public void test0447() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0447", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 3, unit.getProblems().length); //$NON-NLS-1$<
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=25330
+ */
+ public void test0448() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0448", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", node.getNodeType(), ASTNode.METHOD_DECLARATION);
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Not a constructor", methodDeclaration.isConstructor());
+ assertNull("No return type", methodDeclaration.getReturnType2());
+ Block block = methodDeclaration.getBody();
+ assertNotNull("No method body", block);
+ assertEquals("wrong size", 0, block.statements().size());
+ }
+
+ /**
+ * Check that the implicit super constructor call is not there
+ */
+ public void test0449() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0449", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", node.getNodeType(), ASTNode.METHOD_DECLARATION);
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Not a constructor", methodDeclaration.isConstructor());
+ Block block = methodDeclaration.getBody();
+ assertNotNull("No method body", block);
+ assertEquals("wrong size", 1, block.statements().size());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=26452
+ */
+ public void test0450() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0450", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0);
+ assertEquals("Not a type declaration", node.getNodeType(), ASTNode.TYPE_DECLARATION);
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No type binding", typeBinding);
+ assertTrue("not a class", typeBinding.isClass());
+ assertTrue("not a toplevel type", typeBinding.isTopLevel());
+ assertTrue("a local type", !typeBinding.isLocal());
+ assertTrue("an anonymous type", !typeBinding.isAnonymous());
+ assertTrue("a member type", !typeBinding.isMember());
+ assertTrue("a nested type", !typeBinding.isNested());
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not an expression statement", node.getNodeType(), ASTNode.EXPRESSION_STATEMENT);
+ Expression expression = ((ExpressionStatement) node).getExpression();
+ assertEquals("Not a class instance creation", expression.getNodeType(), ASTNode.CLASS_INSTANCE_CREATION);
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ typeBinding = anonymousClassDeclaration.resolveBinding();
+ assertNotNull("No type binding", typeBinding);
+ assertTrue("not a class", typeBinding.isClass());
+ assertTrue("a toplevel type", !typeBinding.isTopLevel());
+ assertTrue("not a local type", typeBinding.isLocal());
+ assertTrue("not an anonymous type", typeBinding.isAnonymous());
+ assertTrue("a member type", !typeBinding.isMember());
+ assertTrue("not a nested type", typeBinding.isNested());
+ ASTNode astNode = unit.findDeclaringNode(typeBinding);
+ assertEquals("Wrong type", ASTNode.ANONYMOUS_CLASS_DECLARATION, astNode.getNodeType());
+ assertNotNull("Didn't get a key", typeBinding.getKey());
+ astNode = unit.findDeclaringNode(typeBinding.getKey());
+ assertNotNull("Didn't get a declaring node", astNode);
+
+ ITypeBinding typeBinding3 = classInstanceCreation.resolveTypeBinding();
+ assertEquals("wrong binding", typeBinding, typeBinding3);
+
+ List bodyDeclarations = anonymousClassDeclaration.bodyDeclarations();
+ assertEquals("wrong size", 2, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue("not a type declaration", bodyDeclaration.getNodeType() == ASTNode.TYPE_DECLARATION);
+ typeDeclaration = (TypeDeclaration) bodyDeclaration;
+
+ bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(1);
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ Block block = methodDeclaration.getBody();
+ assertNotNull("No body", block);
+ List statements = block.statements();
+ assertEquals("wrong size", 2, statements.size());
+ Statement statement = (Statement) statements.get(1);
+ assertEquals("Not a variable declaration statement", statement.getNodeType(), ASTNode.VARIABLE_DECLARATION_STATEMENT);
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) statement;
+ Type type = variableDeclarationStatement.getType();
+ assertNotNull("No type", type);
+
+ ITypeBinding typeBinding2 = type.resolveBinding();
+ typeBinding = typeDeclaration.resolveBinding();
+ assertTrue("not equals", typeBinding == typeBinding2);
+ assertNotNull("No type binding", typeBinding);
+ assertTrue("not a class", typeBinding.isClass());
+ assertTrue("a toplevel type", !typeBinding.isTopLevel());
+ assertTrue("an anonymous type", !typeBinding.isAnonymous());
+ assertTrue("not a member type", typeBinding.isMember());
+ assertTrue("not a nested type", typeBinding.isNested());
+ assertTrue("a local type", !typeBinding.isLocal());
+
+ bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("wrong size", 1, bodyDeclarations.size());
+ bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue("not a type declaration", bodyDeclaration.getNodeType() == ASTNode.TYPE_DECLARATION);
+ typeDeclaration = (TypeDeclaration) bodyDeclaration;
+ typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No type binding", typeBinding);
+ assertTrue("not a class", typeBinding.isClass());
+ assertTrue("a toplevel type", !typeBinding.isTopLevel());
+ assertTrue("an anonymous type", !typeBinding.isAnonymous());
+ assertTrue("not a member type", typeBinding.isMember());
+ assertTrue("not a nested type", typeBinding.isNested());
+ assertTrue("a local type", !typeBinding.isLocal());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=24916
+ */
+ public void test0451() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0451", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 2, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Type type = methodDeclaration.getReturnType2();
+ checkSourceRange(type, "int", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=27204
+ */
+ public void test0452() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "", "NO_WORKING.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ SimpleName name = methodDeclaration.getName();
+ assertEquals("wrong line number", 3, compilationUnit.getLineNumber(name.getStartPosition()));
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=27173
+ */
+ public void test0453() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0453", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0,0);
+ assertNotNull("No node", node);
+ assertTrue("not a return statement", node.getNodeType() == ASTNode.RETURN_STATEMENT); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertTrue("not a super method invocation", expression.getNodeType() == ASTNode.SUPER_METHOD_INVOCATION); //$NON-NLS-1$
+ SuperMethodInvocation methodInvocation = (SuperMethodInvocation) expression;
+ IMethodBinding methodBinding = methodInvocation.resolveMethodBinding();
+ assertNotNull("No method binding", methodBinding);
+ assertEquals("Wrong binding", "toString", methodBinding.getName());
+ }
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=28296
+ */
+ public void test0454() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0454", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0,1);
+ assertNotNull("No node", node);
+ assertTrue("not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertTrue("not a cast expression", expression.getNodeType() == ASTNode.CAST_EXPRESSION); //$NON-NLS-1$
+ checkSourceRange(expression, "(int) (3.14f * a)", source);
+ CastExpression castExpression = (CastExpression) expression;
+ checkSourceRange(castExpression.getType(), "int", source);
+ Expression expression2 = castExpression.getExpression();
+ checkSourceRange(expression2, "(3.14f * a)", source);
+ assertTrue("not a parenthesized expression", expression2.getNodeType() == ASTNode.PARENTHESIZED_EXPRESSION); //$NON-NLS-1$
+ }
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=28682
+ */
+ public void test0455() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0455", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a for statement", node.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node; // first for loop
+ String expectedSource = "for (int i = 0; i < 10; i++) // for 1\n" +
+ " for (int j = 0; j < 10; j++) // for 2\n" +
+ " if (true) { }";
+ checkSourceRange(forStatement, expectedSource, source);
+ Statement body = forStatement.getBody();
+ expectedSource = "for (int j = 0; j < 10; j++) // for 2\n" +
+ " if (true) { }";
+ checkSourceRange(body, expectedSource, source);
+ assertTrue("not a for statement", body.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement2 = (ForStatement) body;
+ body = forStatement2.getBody();
+ expectedSource = "if (true) { }";
+ checkSourceRange(body, expectedSource, source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=28682
+ */
+ public void test0456() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0456", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a for statement", node.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node; // first for loop
+ String expectedSource = "for (int x= 10; x < 20; x++)\n" +
+ " main();";
+ checkSourceRange(forStatement, expectedSource, source);
+ Statement body = forStatement.getBody();
+ expectedSource = "main();";
+ checkSourceRange(body, expectedSource, source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=28682
+ */
+ public void test0457() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0457", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a for statement", node.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node; // first for loop
+ String expectedSource = "for (int i= 10; i < 10; i++)/*[*/\n"+
+ " for (int z= 10; z < 10; z++)\n" +
+ " foo();";
+ checkSourceRange(forStatement, expectedSource, source);
+ Statement body = forStatement.getBody();
+ expectedSource = "for (int z= 10; z < 10; z++)\n" +
+ " foo();";
+ checkSourceRange(body, expectedSource, source);
+ assertTrue("not a for statement", body.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement2 = (ForStatement) body;
+ body = forStatement2.getBody();
+ expectedSource = "foo();";
+ checkSourceRange(body, expectedSource, source);
+ }
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=28682
+ */
+ public void test0458() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0458", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a for statement", node.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node; // first for loop
+ String expectedSource = "for (int i= 10; i < 10; i++)/*[*/\n"+
+ " for (int z= 10; z < 10; z++)\n" +
+ " ;";
+ checkSourceRange(forStatement, expectedSource, source);
+ Statement body = forStatement.getBody();
+ expectedSource = "for (int z= 10; z < 10; z++)\n" +
+ " ;";
+ checkSourceRange(body, expectedSource, source);
+ assertTrue("not a for statement", body.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement2 = (ForStatement) body;
+ body = forStatement2.getBody();
+ expectedSource = ";";
+ checkSourceRange(body, expectedSource, source);
+ assertTrue("not an empty statement", body.getNodeType() == ASTNode.EMPTY_STATEMENT); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=28682
+ */
+ public void test0459() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0459", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a for statement", node.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node; // first for loop
+ String expectedSource = "for (int i= 10; i < 10; i++)/*[*/\n"+
+ " for (int z= 10; z < 10; z++)\n" +
+ " { }";
+ checkSourceRange(forStatement, expectedSource, source);
+ Statement body = forStatement.getBody();
+ expectedSource = "for (int z= 10; z < 10; z++)\n" +
+ " { }";
+ checkSourceRange(body, expectedSource, source);
+ assertTrue("not a for statement", body.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement2 = (ForStatement) body;
+ body = forStatement2.getBody();
+ expectedSource = "{ }";
+ checkSourceRange(body, expectedSource, source);
+ assertTrue("not a block", body.getNodeType() == ASTNode.BLOCK); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=28869
+ */
+ public void test0460() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0460", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertTrue("Has error", compilationUnit.getProblems().length == 0); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("Malformed", !isMalformed(node));
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=28824
+ */
+ public void test0461() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0461", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ char[] source = sourceUnit.getSource().toCharArray();
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertTrue("Has error", compilationUnit.getProblems().length == 0); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("Malformed", !isMalformed(node));
+ assertTrue("not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("not an assignment", expression.getNodeType() == ASTNode.ASSIGNMENT); //$NON-NLS-1$
+ Assignment assignment = (Assignment) expression;
+ checkSourceRange(assignment, "z= foo().y.toList()", source);
+ Expression expression2 = assignment.getRightHandSide();
+ checkSourceRange(expression2, "foo().y.toList()", source);
+ assertTrue("not a method invocation", expression2.getNodeType() == ASTNode.METHOD_INVOCATION);
+ MethodInvocation methodInvocation = (MethodInvocation) expression2;
+ Expression expression3 = methodInvocation.getExpression();
+ checkSourceRange(expression3, "foo().y", source);
+ checkSourceRange(methodInvocation.getName(), "toList", source);
+ assertTrue("not a field access", expression3.getNodeType() == ASTNode.FIELD_ACCESS);
+ FieldAccess fieldAccess = (FieldAccess) expression3;
+ checkSourceRange(fieldAccess.getName(), "y", source);
+ Expression expression4 = fieldAccess.getExpression();
+ checkSourceRange(expression4, "foo()", source);
+ assertTrue("not a method invocation", expression4.getNodeType() == ASTNode.METHOD_INVOCATION);
+ MethodInvocation methodInvocation2 = (MethodInvocation) expression4;
+ checkSourceRange(methodInvocation2.getName(), "foo", source);
+ assertNull("no null", methodInvocation2.getExpression());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=32338
+ */
+ public void test0462() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "", "Test462.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertTrue("Has error", compilationUnit.getProblems().length == 0); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION);
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ assertEquals("Wrong name", "Test462", typeDeclaration.getName().getIdentifier());
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertEquals("Wrong name", "Test462", typeBinding.getQualifiedName());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=33450
+ */
+ public void test0463() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0463", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a return statement", node.getNodeType() == ASTNode.RETURN_STATEMENT); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertNotNull("No expression", expression);
+ assertTrue("not a string literal", expression.getNodeType() == ASTNode.STRING_LITERAL); //$NON-NLS-1$
+ StringLiteral stringLiteral = (StringLiteral) expression;
+ checkSourceRange(stringLiteral, "\"\\012\\015\\u0061\"", source);
+ assertEquals("wrong value", "\012\015a", stringLiteral.getLiteralValue());
+ assertEquals("wrong value", "\"\\012\\015\\u0061\"", stringLiteral.getEscapedValue());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=33039
+ */
+ public void test0464() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0464", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("No error", 1, compilationUnit.getProblems().length); //$NON-NLS-1$
+ assertNotNull("No node", node);
+ assertTrue("not a return statement", node.getNodeType() == ASTNode.RETURN_STATEMENT); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertNotNull("No expression", expression);
+ assertTrue("not a null literal", expression.getNodeType() == ASTNode.NULL_LITERAL); //$NON-NLS-1$
+ NullLiteral nullLiteral = (NullLiteral) expression;
+ ITypeBinding typeBinding = nullLiteral.resolveTypeBinding();
+ assertNotNull("No type binding", typeBinding);
+ assertFalse("A primitive type", typeBinding.isPrimitive());
+ assertTrue("Null type", typeBinding.isNullType());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=33831
+ */
+ public void test0465() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0465", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertEquals("No error", 0, compilationUnit.getProblems().length); //$NON-NLS-1$
+ assertNotNull("No node", node);
+ assertTrue("not a return statement", node.getNodeType() == ASTNode.RETURN_STATEMENT); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertNotNull("No expression", expression);
+ assertTrue("not a field access", expression.getNodeType() == ASTNode.FIELD_ACCESS); //$NON-NLS-1$
+ FieldAccess fieldAccess = (FieldAccess) expression;
+ Name name = fieldAccess.getName();
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong type", IBinding.VARIABLE, binding.getKind());
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Wrong name", "i", variableBinding.getName());
+ assertEquals("Wrong type", "int", variableBinding.getType().getName());
+ IVariableBinding variableBinding2 = fieldAccess.resolveFieldBinding();
+ assertTrue("different binding", variableBinding == variableBinding2);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=33949
+ */
+ public void test0466() throws JavaModelException {
+ Hashtable options = JavaCore.getOptions();
+ Hashtable newOptions = JavaCore.getOptions();
+ try {
+ newOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4);
+ JavaCore.setOptions(newOptions);
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0466", "Assert.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ checkSourceRange(node, "assert ref != null : message;", source);
+ assertTrue("not an assert statement", node.getNodeType() == ASTNode.ASSERT_STATEMENT); //$NON-NLS-1$
+ AssertStatement statement = (AssertStatement) node;
+ checkSourceRange(statement.getExpression(), "ref != null", source);
+ checkSourceRange(statement.getMessage(), "message", source);
+ } finally {
+ JavaCore.setOptions(options);
+ }
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=33949
+ */
+ public void test0467() throws JavaModelException {
+ Hashtable options = JavaCore.getOptions();
+ Hashtable newOptions = JavaCore.getOptions();
+ try {
+ newOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4);
+ JavaCore.setOptions(newOptions);
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0467", "Assert.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ checkSourceRange(node, "assert ref != null : message\\u003B", source);
+ assertTrue("not an assert statement", node.getNodeType() == ASTNode.ASSERT_STATEMENT); //$NON-NLS-1$
+ AssertStatement statement = (AssertStatement) node;
+ checkSourceRange(statement.getExpression(), "ref != null", source);
+ checkSourceRange(statement.getMessage(), "message", source);
+
+ node = getASTNode(compilationUnit, 0, 0, 1);
+ checkSourceRange(node, "assert ref != null\\u003B", source);
+ assertTrue("not an assert statement", node.getNodeType() == ASTNode.ASSERT_STATEMENT); //$NON-NLS-1$
+ statement = (AssertStatement) node;
+ checkSourceRange(statement.getExpression(), "ref != null", source);
+ } finally {
+ JavaCore.setOptions(options);
+ }
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=36772
+ */
+ public void test0468() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0468", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertEquals("No error", 0, compilationUnit.getProblems().length); //$NON-NLS-1$
+ assertNotNull("No node", node);
+ assertTrue("not a return statement", node.getNodeType() == ASTNode.RETURN_STATEMENT); //$NON-NLS-1$
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertNotNull("No expression", expression);
+ assertTrue("not a field access", expression.getNodeType() == ASTNode.FIELD_ACCESS); //$NON-NLS-1$
+ FieldAccess fieldAccess = (FieldAccess) expression;
+ Name name = fieldAccess.getName();
+ IBinding binding = name.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong type", IBinding.VARIABLE, binding.getKind());
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Wrong name", "i", variableBinding.getName());
+ assertEquals("Wrong type", "int", variableBinding.getType().getName());
+ IVariableBinding variableBinding2 = fieldAccess.resolveFieldBinding();
+ assertTrue("different binding", variableBinding == variableBinding2);
+
+ node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull("No node", node);
+ assertEquals("Wrong type", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+
+ ASTNode foundNode = compilationUnit.findDeclaringNode(variableBinding);
+ assertNotNull("No found node", foundNode);
+ assertEquals("wrong node", fragment, foundNode);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=36895
+ */
+ public void test0469() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "codeManipulation", "bug.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 2, 0);
+ assertEquals("No error", 0, compilationUnit.getProblems().length); //$NON-NLS-1$
+ assertNotNull("No node", node);
+ assertTrue("not a variable declaration statement", node.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ ASTNode parent = node.getParent();
+ assertNotNull(parent);
+ assertTrue("not a block", parent.getNodeType() == ASTNode.BLOCK); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=37381
+ */
+ public void test0470() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0470", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("No error", 0, compilationUnit.getProblems().length); //$NON-NLS-1$
+ assertNotNull("No node", node);
+ assertTrue("not a for statement", node.getNodeType() == ASTNode.FOR_STATEMENT); //$NON-NLS-1$
+ ForStatement forStatement = (ForStatement) node;
+ List initializers = forStatement.initializers();
+ assertEquals("wrong size", 1, initializers.size());
+ Expression initializer = (Expression) initializers.get(0);
+ assertTrue("not a variable declaration expression", initializer.getNodeType() == ASTNode.VARIABLE_DECLARATION_EXPRESSION); //$NON-NLS-1$
+ VariableDeclarationExpression variableDeclarationExpression = (VariableDeclarationExpression) initializer;
+ List fragments = variableDeclarationExpression.fragments();
+ assertEquals("wrong size", 2, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ checkSourceRange(fragment, "i= 0", source);
+ fragment = (VariableDeclarationFragment) fragments.get(1);
+ checkSourceRange(fragment, "j= goo(3)", source);
+ checkSourceRange(variableDeclarationExpression, "int i= 0, j= goo(3)", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=38447
+ */
+ public void test0471() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0471", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("No error", 1, compilationUnit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Is a constructor", !methodDeclaration.isConstructor());
+ checkSourceRange(methodDeclaration, "private void foo(){", source);
+ node = getASTNode(compilationUnit, 0, 1);
+ assertNotNull("No node", node);
+ assertTrue("not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Is a constructor", !methodDeclaration.isConstructor());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=38447
+ */
+ public void test0472() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "junit.textui", "ResultPrinter.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("No error", 2, compilationUnit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 2);
+ assertNotNull("No node", node);
+ assertTrue("not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Not a constructor", methodDeclaration.isConstructor());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=38732
+ */
+ public void test0473() throws JavaModelException {
+ Hashtable options = JavaCore.getOptions();
+ Hashtable newOptions = JavaCore.getOptions();
+ try {
+ newOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4);
+ newOptions.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER, JavaCore.ERROR);
+ JavaCore.setOptions(newOptions);
+
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0473", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("No error", 2, compilationUnit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not an assert statement", node.getNodeType() == ASTNode.ASSERT_STATEMENT); //$NON-NLS-1$
+ AssertStatement assertStatement = (AssertStatement) node;
+ checkSourceRange(assertStatement, "assert(true);", source);
+ Expression expression = assertStatement.getExpression();
+ checkSourceRange(expression, "(true)", source);
+ } finally {
+ JavaCore.setOptions(options);
+ }
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=39259
+ */
+ public void test0474() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0474", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("No error", 0, compilationUnit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertNotNull("No node", node);
+ assertEquals("Not a while statement", node.getNodeType(), ASTNode.WHILE_STATEMENT);
+ WhileStatement whileStatement = (WhileStatement) node;
+ Statement statement = whileStatement.getBody();
+ assertEquals("Not a while statement", statement.getNodeType(), ASTNode.WHILE_STATEMENT);
+ WhileStatement whileStatement2 = (WhileStatement) statement;
+ String expectedSource =
+ "while(b())\n" +
+ " foo();";
+ checkSourceRange(whileStatement2, expectedSource, source);
+ Statement statement2 = whileStatement2.getBody();
+ checkSourceRange(statement2, "foo();", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=39259
+ */
+ public void test0475() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0475", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("No error", 0, compilationUnit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertNotNull("No node", node);
+ assertEquals("Not an if statement", node.getNodeType(), ASTNode.IF_STATEMENT);
+ IfStatement statement = (IfStatement) node;
+ Statement statement2 = statement.getThenStatement();
+ assertEquals("Not an if statement", statement2.getNodeType(), ASTNode.IF_STATEMENT);
+ IfStatement statement3 = (IfStatement) statement2;
+ String expectedSource =
+ "if(b())\n" +
+ " foo();";
+ checkSourceRange(statement3, expectedSource, source);
+ Statement statement4 = statement3.getThenStatement();
+ checkSourceRange(statement4, "foo();", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=39259
+ */
+ public void test0476() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0476", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("No error", 0, compilationUnit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertNotNull("No node", node);
+ assertEquals("Not a for statement", node.getNodeType(), ASTNode.FOR_STATEMENT);
+ ForStatement statement = (ForStatement) node;
+ Statement statement2 = statement.getBody();
+ assertEquals("Not a for statement", statement2.getNodeType(), ASTNode.FOR_STATEMENT);
+ ForStatement statement3 = (ForStatement) statement2;
+ String expectedSource =
+ "for(;b();)\n" +
+ " foo();";
+ checkSourceRange(statement3, expectedSource, source);
+ Statement statement4 = statement3.getBody();
+ checkSourceRange(statement4, "foo();", source);
+ }
+
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=39327
+ */
+ public void test0477() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0477", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("No error", 1, compilationUnit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(compilationUnit, 0, 1, 0);
+ assertNotNull("No node", node);
+
+ checkSourceRange(node, "this(undef());", source);
+ assertEquals("Not a constructor invocation", node.getNodeType(), ASTNode.CONSTRUCTOR_INVOCATION);
+ ConstructorInvocation constructorInvocation = (ConstructorInvocation) node;
+ List arguments = constructorInvocation.arguments();
+ assertEquals("Wrong size", 1, arguments.size());
+ IMethodBinding binding = constructorInvocation.resolveConstructorBinding();
+ assertNotNull("No binding", binding);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=40474
+ */
+ public void test0478() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0478", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType[] types = sourceUnit.getTypes();
+ assertNotNull(types);
+ assertEquals("wrong size", 2, types.length);
+ IType type = types[1];
+ IMethod[] methods = type.getMethods();
+ assertNotNull(methods);
+ assertEquals("wrong size", 1, methods.length);
+ IMethod method = methods[0];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, sourceRange.getOffset() + sourceRange.getLength() / 2, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 1, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("wrong name", "test", methodDeclaration.getName().getIdentifier());
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ assertNotNull(methodBinding);
+ List statements = ((MethodDeclaration) node).getBody().statements();
+ assertEquals("wrong size", 2, statements.size());
+ ASTNode node2 = (ASTNode) statements.get(1);
+ assertNotNull(node2);
+ assertTrue("Not an expression statement", node2.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node2;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ assertTrue("Not a simple name", expression2.getNodeType() == ASTNode.SIMPLE_NAME); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) expression2;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("wrong type", binding.getKind() == IBinding.VARIABLE); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Wrong name", "a", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ SimpleName simpleName2 = methodInvocation.getName();
+ assertEquals("Wrong name", "clone", simpleName2.getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding2 = simpleName2.resolveBinding();
+ assertNotNull("no binding2", binding2); //$NON-NLS-1$
+ assertTrue("Wrong type", binding2.getKind() == IBinding.METHOD); //$NON-NLS-1$
+ IMethodBinding methodBinding2 = (IMethodBinding) binding2;
+ assertEquals("Wrong name", "clone", methodBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=40474
+ */
+ public void test0479() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0479", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType[] types = sourceUnit.getTypes();
+ assertNotNull(types);
+ assertEquals("wrong size", 2, types.length);
+ IType type = types[1];
+ IMethod[] methods = type.getMethods();
+ assertNotNull(methods);
+ assertEquals("wrong size", 1, methods.length);
+ IMethod method = methods[0];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, sourceRange.getOffset() + sourceRange.getLength() / 2, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 1, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("wrong name", "test", methodDeclaration.getName().getIdentifier());
+ List statements = ((MethodDeclaration) node).getBody().statements();
+ assertEquals("wrong size", 2, statements.size());
+ ASTNode node2 = (ASTNode) statements.get(1);
+ assertNotNull(node2);
+ assertTrue("Not an expression statement", node2.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node2;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ assertTrue("Not a simple name", expression2.getNodeType() == ASTNode.SIMPLE_NAME); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) expression2;
+ IBinding binding = simpleName.resolveBinding();
+ assertNull("No binding", binding); //$NON-NLS-1$
+ SimpleName simpleName2 = methodInvocation.getName();
+ assertEquals("Wrong name", "clone", simpleName2.getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=40474
+ */
+ public void test0480() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0480", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType[] types = sourceUnit.getTypes();
+ assertNotNull(types);
+ assertEquals("wrong size", 1, types.length);
+ IType type = types[0];
+ IMethod[] methods = type.getMethods();
+ assertNotNull(methods);
+ assertEquals("wrong size", 1, methods.length);
+ IMethod method = methods[0];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, sourceRange.getOffset() + sourceRange.getLength() / 2, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("wrong name", "test", methodDeclaration.getName().getIdentifier());
+ List statements = ((MethodDeclaration) node).getBody().statements();
+ assertEquals("wrong size", 1, statements.size());
+ ASTNode node2 = (ASTNode) statements.get(0);
+ assertNotNull(node2);
+ assertTrue("Not an variable declaration statement", node2.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=40474
+ */
+ public void test0481() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0481", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType[] types = sourceUnit.getTypes();
+ assertNotNull(types);
+ assertEquals("wrong size", 1, types.length);
+ IType type = types[0];
+ IMethod[] methods = type.getMethods();
+ assertNotNull(methods);
+ assertEquals("wrong size", 1, methods.length);
+ IMethod method = methods[0];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, sourceRange.getOffset() + sourceRange.getLength() / 2, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("wrong name", "test", methodDeclaration.getName().getIdentifier());
+ List statements = ((MethodDeclaration) node).getBody().statements();
+ assertEquals("wrong size", 1, statements.size());
+ ASTNode node2 = (ASTNode) statements.get(0);
+ assertNotNull(node2);
+ assertTrue("Not an variable declaration statement", node2.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node2;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertTrue("Not a class instance creation", expression.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ ITypeBinding typeBinding = classInstanceCreation.resolveTypeBinding();
+ assertNotNull(typeBinding);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=40474
+ */
+ public void test0482() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0482", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType[] types = sourceUnit.getTypes();
+ assertNotNull(types);
+ assertEquals("wrong size", 1, types.length);
+ IType type = types[0];
+ IType[] memberTypes = type.getTypes();
+ assertNotNull(memberTypes);
+ assertEquals("wrong size", 1, memberTypes.length);
+ IType memberType = memberTypes[0];
+ IMethod[] methods = memberType.getMethods();
+ assertEquals("wrong size", 1, methods.length);
+ IMethod method = methods[0];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, sourceRange.getOffset() + sourceRange.getLength() / 2, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("wrong name", "test", methodDeclaration.getName().getIdentifier());
+ List statements = ((MethodDeclaration) node).getBody().statements();
+ assertEquals("wrong size", 1, statements.size());
+ ASTNode node2 = (ASTNode) statements.get(0);
+ assertNotNull(node2);
+ assertTrue("Not an variable declaration statement", node2.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node2;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertTrue("Not a class instance creation", expression.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ ITypeBinding typeBinding = classInstanceCreation.resolveTypeBinding();
+ assertNotNull(typeBinding);
+ assertTrue(typeBinding.isAnonymous());
+ assertEquals("Wrong name", "", typeBinding.getName());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=40474
+ */
+ public void test0483() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0483", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType[] types = sourceUnit.getTypes();
+ assertNotNull(types);
+ assertEquals("wrong size", 1, types.length);
+ IType type = types[0];
+ IMethod[] methods = type.getMethods();
+ assertEquals("wrong size", 1, methods.length);
+ IMethod method = methods[0];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, sourceRange.getOffset() + sourceRange.getLength() / 2, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("wrong name", "A", methodDeclaration.getName().getIdentifier());
+ assertTrue("Not a constructor", methodDeclaration.isConstructor());
+ IBinding binding = methodDeclaration.getName().resolveBinding();
+ assertNotNull(binding);
+ assertEquals("Wrong type", IBinding.METHOD, binding.getKind());
+ List statements = ((MethodDeclaration) node).getBody().statements();
+ assertEquals("wrong size", 1, statements.size());
+ ASTNode node2 = (ASTNode) statements.get(0);
+ assertNotNull(node2);
+ assertTrue("Not an variable declaration statement", node2.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node2;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertTrue("Not a class instance creation", expression.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ ITypeBinding typeBinding = classInstanceCreation.resolveTypeBinding();
+ assertNotNull(typeBinding);
+ assertTrue(typeBinding.isAnonymous());
+ assertEquals("Wrong name", "", typeBinding.getName());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=40474
+ */
+ public void test0484() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0482", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType[] types = sourceUnit.getTypes();
+ assertNotNull(types);
+ assertEquals("wrong size", 1, types.length);
+ IType type = types[0];
+ IType[] memberTypes = type.getTypes();
+ assertNotNull(memberTypes);
+ assertEquals("wrong size", 1, memberTypes.length);
+ IType memberType = memberTypes[0];
+ ISourceRange sourceRange = memberType.getSourceRange();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, sourceRange.getOffset() + sourceRange.getLength() / 2, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ assertEquals("wrong name", "B", typeDeclaration.getName().getIdentifier());
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue("Not a method declaration", bodyDeclaration.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=40474
+ */
+ public void test0485() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0482", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType[] types = sourceUnit.getTypes();
+ assertNotNull(types);
+ assertEquals("wrong size", 1, types.length);
+ IType type = types[0];
+ IType[] memberTypes = type.getTypes();
+ assertNotNull(memberTypes);
+ assertEquals("wrong size", 1, memberTypes.length);
+ IType memberType = memberTypes[0];
+ ISourceRange sourceRange = memberType.getSourceRange();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, sourceRange.getOffset() + sourceRange.getLength() / 2, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ assertEquals("wrong name", "B", typeDeclaration.getName().getIdentifier());
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue("Not a method declaration", bodyDeclaration.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=40474
+ */
+ public void test0486() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0486", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType[] types = sourceUnit.getTypes();
+ assertNotNull(types);
+ assertEquals("wrong size", 1, types.length);
+ IType type = types[0];
+ IMethod[] methods = type.getMethods();
+ assertEquals("wrong size", 2, methods.length);
+ IMethod method = methods[1];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, sourceRange.getOffset() + sourceRange.getLength() / 2, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 2);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("Wrong size", 2, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 1);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ block = methodDeclaration.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=40474
+ */
+ public void test0487() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0487", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType[] types = sourceUnit.getTypes();
+ assertNotNull(types);
+ assertEquals("wrong size", 1, types.length);
+ IType type = types[0];
+ IMethod[] methods = type.getMethods();
+ assertEquals("wrong size", 3, methods.length);
+ IMethod method = methods[1];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, sourceRange.getOffset() + sourceRange.getLength() / 2, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 5);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("Wrong size", 2, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 4);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ block = methodDeclaration.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Wrong name", "field", fragment.getName().getIdentifier());
+ assertNotNull("No initializer", expression);
+
+ node = getASTNode((CompilationUnit) result, 0, 1);
+ assertTrue("Not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ expression = fragment.getInitializer();
+ assertEquals("Wrong name", "i", fragment.getName().getIdentifier());
+ assertNotNull("No initializer", expression);
+
+ node = getASTNode((CompilationUnit) result, 0, 2);
+ assertTrue("Not an initializer", node.getNodeType() == ASTNode.INITIALIZER); //$NON-NLS-1$
+ Initializer initializer = (Initializer) node;
+ assertEquals("Not static", Modifier.NONE, initializer.getModifiers());
+ block = initializer.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 3);
+ assertTrue("Not an initializer", node.getNodeType() == ASTNode.INITIALIZER); //$NON-NLS-1$
+ initializer = (Initializer) node;
+ assertEquals("Not static", Modifier.STATIC, initializer.getModifiers());
+ block = initializer.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 6);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ block = methodDeclaration.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=40474
+ */
+ public void test0488() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0488", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType[] types = sourceUnit.getTypes();
+ assertNotNull(types);
+ assertEquals("wrong size", 1, types.length);
+ IType type = types[0];
+ IInitializer[] initializers = type.getInitializers();
+ assertEquals("wrong size", 2, initializers.length);
+ IInitializer init = initializers[1];
+ ISourceRange sourceRange = init.getSourceRange();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, sourceRange.getOffset() + sourceRange.getLength() / 2, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 5);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 4);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ block = methodDeclaration.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Wrong name", "field", fragment.getName().getIdentifier());
+ assertNotNull("No initializer", expression);
+
+ node = getASTNode((CompilationUnit) result, 0, 1);
+ assertTrue("Not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ expression = fragment.getInitializer();
+ assertEquals("Wrong name", "i", fragment.getName().getIdentifier());
+ assertNotNull("No initializer", expression);
+
+ node = getASTNode((CompilationUnit) result, 0, 2);
+ assertTrue("Not an initializer", node.getNodeType() == ASTNode.INITIALIZER); //$NON-NLS-1$
+ Initializer initializer = (Initializer) node;
+ assertEquals("Not static", Modifier.NONE, initializer.getModifiers());
+ block = initializer.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 3);
+ assertTrue("Not an initializer", node.getNodeType() == ASTNode.INITIALIZER); //$NON-NLS-1$
+ initializer = (Initializer) node;
+ assertEquals("Not static", Modifier.STATIC, initializer.getModifiers());
+ block = initializer.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 6);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ block = methodDeclaration.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+ }
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=40804
+ */
+ public void test0489() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0489", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ assertNull("Got a type binding", typeDeclaration.resolveBinding());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=40804
+ */
+ public void test0490() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0490", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=42647
+ */
+ public void test0491() throws JavaModelException {
+ Hashtable options = JavaCore.getOptions();
+ Hashtable newOptions = JavaCore.getOptions();
+ try {
+ newOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4);
+ JavaCore.setOptions(newOptions);
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0491", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertTrue("not an assert statement", node.getNodeType() == ASTNode.ASSERT_STATEMENT); //$NON-NLS-1$
+ AssertStatement assertStatement = (AssertStatement) node;
+ Expression expression = assertStatement.getExpression();
+ assertTrue("not a parenthesized expression", expression.getNodeType() == ASTNode.PARENTHESIZED_EXPRESSION); //$NON-NLS-1$
+ checkSourceRange(expression, "(loginName != null)", source);
+ } finally {
+ JavaCore.setOptions(options);
+ }
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=42647
+ */
+ public void test0492() throws JavaModelException {
+ Hashtable options = JavaCore.getOptions();
+ Hashtable newOptions = JavaCore.getOptions();
+ try {
+ newOptions.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4);
+ JavaCore.setOptions(newOptions);
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0492", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertTrue("not an assert statement", node.getNodeType() == ASTNode.ASSERT_STATEMENT); //$NON-NLS-1$
+ AssertStatement assertStatement = (AssertStatement) node;
+ Expression expression = assertStatement.getExpression();
+ checkSourceRange(expression, "loginName != null", source);
+ } finally {
+ JavaCore.setOptions(options);
+ }
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=42839
+ */
+ public void test0493() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0493", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertTrue("not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ Type type = fieldDeclaration.getType();
+ checkSourceRange(type, "Class[][]", source);
+ assertTrue("not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ Type componentType = arrayType.getComponentType();
+ assertTrue("not an array type", componentType.isArrayType()); //$NON-NLS-1$
+ checkSourceRange(componentType, "Class[]", source);
+ arrayType = (ArrayType) componentType;
+ componentType = arrayType.getComponentType();
+ assertTrue("is an array type", !componentType.isArrayType()); //$NON-NLS-1$
+ checkSourceRange(componentType, "Class", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=42839
+ */
+ public void test0494() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0494", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertTrue("not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ Type type = fieldDeclaration.getType();
+ checkSourceRange(type, "Class[][][]", source);
+ assertTrue("not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ Type componentType = arrayType.getComponentType();
+ assertTrue("not an array type", componentType.isArrayType()); //$NON-NLS-1$
+ checkSourceRange(componentType, "Class[][]", source);
+ arrayType = (ArrayType) componentType;
+ componentType = arrayType.getComponentType();
+ assertTrue("not an array type", componentType.isArrayType()); //$NON-NLS-1$
+ checkSourceRange(componentType, "Class[]", source);
+ arrayType = (ArrayType) componentType;
+ componentType = arrayType.getComponentType();
+ assertTrue("is an array type", !componentType.isArrayType()); //$NON-NLS-1$
+ checkSourceRange(componentType, "Class", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=42839
+ */
+ public void test0495() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0495", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertTrue("not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ Type type = fieldDeclaration.getType();
+ checkSourceRange(type, "Class[][]", source);
+ assertTrue("not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ Type componentType = arrayType.getComponentType();
+ assertTrue("not an array type", componentType.isArrayType()); //$NON-NLS-1$
+ checkSourceRange(componentType, "Class[]", source);
+ arrayType = (ArrayType) componentType;
+ componentType = arrayType.getComponentType();
+ assertTrue("is an array type", !componentType.isArrayType()); //$NON-NLS-1$
+ checkSourceRange(componentType, "Class", source);
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ assertEquals("wrong extra dimension", 1, fragment.getExtraDimensions());
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=42839
+ */
+ public void test0496() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0496", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertTrue("not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ Type type = fieldDeclaration.getType();
+ checkSourceRange(type, "Class[][][][]", source);
+ assertTrue("not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ Type componentType = arrayType.getComponentType();
+ assertTrue("not an array type", componentType.isArrayType()); //$NON-NLS-1$
+ checkSourceRange(componentType, "Class[][][]", source);
+ arrayType = (ArrayType) componentType;
+ componentType = arrayType.getComponentType();
+ assertTrue("not an array type", componentType.isArrayType()); //$NON-NLS-1$
+ checkSourceRange(componentType, "Class[][]", source);
+ arrayType = (ArrayType) componentType;
+ componentType = arrayType.getComponentType();
+ assertTrue("not an array type", componentType.isArrayType()); //$NON-NLS-1$
+ checkSourceRange(componentType, "Class[]", source);
+ arrayType = (ArrayType) componentType;
+ componentType = arrayType.getComponentType();
+ assertTrue("is an array type", !componentType.isArrayType()); //$NON-NLS-1$
+ checkSourceRange(componentType, "Class", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=42839
+ */
+ public void test0497() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0497", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$<
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertTrue("not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ Type type = fieldDeclaration.getType();
+ checkSourceRange(type, "Class[]", source);
+ assertTrue("not an array type", type.isArrayType()); //$NON-NLS-1$
+ ArrayType arrayType = (ArrayType) type;
+ Type componentType = arrayType.getComponentType();
+ assertTrue("is an array type", !componentType.isArrayType()); //$NON-NLS-1$
+ checkSourceRange(componentType, "Class", source);
+ }
+
+ /**
+ */
+ public void test0498() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0498", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=45199
+ */
+ public void test0499() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0499", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0, 1);
+ assertNotNull(node);
+ assertTrue("Not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ Expression expression = ((ExpressionStatement) node).getExpression();
+ assertTrue("Not an assignment", expression.getNodeType() == ASTNode.ASSIGNMENT); //$NON-NLS-1$
+ Assignment assignment = (Assignment) expression;
+ Expression expression2 = assignment.getRightHandSide();
+ assertTrue("Not an infix expression", expression2.getNodeType() == ASTNode.INFIX_EXPRESSION); //$NON-NLS-1$
+ InfixExpression infixExpression = (InfixExpression) expression2;
+ Expression expression3 = infixExpression.getLeftOperand();
+ assertTrue("Not a simple name", expression3.getNodeType() == ASTNode.SIMPLE_NAME); //$NON-NLS-1$
+ ITypeBinding binding = expression3.resolveTypeBinding();
+ assertNotNull("No binding", binding);
+ Expression expression4 = assignment.getLeftHandSide();
+ assertTrue("Not a simple name", expression4.getNodeType() == ASTNode.SIMPLE_NAME); //$NON-NLS-1$
+ ITypeBinding binding2 = expression4.resolveTypeBinding();
+ assertNotNull("No binding", binding2);
+ assertTrue("Should be the same", binding == binding2);
+ }
+
+ /**
+ * Test for bug 45436 fix.
+ * When this bug happened, the first assertion was false (2 problems found).
+ * @see <a href="http://bugs.eclipse.org/bugs/show_bug.cgi?id=45436">bug 45436</a>
+ * @throws JavaModelException
+ */
+ public void test0500() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0500", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IJavaProject project = sourceUnit.getJavaProject();
+ Map originalOptions = project.getOptions(false);
+ try {
+ project.setOption(JavaCore.COMPILER_PB_INVALID_JAVADOC, JavaCore.ERROR);
+ project.setOption(JavaCore.COMPILER_PB_MISSING_JAVADOC_TAGS, JavaCore.ERROR);
+ project.setOption(JavaCore.COMPILER_PB_MISSING_JAVADOC_COMMENTS, JavaCore.ERROR);
+ CompilationUnit result = (CompilationUnit)runConversion(AST.JLS3, sourceUnit, true);
+ IProblem[] problems= result.getProblems();
+ assertTrue(problems.length == 1);
+ assertEquals("Invalid warning", "Javadoc: Missing tag for parameter a", problems[0].getMessage());
+ } finally {
+ project.setOptions(originalOptions);
+ }
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46012
+ */
+ public void test0501() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0501", "JavaEditor.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ assertNotNull(result);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46013
+ */
+ public void test0502a() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0502", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(AST.JLS3, sourceUnit, true);
+
+ // 'i' in initializer
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement)getASTNode(unit, 0, 0, 0);
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) variableDeclarationStatement.fragments().get(0);
+ IVariableBinding localBinding = fragment.resolveBinding();
+ assertEquals("Unexpected key", "Ltest0502/A;#0#i", localBinding.getKey()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46013
+ */
+ public void test0502b() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0502", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(AST.JLS3, sourceUnit, true);
+
+ // 'j' in 'then' block in initializer
+ IfStatement ifStatement = (IfStatement) getASTNode(unit, 0, 0, 1);
+ Block block = (Block)ifStatement.getThenStatement();
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) block.statements().get(0);
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) variableDeclarationStatement.fragments().get(0);
+ IVariableBinding localBinding = fragment.resolveBinding();
+ assertEquals("Unexpected key", "Ltest0502/A;#0#0#j", localBinding.getKey()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46013
+ */
+ public void test0502c() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0502", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(AST.JLS3, sourceUnit, true);
+
+ // 'i' in 'foo()'
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement)getASTNode(unit, 0, 1, 0);
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) variableDeclarationStatement.fragments().get(0);
+ IVariableBinding localBinding = fragment.resolveBinding();
+ assertEquals("Unexpected key", "Ltest0502/A;.foo()V#i", localBinding.getKey()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46013
+ */
+ public void test0502d() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0502", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(AST.JLS3, sourceUnit, true);
+
+ // 'j' in 'then' block in 'foo()'
+ IfStatement ifStatement = (IfStatement) getASTNode(unit, 0, 1, 1);
+ Block block = (Block)ifStatement.getThenStatement();
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) block.statements().get(0);
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) variableDeclarationStatement.fragments().get(0);
+ IVariableBinding localBinding = fragment.resolveBinding();
+ assertEquals("Unexpected key", "Ltest0502/A;.foo()V#0#j", localBinding.getKey()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46013
+ */
+ public void test0502e() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0502", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(AST.JLS3, sourceUnit, true);
+
+ // 'j' in 'else' block in 'foo()'
+ IfStatement ifStatement = (IfStatement) getASTNode(unit, 0, 1, 1);
+ Block block = (Block)ifStatement.getElseStatement();
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) block.statements().get(0);
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) variableDeclarationStatement.fragments().get(0);
+ IVariableBinding localBinding = fragment.resolveBinding();
+ assertEquals("Unexpected key", "Ltest0502/A;.foo()V#1#j", localBinding.getKey()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46013
+ */
+ public void test0502f() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0502", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(AST.JLS3, sourceUnit, true);
+
+ // first 'new Object(){...}' in 'foo()'
+ ExpressionStatement expressionStatement = (ExpressionStatement) getASTNode(unit, 0, 1, 2);
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expressionStatement.getExpression();
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ ITypeBinding typeBinding = anonymousClassDeclaration.resolveBinding();
+ assertEquals("Unexpected key", "Ltest0502/A$182;", typeBinding.getKey()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46013
+ */
+ public void test0502g() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0502", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(AST.JLS3, sourceUnit, true);
+
+ // 'B' in 'foo()'
+ TypeDeclarationStatement typeDeclarationStatement = (TypeDeclarationStatement) getASTNode(unit, 0, 1, 3);
+ AbstractTypeDeclaration typeDeclaration = typeDeclarationStatement.getDeclaration();
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertEquals("Unexpected key", "Ltest0502/A$206$B;", typeBinding.getKey()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46013
+ */
+ public void test0502h() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0502", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(AST.JLS3, sourceUnit, true);
+
+ // second 'new Object(){...}' in 'foo()'
+ ExpressionStatement expressionStatement = (ExpressionStatement) getASTNode(unit, 0, 1, 4);
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expressionStatement.getExpression();
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ ITypeBinding typeBinding = anonymousClassDeclaration.resolveBinding();
+ assertEquals("Unexpected key", "Ltest0502/A$255;", typeBinding.getKey()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46013
+ */
+ public void test0502i() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0502", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(AST.JLS3, sourceUnit, true);
+
+ // 'field' in 'B' in 'foo()'
+ TypeDeclarationStatement typeDeclarationStatement = (TypeDeclarationStatement) getASTNode(unit, 0, 1, 3);
+ AbstractTypeDeclaration abstractTypeDeclaration = typeDeclarationStatement.getDeclaration();
+ assertEquals("Wrong type", abstractTypeDeclaration.getNodeType(), ASTNode.TYPE_DECLARATION);
+ TypeDeclaration typeDeclaration = (TypeDeclaration) abstractTypeDeclaration;
+ FieldDeclaration fieldDeclaration = typeDeclaration.getFields()[0];
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fieldDeclaration.fragments().get(0);
+ IVariableBinding fieldBinding = fragment.resolveBinding();
+ assertEquals("Unexpected key", "Ltest0502/A$206$B;.field)I", fieldBinding.getKey()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46013
+ */
+ public void test0502j() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0502", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(AST.JLS3, sourceUnit, true);
+
+ // 'bar()' in 'B' in 'foo()'
+ TypeDeclarationStatement typeDeclarationStatement = (TypeDeclarationStatement) getASTNode(unit, 0, 1, 3);
+ AbstractTypeDeclaration abstractTypeDeclaration = typeDeclarationStatement.getDeclaration();
+ assertEquals("Wrong type", abstractTypeDeclaration.getNodeType(), ASTNode.TYPE_DECLARATION);
+ TypeDeclaration typeDeclaration = (TypeDeclaration) abstractTypeDeclaration;
+ MethodDeclaration methodDeclaration = typeDeclaration.getMethods()[0];
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ assertEquals("Unexpected key", "Ltest0502/A$206$B;.bar()V", methodBinding.getKey()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46057
+ */
+ public void test0503a() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0503", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(AST.JLS3, sourceUnit, true);
+
+ // top level type A
+ TypeDeclaration type = (TypeDeclaration)getASTNode(unit, 0);
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertEquals("Unexpected binary name", "test0503.A", typeBinding.getBinaryName()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46057
+ */
+ public void test0503b() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0503", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(AST.JLS3, sourceUnit, true);
+
+ // member type B in A
+ TypeDeclaration type = (TypeDeclaration)getASTNode(unit, 0, 0);
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertEquals("Unexpected binary name", "test0503.A$B", typeBinding.getBinaryName()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46057
+ */
+ public void test0503c() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0503", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(AST.JLS3, sourceUnit, true);
+
+ // local type E in foo() in A
+ TypeDeclarationStatement typeDeclarationStatement = (TypeDeclarationStatement) getASTNode(unit, 0, 1, 0);
+ AbstractTypeDeclaration typeDeclaration = typeDeclarationStatement.getDeclaration();
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertEquals("Unexpected binary name", "test0503.A$1$E", typeBinding.getBinaryName()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46057
+ */
+ public void test0503d() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0503", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(AST.JLS3, sourceUnit, true);
+
+ // anonymous type new Object() {...} in foo() in A
+ ExpressionStatement expressionStatement = (ExpressionStatement) getASTNode(unit, 0, 1, 1);
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expressionStatement.getExpression();
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ ITypeBinding typeBinding = anonymousClassDeclaration.resolveBinding();
+ assertEquals("Unexpected binary name", "test0503.A$2", typeBinding.getBinaryName()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46057
+ */
+ public void test0503e() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0503", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(AST.JLS3, sourceUnit, true);
+
+ // type F in anonymous type new Object() {...} in foo() in A
+ ExpressionStatement expressionStatement = (ExpressionStatement) getASTNode(unit, 0, 1, 1);
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expressionStatement.getExpression();
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ TypeDeclaration type = (TypeDeclaration) anonymousClassDeclaration.bodyDeclarations().get(0);
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertEquals("Unexpected binary name", "test0503.A$2$F", typeBinding.getBinaryName()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46057
+ */
+ public void test0503f() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0503", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(AST.JLS3, sourceUnit, true);
+
+ // local type C in bar() in B in A
+ MethodDeclaration method = (MethodDeclaration) getASTNode(unit, 0, 0, 0);
+ TypeDeclarationStatement typeDeclarationStatement = (TypeDeclarationStatement) method.getBody().statements().get(0);
+ AbstractTypeDeclaration typeDeclaration = typeDeclarationStatement.getDeclaration();
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertEquals("Unexpected binary name", "test0503.A$1$C", typeBinding.getBinaryName()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46057
+ */
+ public void test0503g() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0503", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(AST.JLS3, sourceUnit, true);
+
+ // anonymous type new Object() {...} in bar() in B in A
+ MethodDeclaration method = (MethodDeclaration) getASTNode(unit, 0, 0, 0);
+ ExpressionStatement expressionStatement = (ExpressionStatement) method.getBody().statements().get(1);
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expressionStatement.getExpression();
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ ITypeBinding typeBinding = anonymousClassDeclaration.resolveBinding();
+ assertEquals("Unexpected binary name", "test0503.A$1", typeBinding.getBinaryName()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46057
+ */
+ public void test0503h() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0503", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(AST.JLS3, sourceUnit, true);
+
+ // type D in anonymous type new Object() {...} in bar() in B in A
+ MethodDeclaration method = (MethodDeclaration) getASTNode(unit, 0, 0, 0);
+ ExpressionStatement expressionStatement = (ExpressionStatement) method.getBody().statements().get(1);
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expressionStatement.getExpression();
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ TypeDeclaration type = (TypeDeclaration) anonymousClassDeclaration.bodyDeclarations().get(0);
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertEquals("Unexpected binary name", "test0503.A$1$D", typeBinding.getBinaryName()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=46057
+ */
+ public void test0503i() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0503", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ CompilationUnit unit = (CompilationUnit)runConversion(AST.JLS3, sourceUnit, true);
+
+ // unreachable type G in foo() in A
+ IfStatement ifStatement = (IfStatement) getASTNode(unit, 0, 1, 2);
+ Block block = (Block)ifStatement.getThenStatement();
+ TypeDeclarationStatement typeDeclarationStatement = (TypeDeclarationStatement) block.statements().get(0);
+ AbstractTypeDeclaration typeDeclaration = typeDeclarationStatement.getDeclaration();
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertEquals("Unexpected binary name", null, typeBinding.getBinaryName()); //$NON-NLS-1$
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=47396
+ */
+ public void test0504() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0504", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 1, 0);
+ assertNotNull(node);
+ assertTrue("Not a constructor declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration declaration = (MethodDeclaration) node;
+ assertTrue("A constructor", !declaration.isConstructor());
+ checkSourceRange(declaration, "public method(final int parameter);", source);
+ }
+
+ /**
+ * http://bugs.eclipse.org/bugs/show_bug.cgi?id=47396
+ */
+ public void test0505() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0505", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 1, 0);
+ assertNotNull(node);
+ assertTrue("Not a constructor declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration declaration = (MethodDeclaration) node;
+ assertTrue("A constructor", !declaration.isConstructor());
+ checkSourceRange(declaration, "public method(final int parameter) { }", source);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=46699
+ */
+ public void test0506() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0506", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Wrong number of problems", 0, (unit).getProblems().length); //$NON-NLS-1$
+ assertNotNull(node);
+ assertTrue("Not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ assertTrue("Not a class instance creation", expressionStatement.getExpression().getNodeType() == ASTNode.CLASS_INSTANCE_CREATION); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expressionStatement.getExpression();
+ IMethodBinding binding = classInstanceCreation.resolveConstructorBinding();
+ assertFalse("is synthetic", binding.isSynthetic());
+ assertTrue("is default constructor", binding.isDefaultConstructor());
+ assertNull("Has a declaring node", unit.findDeclaringNode(binding));
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=46699
+ */
+ public void test0507() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0507", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Wrong number of problems", 0, (unit).getProblems().length); //$NON-NLS-1$
+ assertNotNull(node);
+ assertTrue("Not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ assertTrue("Not a class instance creation", expressionStatement.getExpression().getNodeType() == ASTNode.CLASS_INSTANCE_CREATION); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expressionStatement.getExpression();
+ IMethodBinding binding = classInstanceCreation.resolveConstructorBinding();
+ assertFalse("is synthetic", binding.isSynthetic());
+ assertTrue("is default constructor", binding.isDefaultConstructor());
+ assertNull("Has a declaring node", unit.findDeclaringNode(binding));
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=46699
+ */
+ public void test0508() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0508", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ ASTNode node = getASTNode(unit, 0, 1, 0);
+ assertEquals("Wrong number of problems", 0, (unit).getProblems().length); //$NON-NLS-1$
+ assertNotNull(node);
+ assertTrue("Not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ assertTrue("Not a class instance creation", expressionStatement.getExpression().getNodeType() == ASTNode.CLASS_INSTANCE_CREATION); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expressionStatement.getExpression();
+ IMethodBinding binding = classInstanceCreation.resolveConstructorBinding();
+ assertFalse("is synthetic", binding.isSynthetic());
+ assertTrue("not a default constructor", !binding.isDefaultConstructor());
+ assertNotNull("Has no declaring node", unit.findDeclaringNode(binding));
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=46699
+ */
+ public void test0509() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0509", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Wrong number of problems", 0, (unit).getProblems().length); //$NON-NLS-1$
+ assertNotNull(node);
+ assertTrue("Not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ assertTrue("Not a class instance creation", expressionStatement.getExpression().getNodeType() == ASTNode.CLASS_INSTANCE_CREATION); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expressionStatement.getExpression();
+ IMethodBinding binding = classInstanceCreation.resolveConstructorBinding();
+ assertFalse("is synthetic", binding.isSynthetic());
+ assertTrue("not a default constructor", !binding.isDefaultConstructor());
+ assertNull("Has a declaring node", unit.findDeclaringNode(binding));
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=46699
+ */
+ public void test0510() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0510", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Wrong number of problems", 0, (unit).getProblems().length); //$NON-NLS-1$
+ assertNotNull(node);
+ assertTrue("Not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ assertTrue("Not a class instance creation", expressionStatement.getExpression().getNodeType() == ASTNode.CLASS_INSTANCE_CREATION); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expressionStatement.getExpression();
+ IMethodBinding binding = classInstanceCreation.resolveConstructorBinding();
+ assertFalse("is synthetic", binding.isSynthetic());
+ assertFalse("is default constructor", binding.isDefaultConstructor());
+ assertNull("Has a declaring node", unit.findDeclaringNode(binding));
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=46699
+ */
+ public void test0511() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0511", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Wrong number of problems", 0, (unit).getProblems().length); //$NON-NLS-1$
+ assertNotNull(node);
+ assertTrue("Not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ assertTrue("Not a class instance creation", expressionStatement.getExpression().getNodeType() == ASTNode.CLASS_INSTANCE_CREATION); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expressionStatement.getExpression();
+ IMethodBinding binding = classInstanceCreation.resolveConstructorBinding();
+ assertFalse("is synthetic", binding.isSynthetic());
+ assertFalse("is default constructor", binding.isDefaultConstructor());
+ assertNull("Has a declaring node", unit.findDeclaringNode(binding));
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=47326
+ */
+ public void test0512() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0512", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertEquals("Wrong number of problems", 2, unit.getProblems().length); //$NON-NLS-1$
+ assertNotNull(node);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration declaration = (MethodDeclaration) node;
+ assertTrue("Not a constructor", declaration.isConstructor());
+ checkSourceRange(declaration, "public A();", source);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=49429
+ */
+ public void test0513() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0513", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$
+ }
+
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=48502
+ */
+ public void test0514() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0514", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=49204
+ */
+ public void test0515() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0515", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a if statement", node.getNodeType() == ASTNode.IF_STATEMENT);
+ IfStatement ifStatement = (IfStatement) node;
+ assertTrue("not an empty statement", ifStatement.getThenStatement().getNodeType() == ASTNode.EMPTY_STATEMENT);
+ checkSourceRange(ifStatement.getThenStatement(), ";", source);
+ Statement statement = ifStatement.getElseStatement();
+ assertTrue("not a if statement", statement.getNodeType() == ASTNode.IF_STATEMENT);
+ ifStatement = (IfStatement) statement;
+ assertTrue("not an empty statement", ifStatement.getThenStatement().getNodeType() == ASTNode.EMPTY_STATEMENT);
+ checkSourceRange(ifStatement.getThenStatement(), ";", source);
+ Statement statement2 = ifStatement.getElseStatement();
+ assertTrue("not an empty statement", statement2.getNodeType() == ASTNode.EMPTY_STATEMENT);
+ checkSourceRange(statement2, ";", source);
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=48489
+ */
+ public void test0516() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0516", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION);
+ MethodDeclaration declaration = (MethodDeclaration) node;
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
+ parser.setSource(source);
+ parser.setSourceRange(declaration.getStartPosition(), declaration.getLength());
+ parser.setCompilerOptions(JavaCore.getOptions());
+ ASTNode result2 = parser.createAST(null);
+ assertNotNull("No node", result2);
+ assertTrue("not a type declaration", result2.getNodeType() == ASTNode.TYPE_DECLARATION);
+ TypeDeclaration typeDeclaration = (TypeDeclaration) result2;
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("wrong size", 1, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue(declaration.subtreeMatch(new ASTMatcher(), bodyDeclaration));
+ ASTNode root = bodyDeclaration.getRoot();
+ assertNotNull("No root", root);
+ assertTrue("not a compilation unit", root.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) root;
+ assertEquals("wrong problem size", 0, compilationUnit.getProblems().length);
+ assertNotNull("No comments", compilationUnit.getCommentList());
+ assertEquals("Wrong size", 3, compilationUnit.getCommentList().size());
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=48489
+ */
+ public void test0517() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0517", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ assertNotNull("No comments", unit.getCommentList());
+ assertEquals("Wrong size", 3, unit.getCommentList().size());
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION);
+ FieldDeclaration declaration = (FieldDeclaration) node;
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
+ parser.setSource(source);
+ parser.setSourceRange(declaration.getStartPosition(), declaration.getLength());
+ parser.setCompilerOptions(JavaCore.getOptions());
+ ASTNode result2 = parser.createAST(null);
+ assertNotNull("No node", result2);
+ assertTrue("not a type declaration", result2.getNodeType() == ASTNode.TYPE_DECLARATION);
+ TypeDeclaration typeDeclaration = (TypeDeclaration) result2;
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("wrong size", 1, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue(declaration.subtreeMatch(new ASTMatcher(), bodyDeclaration));
+ ASTNode root = bodyDeclaration.getRoot();
+ assertNotNull("No root", root);
+ assertTrue("not a compilation unit", root.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) root;
+ assertEquals("wrong problem size", 0, compilationUnit.getProblems().length);
+ assertNotNull("No comments", compilationUnit.getCommentList());
+ assertEquals("Wrong size", 2, compilationUnit.getCommentList().size());
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=48489
+ */
+ public void test0518() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0518", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not an initializer", node.getNodeType() == ASTNode.INITIALIZER);
+ Initializer declaration = (Initializer) node;
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
+ parser.setSource(source);
+ parser.setSourceRange(declaration.getStartPosition(), declaration.getLength());
+ parser.setCompilerOptions(JavaCore.getOptions());
+ ASTNode result2 = parser.createAST(null);
+ assertNotNull("No node", result2);
+ assertTrue("not a type declaration", result2.getNodeType() == ASTNode.TYPE_DECLARATION);
+ TypeDeclaration typeDeclaration = (TypeDeclaration) result2;
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("wrong size", 1, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue(declaration.subtreeMatch(new ASTMatcher(), bodyDeclaration));
+ ASTNode root = bodyDeclaration.getRoot();
+ assertNotNull("No root", root);
+ assertTrue("not a compilation unit", root.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) root;
+ assertEquals("wrong problem size", 0, compilationUnit.getProblems().length);
+ assertNotNull("No comments", compilationUnit.getCommentList());
+ assertEquals("Wrong size", 3, compilationUnit.getCommentList().size());
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=48489
+ */
+ public void test0519() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0519", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ assertNotNull("No comments", unit.getCommentList());
+ assertEquals("Wrong size", 2, unit.getCommentList().size());
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertNotNull("No node", node);
+ ASTNode statement = node;
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_STATEMENTS);
+ parser.setSource(source);
+ parser.setSourceRange(statement.getStartPosition(), statement.getLength());
+ parser.setCompilerOptions(JavaCore.getOptions());
+ ASTNode result2 = parser.createAST(null);
+ assertNotNull("No node", result2);
+ assertTrue("not a block", result2.getNodeType() == ASTNode.BLOCK);
+ Block block = (Block) result2;
+ List statements = block.statements();
+ assertEquals("wrong size", 1, statements.size());
+ Statement statement2 = (Statement) statements.get(0);
+ assertTrue(statement.subtreeMatch(new ASTMatcher(), statement2));
+ ASTNode root = statement2.getRoot();
+ assertNotNull("No root", root);
+ assertTrue("not a compilation unit", root.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) root;
+ assertEquals("wrong problem size", 0, compilationUnit.getProblems().length);
+ assertNotNull("No comments", compilationUnit.getCommentList());
+ assertEquals("Wrong size", 1, compilationUnit.getCommentList().size());
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=48489
+ */
+ public void test0520() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0520", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ assertNotNull("No comments", unit.getCommentList());
+ assertEquals("Wrong size", 2, unit.getCommentList().size());
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a block", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT);
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_EXPRESSION);
+ parser.setSource(source);
+ parser.setSourceRange(expression.getStartPosition(), expression.getLength());
+ parser.setCompilerOptions(JavaCore.getOptions());
+ ASTNode result2 = parser.createAST(null);
+ assertNotNull("No node", result2);
+ assertTrue("not a method invocation", result2.getNodeType() == ASTNode.METHOD_INVOCATION);
+ assertTrue(expression.subtreeMatch(new ASTMatcher(), result2));
+ ASTNode root = result2.getRoot();
+ assertNotNull("No root", root);
+ assertTrue("not a compilation unit", root.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) root;
+ assertEquals("wrong problem size", 0, compilationUnit.getProblems().length);
+ assertNotNull("No comments", compilationUnit.getCommentList());
+ assertEquals("Wrong size", 1, compilationUnit.getCommentList().size());
+ }
+ /**
+ * Ensure an OperationCanceledException is correcly thrown when progress monitor is canceled
+ * @deprecated using deprecated code
+ */
+ public void test0521() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0521", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+
+ // count the number of time isCanceled() is called when converting this source unit
+ WorkingCopyOwner owner = new WorkingCopyOwner() {};
+ CancelCounter counter = new CancelCounter();
+ ASTParser parser = ASTParser.newParser(AST.JLS2);
+ parser.setSource(sourceUnit);
+ parser.setResolveBindings(true);
+ parser.setWorkingCopyOwner(owner);
+ parser.createAST(counter);
+
+ // throw an OperatonCanceledException at each point isCanceled() is called
+ for (int i = 0; i < counter.count; i++) {
+ boolean gotException = false;
+ try {
+ parser = ASTParser.newParser(AST.JLS2);
+ parser.setSource(sourceUnit);
+ parser.setResolveBindings(true);
+ parser.setWorkingCopyOwner(owner);
+ parser.createAST(new Canceler(i));
+ } catch (OperationCanceledException e) {
+ gotException = true;
+ }
+ assertTrue("Should get an OperationCanceledException (" + i + ")", gotException);
+ }
+
+ // last should not throw an OperationCanceledException
+ parser = ASTParser.newParser(AST.JLS2);
+ parser.setSource(sourceUnit);
+ parser.setResolveBindings(true);
+ parser.setWorkingCopyOwner(owner);
+ parser.createAST(new Canceler(counter.count));
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=48292
+ */
+ public void test0522() throws JavaModelException {
+ IClassFile classFile = getClassFile("Converter" , "bins", "test0522", "Test.class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertNotNull(classFile);
+ assertNotNull(classFile.getSource());
+ IType type = classFile.getType();
+ assertNotNull(type);
+ IMethod[] methods = type.getMethods();
+ assertNotNull(methods);
+ assertEquals("wrong size", 2, methods.length);
+ IMethod method = methods[1];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(AST.JLS3, classFile, sourceRange.getOffset() + sourceRange.getLength() / 2, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 1, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("wrong name", "test", methodDeclaration.getName().getIdentifier());
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ assertNotNull(methodBinding);
+ List statements = ((MethodDeclaration) node).getBody().statements();
+ assertEquals("wrong size", 2, statements.size());
+ ASTNode node2 = (ASTNode) statements.get(1);
+ assertNotNull(node2);
+ assertTrue("Not an expression statement", node2.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node2;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ assertTrue("Not a simple name", expression2.getNodeType() == ASTNode.SIMPLE_NAME); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) expression2;
+ IBinding binding = simpleName.resolveBinding();
+ assertNotNull("No binding", binding); //$NON-NLS-1$
+ assertTrue("wrong type", binding.getKind() == IBinding.VARIABLE); //$NON-NLS-1$
+ IVariableBinding variableBinding = (IVariableBinding) binding;
+ assertEquals("Wrong name", "a", variableBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ SimpleName simpleName2 = methodInvocation.getName();
+ assertEquals("Wrong name", "clone", simpleName2.getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ IBinding binding2 = simpleName2.resolveBinding();
+ assertNotNull("no binding2", binding2); //$NON-NLS-1$
+ assertTrue("Wrong type", binding2.getKind() == IBinding.METHOD); //$NON-NLS-1$
+ IMethodBinding methodBinding2 = (IMethodBinding) binding2;
+ assertEquals("Wrong name", "clone", methodBinding2.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=48292
+ */
+ public void test0523() throws JavaModelException {
+ IClassFile classFile = getClassFile("Converter" , "bins", "test0523", "Test.class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertNotNull(classFile);
+ assertNotNull(classFile.getSource());
+ IType type = classFile.getType();
+ assertNotNull(type);
+ IMethod[] methods = type.getMethods();
+ assertNotNull(methods);
+ assertEquals("wrong size", 2, methods.length);
+ IMethod method = methods[1];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(AST.JLS3, classFile, sourceRange.getOffset() + sourceRange.getLength() / 2, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 1, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("wrong name", "test", methodDeclaration.getName().getIdentifier());
+ List statements = ((MethodDeclaration) node).getBody().statements();
+ assertEquals("wrong size", 2, statements.size());
+ ASTNode node2 = (ASTNode) statements.get(1);
+ assertNotNull(node2);
+ assertTrue("Not an expression statement", node2.getNodeType() == ASTNode.EXPRESSION_STATEMENT); //$NON-NLS-1$
+ ExpressionStatement expressionStatement = (ExpressionStatement) node2;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("Not a method invocation", expression.getNodeType() == ASTNode.METHOD_INVOCATION); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ assertTrue("Not a simple name", expression2.getNodeType() == ASTNode.SIMPLE_NAME); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) expression2;
+ IBinding binding = simpleName.resolveBinding();
+ assertNull("No binding", binding); //$NON-NLS-1$
+ SimpleName simpleName2 = methodInvocation.getName();
+ assertEquals("Wrong name", "clone", simpleName2.getIdentifier()); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=48292
+ */
+ public void test0524() throws JavaModelException {
+ IClassFile classFile = getClassFile("Converter" , "bins", "test0524", "A.class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertNotNull(classFile);
+ assertNotNull(classFile.getSource());
+ IType type = classFile.getType();
+ assertNotNull(type);
+ IMethod[] methods = type.getMethods();
+ assertNotNull(methods);
+ assertEquals("wrong size", 2, methods.length);
+ IMethod method = methods[1];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(AST.JLS3, classFile, sourceRange.getOffset() + sourceRange.getLength() / 2, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("wrong name", "test", methodDeclaration.getName().getIdentifier());
+ List statements = ((MethodDeclaration) node).getBody().statements();
+ assertEquals("wrong size", 1, statements.size());
+ ASTNode node2 = (ASTNode) statements.get(0);
+ assertNotNull(node2);
+ assertTrue("Not an variable declaration statement", node2.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=48292
+ */
+ public void test0525() throws JavaModelException {
+ IClassFile classFile = getClassFile("Converter" , "bins", "test0525", "A.class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertNotNull(classFile);
+ assertNotNull(classFile.getSource());
+ IType type = classFile.getType();
+ assertNotNull(type);
+ IMethod[] methods = type.getMethods();
+ assertNotNull(methods);
+ assertEquals("wrong size", 2, methods.length);
+ IMethod method = methods[1];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(AST.JLS3, classFile, sourceRange.getOffset() + sourceRange.getLength() / 2, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("wrong name", "test", methodDeclaration.getName().getIdentifier());
+ List statements = ((MethodDeclaration) node).getBody().statements();
+ assertEquals("wrong size", 1, statements.size());
+ ASTNode node2 = (ASTNode) statements.get(0);
+ assertNotNull(node2);
+ assertTrue("Not an variable declaration statement", node2.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node2;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertTrue("Not a class instance creation", expression.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ ITypeBinding typeBinding = classInstanceCreation.resolveTypeBinding();
+ assertNotNull(typeBinding);
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=48292
+ */
+ public void test0526() throws JavaModelException {
+ IClassFile classFile = getClassFile("Converter" , "bins", "test0526", "A.class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertNotNull(classFile);
+ assertNotNull(classFile.getSource());
+ IType type = classFile.getType();
+ assertNotNull(type);
+ IType[] memberTypes = type.getTypes();
+ assertNotNull(memberTypes);
+ assertEquals("wrong size", 1, memberTypes.length);
+ IType memberType = memberTypes[0];
+ IMethod[] methods = memberType.getMethods();
+ assertEquals("wrong size", 2, methods.length);
+ IMethod method = methods[1];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(AST.JLS3, classFile, sourceRange.getOffset() + sourceRange.getLength() / 2, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("wrong name", "test", methodDeclaration.getName().getIdentifier());
+ List statements = ((MethodDeclaration) node).getBody().statements();
+ assertEquals("wrong size", 1, statements.size());
+ ASTNode node2 = (ASTNode) statements.get(0);
+ assertNotNull(node2);
+ assertTrue("Not an variable declaration statement", node2.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node2;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertTrue("Not a class instance creation", expression.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ ITypeBinding typeBinding = classInstanceCreation.resolveTypeBinding();
+ assertNotNull(typeBinding);
+ assertTrue(typeBinding.isAnonymous());
+ assertEquals("Wrong name", "", typeBinding.getName());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=48292
+ */
+ public void test0527() throws JavaModelException {
+ IClassFile classFile = getClassFile("Converter" , "bins", "test0527", "A.class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertNotNull(classFile);
+ assertNotNull(classFile.getSource());
+ IType type = classFile.getType();
+ assertNotNull(type);
+ IMethod[] methods = type.getMethods();
+ assertEquals("wrong size", 1, methods.length);
+ IMethod method = methods[0];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(AST.JLS3, classFile, sourceRange.getOffset() + sourceRange.getLength() / 2, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertEquals("wrong name", "A", methodDeclaration.getName().getIdentifier());
+ assertTrue("Not a constructor", methodDeclaration.isConstructor());
+ IBinding binding = methodDeclaration.getName().resolveBinding();
+ assertNotNull(binding);
+ assertEquals("Wrong type", IBinding.METHOD, binding.getKind());
+ List statements = ((MethodDeclaration) node).getBody().statements();
+ assertEquals("wrong size", 1, statements.size());
+ ASTNode node2 = (ASTNode) statements.get(0);
+ assertNotNull(node2);
+ assertTrue("Not an variable declaration statement", node2.getNodeType() == ASTNode.VARIABLE_DECLARATION_STATEMENT); //$NON-NLS-1$
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node2;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertTrue("Not a class instance creation", expression.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ ITypeBinding typeBinding = classInstanceCreation.resolveTypeBinding();
+ assertNotNull(typeBinding);
+ assertTrue(typeBinding.isAnonymous());
+ assertEquals("Wrong name", "", typeBinding.getName());
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=48292
+ */
+ public void test0528() throws JavaModelException {
+ IClassFile classFile = getClassFile("Converter" , "bins", "test0528", "A.class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertNotNull(classFile);
+ assertNotNull(classFile.getSource());
+ IType type = classFile.getType();
+ IType[] memberTypes = type.getTypes();
+ assertNotNull(memberTypes);
+ assertEquals("wrong size", 1, memberTypes.length);
+ IType memberType = memberTypes[0];
+ ISourceRange sourceRange = memberType.getSourceRange();
+ ASTNode result = runConversion(AST.JLS3, classFile, sourceRange.getOffset() + sourceRange.getLength() / 2, true);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ assertEquals("wrong name", "B", typeDeclaration.getName().getIdentifier());
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue("Not a method declaration", bodyDeclaration.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size());
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=48292
+ */
+ public void test0529() throws JavaModelException {
+ IClassFile classFile = getClassFile("Converter" , "bins", "test0529", "A.class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertNotNull(classFile);
+ assertNotNull(classFile.getSource());
+ IType type = classFile.getType();
+ IType[] memberTypes = type.getTypes();
+ assertNotNull(memberTypes);
+ assertEquals("wrong size", 1, memberTypes.length);
+ IType memberType = memberTypes[0];
+ ISourceRange sourceRange = memberType.getSourceRange();
+ ASTNode result = runConversion(AST.JLS3, classFile, sourceRange.getOffset() + sourceRange.getLength() / 2, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ assertEquals("wrong name", "B", typeDeclaration.getName().getIdentifier());
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertTrue("Not a method declaration", bodyDeclaration.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=48292
+ */
+ public void test0530() throws JavaModelException {
+ IClassFile classFile = getClassFile("Converter" , "bins", "test0530", "A.class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertNotNull(classFile);
+ assertNotNull(classFile.getSource());
+ IType type = classFile.getType();
+ IMethod[] methods = type.getMethods();
+ assertEquals("wrong size", 3, methods.length);
+ IMethod method = methods[2];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(AST.JLS3, classFile, sourceRange.getOffset() + sourceRange.getLength() / 2, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 2);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("Wrong size", 2, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 1);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ block = methodDeclaration.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=48292
+ */
+ public void test0531() throws JavaModelException {
+ IClassFile classFile = getClassFile("Converter" , "bins", "test0531", "A.class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertNotNull(classFile);
+ assertNotNull(classFile.getSource());
+ IType type = classFile.getType();
+ IMethod[] methods = type.getMethods();
+ assertEquals("wrong size", 5, methods.length);
+ IMethod method = methods[3];
+ ISourceRange sourceRange = method.getSourceRange();
+ ASTNode result = runConversion(AST.JLS3, classFile, sourceRange.getOffset() + sourceRange.getLength() / 2, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 5);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("Wrong size", 2, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 4);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ block = methodDeclaration.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Wrong name", "field", fragment.getName().getIdentifier());
+ assertNotNull("No initializer", expression);
+
+ node = getASTNode((CompilationUnit) result, 0, 1);
+ assertTrue("Not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ expression = fragment.getInitializer();
+ assertEquals("Wrong name", "i", fragment.getName().getIdentifier());
+ assertNotNull("No initializer", expression);
+
+ node = getASTNode((CompilationUnit) result, 0, 2);
+ assertTrue("Not an initializer", node.getNodeType() == ASTNode.INITIALIZER); //$NON-NLS-1$
+ Initializer initializer = (Initializer) node;
+ assertEquals("Not static", Modifier.NONE, initializer.getModifiers());
+ block = initializer.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 3);
+ assertTrue("Not an initializer", node.getNodeType() == ASTNode.INITIALIZER); //$NON-NLS-1$
+ initializer = (Initializer) node;
+ assertEquals("Not static", Modifier.STATIC, initializer.getModifiers());
+ block = initializer.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 6);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ block = methodDeclaration.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=48292
+ */
+ public void test0532() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0488", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType[] types = sourceUnit.getTypes();
+ assertNotNull(types);
+ assertEquals("wrong size", 1, types.length);
+ IType type = types[0];
+ IInitializer[] initializers = type.getInitializers();
+ assertEquals("wrong size", 2, initializers.length);
+ IInitializer init = initializers[1];
+ ISourceRange sourceRange = init.getSourceRange();
+ int position = sourceRange.getOffset() + sourceRange.getLength() / 2;
+
+ IClassFile classFile = getClassFile("Converter" , "bins", "test0532", "A.class"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ assertNotNull(classFile);
+ assertNotNull(classFile.getSource());
+ type = classFile.getType();
+ initializers = type.getInitializers();
+ assertEquals("wrong size", 0, initializers.length);
+ ASTNode result = runConversion(AST.JLS3, classFile, position, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+
+ ASTNode node = getASTNode((CompilationUnit) result, 0, 5);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Block block = methodDeclaration.getBody();
+ List statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 4);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ block = methodDeclaration.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 0);
+ assertTrue("Not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Wrong name", "field", fragment.getName().getIdentifier());
+ assertNotNull("No initializer", expression);
+
+ node = getASTNode((CompilationUnit) result, 0, 1);
+ assertTrue("Not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION); //$NON-NLS-1$
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ expression = fragment.getInitializer();
+ assertEquals("Wrong name", "i", fragment.getName().getIdentifier());
+ assertNotNull("No initializer", expression);
+
+ node = getASTNode((CompilationUnit) result, 0, 2);
+ assertTrue("Not an initializer", node.getNodeType() == ASTNode.INITIALIZER); //$NON-NLS-1$
+ Initializer initializer = (Initializer) node;
+ assertEquals("Not static", Modifier.NONE, initializer.getModifiers());
+ block = initializer.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 3);
+ assertTrue("Not an initializer", node.getNodeType() == ASTNode.INITIALIZER); //$NON-NLS-1$
+ initializer = (Initializer) node;
+ assertEquals("Not static", Modifier.STATIC, initializer.getModifiers());
+ block = initializer.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size());
+
+ node = getASTNode((CompilationUnit) result, 0, 6);
+ assertTrue("Not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION); //$NON-NLS-1$
+ methodDeclaration = (MethodDeclaration) node;
+ block = methodDeclaration.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 0, statements.size());
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=48489
+ * @deprecated using deprecated code
+ */
+ public void test0533() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0533", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a method declaration", node.getNodeType() == ASTNode.METHOD_DECLARATION);
+ MethodDeclaration declaration = (MethodDeclaration) node;
+ ASTParser parser = ASTParser.newParser(AST.JLS2);
+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
+ parser.setSource(source);
+ parser.setSourceRange(declaration.getStartPosition(), declaration.getLength());
+ parser.setCompilerOptions(JavaCore.getOptions());
+ ASTNode result2 = parser.createAST(null);
+ assertNotNull("No node", result2);
+ assertTrue("not a compilation unit", result2.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result2;
+ assertEquals("wrong problem size", 1, compilationUnit.getProblems().length);
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=48489
+ * @deprecated using deprecated code
+ */
+ public void test0534() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0534", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION);
+ FieldDeclaration declaration = (FieldDeclaration) node;
+ ASTParser parser = ASTParser.newParser(AST.JLS2);
+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
+ parser.setSource(source);
+ parser.setSourceRange(declaration.getStartPosition(), declaration.getLength());
+ parser.setCompilerOptions(JavaCore.getOptions());
+ ASTNode result2 = parser.createAST(null);
+ assertNotNull("No node", result2);
+ assertTrue("not a compilation unit", result2.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result2;
+ assertEquals("wrong problem size", 1, compilationUnit.getProblems().length);
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=48489
+ * @deprecated using deprecated code
+ */
+ public void test0535() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0535", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("not an initializer", node.getNodeType() == ASTNode.INITIALIZER);
+ Initializer declaration = (Initializer) node;
+ ASTParser parser = ASTParser.newParser(AST.JLS2);
+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
+ parser.setSource(source);
+ parser.setSourceRange(declaration.getStartPosition(), declaration.getLength());
+ parser.setCompilerOptions(JavaCore.getOptions());
+ ASTNode result2 = parser.createAST(null);
+ assertNotNull("No node", result2);
+ assertTrue("not a compilation unit", result2.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result2;
+ assertEquals("wrong problem size", 1, compilationUnit.getProblems().length);
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=47396
+ */
+ public void test0536() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0536", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ assertNotNull("No compilation unit", result);
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=51089
+ */
+ public void test0537a() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0537", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ assertNotNull("No compilation unit", result);
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=51089
+ */
+ public void test0537b() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0537", "B.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ assertNotNull("No compilation unit", result);
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=51089
+ */
+ public void test0537c() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0537", "C.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ assertNotNull("No compilation unit", result);
+ }
+ /**
+ * Ensures that an AST can be created during reconcile.
+ * @deprecated using deprecated code
+ */
+ public void test0538a() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0538", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ try {
+ sourceUnit.becomeWorkingCopy(null, null);
+ sourceUnit.getBuffer().setContents(
+ "package test0538;\n" +
+ "public class A {\n" +
+ " int i;\n" +
+ "}"
+ );
+ CompilationUnit unit = sourceUnit.reconcile(AST.JLS2, false, null, null);
+ assertNotNull("No level 2 compilation unit", unit);
+ assertEquals("Compilation unit has wrong AST level (2)", AST.JLS2, unit.getAST().apiLevel());
+ // TODO improve test for AST.JLS3
+ } finally {
+ sourceUnit.discardWorkingCopy();
+ }
+ }
+ /*
+ * Ensures that no AST is created during reconcile if not requested.
+ */
+ public void test0538b() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0538", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ try {
+ sourceUnit.becomeWorkingCopy(null);
+ sourceUnit.getBuffer().setContents(
+ "package test0538;\n" +
+ "public class A {\n" +
+ " int i;\n" +
+ "}"
+ );
+ CompilationUnit unit = sourceUnit.reconcile(0, false, null, null);
+ assertNull("Unexpected compilation unit", unit);
+ } finally {
+ sourceUnit.discardWorkingCopy();
+ }
+ }
+ /**
+ * Ensures that no AST is created during reconcile if consistent.
+ * @deprecated using deprecated code
+ */
+ public void test0538c() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0538", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ try {
+ sourceUnit.becomeWorkingCopy(null, null);
+ CompilationUnit unit = sourceUnit.reconcile(AST.JLS2, false, null, null);
+ assertNull("Unexpected compilation unit", unit);
+ // TODO improve test for AST.JLS3
+ } finally {
+ sourceUnit.discardWorkingCopy();
+ }
+ }
+ /**
+ * Ensures that bindings are created during reconcile if the problem requestor is active.
+ * @deprecated using deprecated code
+ */
+ public void test0538d() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0538", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ try {
+ ReconcilerTests.ProblemRequestor pbRequestor = new ReconcilerTests.ProblemRequestor();
+ sourceUnit.becomeWorkingCopy(pbRequestor, null);
+ sourceUnit.getBuffer().setContents(
+ "package test0538;\n" +
+ "public class A {\n" +
+ " Object field;\n" +
+ "}"
+ );
+ // TODO improve test for AST.JLS3
+ CompilationUnit unit = sourceUnit.reconcile(AST.JLS2, false, null, null);
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertNotNull("No node", node);
+ assertTrue("Not original", isOriginal(node));
+ assertTrue("not a field declaration", node.getNodeType() == ASTNode.FIELD_DECLARATION);
+ FieldDeclaration declaration = (FieldDeclaration) node;
+ Type type = declaration.getType();
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No type binding", typeBinding);
+ assertEquals("Wrong name", "Object", typeBinding.getName());
+ } finally {
+ sourceUnit.discardWorkingCopy();
+ }
+ }
+ /**
+ * Ensures that bindings are created during reconcile if force problem detection is turned on.
+ * @deprecated using deprecated code
+ */
+ public void test0538e() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0538", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ try {
+ ReconcilerTests.ProblemRequestor pbRequestor = new ReconcilerTests.ProblemRequestor();
+ sourceUnit.becomeWorkingCopy(pbRequestor, null);
+ // TODO improve test for AST.JLS3
+ CompilationUnit unit = sourceUnit.reconcile(AST.JLS2, true/*force pb detection*/, null, null);
+ ASTNode node = getASTNode(unit, 0);
+ assertNotNull("No node", node);
+ assertTrue("not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION);
+ TypeDeclaration declaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = declaration.resolveBinding();
+ assertNotNull("No type binding", typeBinding);
+ assertEquals("Wrong name", "A", typeBinding.getName());
+ } finally {
+ sourceUnit.discardWorkingCopy();
+ }
+ }
+ /**
+ * Ensures that bindings are created during reconcile if force problem detection is turned on.
+ * Case of a unit containing an anonymous type.
+ * (regression test for bug 55102 NPE when using ICU.reconcile(GET_AST_TRUE, ...))
+ * @deprecated using deprecated code
+ */
+ public void test0538f() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0538", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ try {
+ ReconcilerTests.ProblemRequestor pbRequestor = new ReconcilerTests.ProblemRequestor();
+ sourceUnit.becomeWorkingCopy(pbRequestor, null);
+ sourceUnit.getBuffer().setContents(
+ "package test0538;\n" +
+ "public class A {\n" +
+ " void foo() {\n" +
+ " new Object() {\n" +
+ " void bar() {\n" +
+ " }\n" +
+ " };\n" +
+ " }\n" +
+ "}"
+ );
+ // TODO improve test for AST.JLS3
+ CompilationUnit unit = sourceUnit.reconcile(AST.JLS2, true/*force pb detection*/, null, null);
+ ASTNode node = getASTNode(unit, 0);
+ assertNotNull("No node", node);
+ } finally {
+ sourceUnit.discardWorkingCopy();
+ }
+ }
+ /**
+ * Ensures that bindings are created during reconcile if force problem detection is turned on.
+ * Case of a unit containing an anonymous type.
+ * (regression test for bug 55102 NPE when using ICU.reconcile(GET_AST_TRUE, ...))
+ * @deprecated using deprecated code
+ */
+ public void test0538g() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0538", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ try {
+ ReconcilerTests.ProblemRequestor pbRequestor = new ReconcilerTests.ProblemRequestor();
+ sourceUnit.becomeWorkingCopy(pbRequestor, null);
+ sourceUnit.getBuffer().setContents(
+ "package test0538;\n" +
+ "public class A {\n" +
+ " void foo() {\n" +
+ " new Object() {\n" +
+ " void bar() {\n" +
+ " }\n" +
+ " };\n" +
+ " }\n" +
+ "}"
+ );
+ sourceUnit.reconcile(ICompilationUnit.NO_AST, false/* don't force pb detection*/, null, null);
+ // TODO improve test for AST.JLS3
+ CompilationUnit unit = sourceUnit.reconcile(AST.JLS2, true/*force pb detection*/, null, null);
+ ASTNode node = getASTNode(unit, 0);
+ assertNotNull("No node", node);
+ } finally {
+ sourceUnit.discardWorkingCopy();
+ }
+ }
+ /**
+ * Ensures that asking for well known type doesn't throw a NPE if the problem requestor is not active.
+ * (regression test for bug 64750 NPE in Java AST Creation - editing some random file)
+ * @deprecated using deprecated code
+ */
+ public void test0538h() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0538", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ try {
+ ReconcilerTests.ProblemRequestor pbRequestor = new ReconcilerTests.ProblemRequestor() {
+ public boolean isActive() {
+ return false;
+ }
+ };
+ sourceUnit.becomeWorkingCopy(pbRequestor, null);
+ sourceUnit.getBuffer().setContents(
+ "package test0538;\n" +
+ "public class A {\n" +
+ " Object field;\n" +
+ "}"
+ );
+ // TODO improve test for AST.JLS3
+ CompilationUnit unit = sourceUnit.reconcile(AST.JLS2, false, null, null);
+ assertEquals("Unexpected well known type", null, unit.getAST().resolveWellKnownType("void"));
+ } finally {
+ sourceUnit.discardWorkingCopy();
+ }
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=53477
+ */
+ public void test0539() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0539", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 1, 0);
+ assertNotNull("No node", node);
+ assertTrue("not an expression statement", node.getNodeType() == ASTNode.EXPRESSION_STATEMENT);
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertTrue("not a class instance creation", expression.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION);
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ checkSourceRange(classInstanceCreation, "new A(){}.new Inner(){/*x*/}", source);
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ Expression expression2 = classInstanceCreation.getExpression();
+ assertTrue("not a class instance creation", expression2.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION);
+ ClassInstanceCreation classInstanceCreation2 = (ClassInstanceCreation) expression2;
+ AnonymousClassDeclaration anonymousClassDeclaration2 = classInstanceCreation2.getAnonymousClassDeclaration();
+ assertNotNull("No anonymous class declaration", anonymousClassDeclaration2);
+ checkSourceRange(anonymousClassDeclaration2, "{}", source);
+ assertNotNull("No anonymous class declaration", anonymousClassDeclaration);
+ checkSourceRange(anonymousClassDeclaration, "{/*x*/}", source);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=54431
+ */
+ public void test0540() {
+ char[] source =
+ ("package test0540;\n" + //$NON-NLS-1$
+ "\n" + //$NON-NLS-1$
+ "class Test {\n" + //$NON-NLS-1$
+ " public void foo(int arg) {\n" +//$NON-NLS-1$
+ " assert true;\n" +//$NON-NLS-1$
+ " }\n" + //$NON-NLS-1$
+ "}").toCharArray(); //$NON-NLS-1$
+ IJavaProject project = getJavaProject("Converter"); //$NON-NLS-1$
+ Map options = project.getOptions(true);
+ options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_4);
+ options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_4);
+ options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4);
+ ASTNode result = runConversion(AST.JLS3, source, "Test.java", project, options, true); //$NON-NLS-1$
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertEquals("Problems found", 0, compilationUnit.getProblems().length);
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertTrue("not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No type binding", typeBinding); //$NON-NLS-1$
+ assertEquals("Wrong name", "Test", typeBinding.getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals("Wrong package", "test0540", typeBinding.getPackage().getName()); //$NON-NLS-1$ //$NON-NLS-2$
+ assertTrue("Not an interface", typeBinding.isClass()); //$NON-NLS-1$
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=56697
+ */
+ public void test0541() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0541", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertEquals("not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ class Change14FieldAccessASTVisitor extends ASTVisitor {
+ int counter;
+ Change14FieldAccessASTVisitor() {
+ this.counter = 0;
+ }
+ public void endVisit(QualifiedName qualifiedName) {
+ IBinding i_binding = qualifiedName.getQualifier().resolveBinding();
+ ITypeBinding type_binding = qualifiedName.getQualifier().resolveTypeBinding();
+ if (i_binding == null || type_binding == null) {
+ this.counter++;
+ }
+ }
+ }
+ Change14FieldAccessASTVisitor visitor = new Change14FieldAccessASTVisitor();
+ unit.accept(visitor);
+ assertEquals("Missing binding", 0, visitor.counter);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=55004
+ */
+ public void test0542() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0542", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertTrue("not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "STRING_FIELD", variableBinding.getName());
+ Object constantValue = variableBinding.getConstantValue();
+ assertNotNull("No constant", constantValue);
+ assertEquals("Wrong value", "Hello world!", constantValue);
+ Expression initializer = fragment.getInitializer();
+ assertNotNull("No initializer", initializer);
+ checkSourceRange(initializer, "\"Hello world!\"", source);
+
+ node = getASTNode(unit, 0, 1);
+ assertTrue("not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "BOOLEAN_FIELD", variableBinding.getName());
+ constantValue = variableBinding.getConstantValue();
+ assertNotNull("No constant", constantValue);
+ assertEquals("Wrong value", new Boolean(true), constantValue);
+ initializer = fragment.getInitializer();
+ assertNotNull("No initializer", initializer);
+ checkSourceRange(initializer, "true", source);
+
+ node = getASTNode(unit, 0, 2);
+ assertTrue("not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "BYTE_FIELD", variableBinding.getName());
+ constantValue = variableBinding.getConstantValue();
+ assertNotNull("No constant", constantValue);
+ assertEquals("Wrong value", new Byte((byte)1), constantValue);
+ initializer = fragment.getInitializer();
+ assertNotNull("No initializer", initializer);
+ checkSourceRange(initializer, "1", source);
+
+ node = getASTNode(unit, 0, 3);
+ assertTrue("not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "CHAR_FIELD", variableBinding.getName());
+ constantValue = variableBinding.getConstantValue();
+ assertNotNull("No constant", constantValue);
+ assertEquals("Wrong value", new Character('{'), constantValue);
+ initializer = fragment.getInitializer();
+ assertNotNull("No initializer", initializer);
+ checkSourceRange(initializer, "\'{\'", source);
+
+ node = getASTNode(unit, 0, 4);
+ assertTrue("not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "DOUBLE_FIELD", variableBinding.getName());
+ constantValue = variableBinding.getConstantValue();
+ assertNotNull("No constant", constantValue);
+ assertEquals("Wrong value", new Double("3.1415"), constantValue);
+ initializer = fragment.getInitializer();
+ assertNotNull("No initializer", initializer);
+ checkSourceRange(initializer, "3.1415", source);
+
+ node = getASTNode(unit, 0, 5);
+ assertTrue("not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "FLOAT_FIELD", variableBinding.getName());
+ constantValue = variableBinding.getConstantValue();
+ assertNotNull("No constant", constantValue);
+ assertEquals("Wrong value", new Float("3.14159f"), constantValue);
+ initializer = fragment.getInitializer();
+ assertNotNull("No initializer", initializer);
+ checkSourceRange(initializer, "3.14159f", source);
+
+ node = getASTNode(unit, 0, 6);
+ assertTrue("not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "INT_FIELD", variableBinding.getName());
+ constantValue = variableBinding.getConstantValue();
+ assertNotNull("No constant", constantValue);
+ assertEquals("Wrong value", Integer.valueOf("7fffffff", 16), constantValue);
+ initializer = fragment.getInitializer();
+ assertNotNull("No initializer", initializer);
+ checkSourceRange(initializer, "Integer.MAX_VALUE", source);
+
+ node = getASTNode(unit, 0, 7);
+ assertTrue("not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "LONG_FIELD", variableBinding.getName());
+ constantValue = variableBinding.getConstantValue();
+ assertNotNull("No constant", constantValue);
+ assertEquals("Wrong value", new Long("34"), constantValue);
+ initializer = fragment.getInitializer();
+ assertNotNull("No initializer", initializer);
+ checkSourceRange(initializer, "34L", source);
+
+ node = getASTNode(unit, 0, 8);
+ assertTrue("not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "SHORT_FIELD", variableBinding.getName());
+ constantValue = variableBinding.getConstantValue();
+ assertNotNull("No constant", constantValue);
+ assertEquals("Wrong value", new Short("130"), constantValue);
+ initializer = fragment.getInitializer();
+ assertNotNull("No initializer", initializer);
+ checkSourceRange(initializer, "130", source);
+
+ node = getASTNode(unit, 0, 9);
+ assertTrue("not a field declaration", node instanceof FieldDeclaration); //$NON-NLS-1$
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "int_field", variableBinding.getName());
+ constantValue = variableBinding.getConstantValue();
+ assertNull("Got a constant", constantValue);
+ initializer = fragment.getInitializer();
+ assertNotNull("No initializer", initializer);
+ checkSourceRange(initializer, "Integer.MAX_VALUE", source);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=58436
+ */
+ public void test0543() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0543", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ unit.accept(new GetKeyVisitor());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=51500
+ */
+ public void test0544() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0544", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertEquals("not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType()); //$NON-NLS-1$
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("Not an abstract method", (methodDeclaration.getModifiers() & Modifier.ABSTRACT) != 0);
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ assertNotNull("No binding", methodBinding);
+ assertTrue("Not an abstract method binding", (methodBinding.getModifiers() & Modifier.ABSTRACT) != 0);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=59843
+ */
+ public void test0545() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0545", "First.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertEquals("not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType()); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertEquals("Wrong key", "Ltest0545/First$Test;", typeBinding.getKey());
+
+ sourceUnit = getCompilationUnit("Converter", "src", "test0545", "Second.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ result = runConversion(AST.JLS3, sourceUnit, true);
+ unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ node = getASTNode(unit, 0, 0);
+ assertEquals("not a method declaration", ASTNode.TYPE_DECLARATION, node.getNodeType()); //$NON-NLS-1$
+ typeDeclaration = (TypeDeclaration) node;
+ typeBinding = typeDeclaration.resolveBinding();
+ assertEquals("Wrong key", "Ltest0545/Second$Test;", typeBinding.getKey());
+
+ sourceUnit = getCompilationUnit("Converter", "src", "test0545", "Third.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ result = runConversion(AST.JLS3, sourceUnit, true);
+ unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ node = getASTNode(unit, 0, 0);
+ assertEquals("not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType()); //$NON-NLS-1$
+ typeDeclaration = (TypeDeclaration) node;
+ typeBinding = typeDeclaration.resolveBinding();
+ assertEquals("Wrong key", "Ltest0545/Third$Test;", typeBinding.getKey());
+
+
+ sourceUnit = getCompilationUnit("Converter", "src", "test0545", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ result = runConversion(AST.JLS3, sourceUnit, true);
+ unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ node = getASTNode(unit, 0);
+ assertEquals("not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType()); //$NON-NLS-1$
+ typeDeclaration = (TypeDeclaration) node;
+ typeBinding = typeDeclaration.resolveBinding();
+ assertEquals("Wrong key", "Ltest0545/Test;", typeBinding.getKey());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=59848
+ */
+ public void test0546() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0546", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 0, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 1, 0, 0);
+ assertEquals("not a variable declaration", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType()); //$NON-NLS-1$
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) node;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ ITypeBinding typeBinding = variableBinding.getType();
+ assertTrue("An anonymous type binding", !typeBinding.isAnonymous());
+ Expression initializer = fragment.getInitializer();
+ assertEquals("not a class instance creation", ASTNode.CLASS_INSTANCE_CREATION, initializer.getNodeType()); //$NON-NLS-1$
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) initializer;
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ ITypeBinding typeBinding2 = anonymousClassDeclaration.resolveBinding();
+ assertTrue("Not an anonymous type binding", typeBinding2.isAnonymous());
+ ITypeBinding typeBinding3 = classInstanceCreation.resolveTypeBinding();
+ assertTrue("Not an anonymous type binding", typeBinding3.isAnonymous());
+ node = getASTNode(unit, 1, 0, 1);
+ assertEquals("not a expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType()); //$NON-NLS-1$
+ ExpressionStatement statement = (ExpressionStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType()); //$NON-NLS-1$
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ assertEquals("not a simple name", ASTNode.SIMPLE_NAME, expression2.getNodeType()); //$NON-NLS-1$
+ SimpleName simpleName = (SimpleName) expression2;
+ ITypeBinding typeBinding4 = simpleName.resolveTypeBinding();
+ assertTrue("An anonymous type binding", !typeBinding4.isAnonymous());
+ Type type = classInstanceCreation.getType();
+ IBinding binding = type.resolveBinding();
+ assertEquals("Wrong type", IBinding.TYPE, binding.getKind());
+ ITypeBinding typeBinding5 = (ITypeBinding) binding;
+ assertTrue("An anonymous type binding", !typeBinding5.isAnonymous());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=60078
+ */
+ public void test0547() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0547", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ CompilationUnit unit = (CompilationUnit) result;
+ assertEquals("Wrong number of problems", 1, unit.getProblems().length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("not a type declaration statement", ASTNode.TYPE_DECLARATION_STATEMENT, node.getNodeType()); //$NON-NLS-1$
+ TypeDeclarationStatement typeDeclarationStatement = (TypeDeclarationStatement) node;
+ AbstractTypeDeclaration typeDeclaration = typeDeclarationStatement.getDeclaration();
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertEquals("Wrong key", "Ltest0547/A$74$Local;", typeBinding.getKey());
+
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("wrong size", 3, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertEquals("not a type declaration statement", ASTNode.TYPE_DECLARATION, bodyDeclaration.getNodeType()); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration2 = (TypeDeclaration) bodyDeclaration;
+
+ typeBinding = typeDeclaration2.resolveBinding();
+ assertEquals("Wrong key", "Ltest0547/A$100$LocalMember;", typeBinding.getKey());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=60581
+ */
+ public void test0548() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0548", "PaletteStackEditPart.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=48502
+ */
+ public void test0549() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0549", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=48502
+ */
+ public void test0550() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0550", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=60848
+ */
+ public void test0551() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0551", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 1, problems.length); //$NON-NLS-1$
+ IProblem problem = problems[0];
+ assertEquals("wrong end position", source.length - 1, problem.getSourceEnd());
+ }
+
+ public void test0552() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0552", "Test.java");
+ char[] source = sourceUnit.getSource().toCharArray();
+ CompilationUnit result = (CompilationUnit) runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("Got errors", 0, result.getProblems().length);
+ TypeDeclaration declaration = (TypeDeclaration) result.types().get(0);
+ Block body = declaration.getMethods()[0].getBody();
+ ExpressionStatement expr = (ExpressionStatement) body.statements().get(0);
+ MethodInvocation invocation = (MethodInvocation) expr.getExpression();
+ InfixExpression node = (InfixExpression) invocation.arguments().get(0);
+ ITypeBinding typeBinding = node.resolveTypeBinding();
+ assertEquals("wrong type", "java.lang.String", typeBinding.getQualifiedName());
+ checkSourceRange(node, "\"a\" + \"a\" + \"a\"", source);
+ List extendedOperands = node.extendedOperands();
+ assertEquals("Wrong size", 1, extendedOperands.size());
+ Expression leftOperand = node.getLeftOperand();
+ checkSourceRange(leftOperand, "\"a\"", source);
+ typeBinding = leftOperand.resolveTypeBinding();
+ assertEquals("wrong type", "java.lang.String", typeBinding.getQualifiedName());
+ Expression rightOperand = node.getRightOperand();
+ checkSourceRange(rightOperand, "\"a\"", source);
+ typeBinding = rightOperand.resolveTypeBinding();
+ assertEquals("wrong type", "java.lang.String", typeBinding.getQualifiedName());
+ Expression expression = (Expression) extendedOperands.get(0);
+ checkSourceRange(expression, "\"a\"", source);
+ typeBinding = expression.resolveTypeBinding();
+ assertEquals("wrong type", "java.lang.String", typeBinding.getQualifiedName());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=61946
+ */
+ public void test0553() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0553", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ Object constantValue = variableBinding.getConstantValue();
+ assertNull("Got a constant value", constantValue);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=61946
+ */
+ public void test0554() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0554", "B.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a return statement", ASTNode.RETURN_STATEMENT, node.getNodeType());
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertNotNull("No expression", expression);
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ checkSourceRange(expression2, "A", source);
+ ITypeBinding typeBinding = expression2.resolveTypeBinding();
+ assertEquals("wrong type", "test0554.A", typeBinding.getQualifiedName());
+ IVariableBinding[] fields = typeBinding.getDeclaredFields();
+ assertEquals("Wrong size", 1, fields.length);
+ IVariableBinding variableBinding = fields[0];
+ Object constantValue = variableBinding.getConstantValue();
+ assertNotNull("Missing constant", constantValue);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=61946
+ */
+ public void test0555() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0555", "B.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a return statement", ASTNode.RETURN_STATEMENT, node.getNodeType());
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertNotNull("No expression", expression);
+ assertEquals("Not a qualified name", ASTNode.QUALIFIED_NAME, expression.getNodeType());
+ QualifiedName qualifiedName = (QualifiedName) expression;
+ Name name = qualifiedName.getQualifier();
+ checkSourceRange(name, "A", source);
+ ITypeBinding typeBinding = name.resolveTypeBinding();
+ assertEquals("wrong type", "test0555.A", typeBinding.getQualifiedName());
+ IVariableBinding[] fields = typeBinding.getDeclaredFields();
+ assertEquals("Wrong size", 1, fields.length);
+ IVariableBinding variableBinding = fields[0];
+ Object constantValue = variableBinding.getConstantValue();
+ assertNotNull("No constant value", constantValue);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=62463
+ */
+ public void test0556() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0556", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 1, 0);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertEquals("Not an method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ checkSourceRange(expression2, "(aa.bar())", source);
+ SimpleName simpleName = methodInvocation.getName();
+ checkSourceRange(simpleName, "size", source);
+ checkSourceRange(expression, "(aa.bar()).size()", source);
+ checkSourceRange(expressionStatement, "(aa.bar()).size();", source);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=62463
+ */
+ public void test0557() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0557", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 1, 0);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertEquals("Not an method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ Expression expression2 = methodInvocation.getExpression();
+ checkSourceRange(expression2, "(aa.bar())", source);
+ SimpleName simpleName = methodInvocation.getName();
+ checkSourceRange(simpleName, "get", source);
+ checkSourceRange(expression, "(aa.bar()).get(0)", source);
+ checkSourceRange(expressionStatement, "(aa.bar()).get(0);", source);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=65090
+ * @deprecated using deprecated code
+ */
+ public void test0558() {
+ String src = "\tSystem.out.println(\"Hello\");\n\tSystem.out.println(\"World\");\n";
+ char[] source = src.toCharArray();
+ ASTParser parser = ASTParser.newParser(AST.JLS2);
+ parser.setKind (ASTParser.K_STATEMENTS);
+ parser.setSource (source);
+ ASTNode result = parser.createAST (null);
+ assertNotNull("no result", result);
+ assertEquals("Wrong type", ASTNode.BLOCK, result.getNodeType());
+ Block block = (Block) result;
+ List statements = block.statements();
+ assertNotNull("No statements", statements);
+ assertEquals("Wrong size", 2, statements.size());
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=65562
+ */
+ public void test0559() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0559", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Wrong type", ASTNode.IF_STATEMENT, node.getNodeType());
+ IfStatement ifStatement = (IfStatement) node;
+ Expression expression = ifStatement.getExpression();
+ assertEquals("Wrong type", ASTNode.INFIX_EXPRESSION, expression.getNodeType());
+ InfixExpression infixExpression = (InfixExpression) expression;
+ Expression expression2 = infixExpression.getLeftOperand();
+ assertEquals("Wrong type", ASTNode.METHOD_INVOCATION, expression2.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression2;
+ Expression expression3 = methodInvocation.getExpression();
+ assertEquals("Wrong type", ASTNode.PARENTHESIZED_EXPRESSION, expression3.getNodeType());
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression3;
+ Expression expression4 = parenthesizedExpression.getExpression();
+ assertEquals("Wrong type", ASTNode.STRING_LITERAL, expression4.getNodeType());
+ checkSourceRange(expression4, "\" \"", source);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=65562
+ */
+ public void test0560() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0560", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Wrong type", ASTNode.IF_STATEMENT, node.getNodeType());
+ IfStatement ifStatement = (IfStatement) node;
+ Expression expression = ifStatement.getExpression();
+ assertEquals("Wrong type", ASTNode.INFIX_EXPRESSION, expression.getNodeType());
+ InfixExpression infixExpression = (InfixExpression) expression;
+ Expression expression2 = infixExpression.getLeftOperand();
+ assertEquals("Wrong type", ASTNode.METHOD_INVOCATION, expression2.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression2;
+ Expression expression3 = methodInvocation.getExpression();
+ assertEquals("Wrong type", ASTNode.PARENTHESIZED_EXPRESSION, expression3.getNodeType());
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression3;
+ Expression expression4 = parenthesizedExpression.getExpression();
+ assertEquals("Wrong type", ASTNode.STRING_LITERAL, expression4.getNodeType());
+ checkSourceRange(expression4, "\" \"", source);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=65562
+ */
+ public void test0561() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0561", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Wrong type", ASTNode.IF_STATEMENT, node.getNodeType());
+ IfStatement ifStatement = (IfStatement) node;
+ Expression expression = ifStatement.getExpression();
+ assertEquals("Wrong type", ASTNode.INFIX_EXPRESSION, expression.getNodeType());
+ InfixExpression infixExpression = (InfixExpression) expression;
+ Expression expression2 = infixExpression.getLeftOperand();
+ assertEquals("Wrong type", ASTNode.METHOD_INVOCATION, expression2.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression2;
+ Expression expression3 = methodInvocation.getExpression();
+ assertEquals("Wrong type", ASTNode.PARENTHESIZED_EXPRESSION, expression3.getNodeType());
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression3;
+ Expression expression4 = parenthesizedExpression.getExpression();
+ assertEquals("Wrong type", ASTNode.STRING_LITERAL, expression4.getNodeType());
+ checkSourceRange(expression4, "\" \"", source);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=65562
+ */
+ public void test0562() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0562", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Wrong type", ASTNode.IF_STATEMENT, node.getNodeType());
+ IfStatement ifStatement = (IfStatement) node;
+ Expression expression = ifStatement.getExpression();
+ assertEquals("Wrong type", ASTNode.INFIX_EXPRESSION, expression.getNodeType());
+ InfixExpression infixExpression = (InfixExpression) expression;
+ Expression expression2 = infixExpression.getLeftOperand();
+ assertEquals("Wrong type", ASTNode.METHOD_INVOCATION, expression2.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression2;
+ Expression expression3 = methodInvocation.getExpression();
+ assertEquals("Wrong type", ASTNode.PARENTHESIZED_EXPRESSION, expression3.getNodeType());
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression3;
+ Expression expression4 = parenthesizedExpression.getExpression();
+ assertEquals("Wrong type", ASTNode.STRING_LITERAL, expression4.getNodeType());
+ checkSourceRange(expression4, "\" \"", source);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=65562
+ */
+ public void test0563() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0563", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Wrong type", ASTNode.IF_STATEMENT, node.getNodeType());
+ IfStatement ifStatement = (IfStatement) node;
+ Expression expression = ifStatement.getExpression();
+ assertEquals("Wrong type", ASTNode.INFIX_EXPRESSION, expression.getNodeType());
+ InfixExpression infixExpression = (InfixExpression) expression;
+ Expression expression2 = infixExpression.getLeftOperand();
+ assertEquals("Wrong type", ASTNode.METHOD_INVOCATION, expression2.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression2;
+ Expression expression3 = methodInvocation.getExpression();
+ assertEquals("Wrong type", ASTNode.PARENTHESIZED_EXPRESSION, expression3.getNodeType());
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression3;
+ Expression expression4 = parenthesizedExpression.getExpression();
+ checkSourceRange(expression4, "new String()", source);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=65562
+ */
+ public void test0564() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0564", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Wrong type", ASTNode.IF_STATEMENT, node.getNodeType());
+ IfStatement ifStatement = (IfStatement) node;
+ Expression expression = ifStatement.getExpression();
+ assertEquals("Wrong type", ASTNode.INFIX_EXPRESSION, expression.getNodeType());
+ InfixExpression infixExpression = (InfixExpression) expression;
+ Expression expression2 = infixExpression.getLeftOperand();
+ assertEquals("Wrong type", ASTNode.METHOD_INVOCATION, expression2.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression2;
+ Expression expression3 = methodInvocation.getExpression();
+ assertEquals("Wrong type", ASTNode.PARENTHESIZED_EXPRESSION, expression3.getNodeType());
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression3;
+ Expression expression4 = parenthesizedExpression.getExpression();
+ checkSourceRange(expression4, "new String()", source);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=65562
+ */
+ public void test0565() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0565", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Wrong type", ASTNode.IF_STATEMENT, node.getNodeType());
+ IfStatement ifStatement = (IfStatement) node;
+ Expression expression = ifStatement.getExpression();
+ assertEquals("Wrong type", ASTNode.INFIX_EXPRESSION, expression.getNodeType());
+ InfixExpression infixExpression = (InfixExpression) expression;
+ Expression expression2 = infixExpression.getLeftOperand();
+ assertEquals("Wrong type", ASTNode.METHOD_INVOCATION, expression2.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression2;
+ Expression expression3 = methodInvocation.getExpression();
+ assertEquals("Wrong type", ASTNode.PARENTHESIZED_EXPRESSION, expression3.getNodeType());
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) expression3;
+ Expression expression4 = parenthesizedExpression.getExpression();
+ checkSourceRange(expression4, "(/**/ String /**/) new String()", source);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=69349
+ */
+ public void test0566() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0566", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertEquals("Wrong type", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ assertEquals("Wrong character", '}', source[node.getStartPosition() + node.getLength() - 1]);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=69349
+ */
+ public void test0567() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0567", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertEquals("Wrong type", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ assertEquals("Wrong character", '}', source[node.getStartPosition() + node.getLength() - 1]);
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=70398
+ */
+ public void test0568() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0568", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=70398
+ */
+ public void test0570() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0570", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ }
+
+ /**
+ * No binding when there is no unit name set
+ */
+ public void test0571() throws JavaModelException {
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ String source = "public class A {public boolean foo() {}}";
+ parser.setSource(source.toCharArray());
+ parser.setProject(getJavaProject("Converter"));
+ // no unit name parser.setUnitName("A");
+ parser.setResolveBindings(true);
+ ASTNode node = parser.createAST(null);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) node;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ }
+
+ /**
+ * No binding when there is no unit name set
+ */
+ public void test0572() throws JavaModelException {
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ String source = "public class A {public boolean foo() {}}";
+ parser.setSource(source.toCharArray());
+ parser.setProject(getJavaProject("Converter"));
+ parser.setUnitName("A");
+ parser.setResolveBindings(true);
+ ASTNode node = parser.createAST(null);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) node;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 1, problems.length); //$NON-NLS-1$
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=77968
+ */
+ public void test0573() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0573", "Z.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ String source = sourceUnit.getSource();
+ int pos = source.indexOf("his.ba");
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, pos, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertNotNull("Missing node", node);
+ assertEquals("Wrong type", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ Expression expression = expressionStatement.getExpression();
+ assertNotNull("Missing node", expression);
+ assertEquals("Wrong type", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 1, problems.length); //$NON-NLS-1$
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78735
+ */
+ public void test0574() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0574", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertNotNull("Missing node", node);
+ assertEquals("Wrong type", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ node = getASTNode(unit, 0, 1, 0);
+ assertNotNull("Missing node", node);
+ assertEquals("Wrong type", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding2 = fragment.resolveBinding();
+ assertFalse("are Equals", variableBinding.isEqualTo(variableBinding2));
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78735
+ */
+ public void test0575() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0575", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ final IProblem[] problems = unit.getProblems();
+ assertEquals("Wrong number of problems", 0, problems.length); //$NON-NLS-1$
+ ASTNode node = getASTNode(unit, 0, 2);
+ assertNotNull("Missing node", node);
+ assertEquals("Wrong type", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+ node = getASTNode(unit, 0, 1, 1);
+ assertNotNull("Missing node", node);
+ assertEquals("Wrong type", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ methodDeclaration = (MethodDeclaration) node;
+ IMethodBinding methodBinding2 = methodDeclaration.resolveBinding();
+ assertFalse("are Equals", methodBinding.isEqualTo(methodBinding2));
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=78740
+ * @deprecated marked deprecated to suppress JDOM-related deprecation warnings
+ */
+ public void test0576() throws JavaModelException {
+ org.eclipse.jdt.core.jdom.DOMFactory factory = new org.eclipse.jdt.core.jdom.DOMFactory();
+ org.eclipse.jdt.core.jdom.IDOMCompilationUnit domCompilationUnit = factory.createCompilationUnit(
+ "package x; /** @model */ interface X {}", "NAME");
+ org.eclipse.jdt.core.jdom.IDOMType domType = (org.eclipse.jdt.core.jdom.IDOMType) domCompilationUnit.getFirstChild().getNextNode();
+ assertTrue("Not an interface", Flags.isInterface(domType.getFlags()));
+ domType.getComment();
+ assertTrue("Not an interface", Flags.isInterface(domType.getFlags()));
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=77645
+ */
+ public void test0578() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0578", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertProblemsSize(unit, 0);
+ unit.accept(new ASTVisitor() {
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.SingleVariableDeclaration)
+ */
+ public boolean visit(SingleVariableDeclaration node) {
+ IVariableBinding binding = node.resolveBinding();
+ assertNotNull("No method", binding.getDeclaringMethod());
+ return false;
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.VariableDeclarationFragment)
+ */
+ public boolean visit(VariableDeclarationFragment node) {
+ IVariableBinding binding = node.resolveBinding();
+ ASTNode parent = node.getParent();
+ if (parent != null && binding != null) {
+ final IMethodBinding declaringMethod = binding.getDeclaringMethod();
+ final String variableBindingName = binding.getName();
+ switch(parent.getNodeType()) {
+ case ASTNode.FIELD_DECLARATION :
+ assertNull("Got a method", declaringMethod);
+ break;
+ default :
+ if (variableBindingName.equals("var1")
+ || variableBindingName.equals("var2")) {
+ assertNull("Got a method", declaringMethod);
+ } else {
+ assertNotNull("No method", declaringMethod);
+ String methodName = declaringMethod.getName();
+ if (variableBindingName.equals("var4")) {
+ assertEquals("Wrong method", "foo", methodName);
+ } else if (variableBindingName.equals("var5")) {
+ assertEquals("Wrong method", "foo2", methodName);
+ } else if (variableBindingName.equals("var7")) {
+ assertEquals("Wrong method", "foo3", methodName);
+ } else if (variableBindingName.equals("var8")) {
+ assertEquals("Wrong method", "X", methodName);
+ } else if (variableBindingName.equals("var9")) {
+ assertEquals("Wrong method", "bar3", methodName);
+ } else if (variableBindingName.equals("var10")) {
+ assertEquals("Wrong method", "bar3", methodName);
+ } else if (variableBindingName.equals("var11")) {
+ assertEquals("Wrong method", "X", methodName);
+ }
+ }
+ }
+ }
+ return false;
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#visit(org.eclipse.jdt.core.dom.FieldAccess)
+ */
+ public boolean visit(FieldAccess node) {
+ IVariableBinding binding = node.resolveFieldBinding();
+ assertNull("No method", binding.getDeclaringMethod());
+ return false;
+ }
+ /* (non-Javadoc)
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.SuperFieldAccess)
+ */
+ public boolean visit(SuperFieldAccess node) {
+ IVariableBinding binding = node.resolveFieldBinding();
+ assertNull("No method", binding.getDeclaringMethod());
+ return false;
+ }
+ });
+ }
+
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=77984
+ * @deprecated
+ */
+ public void test0579() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0579", "ParserTask.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = AST.parseCompilationUnit(sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertEquals("not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType()); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ assertEquals("Wrong number of body declarations", 3, typeDeclaration.bodyDeclarations().size());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=79953
+ */
+ public void test0580() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ workingCopy = getWorkingCopy("/Converter/src/p/X.java", true/*resolve*/);
+ String source = "package p;\n" +
+ "public class X {\n" +
+ " d String[][]tab;\n" +
+ "}";
+ ASTNode node = buildAST(
+ source,
+ workingCopy,
+ false);
+ assertEquals("wrong type", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("wrong type", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ checkSourceRange(fieldDeclaration, "d String[][]", source.toCharArray());
+ Type type = fieldDeclaration.getType();
+ assertTrue("Not a simple type", type.isSimpleType());
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ assertEquals("Wrong extended dimensions", 2, fragment.getExtraDimensions());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=80041
+ */
+ public void test0581() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ workingCopy = getWorkingCopy("/Converter/src/p/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ "package p;\n" +
+ "public class X {\n" +
+ " void m(Object obj) {}\n" +
+ " void foo(Object obj) {}\n" +
+ "}",
+ workingCopy);
+ assertEquals("wrong type", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("wrong type", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ SingleVariableDeclaration variableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ IVariableBinding variableBinding = variableDeclaration.resolveBinding();
+ node = getASTNode(compilationUnit, 0, 1);
+ assertEquals("wrong type", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ methodDeclaration = (MethodDeclaration) node;
+ parameters = methodDeclaration.parameters();
+ variableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ IVariableBinding variableBinding2 = variableDeclaration.resolveBinding();
+ assertFalse("Bindings are equal", variableBinding.isEqualTo(variableBinding2));
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=80338
+ */
+ // TODO (jerome) remove this test as it has nothing to do on ASTConverterTest and it is a dup of ExistenceTests#testMethodWithInvalidParameter()
+ public void test0582() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0582", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType[] types = sourceUnit.getTypes();
+ assertEquals("wrong size", 1, types.length);
+ IType type = types[0];
+ IMethod[] methods = type.getMethods();
+ assertEquals("wrong size", 1, methods.length);
+ IMethod method = methods[0];
+ assertEquals("wrong number", 1, method.getNumberOfParameters());
+ assertEquals("wrong signature", "([[I)[[[[[I", method.getSignature());
+ assertEquals("wrong return type", "[[[[[I", method.getReturnType());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82616
+ */
+ public void test0583() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " private char nextChar() {\n" +
+ " return \'\\000\';\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertEquals("Got problems", 0, compilationUnit.getProblems().length);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not a return statement", ASTNode.RETURN_STATEMENT, node.getNodeType());
+ ReturnStatement statement = (ReturnStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("Not a character literal", ASTNode.CHARACTER_LITERAL, expression.getNodeType());
+ CharacterLiteral literal = (CharacterLiteral) expression;
+ assertEquals("Wrong character", '\000', literal.charValue());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82616
+ */
+ public void test0584() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " private char nextChar() {\n" +
+ " return \'\\u0020\';\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertEquals("Got problems", 0, compilationUnit.getProblems().length);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not a return statement", ASTNode.RETURN_STATEMENT, node.getNodeType());
+ ReturnStatement statement = (ReturnStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("Not a character literal", ASTNode.CHARACTER_LITERAL, expression.getNodeType());
+ CharacterLiteral literal = (CharacterLiteral) expression;
+ assertEquals("Wrong character", 32, literal.charValue());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82616
+ */
+ public void test0585() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " private char nextChar() {\n" +
+ " return \'\\b\';\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertEquals("Got problems", 0, compilationUnit.getProblems().length);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not a return statement", ASTNode.RETURN_STATEMENT, node.getNodeType());
+ ReturnStatement statement = (ReturnStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("Not a character literal", ASTNode.CHARACTER_LITERAL, expression.getNodeType());
+ CharacterLiteral literal = (CharacterLiteral) expression;
+ assertEquals("Wrong character", '\b', literal.charValue());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82616
+ */
+ public void test0586() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " private char nextChar() {\n" +
+ " return \'\\t\';\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertEquals("Got problems", 0, compilationUnit.getProblems().length);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not a return statement", ASTNode.RETURN_STATEMENT, node.getNodeType());
+ ReturnStatement statement = (ReturnStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("Not a character literal", ASTNode.CHARACTER_LITERAL, expression.getNodeType());
+ CharacterLiteral literal = (CharacterLiteral) expression;
+ assertEquals("Wrong character", '\t', literal.charValue());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82616
+ */
+ public void test0587() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " private char nextChar() {\n" +
+ " return \'\\n\';\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertEquals("Got problems", 0, compilationUnit.getProblems().length);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not a return statement", ASTNode.RETURN_STATEMENT, node.getNodeType());
+ ReturnStatement statement = (ReturnStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("Not a character literal", ASTNode.CHARACTER_LITERAL, expression.getNodeType());
+ CharacterLiteral literal = (CharacterLiteral) expression;
+ assertEquals("Wrong character", '\n', literal.charValue());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82616
+ */
+ public void test0588() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " private char nextChar() {\n" +
+ " return \'\\f\';\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertEquals("Got problems", 0, compilationUnit.getProblems().length);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not a return statement", ASTNode.RETURN_STATEMENT, node.getNodeType());
+ ReturnStatement statement = (ReturnStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("Not a character literal", ASTNode.CHARACTER_LITERAL, expression.getNodeType());
+ CharacterLiteral literal = (CharacterLiteral) expression;
+ assertEquals("Wrong character", '\f', literal.charValue());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82616
+ */
+ public void test0589() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " private char nextChar() {\n" +
+ " return \'\\r\';\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertEquals("Got problems", 0, compilationUnit.getProblems().length);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not a return statement", ASTNode.RETURN_STATEMENT, node.getNodeType());
+ ReturnStatement statement = (ReturnStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("Not a character literal", ASTNode.CHARACTER_LITERAL, expression.getNodeType());
+ CharacterLiteral literal = (CharacterLiteral) expression;
+ assertEquals("Wrong character", '\r', literal.charValue());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82616
+ */
+ public void test0590() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " private char nextChar() {\n" +
+ " return \'\\\"\';\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertEquals("Got problems", 0, compilationUnit.getProblems().length);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not a return statement", ASTNode.RETURN_STATEMENT, node.getNodeType());
+ ReturnStatement statement = (ReturnStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("Not a character literal", ASTNode.CHARACTER_LITERAL, expression.getNodeType());
+ CharacterLiteral literal = (CharacterLiteral) expression;
+ assertEquals("Wrong character", '\"', literal.charValue());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82616
+ */
+ public void test0591() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " private char nextChar() {\n" +
+ " return \'\\'\';\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertEquals("Got problems", 0, compilationUnit.getProblems().length);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not a return statement", ASTNode.RETURN_STATEMENT, node.getNodeType());
+ ReturnStatement statement = (ReturnStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("Not a character literal", ASTNode.CHARACTER_LITERAL, expression.getNodeType());
+ CharacterLiteral literal = (CharacterLiteral) expression;
+ assertEquals("Wrong character", '\'', literal.charValue());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82616
+ */
+ public void test0592() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " private char nextChar() {\n" +
+ " return \'\\\\\';\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertEquals("Got problems", 0, compilationUnit.getProblems().length);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not a return statement", ASTNode.RETURN_STATEMENT, node.getNodeType());
+ ReturnStatement statement = (ReturnStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("Not a character literal", ASTNode.CHARACTER_LITERAL, expression.getNodeType());
+ CharacterLiteral literal = (CharacterLiteral) expression;
+ assertEquals("Wrong character", '\\', literal.charValue());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82616
+ */
+ public void test0593() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " private char nextChar() {\n" +
+ " return \'\\077\';\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertEquals("Got problems", 0, compilationUnit.getProblems().length);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not a return statement", ASTNode.RETURN_STATEMENT, node.getNodeType());
+ ReturnStatement statement = (ReturnStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("Not a character literal", ASTNode.CHARACTER_LITERAL, expression.getNodeType());
+ CharacterLiteral literal = (CharacterLiteral) expression;
+ assertEquals("Wrong character", '\077', literal.charValue());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82616
+ */
+ public void test0594() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " private char nextChar() {\n" +
+ " return \'\\777\';\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertEquals("Got problems", 1, compilationUnit.getProblems().length);
+ node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ assertTrue("not malformed", isMalformed(methodDeclaration));
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=82985
+ */
+ public void test0595() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0595", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(result);
+ assertTrue("Not a compilation unit", result.getNodeType() == ASTNode.COMPILATION_UNIT);
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ assertProblemsSize(compilationUnit, 0);
+ List imports = compilationUnit.imports();
+ assertEquals("Wrong size", 1, imports.size());
+ ImportDeclaration importDeclaration = (ImportDeclaration) imports.get(0);
+ IBinding binding = importDeclaration.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("Wrong type", IBinding.TYPE, binding.getKind());
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=83098
+ */
+ public void test0596() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " void m(String[] args) {\n" +
+ " for (int i= 0; i < args.length; i++) {\n" +
+ " String string= args[i];\n" +
+ " }\n" +
+ " for (int i= 0; i < args.length; i++) {\n" +
+ " String string= args[i];\n" +
+ " }\n" +
+ " }\n" +
+ "}\n";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertEquals("Got problems", 0, compilationUnit.getProblems().length);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not a for statement", ASTNode.FOR_STATEMENT, node.getNodeType());
+ ForStatement forStatement = (ForStatement) node;
+ Statement action = forStatement.getBody();
+ assertEquals("Not a block", ASTNode.BLOCK, action.getNodeType());
+ Block block = (Block) action;
+ List statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size());
+ Statement statement = (Statement) statements.get(0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, statement.getNodeType());
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) statement;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+
+ node = getASTNode(compilationUnit, 0, 0, 1);
+ assertEquals("Not a for statement", ASTNode.FOR_STATEMENT, node.getNodeType());
+ forStatement = (ForStatement) node;
+ action = forStatement.getBody();
+ assertEquals("Not a block", ASTNode.BLOCK, action.getNodeType());
+ block = (Block) action;
+ statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size());
+ statement = (Statement) statements.get(0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, statement.getNodeType());
+ variableDeclarationStatement = (VariableDeclarationStatement) statement;
+ fragments = variableDeclarationStatement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding2 = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding2);
+
+ assertFalse("Bindings are equals", variableBinding.isEqualTo(variableBinding2));
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=83210
+ */
+ public void test0597() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0597", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode node = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not an if statement", ASTNode.IF_STATEMENT, node.getNodeType());
+ IfStatement ifStatement = (IfStatement) node;
+ Expression expression = ifStatement.getExpression();
+ assertEquals("Not an instanceof expression", ASTNode.INSTANCEOF_EXPRESSION, expression.getNodeType());
+ InstanceofExpression instanceofExpression = (InstanceofExpression) expression;
+ Type type = instanceofExpression.getRightOperand();
+ assertEquals("Not a simple type", ASTNode.SIMPLE_TYPE, type.getNodeType());
+ SimpleType simpleType = (SimpleType) type;
+ Name name = simpleType.getName();
+ assertEquals("Not a simple name", ASTNode.SIMPLE_NAME, name.getNodeType());
+ SimpleName simpleName = (SimpleName) name;
+ ITypeBinding typeBinding = simpleName.resolveTypeBinding();
+
+ List imports = compilationUnit.imports();
+ assertEquals("Wrong size", 2, imports.size());
+ ImportDeclaration importDeclaration = (ImportDeclaration) imports.get(0);
+ name = importDeclaration.getName();
+ assertEquals("Not a qualified name", ASTNode.QUALIFIED_NAME, name.getNodeType());
+ QualifiedName qualifiedName = (QualifiedName) name;
+ simpleName = qualifiedName.getName();
+ ITypeBinding typeBinding2 = simpleName.resolveTypeBinding();
+
+ assertTrue("not identical", typeBinding == typeBinding2);
+ assertTrue("not identical", typeBinding.isEqualTo(typeBinding2));
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=84778
+ */
+ public void test0598() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " int m(int i) {\n" +
+ " return /*start*/1 + 2 + ++i/*end*/;\n" +
+ " }\n" +
+ "}\n";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy);
+ assertEquals("Not an infix expression", ASTNode.INFIX_EXPRESSION, node.getNodeType());
+ assertEquals("Wrong debug string", "1 + 2 + ++i", node.toString());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=86541
+ */
+ public void test0599() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0599", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode node = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ String expectedResult =
+ "The hierarchy of the type X is inconsistent\n" +
+ "The type test0599.Zork2 cannot be resolved. It is indirectly referenced from required .class files";
+ assertProblemsSize(compilationUnit, 2, expectedResult);
+ compilationUnit.accept(new ASTVisitor() {
+ public void endVisit(MethodDeclaration methodDeclaration) {
+ Block body = methodDeclaration.getBody();
+ assertNotNull("No body", body);
+ assertTrue("No statements", body.statements().size() != 0);
+ }
+ });
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=87777
+ */
+ public void test0600() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0600", "Try.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode node = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0, 0);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement statement = (ExpressionStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding = methodInvocation.resolveMethodBinding().getMethodDeclaration();
+
+ sourceUnit = getCompilationUnit("Converter" , "src", "test0600", "C.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ node = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ IMethodBinding methodBinding2 = methodDeclaration.resolveBinding().getMethodDeclaration();
+
+ assertTrue("Not equals", methodBinding.isEqualTo(methodBinding2));
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=89014
+ */
+ public void test0601() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " Runnable one= new Runnable(){\n" +
+ " public void run() {\n" +
+ " }\n" +
+ " };\n" +
+ " Runnable two= new Runnable(){\n" +
+ " public void run() {\n" +
+ " }\n" +
+ " };\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not a class instance creation", ASTNode.CLASS_INSTANCE_CREATION, expression.getNodeType());
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ assertNotNull("No anonymous", anonymousClassDeclaration);
+ List bodyDeclarations = anonymousClassDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, bodyDeclaration.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+
+ node = getASTNode(compilationUnit, 0, 1);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ expression = fragment.getInitializer();
+ assertEquals("Not a class instance creation", ASTNode.CLASS_INSTANCE_CREATION, expression.getNodeType());
+ classInstanceCreation = (ClassInstanceCreation) expression;
+ anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ assertNotNull("No anonymous", anonymousClassDeclaration);
+ bodyDeclarations = anonymousClassDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size());
+ bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, bodyDeclaration.getNodeType());
+ methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ IMethodBinding methodBinding2 = methodDeclaration.resolveBinding();
+
+ assertFalse("Bindings are equals", methodBinding.isEqualTo(methodBinding2));
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=70526
+ */
+ public void test0602() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0602", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode node = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ compilationUnit.accept(new ASTVisitor() {
+ public boolean visit(StringLiteral stringLiteral) {
+ assertTrue("Wrong start position", stringLiteral.getStartPosition() != 0);
+ assertTrue("Wrong length", stringLiteral.getLength() != -1);
+ return false;
+ }
+ });
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=91098
+ */
+ public void test0603() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0603", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode node = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ assertProblemsSize(compilationUnit, 0);
+ compilationUnit.accept(new ASTVisitor() {
+ public boolean visit(SimpleType type) {
+ assertFalse("start cannot be -1", type.getStartPosition() == -1);
+ assertFalse("length cannot be 0", type.getLength() == 0);
+ return false;
+ }
+ public boolean visit(ArrayType type) {
+ assertFalse("start cannot be -1", type.getStartPosition() == -1);
+ assertFalse("length cannot be 0", type.getLength() == 0);
+ return true;
+ }
+ });
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=91098
+ */
+ public void test0604() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0604", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode node = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ assertProblemsSize(compilationUnit, 0);
+ compilationUnit.accept(new ASTVisitor() {
+ public boolean visit(SimpleType type) {
+ assertFalse("start cannot be -1", type.getStartPosition() == -1);
+ assertFalse("length cannot be 0", type.getLength() == 0);
+ return false;
+ }
+ public boolean visit(ArrayType type) {
+ assertFalse("start cannot be -1", type.getStartPosition() == -1);
+ assertFalse("length cannot be 0", type.getLength() == 0);
+ return true;
+ }
+ });
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=92059
+ * check resolvedType binding from variable ref (of array type)
+ */
+ public void test0605() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0605", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode node = runJLS3Conversion(sourceUnit, true, false);
+ assertNotNull(node);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0, 1);
+ assertEquals("Not a variable declaration", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement varDecl = (VariableDeclarationStatement) node;
+ List fragments = varDecl.fragments();
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertEquals("Not a qualified name", ASTNode.QUALIFIED_NAME, expression.getNodeType());
+ IBinding arraylength = ((QualifiedName)expression).resolveBinding();
+ IJavaElement element = arraylength.getJavaElement();
+ assertNull("Shouldn't be binding for arraylength", element);
+ Name name = ((QualifiedName) expression).getQualifier();
+ assertEquals("Not a simple name", ASTNode.SIMPLE_NAME, name.getNodeType());
+ ITypeBinding binding = name.resolveTypeBinding();
+ assertNotNull("No binding", binding);
+ assertTrue("No array", binding.isArray());
+
+ node = getASTNode(compilationUnit, 0, 0, 4);
+ assertEquals("Not a variable declaration", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ varDecl = (VariableDeclarationStatement) node;
+ fragments = varDecl.fragments();
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ expression = fragment.getInitializer();
+ assertEquals("Not a qualified name", ASTNode.QUALIFIED_NAME, expression.getNodeType());
+ name = ((QualifiedName) expression).getQualifier();
+ assertEquals("Not a simple name", ASTNode.QUALIFIED_NAME, name.getNodeType());
+ name = ((QualifiedName) name).getName();
+ assertEquals("Not a simple name", ASTNode.SIMPLE_NAME, name.getNodeType());
+ ITypeBinding binding2 = name.resolveTypeBinding();
+ assertNotNull("No binding", binding2);
+ assertTrue("No array", binding2.isArray());
+
+ assertEquals("Not same binding", binding, binding2);
+
+ node = getASTNode(compilationUnit, 0, 0, 2);
+ assertEquals("Not a variable declaration", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ varDecl = (VariableDeclarationStatement) node;
+ fragments = varDecl.fragments();
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ expression = fragment.getInitializer();
+ assertEquals("Not a qualified name", ASTNode.FIELD_ACCESS, expression.getNodeType());
+ expression = ((FieldAccess) expression).getExpression();
+ assertEquals("Not a simple name", ASTNode.FIELD_ACCESS, expression.getNodeType());
+ name = ((FieldAccess) expression).getName();
+ assertEquals("Not a simple name", ASTNode.SIMPLE_NAME, name.getNodeType());
+ ITypeBinding binding3 = name.resolveTypeBinding();
+ assertNotNull("No binding", binding3);
+ assertTrue("No array", binding3.isArray());
+
+ assertEquals("Not same binding", binding, binding3);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=89014
+ */
+ public void test0606() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " int i = 0;\n" +
+ " i += 1;\n" +
+ " String s = \"\";\n" +
+ " s += \"hello world\";\n" +
+ " System.out.println(i+s);\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0, 0, 1);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ Expression expression = ((ExpressionStatement) node).getExpression();
+ assertEquals("Not an assignment", ASTNode.ASSIGNMENT, expression.getNodeType());
+ Assignment assignment = (Assignment) expression;
+ assertEquals("Wrong operator", Assignment.Operator.PLUS_ASSIGN, assignment.getOperator());
+ ITypeBinding typeBinding = assignment.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding);
+ assertEquals("Wrong type", "int", typeBinding.getQualifiedName());
+
+ node = getASTNode(compilationUnit, 0, 0, 3);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ expression = ((ExpressionStatement) node).getExpression();
+ assertEquals("Not an assignment", ASTNode.ASSIGNMENT, expression.getNodeType());
+ assignment = (Assignment) expression;
+ assertEquals("Wrong operator", Assignment.Operator.PLUS_ASSIGN, assignment.getOperator());
+ typeBinding = assignment.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding);
+ assertEquals("Wrong type", "java.lang.String", typeBinding.getQualifiedName());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=95262
+ */
+ public void test0607() throws JavaModelException {
+ final char[] source = "private static Category[] values = new Category[]{v1, v2, v3};".toCharArray();
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
+ parser.setSource(source);
+ ASTNode root = parser.createAST(null);
+ assertNotNull("cannot be null", root);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=96698
+ */
+ public void test0608() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " for (int /*start*/i = 0/*end*/; i < args.length; i++) {\n" +
+ " System.out.println(args[i]);\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy);
+ assertEquals("Not a variable declaration fragment", ASTNode.VARIABLE_DECLARATION_FRAGMENT, node.getNodeType());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) node;
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ IJavaElement javaElement = variableBinding.getJavaElement();
+ assertNotNull("No java element", javaElement);
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=96698
+ */
+ public void test0609() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " int /*start*/i = 0/*end*/;\n" +
+ " System.out.println(i);\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy);
+ assertEquals("Not a variable declaration fragment", ASTNode.VARIABLE_DECLARATION_FRAGMENT, node.getNodeType());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) node;
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ IJavaElement javaElement = variableBinding.getJavaElement();
+ assertNotNull("No java element", javaElement);
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=98088
+ */
+ public void test0610() throws JavaModelException {
+ final ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0610", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ final ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) result;
+ assertProblemsSize(unit, 1, "The type Test is deprecated");
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=96698
+ */
+ public void test0611() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "abstract class SearchPattern {\n" +
+ "}\n" +
+ "class InternalSearchPattern extends SearchPattern {\n" +
+ " boolean mustResolve;\n" +
+ "}\n" +
+ "public class X {\n" +
+ " public static final int POSSIBLE_MATCH = 0;\n" +
+ " public static final int ACCURATE_MATCH = 1;\n" +
+ " \n" +
+ " public void foo(SearchPattern pattern) {\n" +
+ " int declarationLevel = ((InternalSearchPattern) pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH;\n" +
+ " System.out.println(declarationLevel);\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 2, 2, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ checkSourceRange(expression, "((InternalSearchPattern) pattern).mustResolve ? POSSIBLE_MATCH : ACCURATE_MATCH", contents);
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ public void test0612() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " void foo(boolean[]value) {\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ assertEquals("Wrong size", 1, parameters.size());
+ SingleVariableDeclaration variableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ checkSourceRange(variableDeclaration, "boolean[]value", contents);
+ Type type = variableDeclaration.getType();
+ checkSourceRange(type, "boolean[]", contents);
+ assertTrue("Not an array type", type.isArrayType());
+ ArrayType arrayType = (ArrayType) type;
+ Type componentType = arrayType.getComponentType();
+ assertTrue("Not a primitive type", componentType.isPrimitiveType());
+ PrimitiveType primitiveType = (PrimitiveType) componentType;
+ assertEquals("Not boolean", PrimitiveType.BOOLEAN, primitiveType.getPrimitiveTypeCode());
+ checkSourceRange(primitiveType, "boolean", contents);
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ public void test0613() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " void foo(boolean b) {\n" +
+ " Zork z = null;\n" +
+ " if (b) {\n" +
+ " System.out.println(z);\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false,
+ false,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 1, "Zork cannot be resolved to a type");
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding binding = fragment.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("LX;.foo(Z)V#z", binding.getKey());
+
+ node = getASTNode(unit, 0, 0, 1);
+ assertEquals("Not an if statement", ASTNode.IF_STATEMENT, node.getNodeType());
+ IfStatement ifStatement = (IfStatement) node;
+ Statement statement2 = ifStatement.getThenStatement();
+ assertEquals("Not a block", ASTNode.BLOCK, statement2.getNodeType());
+ Block block = (Block) statement2;
+ List statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size());
+
+ Statement statement3 = (Statement) statements.get(0);
+ assertEquals("Not a expression statement", ASTNode.EXPRESSION_STATEMENT, statement3.getNodeType());
+ ExpressionStatement expressionStatement = (ExpressionStatement) statement3;
+ Expression expression = expressionStatement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) expression;
+ List arguments = methodInvocation.arguments();
+ assertEquals("Wrong size", 1, arguments.size());
+ Expression expression2 = (Expression) arguments.get(0);
+ ITypeBinding typeBinding = expression2.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding);
+ assertEquals("LX;.foo(Z)V#z", binding.getKey());
+ assertEquals("Not a simple name", ASTNode.SIMPLE_NAME, expression2.getNodeType());
+ SimpleName simpleName = (SimpleName) expression2;
+ IBinding binding2 = simpleName.resolveBinding();
+ assertNotNull("Got a binding", binding2);
+ assertEquals("LX;.foo(Z)V#z", binding2.getKey());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ // https://bugs.eclipse.org/bugs/show_bug.cgi?id=105192
+ public void test0614() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "class T { void m() { for (i=0, j=0; i<10; i++, j++) ; }}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", false/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false);
+ final String expectedOutput = "class T {\n" +
+ " void m(){\n" +
+ " for (i=0, j=0; i < 10; i++, j++) ;\n" +
+ " }\n" +
+ "}\n";
+ assertEquals("Wrong output", Util.convertToIndependantLineDelimiter(expectedOutput), Util.convertToIndependantLineDelimiter(node.toString()));
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=100041
+ */
+ public void test0615() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "class X {\n" +
+ " static Object object;\n" +
+ " static void foo() {\n" +
+ " /**\n" +
+ " * javadoc comment.\n" +
+ " */\n" +
+ " if (object instanceof String) {\n" +
+ " final String clr = null;\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 1, 0);
+ assertNotNull("No node", node);
+ assertEquals("Not an if statement", ASTNode.IF_STATEMENT, node.getNodeType());
+ IfStatement ifStatement = (IfStatement) node;
+ String expectedSource = "if (object instanceof String) {\n" +
+ " final String clr = null;\n" +
+ " }";
+ checkSourceRange(ifStatement, expectedSource, contents);
+ Statement statement = ifStatement.getThenStatement();
+ assertNotNull("No then statement", statement);
+ assertEquals("not a block", ASTNode.BLOCK, statement.getNodeType());
+ Block block = (Block) statement;
+ expectedSource = "{\n" +
+ " final String clr = null;\n" +
+ " }";
+ checkSourceRange(block, expectedSource, contents);
+ List statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size());
+ Statement statement2 = (Statement) statements.get(0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, statement2.getNodeType());
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) statement2;
+ checkSourceRange(variableDeclarationStatement, "final String clr = null;", contents);
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=109333
+ */
+ public void test0616() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "class X {\n" +
+ " boolean val = true && false && true && false && true;\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ workingCopy.getBuffer().setContents(contents.toCharArray());
+ ASTNode node = runConversion(AST.JLS3, workingCopy, true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 1, "Dead code");
+ node = getASTNode(unit, 0, 0);
+ assertNotNull("No node", node);
+ assertEquals("Not a field declaration ", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ final FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ final List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ final Expression initializer = fragment.getInitializer();
+ assertNotNull("No initializer", initializer);
+ assertEquals("Not an infix expression", ASTNode.INFIX_EXPRESSION, initializer.getNodeType());
+ InfixExpression infixExpression = (InfixExpression) initializer;
+ final List extendedOperands = infixExpression.extendedOperands();
+ assertEquals("Wrong size", 3, extendedOperands.size());
+ assertEquals("Wrong operator", InfixExpression.Operator.CONDITIONAL_AND, infixExpression.getOperator());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=109333
+ */
+ public void test0617() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "class X {\n" +
+ " boolean val = true || false || true || false || true;\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ workingCopy.getBuffer().setContents(contents.toCharArray());
+ ASTNode node = runConversion(AST.JLS3, workingCopy, true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedOutput = "Dead code";
+ assertProblemsSize(unit, 1, expectedOutput);
+ node = getASTNode(unit, 0, 0);
+ assertNotNull("No node", node);
+ assertEquals("Not a field declaration ", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ final FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ final List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ final Expression initializer = fragment.getInitializer();
+ assertNotNull("No initializer", initializer);
+ assertEquals("Not an infix expression", ASTNode.INFIX_EXPRESSION, initializer.getNodeType());
+ InfixExpression infixExpression = (InfixExpression) initializer;
+ final List extendedOperands = infixExpression.extendedOperands();
+ assertEquals("Wrong size", 3, extendedOperands.size());
+ assertEquals("Wrong operator", InfixExpression.Operator.CONDITIONAL_OR, infixExpression.getOperator());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=109535
+ */
+ public void test0618() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " String f = \"\" + \"\" - 1;\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", false/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0);
+ assertNotNull("No node", node);
+ assertEquals("Not a field declaration ", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ final FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ final List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ final Expression initializer = fragment.getInitializer();
+ assertNotNull("No initializer", initializer);
+ assertEquals("Not an infix expression", ASTNode.INFIX_EXPRESSION, initializer.getNodeType());
+ InfixExpression infixExpression = (InfixExpression) initializer;
+ List extendedOperands = infixExpression.extendedOperands();
+ assertEquals("Wrong size", 0, extendedOperands.size());
+ assertEquals("Wrong operator", InfixExpression.Operator.MINUS, infixExpression.getOperator());
+ Expression leftOperand = infixExpression.getLeftOperand();
+ assertEquals("Not an infix expression", ASTNode.INFIX_EXPRESSION, leftOperand.getNodeType());
+ InfixExpression infixExpression2 = (InfixExpression) leftOperand;
+ extendedOperands = infixExpression.extendedOperands();
+ assertEquals("Wrong size", 0, extendedOperands.size());
+ assertEquals("Wrong operator", InfixExpression.Operator.PLUS, infixExpression2.getOperator());
+ assertEquals("Not a string literal", ASTNode.STRING_LITERAL, infixExpression2.getLeftOperand().getNodeType());
+ assertEquals("Not a string literal", ASTNode.STRING_LITERAL, infixExpression2.getRightOperand().getNodeType());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=109646
+ */
+ public void test0619() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter", "src", "test0619", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, false);
+ final CompilationUnit unit = (CompilationUnit) result;
+ assertProblemsSize(unit, 0);
+ ASTNode node = getASTNode(unit, 0, 0, 0);
+ assertNotNull("No node", node);
+ ASTNode statement = node;
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_STATEMENTS);
+ parser.setSource(source);
+ parser.setSourceRange(statement.getStartPosition(), statement.getLength());
+ parser.setCompilerOptions(JavaCore.getOptions());
+ ASTNode result2 = parser.createAST(null);
+ assertNotNull("No node", result2);
+ assertTrue("not a block", result2.getNodeType() == ASTNode.BLOCK);
+ Block block = (Block) result2;
+ List statements = block.statements();
+ assertEquals("wrong size", 1, statements.size());
+ Statement statement2 = (Statement) statements.get(0);
+ assertEquals("Statement is not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, statement2.getNodeType());
+ VariableDeclarationStatement declarationStatement = (VariableDeclarationStatement) statement2;
+ assertEquals("Wrong number of fragments", 4, declarationStatement.fragments().size());
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=109940
+ */
+ public void test0620() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println((int) \'\\0\');\n" +
+ " System.out.println((int) \'\\1\');\n" +
+ " System.out.println((int) \'\\2\');\n" +
+ " System.out.println((int) \'\\3\');\n" +
+ " System.out.println((int) \'\\4\');\n" +
+ " System.out.println((int) \'\\5\');\n" +
+ " System.out.println((int) \'\\6\');\n" +
+ " System.out.println((int) \'\\7\');\n" +
+ " System.out.println((int) \'\\077\');\n" +
+ " System.out.println((int) \'\\55\');\n" +
+ " System.out.println((int) \'\\77\');\n" +
+ " System.out.println((int) \'\\377\');\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", false/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ unit.accept(new ASTVisitor() {
+ public boolean visit(CharacterLiteral characterLiteral) {
+ try {
+ final String escapedValue = characterLiteral.getEscapedValue();
+ final char charValue = characterLiteral.charValue();
+ if (escapedValue.equals("\'\\0\'")) {
+ assertEquals("Wrong value", 0, charValue);
+ } else if (escapedValue.equals("\'\\1\'")) {
+ assertEquals("Wrong value", 1, charValue);
+ } else if (escapedValue.equals("\'\\2\'")) {
+ assertEquals("Wrong value", 2, charValue);
+ } else if (escapedValue.equals("\'\\3\'")) {
+ assertEquals("Wrong value", 3, charValue);
+ } else if (escapedValue.equals("\'\\4\'")) {
+ assertEquals("Wrong value", 4, charValue);
+ } else if (escapedValue.equals("\'\\5\'")) {
+ assertEquals("Wrong value", 5, charValue);
+ } else if (escapedValue.equals("\'\\6\'")) {
+ assertEquals("Wrong value", 6, charValue);
+ } else if (escapedValue.equals("\'\\7\'")) {
+ assertEquals("Wrong value", 7, charValue);
+ } else if (escapedValue.equals("\'\\077\'")) {
+ assertEquals("Wrong value", 63, charValue);
+ } else if (escapedValue.equals("\'\\55\'")) {
+ assertEquals("Wrong value", 45, charValue);
+ } else if (escapedValue.equals("\'\\77\'")) {
+ assertEquals("Wrong value", 63, charValue);
+ } else if (escapedValue.equals("\'\\377\'")) {
+ assertEquals("Wrong value", 255, charValue);
+ } else {
+ assertTrue("Should not get there", false);
+ }
+ } catch(IllegalArgumentException e) {
+ assertTrue("Should not happen", false);
+ }
+ return false;
+ }
+ });
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=109963
+ */
+ public void test0621() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " public void foo(int y) {\n" +
+ " switch (y) {\n" +
+ " case 1:\n" +
+ " int i,j;\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", false/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0, 0);
+ assertNotNull("No node", node);
+ assertEquals("Not a switch statement", ASTNode.SWITCH_STATEMENT, node.getNodeType());
+ SwitchStatement switchStatement = (SwitchStatement) node;
+ List statements = switchStatement.statements();
+ assertEquals("Wrong size", 2, statements.size());
+ Statement statement = (Statement) statements.get(1);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, statement.getNodeType());
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) statement;
+ assertEquals("Wrong size", 2, variableDeclarationStatement.fragments().size());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=92866
+ */
+ public void test0622() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println((int) \'\\0\');\n" +
+ " System.out.println((int) \'\\00\');\n" +
+ " System.out.println((int) \'\\000\');\n" +
+ " System.out.println((int) \'\\40\');\n" +
+ " System.out.println((int) \'\\040\');\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", false/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ unit.accept(new ASTVisitor() {
+ public boolean visit(CharacterLiteral characterLiteral) {
+ try {
+ characterLiteral.charValue();
+ } catch(IllegalArgumentException e) {
+ assertTrue("Should not happen", false);
+ }
+ return false;
+ }
+ });
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=116573
+ */
+ public void test0623() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "class X {\n" +
+ " X(boolean x, String y, String z) {}\n" +
+ " X(int x, String y) {}\n" +
+ " X(String x) {\n" +
+ " this(first, second);\n" +
+ " }\n" +
+ " void test() {\n" +
+ " new X(first, second);\n" +
+ " }\n" +
+ " class Z extends X {\n" +
+ " public Z() {\n" +
+ " super(first, second);\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedOutput =
+ "first cannot be resolved to a variable\n" +
+ "second cannot be resolved to a variable\n" +
+ "first cannot be resolved to a variable\n" +
+ "second cannot be resolved to a variable\n" +
+ "first cannot be resolved to a variable\n" +
+ "second cannot be resolved to a variable";
+ assertProblemsSize(unit, 6, expectedOutput);
+ unit.accept(new ASTVisitor() {
+ public boolean visit(ConstructorInvocation constructorInvocation) {
+ assertNotNull("No binding", constructorInvocation.resolveConstructorBinding());
+ return false;
+ }
+ public boolean visit(ClassInstanceCreation classInstanceCreation) {
+ assertNotNull("No binding", classInstanceCreation.resolveConstructorBinding());
+ return false;
+ }
+ });
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=118876
+ */
+ public void test0624() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X extend {}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedOutput =
+ "Syntax error on token \"extend\", delete this token";
+ assertProblemsSize(unit, 1, expectedOutput);
+ unit.accept(new ASTVisitor() {
+ public boolean visit(TypeDeclaration typeDeclaration) {
+ assertTrue("Should be malformed", isMalformed(typeDeclaration));
+ return false;
+ }
+ public boolean visit(CompilationUnit compilationUnit) {
+ assertFalse("Should not be malformed", isMalformed(compilationUnit));
+ return true;
+ }
+ });
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=118897
+ */
+ public void test0625() {
+ char[] source =
+ ("package test0305;\n" + //$NON-NLS-1$
+ "\n" + //$NON-NLS-1$
+ "class Test {\n" + //$NON-NLS-1$
+ " public void foo(int arg) {}\n" + //$NON-NLS-1$
+ "}").toCharArray(); //$NON-NLS-1$
+ IJavaProject project = getJavaProject("Converter"); //$NON-NLS-1$
+ ASTNode result = runConversion(AST.JLS3, source, "Test.java", project); //$NON-NLS-1$
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertTrue("not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNull("Got a type binding", typeBinding); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=118897
+ */
+ public void test0626() {
+ char[] source =
+ ("package java.lang;\n" + //$NON-NLS-1$
+ "\n" + //$NON-NLS-1$
+ "class Object {\n" + //$NON-NLS-1$
+ " public void foo(int arg) {}\n" + //$NON-NLS-1$
+ "}").toCharArray(); //$NON-NLS-1$
+ IJavaProject project = getJavaProject("Converter"); //$NON-NLS-1$
+ ASTNode result = runConversion(AST.JLS3, source, "Object.java", project); //$NON-NLS-1$
+ assertNotNull("No compilation unit", result); //$NON-NLS-1$
+ assertTrue("result is not a compilation unit", result instanceof CompilationUnit); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ ASTNode node = getASTNode(compilationUnit, 0);
+ assertTrue("not a TypeDeclaration", node instanceof TypeDeclaration); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNull("Got a type binding", typeBinding); //$NON-NLS-1$
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=116833
+ */
+ public void test0627() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " void m() {\n" +
+ " error();\n" +
+ " new Cloneable() {\n" +
+ " void xx() {}\n" +
+ " };\n" +
+ " new Cloneable() {\n" +
+ " void xx() {}\n" +
+ " };\n" + " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedOutput =
+ "The method error() is undefined for the type X";
+ assertProblemsSize(unit, 1, expectedOutput);
+ node = getASTNode(unit, 0, 0, 1);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ Expression expression = ((ExpressionStatement) node).getExpression();
+ assertEquals("Not a class instance creation", ASTNode.CLASS_INSTANCE_CREATION, expression.getNodeType());
+ AnonymousClassDeclaration anonymousClassDeclaration = ((ClassInstanceCreation) expression).getAnonymousClassDeclaration();
+ assertNotNull("No anonymous class declaration", anonymousClassDeclaration);
+ List bodyDeclarations = anonymousClassDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, bodyDeclaration.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ IMethodBinding methodBinding = methodDeclaration.resolveBinding();
+
+ node = getASTNode(unit, 0, 0, 2);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ expression = ((ExpressionStatement) node).getExpression();
+ assertEquals("Not a class instance creation", ASTNode.CLASS_INSTANCE_CREATION, expression.getNodeType());
+ anonymousClassDeclaration = ((ClassInstanceCreation) expression).getAnonymousClassDeclaration();
+ assertNotNull("No anonymous class declaration", anonymousClassDeclaration);
+ bodyDeclarations = anonymousClassDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size());
+ bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, bodyDeclaration.getNodeType());
+ methodDeclaration = (MethodDeclaration) bodyDeclaration;
+ IMethodBinding methodBinding2 = methodDeclaration.resolveBinding();
+
+ assertFalse("Should not be equal", methodBinding.isEqualTo(methodBinding2));
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=125270
+ */
+ public void test0628() throws JavaModelException {
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_EXPRESSION);
+ String source = "{\"red\", \"yellow\"}";
+ parser.setSource(source.toCharArray());
+ parser.setSourceRange(0, source.length());
+ parser.setCompilerOptions(JavaCore.getOptions());
+ ASTNode result = parser.createAST(null);
+ assertNotNull("No node", result);
+ assertEquals("not an array initializer", ASTNode.ARRAY_INITIALIZER, result.getNodeType());
+ ArrayInitializer arrayInitializer = (ArrayInitializer) result;
+ List expressions = arrayInitializer.expressions();
+ assertEquals("Wrong size", 2, expressions.size());
+ assertEquals("Wrong type", ASTNode.STRING_LITERAL, ((Expression) expressions.get(0)).getNodeType());
+ assertEquals("Wrong type", ASTNode.STRING_LITERAL, ((Expression) expressions.get(1)).getNodeType());
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=126598
+ */
+ public void test0629() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0629", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true, true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ String expectedOutput =
+ "Syntax error on token \",\", invalid VariableInitializer";
+ assertProblemsSize(compilationUnit, 1, expectedOutput);
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a compilation unit", ASTNode.FIELD_DECLARATION, node.getNodeType()); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ checkSourceRange(fragment, "s = {\"\",,,}", source);
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=126598
+ */
+ public void test0630() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0630", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true, true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ String expectedOutput =
+ "Syntax error on token \",\", invalid VariableInitializer";
+ assertProblemsSize(compilationUnit, 1, expectedOutput);
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=126598
+ */
+ public void test0631() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0631", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ char[] source = sourceUnit.getSource().toCharArray();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true, true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType()); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) result;
+ String expectedOutput =
+ "Syntax error, insert \"}\" to complete ArrayInitializer\n" +
+ "Syntax error, insert \";\" to complete FieldDeclaration\n" +
+ "Syntax error, insert \"}\" to complete ClassBody";
+ assertProblemsSize(compilationUnit, 3, expectedOutput);
+ ASTNode node = getASTNode(compilationUnit, 0, 0);
+ assertEquals("Not a compilation unit", ASTNode.FIELD_DECLARATION, node.getNodeType()); //$NON-NLS-1$
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ checkSourceRange(fragment, "s = {\"\",,,", source);
+ assertTrue("Not initializer", fragment.getInitializer() == null);
+ assertTrue("Not a malformed node", isMalformed(fragment));
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=128539
+ */
+ public void test0632() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " void m(int state) {\n" +
+ " switch (state) {\n" +
+ " case 4:\n" +
+ " double M0,M1;\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a switch statement", ASTNode.SWITCH_STATEMENT, node.getNodeType());
+ SwitchStatement statement = (SwitchStatement) node;
+ List statements = statement.statements();
+ assertEquals("wrong size", 2, statements.size());
+ assertEquals("Not a switch case", ASTNode.SWITCH_CASE, ((ASTNode) statements.get(0)).getNodeType());
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, ((ASTNode) statements.get(1)).getNodeType());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=128539
+ */
+ public void test0633() {
+ String src = "switch (state) {case 4:double M0,M1;}";
+ char[] source = src.toCharArray();
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind (ASTParser.K_STATEMENTS);
+ parser.setSource (source);
+ ASTNode result = parser.createAST (null);
+ assertNotNull("no result", result);
+ assertEquals("Wrong type", ASTNode.BLOCK, result.getNodeType());
+ Block block = (Block) result;
+ List statements = block.statements();
+ assertNotNull("No statements", statements);
+ assertEquals("Wrong size", 1, statements.size());
+ final ASTNode node = (ASTNode) statements.get(0);
+ assertEquals("Not a switch statement", ASTNode.SWITCH_STATEMENT, node.getNodeType());
+ SwitchStatement statement = (SwitchStatement) node;
+ statements = statement.statements();
+ assertEquals("wrong size", 2, statements.size());
+ assertEquals("Not a switch case", ASTNode.SWITCH_CASE, ((ASTNode) statements.get(0)).getNodeType());
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, ((ASTNode) statements.get(1)).getNodeType());
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=128823
+ */
+ public void test0634() throws JavaModelException {
+ try {
+ String src =
+ "public class X {\n" +
+ " void foo() {\n" +
+ " int i1 i1;\n" +
+ " int i2 i2;\n" +
+ " int i3 i3;\n" +
+ " int i4 i4;\n" +
+ " int i5 i5;\n" +
+ " int i6 i6;\n" +
+ " int i7 i7;\n" +
+ " int i8 i8;\n" +
+ " int i9 i9;\n" +
+ " int i10 i10;\n" +
+ " int i11 i11;\n" +
+ " \n" +
+ " for for ;;){}\n" +
+ " }\n" +
+ "}";
+
+ char[] source = src.toCharArray();
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind (ASTParser.K_COMPILATION_UNIT);
+ parser.setSource (source);
+ parser.setStatementsRecovery(true);
+ ASTNode result = parser.createAST (null);
+ assertNotNull("no result", result);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ assertTrue("ArrayIndexOutOfBoundsException", false);
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=128960
+ */
+ public void test0635() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " void foo(Object tab[]) {\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration declaration = (MethodDeclaration) node;
+ List parameters = declaration.parameters();
+ assertEquals("wrong number", 1, parameters.size());
+ SingleVariableDeclaration variableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ checkSourceRange(variableDeclaration, "Object tab[]", contents);
+ checkSourceRange(variableDeclaration.getType(), "Object", contents);
+ checkSourceRange(variableDeclaration.getName(), "tab", contents);
+ assertEquals("wrong number of extra dimensions", 1, variableDeclaration.getExtraDimensions());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=128960
+ */
+ public void test0636() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " void foo(java.lang.Object tab[]) {\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration declaration = (MethodDeclaration) node;
+ List parameters = declaration.parameters();
+ assertEquals("wrong number", 1, parameters.size());
+ SingleVariableDeclaration variableDeclaration = (SingleVariableDeclaration) parameters.get(0);
+ checkSourceRange(variableDeclaration, "java.lang.Object tab[]", contents);
+ checkSourceRange(variableDeclaration.getType(), "java.lang.Object", contents);
+ checkSourceRange(variableDeclaration.getName(), "tab", contents);
+ assertEquals("wrong number of extra dimensions", 1, variableDeclaration.getExtraDimensions());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=128961
+ */
+ public void test0637() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " void foo() {\n" +
+ " for( int i = (1); ; ) {\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a for statement", ASTNode.FOR_STATEMENT, node.getNodeType());
+ ForStatement forStatement = (ForStatement) node;
+ List inits = forStatement.initializers();
+ assertEquals("Wrong size", 1, inits.size());
+ Expression expression = (Expression) inits.get(0);
+ assertEquals("Not a variable declaration expression", ASTNode.VARIABLE_DECLARATION_EXPRESSION, expression.getNodeType());
+ VariableDeclarationExpression declarationExpression = (VariableDeclarationExpression) expression;
+ List fragments = declarationExpression.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression initializer = fragment.getInitializer();
+ checkSourceRange(initializer, "(1)", contents);
+ checkSourceRange(fragment, "i = (1)", contents);
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=128961
+ */
+ public void test0638() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " int i = (1);\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression initializer = fragment.getInitializer();
+ checkSourceRange(initializer, "(1)", contents);
+ checkSourceRange(fragment, "i = (1)", contents);
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=128961
+ */
+ public void test0639() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " void foo() {\n" +
+ " for( int i = (1), j = 0; ; ) {\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a for statement", ASTNode.FOR_STATEMENT, node.getNodeType());
+ ForStatement forStatement = (ForStatement) node;
+ List inits = forStatement.initializers();
+ assertEquals("Wrong size", 1, inits.size());
+ Expression expression = (Expression) inits.get(0);
+ assertEquals("Not a variable declaration expression", ASTNode.VARIABLE_DECLARATION_EXPRESSION, expression.getNodeType());
+ VariableDeclarationExpression declarationExpression = (VariableDeclarationExpression) expression;
+ List fragments = declarationExpression.fragments();
+ assertEquals("Wrong size", 2, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression initializer = fragment.getInitializer();
+ checkSourceRange(initializer, "(1)", contents);
+ checkSourceRange(fragment, "i = (1)", contents);
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+ /*
+ * Ensures that 2 type bindings (one from .class file, the other from attache source) are "isEqualTo(...)".
+ * (regression test for bug 130317 ASTParser with IClassFile as source creates type bindings that are not isEqualTo(..) binary bindings)
+ */
+ public void test0641() throws JavaModelException {
+ // Integer from attached source
+ IClassFile classFile = getClassFile("Converter", getConverterJCLPath().toOSString(), "java.lang", "Integer.class");
+ String source = classFile.getSource();
+ MarkerInfo markerInfo = new MarkerInfo(source);
+ markerInfo.astStarts = new int[] {source.indexOf("public")};
+ markerInfo.astEnds = new int[] {source.lastIndexOf('}') + 1};
+ ASTNode node = buildAST(markerInfo, classFile);
+ IBinding bindingFromAttachedSource = ((TypeDeclaration) node).resolveBinding();
+
+ ICompilationUnit workingCopy = null;
+ try {
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " /*start*/Integer/*end*/ field;\n" +
+ "}";
+ IBinding[] bindings = resolveBindings(contents, workingCopy);
+ assertTrue("2 type bindings should be equals", bindingFromAttachedSource.isEqualTo(bindings[0]));
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=129330
+ */
+ public void test0642() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "import java.awt.Point;\n" +
+ "public class X {\n" +
+ " public void foo(Point p, int[] a) {\n" +
+ " p.x;\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 1, "Syntax error, insert \"AssignmentOperator Expression\" to complete Expression");
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ assertTrue("Not recovered", isRecovered(node));
+ final Expression expression = ((ExpressionStatement) node).getExpression();
+ assertEquals("Not a qualified name", ASTNode.QUALIFIED_NAME, expression.getNodeType());
+ assertTrue("Not recovered", isRecovered(expression));
+ checkSourceRange(expression, "p.x", contents);
+ checkSourceRange(node, "p.x;", contents);
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=129330
+ */
+ public void test0643() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "import java.awt.Point;\n" +
+ "public class X {\n" +
+ " public void foo(Point p, int[] a) {\n" +
+ " a[0];\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 1, "Syntax error, insert \"AssignmentOperator Expression\" to complete Expression");
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ assertTrue("Not recovered", isRecovered(node));
+ final Expression expression = ((ExpressionStatement) node).getExpression();
+ assertEquals("Not an array access", ASTNode.ARRAY_ACCESS, expression.getNodeType());
+ assertTrue("Not recovered", isRecovered(expression));
+ checkSourceRange(expression, "a[0]", contents);
+ checkSourceRange(node, "a[0];", contents);
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=129330
+ */
+ public void test0644() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " public void foo() {\n" +
+ " int x =;\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 1, "Syntax error on token \"=\", VariableInitializer expected after this token");
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a vaviable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertNull("No initializer", expression);
+ assertTrue("Not recovered", isRecovered(fragment));
+ checkSourceRange(fragment, "x =", contents);
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=135997
+ */
+ public void test0645() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " {\n" +
+ " new Object();\n" +
+ " Object.equ;\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(
+ unit,
+ 2,
+ "Object.equ cannot be resolved to a variable\n" +
+ "Syntax error, insert \"AssignmentOperator Expression\" to complete Expression");
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a field declaration statement", ASTNode.INITIALIZER, node.getNodeType());
+ Initializer initializer = (Initializer) node;
+ checkSourceRange(
+ initializer,
+ "{\n" +
+ " new Object();\n" +
+ " Object.equ;\n" +
+ " }",
+ contents);
+ Block block = initializer.getBody();
+ checkSourceRange(
+ block,
+ "{\n" +
+ " new Object();\n" +
+ " Object.equ;\n" +
+ " }",
+ contents);
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=136972
+ */
+ public void test0646() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " static {\n" +
+ " class A\n" +
+ " Object o = new Object(){\n" +
+ " void test(){\n" +
+ " }\n" +
+ " };\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=141043
+ */
+ public void test0647() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " public void run(int i) {\n" +
+ " }\n" +
+ " public void foo() {\n" +
+ " new Runnable() {\n" +
+ " public void run() {\n" +
+ " run(1); \n" +
+ " }\n" +
+ " };\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 1, "The method run() in the type new Runnable(){} is not applicable for the arguments (int)");
+ node = getASTNode(unit, 0, 1, 0);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ Expression expression = ((ExpressionStatement) node).getExpression();
+ ITypeBinding typeBinding = expression.resolveTypeBinding();
+ IMethodBinding[] methodBindings = typeBinding.getDeclaredMethods();
+ assertEquals("Wrong size", 2, methodBindings.length);
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=147877
+ */
+ public void test0648() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " public void foo(int[] a) {\n" +
+ " int i = a[0];\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a vaviable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertNotNull("No initializer", expression);
+ checkSourceRange(expression, "a[0]", contents);
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=147877
+ */
+ public void test0649() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " public void foo(int[] a) {\n" +
+ " int i = a[0\\u005D;\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a vaviable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertNotNull("No initializer", expression);
+ checkSourceRange(expression, "a[0\\u005D", contents);
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=147877
+ */
+ public void test0650() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " public void foo(int[] a) {\n" +
+ " int[] i = new int[0];\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a vaviable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertNotNull("No initializer", expression);
+ checkSourceRange(expression, "new int[0]", contents);
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=147877
+ */
+ public void test0651() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " public void foo(int[] a) {\n" +
+ " int[] i = new int[0\\u005D;\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a vaviable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ Expression expression = fragment.getInitializer();
+ assertNotNull("No initializer", expression);
+ checkSourceRange(expression, "new int[0\\u005D", contents);
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * @bug 149126: IllegalArgumentException in ASTConverter
+ * @see "https://bugs.eclipse.org/bugs/show_bug.cgi?id=149126"
+ */
+ public void test0652() throws CoreException {
+ ASTResult result = this.buildMarkedAST(
+ "/Converter/src/TestCharset.java",
+ "import java.nio.ByteBuffer;\n" +
+ "import java.nio.CharBuffer;\n" +
+ "import java.nio.charset.Charset;\n" +
+ "import java.nio.charset.CharsetDecoder;\n" +
+ "import java.nio.charset.CharsetEncoder;\n" +
+ "import java.nio.charset.CoderResult;\n" +
+ "public class TestCharset extends Charset {\n" +
+ " public CharsetDecoder newDecoder() {\n" +
+ " return new CharsetDecoder(this, 2.0, 2.0) {\n" +
+ " CharsetDecoder(CharSet\n" +
+ " protected CoderResult decodeLoop(ByteBuffer in,\n" +
+ "CharBuffer out) {\n" +
+ " return null;\n" +
+ " }\n" +
+ " };;\n" +
+ " }\n" +
+ " public CharsetEncoder newEncoder() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}");
+
+ assertASTResult(
+ "===== AST =====\n" +
+ "import java.nio.ByteBuffer;\n" +
+ "import java.nio.CharBuffer;\n" +
+ "import java.nio.charset.Charset;\n" +
+ "import java.nio.charset.CharsetDecoder;\n" +
+ "import java.nio.charset.CharsetEncoder;\n" +
+ "import java.nio.charset.CoderResult;\n" +
+ "public class TestCharset extends Charset {\n" +
+ " public CharsetDecoder newDecoder(){\n" +
+ " return new CharsetDecoder(this,2.0,2.0){\n" +
+ " void CharsetDecoder(){\n" +
+ " }\n" +
+ " protected CoderResult decodeLoop( ByteBuffer in, CharBuffer out){\n" +
+ " return null;\n" +
+ " }\n" +
+ " }\n" +
+ ";\n" +
+ " ;\n" +
+ " }\n" +
+ " public CharsetEncoder newEncoder(){\n" +
+ " return null;\n" +
+ " }\n" +
+ "}\n" +
+ "\n" +
+ "===== Details =====\n" +
+ "===== Problems =====\n" +
+ "1. ERROR in /Converter/src/TestCharset.java (at line 1)\n" +
+ " import java.nio.ByteBuffer;\n" +
+ " ^^^^^^^^\n" +
+ "The import java.nio cannot be resolved\n" +
+ "2. ERROR in /Converter/src/TestCharset.java (at line 2)\n" +
+ " import java.nio.CharBuffer;\n" +
+ " ^^^^^^^^\n" +
+ "The import java.nio cannot be resolved\n" +
+ "3. ERROR in /Converter/src/TestCharset.java (at line 3)\n" +
+ " import java.nio.charset.Charset;\n" +
+ " ^^^^^^^^\n" +
+ "The import java.nio cannot be resolved\n" +
+ "4. ERROR in /Converter/src/TestCharset.java (at line 4)\n" +
+ " import java.nio.charset.CharsetDecoder;\n" +
+ " ^^^^^^^^\n" +
+ "The import java.nio cannot be resolved\n" +
+ "5. ERROR in /Converter/src/TestCharset.java (at line 5)\n" +
+ " import java.nio.charset.CharsetEncoder;\n" +
+ " ^^^^^^^^\n" +
+ "The import java.nio cannot be resolved\n" +
+ "6. ERROR in /Converter/src/TestCharset.java (at line 6)\n" +
+ " import java.nio.charset.CoderResult;\n" +
+ " ^^^^^^^^\n" +
+ "The import java.nio cannot be resolved\n" +
+ "7. ERROR in /Converter/src/TestCharset.java (at line 7)\n" +
+ " public class TestCharset extends Charset {\n" +
+ " ^^^^^^^\n" +
+ "Charset cannot be resolved to a type\n" +
+ "8. ERROR in /Converter/src/TestCharset.java (at line 8)\n" +
+ " public CharsetDecoder newDecoder() {\n" +
+ " ^^^^^^^^^^^^^^\n" +
+ "CharsetDecoder cannot be resolved to a type\n" +
+ "9. ERROR in /Converter/src/TestCharset.java (at line 9)\n" +
+ " return new CharsetDecoder(this, 2.0, 2.0) {\n" +
+ " ^^^^^^^^^^^^^^\n" +
+ "CharsetDecoder cannot be resolved to a type\n" +
+ "10. ERROR in /Converter/src/TestCharset.java (at line 10)\n" +
+ " CharsetDecoder(CharSet\n" +
+ " ^^^^^^^^^^^^^^^^^^^^^^\n" +
+ "Syntax error on token(s), misplaced construct(s)\n" +
+ "11. ERROR in /Converter/src/TestCharset.java (at line 10)\n" +
+ " CharsetDecoder(CharSet\n" +
+ " ^^^^^^^^^^^^^^^\n" +
+ "Return type for the method is missing\n" +
+ "12. ERROR in /Converter/src/TestCharset.java (at line 11)\n" +
+ " protected CoderResult decodeLoop(ByteBuffer in,\n" +
+ " ^^^^^^^^^^^\n" +
+ "CoderResult cannot be resolved to a type\n" +
+ "13. ERROR in /Converter/src/TestCharset.java (at line 11)\n" +
+ " protected CoderResult decodeLoop(ByteBuffer in,\n" +
+ " ^^^^^^^^^^\n" +
+ "ByteBuffer cannot be resolved to a type\n" +
+ "14. ERROR in /Converter/src/TestCharset.java (at line 12)\n" +
+ " CharBuffer out) {\n" +
+ " ^^^^^^^^^^\n" +
+ "CharBuffer cannot be resolved to a type\n" +
+ "15. ERROR in /Converter/src/TestCharset.java (at line 17)\n" +
+ " public CharsetEncoder newEncoder() {\n" +
+ " ^^^^^^^^^^^^^^\n" +
+ "CharsetEncoder cannot be resolved to a type\n",
+ result);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=150409
+ */
+ public void test0653() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0653", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType());
+ CompilationUnit unit = (CompilationUnit) result;
+
+ ASTNode node = getASTNode(unit, 0, 2, 0);
+ assertEquals("Not a method invocation", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement statement = (ExpressionStatement) node;
+ MethodInvocation invocation = (MethodInvocation) statement.getExpression();
+ List arguments = invocation.arguments();
+ assertEquals("Wrong size", 1, arguments.size());
+ Expression argument = (Expression) arguments.get(0);
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, argument.getNodeType());
+ invocation = (MethodInvocation) argument;
+ Expression expression = invocation.getExpression();
+ assertEquals("Not a method invocation", ASTNode.FIELD_ACCESS, expression.getNodeType());
+ FieldAccess fieldAccess = (FieldAccess) expression;
+ IVariableBinding variableBinding = fieldAccess.resolveFieldBinding();
+ assertNotNull("No variable binding", variableBinding);
+ }
+
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=148224
+ */
+ public void test0654() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " int i;\n" +
+ " public void foo(int[] a) {\n" +
+ " }\n" +
+ " String s;\n" +
+ " public String[][] bar() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration declaration = (FieldDeclaration) node;
+ Type type = declaration.getType();
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertTrue("Not a primitive type", typeBinding.isPrimitive());
+ assertEquals("Not int", "int", typeBinding.getName());
+ try {
+ typeBinding.createArrayType(-1);
+ assertTrue("Should throw an exception", false);
+ } catch(IllegalArgumentException exception) {
+ // ignore
+ }
+ try {
+ typeBinding.createArrayType(0);
+ assertTrue("Should throw an exception", false);
+ } catch(IllegalArgumentException exception) {
+ // ignore
+ }
+ try {
+ typeBinding.createArrayType(256);
+ assertTrue("Should throw an exception", false);
+ } catch(IllegalArgumentException exception) {
+ // ignore
+ }
+ ITypeBinding binding = typeBinding.createArrayType(2);
+ assertEquals("Wrong dimensions", 2, binding.getDimensions());
+ assertTrue("Not an array type binding", binding.isArray());
+ ITypeBinding componentType = binding.getComponentType();
+ assertTrue("Not an array type binding", componentType.isArray());
+ assertEquals("Wrong dimensions", 1, componentType.getDimensions());
+ componentType = componentType.getComponentType();
+ assertFalse("An array type binding", componentType.isArray());
+ assertEquals("Wrong dimensions", 0, componentType.getDimensions());
+
+ binding = typeBinding.createArrayType(1);
+ node = getASTNode(unit, 0, 1);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ List parameters = methodDeclaration.parameters();
+ assertEquals("Wrong size", 1, parameters.size());
+ SingleVariableDeclaration parameter = (SingleVariableDeclaration) parameters.get(0);
+ Type type2 = parameter.getType();
+ ITypeBinding typeBinding2 = type2.resolveBinding();
+ assertNotNull("No binding", typeBinding2);
+ assertTrue("Not an array binding", typeBinding2.isArray());
+ assertEquals("Wrong dimension", 1, typeBinding2.getDimensions());
+ assertEquals("Wrong type", "int", typeBinding2.getElementType().getName());
+ assertTrue("Should be equals", binding == typeBinding2);
+
+ binding = typeBinding2.createArrayType(3);
+ assertTrue("Not an array binding", binding.isArray());
+ assertEquals("Wrong dimension", 4, binding.getDimensions());
+
+ node = getASTNode(unit, 0, 2);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ declaration = (FieldDeclaration) node;
+ type = declaration.getType();
+ typeBinding = type.resolveBinding();
+ assertTrue("A primitive type", !typeBinding.isPrimitive());
+ assertEquals("Not String", "String", typeBinding.getName());
+
+ binding = typeBinding.createArrayType(1);
+ node = getASTNode(unit, 0, 3);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ methodDeclaration = (MethodDeclaration) node;
+ type = methodDeclaration.getReturnType2();
+ assertNotNull("No return type", type);
+ typeBinding2 = type.resolveBinding();
+ assertNotNull("No binding", typeBinding2);
+ assertTrue("Not an array binding", typeBinding2.isArray());
+ assertEquals("Wrong dimension", 2, typeBinding2.getDimensions());
+ assertEquals("Wrong type", "String", typeBinding2.getElementType().getName());
+ typeBinding2 = typeBinding2.getComponentType();
+ assertTrue("Not an array binding", typeBinding2.isArray());
+ assertEquals("Wrong dimension", 1, typeBinding2.getDimensions());
+ assertTrue("Should be equals", binding == typeBinding2);
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=157570
+ */
+ public void test0655() {
+ String src = "public static void m1()\n" +
+ " {\n" +
+ " int a;\n" +
+ " int b;\n" +
+ " }\n" +
+ "\n" +
+ " public static void m2()\n" +
+ " {\n" +
+ " int c;\n" +
+ " int d;\n" +
+ " }";
+ char[] source = src.toCharArray();
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind (ASTParser.K_STATEMENTS);
+ parser.setStatementsRecovery(true);
+ parser.setSource (source);
+ ASTNode result = parser.createAST (null);
+ assertNotNull("no result", result);
+ assertEquals("Not a block", ASTNode.BLOCK, result.getNodeType());
+ Block block = (Block) result;
+ List statements = block.statements();
+ for (Iterator iterator = statements.iterator(); iterator.hasNext(); ) {
+ Statement statement = (Statement) iterator.next();
+ if (statement.getNodeType() == ASTNode.EXPRESSION_STATEMENT) {
+ // only the expression statements are recovered. The others are considered as valid blocks.
+ assertTrue(isRecovered(statement));
+ }
+ }
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=157570
+ */
+ public void test0656() {
+ String src = "public static void m1()\n" +
+ " {\n" +
+ " int a;\n" +
+ " int b;\n" +
+ " }\n" +
+ "\n" +
+ " public static void m2()\n" +
+ " {\n" +
+ " int c;\n" +
+ " int d;\n" +
+ " }";
+ char[] source = src.toCharArray();
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind (ASTParser.K_STATEMENTS);
+ parser.setStatementsRecovery(false);
+ parser.setSource (source);
+ ASTNode result = parser.createAST (null);
+ assertNotNull("no result", result);
+ assertEquals("Not a block", ASTNode.BLOCK, result.getNodeType());
+ Block block = (Block) result;
+ List statements = block.statements();
+ assertEquals("Should be empty", 0, statements.size());
+ }
+
+ // http://dev.eclipse.org/bugs/show_bug.cgi?id=160198
+ public void test0657() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0657", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ICompilationUnit sourceUnit2 = getCompilationUnit("Converter" , "src", "test0657", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ class TestASTRequestor extends ASTRequestor {
+ public ArrayList asts = new ArrayList();
+ public void acceptAST(ICompilationUnit source, CompilationUnit compilationUnit) {
+ this.asts.add(compilationUnit);
+ }
+ public void acceptBinding(String bindingKey, IBinding binding) {
+ }
+ }
+ TestASTRequestor requestor = new TestASTRequestor();
+ resolveASTs(
+ new ICompilationUnit[] {sourceUnit, sourceUnit2},
+ new String[0],
+ requestor,
+ getJavaProject("Converter"),
+ sourceUnit.getOwner()
+ );
+ ArrayList arrayList = requestor.asts;
+ assertEquals("Wrong size", 2, arrayList.size());
+ int problemsCount = 0;
+ for (int i = 0, max = arrayList.size(); i < max; i++) {
+ Object current = arrayList.get(i);
+ assertTrue("not a compilation unit", current instanceof CompilationUnit);
+ CompilationUnit unit = (CompilationUnit) current;
+ IProblem[] problems = unit.getProblems();
+ problemsCount += problems.length;
+ }
+ assertEquals("wrong size", 1, problemsCount);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=157570
+ */
+ public void test0658() {
+ String src = "public static void m1()\n" +
+ " {\n" +
+ " int a;\n" +
+ " int b;\n" +
+ " }\n" +
+ "\n" +
+ " public static void m2()\n" +
+ " {\n" +
+ " int c;\n" +
+ " int d;\n" +
+ " }";
+ char[] source = src.toCharArray();
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind (ASTParser.K_STATEMENTS);
+ parser.setStatementsRecovery(true);
+ parser.setSource (source);
+ ASTNode result = parser.createAST (null);
+ assertNotNull("no result", result);
+ assertEquals("Not a block", ASTNode.BLOCK, result.getNodeType());
+ Block block = (Block) result;
+ List statements = block.statements();
+ assertEquals("Should be empty", 4, statements.size());
+ assertTrue("Not recovered", isRecovered(block));
+ ASTNode root = block.getRoot();
+ assertNotNull("No root", root);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, root.getNodeType());
+ CompilationUnit unit = (CompilationUnit) root;
+ String errors =
+ "Syntax error on token(s), misplaced construct(s)\n" +
+ "Syntax error, insert \";\" to complete BlockStatements\n" +
+ "Syntax error on token(s), misplaced construct(s)\n" +
+ "Syntax error, insert \";\" to complete Statement";
+ assertProblemsSize(unit, 4, errors);
+ }
+
+ public void test0659() throws CoreException, JavaModelException {
+ IJavaProject javaProject = createJavaProject("P659", new String[] { "src" }, new String[0], "bin");
+ try {
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_COMPILATION_UNIT);
+ parser.setStatementsRecovery(true);
+ parser.setBindingsRecovery(true);
+ String source ="package java.lang;\n" +
+ "public class Object {\n" +
+ " public String toString() {\n" +
+ " return \"\";\n" +
+ " }\n" +
+ "}";
+ parser.setSource(source.toCharArray());
+ parser.setProject(javaProject);
+ parser.setResolveBindings(true);
+ parser.setUnitName("Object.java");
+ ASTNode result = parser.createAST (null);
+ assertNotNull("no result", result);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, result.getNodeType());
+ CompilationUnit unit = (CompilationUnit) result;
+ ASTNode node = getASTNode(unit, 0, 0);
+ assertNotNull("No node", node);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration declaration = (MethodDeclaration) node;
+ Block block = declaration.getBody();
+ assertNotNull("no block", block);
+ List statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size());
+ ReturnStatement returnStatement = (ReturnStatement) statements.get(0);
+ Expression expression = returnStatement.getExpression();
+ assertNotNull("No expression", expression);
+ ITypeBinding binding = expression.resolveTypeBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("LString;", binding.getKey());
+ } finally {
+ deleteProject("P659");
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=144858
+ */
+ public void test0660() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " void foo() {\n" +
+ " int x = 0;\n" +
+ " String x = \"\"; //$NON-NLS-1$\n" +
+ " x.toString();\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 1, "Duplicate local variable x");
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "x", variableBinding.getName());
+ // (PR 149590)
+ String key = variableBinding.getKey();
+
+ node = getASTNode(unit, 0, 0, 1);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ statement = (VariableDeclarationStatement) node;
+ fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "x", variableBinding.getName());
+ // (PR 149590)
+ String key2 = variableBinding.getKey();
+ assertFalse("Keys should not be equals", key2.equals(key));
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=144858
+ */
+ public void test0661() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " int x = 2;\n" +
+ " try {\n" +
+ "\n" +
+ " } catch(NullPointerException x) {\n" +
+ " } catch(Exception e) {\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 1, "Duplicate parameter x");
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "x", variableBinding.getName());
+ // (PR 149590)
+ String key = variableBinding.getKey();
+
+ node = getASTNode(unit, 0, 0, 1);
+ assertEquals("Not a try statement", ASTNode.TRY_STATEMENT, node.getNodeType());
+ TryStatement statement2 = (TryStatement) node;
+ List catchClauses = statement2.catchClauses();
+ assertEquals("Wrong size", 2, catchClauses.size());
+ CatchClause catchClause = (CatchClause) catchClauses.get(0);
+ SingleVariableDeclaration variableDeclaration = catchClause.getException();
+ variableBinding = variableDeclaration.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "x", variableBinding.getName());
+ // (PR 149590)
+ String key2 = variableBinding.getKey();
+ assertFalse("Keys should not be equals", key2.equals(key));
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=144858
+ */
+ public void test0662() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " int x = x = 0;\n" +
+ " if (true) {\n" +
+ " int x = x = 1;\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedLog =
+ "The assignment to variable x has no effect\n" +
+ "Duplicate local variable x\n" +
+ "The assignment to variable x has no effect";
+ assertProblemsSize(unit, 3, expectedLog);
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "x", variableBinding.getName());
+ // (PR 149590)
+ String key = variableBinding.getKey();
+
+ node = getASTNode(unit, 0, 0, 1);
+ assertEquals("Not an if statement", ASTNode.IF_STATEMENT, node.getNodeType());
+ IfStatement ifStatement = (IfStatement) node;
+ Block block = (Block) ifStatement.getThenStatement();
+ List statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size());
+ Statement statement2 = (Statement) statements.get(0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, statement2.getNodeType());
+ statement = (VariableDeclarationStatement) statement2;
+ fragments = statement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "x", variableBinding.getName());
+
+ // (PR 149590)
+ String key2 = variableBinding.getKey();
+ assertFalse("Keys should not be equals", key2.equals(key));
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=144858
+ */
+ public void test0663() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " public static void main(String[] args) {\n" +
+ " for (int i = 0; i < 10; i++) {\n" +
+ " for (int i = 0; i < 5; i++) {\n" +
+ " // do something\n" +
+ " }\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedLog = "Duplicate local variable i";
+ assertProblemsSize(unit, 1, expectedLog);
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a for statement", ASTNode.FOR_STATEMENT, node.getNodeType());
+ ForStatement statement = (ForStatement) node;
+ List initializers = statement.initializers();
+ assertEquals("Wrong size", 1, initializers.size());
+ Expression expression = (Expression) initializers.get(0);
+ assertEquals("Not a variable declaration expression", ASTNode.VARIABLE_DECLARATION_EXPRESSION, expression.getNodeType());
+ VariableDeclarationExpression expression2 = (VariableDeclarationExpression) expression;
+ List fragments = expression2.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "i", variableBinding.getName());
+ // (PR 149590)
+ String key = variableBinding.getKey();
+
+ Block block = (Block) statement.getBody();
+ List statements = block.statements();
+ assertEquals("Wrong size", 1, statements.size());
+ Statement statement2 = (Statement) statements.get(0);
+ assertEquals("Not a for statement", ASTNode.FOR_STATEMENT, statement2.getNodeType());
+ statement = (ForStatement) statement2;
+ initializers = statement.initializers();
+ assertEquals("Wrong size", 1, initializers.size());
+ expression = (Expression) initializers.get(0);
+ assertEquals("Not a variable declaration expression", ASTNode.VARIABLE_DECLARATION_EXPRESSION, expression.getNodeType());
+ expression2 = (VariableDeclarationExpression) expression;
+ fragments = expression2.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "i", variableBinding.getName());
+
+ // (PR 149590)
+ String key2 = variableBinding.getKey();
+ assertFalse("Keys should not be equals", key2.equals(key));
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=165662
+ */
+ public void test0664() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " void foo() {\n" +
+ " class Local {\n" +
+ " void foo() {}\n" +
+ " }\n" +
+ " {\n" +
+ " class Local {\n" +
+ " Local(int i) {\n" +
+ " this.init(i);\n" +
+ " }\n" +
+ " void init(int i) {}\n" +
+ " }\n" +
+ " Local l = new Local(0);\n" +
+ " }\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedLog = "Duplicate nested type Local";
+ assertProblemsSize(unit, 1, expectedLog);
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a type declaration statement", ASTNode.TYPE_DECLARATION_STATEMENT, node.getNodeType());
+ TypeDeclarationStatement statement = (TypeDeclarationStatement) node;
+ ITypeBinding typeBinding = statement.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ String key = typeBinding.getKey();
+ assertNotNull("No key", key);
+
+ node = getASTNode(unit, 0, 0, 1);
+ assertEquals("Not a block", ASTNode.BLOCK, node.getNodeType());
+ Block block = (Block) node;
+ List statements = block.statements();
+ assertEquals("wrong size", 2, statements.size());
+ Statement statement2 = (Statement) statements.get(0);
+ assertEquals("Not a type declaration statement", ASTNode.TYPE_DECLARATION_STATEMENT, statement2.getNodeType());
+ statement = (TypeDeclarationStatement) statement2;
+ typeBinding = statement.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ String key2 = typeBinding.getKey();
+ assertNotNull("No key2", key2);
+ assertFalse("Keys should not be equals", key.equals(key2));
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=165662
+ */
+ public void test0665() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " void foo() {\n" +
+ " class Local {\n" +
+ " void foo() {\n" +
+ " }\n" +
+ " }\n" +
+ " {\n" +
+ " class Local {\n" +
+ " Local(int i) {\n" +
+ " this.init(i);\n" +
+ " this.bar();\n" +
+ " }\n" +
+ " void init(int i) {}\n" +
+ " void bar() {\n" +
+ " }\n" +
+ " }\n" +
+ " Local l = new Local(0);\n" +
+ " }\n" +
+ " Local l = new Local();\n" +
+ " l.foo();\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedLog = "Duplicate nested type Local";
+ assertProblemsSize(unit, 1, expectedLog);
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a type declaration statement", ASTNode.TYPE_DECLARATION_STATEMENT, node.getNodeType());
+ TypeDeclarationStatement statement = (TypeDeclarationStatement) node;
+ ITypeBinding typeBinding = statement.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ String key = typeBinding.getKey();
+ assertNotNull("No key", key);
+
+ node = getASTNode(unit, 0, 0, 1);
+ assertEquals("Not a block", ASTNode.BLOCK, node.getNodeType());
+ Block block = (Block) node;
+ List statements = block.statements();
+ assertEquals("wrong size", 2, statements.size());
+ Statement statement2 = (Statement) statements.get(0);
+ assertEquals("Not a type declaration statement", ASTNode.TYPE_DECLARATION_STATEMENT, statement2.getNodeType());
+ statement = (TypeDeclarationStatement) statement2;
+ typeBinding = statement.resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ String key2 = typeBinding.getKey();
+ assertNotNull("No key2", key2);
+ assertFalse("Keys should not be equals", key.equals(key2));
+
+ Statement statement3 = (Statement) statements.get(1);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, statement3.getNodeType());
+ VariableDeclarationStatement variableDeclarationStatement = (VariableDeclarationStatement) statement3;
+ List fragments = variableDeclarationStatement.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("Wrong name", "l", variableBinding.getName());
+ Expression expression = fragment.getInitializer();
+ ITypeBinding typeBinding2 = expression.resolveTypeBinding();
+ assertNotNull("No type binding2", typeBinding2);
+
+ AbstractTypeDeclaration declaration = statement.getDeclaration();
+ List bodyDeclarations = declaration.bodyDeclarations();
+ assertEquals("Wrong size", 3, bodyDeclarations.size());
+ BodyDeclaration declaration2 = (BodyDeclaration) bodyDeclarations.get(0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, declaration2.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) declaration2;
+ assertTrue("not a constructor", methodDeclaration.isConstructor());
+ block = methodDeclaration.getBody();
+ statements = block.statements();
+ assertEquals("Wrong size", 2, statements.size());
+ statement3 = (Statement) statements.get(1);
+ assertEquals("Not a expression statement", ASTNode.EXPRESSION_STATEMENT, statement3.getNodeType());
+ expression = ((ExpressionStatement) statement3).getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, expression.getNodeType());
+ MethodInvocation invocation = (MethodInvocation) expression;
+ IMethodBinding methodBinding = invocation.resolveMethodBinding();
+ assertNotNull(methodBinding);
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=149567
+ */
+ public void test0666() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "import java.util.ArrayList;\n" +
+ "\n" +
+ "public class X {\n" +
+ " protected String foo() {\n" +
+ " List c = new ArrayList();\n" +
+ " c.add(null);\n" +
+ " return c;\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false,
+ true,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedError =
+ "List cannot be resolved to a type";
+ assertProblemsSize(unit, 1, expectedError);
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("No fragments", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertEquals("LX;.foo()Ljava/lang/String;#c", variableBinding.getKey());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=149567
+ */
+ public void test0666_2() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "import java.util.ArrayList;\n" +
+ "\n" +
+ "public class X {\n" +
+ " protected String foo() {\n" +
+ " List c = new ArrayList();\n" +
+ " c.add(null);\n" +
+ " return c;\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false,
+ true,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedError =
+ "List cannot be resolved to a type";
+ assertProblemsSize(unit, 1, expectedError);
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("No fragments", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNull("Got a binding", variableBinding);
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=149567
+ */
+ public void test0667() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "import java.util.ArrayList;\n" +
+ "\n" +
+ "public class X {\n" +
+ " List foo() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedError = "List cannot be resolved to a type";
+ assertProblemsSize(unit, 1, expectedError);
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration declaration = (MethodDeclaration) node;
+ IMethodBinding binding = declaration.resolveBinding();
+ assertNull("Got a binding", binding);
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=149567
+ */
+ public void test0667_2() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "import java.util.ArrayList;\n" +
+ "\n" +
+ "public class X {\n" +
+ " List foo() {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy,
+ false,
+ false,
+ true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedError = "List cannot be resolved to a type";
+ assertProblemsSize(unit, 1, expectedError);
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration declaration = (MethodDeclaration) node;
+ IMethodBinding binding = declaration.resolveBinding();
+ assertNotNull("No binding", binding);
+ assertEquals("LX;.foo()LList;", binding.getKey());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=174298
+ */
+ public void test0668() throws JavaModelException {
+ assertEquals("Wrong name property", "org.eclipse.jdt.core.dom.SimpleName", AnnotationTypeDeclaration.NAME_PROPERTY.getChildType().getName());
+ assertEquals("Wrong name property", "org.eclipse.jdt.core.dom.SimpleName", EnumDeclaration.NAME_PROPERTY.getChildType().getName());
+ assertEquals("Wrong name property", "org.eclipse.jdt.core.dom.SimpleName", TypeDeclaration.NAME_PROPERTY.getChildType().getName());
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=176057
+ */
+ public void test0669() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0669", "UIPerformChangeOperation.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true, true);
+ assertNotNull(result);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=149567
+ */
+ public void test0670() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "import java.util.ArrayList;\n" +
+ "\n" +
+ "public class X {\n" +
+ " protected String foo() {\n" +
+ " List c = new ArrayList();\n" +
+ " c.add(null);\n" +
+ " return c;\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ workingCopy.getBuffer().setContents(contents);
+ ASTNode node = runConversion(AST.JLS3, workingCopy, true, true, true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedError =
+ "List cannot be resolved to a type";
+ assertProblemsSize(unit, 1, expectedError);
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("No fragments", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertFalse("Not a recovered binding", variableBinding.isRecovered());
+ ITypeBinding typeBinding = variableBinding.getType();
+ assertNotNull("No binding", typeBinding);
+ assertTrue("Not a recovered binding", typeBinding.isRecovered());
+ assertEquals("Wrong name", "List", typeBinding.getName());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=149567
+ */
+ public void test0671() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "import java.util.ArrayList;\n" +
+ "\n" +
+ "public class X {\n" +
+ " protected String foo() {\n" +
+ " List[] c[] = new ArrayList();\n" +
+ " c.add(null);\n" +
+ " return c;\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ workingCopy.getBuffer().setContents(contents);
+ ASTNode node = runConversion(AST.JLS3, workingCopy, true, true, true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedError =
+ "List cannot be resolved to a type" ;
+ assertProblemsSize(unit, 1, expectedError);
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("No fragments", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertFalse("Unexpected recovered binding", variableBinding.isRecovered());
+ ITypeBinding typeBinding = variableBinding.getType();
+ assertNotNull("No binding", typeBinding);
+ assertTrue("Not a recovered binding", typeBinding.isRecovered());
+ assertEquals("Wrong name", "List[][]", typeBinding.getName());
+ assertEquals("Wrong dimension", 2, typeBinding.getDimensions());
+ ITypeBinding componentType = typeBinding.getComponentType();
+ assertNotNull("No binding", componentType);
+ assertTrue("Not a recovered binding", componentType.isRecovered());
+ assertEquals("Wrong name", "List[]", componentType.getName());
+ componentType = componentType.getComponentType();
+ assertNotNull("No binding", componentType);
+ assertTrue("Not a recovered binding", componentType.isRecovered());
+ assertEquals("Wrong name", "List", componentType.getName());
+ ITypeBinding elementType = typeBinding.getElementType();
+ assertNotNull("No binding", elementType);
+ assertTrue("Not a recovered binding", elementType.isRecovered());
+ assertEquals("Wrong name", "List", elementType.getName());
+
+ typeBinding = statement.getType().resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertTrue("Not a recovered binding", typeBinding.isRecovered());
+ assertEquals("Wrong name", "List[]", typeBinding.getName());
+ assertEquals("Wrong dimension", 1, typeBinding.getDimensions());
+ componentType = typeBinding.getComponentType();
+ assertEquals("Wrong name", "List", componentType.getName());
+ assertNotNull("No binding", componentType);
+ assertTrue("Not a recovered binding", componentType.isRecovered());
+ elementType = typeBinding.getElementType();
+ assertNotNull("No binding", elementType);
+ assertTrue("Not a recovered binding", elementType.isRecovered());
+ assertEquals("Wrong name", "List", elementType.getName());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=149567
+ */
+ public void test0672() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "import java.util.ArrayList;\n" +
+ "\n" +
+ "public class X {\n" +
+ " protected String foo() {\n" +
+ " List[][] c = new ArrayList();\n" +
+ " c.add(null);\n" +
+ " return c;\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ workingCopy.getBuffer().setContents(contents);
+ ASTNode node = runConversion(AST.JLS3, workingCopy, true, true, true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedError =
+ "List cannot be resolved to a type";
+ assertProblemsSize(unit, 1, expectedError);
+ assertTrue("No binding recovery", unit.getAST().hasBindingsRecovery());
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("No fragments", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ assertNotNull("No binding", variableBinding);
+ assertFalse("Unexpected recovered binding", variableBinding.isRecovered());
+ ITypeBinding typeBinding = variableBinding.getType();
+ assertNotNull("No binding", typeBinding);
+ assertTrue("Not a recovered binding", typeBinding.isRecovered());
+ assertEquals("Wrong name", "List[][]", typeBinding.getName());
+ assertEquals("Wrong dimension", 2, typeBinding.getDimensions());
+ ITypeBinding componentType = typeBinding.getComponentType();
+ assertNotNull("No binding", componentType);
+ assertTrue("Not a recovered binding", componentType.isRecovered());
+ assertEquals("Wrong name", "List[]", componentType.getName());
+ ITypeBinding elementType = typeBinding.getElementType();
+ assertNotNull("No binding", elementType);
+ assertTrue("Not a recovered binding", elementType.isRecovered());
+ assertEquals("Wrong name", "List", elementType.getName());
+
+ typeBinding = statement.getType().resolveBinding();
+ assertNotNull("No binding", typeBinding);
+ assertTrue("Not a recovered binding", typeBinding.isRecovered());
+ assertEquals("Wrong name", "List[][]", typeBinding.getName());
+ assertEquals("Wrong dimension", 2, typeBinding.getDimensions());
+ componentType = typeBinding.getComponentType();
+ assertEquals("Wrong name", "List[]", componentType.getName());
+ assertNotNull("No binding", componentType);
+ assertTrue("Not a recovered binding", componentType.isRecovered());
+ elementType = typeBinding.getElementType();
+ assertNotNull("No binding", elementType);
+ assertEquals("Wrong name", "List", elementType.getName());
+ assertTrue("Not a recovered binding", elementType.isRecovered());
+
+ IJavaElement javaElement = elementType.getJavaElement();
+ assertNotNull("No java element", javaElement);
+ assertTrue("Javalement exists", !javaElement.exists());
+ IPackageBinding packageBinding = elementType.getPackage();
+ assertNotNull("No package", packageBinding);
+ assertTrue("Not the default package", packageBinding.isUnnamed());
+ ITypeBinding arrayBinding = elementType.createArrayType(2);
+ assertNotNull("No array binding", arrayBinding);
+ assertEquals("Wrong dimensions", 2, arrayBinding.getDimensions());
+ ITypeBinding elementType2 = arrayBinding.getElementType();
+ assertNotNull("No element type", elementType2);
+ assertNotNull("No key", elementType.getKey());
+ assertTrue("Not equals", elementType2.isEqualTo(elementType));
+
+ node = getASTNode(unit, 0);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding2 = typeDeclaration.resolveBinding();
+ ITypeBinding javaLangObject = typeBinding2.getSuperclass();
+ assertEquals("Not java.lang.Object", "java.lang.Object", javaLangObject.getQualifiedName());
+ assertTrue("Not isCastCompatible", elementType.isCastCompatible(javaLangObject));
+ assertTrue("Not isCastCompatible", elementType.isCastCompatible(elementType2));
+
+ assertTrue("Not isSubTypeCompatible", elementType.isSubTypeCompatible(javaLangObject));
+ assertTrue("Not isSubTypeCompatible", elementType.isSubTypeCompatible(elementType2));
+
+ assertTrue("Not isAssignmentCompatible", elementType.isAssignmentCompatible(javaLangObject));
+ assertTrue("Not isAssignmentCompatible", elementType.isAssignmentCompatible(elementType2));
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=149567
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=180905
+ */
+ public void test0673() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " B foo() {\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ workingCopy.getBuffer().setContents(contents);
+ ASTNode node = runConversion(AST.JLS3, workingCopy, true, true, true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertTrue("no binding recovery", unit.getAST().hasBindingsRecovery());
+ assertTrue("no statement recovery", unit.getAST().hasStatementsRecovery());
+ assertTrue("no binding resolution", unit.getAST().hasResolvedBindings());
+ String expectedError = "B cannot be resolved to a type";
+ assertProblemsSize(unit, 1, expectedError);
+ assertTrue("No binding recovery", unit.getAST().hasBindingsRecovery());
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Type type = methodDeclaration.getReturnType2();
+ assertNotNull("No type", type);
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No type binding", typeBinding);
+ assertTrue("Not a recovered binding", typeBinding.isRecovered());
+ IJavaElement javaElement = typeBinding.getJavaElement();
+ assertNotNull("No java element", javaElement);
+ assertTrue("Javalement exists", !javaElement.exists());
+ IPackageBinding packageBinding = typeBinding.getPackage();
+ assertNotNull("No package", packageBinding);
+ assertTrue("Not the default package", packageBinding.isUnnamed());
+ ITypeBinding arrayBinding = typeBinding.createArrayType(2);
+ assertNotNull("No array binding", arrayBinding);
+ assertEquals("Wrong dimensions", 2, arrayBinding.getDimensions());
+ ITypeBinding elementType = arrayBinding.getElementType();
+ assertNotNull("No element type", elementType);
+ assertNotNull("No key", typeBinding.getKey());
+ assertTrue("Not equals", elementType.isEqualTo(typeBinding));
+
+ node = getASTNode(unit, 0);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding2 = typeDeclaration.resolveBinding();
+ ITypeBinding javaLangObject = typeBinding2.getSuperclass();
+ assertEquals("Not java.lang.Object", "java.lang.Object", javaLangObject.getQualifiedName());
+ assertTrue("Not isCastCompatible", typeBinding.isCastCompatible(javaLangObject));
+ assertTrue("Not isCastCompatible", typeBinding.isCastCompatible(elementType));
+
+ assertTrue("Not isSubTypeCompatible", typeBinding.isSubTypeCompatible(javaLangObject));
+ assertTrue("Not isSubTypeCompatible", typeBinding.isSubTypeCompatible(elementType));
+
+ assertTrue("Not isAssignmentCompatible", typeBinding.isAssignmentCompatible(javaLangObject));
+ assertTrue("Not isAssignmentCompatible", typeBinding.isAssignmentCompatible(elementType));
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=180524
+ */
+ public void test0674() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " Object foo() {\n" +
+ " return new Object() {/*anon*/};\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ workingCopy.getBuffer().setContents(contents);
+ ASTNode node = runConversion(AST.JLS3, workingCopy, true, true, true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a return statement", ASTNode.RETURN_STATEMENT, node.getNodeType());
+ ReturnStatement statement = (ReturnStatement) node;
+ Expression expression = statement.getExpression();
+ assertEquals("Not a class instance creation", ASTNode.CLASS_INSTANCE_CREATION, expression.getNodeType());
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ ITypeBinding binding = classInstanceCreation.resolveTypeBinding();
+ assertTrue("not an anonymous type", binding.isAnonymous());
+ try {
+ assertNotNull(binding.createArrayType(2));
+ } catch (IllegalArgumentException e) {
+ assertTrue("Should not be rejected", false);
+ }
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=166963
+ */
+ public void test0675() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " public X(String label) {}\n" +
+ " public X() {\n" +
+ " String s= \"foo\";\n" +
+ " System.out.println(s);\n" +
+ " this(s);\n" +
+ " System.out.println(s);\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ workingCopy.getBuffer().setContents(contents);
+ ASTNode node = runConversion(AST.JLS3, workingCopy, true, true, true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedError = "Constructor call must be the first statement in a constructor";
+ assertProblemsSize(unit, 1, expectedError);
+ node = getASTNode(unit, 0, 1, 2);
+ assertEquals("Not a constructor invocation", ASTNode.CONSTRUCTOR_INVOCATION, node.getNodeType());
+ ConstructorInvocation constructorInvocation = (ConstructorInvocation) node;
+ assertNull("Got a binding", constructorInvocation.resolveConstructorBinding());
+ List arguments = constructorInvocation.arguments();
+ assertEquals("wrong size", 1, arguments.size());
+ Expression expression = (Expression) arguments.get(0);
+ ITypeBinding typeBinding = expression.resolveTypeBinding();
+ assertNotNull("No binding", typeBinding);
+ assertEquals("Wrong type", "java.lang.String", typeBinding.getQualifiedName());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=149567
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=180905
+ */
+ public void test0676() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0676", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode node = runConversion(AST.JLS3, sourceUnit, true, true, true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertTrue("no binding recovery", unit.getAST().hasBindingsRecovery());
+ assertTrue("no statement recovery", unit.getAST().hasStatementsRecovery());
+ assertTrue("no binding resolution", unit.getAST().hasResolvedBindings());
+ String expectedError = "B cannot be resolved to a type";
+ assertProblemsSize(unit, 1, expectedError);
+ assertTrue("No binding recovery", unit.getAST().hasBindingsRecovery());
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, node.getNodeType());
+ MethodDeclaration methodDeclaration = (MethodDeclaration) node;
+ Type type = methodDeclaration.getReturnType2();
+ assertNotNull("No type", type);
+ ITypeBinding typeBinding = type.resolveBinding();
+ assertNotNull("No type binding", typeBinding);
+ assertTrue("Not a recovered binding", typeBinding.isRecovered());
+ IJavaElement javaElement = typeBinding.getJavaElement();
+ assertNotNull("No java element", javaElement);
+ assertTrue("Java element exists", !javaElement.exists());
+ IPackageBinding packageBinding = typeBinding.getPackage();
+ assertNotNull("No package", packageBinding);
+ assertNotNull("No java element for package", packageBinding.getJavaElement());
+ assertEquals("Not the package test0676", "test0676", packageBinding.getName());
+ ITypeBinding arrayBinding = typeBinding.createArrayType(2);
+ assertNotNull("No array binding", arrayBinding);
+ assertEquals("Wrong dimensions", 2, arrayBinding.getDimensions());
+ ITypeBinding elementType = arrayBinding.getElementType();
+ assertNotNull("No element type", elementType);
+ assertNotNull("No key", typeBinding.getKey());
+ assertTrue("Not equals", elementType.isEqualTo(typeBinding));
+
+ node = getASTNode(unit, 0);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding2 = typeDeclaration.resolveBinding();
+ ITypeBinding javaLangObject = typeBinding2.getSuperclass();
+ assertEquals("Not java.lang.Object", "java.lang.Object", javaLangObject.getQualifiedName());
+ assertTrue("Not isCastCompatible", typeBinding.isCastCompatible(javaLangObject));
+ assertTrue("Not isCastCompatible", typeBinding.isCastCompatible(elementType));
+
+ assertTrue("Not isSubTypeCompatible", typeBinding.isSubTypeCompatible(javaLangObject));
+ assertTrue("Not isSubTypeCompatible", typeBinding.isSubTypeCompatible(elementType));
+
+ assertTrue("Not isAssignmentCompatible", typeBinding.isAssignmentCompatible(javaLangObject));
+ assertTrue("Not isAssignmentCompatible", typeBinding.isAssignmentCompatible(elementType));
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=185306
+ */
+ public void test0677() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0677", "A.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode node = runConversion(AST.JLS3, sourceUnit, true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType()); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) node;
+ node = getASTNode(unit, 0);
+ assertProblemsSize(unit, 0);
+ assertNotNull(node);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, node.getNodeType()); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ assertNotNull("No type binding", typeBinding);
+ ITypeBinding superclass = typeBinding.getSuperclass();
+ assertNotNull("No super class", superclass);
+ IMethodBinding[] methods = superclass.getDeclaredMethods();
+ assertNotNull("No methods", methods);
+ assertTrue("Empty", methods.length != 0);
+ IVariableBinding[] fields = superclass.getDeclaredFields();
+ assertNotNull("No fields", fields);
+ assertTrue("Empty", fields.length != 0);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=193979
+ */
+ public void test0678() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " public String foo() {\n" +
+ " return((true ? \"\" : (\"Hello\" + \" World\") + \"!\"));\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ workingCopy.getBuffer().setContents(contents.toCharArray());
+ ASTNode node = runConversion(AST.JLS3, workingCopy, true);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ String expectedOutput = "Dead code";
+ assertProblemsSize(unit, 1, expectedOutput);
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a return statement", ASTNode.RETURN_STATEMENT, node.getNodeType());
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertNotNull("No expression", expression);
+ assertEquals("Not a parenthesized expression", ASTNode.PARENTHESIZED_EXPRESSION, expression.getNodeType());
+ expression = ((ParenthesizedExpression) expression).getExpression();
+ assertEquals("Not a parenthesized expression", ASTNode.PARENTHESIZED_EXPRESSION, expression.getNodeType());
+ expression = ((ParenthesizedExpression) expression).getExpression();
+ assertEquals("Not a conditional expression", ASTNode.CONDITIONAL_EXPRESSION, expression.getNodeType());
+ ConditionalExpression conditionalExpression = (ConditionalExpression) expression;
+ final Expression elseExpression = conditionalExpression.getElseExpression();
+ assertEquals("Not an infix expression", ASTNode.INFIX_EXPRESSION, elseExpression.getNodeType());
+ InfixExpression infixExpression = (InfixExpression) elseExpression;
+ List extendedOperands = infixExpression.extendedOperands();
+ assertEquals("wrong size", 0, extendedOperands.size());
+ Expression leftOperand = infixExpression.getLeftOperand();
+ assertEquals("Not a parenthesized expression", ASTNode.PARENTHESIZED_EXPRESSION, leftOperand.getNodeType());
+ ParenthesizedExpression parenthesizedExpression = (ParenthesizedExpression) leftOperand;
+ assertEquals("Not an infix expression", ASTNode.INFIX_EXPRESSION, parenthesizedExpression.getExpression().getNodeType());
+ Expression rightOperand = infixExpression.getRightOperand();
+ assertEquals("Not a string literal", ASTNode.STRING_LITERAL, rightOperand.getNodeType());
+ StringLiteral stringLiteral = (StringLiteral) rightOperand;
+ assertEquals("wrong value", "!", stringLiteral.getLiteralValue());
+ infixExpression = (InfixExpression) parenthesizedExpression.getExpression();
+ leftOperand = infixExpression.getLeftOperand();
+ assertEquals("Not a string literal", ASTNode.STRING_LITERAL, leftOperand.getNodeType());
+ stringLiteral = (StringLiteral) leftOperand;
+ assertEquals("wrong value", "Hello", stringLiteral.getLiteralValue());
+ rightOperand = infixExpression.getRightOperand();
+ assertEquals("Not a string literal", ASTNode.STRING_LITERAL, rightOperand.getNodeType());
+ stringLiteral = (StringLiteral) rightOperand;
+ assertEquals("wrong value", " World", stringLiteral.getLiteralValue());
+ assertEquals("Wrong size", 0, infixExpression.extendedOperands().size());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=169745
+ */
+ public void _test0679() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " int i = 1 - 2 + 3 + 4 + 5;\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ final List fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 1, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ final Expression initializer = fragment.getInitializer();
+ assertEquals("Not an infix expression", ASTNode.INFIX_EXPRESSION, initializer.getNodeType());
+ InfixExpression infixExpression = (InfixExpression) initializer;
+ final Expression leftOperand = infixExpression.getLeftOperand();
+ assertEquals("Not a number literal", ASTNode.NUMBER_LITERAL, leftOperand.getNodeType());
+ NumberLiteral literal = (NumberLiteral) leftOperand;
+ assertEquals("Wrong value", "1", literal.getToken());
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=196249
+ */
+ public void test0680() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0680", "SAMPLE_UTF8.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode node = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("Not a compilation unit", node.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ node = getASTNode(compilationUnit, 0);
+ assertNotNull(node);
+ assertTrue("Not a type declaration", node.getNodeType() == ASTNode.TYPE_DECLARATION); //$NON-NLS-1$
+ TypeDeclaration typeDeclaration = (TypeDeclaration) node;
+ final List modifiers = typeDeclaration.modifiers();
+ assertEquals("Wrong size", 1, modifiers.size());
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=196354
+ */
+ public void test0681() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "Sample", "Sample.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode node = runConversion(AST.JLS3, sourceUnit, true);
+ assertTrue("Not a compilation unit", node.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertProblemsSize(compilationUnit, 0);
+ final PackageDeclaration packageDeclaration = compilationUnit.getPackage();
+ final IPackageBinding packageBinding = packageDeclaration.resolveBinding();
+ assertNotNull("No binding", packageBinding);
+ assertEquals("Wrong name", "Sample", packageBinding.getName());
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=196514
+ */
+ public void test0682() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0682", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode node = runConversion(AST.JLS3, sourceUnit, true, true);
+ assertTrue("Not a compilation unit", node.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(
+ unit,
+ 2,
+ "Variable must provide either dimension expressions or an array initializer\n" +
+ "Syntax error on token \"String\", [ expected after this token");
+ node = getASTNode(unit, 0, 1, 0);
+ assertEquals("Not a expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ node = expressionStatement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, node.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) node;
+ List arguments = methodInvocation.arguments();
+ assertEquals("Wrong size", 1, arguments.size());
+ node = (ASTNode)arguments.get(0);
+ assertEquals("Not an array creation", ASTNode.ARRAY_CREATION, node.getNodeType());
+ ArrayCreation arrayCreation = (ArrayCreation) node;
+ ArrayType arrayType = arrayCreation.getType();
+ checkSourceRange(arrayType, "String]", sourceUnit.getSource());
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=196514
+ */
+ public void test0683() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0683", "Test.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode node = runConversion(AST.JLS3, sourceUnit, true, true);
+ assertTrue("Not a compilation unit", node.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 1, 0);
+ assertEquals("Not a expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ ExpressionStatement expressionStatement = (ExpressionStatement) node;
+ node = expressionStatement.getExpression();
+ assertEquals("Not a method invocation", ASTNode.METHOD_INVOCATION, node.getNodeType());
+ MethodInvocation methodInvocation = (MethodInvocation) node;
+ List arguments = methodInvocation.arguments();
+ assertEquals("Wrong size", 1, arguments.size());
+ node = (ASTNode)arguments.get(0);
+ assertEquals("Not an array creation", ASTNode.ARRAY_CREATION, node.getNodeType());
+ ArrayCreation arrayCreation = (ArrayCreation) node;
+ ArrayType arrayType = arrayCreation.getType();
+ checkSourceRange(arrayType, "String[0][b[10]][]", sourceUnit.getSource());
+ node = arrayType.getComponentType();
+ assertEquals("Not an array type", ASTNode.ARRAY_TYPE, node.getNodeType());
+ arrayType = (ArrayType)node;
+ checkSourceRange(arrayType, "String[0][b[10]]", sourceUnit.getSource());
+ node = arrayType.getComponentType();
+ assertEquals("Not an array type", ASTNode.ARRAY_TYPE, node.getNodeType());
+ arrayType = (ArrayType)node;
+ checkSourceRange(arrayType, "String[0]", sourceUnit.getSource());
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=201929
+ */
+ public void test0684() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0684", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode node = runConversion(AST.JLS3, sourceUnit, true, true);
+ assertTrue("Not a compilation unit", node.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a return statement", ASTNode.RETURN_STATEMENT, node.getNodeType());
+ ReturnStatement returnStatement = (ReturnStatement) node;
+ Expression expression = returnStatement.getExpression();
+ assertEquals("Not a class instance creation", ASTNode.CLASS_INSTANCE_CREATION, expression.getNodeType());
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ final AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ final List bodyDeclarations = anonymousClassDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size());
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, ((BodyDeclaration) bodyDeclarations.get(0)).getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) bodyDeclarations.get(0);
+ final ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ final String qualifiedName = typeBinding.getQualifiedName();
+ assertEquals("wrong qualified name", "", qualifiedName);
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=201929
+ */
+ public void test0685() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0685", "C.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode node = runConversion(AST.JLS3, sourceUnit, true, true);
+ assertTrue("Not a compilation unit", node.getNodeType() == ASTNode.COMPILATION_UNIT); //$NON-NLS-1$
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not an expression statement", ASTNode.EXPRESSION_STATEMENT, node.getNodeType());
+ Expression expression = ((ExpressionStatement) node).getExpression();
+ assertEquals("Not a class instance creation", ASTNode.CLASS_INSTANCE_CREATION, expression.getNodeType());
+ ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
+ final AnonymousClassDeclaration anonymousClassDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
+ final List bodyDeclarations = anonymousClassDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size());
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, ((BodyDeclaration) bodyDeclarations.get(0)).getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) bodyDeclarations.get(0);
+ final ITypeBinding typeBinding = typeDeclaration.resolveBinding();
+ final String qualifiedName = typeBinding.getQualifiedName();
+ assertEquals("wrong qualified name", "", qualifiedName);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=203579
+ */
+ public void test0686() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " void foo() {\n" +
+ " int a , b ;\n" +
+ " for (int i , j ;;) {}\n" +
+ " }\n" +
+ " int n , m ;\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a variable statement declaration", ASTNode.VARIABLE_DECLARATION_STATEMENT, node.getNodeType());
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) node;
+ List fragments = statement.fragments();
+ assertEquals("Wrong size", 2, fragments.size());
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) fragments.get(0);
+ checkSourceRange(fragment, "a", contents);
+ fragment = (VariableDeclarationFragment) fragments.get(1);
+ checkSourceRange(fragment, "b", contents);
+ node = getASTNode(unit, 0, 0, 1);
+ assertEquals("Not a for statement", ASTNode.FOR_STATEMENT, node.getNodeType());
+ ForStatement forStatement = (ForStatement) node;
+ final List initializers = forStatement.initializers();
+ assertEquals("Wrong size", 1, initializers.size());
+ VariableDeclarationExpression expression = (VariableDeclarationExpression) initializers.get(0);
+ fragments = expression.fragments();
+ assertEquals("Wrong size", 2, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ assertFalse("Not a malformed node", isMalformed(fragment));
+ checkSourceRange(fragment, "i", contents);
+ fragment = (VariableDeclarationFragment) fragments.get(1);
+ checkSourceRange(fragment, "j", contents);
+ assertFalse("Not a malformed node", isMalformed(fragment));
+
+ node = getASTNode(unit, 0, 1);
+ assertEquals("Not a field declaration", ASTNode.FIELD_DECLARATION, node.getNodeType());
+ FieldDeclaration fieldDeclaration = (FieldDeclaration) node;
+ fragments = fieldDeclaration.fragments();
+ assertEquals("Wrong size", 2, fragments.size());
+ fragment = (VariableDeclarationFragment) fragments.get(0);
+ checkSourceRange(fragment, "n", contents);
+ assertFalse("Not a malformed node", isMalformed(fragment));
+ fragment = (VariableDeclarationFragment) fragments.get(1);
+ checkSourceRange(fragment, "m", contents);
+ assertFalse("Not a malformed node", isMalformed(fragment));
+ } finally {
+ if (workingCopy != null)
+ workingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=207754
+ */
+ public void test0687() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " protected String foo(String string) {\n" +
+ " return (\"\" + string + \"\") + (\"\");\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ASTNode node = buildAST(
+ contents,
+ workingCopy);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit unit = (CompilationUnit) node;
+ assertProblemsSize(unit, 0);
+ node = getASTNode(unit, 0, 0, 0);
+ assertEquals("Not a return statement", ASTNode.RETURN_STATEMENT, node.getNodeType());
+ ReturnStatement statement = (ReturnStatement) node;
+ Expression expression = statement.getExpression();
+ checkSourceRange(expression, "(\"\" + string + \"\") + (\"\")", contents);
+ assertEquals("Not an infix expression", ASTNode.INFIX_EXPRESSION, expression.getNodeType());
+ InfixExpression infixExpression = (InfixExpression) expression;
+ Expression leftOperand = infixExpression.getLeftOperand();
+ checkSourceRange(leftOperand, "(\"\" + string + \"\")", contents);
+ } finally {
+ if (workingCopy != null) {
+ workingCopy.discardWorkingCopy();
+ }
+ }
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=215858
+ */
+ public void test0688() throws JavaModelException {
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0688", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType[] types = sourceUnit.getTypes();
+ assertNotNull(types);
+ assertEquals("wrong size", 1, types.length);
+ IType type = types[0];
+ IField field = type.getField("i");
+ assertNotNull("No field", field);
+ ISourceRange sourceRange = field.getNameRange();
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, sourceRange.getOffset() + sourceRange.getLength() / 2, false);
+ assertNotNull(result);
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=240815
+ */
+ public void test0689() throws JavaModelException {
+ IJavaProject project = getJavaProject("Converter");
+ if (project == null) {
+ return;
+ }
+ // replace JCL_LIB with JCL15_LIB, and JCL_SRC with JCL15_SRC
+ IClasspathEntry[] classpath = project.getRawClasspath();
+ try {
+ ArrayList newClasspathEntries = new ArrayList();
+ for (int i = 0, length = classpath.length; i < length; i++) {
+ IClasspathEntry entry = classpath[i];
+ if (entry.getEntryKind() != IClasspathEntry.CPE_VARIABLE) {
+ newClasspathEntries.add(entry);
+ }
+ }
+ IClasspathEntry[] newClasspath = new IClasspathEntry[newClasspathEntries.size()];
+ newClasspathEntries.toArray(newClasspath);
+ project.setRawClasspath(newClasspath, null);
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0689", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true, true);
+ assertNotNull(result);
+ ITypeBinding typeBinding = result.getAST().resolveWellKnownType("java.lang.Boolean");
+ assertNull("Should be null", typeBinding);
+ } finally {
+ project.setRawClasspath(classpath, null);
+ }
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=240815
+ */
+ public void test0690() throws JavaModelException {
+ IJavaProject project = getJavaProject("Converter");
+ if (project == null) {
+ return;
+ }
+ // replace JCL_LIB with JCL15_LIB, and JCL_SRC with JCL15_SRC
+ IClasspathEntry[] classpath = project.getRawClasspath();
+ try {
+ ArrayList newClasspathEntries = new ArrayList();
+ for (int i = 0, length = classpath.length; i < length; i++) {
+ IClasspathEntry entry = classpath[i];
+ if (entry.getEntryKind() != IClasspathEntry.CPE_VARIABLE) {
+ newClasspathEntries.add(entry);
+ }
+ }
+ IClasspathEntry[] newClasspath = new IClasspathEntry[newClasspathEntries.size()];
+ newClasspathEntries.toArray(newClasspath);
+ project.setRawClasspath(newClasspath, null);
+ ICompilationUnit sourceUnit = getCompilationUnit("Converter" , "src", "test0690", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ASTNode result = runConversion(AST.JLS3, sourceUnit, true, true, true);
+ assertNotNull(result);
+ ITypeBinding typeBinding = result.getAST().resolveWellKnownType("java.lang.Boolean");
+ assertNull("Should be null", typeBinding);
+ } finally {
+ project.setRawClasspath(classpath, null);
+ }
+ }
+
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=242292
+ */
+ public void test0691() throws JavaModelException {
+ ICompilationUnit unit = getCompilationUnit("Converter" , "src", "test0691", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ IType type = unit.getType("X");
+ IMethod method = type.getMethod("foo", new String[0]);
+
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
+ parser.setSource(unit);
+ Hashtable options = JavaCore.getOptions();
+ options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED);
+ parser.setCompilerOptions(options);
+ ISourceRange range = method.getSourceRange();
+ parser.setSourceRange(range.getOffset(), range.getLength());
+ ASTNode node = parser.createAST(null);
+ assertNotNull("No node", node);
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=242961
+ */
+ public void test0692() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "/*start*/public class X {\n" +
+ " int k;\n" +
+ " Zork z;\n" +
+ "}/*end*/";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ TypeDeclaration typeDeclaration = (TypeDeclaration) buildAST(
+ contents,
+ workingCopy,
+ false,
+ false,
+ false);
+ ITypeBinding binding = typeDeclaration.resolveBinding();
+ IVariableBinding[] declaredFields = binding.getDeclaredFields();
+ assertEquals("Wrong size", 1, declaredFields.length);
+ } finally {
+ if (workingCopy != null) {
+ workingCopy.discardWorkingCopy();
+ }
+ }
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=243715
+ */
+ public void test0693() throws JavaModelException {
+ ICompilationUnit unit = getCompilationUnit("Converter" , "src", "test0693", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ICompilationUnit unit2 = getCompilationUnit("Converter" , "src", "test0693", "Y.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ ASTRequestor requestor = new ASTRequestor() {};
+ ICompilationUnit[] cus = new ICompilationUnit[2];
+ cus[0] = unit;
+ cus[1] = unit2;
+
+ try {
+ // the following line will throw exception but seemingly shouldn't
+ parser.createASTs(cus, new String[0], requestor, null);
+ } catch(Exception e) {
+ e.printStackTrace();
+ assertFalse("Should not get there", true);
+ }
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=243715
+ */
+ public void test0694() throws JavaModelException {
+ ICompilationUnit unit = getCompilationUnit("Converter" , "src", "test0694", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+ ICompilationUnit unit2 = getCompilationUnit("Converter" , "src", "test0694", "Y.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ ASTRequestor requestor = new ASTRequestor() {};
+ ICompilationUnit[] cus = new ICompilationUnit[2];
+ cus[0] = unit;
+ cus[1] = unit2;
+
+ try {
+ // the following line will throw exception but seemingly shouldn't
+ parser.createASTs(cus, new String[0], requestor, null);
+ } catch(Exception e) {
+ e.printStackTrace();
+ assertFalse("Should not get there", true);
+ }
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=245348
+ */
+ public void test0695() throws JavaModelException {
+ ICompilationUnit unit = getCompilationUnit("Converter" , "src", "test0695", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_COMPILATION_UNIT);
+ parser.setSource(unit.getSource().toCharArray());
+ Map options = JavaCore.getOptions();
+ options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3);
+ options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4);
+ options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2);
+ parser.setCompilerOptions(options);
+
+ CompilationUnit astRoot = (CompilationUnit) parser.createAST(null);
+ ASTVisitor visitor = new ASTVisitor() {
+ public boolean visit(EnumDeclaration node) {
+ assertFalse("Should not be there", true);
+ return false;
+ }
+ };
+ astRoot.accept(visitor);
+ assertEquals("No problem found", 1, astRoot.getProblems().length);
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=245348
+ */
+ public void test0696() throws JavaModelException {
+ ICompilationUnit unit = getCompilationUnit("Converter" , "src", "test0696", "X.java"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_COMPILATION_UNIT);
+ parser.setSource(unit.getSource().toCharArray());
+ Map options = JavaCore.getOptions();
+ options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_3);
+ options.put(JavaCore.COMPILER_COMPLIANCE, JavaCore.VERSION_1_4);
+ options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM, JavaCore.VERSION_1_2);
+ parser.setCompilerOptions(options);
+
+ CompilationUnit astRoot = (CompilationUnit) parser.createAST(null);
+ ASTVisitor visitor = new ASTVisitor() {
+ public boolean visit(AnnotationTypeDeclaration node) {
+ assertFalse("Should not be there", true);
+ return false;
+ }
+ };
+ astRoot.accept(visitor);
+ assertEquals("No problem found", 1, astRoot.getProblems().length);
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=248246
+ */
+ public void test0697() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " /*start*/private void foo() {\n" +
+ " Object o = new new Object() {};\n" +
+ " }/*end*/\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ MethodDeclaration methodDeclaration = (MethodDeclaration) buildAST(
+ contents,
+ workingCopy,
+ false,
+ false,
+ true);
+ Block body = methodDeclaration.getBody();
+ assertEquals("Should contain 1 statement", 1, body.statements().size());
+ } finally {
+ if (workingCopy != null) {
+ workingCopy.discardWorkingCopy();
+ }
+ }
+ }
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=248246
+ */
+ public void test0698a() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " private void foo() {\n" +
+ " Object o = new /*start*/new Object() {}/*end*/;\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ ExpressionStatement statement = (ExpressionStatement) buildAST(
+ contents,
+ workingCopy,
+ false,
+ true,
+ true);
+ String expectedContents = "new Object() {}";
+ checkSourceRange(statement, expectedContents, new MarkerInfo(contents).source);
+ } finally {
+ if (workingCopy != null) {
+ workingCopy.discardWorkingCopy();
+ }
+ }
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=248246
+ */
+ public void test0698b() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ String contents =
+ "public class X {\n" +
+ " private void foo() {\n" +
+ " /*start*/Object o = new /*end*/new Object() {};\n" +
+ " }\n" +
+ "}";
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) buildAST(
+ contents,
+ workingCopy,
+ false,
+ true,
+ true);
+ String expectedContents = "Object o = new ";
+ checkSourceRange(statement, expectedContents, new MarkerInfo(contents).source);
+ } finally {
+ if (workingCopy != null) {
+ workingCopy.discardWorkingCopy();
+ }
+ }
+ }
+
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=264443
+ public void test0699() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ workingCopy = getWorkingCopy("/Converter/src/example/Test.java", true/*resolve*/);
+ String contents =
+ "package example;\n" +
+ "public class Test {\n" +
+ " public void test() throws Throwable {\n" +
+ " B /*start*/b = new B()/*end*/;\n" +
+ " }\n" +
+ "}";
+
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) buildAST(contents, workingCopy, false, true, true);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ final String key = variableBinding.getKey();
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setProject(workingCopy.getJavaProject());
+ parser.setResolveBindings(true);
+ parser.setKind(ASTParser.K_COMPILATION_UNIT);
+
+ parser.createASTs(
+ new ICompilationUnit[] { workingCopy },
+ new String[] { key },
+ new ASTRequestor() {
+ public void acceptBinding(String bindingKey,
+ IBinding binding) {
+ assertEquals("Wrong key", key, bindingKey);
+ assertTrue("Not a variable binding", binding.getKind() == IBinding.VARIABLE);
+ }
+
+ public void acceptAST(ICompilationUnit source,
+ CompilationUnit astCompilationUnit) {
+ }
+ }, null);
+ } finally {
+ if (workingCopy != null) {
+ workingCopy.discardWorkingCopy();
+ }
+ }
+ }
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=264443
+ public void test0700() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ workingCopy = getWorkingCopy("/Converter/src/example/Test.java", true/*resolve*/);
+ String contents =
+ "package example;\n" +
+ "import java.io.IOException;\n" +
+ "public class Test {\n" +
+ " public void test() throws IOException, RuntimeException {\n" +
+ " B /*start*/b = new B()/*end*/;\n" +
+ " }\n" +
+ "}";
+
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) buildAST(contents, workingCopy, false, true, true);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ final String key = variableBinding.getKey();
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setProject(workingCopy.getJavaProject());
+ parser.setResolveBindings(true);
+ parser.setKind(ASTParser.K_COMPILATION_UNIT);
+
+ parser.createASTs(
+ new ICompilationUnit[] { workingCopy },
+ new String[] { key },
+ new ASTRequestor() {
+ public void acceptBinding(String bindingKey,
+ IBinding binding) {
+ assertEquals("Wrong key", key, bindingKey);
+ assertTrue("Not a variable binding", binding.getKind() == IBinding.VARIABLE);
+ }
+
+ public void acceptAST(ICompilationUnit source,
+ CompilationUnit astCompilationUnit) {
+ }
+ }, null);
+ } finally {
+ if (workingCopy != null) {
+ workingCopy.discardWorkingCopy();
+ }
+ }
+ }
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=264443
+ //no thrown exceptions
+ public void test0701() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ workingCopy = getWorkingCopy("/Converter/src/example/Test.java", true/*resolve*/);
+ String contents =
+ "package example;\n" +
+ "import java.io.IOException;\n" +
+ "public class Test {\n" +
+ " public void test() {\n" +
+ " B /*start*/b = new B()/*end*/;\n" +
+ " }\n" +
+ "}";
+
+ VariableDeclarationFragment fragment = (VariableDeclarationFragment) buildAST(contents, workingCopy, false, true, true);
+ IVariableBinding variableBinding = fragment.resolveBinding();
+ final String key = variableBinding.getKey();
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setProject(workingCopy.getJavaProject());
+ parser.setResolveBindings(true);
+ parser.setKind(ASTParser.K_COMPILATION_UNIT);
+
+ parser.createASTs(
+ new ICompilationUnit[] { workingCopy },
+ new String[] { key },
+ new ASTRequestor() {
+ public void acceptBinding(String bindingKey,
+ IBinding binding) {
+ assertEquals("Wrong key", key, bindingKey);
+ assertTrue("Not a variable binding", binding.getKind() == IBinding.VARIABLE);
+ }
+ public void acceptAST(ICompilationUnit source,
+ CompilationUnit astCompilationUnit) {
+ }
+ }, null);
+ } finally {
+ if (workingCopy != null) {
+ workingCopy.discardWorkingCopy();
+ }
+ }
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=270148
+ */
+ public void test0702() throws JavaModelException {
+ final char[] source = ("void foo() {\n" +
+ " Integer I = new ${cursor}\n" +
+ "}").toCharArray();
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
+ parser.setStatementsRecovery(true);
+ parser.setSource(source);
+ ASTNode root = parser.createAST(null);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, root.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) root;
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, bodyDeclaration.getNodeType());
+ MethodDeclaration declaration = (MethodDeclaration) bodyDeclaration;
+ // check if there is a body with one statement in it
+ assertEquals("No statement found", 1, declaration.getBody().statements().size());
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=270148
+ */
+ public void test0703() throws JavaModelException {
+ final char[] source = ("public class Try {\n" +
+ " void foo() {\n" +
+ " Integer I = new ${cursor}\n" +
+ " }\n" +
+ "}").toCharArray();
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_COMPILATION_UNIT);
+ parser.setStatementsRecovery(true);
+ parser.setSource(source);
+ ASTNode root = parser.createAST(null);
+ assertEquals("Not a compilation declaration", ASTNode.COMPILATION_UNIT, root.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) ((CompilationUnit) root).types().get(0);
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertEquals("Not a method declaration", ASTNode.METHOD_DECLARATION, bodyDeclaration.getNodeType());
+ MethodDeclaration declaration = (MethodDeclaration) bodyDeclaration;
+ // check if there is a body with one statement in it
+ assertEquals("No statement found", 1, declaration.getBody().statements().size());
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=270148
+ */
+ public void test0704() throws JavaModelException {
+ final char[] source = ("{\n" +
+ " Integer I = new ${cursor}\n" +
+ "}").toCharArray();
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
+ parser.setStatementsRecovery(true);
+ parser.setSource(source);
+ ASTNode root = parser.createAST(null);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, root.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) root;
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertEquals("Not an initializer", ASTNode.INITIALIZER, bodyDeclaration.getNodeType());
+ Initializer initializer = (Initializer) bodyDeclaration;
+ // check if there is a body with one statement in it
+ assertEquals("No statement found", 1, initializer.getBody().statements().size());
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=270148
+ */
+ public void test0705() throws JavaModelException {
+ final char[] source = ("{\n" +
+ " Integer I = new ${cursor}\n" +
+ "}\n" +
+ "{\n" +
+ " Integer I = new ${cursor}\n" +
+ "}").toCharArray();
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
+ parser.setStatementsRecovery(true);
+ parser.setSource(source);
+ ASTNode root = parser.createAST(null);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, root.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) root;
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 2, bodyDeclarations.size());
+ BodyDeclaration bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(0);
+ assertEquals("Not an initializer", ASTNode.INITIALIZER, bodyDeclaration.getNodeType());
+ Initializer initializer = (Initializer) bodyDeclaration;
+ // check if there is a body with one statement in it
+ assertEquals("No statement found", 1, initializer.getBody().statements().size());
+ bodyDeclaration = (BodyDeclaration) bodyDeclarations.get(1);
+ assertEquals("Not an initializer", ASTNode.INITIALIZER, bodyDeclaration.getNodeType());
+ initializer = (Initializer) bodyDeclaration;
+ // check if there is a body with one statement in it
+ assertEquals("No statement found", 1, initializer.getBody().statements().size());
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=270148
+ */
+ public void test0706() throws JavaModelException {
+ final char[] source = ("public class Try {\n" +
+ " Integer i = new Integer() {\n" +
+ " Integer I = new ${cursor}\n" +
+ " };\"\n" +
+ "}").toCharArray();
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_COMPILATION_UNIT);
+ parser.setStatementsRecovery(true);
+ parser.setSource(source);
+ ASTNode root = parser.createAST(null);
+ assertEquals("Not a compilation declaration", ASTNode.COMPILATION_UNIT, root.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) ((CompilationUnit) root).types().get(0);
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size());
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=270148
+ */
+ public void test0707() throws JavaModelException {
+ final char[] source = ("Integer i = new Integer() {\n" +
+ " Integer I = new ${cursor}\n" +
+ "};").toCharArray();
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
+ parser.setStatementsRecovery(true);
+ parser.setSource(source);
+ ASTNode root = parser.createAST(null);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, root.getNodeType());
+ List bodyDeclarations = ((TypeDeclaration) root).bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size());
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=270148
+ */
+ public void test0708() throws JavaModelException {
+ final char[] source = ("System.out.println()\nint i;\n").toCharArray();
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_STATEMENTS);
+ parser.setStatementsRecovery(true);
+ parser.setSource(source);
+ ASTNode root = parser.createAST(null);
+ assertEquals("Not a block", ASTNode.BLOCK, root.getNodeType());
+ Block block = (Block) root;
+ List statements = block.statements();
+ assertEquals("Wrong size", 2, statements.size());
+ }
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=270367
+ public void test0709() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public Integer test() {\n" +
+ " return (new Integer(getId()));\n" +
+ " }\n" +
+ " public String getId() {\n" +
+ " return \"1\";\n" +
+ " }\n" +
+ "}";
+
+ ASTNode node = buildAST(
+ contents,
+ workingCopy);
+ node.accept(new ASTVisitor() {
+ public boolean visit(ParenthesizedExpression parenthesizedExpression) {
+ assertNotNull(parenthesizedExpression.resolveTypeBinding());
+ return true;
+ }
+ });
+ } finally {
+ if (workingCopy != null) {
+ workingCopy.discardWorkingCopy();
+ }
+ }
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=280079
+ */
+ public void test0710() throws JavaModelException {
+ final char[] source = (";").toCharArray();
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
+ parser.setStatementsRecovery(true);
+ parser.setSource(source);
+ ASTNode root = parser.createAST(null);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, root.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) root;
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 0, bodyDeclarations.size());
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=280079
+ */
+ public void test0711() throws JavaModelException {
+ final char[] source = (";void foo() {}").toCharArray();
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
+ parser.setStatementsRecovery(true);
+ parser.setSource(source);
+ ASTNode root = parser.createAST(null);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, root.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) root;
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size());
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=280079
+ */
+ public void test0712() throws JavaModelException {
+ final char[] source = (";void foo() {};").toCharArray();
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
+ parser.setStatementsRecovery(true);
+ parser.setSource(source);
+ ASTNode root = parser.createAST(null);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, root.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) root;
+ List bodyDeclarations = typeDeclaration.bodyDeclarations();
+ assertEquals("Wrong size", 1, bodyDeclarations.size());
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=280063
+ */
+ public void test0713() throws JavaModelException {
+ final char[] source = (" class MyCommand extends CompoundCommand\n" +
+ " {\n" +
+ " public void execute()\n" +
+ " {\n" +
+ " // ...\n" +
+ " appendAndExecute(new AddCommand(...));\n" +
+ " if (condition) appendAndExecute(new AddCommand(...));\n" +
+ " }\n" +
+ " }").toCharArray();
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
+ parser.setStatementsRecovery(false);
+ parser.setSource(source);
+ ASTNode root = parser.createAST(null);
+ assertEquals("Not a type declaration", ASTNode.COMPILATION_UNIT, root.getNodeType());
+ CompilationUnit unit = (CompilationUnit) root;
+ assertTrue("No problem reported", unit.getProblems().length != 0);
+ }
+ /**
+ * http://dev.eclipse.org/bugs/show_bug.cgi?id=280063
+ */
+ public void test0714() throws JavaModelException {
+ final char[] source = ("class MyCommand extends CommandBase\n" +
+ " {\n" +
+ " protected Command subcommand;\n" +
+ "\n" +
+ " //...\n" +
+ "\n" +
+ " public void execute()\n" +
+ " {\n" +
+ " // ...\n" +
+ " Compound subcommands = new CompoundCommand();\n" +
+ " subcommands.appendAndExecute(new AddCommand(...));\n" +
+ " if (condition) subcommands.appendAndExecute(new AddCommand(...));\n" +
+ " subcommand = subcommands.unwrap();\n" +
+ " }\n" +
+ "\n" +
+ " public void undo()\n" +
+ " {\n" +
+ " // ...\n" +
+ " subcommand.undo();\n" +
+ " }\n" +
+ "\n" +
+ " public void redo()\n" +
+ " {\n" +
+ " // ...\n" +
+ " subcommand.redo();\n" +
+ " }\n" +
+ "\n" +
+ " public void dispose()\n" +
+ " {\n" +
+ " // ...\n" +
+ " if (subcommand != null)\n" +
+ " {\n" +
+ " subcommand.dispose();\n" +
+ " }\n" +
+ " }\n" +
+ " }").toCharArray();
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
+ parser.setStatementsRecovery(false);
+ parser.setSource(source);
+ ASTNode root = parser.createAST(null);
+ assertEquals("Not a type declaration", ASTNode.COMPILATION_UNIT, root.getNodeType());
+ CompilationUnit unit = (CompilationUnit) root;
+ assertTrue("No problem reported", unit.getProblems().length != 0);
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=288211
+ */
+ public void test0715() throws JavaModelException {
+ final char[] source = ("System.out.println()\nint i;\n").toCharArray();
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_STATEMENTS);
+ parser.setStatementsRecovery(true);
+ parser.setIgnoreMethodBodies(true);
+ parser.setSource(source);
+ ASTNode root = parser.createAST(null);
+ assertEquals("Not a block", ASTNode.BLOCK, root.getNodeType());
+ Block block = (Block) root;
+ List statements = block.statements();
+ assertEquals("Wrong size", 2, statements.size());
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=288211
+ */
+ public void test0716() {
+ String src = "switch (state) {case 4:double M0,M1;}";
+ char[] source = src.toCharArray();
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind (ASTParser.K_STATEMENTS);
+ parser.setIgnoreMethodBodies(true);
+ parser.setSource (source);
+ ASTNode result = parser.createAST (null);
+ assertNotNull("no result", result);
+ assertEquals("Wrong type", ASTNode.BLOCK, result.getNodeType());
+ Block block = (Block) result;
+ List statements = block.statements();
+ assertNotNull("No statements", statements);
+ assertEquals("Wrong size", 1, statements.size());
+ final ASTNode node = (ASTNode) statements.get(0);
+ assertEquals("Not a switch statement", ASTNode.SWITCH_STATEMENT, node.getNodeType());
+ SwitchStatement statement = (SwitchStatement) node;
+ statements = statement.statements();
+ assertEquals("wrong size", 2, statements.size());
+ assertEquals("Not a switch case", ASTNode.SWITCH_CASE, ((ASTNode) statements.get(0)).getNodeType());
+ assertEquals("Not a variable declaration statement", ASTNode.VARIABLE_DECLARATION_STATEMENT, ((ASTNode) statements.get(1)).getNodeType());
+ }
+ /**
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=288211
+ */
+ public void test0717() throws JavaModelException {
+ final char[] source = (" class MyCommand extends CompoundCommand\n" +
+ " {\n" +
+ " public void execute()\n" +
+ " {\n" +
+ " // ...\n" +
+ " appendAndExecute(new AddCommand());\n" +
+ " if (condition) appendAndExecute(new AddCommand());\n" +
+ " }\n" +
+ " }").toCharArray();
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
+ parser.setStatementsRecovery(false);
+ parser.setIgnoreMethodBodies(true);
+ parser.setSource(source);
+ ASTNode root = parser.createAST(null);
+ assertEquals("Not a type declaration", ASTNode.TYPE_DECLARATION, root.getNodeType());
+ TypeDeclaration typeDeclaration = (TypeDeclaration) root;
+ typeDeclaration.accept(new ASTVisitor() {
+ public boolean visit(MethodDeclaration node) {
+ Block body = node.getBody();
+ assertNotNull(body);
+ assertTrue(body.statements().size() == 0);
+ return true;
+ }
+ });
+ }
+ //https://bugs.eclipse.org/bugs/show_bug.cgi?id=296629
+ public void test0718() throws JavaModelException {
+ ICompilationUnit workingCopy = null;
+ try {
+ workingCopy = getWorkingCopy("/Converter/src/X.java", true/*resolve*/);
+ String contents =
+ "public class X {\n" +
+ " public void v() {\n" +
+ " class Test2 {}\n" +
+ " Test2 t = get();\n" +
+ " t.toString();\n" +
+ " }\n" +
+ " public Object get() {return null;}\n" +
+ "}";
+
+ CompilationUnit unit = (CompilationUnit) buildAST(
+ contents,
+ workingCopy,
+ false);
+ VariableDeclarationStatement statement = (VariableDeclarationStatement) getASTNode(unit, 0, 0, 1);
+ ITypeBinding typeBinding = statement.getType().resolveBinding();
+ ITypeBinding typeBinding2 = ((VariableDeclarationFragment) statement.fragments().get(0)).getInitializer().resolveTypeBinding();
+ assertTrue("Is not cast compatible", typeBinding.isCastCompatible(typeBinding2));
+ } finally {
+ if (workingCopy != null) {
+ workingCopy.discardWorkingCopy();
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTMatcherTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTMatcherTest.java
new file mode 100644
index 0000000..9d73b71
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTMatcherTest.java
@@ -0,0 +1,1284 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2009 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.dom;
+
+import java.lang.reflect.Method;
+
+import junit.framework.Test;
+import org.eclipse.jdt.core.dom.*;
+import org.eclipse.jdt.core.dom.ASTNode;
+
+/**
+ * Test suite for <code>ASTMatcher</code> and <code>ASTNode.subtreeMatch</code>.
+ */
+public class ASTMatcherTest extends org.eclipse.jdt.core.tests.junit.extension.TestCase {
+
+ /** @deprecated using deprecated code */
+ public static Test suite() {
+ // TODO (frederic) use buildList + setAstLevel(init) instead...
+ junit.framework.TestSuite suite = new junit.framework.TestSuite(ASTMatcherTest.class.getName());
+
+ Class c = ASTMatcherTest.class;
+ Method[] methods = c.getMethods();
+ for (int i = 0, max = methods.length; i < max; i++) {
+ if (methods[i].getName().startsWith("test")) { //$NON-NLS-1$
+ suite.addTest(new ASTMatcherTest(methods[i].getName(), AST.JLS2));
+ suite.addTest(new ASTMatcherTest(methods[i].getName(), AST.JLS3));
+ }
+ }
+ return suite;
+ }
+
+ AST ast;
+ SimpleName N1;
+ SimpleName N2;
+ SimpleName N3;
+ SimpleName N4;
+ Expression E1;
+ Expression E2;
+ Type T1;
+ String T1S;
+ Type T2;
+ String T2S;
+ ParameterizedType PT1;
+ String PT1S;
+ Statement S1;
+ Statement S2;
+ Block B1;
+ SingleVariableDeclaration V1;
+ SingleVariableDeclaration V2;
+ VariableDeclarationFragment W1;
+ VariableDeclarationFragment W2;
+ FieldDeclaration FD1;
+ FieldDeclaration FD2;
+ PackageDeclaration PD1;
+ ImportDeclaration ID1;
+ ImportDeclaration ID2;
+ TypeDeclaration TD1;
+ TypeDeclaration TD2;
+ AnonymousClassDeclaration ACD1;
+ Javadoc JD1;
+ Javadoc JD2;
+ String JD2S;
+ TypeParameter TP1;
+ String TP1S;
+ TypeParameter TP2;
+ String TP2S;
+ TagElement TAG1;
+ TagElement TAG2;
+ TextElement TEXT1;
+ MemberRef MBREF1;
+ MethodRef MTHREF1;
+ MethodRefParameter MPARM1;
+ LineComment LC1;
+ BlockComment BC1;
+ MemberValuePair MVP1;
+ MemberValuePair MVP2;
+ MarkerAnnotation ANO1;
+ SingleMemberAnnotation ANO2;
+ Modifier MOD1;
+ Modifier MOD2;
+ EnumConstantDeclaration EC1;
+ EnumConstantDeclaration EC2;
+
+ final StringBuffer b = new StringBuffer();
+
+ int API_LEVEL;
+
+ public ASTMatcherTest(String name, int apiLevel) {
+ super(name);
+ this.API_LEVEL = apiLevel;
+ }
+
+ /**
+ * @deprecated (not really - just suppressing the warnings
+ * that come from testing Javadoc.getComment())
+ *
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+
+ this.ast = AST.newAST(this.API_LEVEL);
+ this.N1 = this.ast.newSimpleName("N"); //$NON-NLS-1$
+ this.N2 = this.ast.newSimpleName("M"); //$NON-NLS-1$
+ this.N3 = this.ast.newSimpleName("O"); //$NON-NLS-1$
+ this.N4 = this.ast.newSimpleName("P"); //$NON-NLS-1$
+ this.E1 = this.ast.newSimpleName("X"); //$NON-NLS-1$
+ this.E2 = this.ast.newSimpleName("Y"); //$NON-NLS-1$
+ this.T1 = this.ast.newSimpleType(this.ast.newSimpleName("Z")); //$NON-NLS-1$
+ this.T1S = "(tS(nSZZnS)tS)"; //$NON-NLS-1$
+ this.T2 = this.ast.newSimpleType(this.ast.newSimpleName("Y")); //$NON-NLS-1$
+ this.T2S = "(tS(nSYYnS)tS)"; //$NON-NLS-1$
+ this.S1 = this.ast.newContinueStatement();
+ this.S2 = this.ast.newBreakStatement();
+ this.B1 = this.ast.newBlock();
+ this.V1 = this.ast.newSingleVariableDeclaration();
+ this.V1.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+ this.V1.setName(this.ast.newSimpleName("a")); //$NON-NLS-1$
+ this.V2 = this.ast.newSingleVariableDeclaration();
+ this.V2.setType(this.ast.newPrimitiveType(PrimitiveType.BYTE));
+ this.V2.setName(this.ast.newSimpleName("b")); //$NON-NLS-1$
+ this.W1 = this.ast.newVariableDeclarationFragment();
+ this.W1.setName(this.ast.newSimpleName("a")); //$NON-NLS-1$
+ this.W2 = this.ast.newVariableDeclarationFragment();
+ this.W2.setName(this.ast.newSimpleName("b")); //$NON-NLS-1$
+ {
+ VariableDeclarationFragment temp = this.ast.newVariableDeclarationFragment();
+ temp.setName(this.ast.newSimpleName("f")); //$NON-NLS-1$
+ this.FD1 = this.ast.newFieldDeclaration(temp);
+ this.FD1.setType(this.ast.newPrimitiveType(PrimitiveType.INT));
+ }
+ {
+ VariableDeclarationFragment temp = this.ast.newVariableDeclarationFragment();
+ temp.setName(this.ast.newSimpleName("g")); //$NON-NLS-1$
+ this.FD2 = this.ast.newFieldDeclaration(temp);
+ this.FD2.setType(this.ast.newPrimitiveType(PrimitiveType.CHAR));
+ }
+ this.PD1 = this.ast.newPackageDeclaration();
+ this.PD1.setName(this.ast.newSimpleName("p")); //$NON-NLS-1$
+ this.ID1 = this.ast.newImportDeclaration();
+ this.ID1.setName(this.ast.newSimpleName("i")); //$NON-NLS-1$
+ this.ID2 = this.ast.newImportDeclaration();
+ this.ID2.setName(this.ast.newSimpleName("j")); //$NON-NLS-1$
+ this.TD1 = this.ast.newTypeDeclaration();
+ this.TD1.setName(this.ast.newSimpleName("c")); //$NON-NLS-1$
+ this.TD2 = this.ast.newTypeDeclaration();
+ this.TD2.setName(this.ast.newSimpleName("d")); //$NON-NLS-1$
+
+ this.ACD1 = this.ast.newAnonymousClassDeclaration();
+
+ this.JD1 = this.ast.newJavadoc();
+ this.JD2 = this.ast.newJavadoc();
+ if (this.ast.apiLevel() == AST.JLS2) {
+ this.JD1.setComment("/**X*/"); //$NON-NLS-1$
+ this.JD2.setComment("/**Y*/"); //$NON-NLS-1$
+ }
+
+ this.BC1 = this.ast.newBlockComment();
+
+ this.TAG1 = this.ast.newTagElement();
+ this.TAG1.setTagName("@foo"); //$NON-NLS-1$
+
+ this.TAG2 = this.ast.newTagElement();
+ this.TAG2.setTagName("@bar"); //$NON-NLS-1$
+
+ this.TEXT1 = this.ast.newTextElement();
+ this.TEXT1.setText("foo"); //$NON-NLS-1$
+
+ this.MBREF1 = this.ast.newMemberRef();
+ this.MBREF1.setName(this.ast.newSimpleName("p")); //$NON-NLS-1$
+
+ this.MTHREF1 = this.ast.newMethodRef();
+ this.MTHREF1.setName(this.ast.newSimpleName("p")); //$NON-NLS-1$
+
+ this.MPARM1 = this.ast.newMethodRefParameter();
+ this.MPARM1.setType(this.ast.newPrimitiveType(PrimitiveType.CHAR));
+
+ if (this.ast.apiLevel() >= AST.JLS3) {
+ this.PT1 = this.ast.newParameterizedType(this.ast.newSimpleType(this.ast.newSimpleName("Z"))); //$NON-NLS-1$
+ this.PT1S = "[(tM[(tS[(nSZZnS)]tS)]tM)]"; //$NON-NLS-1$
+
+ this.TP1 = this.ast.newTypeParameter();
+ this.TP1.setName(this.ast.newSimpleName("x")); //$NON-NLS-1$
+ this.TP1S = "[(tTP[(nSxxnS)]tTP)]"; //$NON-NLS-1$
+
+ this.TP2 = this.ast.newTypeParameter();
+ this.TP2.setName(this.ast.newSimpleName("y")); //$NON-NLS-1$
+ this.TP2S = "[(tTP[(nSyynS)]tTP)]"; //$NON-NLS-1$
+ this.LC1 = this.ast.newLineComment();
+
+ this.MVP1 = this.ast.newMemberValuePair();
+ this.MVP1.setName(this.ast.newSimpleName("x")); //$NON-NLS-1$
+ this.MVP1.setValue(this.ast.newSimpleName("y")); //$NON-NLS-1$
+
+ this.MVP2 = this.ast.newMemberValuePair();
+ this.MVP2.setName(this.ast.newSimpleName("a")); //$NON-NLS-1$
+ this.MVP2.setValue(this.ast.newSimpleName("b")); //$NON-NLS-1$
+
+ this.ANO1 = this.ast.newMarkerAnnotation();
+ this.ANO1.setTypeName(this.ast.newSimpleName("p")); //$NON-NLS-1$
+
+ this.ANO2 = this.ast.newSingleMemberAnnotation();
+ this.ANO2.setTypeName(this.ast.newSimpleName("q")); //$NON-NLS-1$
+ this.ANO2.setValue(this.ast.newSimpleName("v")); //$NON-NLS-1$
+
+ this.MOD1 = this.ast.newModifier(Modifier.ModifierKeyword.PUBLIC_KEYWORD);
+ this.MOD2 = this.ast.newModifier(Modifier.ModifierKeyword.FINAL_KEYWORD);
+
+ this.EC1 = this.ast.newEnumConstantDeclaration();
+ this.EC1.setName(this.ast.newSimpleName("F")); //$NON-NLS-1$
+ this.EC2 = this.ast.newEnumConstantDeclaration();
+ this.EC2.setName(this.ast.newSimpleName("G")); //$NON-NLS-1$
+ }
+
+ }
+
+ protected void tearDown() throws Exception {
+ this.ast = null;
+ super.tearDown();
+ }
+
+ /** @deprecated using deprecated code */
+ public String getName() {
+ String name = super.getName();
+ switch (this.API_LEVEL) {
+ case AST.JLS2:
+ name = "JLS2 - " + name;
+ break;
+ case AST.JLS3:
+ name = "JLS3 - " + name;
+ break;
+ }
+ return name;
+ }
+
+ /**
+ * An ASTMatcher that simply records the arguments it is passed,
+ * immediately returns a pre-ordained answer, and counts how many
+ * times it is called.
+ */
+ class TestMatcher extends ASTMatcher {
+
+ public Object receiverNode;
+ public Object otherNode;
+ public boolean result;
+ public boolean superMatch;
+ public boolean superMatchResult;
+ public int matchCalls = 0;
+
+ TestMatcher() {
+ this(false);
+ }
+
+ TestMatcher(boolean visitDocTags) {
+ super(visitDocTags);
+ }
+
+ boolean standardBody(ASTNode receiver, Object other, boolean matchResult) {
+ this.matchCalls++;
+ this.receiverNode = receiver;
+ this.otherNode = other;
+ this.superMatchResult = matchResult;
+ if (this.superMatch) {
+ return this.superMatchResult;
+ }
+ return this.result;
+ }
+
+ public boolean match(AnnotationTypeDeclaration node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(AnnotationTypeMemberDeclaration node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(AnonymousClassDeclaration node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(ArrayAccess node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(ArrayCreation node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(ArrayInitializer node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(ArrayType node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(AssertStatement node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(Assignment node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(Block node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(BlockComment node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(BooleanLiteral node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(BreakStatement node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(CastExpression node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(CatchClause node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(CharacterLiteral node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(ClassInstanceCreation node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(CompilationUnit node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(ConditionalExpression node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(ConstructorInvocation node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(ContinueStatement node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(DoStatement node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(EmptyStatement node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(EnhancedForStatement node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(EnumConstantDeclaration node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(EnumDeclaration node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(ExpressionStatement node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(FieldAccess node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(FieldDeclaration node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(ForStatement node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(IfStatement node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(ImportDeclaration node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(InfixExpression node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(Initializer node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(Javadoc node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(LabeledStatement node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(LineComment node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(MarkerAnnotation node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(MemberRef node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(MemberValuePair node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(MethodDeclaration node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(MethodInvocation node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(MethodRef node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(MethodRefParameter node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(Modifier node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(NormalAnnotation node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(NullLiteral node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(NumberLiteral node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(PackageDeclaration node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(ParameterizedType node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(ParenthesizedExpression node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(PostfixExpression node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(PrefixExpression node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(PrimitiveType node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(QualifiedName node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(QualifiedType node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(ReturnStatement node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(SimpleName node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(SimpleType node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(SingleMemberAnnotation node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(SingleVariableDeclaration node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(StringLiteral node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(SuperConstructorInvocation node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(SuperFieldAccess node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(SuperMethodInvocation node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(SwitchCase node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(SwitchStatement node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(SynchronizedStatement node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(TagElement node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(TextElement node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(ThisExpression node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(ThrowStatement node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(TryStatement node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(TypeDeclaration node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(TypeDeclarationStatement node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(TypeLiteral node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(TypeParameter node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(VariableDeclarationExpression node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(VariableDeclarationFragment node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(VariableDeclarationStatement node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(WhileStatement node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ public boolean match(WildcardType node, Object other) {
+ return standardBody(node, other, this.superMatch ? super.match(node, other) : false);
+ }
+ }
+
+ /**
+ * AST node visitor that counts the nodes visited.
+ */
+ static class NodeCounter extends ASTVisitor {
+ public NodeCounter(boolean visitDocTags) {
+ super(visitDocTags);
+ }
+
+ public int count = 0;
+
+ /* (no javadoc for this method)
+ * Method declared on ASTVisitor.
+ */
+ public void preVisit(ASTNode node) {
+ this.count++;
+ }
+
+ }
+
+ /**
+ * Returns the number of AST nodes in the given subtree.
+ *
+ * @param node the root of the subtree
+ * @param visitDocTags true if doc tags should be visited
+ * @return the number of nodes (always positive)
+ */
+ static int nodeCount(ASTNode node, boolean visitDocTags) {
+ NodeCounter c = new NodeCounter(visitDocTags);
+ node.accept(c);
+ return c.count;
+ }
+
+ /**
+ * Checks that the ASTNode.subtreeMatch mechanism is working
+ * for a node of a given type.
+ */
+ void basicMatch(ASTNode node) {
+ TestMatcher[] m = {
+ new TestMatcher(),
+ new TestMatcher(true),
+ new TestMatcher(false)};
+ for (int i = 0; i < m.length; i++) {
+ // check that matcher was called with right arguments
+ // and that matches succeed
+ TestMatcher m1 = m[i];
+ Object o1 = new Object();
+ m1.result = true;
+ boolean result = node.subtreeMatch(m1, o1);
+ assertTrue(m1.matchCalls == 1);
+ assertTrue(m1.receiverNode == node);
+ assertTrue(m1.otherNode == o1);
+ assertTrue(result == true);
+ }
+
+ m = new TestMatcher[] {
+ new TestMatcher(),
+ new TestMatcher(true),
+ new TestMatcher(false)};
+ for (int i = 0; i < m.length; i++) {
+ // check that matcher was called with right arguments
+ // and that non-matches fail
+ TestMatcher m1 = m[i];
+ Object o1 = new Object();
+ m1.result = false;
+ boolean result = node.subtreeMatch(m1, o1);
+ assertTrue(m1.matchCalls == 1);
+ assertTrue(m1.receiverNode == node);
+ assertTrue(m1.otherNode == o1);
+ assertTrue(result == false);
+ }
+
+ // check that ASTMatcher() default implementations delegate
+ {
+ int count = nodeCount(node, false); // ignore doc tags
+ TestMatcher m1 = new TestMatcher();
+ m1.superMatch = true;
+ boolean result = node.subtreeMatch(m1, node);
+ assertTrue(m1.matchCalls == count);
+ assertTrue(result == true);
+ }
+
+ // check that ASTMatcher(false) default implementations delegate
+ {
+ int count = nodeCount(node, false); // ignore doc tags
+ TestMatcher m1 = new TestMatcher(false);
+ m1.superMatch = true;
+ boolean result = node.subtreeMatch(m1, node);
+ assertTrue(m1.matchCalls == count);
+ assertTrue(result == true);
+ }
+
+ // check that ASTMatcher(true) default implementations delegate
+ {
+ int count = nodeCount(node, true); // include doc tags
+ TestMatcher m1 = new TestMatcher(true);
+ m1.superMatch = true;
+ boolean result = node.subtreeMatch(m1, node);
+ assertTrue(m1.matchCalls == count);
+ assertTrue(result == true);
+ }
+
+ }
+
+ // NAMES
+ public void testSimpleName() {
+ Name x1 = this.ast.newName(new String[]{"Z"}); //$NON-NLS-1$
+ basicMatch(x1);
+ }
+
+ public void testQualifiedName() {
+ Name x1 = this.ast.newName(new String[]{"X", "Y"}); //$NON-NLS-1$ //$NON-NLS-2$
+ basicMatch(x1);
+ }
+
+
+ // TYPES
+ public void testPrimitiveType() {
+ Type x1 = this.ast.newPrimitiveType(PrimitiveType.CHAR);
+ basicMatch(x1);
+ }
+
+ public void testSimpleType() {
+ Type x1 = this.ast.newSimpleType(this.N1);
+ basicMatch(x1);
+ }
+
+ public void testArrayType() {
+ Type x0 = this.ast.newPrimitiveType(PrimitiveType.CHAR);
+ Type x1 = this.ast.newArrayType(x0);
+ basicMatch(x1);
+ }
+
+ /** @deprecated using deprecated code */
+ public void testParameterizedType() {
+ if (this.ast.apiLevel() == AST.JLS2) {
+ return;
+ }
+ ParameterizedType x1 = this.ast.newParameterizedType(this.ast.newSimpleType(this.ast.newSimpleName("X"))); //$NON-NLS-1$
+ x1.typeArguments().add(this.T1);
+ x1.typeArguments().add(this.T2);
+ basicMatch(x1);
+ }
+
+ /** @deprecated using deprecated code */
+ public void testQualifiedType() {
+ if (this.ast.apiLevel() == AST.JLS2) {
+ return;
+ }
+ Type x1 = this.ast.newQualifiedType(this.T1, this.N1);
+ basicMatch(x1);
+ }
+
+ /** @deprecated using deprecated code */
+ public void testWildcardType() {
+ if (this.ast.apiLevel() == AST.JLS2) {
+ return;
+ }
+ WildcardType x1 = this.ast.newWildcardType();
+ x1.setBound(this.T1, true);
+ basicMatch(x1);
+ }
+
+ // EXPRESSIONS and STATEMENTS
+
+ public void testAnonymousClassDeclaration() {
+ AnonymousClassDeclaration x1 = this.ast.newAnonymousClassDeclaration();
+ x1.bodyDeclarations().add(this.FD1);
+ x1.bodyDeclarations().add(this.FD2);
+ basicMatch(x1);
+ }
+ public void testArrayAccess() {
+ ArrayAccess x1 = this.ast.newArrayAccess();
+ x1.setArray(this.E1);
+ x1.setIndex(this.E2);
+ basicMatch(x1);
+ }
+ public void testArrayCreation() {
+ ArrayCreation x1 = this.ast.newArrayCreation();
+ x1.setType(this.ast.newArrayType(this.T1));
+ x1.dimensions().add(this.E1);
+ x1.dimensions().add(this.E2);
+ x1.setInitializer(this.ast.newArrayInitializer());
+ basicMatch(x1);
+ }
+ public void testArrayInitializer() {
+ ArrayInitializer x1 = this.ast.newArrayInitializer();
+ x1.expressions().add(this.E1);
+ x1.expressions().add(this.E2);
+ basicMatch(x1);
+ }
+ public void testAssertStatement() {
+ AssertStatement x1 = this.ast.newAssertStatement();
+ x1.setExpression(this.E1);
+ x1.setMessage(this.E2);
+ basicMatch(x1);
+ }
+ public void testAssignment() {
+ Assignment x1 = this.ast.newAssignment();
+ x1.setLeftHandSide(this.E1);
+ x1.setRightHandSide(this.E2);
+ basicMatch(x1);
+ }
+ public void testBlock() {
+ Block x1 = this.ast.newBlock();
+ x1.statements().add(this.S1);
+ x1.statements().add(this.S2);
+ basicMatch(x1);
+ }
+
+ public void testBlockComment() {
+ BlockComment x1 = this.ast.newBlockComment();
+ basicMatch(x1);
+ }
+
+ public void testBooleanLiteral() {
+ BooleanLiteral x1 = this.ast.newBooleanLiteral(true);
+ basicMatch(x1);
+ }
+ public void testBreakStatement() {
+ BreakStatement x1 = this.ast.newBreakStatement();
+ x1.setLabel(this.N1);
+ basicMatch(x1);
+ }
+ public void testCastExpression() {
+ CastExpression x1 = this.ast.newCastExpression();
+ x1.setType(this.T1);
+ x1.setExpression(this.E1);
+ basicMatch(x1);
+ }
+ public void testCatchClause() {
+ CatchClause x1 = this.ast.newCatchClause();
+ x1.setException(this.V1);
+ x1.setBody(this.B1);
+ basicMatch(x1);
+ }
+ public void testCharacterLiteral() {
+ CharacterLiteral x1 = this.ast.newCharacterLiteral();
+ x1.setCharValue('q');
+ basicMatch(x1);
+ }
+ /** @deprecated using deprecated code */
+ public void testClassInstanceCreation() {
+ ClassInstanceCreation x1 = this.ast.newClassInstanceCreation();
+ x1.setExpression(this.E1);
+ if (this.ast.apiLevel() == AST.JLS2) {
+ x1.setName(this.N1);
+ } else {
+ x1.typeArguments().add(this.PT1);
+ x1.setType(this.T1);
+ }
+ x1.setAnonymousClassDeclaration(this.ACD1);
+ basicMatch(x1);
+ }
+ public void testCompilationUnit() {
+ CompilationUnit x1 = this.ast.newCompilationUnit();
+ x1.setPackage(this.PD1);
+ x1.imports().add(this.ID1);
+ x1.imports().add(this.ID2);
+ x1.types().add(this.TD1);
+ x1.types().add(this.TD2);
+ basicMatch(x1);
+ }
+ public void testConditionalExpression() {
+ ConditionalExpression x1 = this.ast.newConditionalExpression();
+ x1.setExpression(this.E1);
+ x1.setThenExpression(this.E2);
+ x1.setElseExpression(this.N1);
+ basicMatch(x1);
+ }
+ public void testConstructorInvocation() {
+ ConstructorInvocation x1 = this.ast.newConstructorInvocation();
+ if (this.ast.apiLevel() >= AST.JLS3) {
+ x1.typeArguments().add(this.PT1);
+ }
+ x1.arguments().add(this.E1);
+ x1.arguments().add(this.E2);
+ basicMatch(x1);
+ }
+ public void testContinueStatement() {
+ ContinueStatement x1 = this.ast.newContinueStatement();
+ x1.setLabel(this.N1);
+ basicMatch(x1);
+ }
+ public void testDoStatement() {
+ DoStatement x1 = this.ast.newDoStatement();
+ x1.setExpression(this.E1);
+ x1.setBody(this.S1);
+ basicMatch(x1);
+ }
+ public void testEmptyStatement() {
+ EmptyStatement x1 = this.ast.newEmptyStatement();
+ basicMatch(x1);
+ }
+ /** @deprecated using deprecated code */
+ public void testEnhancedForStatement() {
+ if (this.ast.apiLevel() == AST.JLS2) {
+ return;
+ }
+ EnhancedForStatement x1 = this.ast.newEnhancedForStatement();
+ x1.setParameter(this.V1);
+ x1.setExpression(this.E1);
+ x1.setBody(this.S1);
+ basicMatch(x1);
+ }
+ /** @deprecated Only to suppress warnings for refs to bodyDeclarations. */
+ // TODO (jeem) - remove deprecation after 3.1 M4
+ public void testEnumConstantDeclaration() {
+ if (this.ast.apiLevel() == AST.JLS2) {
+ return;
+ }
+ EnumConstantDeclaration x1 = this.ast.newEnumConstantDeclaration();
+ x1.setJavadoc(this.JD1);
+ x1.modifiers().add(this.MOD1);
+ x1.modifiers().add(this.MOD2);
+ x1.setName(this.N1);
+ x1.arguments().add(this.E1);
+ x1.arguments().add(this.E2);
+ x1.setAnonymousClassDeclaration(this.ACD1);
+ basicMatch(x1);
+ }
+ /** @deprecated using deprecated code */
+ public void testEnumDeclaration() {
+ if (this.ast.apiLevel() == AST.JLS2) {
+ return;
+ }
+ EnumDeclaration x1 = this.ast.newEnumDeclaration();
+ x1.setJavadoc(this.JD1);
+ x1.modifiers().add(this.MOD1);
+ x1.modifiers().add(this.MOD2);
+ x1.setName(this.N1);
+ x1.superInterfaceTypes().add(this.T1);
+ x1.superInterfaceTypes().add(this.T2);
+ x1.enumConstants().add(this.EC1);
+ x1.enumConstants().add(this.EC2);
+ x1.bodyDeclarations().add(this.FD1);
+ x1.bodyDeclarations().add(this.FD2);
+ basicMatch(x1);
+ }
+ public void testExpressionStatement() {
+ ExpressionStatement x1 = this.ast.newExpressionStatement(this.E1);
+ basicMatch(x1);
+ }
+ public void testFieldAccess() {
+ FieldAccess x1 = this.ast.newFieldAccess();
+ x1.setExpression(this.E1);
+ x1.setName(this.N1);
+ basicMatch(x1);
+ }
+ public void testFieldDeclaration() {
+ FieldDeclaration x1 = this.ast.newFieldDeclaration(this.W1);
+ x1.setJavadoc(this.JD1);
+ if (this.ast.apiLevel() >= AST.JLS3) {
+ x1.modifiers().add(this.MOD1);
+ x1.modifiers().add(this.MOD2);
+ }
+ x1.setType(this.T1);
+ x1.fragments().add(this.W2);
+ basicMatch(x1);
+ }
+ public void testForStatement() {
+ ForStatement x1 = this.ast.newForStatement();
+ x1.initializers().add(this.E1);
+ x1.initializers().add(this.E2);
+ x1.setExpression(this.N1);
+ x1.updaters().add(this.N2);
+ x1.updaters().add(this.N3);
+ x1.setBody(this.S1);
+ basicMatch(x1);
+ }
+ public void testIfStatement() {
+ IfStatement x1 = this.ast.newIfStatement();
+ x1.setExpression(this.E1);
+ x1.setThenStatement(this.S1);
+ x1.setElseStatement(this.S2);
+ basicMatch(x1);
+ }
+ public void testImportDeclaration() {
+ ImportDeclaration x1 = this.ast.newImportDeclaration();
+ x1.setName(this.N1);
+ basicMatch(x1);
+ }
+ public void testInfixExpression() {
+ InfixExpression x1 = this.ast.newInfixExpression();
+ x1.setOperator(InfixExpression.Operator.PLUS);
+ x1.setLeftOperand(this.E1);
+ x1.setRightOperand(this.E2);
+ x1.extendedOperands().add(this.N1);
+ x1.extendedOperands().add(this.N2);
+ basicMatch(x1);
+ }
+ public void testInitializer() {
+ Initializer x1 = this.ast.newInitializer();
+ x1.setJavadoc(this.JD1);
+ if (this.ast.apiLevel() >= AST.JLS3) {
+ x1.modifiers().add(this.MOD1);
+ x1.modifiers().add(this.MOD2);
+ }
+ x1.setBody(this.B1);
+ basicMatch(x1);
+ }
+ /**
+ * @deprecated (not really - just suppressing the warnings
+ * that come from testing Javadoc.getComment())
+ *
+ */
+ public void testJavadoc() {
+ Javadoc x1 = this.ast.newJavadoc();
+ if (this.ast.apiLevel() == AST.JLS2) {
+ x1.setComment("/**?*/"); //$NON-NLS-1$
+ }
+ x1.tags().add(this.TAG1);
+ x1.tags().add(this.TAG2);
+ basicMatch(x1);
+ }
+
+ public void testLabeledStatement() {
+ LabeledStatement x1 = this.ast.newLabeledStatement();
+ x1.setLabel(this.N1);
+ x1.setBody(this.S1);
+ basicMatch(x1);
+ }
+
+ public void testLineComment() {
+ LineComment x1 = this.ast.newLineComment();
+ basicMatch(x1);
+ }
+
+ public void testMemberRef() {
+ MemberRef x1 = this.ast.newMemberRef();
+ x1.setQualifier(this.N1);
+ x1.setName(this.N2);
+ basicMatch(x1);
+ }
+
+ /** @deprecated using deprecated code */
+ public void testMethodDeclaration() {
+ MethodDeclaration x1 = this.ast.newMethodDeclaration();
+ x1.setJavadoc(this.JD1);
+ if (this.ast.apiLevel() == AST.JLS2) {
+ x1.setReturnType(this.T1);
+ } else {
+ x1.modifiers().add(this.MOD1);
+ x1.modifiers().add(this.MOD2);
+ x1.typeParameters().add(this.TP1);
+ x1.typeParameters().add(this.TP2);
+ x1.setReturnType2(this.T1);
+ }
+ x1.setName(this.N1);
+ x1.parameters().add(this.V1);
+ x1.parameters().add(this.V2);
+ x1.thrownExceptions().add(this.N2);
+ x1.thrownExceptions().add(this.N3);
+ x1.setBody(this.B1);
+ basicMatch(x1);
+ }
+ public void testMethodInvocation() {
+ MethodInvocation x1 = this.ast.newMethodInvocation();
+ x1.setExpression(this.N1);
+ if (this.ast.apiLevel() >= AST.JLS3) {
+ x1.typeArguments().add(this.PT1);
+ }
+ x1.setName(this.N2);
+ x1.arguments().add(this.E1);
+ x1.arguments().add(this.E2);
+ basicMatch(x1);
+ }
+
+ public void testMethodRef() {
+ MethodRef x1 = this.ast.newMethodRef();
+ basicMatch(x1);
+ x1.setQualifier(this.N1);
+ x1.setName(this.N2);
+ x1.parameters().add(this.MPARM1);
+ }
+ public void testMethodRefParameter() {
+ MethodRefParameter x1 = this.ast.newMethodRefParameter();
+ x1.setType(this.T1);
+ x1.setName(this.N1);
+ basicMatch(x1);
+ }
+
+ public void testNullLiteral() {
+ NullLiteral x1 = this.ast.newNullLiteral();
+ basicMatch(x1);
+ }
+ public void testNumberLiteral() {
+ NumberLiteral x1 = this.ast.newNumberLiteral("1.0"); //$NON-NLS-1$
+ basicMatch(x1);
+ }
+ public void testPackageDeclaration() {
+ PackageDeclaration x1 = this.ast.newPackageDeclaration();
+ if (this.ast.apiLevel() >= AST.JLS3) {
+ x1.setJavadoc(this.JD1);
+ x1.annotations().add(this.ANO1);
+ x1.annotations().add(this.ANO2);
+ }
+ basicMatch(x1);
+ }
+ public void testParenthesizedExpression() {
+ ParenthesizedExpression x1 = this.ast.newParenthesizedExpression();
+ basicMatch(x1);
+ }
+ public void testPostfixExpression() {
+ PostfixExpression x1 = this.ast.newPostfixExpression();
+ x1.setOperand(this.E1);
+ x1.setOperator(PostfixExpression.Operator.INCREMENT);
+ basicMatch(x1);
+ }
+ public void testPrefixExpression() {
+ PrefixExpression x1 = this.ast.newPrefixExpression();
+ x1.setOperand(this.E1);
+ x1.setOperator(PrefixExpression.Operator.INCREMENT);
+ basicMatch(x1);
+ }
+ public void testReturnStatement() {
+ ReturnStatement x1 = this.ast.newReturnStatement();
+ x1.setExpression(this.E1);
+ basicMatch(x1);
+ }
+ public void testSingleVariableDeclaration() {
+ SingleVariableDeclaration x1 = this.ast.newSingleVariableDeclaration();
+ if (this.ast.apiLevel() >= AST.JLS3) {
+ x1.modifiers().add(this.MOD1);
+ x1.modifiers().add(this.MOD2);
+ }
+ x1.setType(this.T1);
+ x1.setName(this.N1);
+ x1.setInitializer(this.E1);
+ basicMatch(x1);
+ }
+ public void testStringLiteral() {
+ StringLiteral x1 = this.ast.newStringLiteral();
+ x1.setLiteralValue("H"); //$NON-NLS-1$
+ basicMatch(x1);
+ }
+ public void testSuperConstructorInvocation() {
+ SuperConstructorInvocation x1 = this.ast.newSuperConstructorInvocation();
+ x1.setExpression(this.N1);
+ if (this.ast.apiLevel() >= AST.JLS3) {
+ x1.typeArguments().add(this.PT1);
+ }
+ x1.arguments().add(this.E1);
+ x1.arguments().add(this.E2);
+ basicMatch(x1);
+ }
+ public void testSuperFieldAccess() {
+ SuperFieldAccess x1 = this.ast.newSuperFieldAccess();
+ x1.setQualifier(this.N1);
+ x1.setName(this.N2);
+ basicMatch(x1);
+ }
+ public void testSuperMethodInvocation() {
+ SuperMethodInvocation x1 = this.ast.newSuperMethodInvocation();
+ x1.setQualifier(this.N1);
+ if (this.ast.apiLevel() >= AST.JLS3) {
+ x1.typeArguments().add(this.PT1);
+ }
+ x1.setName(this.N2);
+ x1.arguments().add(this.E1);
+ x1.arguments().add(this.E2);
+ basicMatch(x1);
+ }
+ public void testSwitchCase() {
+ SwitchCase x1 = this.ast.newSwitchCase();
+ x1.setExpression(this.E1);
+ basicMatch(x1);
+ }
+ public void testSwitchStatement() {
+ SwitchStatement x1 = this.ast.newSwitchStatement();
+ x1.setExpression(this.E1);
+ x1.statements().add(this.S1);
+ x1.statements().add(this.S2);
+ basicMatch(x1);
+ }
+ public void testSynchronizedStatement() {
+ SynchronizedStatement x1 = this.ast.newSynchronizedStatement();
+ x1.setExpression(this.E1);
+ x1.setBody(this.B1);
+ basicMatch(x1);
+ }
+
+ public void testTagElement() {
+ TagElement x1 = this.ast.newTagElement();
+ x1.setTagName("@foo"); //$NON-NLS-1$
+ x1.fragments().add(this.TAG1);
+ x1.fragments().add(this.TEXT1);
+ x1.fragments().add(this.N1);
+ x1.fragments().add(this.MTHREF1);
+ basicMatch(x1);
+ }
+ public void testTextElement() {
+ TextElement x1 = this.ast.newTextElement();
+ x1.setText("foo"); //$NON-NLS-1$
+ basicMatch(x1);
+ }
+
+ public void testThisExpression() {
+ ThisExpression x1 = this.ast.newThisExpression();
+ x1.setQualifier(this.N1);
+ basicMatch(x1);
+ }
+ public void testThrowStatement() {
+ ThrowStatement x1 = this.ast.newThrowStatement();
+ x1.setExpression(this.E1);
+ basicMatch(x1);
+ }
+ public void testTryStatement() {
+ TryStatement x1 = this.ast.newTryStatement();
+ x1.setBody(this.B1);
+ CatchClause c1 = this.ast.newCatchClause();
+ c1.setException(this.V1);
+ c1.setBody(this.ast.newBlock());
+ x1.catchClauses().add(c1);
+ CatchClause c2 = this.ast.newCatchClause();
+ c2.setException(this.V2);
+ c2.setBody(this.ast.newBlock());
+ x1.catchClauses().add(c2);
+ x1.setFinally(this.ast.newBlock());
+ basicMatch(x1);
+ }
+ /** @deprecated using deprecated code */
+ public void testTypeDeclaration() {
+ TypeDeclaration x1 = this.ast.newTypeDeclaration();
+ x1.setJavadoc(this.JD1);
+ x1.setName(this.N1);
+ if (this.ast.apiLevel() == AST.JLS2) {
+ x1.setSuperclass(this.N2);
+ x1.superInterfaces().add(this.N3);
+ x1.superInterfaces().add(this.N4);
+ } else {
+ x1.modifiers().add(this.MOD1);
+ x1.modifiers().add(this.MOD2);
+ x1.typeParameters().add(this.TP1);
+ x1.typeParameters().add(this.TP2);
+ x1.setSuperclassType(this.PT1);
+ x1.superInterfaceTypes().add(this.T1);
+ x1.superInterfaceTypes().add(this.T2);
+ }
+ x1.bodyDeclarations().add(this.FD1);
+ x1.bodyDeclarations().add(this.FD2);
+ basicMatch(x1);
+ }
+ public void testTypeDeclarationStatement() {
+ TypeDeclarationStatement x1 = this.ast.newTypeDeclarationStatement(this.TD1);
+ basicMatch(x1);
+ }
+ public void testTypeLiteral() {
+ TypeLiteral x1 = this.ast.newTypeLiteral();
+ x1.setType(this.T1);
+ basicMatch(x1);
+ }
+ /** @deprecated using deprecated code */
+ public void testTypeParameter() {
+ if (this.ast.apiLevel() == AST.JLS2) {
+ return;
+ }
+ TypeParameter x1 = this.ast.newTypeParameter();
+ x1.setName(this.N1);
+ x1.typeBounds().add(this.T1);
+ x1.typeBounds().add(this.T2);
+ basicMatch(x1);
+ }
+ public void testVariableDeclarationFragment() {
+ VariableDeclarationFragment x1 = this.ast.newVariableDeclarationFragment();
+ x1.setName(this.N1);
+ x1.setInitializer(this.E1);
+ basicMatch(x1);
+ }
+ public void testVariableDeclarationExpression() {
+ VariableDeclarationExpression x1 = this.ast.newVariableDeclarationExpression(this.W1);
+ if (this.ast.apiLevel() >= AST.JLS3) {
+ x1.modifiers().add(this.MOD1);
+ x1.modifiers().add(this.MOD2);
+ }
+ x1.setType(this.T1);
+ x1.fragments().add(this.W2);
+ basicMatch(x1);
+ }
+ public void testVariableDeclarationStatement() {
+ VariableDeclarationStatement x1 = this.ast.newVariableDeclarationStatement(this.W1);
+ if (this.ast.apiLevel() >= AST.JLS3) {
+ x1.modifiers().add(this.MOD1);
+ x1.modifiers().add(this.MOD2);
+ }
+ x1.setType(this.T1);
+ x1.fragments().add(this.W2);
+ basicMatch(x1);
+ }
+ public void testWhileStatement() {
+ WhileStatement x1 = this.ast.newWhileStatement();
+ x1.setExpression(this.E1);
+ x1.setBody(this.S1);
+ basicMatch(x1);
+ }
+
+ // annotation-related
+ /** @deprecated using deprecated code */
+ public void testAnnotationTypeDeclaration() {
+ if (this.ast.apiLevel() == AST.JLS2) {
+ return;
+ }
+ AnnotationTypeDeclaration x1 = this.ast.newAnnotationTypeDeclaration();
+ x1.setJavadoc(this.JD1);
+ x1.modifiers().add(this.MOD1);
+ x1.modifiers().add(this.MOD2);
+ x1.setName(this.N1);
+ x1.bodyDeclarations().add(this.FD1);
+ x1.bodyDeclarations().add(this.FD2);
+ basicMatch(x1);
+ }
+
+ /** @deprecated using deprecated code */
+ public void testAnnotationTypeMemberDeclaration() {
+ if (this.ast.apiLevel() == AST.JLS2) {
+ return;
+ }
+ AnnotationTypeMemberDeclaration x1 = this.ast.newAnnotationTypeMemberDeclaration();
+ x1.setJavadoc(this.JD1);
+ x1.modifiers().add(this.MOD1);
+ x1.modifiers().add(this.MOD2);
+ x1.setType(this.T1);
+ x1.setName(this.N1);
+ x1.setDefault(this.E1);
+ basicMatch(x1);
+ }
+
+ /** @deprecated using deprecated code */
+ public void testNormalAnnotation() {
+ if (this.ast.apiLevel() == AST.JLS2) {
+ return;
+ }
+ NormalAnnotation x1 = this.ast.newNormalAnnotation();
+ x1.setTypeName(this.N1);
+ x1.values().add(this.MVP1);
+ x1.values().add(this.MVP2);
+ basicMatch(x1);
+ }
+
+ /** @deprecated using deprecated code */
+ public void testMarkerAnnotation() {
+ if (this.ast.apiLevel() == AST.JLS2) {
+ return;
+ }
+ MarkerAnnotation x1 = this.ast.newMarkerAnnotation();
+ x1.setTypeName(this.N1);
+ basicMatch(x1);
+ }
+
+ /** @deprecated using deprecated code */
+ public void testSingleMemberAnnotation() {
+ if (this.ast.apiLevel() == AST.JLS2) {
+ return;
+ }
+ SingleMemberAnnotation x1 = this.ast.newSingleMemberAnnotation();
+ x1.setTypeName(this.N1);
+ x1.setValue(this.E1);
+ basicMatch(x1);
+ }
+
+}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTModelBridgeTests.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTModelBridgeTests.java
new file mode 100644
index 0000000..e3e82c9
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTModelBridgeTests.java
@@ -0,0 +1,2137 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2008 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.dom;
+
+import java.io.File;
+import java.io.IOException;
+
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.jdt.core.*;
+import org.eclipse.jdt.core.compiler.IProblem;
+import org.eclipse.jdt.core.dom.*;
+import org.eclipse.jdt.core.search.IJavaSearchConstants;
+import org.eclipse.jdt.core.search.IJavaSearchScope;
+import org.eclipse.jdt.core.search.SearchEngine;
+import org.eclipse.jdt.core.tests.model.AbstractJavaSearchTests;
+
+import junit.framework.Test;
+
+/*
+ * Test the bridge between the DOM AST and the Java model.
+ */
+public class ASTModelBridgeTests extends AbstractASTTests {
+
+ ICompilationUnit workingCopy;
+
+ public ASTModelBridgeTests(String name) {
+ super(name);
+ }
+
+ public static Test suite() {
+ return buildModelTestSuite(ASTModelBridgeTests.class);
+ }
+
+ // Use this static initializer to specify subset for tests
+ // All specified tests which do not belong to the class are skipped...
+ static {
+// TESTS_PREFIX = "testBug86380";
+// TESTS_NAMES = new String[] { "testCreateBindings23" };
+// TESTS_NUMBERS = new int[] { 83230 };
+// TESTS_RANGE = new int[] { 83304, -1 };
+ }
+
+ private void assertFindElement(String key, String expectedElement) throws JavaModelException {
+ IJavaElement element = getJavaProject("P").findElement(key, this.workingCopy.getOwner());
+ assertElementEquals(
+ "Unexpected found element",
+ expectedElement,
+ element
+ );
+ }
+
+ /*
+ * Removes the marker comments "*start*" and "*end*" from the given contents,
+ * builds an AST from the resulting source, and returns the AST node that was delimited
+ * by "*start*" and "*end*".
+ */
+ private ASTNode buildAST(String contents) throws JavaModelException {
+ return buildAST(contents, this.workingCopy);
+ }
+
+ /*
+ * Removes the marker comments "*start*" and "*end*" from the given contents,
+ * builds an AST from the resulting source, gets the binding from the AST node that was delimited
+ * by "*start*" and "*end*", and returns the binding key.
+ */
+ private String buildBindingKey(String contents) throws JavaModelException {
+ ASTNode node = buildAST(contents);
+ if (node == null) return null;
+ IBinding binding = resolveBinding(node);
+ if (binding == null) return null;
+ return binding.getKey();
+ }
+
+ private IBinding[] createBindings(String contents, IJavaElement element) throws JavaModelException {
+ this.workingCopy.getBuffer().setContents(contents);
+ this.workingCopy.makeConsistent(null);
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setProject(getJavaProject("P"));
+ IJavaElement[] elements = new IJavaElement[] {element};
+ return parser.createBindings(elements, null);
+ }
+
+ private IBinding[] createBinaryBindings(String contents, IJavaElement element) throws CoreException {
+ createClassFile("/P/lib", "A.class", contents);
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setProject(getJavaProject("P"));
+ IJavaElement[] elements = new IJavaElement[] {element};
+ return parser.createBindings(elements, null);
+ }
+
+ public void setUpSuite() throws Exception {
+ super.setUpSuite();
+ setUpJavaProject();
+ }
+
+ private void setUpJavaProject() throws CoreException, IOException, JavaModelException {
+ IJavaProject project = createJavaProject("P", new String[] {"src"}, new String[] {"JCL15_LIB,JCL15_SRC", "/P/lib"}, "bin", "1.5");
+ project.setOption(JavaCore.COMPILER_PB_UNUSED_LOCAL, JavaCore.IGNORE);
+ project.setOption(JavaCore.COMPILER_PB_UNUSED_PRIVATE_MEMBER, JavaCore.IGNORE);
+ project.setOption(JavaCore.COMPILER_PB_FIELD_HIDING, JavaCore.IGNORE);
+ project.setOption(JavaCore.COMPILER_PB_LOCAL_VARIABLE_HIDING, JavaCore.IGNORE);
+ project.setOption(JavaCore.COMPILER_PB_TYPE_PARAMETER_HIDING, JavaCore.IGNORE);
+ project.setOption(JavaCore.COMPILER_PB_RAW_TYPE_REFERENCE, JavaCore.IGNORE);
+ addLibrary(
+ project,
+ "lib.jar",
+ "libsrc.zip",
+ new String[] {
+ "p/Y.java",
+ "package p;\n" +
+ "public class Y<T> {\n" +
+ " public Y(T t) {\n" +
+ " }\n" +
+ "}",
+ "p/Z.java",
+ "package p;\n" +
+ "public class Z {\n" +
+ " /*start*/class Member {\n" +
+ " }/*end*/\n" +
+ " void foo() {\n" +
+ " new Member() {};\n" +
+ " }\n" +
+ "}",
+ "p/W.java",
+ "package p;\n" +
+ "public class W {\n" +
+ " class Member {\n" +
+ " /*start*/Member(String s) {\n" +
+ " }/*end*/\n" +
+ " }\n" +
+ "}",
+ "p/ABC.java",
+ "package p;\n" +
+ "public class ABC {\n" +
+ "}",
+ "Z.java",
+ "public class Z {\n" +
+ " /*start*/class Member {\n" +
+ " }/*end*/\n" +
+ " void foo() {\n" +
+ " new Member() {};\n" +
+ " }\n" +
+ "}",
+ "p/Q.java",
+ "package p;\n" +
+ "/*start*/@MyAnnot/*end*/\n" +
+ "public class Q {\n" +
+ "}\n" +
+ "@interface MyAnnot {\n" +
+ "}",
+ },
+ "1.5");
+ setUpWorkingCopy();
+ }
+
+ private void setUpWorkingCopy() throws JavaModelException {
+ if (this.workingCopy != null)
+ this.workingCopy.discardWorkingCopy();
+ IProblemRequestor problemRequestor = new IProblemRequestor() {
+ public void acceptProblem(IProblem problem) {}
+ public void beginReporting() {}
+ public void endReporting() {}
+ public boolean isActive() {
+ return true;
+ }
+ };
+ this.workingCopy = getCompilationUnit("/P/src/X.java").getWorkingCopy(
+ newWorkingCopyOwner(problemRequestor),
+ null/*no progress*/);
+ }
+
+ public void tearDownSuite() throws Exception {
+ tearDownJavaProject();
+ super.tearDownSuite();
+ }
+
+ private void tearDownJavaProject() throws JavaModelException, CoreException {
+ if (this.workingCopy != null)
+ this.workingCopy.discardWorkingCopy();
+ deleteProject("P");
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing an annotation is correct.
+ */
+ public void testAnnotation1() throws JavaModelException {
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " /*start*/@MyAnnot/*end*/\n" +
+ " void foo() {\n" +
+ " }\n" +
+ "}\n" +
+ "@interface MyAnnot {\n" +
+ "}"
+ );
+ IBinding binding = ((Annotation) node).resolveAnnotationBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "@MyAnnot [in foo() [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing an annotation is correct.
+ */
+ public void testAnnotation2() throws JavaModelException {
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " /*start*/@MyAnnot/*end*/\n" +
+ " int field;\n" +
+ "}\n" +
+ "@interface MyAnnot {\n" +
+ "}"
+ );
+ IBinding binding = ((Annotation) node).resolveAnnotationBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "@MyAnnot [in field [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing an annotation is correct.
+ */
+ public void testAnnotation3() throws JavaModelException {
+ ASTNode node = buildAST(
+ "/*start*/@MyAnnot/*end*/\n" +
+ "public class X {\n" +
+ "}\n" +
+ "@interface MyAnnot {\n" +
+ "}"
+ );
+ IBinding binding = ((Annotation) node).resolveAnnotationBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "@MyAnnot [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing an annotation is correct.
+ */
+ public void testAnnotation4() throws JavaModelException {
+ ICompilationUnit myAnnot = null;
+ ICompilationUnit packageInfo = null;
+ try {
+ WorkingCopyOwner owner = this.workingCopy.getOwner();
+ myAnnot = getCompilationUnit("/P/src/pkg/MyAnnot.java").getWorkingCopy(owner, null);
+ myAnnot.getBuffer().setContents(
+ "package pkg;\n" +
+ "public @interface MyAnnot {\n" +
+ "}"
+ );
+ myAnnot.makeConsistent(null);
+ packageInfo = getCompilationUnit("/P/src/pkg/package-info.java").getWorkingCopy(owner, null);
+ ASTNode node = buildAST(
+ "/*start*/@MyAnnot/*end*/\n" +
+ "package pkg;",
+ packageInfo
+ );
+ IBinding binding = ((Annotation) node).resolveAnnotationBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "@MyAnnot [in package pkg [in [Working copy] package-info.java [in pkg [in src [in P]]]]]",
+ element
+ );
+ } finally {
+ if (myAnnot != null)
+ myAnnot.discardWorkingCopy();
+ if (packageInfo != null)
+ packageInfo.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing an annotation is correct.
+ */
+ public void testAnnotation5() throws JavaModelException {
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " void foo() {\n" +
+ " /*start*/@MyAnnot/*end*/\n" +
+ " int var1 = 2;\n" +
+ " }\n" +
+ "}\n" +
+ "@interface MyAnnot {\n" +
+ "}"
+ );
+ IBinding binding = ((Annotation) node).resolveAnnotationBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "@MyAnnot [in var1 [in foo() [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing an annotation on an annotation type is correct.
+ * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=249844 )
+ */
+ public void testAnnotation6() throws JavaModelException {
+ ASTNode node = buildAST(
+ "/*start*/@MyAnnot/*end*/\n" +
+ "public @interface X {\n" +
+ "}\n" +
+ "@interface MyAnnot {\n" +
+ "}"
+ );
+ IBinding binding = ((Annotation) node).resolveAnnotationBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "@MyAnnot [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing an annotation on an enum type is correct.
+ * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=249844 )
+ */
+ public void testAnnotation7() throws JavaModelException {
+ ASTNode node = buildAST(
+ "/*start*/@MyAnnot/*end*/\n" +
+ "public enum X {\n" +
+ "}\n" +
+ "@interface MyAnnot {\n" +
+ "}"
+ );
+ IBinding binding = ((Annotation) node).resolveAnnotationBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "@MyAnnot [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing an annotation of a binary member type is correct.
+ */
+ public void testAnnotation8() throws Exception {
+ IClassFile classFile = getClassFile("P", "/P/lib.jar", "p", "Q.class");
+ ASTNode node = buildAST(classFile);
+ IBinding binding = ((Annotation) node).resolveAnnotationBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "@p.MyAnnot [in Q [in Q.class [in p [in lib.jar [in P]]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing an anonymous type is correct.
+ */
+ public void testAnonymousType() throws JavaModelException {
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " Object foo() {\n" +
+ " return new Object() /*start*/{\n" +
+ " }/*end*/;\n" +
+ " }\n" +
+ "}"
+ );
+ IBinding binding = ((AnonymousClassDeclaration) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "<anonymous #1> [in foo() [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]]",
+ element
+ );
+ }
+
+ public void testAnonymousType2() throws JavaModelException {
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " public void foo() {\n" +
+ " new Y(0/*c*/) /*start*/{\n" +
+ " Object field;\n" +
+ " }/*end*/;\n" +
+ " }\n" +
+ "}\n" +
+ "class Y {\n" +
+ " Y(int i) {\n" +
+ " }\n" +
+ "}"
+ );
+ IBinding binding = ((AnonymousClassDeclaration) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "<anonymous #1> [in foo() [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing an array type is correct.
+ */
+ public void testArrayType1() throws JavaModelException {
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " /*start*/Object[]/*end*/ field;\n" +
+ "}"
+ );
+ IBinding binding = ((ArrayType) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "Object [in Object.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing an array type of base type null.
+ * (regression test for bug 100142
+ CCE when calling ITypeBinding#getJavaElement() on char[][]
+ */
+ public void testArrayType2() throws JavaModelException {
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " /*start*/char[][]/*end*/ field;\n" +
+ "}"
+ );
+ IBinding binding = ((ArrayType) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "<null>",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a method coming from a class file is correct.
+ * (regression test for bug 91445 IMethodBinding.getJavaElement() returns an "unopen" IMethod)
+ */
+ public void testBinaryMethod() throws JavaModelException {
+ IClassFile classFile = getClassFile("P", getExternalJCLPathString("1.5"), "java.lang", "Enum.class");
+ String source = classFile.getSource();
+ MarkerInfo markerInfo = new MarkerInfo(source);
+ markerInfo.astStarts = new int[] {source.indexOf("protected Enum")};
+ markerInfo.astEnds = new int[] {source.indexOf('}', markerInfo.astStarts[0]) + 1};
+ ASTNode node = buildAST(markerInfo, classFile);
+ IBinding binding = ((MethodDeclaration) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "Enum(java.lang.String, int) [in Enum [in Enum.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a constructor of a binary member type is correct.
+ * (regression test for bug 119249 codeResolve, search, etc. don't work on constructor of binary inner class)
+ */
+ public void testBinaryMemberTypeConstructor() throws JavaModelException {
+ IClassFile classFile = getClassFile("P", "/P/lib.jar", "p", "W$Member.class");
+ ASTNode node = buildAST(classFile);
+ IBinding binding = ((MethodDeclaration) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "Member(p.W, java.lang.String) [in Member [in W$Member.class [in p [in lib.jar [in P]]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a type coming from a class file is correct.
+ */
+ public void testBinaryType() throws JavaModelException {
+ IClassFile classFile = getClassFile("P", getExternalJCLPathString("1.5"), "java.lang", "String.class");
+ String source = classFile.getSource();
+ MarkerInfo markerInfo = new MarkerInfo(source);
+ markerInfo.astStarts = new int[] {source.indexOf("public")};
+ markerInfo.astEnds = new int[] {source.lastIndexOf('}') + 1};
+ ASTNode node = buildAST(markerInfo, classFile);
+ IBinding binding = ((TypeDeclaration) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "String [in String.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a type coming from a class file is correct
+ * after searching for references to this type.
+ * (regression test for bug 136016 [refactoring] CCE during Use Supertype refactoring)
+ */
+ public void testBinaryType2() throws CoreException {
+ IClassFile classFile = getClassFile("P", "lib.jar", "p", "ABC.class"); // class with no references
+
+ // ensure classfile is open
+ classFile.open(null);
+
+ //search for references to p.ABC after adding references in exactly 1 file
+ try {
+ createFile(
+ "/P/src/Test.java",
+ "import p.ABC;\n" +
+ "public class Test extends ABC {\n" +
+ "}"
+ );
+ IJavaSearchScope scope = SearchEngine.createJavaSearchScope(new IJavaElement[] {getPackageFragmentRoot("/P/src")});
+ search(classFile.getType(), IJavaSearchConstants.REFERENCES, scope, new AbstractJavaSearchTests.JavaSearchResultCollector());
+ } finally {
+ deleteFile("/P/src/Test.java");
+ }
+
+ String source = classFile.getSource();
+ MarkerInfo markerInfo = new MarkerInfo(source);
+ markerInfo.astStarts = new int[] {source.indexOf("public")};
+ markerInfo.astEnds = new int[] {source.lastIndexOf('}') + 1};
+ ASTNode node = buildAST(markerInfo, classFile);
+ IBinding binding = ((TypeDeclaration) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "ABC [in ABC.class [in p [in lib.jar [in P]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a type in a jar is correct after deleting the first project
+ * referencing it.
+ */
+ public void testBinaryType3() throws CoreException, IOException {
+ // force String to be put in the jar cache
+ buildAST(
+ "public class X {\n" +
+ " /*start*/String/*end*/ field;\n" +
+ "}"
+ );
+ try {
+ tearDownJavaProject();
+
+ createJavaProject("P1", new String[] {""}, new String[] {"JCL15_LIB"}, "", "1.5");
+ createFile(
+ "/P1/X.java",
+ "public class X {\n" +
+ " /*start*/String/*end*/ field;\n" +
+ "}"
+ );
+ ASTNode node = buildAST(getCompilationUnit("/P1/X.java"));
+ IBinding binding = ((Type) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "String [in String.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]",
+ element
+ );
+ } finally {
+ deleteProject("P1");
+ setUpJavaProject();
+ }
+ }
+
+ /*
+ * Ensures that the IJavaElement for a binary member type coming from an anoumous class file is correct.
+ * (regression test for bug 100636 [model] Can't find overriden methods of protected nonstatic inner class.)
+ */
+ public void testBinaryMemberTypeFromAnonymousClassFile1() throws JavaModelException {
+ IClassFile classFile = getClassFile("P", "/P/lib.jar", "p", "Z$1.class");
+ ASTNode node = buildAST(classFile);
+ IBinding binding = ((TypeDeclaration) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "Member [in Z$Member.class [in p [in lib.jar [in P]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement for a binary member type coming from an anoumous class file is correct.
+ * (regression test for bug 100636 [model] Can't find overriden methods of protected nonstatic inner class.)
+ */
+ public void testBinaryMemberTypeFromAnonymousClassFile2() throws JavaModelException {
+ IClassFile classFile = getClassFile("P", "/P/lib.jar", "", "Z$1.class");
+ ASTNode node = buildAST(classFile);
+ IBinding binding = ((TypeDeclaration) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "Member [in Z$Member.class [in <default> [in lib.jar [in P]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the correct IBindings are created for a given set of IJavaElement
+ * (test several kinds of elements)
+ */
+ public void testCreateBindings01() throws JavaModelException {
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setResolveBindings(true);
+ parser.setProject(getJavaProject("P"));
+ WorkingCopyOwner owner = new WorkingCopyOwner() {};
+ this.workingCopies = new ICompilationUnit[3];
+ this.workingCopies[0] = getWorkingCopy(
+ "/P/src/X.java",
+ "public class X {\n" +
+ " public void foo(int i, String s) {\n" +
+ " }\n" +
+ "}",
+ owner
+ );
+ this.workingCopies[1] = getWorkingCopy(
+ "/P/src/Y.java",
+ "public class Y extends X {\n" +
+ " void bar() {\n" +
+ " new Y() {};\n" +
+ " }\n" +
+ "}",
+ owner
+ );
+ this.workingCopies[2] = getWorkingCopy(
+ "/P/src/I.java",
+ "public interface I {\n" +
+ " int BAR;\n" +
+ "}",
+ owner
+ );
+ IType typeX = this.workingCopies[0].getType("X");
+ IJavaElement[] elements = new IJavaElement[] {
+ typeX,
+ getClassFile("P", getExternalJCLPathString("1.5"), "java.lang", "Object.class").getType(),
+ typeX.getMethod("foo", new String[] {"I", "QString;"}),
+ this.workingCopies[2].getType("I").getField("BAR"),
+ this.workingCopies[1].getType("Y").getMethod("bar", new String[0]).getType("", 1)
+ };
+ IBinding[] bindings = parser.createBindings(elements, null);
+ assertBindingsEqual(
+ "LX;\n" +
+ "Ljava/lang/Object;\n" +
+ "LX;.foo(ILjava/lang/String;)V\n" +
+ "LI;.BAR)I\n" +
+ "LY$50;",
+ bindings);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=297757
+ */
+ public void testCreateBindings23() throws JavaModelException {
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setProject(getJavaProject("P"));
+ WorkingCopyOwner owner = new WorkingCopyOwner() {};
+ this.workingCopies = new ICompilationUnit[3];
+ this.workingCopies[0] = getWorkingCopy(
+ "/P/src/p/IScriptRunnable.java",
+ "package p;\n" +
+ "public interface IScriptRunnable<V, E extends Exception> {\n" +
+ " public V run(Object cx, Object scope) throws E;\n" +
+ "}",
+ owner
+ );
+ this.workingCopies[1] = getWorkingCopy(
+ "/P/src/p/Environment.java",
+ "package p;\n" +
+ "public interface Environment {\n" +
+ " public <V, E extends Exception> V execute(IScriptRunnable<V, E> code) throws E;\n" +
+ "}",
+ owner
+ );
+ this.workingCopies[2] = getWorkingCopy(
+ "/P/src/X.java",
+ "import p.*;\n" +
+ "public class X {\n" +
+ " p.Environment env;\n" +
+ " private void test() {\n" +
+ " env.execute(new IScriptRunnable<Object, RuntimeException>() {\n" +
+ " public Object run(Object cx, Object scope) throws RuntimeException {\n" +
+ " return null;\n" +
+ " }\n" +
+ " });\n" +
+ " }\n" +
+ "}",
+ owner
+ );
+ IJavaElement[] elements = new IJavaElement[] {
+ this.workingCopies[0].getType("IScriptRunnable"),
+ this.workingCopies[1].getType("Environment"),
+ this.workingCopies[2].getType("X").getMethod("test", new String[0]).getType("", 1)
+ };
+ IBinding[] bindings = parser.createBindings(elements, null);
+ assertBindingsEqual(
+ "Lp/IScriptRunnable<TV;TE;>;\n" +
+ "Lp/Environment;\n" +
+ "LX$90;",
+ bindings);
+ }
+
+ /*
+ * Ensures that the correct IBindings are created for a given set of IJavaElement
+ * (top level type)
+ */
+ public void testCreateBindings02() throws JavaModelException {
+ IBinding[] bindings = createBindings(
+ "public class X {\n" +
+ "}",
+ this.workingCopy.getType("X")
+ );
+ assertBindingsEqual(
+ "LX;",
+ bindings);
+ }
+
+ /*
+ * Ensures that the correct IBindings are created for a given set of IJavaElement
+ * (member type)
+ */
+ public void testCreateBindings03() throws JavaModelException {
+ IBinding[] bindings = createBindings(
+ "public class X {\n" +
+ " public class Member {\n" +
+ " }\n" +
+ "}",
+ this.workingCopy.getType("X").getType("Member")
+ );
+ assertBindingsEqual(
+ "LX$Member;",
+ bindings);
+ }
+
+ /*
+ * Ensures that the correct IBindings are created for a given set of IJavaElement
+ * (anonymous type)
+ */
+ public void testCreateBindings04() throws JavaModelException {
+ IBinding[] bindings = createBindings(
+ "public class X {\n" +
+ " void foo() {\n" +
+ " new X() {\n" +
+ " };\n" +
+ " }\n" +
+ "}",
+ this.workingCopy.getType("X").getMethod("foo", new String[0]).getType("", 1)
+ );
+ assertBindingsEqual(
+ "LX$40;",
+ bindings);
+ }
+
+ /*
+ * Ensures that the correct IBindings are created for a given set of IJavaElement
+ * (local type)
+ */
+ public void testCreateBindings05() throws JavaModelException {
+ IBinding[] bindings = createBindings(
+ "public class X {\n" +
+ " void foo() {\n" +
+ " class Y {\n" +
+ " }\n" +
+ " }\n" +
+ "}",
+ this.workingCopy.getType("X").getMethod("foo", new String[0]).getType("Y", 1)
+ );
+ assertBindingsEqual(
+ "LX$42$Y;",
+ bindings);
+ }
+
+ /*
+ * Ensures that the correct IBindings are created for a given set of IJavaElement
+ * (field)
+ */
+ public void testCreateBindings06() throws JavaModelException {
+ IBinding[] bindings = createBindings(
+ "public class X {\n" +
+ " int field;\n" +
+ "}",
+ this.workingCopy.getType("X").getField("field")
+ );
+ assertBindingsEqual(
+ "LX;.field)I",
+ bindings);
+ }
+
+ /*
+ * Ensures that the correct IBindings are created for a given set of IJavaElement
+ * (method)
+ */
+ public void testCreateBindings07() throws JavaModelException {
+ IBinding[] bindings = createBindings(
+ "public class X {\n" +
+ " void foo() {}\n" +
+ "}",
+ this.workingCopy.getType("X").getMethod("foo", new String[0])
+ );
+ assertBindingsEqual(
+ "LX;.foo()V",
+ bindings);
+ }
+
+ /*
+ * Ensures that the correct IBindings are created for a given set of IJavaElement
+ * (annotation declaration)
+ */
+ public void testCreateBindings08() throws JavaModelException {
+ IBinding[] bindings = createBindings(
+ "@interface X {\n" +
+ "}",
+ this.workingCopy.getType("X")
+ );
+ assertBindingsEqual(
+ "LX;",
+ bindings);
+ }
+
+ /*
+ * Ensures that the correct IBindings are created for a given set of IJavaElement
+ * (enum declaration)
+ */
+ public void testCreateBindings09() throws JavaModelException {
+ IBinding[] bindings = createBindings(
+ "public enum X {\n" +
+ "}",
+ this.workingCopy.getType("X")
+ );
+ assertBindingsEqual(
+ "LX;",
+ bindings);
+ }
+
+ /*
+ * Ensures that the correct IBindings are created for a given set of IJavaElement
+ * (annotation member declaration)
+ */
+ public void testCreateBindings10() throws JavaModelException {
+ IBinding[] bindings = createBindings(
+ "@interface X {\n" +
+ " int foo();\n" +
+ "}",
+ this.workingCopy.getType("X").getMethod("foo", new String[0])
+ );
+ assertBindingsEqual(
+ "LX;.foo()I",
+ bindings);
+ }
+
+ /*
+ * Ensures that the correct IBindings are created for a given set of IJavaElement
+ * (enum constant)
+ */
+ public void testCreateBindings11() throws JavaModelException {
+ IBinding[] bindings = createBindings(
+ "public enum X {\n" +
+ " FOO;\n" +
+ "}",
+ this.workingCopy.getType("X").getField("FOO")
+ );
+ assertBindingsEqual(
+ "LX;.FOO)LX;",
+ bindings);
+ }
+
+ /*
+ * Ensures that the correct IBindings are created for a given set of IJavaElement
+ * (import)
+ */
+ public void testCreateBindings12() throws JavaModelException {
+ IBinding[] bindings = createBindings(
+ "import java.io.*;\n" +
+ "public class X implements Serializable {\n" +
+ " static final long serialVersionUID = 0;\n" +
+ "}",
+ this.workingCopy.getImport("java.io.*")
+ );
+ assertBindingsEqual(
+ "java/io",
+ bindings);
+ }
+
+ /*
+ * Ensures that the correct IBindings are created for a given set of IJavaElement
+ * (import)
+ */
+ public void testCreateBindings13() throws JavaModelException {
+ IBinding[] bindings = createBindings(
+ "import java.io.Serializable;\n" +
+ "public class X implements Serializable {\n" +
+ " static final long serialVersionUID = 0;\n" +
+ "}",
+ this.workingCopy.getImport("java.io.Serializable")
+ );
+ assertBindingsEqual(
+ "Ljava/io/Serializable;",
+ bindings);
+ }
+
+ /*
+ * Ensures that the correct IBindings are created for a given set of IJavaElement
+ * (type parameter)
+ */
+ public void testCreateBindings14() throws JavaModelException {
+ IBinding[] bindings = createBindings(
+ "public class X<T> {\n" +
+ "}",
+ this.workingCopy.getType("X").getTypeParameter("T")
+ );
+ assertBindingsEqual(
+ "LX;:TT;",
+ bindings);
+ }
+
+ /*
+ * Ensures that the correct IBindings are created for a given set of IJavaElement
+ * (binary type)
+ */
+ public void testCreateBindings15() throws CoreException {
+ IBinding[] bindings = createBinaryBindings(
+ "public class A {\n" +
+ "}",
+ getClassFile("/P/lib/A.class").getType()
+ );
+ assertBindingsEqual(
+ "LA;",
+ bindings);
+ }
+
+ /*
+ * Ensures that the correct IBindings are created for a given set of IJavaElement
+ * (binary field)
+ */
+ public void testCreateBindings16() throws CoreException {
+ IBinding[] bindings = createBinaryBindings(
+ "public class A {\n" +
+ " int field;\n" +
+ "}",
+ getClassFile("/P/lib/A.class").getType().getField("field")
+ );
+ assertBindingsEqual(
+ "LA;.field)I",
+ bindings);
+ }
+
+ /*
+ * Ensures that the correct IBindings are created for a given set of IJavaElement
+ * (binary method)
+ */
+ public void testCreateBindings17() throws CoreException {
+ IBinding[] bindings = createBinaryBindings(
+ "public class A {\n" +
+ " int foo(String s, boolean b) {\n" +
+ " return -1;\n" +
+ " }\n" +
+ "}",
+ getClassFile("/P/lib/A.class").getType().getMethod("foo", new String[] {"Ljava.lang.String;", "Z"})
+ );
+ assertBindingsEqual(
+ "LA;.foo(Ljava/lang/String;Z)I",
+ bindings);
+ }
+
+ /*
+ * Ensures that the correct IBindings are created for a given set of IJavaElement
+ * (binary method)
+ * (regression test for bug 122650 ASTParser.createBindings(IJavaElement[]) returns wrong element)
+ */
+ public void testCreateBindings18() throws CoreException {
+ IBinding[] bindings = createBinaryBindings(
+ "public class A {\n" +
+ " <E> void foo(E e) {\n" +
+ " }\n" +
+ "}",
+ getClassFile("/P/lib/A.class").getType().getMethod("foo", new String[] {"TE;"})
+ );
+ assertBindingsEqual(
+ "LA;.foo<E:Ljava/lang/Object;>(TE;)V",
+ bindings);
+ }
+
+ /*
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=160637
+ */
+ public void testCreateBindings19() throws CoreException {
+ IBinding[] bindings = createBinaryBindings(
+ "public class A {\n" +
+ " String foo(String s) {\n" +
+ " return null;\n" +
+ " }\n" +
+ "}",
+ getClassFile("/P/lib/A.class").getType().getMethod("foo", new String[] {"Ljava.lang.String;"})
+ );
+ assertBindingsEqual(
+ "LA;.foo(Ljava/lang/String;)Ljava/lang/String;",
+ bindings);
+ }
+
+ /*
+ * Ensures that the correct IBinding is created for an IField starting with a 'L'
+ * (regression test for 205860 ASTParser.createBindings() returns [null])
+ */
+ public void testCreateBindings20() throws CoreException {
+ IField field = getClassFile("/P/lib/A.class").getType().getField("LINE");
+ IBinding[] bindings = createBinaryBindings(
+ "public class A {\n" +
+ " static int LINE = 0;\n" +
+ "}",
+ field
+ );
+ assertBindingsEqual(
+ "LA;.LINE)I",
+ bindings);
+ }
+
+ /*
+ * Ensures that the correct IBinding is created for an IField starting with a 'T'
+ * (regression test for 205860 ASTParser.createBindings() returns [null])
+ */
+ public void testCreateBindings21() throws CoreException {
+ IField field = getClassFile("/P/lib/A.class").getType().getField("THREE");
+ IBinding[] bindings = createBinaryBindings(
+ "public class A {\n" +
+ " static int THREE = 0;\n" +
+ "}",
+ field
+ );
+ assertBindingsEqual(
+ "LA;.THREE)I",
+ bindings);
+ }
+
+ /*
+ * Ensures that the correct IBindings are created for a given set of IJavaElement
+ * (annotation)
+ */
+ public void testCreateBindings22() throws JavaModelException {
+ IBinding[] bindings = createBindings(
+ "@MyAnnot\n" +
+ "public class X {\n" +
+ "}\n" +
+ "@interface MyAnnot {\n" +
+ "}",
+ this.workingCopy.getType("X").getAnnotation("MyAnnot")
+ );
+ assertBindingsEqual(
+ "LX;@LX~MyAnnot;",
+ bindings);
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a field is correct.
+ */
+ public void testField1() throws JavaModelException {
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " Object /*start*/field/*end*/;\n" +
+ "}"
+ );
+ IBinding binding = ((VariableDeclaration) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "field [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a field is correct.
+ */
+ public void testField2() throws JavaModelException {
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " Object foo() {\n" +
+ " return new Object() {\n" +
+ " Object /*start*/field/*end*/;\n" +
+ " };\n" +
+ " }\n" +
+ "}"
+ );
+ IBinding binding = ((VariableDeclaration) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "field [in <anonymous #1> [in foo() [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that an IType can be found using its binding key.
+ */
+ public void testFindElement01() throws JavaModelException {
+ String bindingKey = buildBindingKey(
+ "/*start*/public class X {\n" +
+ "}/*end*/"
+ );
+ assertFindElement(
+ bindingKey,
+ "X [in [Working copy] X.java [in <default> [in src [in P]]]]"
+ );
+ }
+
+ /*
+ * Ensures that an IMethod can be found using its binding key.
+ */
+ public void testFindElement02() throws JavaModelException {
+ String bindingKey = buildBindingKey(
+ "public class X {\n" +
+ " /*start*/void foo() {\n" +
+ " }/*end*/\n" +
+ "}"
+ );
+ assertFindElement(
+ bindingKey,
+ "foo() [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]"
+ );
+ }
+
+ /*
+ * Ensures that an IField can be found using its binding key.
+ */
+ public void testFindElement03() throws JavaModelException {
+ String bindingKey = buildBindingKey(
+ "public class X {\n" +
+ " int /*start*/field/*end*/;\n" +
+ "}"
+ );
+ assertFindElement(
+ bindingKey,
+ "field [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]"
+ );
+ }
+
+ /*
+ * Ensures that a member IType can be found using its binding key.
+ */
+ public void testFindElement04() throws JavaModelException {
+ String bindingKey = buildBindingKey(
+ "public class X {\n" +
+ " /*start*/class Member {\n" +
+ " }/*end*/\n" +
+ "}"
+ );
+ assertFindElement(
+ bindingKey,
+ "Member [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]"
+ );
+ }
+
+ /*
+ * Ensures that a local IType can be found using its binding key.
+ */
+ public void testFindElement05() throws JavaModelException {
+ String bindingKey = buildBindingKey(
+ "public class X {\n" +
+ " void foo() {\n" +
+ " /*start*/class Local {\n" +
+ " }/*end*/\n" +
+ " }\n" +
+ "}"
+ );
+ assertFindElement(
+ bindingKey,
+ "Local [in foo() [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]]"
+ );
+ }
+
+ /*
+ * Ensures that an anonymous IType can be found using its binding key.
+ */
+ public void testFindElement06() throws JavaModelException {
+ String bindingKey = buildBindingKey(
+ "public class X {\n" +
+ " void foo() {\n" +
+ " new X() /*start*/{\n" +
+ " }/*end*/;\n" +
+ " }\n" +
+ "}"
+ );
+ assertFindElement(
+ bindingKey,
+ "<anonymous #1> [in foo() [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]]"
+ );
+ }
+
+ /*
+ * Ensures that a secondary IType can be found using its binding key.
+ */
+ public void testFindElement07() throws JavaModelException {
+ String bindingKey = buildBindingKey(
+ "public class X {\n" +
+ "}\n" +
+ "/*start*/class Secondary {\n" +
+ "}/*end*/"
+ );
+ assertFindElement(
+ bindingKey,
+ "Secondary [in [Working copy] X.java [in <default> [in src [in P]]]]"
+ );
+ }
+
+ /*
+ * Ensures that an IAnnotation can be found using its binding key.
+ */
+ public void testFindElement08() throws JavaModelException {
+ String bindingKey = buildBindingKey(
+ "/*start*/@MyAnnot/*end*/\n" +
+ "public class X {\n" +
+ "}\n" +
+ "@interface MyAnnot {\n" +
+ "}"
+ );
+ assertFindElement(
+ bindingKey,
+ "@MyAnnot [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]"
+ );
+ }
+
+ /*
+ * Ensures that an IPackageFragment can be found using its binding key.
+ */
+ public void testFindElement09() throws JavaModelException {
+ String bindingKey = buildBindingKey(
+ "public class X {\n" +
+ " /*start*/java.lang/*end*/.String field;\n" +
+ "}"
+ );
+ assertFindElement(
+ bindingKey,
+ "java.lang [in "+ getExternalJCLPathString("1.5") + "]"
+ );
+ }
+
+ /*
+ * Ensures that an ITypeParameter can be found using its binding key.
+ */
+ public void testFindElement10() throws JavaModelException {
+ String bindingKey = buildBindingKey(
+ "public class X</*start*/T/*end*/> {\n" +
+ "}"
+ );
+ assertFindElement(
+ bindingKey,
+ "<T> [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]"
+ );
+ }
+
+ /*
+ * Ensures that a binary top level IType can be found using its binding key.
+ */
+ public void testFindElement11() throws JavaModelException {
+ String bindingKey = getClassFile("/P/lib.jar/p/Y.class").getType().getKey();
+ assertFindElement(
+ bindingKey,
+ "Y [in Y.class [in p [in lib.jar [in P]]]]"
+ );
+ }
+
+ /*
+ * Ensures that a binary member IType can be found using its binding key.
+ */
+ public void testFindElement12() throws JavaModelException {
+ String bindingKey = getClassFile("/P/lib.jar/p/Z$Member.class").getType().getKey();
+ assertFindElement(
+ bindingKey,
+ "Member [in Z$Member.class [in p [in lib.jar [in P]]]]"
+ );
+ }
+
+ /*
+ * Ensures that a binary anonymous IType can be found using its binding key.
+ */
+ public void testFindElement13() throws JavaModelException {
+ String bindingKey = getClassFile("/P/lib.jar/p/Z$1.class").getType().getKey();
+ assertFindElement(
+ bindingKey,
+ "Z$1.class [in p [in lib.jar [in P]]]"
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a local type is correct.
+ */
+ public void testLocalType() throws JavaModelException {
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " void foo() {\n" +
+ " /*start*/class Y {\n" +
+ " }/*end*/\n" +
+ " }\n" +
+ "}"
+ );
+ IBinding binding = ((TypeDeclarationStatement) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "Y [in foo() [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a local type
+ * and coming from a binding key resolution is correct.
+ */
+ public void testLocalType2() throws CoreException {
+ String filePath = "/P/src/Z.java";
+ try {
+ String contents =
+ "public class Z {\n" +
+ " void foo() {\n" +
+ " /*start*/class Local {\n" +
+ " }/*end*/\n" +
+ " }\n" +
+ "}";
+ createFile(filePath, contents);
+
+ // Get the binding key
+ ASTNode node = buildAST(contents, getCompilationUnit(filePath));
+ IBinding binding = ((TypeDeclarationStatement) node).resolveBinding();
+ String bindingKey = binding.getKey();
+
+ // Resolve the binding key
+ BindingRequestor requestor = new BindingRequestor();
+ String[] bindingKeys = new String[] {bindingKey};
+ resolveASTs(
+ new ICompilationUnit[] {},
+ bindingKeys,
+ requestor,
+ getJavaProject("P"),
+ this.workingCopy.getOwner()
+ );
+ IBinding[] bindings = requestor.getBindings(bindingKeys);
+
+ // Ensure the Java element is correct
+ IJavaElement element = bindings[0].getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "Local [in foo() [in Z [in Z.java [in <default> [in src [in P]]]]]]",
+ element
+ );
+ } finally {
+ deleteFile(filePath);
+ }
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a local variable is correct.
+ * (regression test for bug 79610 IVariableBinding#getJavaElement() returns null for local variables)
+ */
+ public void testLocalVariable1() throws JavaModelException {
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " void foo() {\n" +
+ " int /*start*/local/*end*/;\n" +
+ " }\n" +
+ "}"
+ );
+ IBinding binding = ((VariableDeclaration) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ IJavaElement expected = getLocalVariable(this.workingCopy, "local", "local");
+ assertEquals(
+ "Unexpected Java element",
+ expected,
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a local variable is correct.
+ * (regression test for bug 79610 IVariableBinding#getJavaElement() returns null for local variables)
+ */
+ public void testLocalVariable2() throws JavaModelException {
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " void foo() {\n" +
+ " Object first, /*start*/second/*end*/, third;\n" +
+ " }\n" +
+ "}"
+ );
+ IBinding binding = ((VariableDeclaration) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ IJavaElement expected = getLocalVariable(this.workingCopy, "second", "second");
+ assertEquals(
+ "Unexpected Java element",
+ expected,
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a local variable is correct.
+ * (regression test for bug 80021 [1.5] CCE in VariableBinding.getJavaElement())
+ */
+ public void testLocalVariable3() throws JavaModelException {
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " void foo(/*start*/int arg/*end*/) {\n" +
+ " }\n" +
+ "}"
+ );
+ IBinding binding = ((VariableDeclaration) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ IJavaElement expected = getLocalVariable(this.workingCopy, "arg", "arg");
+ assertEquals(
+ "Unexpected Java element",
+ expected,
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a local variable in an anonymous type
+ * in a discarded working copy is null.
+ * (regression test for bug https://bugs.eclipse.org/bugs/show_bug.cgi?id=212096 )
+ */
+ public void testLocalVariable4() throws JavaModelException {
+ try {
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " void foo() {\n" +
+ " new Object() {\n" +
+ " void bar() {\n" +
+ " int /*start*/local/*end*/;\n" +
+ " }\n" +
+ " };\n" +
+ " }\n" +
+ "}"
+ );
+ IBinding binding = ((VariableDeclaration) node).resolveBinding();
+ this.workingCopy.discardWorkingCopy();
+ IJavaElement element = binding.getJavaElement();
+ assertEquals(
+ "Unexpected Java element",
+ null,
+ element
+ );
+ } finally {
+ setUpWorkingCopy();
+ }
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a local variable in an initializer is correct.
+ * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=217287 )
+ */
+ public void testLocalVariable5() throws JavaModelException {
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " {\n" +
+ " int /*start*/local/*end*/;\n" +
+ " }\n" +
+ "}"
+ );
+ IBinding binding = ((VariableDeclaration) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ IJavaElement expected = getLocalVariable(this.workingCopy, "local", "local");
+ assertEquals(
+ "Unexpected Java element",
+ expected,
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a member type is correct.
+ */
+ public void testMemberType() throws JavaModelException {
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " /*start*/class Y {\n" +
+ " }/*end*/\n" +
+ "}"
+ );
+ IBinding binding = ((TypeDeclaration) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementEquals(
+ "Unexpected Java element",
+ "Y [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]",
+ element
+ );
+ assertTrue("Element should exist", element.exists());
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a method is correct.
+ */
+ public void testMethod01() throws JavaModelException {
+ ASTNode node = buildAST(
+ "public class X<K, V> {\n" +
+ " /*start*/void foo(int i, Object o, java.lang.String s, Class[] c, X<K, V> x) {\n" +
+ " }/*end*/\n" +
+ "}"
+ );
+ IBinding binding = ((MethodDeclaration) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "foo(int, Object, java.lang.String, Class[], X<K,V>) [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a method is correct.
+ */
+ public void testMethod02() throws JavaModelException {
+ ASTNode node = buildAST(
+ "public class X<K, V> {\n" +
+ " /*start*/void foo() {\n" +
+ " }/*end*/\n" +
+ "}"
+ );
+ IBinding binding = ((MethodDeclaration) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "foo() [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a method is correct.
+ * (regression test for bug 78757 MethodBinding.getJavaElement() returns null)
+ */
+ public void testMethod03() throws JavaModelException {
+ ICompilationUnit otherWorkingCopy = null;
+ try {
+ otherWorkingCopy = getWorkingCopy(
+ "/P/src/Y.java",
+ "public class Y {\n" +
+ " void foo(int i, String[] args, java.lang.Class clazz) {}\n" +
+ "}",
+ this.workingCopy.getOwner()
+ );
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " void bar() {\n" +
+ " Y y = new Y();\n" +
+ " /*start*/y.foo(1, new String[0], getClass())/*end*/;\n" +
+ " }\n" +
+ "}"
+ );
+ IBinding binding = ((MethodInvocation) node).resolveMethodBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "foo(int, String[], java.lang.Class) [in Y [in [Working copy] Y.java [in <default> [in src [in P]]]]]",
+ element
+ );
+ } finally {
+ if (otherWorkingCopy != null)
+ otherWorkingCopy.discardWorkingCopy();
+ }
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a method is correct.
+ * (regression test for bug 81258 IMethodBinding#getJavaElement() is null with inferred method parameterization)
+ */
+ public void testMethod04() throws JavaModelException {
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " void foo() {\n" +
+ " /*start*/bar(new B<Object>())/*end*/;\n" +
+ " }\n" +
+ " <T extends Object> void bar(A<? extends T> arg) {\n" +
+ " }\n" +
+ "}\n" +
+ "class A<T> {\n" +
+ "}\n" +
+ "class B<T> extends A<T> { \n" +
+ "}"
+ );
+ IBinding binding = ((MethodInvocation) node).resolveMethodBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "bar(A<? extends T>) [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a parameterized method is correct.
+ * (regression test for bug 82382 IMethodBinding#getJavaElement() for method m(T t) in parameterized type Gen<T> is null)
+ */
+ public void testMethod05() throws JavaModelException {
+ ASTNode node = buildAST(
+ "public class X<T> {\n" +
+ " void m(T t) { }\n" +
+ "}\n" +
+ "\n" +
+ "class Y {\n" +
+ " {\n" +
+ " /*start*/new X<String>().m(\"s\")/*end*/;\n" +
+ " }\n" +
+ "}"
+ );
+ IBinding binding = ((MethodInvocation) node).resolveMethodBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "m(T) [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a method inside an annotation is correct.
+ * (regression test for bug 83300 [1.5] ClassCastException in #getJavaElement() on binding of annotation element)
+ */
+ public void testMethod06() throws JavaModelException {
+ ASTNode node = buildAST(
+ "@X(/*start*/value/*end*/=\"Hello\", count=-1)\n" +
+ "@interface X {\n" +
+ " String value();\n" +
+ " int count();\n" +
+ "}"
+ );
+ IBinding binding = ((SimpleName) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "value() [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a method with array parameters is correct.
+ * (regression test for bug 88769 IMethodBinding#getJavaElement() drops extra array dimensions and varargs
+ */
+ public void testMethod07() throws JavaModelException {
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " /*start*/public int[] bar(int a[]) {\n" +
+ " return a;\n" +
+ " }/*end*/\n" +
+ "}"
+ );
+ IBinding binding = ((MethodDeclaration) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "bar(int[]) [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a method with array parameters is correct.
+ * (regression test for bug 88769 IMethodBinding#getJavaElement() drops extra array dimensions and varargs
+ */
+ public void testMethod08() throws JavaModelException {
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " /*start*/public Object[] bar2(Object[] o[][]) [][] {\n" +
+ " return o;\n" +
+ " }/*end*/\n" +
+ "}"
+ );
+ IBinding binding = ((MethodDeclaration) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "bar2(Object[][][]) [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a method with varargs parameters is correct.
+ * (regression test for bug 88769 IMethodBinding#getJavaElement() drops extra array dimensions and varargs
+ */
+ public void testMethod09() throws JavaModelException {
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " /*start*/public void bar3(Object... objs) {\n" +
+ " }/*end*/\n" +
+ "}"
+ );
+ IBinding binding = ((MethodDeclaration) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "bar3(Object[]) [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that getting the IJavaElement of an IBinding representing a method in an anonymous type
+ * doesn't throw a ClassCastException if there is a syntax error.
+ * (regression test for bug 149853 CCE in IMethodBinding#getJavaElement() for recovered anonymous type)
+ */
+ public void testMethod10() throws CoreException {
+ try {
+ // use a compilation unit instead of a working copy to use the ASTParser instead of reconcile
+ createFile(
+ "/P/src/Test.java",
+ "public class X {\n" +
+ " void test() {\n" +
+ " new Object() {\n" +
+ " /*start*/public void yes() {\n" +
+ " System.out.println(\"hello world\");\n" +
+ " }/*end*/\n" +
+ " } // missing semicolon;\n" +
+ " }\n" +
+ "}"
+ );
+ ICompilationUnit cu = getCompilationUnit("/P/src/Test.java");
+
+ ASTNode node = buildAST(null/*use existing contents*/, cu, false/*don't report errors*/, true/*statement recovery*/, false);
+ IBinding binding = ((MethodDeclaration) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "yes() [in <anonymous #1> [in test() [in X [in Test.java [in <default> [in src [in P]]]]]]]",
+ element
+ );
+ } finally {
+ deleteFile("/P/src/Test.java");
+ }
+ }
+
+ /*
+ * Ensures that no ClassCastException is thrown if the method is in an anonymous
+ * which is inside the initializer of another anonymous.
+ * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=208013)
+ */
+ public void testMethod11() throws JavaModelException {
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " public void foo() {\n" +
+ " new Object() {\n" +
+ " Object o;\n" +
+ " {\n"+
+ " new Object() {\n" +
+ " /*start*/void bar() {\n" +
+ " }/*end*/\n" +
+ " };\n" +
+ " }\n" +
+ " };\n"+
+ " }\n" +
+ "}"
+ );
+ IBinding binding = ((MethodDeclaration) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "bar() [in <anonymous #1> [in <initializer #1> [in <anonymous #1> [in foo() [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a method is correct.
+ * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=249567 )
+ */
+ public void testMethod12() throws Exception {
+ try {
+ createFolder("/P/src/p1");
+ createFile(
+ "/P/src/p1/X249567.java",
+ "package p1;\n" +
+ "public class X249567 {}"
+ );
+ createFolder("/P/src/p2");
+ createFile(
+ "/P/src/p2/X249567.java",
+ "package p2;\n" +
+ "public class X249567 {}"
+ );
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " void foo(p1.X249567 x) {\n" +
+ " }\n" +
+ " /*start*/void foo(p2.X249567 x) {\n" +
+ " }/*end*/\n" +
+ "}"
+ );
+ IBinding binding = ((MethodDeclaration) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "foo(p2.X249567) [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]",
+ element
+ );
+ } finally {
+ deleteFolder("/P/src/p1");
+ deleteFolder("/P/src/p2");
+ }
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a method is correct.
+ * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=249567 )
+ */
+ public void testMethod13() throws Exception {
+ try {
+ createFolder("/P/src/p1");
+ createFile(
+ "/P/src/p1/X249567.java",
+ "package p1;\n" +
+ "public class X249567 {\n" +
+ " public class Member {}\n" +
+ "}"
+ );
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " /*start*/void foo(p1.X249567.Member x) {\n" +
+ " }/*end*/\n" +
+ "}"
+ );
+ IBinding binding = ((MethodDeclaration) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "foo(p1.X249567.Member) [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]",
+ element
+ );
+ } finally {
+ deleteFolder("/P/src/p1");
+ }
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a method is correct.
+ * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=249567 )
+ */
+ public void testMethod14() throws Exception {
+ try {
+ createFolder("/P/src/p1");
+ createFile(
+ "/P/src/p1/X249567.java",
+ "package p1;\n" +
+ "public class X249567 {\n" +
+ " public class Member<T> {}\n" +
+ "}"
+ );
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " /*start*/void foo(p1.X249567.Member<java.lang.String> x) {\n" +
+ " }/*end*/\n" +
+ "}"
+ );
+ IBinding binding = ((MethodDeclaration) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "foo(p1.X249567.Member<java.lang.String>) [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]",
+ element
+ );
+ } finally {
+ deleteFolder("/P/src/p1");
+ }
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a package is correct.
+ */
+ public void testPackage1() throws CoreException {
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " /*start*/java.lang/*end*/.String field;\n" +
+ "}"
+ );
+ IBinding binding = ((QualifiedName) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "java.lang [in "+ getExternalJCLPathString("1.5") + "]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a package is correct
+ * (case of default package)
+ */
+ public void testPackage2() throws CoreException {
+ ASTNode node = buildAST(
+ "/*start*/public class X {\n" +
+ "}/*end*/"
+ );
+ ITypeBinding typeBinding = ((TypeDeclaration) node).resolveBinding();
+ IPackageBinding binding = typeBinding.getPackage();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "<default> [in src [in P]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a parameterized binary type is correct.
+ * (regression test for bug 78087 [dom] TypeBinding#getJavaElement() throws IllegalArgumentException for parameterized or raw reference to binary type)
+ */
+ public void testParameterizedBinaryType() throws CoreException {
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " /*start*/Comparable<String>/*end*/ field;\n" +
+ "}"
+ );
+ IBinding binding = ((Type) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "Comparable [in Comparable.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a parameterized binary method is correct.
+ * (regression test for bug 88892 [1.5] IMethodBinding#getJavaElement() returns nonexistent IMethods (wrong parameter types))
+ */
+ public void testParameterizedBinaryMethod() throws CoreException {
+ ASTNode node = buildAST(
+ "public class X extends p.Y<String> {\n" +
+ " public X(String s) {\n" +
+ " /*start*/super(s);/*end*/\n" +
+ " }\n" +
+ "}"
+ );
+ IBinding binding = ((SuperConstructorInvocation) node).resolveConstructorBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "Y(T) [in Y [in Y.class [in p [in lib.jar [in P]]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a raw binary type is correct.
+ * (regression test for bug 78087 [dom] TypeBinding#getJavaElement() throws IllegalArgumentException for parameterized or raw reference to binary type)
+ */
+ public void testRawBinaryType() throws CoreException {
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " /*start*/Comparable/*end*/ field;\n" +
+ "}"
+ );
+ IBinding binding = ((Type) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "Comparable [in Comparable.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a recovered type is correct.
+ * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=232037 )
+ */
+ public void testRecoveredTypeBinding1() throws Exception {
+ try {
+ IJavaProject p = createJavaProject("P15", new String[] {""}, new String[] {"JCL15_LIB", "/P15/util.jar"}, "", "1.5");
+ org.eclipse.jdt.core.tests.util.Util.createJar(new String[] {
+ "java/util/List.java",
+ "package java.util;\n" +
+ "public class List<T> {\n" +
+ "}"
+ }, p.getProject().getLocation() + File.separator + "util.jar",
+ "1.5");
+ p.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
+ createFile("/P15/X.java", "");
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " void m() {\n" +
+ " /*start*/new java.util.List<URL>()/*end*/;\n" +
+ " }\n" +
+ "}",
+ getCompilationUnit("/P15/X.java"),
+ false/*don't report errors*/,
+ true/*statement recovery*/,
+ true/*binding recovery*/
+ );
+ IBinding binding = ((ClassInstanceCreation) node).resolveTypeBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertEquals(element, element); // equals should not throw an NPE
+ } finally {
+ deleteProject("P15");
+ }
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a recovered type is correct.
+ * (regression test for https://bugs.eclipse.org/bugs/show_bug.cgi?id=232037 )
+ */
+ public void testRecoveredTypeBinding2() throws Exception {
+ try {
+ createJavaProject("P15", new String[] {""}, new String[] {"JCL15_LIB"}, "", "1.5");
+ createFile("/P15/X.java", "");
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " void m() {\n" +
+ " new /*start*/java.util.List<URL>/*end*/();\n" +
+ " }\n" +
+ "}",
+ getCompilationUnit("/P15/X.java"),
+ false/*don't report errors*/,
+ true/*statement recovery*/,
+ true/*binding recovery*/
+ );
+ IBinding binding = ((ParameterizedType) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertEquals(element, element); // equals should not throw an NPE
+ } finally {
+ deleteProject("P15");
+ }
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a top level type is correct.
+ */
+ public void testTopLevelType1() throws JavaModelException {
+ ASTNode node = buildAST(
+ "/*start*/public class X {\n" +
+ "}/*end*/"
+ );
+ IBinding binding = ((TypeDeclaration) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "X [in [Working copy] X.java [in <default> [in src [in P]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a top level type is correct
+ * (the top level type being in another compilation unit)
+ */
+ public void testTopLevelType2() throws CoreException {
+ try {
+ createFile(
+ "/P/src/Y.java",
+ "public class Y {\n" +
+ "}"
+ );
+ ASTNode node = buildAST(
+ "public class X extends /*start*/Y/*end*/ {\n" +
+ "}"
+ );
+ IBinding binding = ((Type) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "Y [in Y.java [in <default> [in src [in P]]]]",
+ element
+ );
+ } finally {
+ deleteFile("/P/src/Y.java");
+ }
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a top level type is correct
+ * (the top level type being in a jar)
+ */
+ public void testTopLevelType3() throws CoreException {
+ ASTNode node = buildAST(
+ "public class X {\n" +
+ " /*start*/String/*end*/ field;\n" +
+ "}"
+ );
+ IBinding binding = ((Type) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "String [in String.class [in java.lang [in "+ getExternalJCLPathString("1.5") + "]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a parameter type is correct.
+ * (regression test for bug 78930 ITypeBinding#getJavaElement() throws NPE for type variable)
+ */
+ public void testTypeParameter() throws JavaModelException {
+ ASTNode node = buildAST(
+ "public class X</*start*/T/*end*/> {\n" +
+ "}"
+ );
+ IBinding binding = ((TypeParameter) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "<T> [in X [in [Working copy] X.java [in <default> [in src [in P]]]]]",
+ element
+ );
+ }
+
+ /*
+ * Ensures that the IJavaElement of an IBinding representing a wild card is correct.
+ * (regression test for bug 81417 [dom] getJavaElement() throws a NPE for WildcardBinding)
+ */
+ public void testWildCard() throws JavaModelException {
+ ASTNode node = buildAST(
+ "public class X<T> {\n" +
+ " X</*start*/? extends Exception/*end*/> field;\n" +
+ "}"
+ );
+ IBinding binding = ((WildcardType) node).resolveBinding();
+ IJavaElement element = binding.getJavaElement();
+ assertElementExists(
+ "Unexpected Java element",
+ "<null>",
+ element
+ );
+ }
+
+}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTNodeFinderTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTNodeFinderTest.java
new file mode 100644
index 0000000..90e6d3c
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTNodeFinderTest.java
@@ -0,0 +1,242 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2009 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.dom;
+
+import junit.framework.Test;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.SourceRange;
+import org.eclipse.jdt.core.compiler.CharOperation;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.NodeFinder;
+
+public class ASTNodeFinderTest extends ConverterTestSetup {
+
+ ICompilationUnit workingCopy;
+
+ public void setUpSuite() throws Exception {
+ super.setUpSuite();
+ this.ast = AST.newAST(AST.JLS3);
+ }
+
+ public ASTNodeFinderTest(String name) {
+ super(name);
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ if (this.workingCopy != null) {
+ this.workingCopy.discardWorkingCopy();
+ this.workingCopy = null;
+ }
+ }
+
+ static {
+// TESTS_NUMBERS = new int[] { 9 };
+ }
+
+ public static Test suite() {
+ return buildModelTestSuite(ASTNodeFinderTest.class);
+ }
+
+ public void test0001() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/NodeFinder/src/test0001/Test.java", false);
+ String contents =
+ "package test0001;\n" +
+ "import java.util.*;\n" +
+ "public class Test {\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(\"Hello\" + \" world\");\n" +
+ " }\n" +
+ "}";
+ ASTNode result = buildAST(
+ contents,
+ this.workingCopy);
+ char[] source = contents.toCharArray();
+ char[] className = "Test".toCharArray();
+ int index = CharOperation.indexOf(className, source, true);
+ int index2 = CharOperation.indexOf('{', source, index + 1, source.length);
+ ASTNode node = NodeFinder.perform(result, index, index2 - index + 1);
+ NodeFinder nodeFinder = new NodeFinder(result, index, index2 - index + 1);
+ assertTrue("Different node", nodeFinder.getCoveringNode() == node);
+ }
+ public void test0002() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/NodeFinder/src/test0001/Test.java", false);
+ String contents =
+ "package test0001;\n" +
+ "import java.util.*;\n" +
+ "public class Test {\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(\"Hello\" + \" world\");\n" +
+ " }\n" +
+ "}";
+ ASTNode result = buildAST(
+ contents,
+ this.workingCopy);
+ char[] source = contents.toCharArray();
+ char[] className = "Test".toCharArray();
+ int index = CharOperation.indexOf(className, source, true);
+ ASTNode node = NodeFinder.perform(result, index, className.length);
+ NodeFinder nodeFinder = new NodeFinder(result, index, className.length);
+ assertTrue("Different node", nodeFinder.getCoveredNode() == node);
+ }
+ public void test0003() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/NodeFinder/src/test0001/Test.java", false);
+ String contents =
+ "package test0001;\n" +
+ "import java.util.*;\n" +
+ "public class Test {\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(\"Hello\" + \" world\");\n" +
+ " }\n" +
+ "}";
+ ASTNode result = buildAST(
+ contents,
+ this.workingCopy);
+ char[] source = contents.toCharArray();
+ char[] className = "Test".toCharArray();
+ int index = CharOperation.indexOf(className, source, true);
+ int index2 = CharOperation.indexOf('{', source, index + 1, source.length);
+ SourceRange range = new SourceRange(index, index2 - index + 1);
+ ASTNode node = NodeFinder.perform(result, range);
+ NodeFinder nodeFinder = new NodeFinder(result, index, index2 - index + 1);
+ assertTrue("Different node", nodeFinder.getCoveringNode() == node);
+ }
+ public void test0004() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/NodeFinder/src/test0001/Test.java", false);
+ String contents =
+ "package test0001;\n" +
+ "import java.util.*;\n" +
+ "public class Test {\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(\"Hello\" + \" world\");\n" +
+ " }\n" +
+ "}";
+ ASTNode result = buildAST(
+ contents,
+ this.workingCopy);
+ char[] source = contents.toCharArray();
+ char[] className = "Test".toCharArray();
+ int index = CharOperation.indexOf(className, source, true);
+ SourceRange range = new SourceRange(index, className.length);
+ ASTNode node = NodeFinder.perform(result, range);
+ NodeFinder nodeFinder = new NodeFinder(result, index, className.length);
+ assertTrue("Different node", nodeFinder.getCoveredNode() == node);
+ }
+ public void test0005() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/NodeFinder/src/test0001/Test.java", false);
+ String contents =
+ "package test0001;\n" +
+ "import java.util.*;\n" +
+ "public class Test {\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(\"Hello\" + \" world\");\n" +
+ " }\n" +
+ "}";
+ ASTNode result = buildAST(
+ contents,
+ this.workingCopy);
+ char[] source = contents.toCharArray();
+ char[] className = "Test".toCharArray();
+ int index = CharOperation.indexOf(className, source, true);
+ int index2 = CharOperation.indexOf('{', source, index + 1, source.length);
+ ASTNode node = NodeFinder.perform(result, index, index2 - index + 1, this.workingCopy);
+ NodeFinder nodeFinder = new NodeFinder(result, index, index2 - index + 1);
+ assertTrue("Different node", nodeFinder.getCoveringNode() == node);
+ }
+ public void test0006() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/NodeFinder/src/test0001/Test.java", false);
+ String contents =
+ "package test0001;\n" +
+ "import java.util.*;\n" +
+ "public class Test {\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(\"Hello\" + \" world\");\n" +
+ " }\n" +
+ "}";
+ ASTNode result = buildAST(
+ contents,
+ this.workingCopy);
+ char[] source = contents.toCharArray();
+ char[] className = "Test".toCharArray();
+ int index = CharOperation.indexOf(className, source, true);
+ ASTNode node = NodeFinder.perform(result, index, className.length, this.workingCopy);
+ NodeFinder nodeFinder = new NodeFinder(result, index, className.length);
+ assertTrue("Different node", nodeFinder.getCoveredNode() == node);
+ }
+ public void test0007() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/NodeFinder/src/test0001/Test.java", false);
+ String contents =
+ "package test0001;\n" +
+ "import java.util.*;\n" +
+ "public class Test {\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(\"Hello\" + \" world\");\n" +
+ " }\n" +
+ "}";
+ ASTNode result = buildAST(
+ contents,
+ this.workingCopy);
+ char[] source = contents.toCharArray();
+ char[] className = "Test".toCharArray();
+ int index = CharOperation.indexOf(className, source, true);
+ ASTNode node = NodeFinder.perform(result, index - 1, 1);
+ NodeFinder nodeFinder = new NodeFinder(result, index - 1, 1);
+ assertNull("No covered node", nodeFinder.getCoveredNode());
+ assertNotNull("Got a covering node", node);
+ }
+ public void test0008() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/NodeFinder/src/test0001/Test.java", false);
+ String contents =
+ "package test0001;\n" +
+ "import java.util.*;\n" +
+ "public class Test {\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(\"Hello\" + \" world\");\n" +
+ " }\n" +
+ "}";
+ ASTNode result = buildAST(
+ contents,
+ this.workingCopy);
+ char[] source = contents.toCharArray();
+ char[] className = "Test".toCharArray();
+ int index = CharOperation.indexOf(className, source, true);
+ SourceRange range = new SourceRange(index - 1, 1);
+ ASTNode node = NodeFinder.perform(result, range);
+ NodeFinder nodeFinder = new NodeFinder(result, index - 1, 1);
+ assertNull("No covered node", nodeFinder.getCoveredNode());
+ assertNotNull("Got a covering node", node);
+ }
+ public void test0009() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/NodeFinder/src/test0001/Test.java", false);
+ String contents =
+ "package test0001;\n" +
+ "import java.util.*;\n" +
+ "public class Test {\n" +
+ " public static void main(String[] args) {\n" +
+ " System.out.println(\"Hello\" + \" world\");\n" +
+ " }\n" +
+ "}";
+ ASTNode result = buildAST(
+ contents,
+ this.workingCopy);
+ char[] source = contents.toCharArray();
+ char[] className = "Test".toCharArray();
+ int index = CharOperation.indexOf(className, source, true);
+ ASTNode node = NodeFinder.perform(result, index - 1, 1, this.workingCopy);
+ NodeFinder nodeFinder = new NodeFinder(result, index - 1, 1);
+ assertNull("No covered node", nodeFinder.getCoveredNode());
+ assertNull("No covering node", node);
+ }
+}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTNodesCollectorVisitor.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTNodesCollectorVisitor.java
new file mode 100644
index 0000000..609c3e9
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTNodesCollectorVisitor.java
@@ -0,0 +1,274 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2009 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.dom;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.jdt.core.dom.*;
+import org.eclipse.jdt.core.dom.ASTVisitor;
+
+class ASTNodesCollectorVisitor extends ASTVisitor {
+
+ private Set detachedAstNodes;
+
+ /**
+ *
+ * @see java.lang.Object#Object()
+ */
+ ASTNodesCollectorVisitor() {
+ // visit Javadoc.tags()
+ super(true);
+ this.detachedAstNodes = new HashSet();
+ }
+
+ private void add(ASTNode node) {
+ this.detachedAstNodes.add(node);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(AnnotationTypeDeclaration)
+ * @since 3.0
+ */
+ public void endVisit(AnnotationTypeDeclaration node) {
+ add(node);
+ node.setName(node.getAST().newSimpleName("XXX")); //$NON-NLS-1$
+ detachedListElement(node.bodyDeclarations());
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(AnnotationTypeMemberDeclaration)
+ * @since 3.0
+ */
+ public void endVisit(AnnotationTypeMemberDeclaration node) {
+ node.setName(node.getAST().newSimpleName("XXX")); //$NON-NLS-1$
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.AnonymousClassDeclaration)
+ */
+ public void endVisit(AnonymousClassDeclaration node) {
+ add(node);
+ detachedListElement(node.bodyDeclarations());
+ }
+
+ private void detachedListElement(List list) {
+ for (int i = 0; i < list.size(); i++) {
+ list.remove(0);
+ }
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.ClassInstanceCreation)
+ * @deprecated using deprecated code
+ */
+ public void endVisit(ClassInstanceCreation node) {
+ if (node.getAST().apiLevel() == AST.JLS2) {
+ node.setName(
+ node.getAST().newSimpleName("XXX")); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.CompilationUnit)
+ */
+ public void endVisit(CompilationUnit node) {
+ detachedListElement(node.imports());
+ node.setPackage(node.getAST().newPackageDeclaration());
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(EnumConstantDeclaration)
+ * @since 3.0
+ */
+ public void endVisit(EnumConstantDeclaration node) {
+ add(node);
+ node.setName(node.getAST().newSimpleName("XXX")); //$NON-NLS-1$
+ detachedListElement(node.getAnonymousClassDeclaration().bodyDeclarations());
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(EnumDeclaration)
+ * @since 3.0
+ */
+ public void endVisit(EnumDeclaration node) {
+ add(node);
+ node.setName(node.getAST().newSimpleName("XXX")); //$NON-NLS-1$
+ detachedListElement(node.bodyDeclarations());
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.FieldAccess)
+ */
+ public void endVisit(FieldAccess node) {
+ node.setName(node.getAST().newSimpleName("XXX")); //$NON-NLS-1$
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.FieldDeclaration)
+ */
+ public void endVisit(FieldDeclaration node) {
+ detachedListElement(node.fragments());
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.ImportDeclaration)
+ */
+ public void endVisit(ImportDeclaration node) {
+ add(node);
+ node.setName(node.getAST().newSimpleName("XXX")); //$NON-NLS-1$
+ }
+
+ /**
+ * @see ASTVisitor#endVisit(MemberRef)
+ * @since 3.0
+ */
+ public void endVisit(MemberRef node) {
+ add(node);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.MethodDeclaration)
+ */
+ public void endVisit(MethodDeclaration node) {
+ node.setName(node.getAST().newSimpleName("XXX")); //$NON-NLS-1$
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.MethodInvocation)
+ */
+ public void endVisit(MethodInvocation node) {
+ add(node);
+ node.setName(node.getAST().newSimpleName("XXX")); //$NON-NLS-1$
+ }
+
+ /**
+ * @see ASTVisitor#endVisit(MethodRef)
+ * @since 3.0
+ */
+ public void endVisit(MethodRef node) {
+ add(node);
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.PackageDeclaration)
+ */
+ public void endVisit(PackageDeclaration node) {
+ add(node);
+ node.setName(node.getAST().newSimpleName("XXX")); //$NON-NLS-1$
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.QualifiedName)
+ */
+ public void endVisit(QualifiedName node) {
+ add(node);
+ node.setQualifier(node.getAST().newSimpleName("sss")); //$NON-NLS-1$
+ node.setName(node.getAST().newSimpleName("sss")); //$NON-NLS-1$
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.SimpleName)
+ */
+ public void endVisit(SimpleName node) {
+ ASTNode parent = node.getParent();
+ switch(parent.getNodeType()) {
+ case ASTNode.CONTINUE_STATEMENT :
+ case ASTNode.BREAK_STATEMENT :
+ case ASTNode.LABELED_STATEMENT :
+ break;
+ default :
+ add(node);
+ }
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.SimpleType)
+ */
+ public void endVisit(SimpleType node) {
+ node.setName(node.getAST().newSimpleName("XXX")); //$NON-NLS-1$
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.SingleVariableDeclaration)
+ */
+ public void endVisit(SingleVariableDeclaration node) {
+ node.setName(node.getAST().newSimpleName("XXX")); //$NON-NLS-1$
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.SuperFieldAccess)
+ */
+ public void endVisit(SuperFieldAccess node) {
+ node.setName(node.getAST().newSimpleName("XXX")); //$NON-NLS-1$
+ node.setQualifier(node.getAST().newSimpleName("XXX")); //$NON-NLS-1$
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.SuperMethodInvocation)
+ */
+ public void endVisit(SuperMethodInvocation node) {
+ node.setName(node.getAST().newSimpleName("XXX")); //$NON-NLS-1$
+ node.setQualifier(node.getAST().newSimpleName("XXX")); //$NON-NLS-1$
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.ThisExpression)
+ */
+ public void endVisit(ThisExpression node) {
+ node.setQualifier(node.getAST().newSimpleName("XXX")); //$NON-NLS-1$
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.TypeDeclaration)
+ * @deprecated using deprecated code
+ */
+ public void endVisit(TypeDeclaration node) {
+ add(node);
+ node.setName(node.getAST().newSimpleName("XXX")); //$NON-NLS-1$
+ if (node.getAST().apiLevel() == AST.JLS2) {
+ node.setSuperclass(node.getAST().newSimpleName("XXX")); //$NON-NLS-1$
+ }
+ detachedListElement(node.bodyDeclarations());
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.VariableDeclarationExpression)
+ */
+ public void endVisit(VariableDeclarationExpression node) {
+ detachedListElement(node.fragments());
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.VariableDeclarationFragment)
+ */
+ public void endVisit(VariableDeclarationFragment node) {
+ add(node);
+ node.setName(node.getAST().newSimpleName("XXX")); //$NON-NLS-1$
+ }
+
+ /**
+ * @see org.eclipse.jdt.core.dom.ASTVisitor#endVisit(org.eclipse.jdt.core.dom.VariableDeclarationStatement)
+ */
+ public void endVisit(VariableDeclarationStatement node) {
+ detachedListElement(node.fragments());
+ }
+
+ /**
+ * Returns the detachedAstNodes.
+ * @return Set
+ */
+ public Set getDetachedAstNodes() {
+ return this.detachedAstNodes;
+ }
+
+}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTParserTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTParserTest.java
new file mode 100644
index 0000000..49e462e
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTParserTest.java
@@ -0,0 +1,116 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2009 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.dom;
+
+import java.lang.reflect.Method;
+import java.util.HashMap;
+
+import junit.framework.Test;
+
+import org.eclipse.jdt.core.IClassFile;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTParser;
+
+public class ASTParserTest extends org.eclipse.jdt.core.tests.junit.extension.TestCase {
+
+ /** @deprecated using deprecated code */
+ public static Test suite() {
+ // TODO (frederic) use buildList + setAstLevel(init) instead...
+ junit.framework.TestSuite suite = new junit.framework.TestSuite(ASTParserTest.class.getName());
+
+ Class c = ASTParserTest.class;
+ Method[] methods = c.getMethods();
+ for (int i = 0, max = methods.length; i < max; i++) {
+ if (methods[i].getName().startsWith("test")) { //$NON-NLS-1$
+ suite.addTest(new ASTParserTest(methods[i].getName(), AST.JLS2));
+ suite.addTest(new ASTParserTest(methods[i].getName(), AST.JLS3));
+ }
+ }
+ return suite;
+ }
+
+ AST ast;
+ ASTParser parser;
+ int API_LEVEL;
+
+ public ASTParserTest(String name, int apiLevel) {
+ super(name);
+ this.API_LEVEL = apiLevel;
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.ast = AST.newAST(this.API_LEVEL);
+ this.parser = ASTParser.newParser(this.API_LEVEL);
+ }
+
+ protected void tearDown() throws Exception {
+ this.ast = null;
+ super.tearDown();
+ }
+
+ /** @deprecated using deprecated code */
+ public String getName() {
+ String name = super.getName();
+ switch (this.API_LEVEL) {
+ case AST.JLS2:
+ name = "JLS2 - " + name;
+ break;
+ case AST.JLS3:
+ name = "JLS3 - " + name;
+ break;
+ }
+ return name;
+ }
+
+ public void testKConstants() {
+ assertSame(ASTParser.K_EXPRESSION, 1);
+ assertSame(ASTParser.K_STATEMENTS, 2);
+ assertSame(ASTParser.K_CLASS_BODY_DECLARATIONS, 4);
+ assertSame(ASTParser.K_COMPILATION_UNIT, 8);
+ }
+
+ public void testSetting() {
+ // for now, just slam some values in
+ this.parser.setKind(ASTParser.K_COMPILATION_UNIT);
+ this.parser.setKind(ASTParser.K_CLASS_BODY_DECLARATIONS);
+ this.parser.setKind(ASTParser.K_EXPRESSION);
+ this.parser.setKind(ASTParser.K_STATEMENTS);
+
+ this.parser.setSource(new char[0]);
+ this.parser.setSource((char[]) null);
+ this.parser.setSource((ICompilationUnit) null);
+ this.parser.setSource((IClassFile) null);
+
+ this.parser.setResolveBindings(false);
+ this.parser.setResolveBindings(true);
+
+ this.parser.setSourceRange(0, -1);
+ this.parser.setSourceRange(0, 1);
+ this.parser.setSourceRange(1, 0);
+ this.parser.setSourceRange(1, -1);
+
+ this.parser.setWorkingCopyOwner(null);
+
+ this.parser.setUnitName(null);
+ this.parser.setUnitName("Foo.java"); //$NON-NLS-1$
+
+ this.parser.setProject(null);
+
+ this.parser.setFocalPosition(-1);
+ this.parser.setFocalPosition(0);
+
+ this.parser.setCompilerOptions(null);
+ this.parser.setCompilerOptions(new HashMap());
+ }
+}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTPositionsTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTPositionsTest.java
new file mode 100644
index 0000000..ecfd7e0
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTPositionsTest.java
@@ -0,0 +1,152 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2009 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.dom;
+
+import junit.framework.Test;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+
+public class ASTPositionsTest extends ConverterTestSetup {
+
+ ICompilationUnit workingCopy;
+
+ public void setUpSuite() throws Exception {
+ super.setUpSuite();
+ this.ast = AST.newAST(AST.JLS3);
+ }
+
+ public ASTPositionsTest(String name) {
+ super(name);
+ }
+
+ static {
+// TESTS_NUMBERS = new int[] { 182, 183 };
+// TESTS_NAMES = new String[] {"test0177"};
+ }
+ public static Test suite() {
+ return buildModelTestSuite(ASTPositionsTest.class);
+ }
+
+ private void sanityCheck(final String contents, CompilationUnit compilationUnit) {
+ for (int i = 0, max = contents.length(); i < max; i++) {
+ final int lineNumber = compilationUnit.getLineNumber(i);
+ assertTrue("Wrong value for char at " + i, lineNumber >= 1);
+ final int columnNumber = compilationUnit.getColumnNumber(i);
+ assertTrue("Wrong value for char at " + i, columnNumber >= 0);
+ final int position = compilationUnit.getPosition(lineNumber, columnNumber);
+ assertTrue("Wrong value for char at i", position >= 0);
+ if (position == 0) {
+ assertEquals("Only true for first character", 0, i);
+ }
+ assertEquals("Wrong char", contents.charAt(i), contents.charAt(position));
+ }
+ }
+
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ if (this.workingCopy != null) {
+ this.workingCopy.discardWorkingCopy();
+ this.workingCopy = null;
+ }
+ }
+
+ public void test001() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ final String contents =
+ "import java.util.Map;\r\n" +
+ "public class X {\r\n" +
+ " Map<String, Number> map= null;\r\n" +
+ "}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertEquals("Wrong char", 'X', contents.charAt(compilationUnit.getPosition(2, 13)));
+ assertEquals("Wrong char", 'i', contents.charAt(compilationUnit.getPosition(1, 0)));
+ assertEquals("Wrong position", -1, compilationUnit.getPosition(1, -1));
+ assertEquals("Wrong position", -1, compilationUnit.getPosition(-1, 0));
+ assertEquals("Wrong position", -1, compilationUnit.getPosition(5, 0));
+ assertEquals("Wrong position", -1, compilationUnit.getPosition(4, 1));
+ assertEquals("Wrong char", '}', contents.charAt(compilationUnit.getPosition(4, 0)));
+ assertEquals("Wrong char", '\r', contents.charAt(compilationUnit.getPosition(1, 21)));
+
+ sanityCheck(contents, compilationUnit);
+ }
+
+ public void test002() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ final String contents =
+ "import java.util.Map;\n" +
+ "public class X {\n" +
+ " Map<String, Number> map= null;\n" +
+ "}\n";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ sanityCheck(contents, compilationUnit);
+ }
+
+ public void test003() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ final String contents =
+ "import java.util.Map;\r" +
+ "public class X {\r" +
+ " Map<String, Number> map= null;\r" +
+ "}\r";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ sanityCheck(contents, compilationUnit);
+ }
+
+ public void test004() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "package pack1;\npublic class X {}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ sanityCheck(contents, compilationUnit);
+ assertEquals(1, compilationUnit.getLineNumber(0));
+ }
+
+ public void test005() throws JavaModelException {
+ this.workingCopy = getWorkingCopy("/Converter15/src/X.java", true/*resolve*/);
+ String contents =
+ "package pack1;public class X {}";
+ ASTNode node = buildAST(
+ contents,
+ this.workingCopy,
+ false);
+ assertEquals("Not a compilation unit", ASTNode.COMPILATION_UNIT, node.getNodeType());
+ CompilationUnit compilationUnit = (CompilationUnit) node;
+ assertEquals(1, compilationUnit.getLineNumber(0));
+ sanityCheck(contents, compilationUnit);
+ }
+
+
+}
diff --git a/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTStructuralPropertyTest.java b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTStructuralPropertyTest.java
new file mode 100644
index 0000000..b63526d
--- /dev/null
+++ b/org.eclipse.jdt.core.tests.model/src/org/eclipse/jdt/core/tests/dom/ASTStructuralPropertyTest.java
@@ -0,0 +1,391 @@
+/*******************************************************************************
+ * Copyright (c) 2004, 2009 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
+ * Technical University Berlin - adapted for Object Teams
+ *******************************************************************************/
+
+package org.eclipse.jdt.core.tests.dom;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import junit.framework.Test;
+
+import org.eclipse.jdt.core.dom.*;
+
+public class ASTStructuralPropertyTest extends org.eclipse.jdt.core.tests.junit.extension.TestCase {
+
+ /** @deprecated using deprecated code */
+ public static Test suite() {
+ // TODO (frederic) use buildList + setAstLevel(init) instead...
+ junit.framework.TestSuite suite = new junit.framework.TestSuite(ASTStructuralPropertyTest.class.getName());
+
+ Class c = ASTStructuralPropertyTest.class;
+ Method[] methods = c.getMethods();
+ for (int i = 0, max = methods.length; i < max; i++) {
+ if (methods[i].getName().startsWith("test")) { //$NON-NLS-1$
+ suite.addTest(new ASTStructuralPropertyTest(methods[i].getName(), AST.JLS2));
+ suite.addTest(new ASTStructuralPropertyTest(methods[i].getName(), AST.JLS3));
+ }
+ }
+ return suite;
+ }
+
+ AST ast;
+ ASTParser parser;
+ int API_LEVEL;
+
+ public ASTStructuralPropertyTest(String name, int apiLevel) {
+ super(name);
+ this.API_LEVEL = apiLevel;
+ }
+
+ protected void setUp() throws Exception {
+ super.setUp();
+ this.ast = AST.newAST(this.API_LEVEL);
+ this.parser = ASTParser.newParser(this.API_LEVEL);
+ }
+
+ protected void tearDown() throws Exception {
+ this.ast = null;
+ super.tearDown();
+ }
+
+ /** @deprecated using deprecated code */
+ public String getName() {
+ String name = super.getName();
+ switch (this.API_LEVEL) {
+ case AST.JLS2:
+ name = "JLS2 - " + name;
+ break;
+ case AST.JLS3:
+ name = "JLS3 - " + name;
+ break;
+ }
+ return name;
+ }
+
+ public void testLocationInParent() {
+ final ASTNode root = SampleASTs.oneOfEach(this.ast);
+ ASTVisitor v = new ASTVisitor(true) {
+ public void postVisit(ASTNode node) {
+ StructuralPropertyDescriptor me = node.getLocationInParent();
+ assertTrue(me != null || (node == root));
+ ASTNode p = node.getParent();
+ if (p != null) {
+ List parentProperties = p.structuralPropertiesForType();
+ boolean foundMe = false;
+ for (Iterator it = parentProperties.iterator(); it
+ .hasNext();) {
+ StructuralPropertyDescriptor prop =
+ (StructuralPropertyDescriptor) it.next();
+ if (me == prop || prop.getId().equals(me.getId())) {
+ foundMe = true;
+ break;
+ }
+ }
+ assertTrue(foundMe);
+ }
+ }
+ };
+ root.accept(v);
+ }
+
+ /**
+ * @deprecated since using deprecated constant
+ */
+ public void testStructuralProperties() {
+ final ASTNode root = SampleASTs.oneOfEach(this.ast);
+
+ final Set simpleProperties = new HashSet(400);
+ final Set childProperties = new HashSet(400);
+ final Set childListProperties = new HashSet(400);
+