Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authornhauge2012-05-29 15:22:26 +0000
committernhauge2012-05-29 15:22:26 +0000
commit21bf713dfb1a6d72de2bc2e1ca10cefb703b97c4 (patch)
treec4694847f199842db5dea94d14fc086512092424 /common/tests/org.eclipse.jpt.common.core.tests
parentb6664f758d0426d7078470485bab671401edfaf5 (diff)
downloadwebtools.dali-201205290000.tar.gz
webtools.dali-201205290000.tar.xz
webtools.dali-201205290000.zip
This commit was manufactured by cvs2svn to create tag 'v201205290000'.v201205290000
Diffstat (limited to 'common/tests/org.eclipse.jpt.common.core.tests')
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/.classpath13
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/.cvsignore1
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/.project28
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/.settings/org.eclipse.jdt.core.prefs12
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/META-INF/MANIFEST.MF21
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/about.html34
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/build.properties16
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/plugin.properties23
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/JptCommonCoreTests.java30
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/projects/TestFacetedProject.java85
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/projects/TestJavaProject.java121
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/projects/TestPlatformProject.java97
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/resource/java/JavaResourceModelTestCase.java197
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/resource/java/JptCommonCoreResourceJavaTests.java28
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/resource/java/SourceAttributeTests.java135
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/ASTToolsTests.java196
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/AnnotationTestCase.java1099
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/CombinationIndexedDeclarationAnnotationAdapterTests.java744
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/DefaultAnnotationEditFormatterTests.java75
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/JDTToolsTests.java65
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/JptCommonCoreUtilityJdtTests.java36
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/MemberAnnotationElementAdapterTests.java1298
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/MiscTests.java48
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/NestedDeclarationAnnotationAdapterTests.java763
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/NestedIndexedDeclarationAnnotationAdapterTests.java2229
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/SimpleDeclarationAnnotationAdapterTests.java274
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/TypeTests.java52
-rw-r--r--common/tests/org.eclipse.jpt.common.core.tests/test.xml45
28 files changed, 0 insertions, 7765 deletions
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/.classpath b/common/tests/org.eclipse.jpt.common.core.tests/.classpath
deleted file mode 100644
index 1e530394ab..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/.classpath
+++ /dev/null
@@ -1,13 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src"/>
- <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
- <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins">
- <accessrules>
- <accessrule kind="accessible" pattern="org/eclipse/jpt/common/core/**"/>
- <accessrule kind="accessible" pattern="org/eclipse/jpt/common/utility/**"/>
- <accessrule kind="accessible" pattern="org/eclipse/wst/**"/>
- </accessrules>
- </classpathentry>
- <classpathentry kind="output" path="bin"/>
-</classpath>
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/.cvsignore b/common/tests/org.eclipse.jpt.common.core.tests/.cvsignore
deleted file mode 100644
index ba077a4031..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/.cvsignore
+++ /dev/null
@@ -1 +0,0 @@
-bin
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/.project b/common/tests/org.eclipse.jpt.common.core.tests/.project
deleted file mode 100644
index 0839d137f9..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/.project
+++ /dev/null
@@ -1,28 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<projectDescription>
- <name>org.eclipse.jpt.common.core.tests</name>
- <comment></comment>
- <projects>
- </projects>
- <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.pde.PluginNature</nature>
- <nature>org.eclipse.jdt.core.javanature</nature>
- </natures>
-</projectDescription>
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/.settings/org.eclipse.jdt.core.prefs b/common/tests/org.eclipse.jpt.common.core.tests/.settings/org.eclipse.jdt.core.prefs
deleted file mode 100644
index 294090b50a..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/.settings/org.eclipse.jdt.core.prefs
+++ /dev/null
@@ -1,12 +0,0 @@
-#Tue Mar 08 12:06:24 EST 2011
-eclipse.preferences.version=1
-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.problem.assertIdentifier=error
-org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
-org.eclipse.jdt.core.compiler.source=1.5
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/META-INF/MANIFEST.MF b/common/tests/org.eclipse.jpt.common.core.tests/META-INF/MANIFEST.MF
deleted file mode 100644
index 1d370da61b..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/META-INF/MANIFEST.MF
+++ /dev/null
@@ -1,21 +0,0 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-Name: %pluginName
-Bundle-Vendor: %providerName
-Bundle-SymbolicName: org.eclipse.jpt.common.core.tests;singleton:=true
-Bundle-Version: 1.2.0.qualifier
-Bundle-Localization: plugin
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
-Bundle-ActivationPolicy: lazy
-Require-Bundle: org.eclipse.core.resources;bundle-version="[3.4.0,4.0.0)",
- org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)",
- org.eclipse.jdt.core;bundle-version="[3.4.0,4.0.0)",
- org.eclipse.jpt.common.core;bundle-version="[1.0.0,2.0.0)",
- org.eclipse.jpt.common.utility;bundle-version="[2.0.0,3.0.0)",
- org.eclipse.jpt.common.utility.tests;bundle-version="[2.0.0,3.0.0)",
- org.eclipse.wst.common.project.facet.core;bundle-version="[1.3.0,2.0.0)",
- org.junit;bundle-version="[4.0.0,5.0.0)"
-Export-Package: org.eclipse.jpt.common.core.tests.internal;x-internal:=true,
- org.eclipse.jpt.common.core.tests.internal.projects;x-internal:=true,
- org.eclipse.jpt.common.core.tests.internal.resource.java;x-internal:=true,
- org.eclipse.jpt.common.core.tests.internal.utility.jdt;x-internal:=true
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/about.html b/common/tests/org.eclipse.jpt.common.core.tests/about.html
deleted file mode 100644
index be534ba44f..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/about.html
+++ /dev/null
@@ -1,34 +0,0 @@
-<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
-<HTML>
-
-<head>
-<title>About</title>
-<meta http-equiv=Content-Type content="text/html; charset=ISO-8859-1">
-</head>
-
-<BODY lang="EN-US">
-
-<H3>About This Content</H3>
-
-<P>May 02, 2008</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/org/documents/epl-v10.php">http://www.eclipse.org/org/documents/epl-v10.php</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>
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/build.properties b/common/tests/org.eclipse.jpt.common.core.tests/build.properties
deleted file mode 100644
index 9cd29bcb38..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/build.properties
+++ /dev/null
@@ -1,16 +0,0 @@
-################################################################################
-# Copyright (c) 2011 Oracle. 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:
-# Oracle - initial API and implementation
-################################################################################
-bin.includes = .,\
- META-INF/,\
- about.html,\
- test.xml,\
- plugin.properties
-source.. = src/
-output.. = bin/
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/plugin.properties b/common/tests/org.eclipse.jpt.common.core.tests/plugin.properties
deleted file mode 100644
index b22b820267..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/plugin.properties
+++ /dev/null
@@ -1,23 +0,0 @@
-################################################################################
-# Copyright (c) 2011 Oracle. 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:
-# Oracle - initial API and implementation
-################################################################################
-# ====================================================================
-# To code developer:
-# Do NOT change the properties between this line and the
-# "%%% END OF TRANSLATED PROPERTIES %%%" line.
-# Make a new property name, append to the end of the file and change
-# the code to use the new property.
-# ====================================================================
-
-# ====================================================================
-# %%% END OF TRANSLATED PROPERTIES %%%
-# ====================================================================
-
-pluginName=Dali Java Persistence Tools - Common Core Tests
-providerName=Eclipse Web Tools Platform
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/JptCommonCoreTests.java b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/JptCommonCoreTests.java
deleted file mode 100644
index b53253a105..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/JptCommonCoreTests.java
+++ /dev/null
@@ -1,30 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 Oracle. 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:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.core.tests.internal;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.eclipse.jpt.common.core.tests.internal.resource.java.JptCommonCoreResourceJavaTests;
-import org.eclipse.jpt.common.core.tests.internal.utility.jdt.JptCommonCoreUtilityJdtTests;
-
-public class JptCommonCoreTests {
-
- public static Test suite() {
- TestSuite suite = new TestSuite(JptCommonCoreTests.class.getPackage().getName());
- suite.addTest(JptCommonCoreResourceJavaTests.suite());
- suite.addTest(JptCommonCoreUtilityJdtTests.suite());
- return suite;
- }
-
- private JptCommonCoreTests() {
- super();
- throw new UnsupportedOperationException();
- }
-}
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/projects/TestFacetedProject.java b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/projects/TestFacetedProject.java
deleted file mode 100644
index a2ba74b0b3..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/projects/TestFacetedProject.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2009 Oracle. 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:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.core.tests.internal.projects;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.wst.common.project.facet.core.IFacetedProject;
-import org.eclipse.wst.common.project.facet.core.IProjectFacetVersion;
-import org.eclipse.wst.common.project.facet.core.ProjectFacetsManager;
-
-/**
- * This builds and holds a "faceted" project.
- * Support for installing facets.
- */
-public class TestFacetedProject extends TestPlatformProject {
- private final IFacetedProject facetedProject;
-
-
- // ********** builders *****************************
-
- public static TestFacetedProject buildFacetedProject(String baseProjectName, boolean autoBuild)
- throws CoreException {
- return new TestFacetedProject(baseProjectName, autoBuild);
- }
-
-
- // ********** constructors/initialization **********
-
- public TestFacetedProject(String projectName) throws CoreException {
- this(projectName, true);
- }
-
- public TestFacetedProject(String projectName, boolean autoBuild) throws CoreException {
- super(projectName, autoBuild);
- this.facetedProject = this.createFacetedProject();
- }
-
- private IFacetedProject createFacetedProject() throws CoreException {
- return ProjectFacetsManager.create(this.getProject(), true, null); // true = "convert if necessary"
- }
-
-
- // ********** public methods **********
-
- public IFacetedProject getFacetedProject() {
- return this.facetedProject;
- }
-
- public void installFacet(String facetName, String versionName) throws CoreException {
- this.installFacet(facetName, versionName, null);
- }
-
- public void uninstallFacet(String facetName, String versionName) throws CoreException {
- this.uninstallFacet(facetName, versionName, null);
- }
-
- /**
- * if 'config' is null (and 'facetName' is "jpt.jpa"), the JPA project will be built with the defaults
- * defined in JpaFacetInstallDataModelProvider#getDefaultProperty(String)
- * In JPA the config object will be an IDataModel
- * In JAXB the config object will be a JaxbFacetInstallConfig
- */
- public void installFacet(String facetName, String versionName, Object config) throws CoreException {
- this.facetedProject.installProjectFacet(this.facetVersion(facetName, versionName), config, null);
- }
-
- /**
- * In JPA the config object will be an IDataModel
- * In JAXB the config object will be a JaxbFacetUninstallConfig
- */
- public void uninstallFacet(String facetName, String versionName, Object config) throws CoreException {
- this.facetedProject.uninstallProjectFacet(this.facetVersion(facetName, versionName), config, null);
- }
-
- private IProjectFacetVersion facetVersion(String facetName, String versionName) {
- return ProjectFacetsManager.getProjectFacet(facetName).getVersion(versionName);
- }
-
-}
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/projects/TestJavaProject.java b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/projects/TestJavaProject.java
deleted file mode 100644
index 7ea7e3813a..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/projects/TestJavaProject.java
+++ /dev/null
@@ -1,121 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2009 Oracle. 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:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.core.tests.internal.projects;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.jdt.core.IClasspathEntry;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jdt.core.IPackageFragment;
-import org.eclipse.jdt.core.IPackageFragmentRoot;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jpt.common.utility.internal.ArrayTools;
-
-/**
- * This builds and holds a "Java" project.
- * Support for adding packages and types.
- *
- * "Java" projects aren't required to be "faceted" projects, but for JPA
- * testing they are.
- */
-@SuppressWarnings("nls")
-public class TestJavaProject extends TestFacetedProject {
- private final IJavaProject javaProject;
- private final IPackageFragmentRoot sourceFolder;
-
-
- // ********** builders *****************************
-
- public static TestJavaProject buildJavaProject(String baseProjectName, boolean autoBuild)
- throws CoreException {
- return new TestJavaProject(baseProjectName, autoBuild);
- }
-
-
- // ********** constructors/initialization **********
-
- public TestJavaProject(String projectName) throws CoreException {
- this(projectName, false);
- }
-
- public TestJavaProject(String projectName, boolean autoBuild) throws CoreException {
- super(projectName, autoBuild);
- this.installFacet("jst.java", "5.0");
- this.javaProject = JavaCore.create(this.getProject());
- this.sourceFolder = this.javaProject.getPackageFragmentRoot(this.getProject().getFolder("src"));
- }
-
- public void addJar(String jarPath) throws JavaModelException {
- this.addClasspathEntry(JavaCore.newLibraryEntry(new Path(jarPath), null, null));
- }
-
- private void addClasspathEntry(IClasspathEntry entry) throws JavaModelException {
- this.javaProject.setRawClasspath(ArrayTools.add(this.javaProject.getRawClasspath(), entry), null);
- }
-
-
- // ********** public methods **********
-
- public IJavaProject getJavaProject() {
- return this.javaProject;
- }
-
- public IPackageFragment createPackage(String packageName) throws CoreException {
- return this.sourceFolder.createPackageFragment(packageName, false, null); // false = "no force"
- }
-
- /**
- * The source should NOT contain a package declaration;
- * it will be added here.
- */
- public ICompilationUnit createCompilationUnit(String packageName, String compilationUnitName, String source) throws CoreException {
- return this.createCompilationUnit(this.createPackage(packageName), compilationUnitName, new SimpleSourceWriter(source));
- }
-
- /**
- * The source should NOT contain a package declaration;
- * it will be added here.
- */
- public ICompilationUnit createCompilationUnit(String packageName, String compilationUnitName, SourceWriter sourceWriter) throws CoreException {
- return this.createCompilationUnit(this.createPackage(packageName), compilationUnitName, sourceWriter);
- }
-
- /**
- * The source should NOT contain a package declaration;
- * it will be added here.
- */
- public ICompilationUnit createCompilationUnit(IPackageFragment packageFragment, String compilationUnitName, SourceWriter sourceWriter) throws CoreException {
- StringBuilder sb = new StringBuilder(2000);
- sourceWriter.appendSourceTo(sb);
- String source = sb.toString();
- return packageFragment.createCompilationUnit(compilationUnitName, source, false, null); // false = "no force"
- }
-
-
- // ********** member classes **********
-
- public interface SourceWriter {
- void appendSourceTo(StringBuilder sb);
- }
-
- public class SimpleSourceWriter implements SourceWriter {
- private final String source;
- public SimpleSourceWriter(String source) {
- super();
- this.source = source;
- }
- public void appendSourceTo(StringBuilder sb) {
- sb.append(this.source);
- }
- }
-
-}
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/projects/TestPlatformProject.java b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/projects/TestPlatformProject.java
deleted file mode 100644
index 22ea400073..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/projects/TestPlatformProject.java
+++ /dev/null
@@ -1,97 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2005, 2012 Oracle. 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:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.core.tests.internal.projects;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IProjectDescription;
-import org.eclipse.core.resources.IWorkspaceDescription;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jpt.common.utility.internal.ArrayTools;
-import org.eclipse.jpt.common.utility.internal.StringTools;
-import org.eclipse.jpt.common.utility.tests.internal.TestCommand;
-import org.eclipse.jpt.common.utility.tests.internal.TestTools;
-
-/**
- * This builds and holds a "general" Eclipse project.
- * Support for adding natures, folders, and files.
- */
-public class TestPlatformProject {
- private final IProject project;
-
- /** carriage return */
- public static final String CR = StringTools.CR;
-
-
- // ********** builders **********
-
- public static TestPlatformProject buildPlatformProject(String baseProjectName, boolean autoBuild)
- throws CoreException {
- return new TestPlatformProject(baseProjectName, autoBuild);
- }
-
-
- // ********** constructors/initialization **********
-
- public TestPlatformProject(String projectName, boolean autoBuild) throws CoreException {
- super();
- this.setAutoBuild(autoBuild); // workspace-wide setting
- this.project = this.buildPlatformProject(projectName);
- }
-
- private void setAutoBuild(boolean autoBuild) throws CoreException {
- IWorkspaceDescription description = ResourcesPlugin.getWorkspace().getDescription();
- description.setAutoBuilding(autoBuild);
- ResourcesPlugin.getWorkspace().setDescription(description);
- }
-
- private IProject buildPlatformProject(String projectName) throws CoreException {
- IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
- this.createProject(p);
- p.open(null);
- return p;
- }
-
- private void createProject(IProject p) {
- TestTools.execute(new CreateProjectCommand(p), 4);
- }
-
- protected static class CreateProjectCommand
- implements TestCommand
- {
- private final IProject project;
- protected CreateProjectCommand(IProject project) {
- super();
- this.project = project;
- }
- public void execute() throws Exception {
- this.project.create(null);
- }
- }
-
-
- // ********** public methods **********
-
- public IProject getProject() {
- return this.project;
- }
-
- public void addProjectNature(String natureID) throws CoreException {
- IProjectDescription description = this.project.getDescription();
- description.setNatureIds(ArrayTools.add(description.getNatureIds(), natureID));
- this.project.setDescription(description, null);
- }
-
- public void removeProjectNature(String natureID) throws CoreException {
- IProjectDescription description = this.project.getDescription();
- description.setNatureIds(ArrayTools.removeAllOccurrences(description.getNatureIds(), natureID));
- this.project.setDescription(description, null);
- }
-}
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/resource/java/JavaResourceModelTestCase.java b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/resource/java/JavaResourceModelTestCase.java
deleted file mode 100644
index 6f952c5ff5..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/resource/java/JavaResourceModelTestCase.java
+++ /dev/null
@@ -1,197 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2010, 2012 Oracle. 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:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.core.tests.internal.resource.java;
-
-import org.eclipse.jdt.core.ElementChangedEvent;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.IElementChangedListener;
-import org.eclipse.jdt.core.IJavaElement;
-import org.eclipse.jdt.core.IJavaElementDelta;
-import org.eclipse.jdt.core.JavaCore;
-import org.eclipse.jpt.common.core.AnnotationProvider;
-import org.eclipse.jpt.common.core.GenericAnnotationProvider;
-import org.eclipse.jpt.common.core.internal.resource.java.source.SourcePackageInfoCompilationUnit;
-import org.eclipse.jpt.common.core.internal.resource.java.source.SourceTypeCompilationUnit;
-import org.eclipse.jpt.common.core.internal.utility.jdt.NullAnnotationEditFormatter;
-import org.eclipse.jpt.common.core.resource.java.AnnotationDefinition;
-import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType;
-import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit;
-import org.eclipse.jpt.common.core.resource.java.JavaResourceEnum;
-import org.eclipse.jpt.common.core.resource.java.JavaResourceEnumConstant;
-import org.eclipse.jpt.common.core.resource.java.JavaResourceField;
-import org.eclipse.jpt.common.core.resource.java.JavaResourceMethod;
-import org.eclipse.jpt.common.core.resource.java.JavaResourcePackage;
-import org.eclipse.jpt.common.core.resource.java.JavaResourcePackageInfoCompilationUnit;
-import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
-import org.eclipse.jpt.common.core.resource.java.NestableAnnotationDefinition;
-import org.eclipse.jpt.common.core.tests.internal.utility.jdt.AnnotationTestCase;
-import org.eclipse.jpt.common.utility.command.CommandExecutor;
-import org.eclipse.jpt.common.utility.internal.BitTools;
-import org.eclipse.jpt.common.utility.internal.CollectionTools;
-import org.eclipse.jpt.common.utility.internal.ReflectionTools;
-import org.eclipse.jpt.common.utility.internal.StringTools;
-
-@SuppressWarnings("nls")
-public abstract class JavaResourceModelTestCase
- extends AnnotationTestCase {
-
- private JavaElementChangeListener javaElementChangeListener;
- protected JavaResourceCompilationUnit javaResourceCompilationUnit;
-
-
- public JavaResourceModelTestCase(String name) {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- this.javaElementChangeListener = new JavaElementChangeListener();
- JavaCore.addElementChangedListener(this.javaElementChangeListener);
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- JavaCore.removeElementChangedListener(this.javaElementChangeListener);
- this.javaElementChangeListener = null;
- }
-
- private class JavaElementChangeListener
- implements IElementChangedListener {
-
- JavaElementChangeListener() {
- super();
- }
-
- public void elementChanged(ElementChangedEvent event) {
- JavaResourceModelTestCase.this.javaElementChanged(event);
- }
-
- @Override
- public String toString() {
- return StringTools.buildToStringFor(this);
- }
- }
-
- void javaElementChanged(ElementChangedEvent event) {
- if (this.javaResourceCompilationUnit == null) {
- return;
- }
- this.syncWithJavaDelta(event.getDelta());
- }
-
- /**
- * NB: this is copied from GenericJpaProject, so it might need to be
- * kept in synch with that code if it changes... yech...
- */
- protected void syncWithJavaDelta(IJavaElementDelta delta) {
- switch (delta.getElement().getElementType()) {
- case IJavaElement.JAVA_MODEL :
- case IJavaElement.JAVA_PROJECT :
- case IJavaElement.PACKAGE_FRAGMENT_ROOT :
- case IJavaElement.PACKAGE_FRAGMENT :
- this.syncWithJavaDeltaChildren(delta);
- break;
- case IJavaElement.COMPILATION_UNIT :
- this.javaCompilationUnitChanged(delta);
- break;
- default :
- break; // ignore the elements inside a compilation unit
- }
- }
-
- protected void syncWithJavaDeltaChildren(IJavaElementDelta delta) {
- for (IJavaElementDelta child : delta.getAffectedChildren()) {
- this.syncWithJavaDelta(child); // recurse
- }
- }
-
- protected void javaCompilationUnitChanged(IJavaElementDelta delta) {
- if (this.deltaIsRelevant(delta)) {
- this.javaResourceCompilationUnit.synchronizeWithJavaSource();
- }
- }
-
- protected boolean deltaIsRelevant(IJavaElementDelta delta) {
- if (BitTools.onlyFlagIsSet(delta.getFlags(), IJavaElementDelta.F_PRIMARY_WORKING_COPY)) {
- return false;
- }
- return delta.getKind() == IJavaElementDelta.CHANGED;
- }
-
- protected ICompilationUnit createAnnotationAndMembers(String packageName, String annotationName, String annotationBody) throws Exception {
- return this.javaProject.createCompilationUnit(packageName, annotationName + ".java", "public @interface " + annotationName + " { " + annotationBody + " }");
- }
-
- protected ICompilationUnit createEnumAndMembers(String packageName, String enumName, String enumBody) throws Exception {
- return this.javaProject.createCompilationUnit(packageName, enumName + ".java", "public enum " + enumName + " { " + enumBody + " }");
- }
-
- protected JavaResourcePackage buildJavaResourcePackage(ICompilationUnit cu) {
- JavaResourcePackageInfoCompilationUnit pkgCu =
- new SourcePackageInfoCompilationUnit(
- cu,
- this.buildAnnotationProvider(),
- NullAnnotationEditFormatter.instance(),
- CommandExecutor.Default.instance());
- this.javaResourceCompilationUnit = pkgCu;
- return pkgCu.getPackage();
- }
-
- protected JavaResourceType buildJavaResourceType(ICompilationUnit cu) {
- return (JavaResourceType) this.buildJavaResourceType_(cu);
- }
-
- protected JavaResourceEnum buildJavaResourceEnum(ICompilationUnit cu) {
- return (JavaResourceEnum) this.buildJavaResourceType_(cu);
- }
-
- private JavaResourceAbstractType buildJavaResourceType_(ICompilationUnit cu) {
- this.javaResourceCompilationUnit = this.buildJavaResourceCompilationUnit(cu);
- this.javaResourceCompilationUnit.resolveTypes();
- return this.hackJavaResourceType();
- }
-
- protected JavaResourceField getField(JavaResourceType type, int index) {
- return CollectionTools.get(type.getFields(), index);
- }
-
- protected JavaResourceMethod getMethod(JavaResourceType type, int index) {
- return CollectionTools.get(type.getMethods(), index);
- }
-
- protected JavaResourceEnumConstant getEnumConstant(JavaResourceEnum resourceEnum, int index) {
- return CollectionTools.get(resourceEnum.getEnumConstants(), index);
- }
-
- protected JavaResourceAbstractType hackJavaResourceType() {
- return (JavaResourceAbstractType) ReflectionTools.getFieldValue(this.javaResourceCompilationUnit, "primaryType");
- }
-
- protected JavaResourceCompilationUnit buildJavaResourceCompilationUnit(ICompilationUnit cu) {
- if (this.javaResourceCompilationUnit != null) {
- throw new IllegalStateException();
- }
- return new SourceTypeCompilationUnit(
- cu,
- this.buildAnnotationProvider(),
- NullAnnotationEditFormatter.instance(),
- CommandExecutor.Default.instance());
- }
-
- protected AnnotationProvider buildAnnotationProvider() {
- return new GenericAnnotationProvider(this.annotationDefinitions(), this.nestableAnnotationDefinitions());
- }
-
- protected abstract AnnotationDefinition[] annotationDefinitions();
-
- protected abstract NestableAnnotationDefinition[] nestableAnnotationDefinitions();
-}
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/resource/java/JptCommonCoreResourceJavaTests.java b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/resource/java/JptCommonCoreResourceJavaTests.java
deleted file mode 100644
index 34f6a682ab..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/resource/java/JptCommonCoreResourceJavaTests.java
+++ /dev/null
@@ -1,28 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 Oracle. 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:
- * Oracle - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.common.core.tests.internal.resource.java;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-
-public class JptCommonCoreResourceJavaTests {
-
- public static Test suite() {
- TestSuite suite = new TestSuite(JptCommonCoreResourceJavaTests.class.getPackage().getName());
- suite.addTestSuite(SourceAttributeTests.class);
- return suite;
- }
-
- private JptCommonCoreResourceJavaTests() {
- super();
- throw new UnsupportedOperationException();
- }
-}
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/resource/java/SourceAttributeTests.java b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/resource/java/SourceAttributeTests.java
deleted file mode 100644
index d5cfc8908c..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/resource/java/SourceAttributeTests.java
+++ /dev/null
@@ -1,135 +0,0 @@
-package org.eclipse.jpt.common.core.tests.internal.resource.java;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jpt.common.core.resource.java.AnnotationDefinition;
-import org.eclipse.jpt.common.core.resource.java.JavaResourceField;
-import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
-import org.eclipse.jpt.common.core.resource.java.NestableAnnotationDefinition;
-import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter;
-
-
-public class SourceAttributeTests
- extends JavaResourceModelTestCase {
-
- private static String TEST_CLASS_NAME = "TestClass";
-
-
- public SourceAttributeTests(String name) {
- super(name);
- }
-
-
- @Override
- protected AnnotationDefinition[] annotationDefinitions() {
- return new AnnotationDefinition[0];
- }
-
- @Override
- protected NestableAnnotationDefinition[] nestableAnnotationDefinitions() {
- return new NestableAnnotationDefinition[0];
- }
-
-
- private ICompilationUnit createTestClassWithVariousAttributes() throws CoreException {
- SourceWriter sourceWriter = new SourceWriter() {
- public void appendSourceTo(StringBuilder sb) {
- sb.append(CR);
- sb.append("import java.util.List;").append(CR);
- sb.append(CR);
- sb.append("public class ").append(TEST_CLASS_NAME).append("<T extends Number> ").append("{").append(CR);
- sb.append(" public String string;").append(CR);
- sb.append(" public List<String> stringList;").append(CR);
- sb.append(" public String[] stringArray;").append(CR);
- sb.append(" public String[][] stringDoubleArray;").append(CR);
- sb.append(" public T generic;").append(CR);
- sb.append(" public List<T> genericList;").append(CR);
- sb.append(" public T[] genericArray;").append(CR);
- sb.append(" public List<?> wildcardList;").append(CR);
- sb.append("}").append(CR);
- }
- };
- return this.javaProject.createCompilationUnit(PACKAGE_NAME, TEST_CLASS_NAME + ".java", sourceWriter);
- }
-
-
- public void testAttributeTypes() throws Exception {
- ICompilationUnit testClassCU = createTestClassWithVariousAttributes();
- JavaResourceType testClass = buildJavaResourceType(testClassCU);
-
- // String string
- JavaResourceField att = getField(testClass, 0);
- assertEquals("string", att.getName());
- assertEquals("java.lang.String", att.getTypeName());
- assertEquals(false, att.typeIsArray());
- assertEquals(null, att.getTypeArrayComponentTypeName());
- assertEquals(0, att.getTypeArrayDimensionality());
- assertEquals(0, att.getTypeTypeArgumentNamesSize());
-
- // List<String> stringList
- att = getField(testClass, 1);
- assertEquals("stringList", att.getName());
- assertEquals("java.util.List", att.getTypeName());
- assertEquals(false, att.typeIsArray());
- assertEquals(null, att.getTypeArrayComponentTypeName());
- assertEquals(0, att.getTypeArrayDimensionality());
- assertEquals(1, att.getTypeTypeArgumentNamesSize());
- assertEquals("java.lang.String", att.getTypeTypeArgumentName(0));
-
- // String[] stringArray
- att = getField(testClass, 2);
- assertEquals("stringArray", att.getName());
- assertEquals("java.lang.String[]", att.getTypeName());
- assertEquals(true, att.typeIsArray());
- assertEquals("java.lang.String", att.getTypeArrayComponentTypeName());
- assertEquals(1, att.getTypeArrayDimensionality());
- assertEquals(0, att.getTypeTypeArgumentNamesSize());
-
- // String[] stringDoubleArray
- att = getField(testClass, 3);
- assertEquals("stringDoubleArray", att.getName());
- assertEquals("java.lang.String[][]", att.getTypeName());
- assertEquals(true, att.typeIsArray());
- assertEquals("java.lang.String", att.getTypeArrayComponentTypeName());
- assertEquals(2, att.getTypeArrayDimensionality());
- assertEquals(0, att.getTypeTypeArgumentNamesSize());
-
- // T generic
- att = getField(testClass, 4);
- assertEquals("generic", att.getName());
- assertEquals("java.lang.Number", att.getTypeName());
- assertEquals(false, att.typeIsArray());
- assertEquals(null, att.getTypeArrayComponentTypeName());
- assertEquals(0, att.getTypeArrayDimensionality());
- assertEquals(0, att.getTypeTypeArgumentNamesSize());
-
- // List<T> genericList
- att = getField(testClass, 5);
- assertEquals("genericList", att.getName());
- assertEquals("java.util.List", att.getTypeName());
- assertEquals(false, att.typeIsArray());
- assertEquals(null, att.getTypeArrayComponentTypeName());
- assertEquals(0, att.getTypeArrayDimensionality());
- assertEquals(1, att.getTypeTypeArgumentNamesSize());
- assertEquals("java.lang.Number", att.getTypeTypeArgumentName(0));
-
- // T[] genericArray
- att = getField(testClass, 6);
- assertEquals("genericArray", att.getName());
- assertEquals("java.lang.Number[]", att.getTypeName());
- assertEquals(true, att.typeIsArray());
- assertEquals("java.lang.Number", att.getTypeArrayComponentTypeName());
- assertEquals(1, att.getTypeArrayDimensionality());
- assertEquals(0, att.getTypeTypeArgumentNamesSize());
-
- // List<?> wildcardList
- att = getField(testClass, 7);
- assertEquals("wildcardList", att.getName());
- assertEquals("java.util.List", att.getTypeName());
- assertEquals(false, att.typeIsArray());
- assertEquals(null, att.getTypeArrayComponentTypeName());
- assertEquals(0, att.getTypeArrayDimensionality());
- assertEquals(1, att.getTypeTypeArgumentNamesSize());
- assertEquals("java.lang.Object", att.getTypeTypeArgumentName(0));
- }
-}
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/ASTToolsTests.java b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/ASTToolsTests.java
deleted file mode 100644
index e8d26126ed..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/ASTToolsTests.java
+++ /dev/null
@@ -1,196 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2010 Oracle. 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:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.core.tests.internal.utility.jdt;
-
-import java.util.Iterator;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.dom.Name;
-import org.eclipse.jpt.common.core.internal.utility.jdt.ASTTools;
-import org.eclipse.jpt.common.core.internal.utility.jdt.AnnotationStringArrayExpressionConverter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.JDTFieldAttribute;
-import org.eclipse.jpt.common.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
-import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationAdapter;
-import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationElementAdapter;
-import org.eclipse.jpt.common.utility.internal.CollectionTools;
-import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
-
-@SuppressWarnings("nls")
-public class ASTToolsTests
- extends AnnotationTestCase {
-
- public ASTToolsTests(String name) {
- super(name);
- }
-
-
- private void createClassAndMembers(String className, String classBody) throws Exception {
- this.javaProject.createCompilationUnit("clazz", className + ".java", "public class " + className + " { " + classBody + " }");
- }
-
- private void createEnumAndMembers(String enumName, String enumBody) throws Exception {
- this.javaProject.createCompilationUnit("enums", enumName + ".java", "public enum " + enumName + " { " + enumBody + " }");
- }
-
- private void createAnnotationAndMembers(String annotationName, String annotationBody) throws Exception {
- this.javaProject.createCompilationUnit("annot", annotationName + ".java", "public @interface " + annotationName + " { " + annotationBody + " }");
- }
-
- private ICompilationUnit createTestType(final Iterator<String> imports, final String idFieldAnnotation)
- throws Exception {
- return createTestType(
- new DefaultAnnotationWriter() {
- @Override
- public Iterator<String> imports() {
- return imports;
- }
- @Override
- public void appendIdFieldAnnotationTo(StringBuilder sb) {
- sb.append(idFieldAnnotation);
- }
- });
- }
-
- public void testResolveEnum1() throws Exception {
- this.createEnumAndMembers("TestEnum", "FOO, BAR, BAZ");
- this.createAnnotationAndMembers("TestAnnotation", "TestEnum foo();");
-
- ICompilationUnit cu = this.createTestType("@annot.TestAnnotation(foo=enums.TestEnum.BAZ)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.TestAnnotation");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "foo");
- JDTFieldAttribute field = this.idField(cu);
-
- String actual = ASTTools.resolveEnum((Name) daea.getExpression(field.getModifiedDeclaration(this.buildASTRoot(cu))));
- assertEquals("enums.TestEnum.BAZ", actual);
- }
-
- public void testResolveEnum2() throws Exception {
- this.createEnumAndMembers("TestEnum", "FOO, BAR, BAZ");
- this.createAnnotationAndMembers("TestAnnotation", "TestEnum foo();");
-
- ICompilationUnit cu = this.createTestType("static enums.TestEnum.BAZ", "@annot.TestAnnotation(foo=BAZ)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.TestAnnotation");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "foo");
- JDTFieldAttribute field = this.idField(cu);
-
- String actual = ASTTools.resolveEnum((Name) daea.getExpression(field.getModifiedDeclaration(this.buildASTRoot(cu))));
- assertEquals("enums.TestEnum.BAZ", actual);
- }
-
- public void testResolveEnum3() throws Exception {
- this.createEnumAndMembers("TestEnum", "FOO, BAR, BAZ");
- this.createAnnotationAndMembers("TestAnnotation", "TestEnum foo();");
-
- ICompilationUnit cu = this.createTestType("static enums.TestEnum.*", "@annot.TestAnnotation(foo=BAZ)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.TestAnnotation");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "foo");
- JDTFieldAttribute field = this.idField(cu);
-
- String actual = ASTTools.resolveEnum((Name)daea.getExpression(field.getModifiedDeclaration(this.buildASTRoot(cu))));
- assertEquals("enums.TestEnum.BAZ", actual);
- }
-
- public void testResolveEnum4() throws Exception {
- this.createEnumAndMembers("TestEnum", "FOO, BAR, BAZ");
- this.createAnnotationAndMembers("TestAnnotation", "TestEnum foo();");
-
- ICompilationUnit cu = this.createTestType("enums.TestEnum", "@annot.TestAnnotation(foo=TestEnum.BAZ)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.TestAnnotation");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "foo");
- JDTFieldAttribute field = this.idField(cu);
-
- String actual = ASTTools.resolveEnum((Name) daea.getExpression(field.getModifiedDeclaration(this.buildASTRoot(cu))));
- assertEquals("enums.TestEnum.BAZ", actual);
- }
-
- public void testResolveFullyQualifiedNames() throws Exception {
- final String otherClassName = "OtherClass";
- final String otherClassName2 = "OtherClass2";
- final String fqOtherClassName = "clazz.OtherClass";
- final String fqOtherClassName2 = "clazz.OtherClass2";
- final String annotationName = "TestAnnotation";
- final String fqAnnotationName = "annot.TestAnnotation";
-
- createClassAndMembers(otherClassName, "");
- createClassAndMembers(otherClassName2, "");
- createAnnotationAndMembers(annotationName, "Class[] foo();");
-
- ICompilationUnit cu = createTestType(
- new ArrayIterator<String>(new String[] {fqOtherClassName, fqOtherClassName2, fqAnnotationName}),
- "@TestAnnotation(foo={" + otherClassName + ".class, " + otherClassName2 + ".class})");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter(fqAnnotationName);
- DeclarationAnnotationElementAdapter<String[]> daea =
- new ConversionDeclarationAnnotationElementAdapter<String[]>(
- daa, "foo", AnnotationStringArrayExpressionConverter.forTypes());
- JDTFieldAttribute field = idField(cu);
-
- Iterable<String> actual = ASTTools.resolveFullyQualifiedNames(daea.getExpression(field.getModifiedDeclaration(this.buildASTRoot(cu))));
-
- assertEquals(
- CollectionTools.list(new String[] {fqOtherClassName, fqOtherClassName2}),
- CollectionTools.list(actual));
- }
-
- public void testResolveFullyQualifiedNames2() throws Exception {
- final String otherClassName = "OtherClass";
- final String otherClassName2 = "OtherClass2";
- final String fqOtherClassName = "clazz.OtherClass";
- final String fqOtherClassName2 = "clazz.OtherClass2";
- final String annotationName = "TestAnnotation";
- final String fqAnnotationName = "annot.TestAnnotation";
-
- createClassAndMembers(otherClassName, "");
- createClassAndMembers(otherClassName2, "");
- createAnnotationAndMembers(annotationName, "Class[] foo();");
-
- ICompilationUnit cu = createTestType(
- new ArrayIterator<String>(new String[] {fqOtherClassName, fqOtherClassName2, fqAnnotationName}),
- "@TestAnnotation(foo={1, " + otherClassName + ".class})");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter(fqAnnotationName);
- DeclarationAnnotationElementAdapter<String[]> daea =
- new ConversionDeclarationAnnotationElementAdapter<String[]>(
- daa, "foo", AnnotationStringArrayExpressionConverter.forTypes());
- JDTFieldAttribute field = idField(cu);
-
- Iterable<String> actual = ASTTools.resolveFullyQualifiedNames(daea.getExpression(field.getModifiedDeclaration(this.buildASTRoot(cu))));
-
- assertEquals(
- CollectionTools.list(new String[] {null, fqOtherClassName}),
- CollectionTools.list(actual));
- }
-
- public void testResolveFullyQualifiedNames3() throws Exception {
- final String otherClassName = "OtherClass";
- final String otherClassName2 = "OtherClass2";
- final String fqOtherClassName = "clazz.OtherClass";
- final String fqOtherClassName2 = "clazz.OtherClass2";
- final String annotationName = "TestAnnotation";
- final String fqAnnotationName = "annot.TestAnnotation";
-
- createClassAndMembers(otherClassName, "");
- createClassAndMembers(otherClassName2, "");
- createAnnotationAndMembers(annotationName, "Class[] foo();");
-
- ICompilationUnit cu = createTestType(
- new ArrayIterator<String>(new String[] {fqOtherClassName, fqOtherClassName2, fqAnnotationName}),
- "@TestAnnotation(foo={@TestAnnotation(), " + otherClassName + ".class}");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter(fqAnnotationName);
- DeclarationAnnotationElementAdapter<String[]> daea =
- new ConversionDeclarationAnnotationElementAdapter<String[]>(
- daa, "foo", AnnotationStringArrayExpressionConverter.forTypes());
- JDTFieldAttribute field = idField(cu);
-
- Iterable<String> actual = ASTTools.resolveFullyQualifiedNames(daea.getExpression(field.getModifiedDeclaration(this.buildASTRoot(cu))));
-
- assertEquals(
- CollectionTools.list(new String[] {null, fqOtherClassName}),
- CollectionTools.list(actual));
- }
-}
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/AnnotationTestCase.java b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/AnnotationTestCase.java
deleted file mode 100644
index 7eca5e2f1b..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/AnnotationTestCase.java
+++ /dev/null
@@ -1,1099 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2010 Oracle. 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:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.core.tests.internal.utility.jdt;
-
-import java.io.File;
-import java.util.Collections;
-import java.util.Iterator;
-import java.util.List;
-import junit.framework.TestCase;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
-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.Annotation;
-import org.eclipse.jdt.core.dom.ArrayInitializer;
-import org.eclipse.jdt.core.dom.BodyDeclaration;
-import org.eclipse.jdt.core.dom.BooleanLiteral;
-import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.dom.EnumConstantDeclaration;
-import org.eclipse.jdt.core.dom.EnumDeclaration;
-import org.eclipse.jdt.core.dom.Expression;
-import org.eclipse.jdt.core.dom.IExtendedModifier;
-import org.eclipse.jdt.core.dom.MarkerAnnotation;
-import org.eclipse.jdt.core.dom.MemberValuePair;
-import org.eclipse.jdt.core.dom.Name;
-import org.eclipse.jdt.core.dom.NormalAnnotation;
-import org.eclipse.jdt.core.dom.NumberLiteral;
-import org.eclipse.jdt.core.dom.PackageDeclaration;
-import org.eclipse.jdt.core.dom.SimpleName;
-import org.eclipse.jdt.core.dom.SimpleType;
-import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
-import org.eclipse.jdt.core.dom.StringLiteral;
-import org.eclipse.jdt.core.dom.TypeLiteral;
-import org.eclipse.jpt.common.core.internal.utility.jdt.ASTTools;
-import org.eclipse.jpt.common.core.internal.utility.jdt.JDTFieldAttribute;
-import org.eclipse.jpt.common.core.internal.utility.jdt.JDTMethodAttribute;
-import org.eclipse.jpt.common.core.internal.utility.jdt.JDTType;
-import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject;
-import org.eclipse.jpt.common.core.tests.internal.projects.TestJavaProject.SourceWriter;
-import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration;
-import org.eclipse.jpt.common.core.utility.jdt.Type;
-import org.eclipse.jpt.common.utility.internal.CollectionTools;
-import org.eclipse.jpt.common.utility.internal.iterators.ArrayIterator;
-import org.eclipse.jpt.common.utility.internal.iterators.EmptyIterator;
-import org.eclipse.jpt.common.utility.internal.iterators.SingleElementIterator;
-import org.eclipse.jpt.common.utility.tests.internal.TestTools;
-
-/**
- * Provide an easy(?) way to build an annotated source file.
- * The type must be created by calling one of the {@link #createTestType()}
- * methods before calling any of the various helper methods (i.e. the type is
- * <em>not</em> created during {@link #setUp()}).
- */
-@SuppressWarnings("nls")
-public abstract class AnnotationTestCase
- extends TestCase
-{
- protected TestJavaProject javaProject;
-
- public static final String CR = System.getProperty("line.separator");
- public static final String SEP = File.separator;
- public static final String PROJECT_NAME = "AnnotationTestProject";
- public static final String PACKAGE_NAME = "test";
- public static final String PACKAGE_NAME_ = PACKAGE_NAME + '.';
- public static final String PACKAGE_INFO_FILE_NAME = "package-info.java";
- public static final IPath PACKAGE_INFO_FILE_PATH = new Path("src" + SEP + PACKAGE_NAME + SEP + PACKAGE_INFO_FILE_NAME);
- public static final String TYPE_NAME = "AnnotationTestType";
- public static final String FULLY_QUALIFIED_TYPE_NAME = PACKAGE_NAME_ + TYPE_NAME;
- public static final String FILE_NAME = TYPE_NAME + ".java";
- public static final IPath FILE_PATH = new Path("src" + SEP + PACKAGE_NAME + SEP + FILE_NAME);
-
- public static final String[] EMPTY_STRING_ARRAY = new String[0];
-
-
- // ********** TestCase behavior **********
-
- protected AnnotationTestCase(String name) {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- this.javaProject = this.buildJavaProject(false); // false = no auto-build
- }
-
- protected TestJavaProject buildJavaProject(boolean autoBuild) throws Exception {
- return this.buildJavaProject(PROJECT_NAME, autoBuild);
- }
-
- protected TestJavaProject buildJavaProject(String projectName, boolean autoBuild) throws Exception {
- return new TestJavaProject(projectName, autoBuild);
- }
-
- @Override
- protected void tearDown() throws Exception {
-// this.dumpSource();
- this.deleteProject();
- TestTools.clear(this);
- super.tearDown();
- }
-
- protected void deleteProject() throws Exception {
- int i = 1;
- boolean deleted = false;
- while ( ! deleted) {
- try {
- this.javaProject.getProject().delete(true, true, null);
- deleted = true;
- } catch (CoreException ex) {
- if (i == 4) {
- throw new RuntimeException(this.getName() + " - unable to delete project", ex);
- }
- Thread.sleep(1000);
- i++;
- }
- }
- }
-
- protected void dumpSource(ICompilationUnit cu) throws Exception {
- System.out.println("*** " + this.getName() + " ****");
- System.out.println(this.getSource(cu));
- System.out.println();
- }
-
-
- // ********** package creation *********
-
- /**
- * create an un-annotated package-info
- */
- protected ICompilationUnit createTestPackageInfo() throws CoreException {
- return this.createTestPackageInfo(new DefaultAnnotationWriter());
- }
-
- /**
- * create an un-annotated package-info in a package the given name
- */
- protected ICompilationUnit createTestPackageInfo(String packageName) throws CoreException {
- return this.createTestPackageInfo(packageName, new DefaultAnnotationWriter());
- }
-
- /**
- * shortcut for simply adding an annotation to the package declaration
- */
- protected ICompilationUnit createTestPackageInfo(
- final String packageAnnotation, final String ... imports)
- throws CoreException {
-
- return createTestPackageInfo(
- new DefaultAnnotationWriter() {
- @Override
- public Iterator<String> imports() {
- return new ArrayIterator<String>(imports);
- }
-
- @Override
- public void appendPackageAnnotationTo(StringBuilder sb) {
- sb.append(packageAnnotation);
- }
- });
- }
-
- protected ICompilationUnit createTestPackageInfo(AnnotationWriter annotationWriter) throws CoreException {
- return this.createTestPackageInfo(PACKAGE_NAME, annotationWriter);
- }
-
- protected ICompilationUnit createTestPackageInfo(String packageName, AnnotationWriter annotationWriter) throws CoreException {
- return this.javaProject.createCompilationUnit(
- packageName, PACKAGE_INFO_FILE_NAME, this.createSourceWriter(annotationWriter, packageName, null));
- }
-
-
- // ********** type creation **********
-
- /**
- * create an un-annotated type
- */
- protected ICompilationUnit createTestType() throws CoreException {
- return this.createTestType(new DefaultAnnotationWriter());
- }
-
- /**
- * shortcut for simply adding an annotation to the 'id' field
- */
- protected ICompilationUnit createTestType(final String annotationImport, final String idFieldAnnotation) throws CoreException {
- return this.createTestType(new DefaultAnnotationWriter() {
- @Override
- public Iterator<String> imports() {
- return (annotationImport == null) ?
- EmptyIterator.<String>instance() :
- new SingleElementIterator<String>(annotationImport);
- }
- @Override
- public void appendIdFieldAnnotationTo(StringBuilder sb) {
- sb.append(idFieldAnnotation);
- }
- });
- }
-
- /**
- * shortcut for simply adding a fully-qualified annotation to the 'id' field
- */
- protected ICompilationUnit createTestType(final String idFieldAnnotation) throws CoreException {
- return this.createTestType(null, idFieldAnnotation);
- }
-
- protected ICompilationUnit createTestType(AnnotationWriter annotationWriter) throws CoreException {
- return this.javaProject.createCompilationUnit(PACKAGE_NAME, FILE_NAME, this.createSourceWriter(annotationWriter));
- }
-
- protected ICompilationUnit createTestType(String typeName, AnnotationWriter annotationWriter) throws CoreException {
- return this.javaProject.createCompilationUnit(PACKAGE_NAME, typeName + ".java", createSourceWriter(annotationWriter, typeName));
- }
-
- protected ICompilationUnit createTestType(String packageName, String fileName, String typeName, AnnotationWriter annotationWriter) throws CoreException {
- return this.javaProject.createCompilationUnit(packageName, fileName, this.createSourceWriter(annotationWriter, typeName));
- }
-
- protected SourceWriter createSourceWriter(AnnotationWriter annotationWriter) {
- return new AnnotatedSourceWriter(annotationWriter);
- }
-
- protected SourceWriter createSourceWriter(AnnotationWriter annotationWriter, String typeName) {
- return new AnnotatedSourceWriter(annotationWriter, typeName);
- }
-
- protected SourceWriter createSourceWriter(AnnotationWriter annotationWriter, String packageName, String typeName) {
- return new AnnotatedSourceWriter(annotationWriter, packageName, typeName);
- }
-
- protected ICompilationUnit createTestEnum(EnumAnnotationWriter annotationWriter) throws CoreException {
- return this.javaProject.createCompilationUnit(PACKAGE_NAME, FILE_NAME, this.createEnumSourceWriter(annotationWriter));
- }
-
- protected ICompilationUnit createTestEnum(String packageName, String fileName, String enumName, EnumAnnotationWriter annotationWriter) throws CoreException {
- return this.javaProject.createCompilationUnit(packageName, fileName, this.createEnumSourceWriter(annotationWriter, enumName));
- }
-
- protected SourceWriter createEnumSourceWriter(EnumAnnotationWriter annotationWriter) {
- return new EnumAnnotatedSourceWriter(annotationWriter);
- }
-
- protected SourceWriter createEnumSourceWriter(EnumAnnotationWriter annotationWriter, String enumName) {
- return new EnumAnnotatedSourceWriter(annotationWriter, enumName);
- }
-
- protected SourceWriter createEnumSourceWriter(EnumAnnotationWriter annotationWriter, String packageName, String enumName) {
- return new EnumAnnotatedSourceWriter(annotationWriter, packageName, enumName);
- }
-
- protected ICompilationUnit createAnnotatedEnumAndMembers(String enumName, String enumBody) throws Exception {
- StringBuilder sb = new StringBuilder();
- sb.append("package ").append(PACKAGE_NAME).append(";").append(CR);
- sb.append(CR);
- sb.append("import javax.xml.bind.annotation.XmlEnum;");
- sb.append(CR);
- sb.append(CR);
- sb.append("@XmlEnum");
- sb.append(CR);
- sb.append("public enum ").append(enumName).append(" { ").append(enumBody).append(" }");
-
- return this.javaProject.createCompilationUnit(PACKAGE_NAME, enumName + ".java", sb.toString());
- }
-
- /**
- * writes source for package-info java files
- */
- protected void appendSourceTo(
- StringBuilder sb, AnnotationWriter annotationWriter, String packageName) {
-
- annotationWriter.appendPackageAnnotationTo(sb);
- sb.append(CR);
- sb.append("package ").append(packageName).append(";").append(CR);
- sb.append(CR);
- for (Iterator<String> stream = annotationWriter.imports(); stream.hasNext(); ) {
- sb.append("import ").append(stream.next()).append(";").append(CR);
- }
- }
-
- /**
- * writes source for typical java files
- */
- protected void appendSourceTo(
- StringBuilder sb, AnnotationWriter annotationWriter,
- String packageName, String typeName) {
-
- sb.append("package ").append(packageName).append(";").append(CR);
- sb.append(CR);
- for (Iterator<String> stream = annotationWriter.imports(); stream.hasNext(); ) {
- sb.append("import ");
- sb.append(stream.next());
- sb.append(";");
- sb.append(CR);
- }
- sb.append(CR);
- annotationWriter.appendTypeAnnotationTo(sb);
- sb.append(CR);
- sb.append("public class ").append(typeName).append(" ");
- annotationWriter.appendExtendsImplementsTo(sb);
- sb.append("{").append(CR);
- sb.append(CR);
- sb.append(" ");
- annotationWriter.appendIdFieldAnnotationTo(sb);
- sb.append(CR);
- sb.append(" private int id;").append(CR);
- sb.append(CR);
- sb.append(" ");
- annotationWriter.appendNameFieldAnnotationTo(sb);
- sb.append(CR);
- sb.append(" private String name;").append(CR);
- sb.append(CR);
- sb.append(" ");
- annotationWriter.appendGetIdMethodAnnotationTo(sb);
- sb.append(CR);
- sb.append(" public int getId() {").append(CR);
- sb.append(" return this.id;").append(CR);
- sb.append(" }").append(CR);
- sb.append(CR);
- sb.append(" ");
- annotationWriter.appendSetIdMethodAnnotationTo(sb);
- sb.append(CR);
- sb.append(" public void setId(int id) {").append(CR);
- sb.append(" this.id = id;").append(CR);
- sb.append(" }").append(CR);
- sb.append(CR);
- sb.append(" ");
- annotationWriter.appendGetNameMethodAnnotationTo(sb);
- sb.append(CR);
- sb.append(" public String getName() {").append(CR);
- sb.append(" return this.name;").append(CR);
- sb.append(" }").append(CR);
- sb.append(CR);
- sb.append(" ");
- annotationWriter.appendSetNameMethodAnnotationTo(sb);
- sb.append(CR);
- sb.append(" public void setTestField(String testField) {").append(CR);
- sb.append(" this.testField = testField;").append(CR);
- sb.append(" }").append(CR);
- sb.append(CR);
- annotationWriter.appendMemberTypeTo(sb);
- sb.append(CR);
- sb.append("}").append(CR);
- annotationWriter.appendTopLevelTypesTo(sb);
- sb.append(CR);
- }
-
-
- /**
- * writes source for typical java enum files
- */
- protected void appendEnumSourceTo(
- StringBuilder sb, EnumAnnotationWriter annotationWriter,
- String packageName, String enumName) {
-
- sb.append("package ").append(packageName).append(";").append(CR);
- sb.append(CR);
- for (Iterator<String> stream = annotationWriter.imports(); stream.hasNext(); ) {
- sb.append("import ");
- sb.append(stream.next());
- sb.append(";");
- sb.append(CR);
- }
- sb.append(CR);
- annotationWriter.appendEnumAnnotationTo(sb);
- sb.append(CR);
- sb.append("public enum ").append(enumName).append(" {").append(CR);
- sb.append(CR);
- sb.append(" ");
- annotationWriter.appendSundayEnumConstantAnnotationTo(sb);
- sb.append(CR);
- sb.append(" SUNDAY, ").append(CR);
- sb.append(CR);
- sb.append(" ");
- annotationWriter.appendMondayEnumConstantAnnotationTo(sb);
- sb.append(CR);
- sb.append(" MONDAY").append(CR);
- sb.append(CR);
- sb.append("}").append(CR);
- sb.append(CR);
- }
-
-
- // ********** queries **********
-
- protected TestJavaProject getJavaProject() {
- return this.javaProject;
- }
-
- protected JDTType testType(ICompilationUnit cu) {
- return this.buildType(TYPE_NAME, cu);
- }
-
- protected JDTType buildType(String name, ICompilationUnit cu) {
- return this.buildType(name, 1, cu);
- }
-
- protected JDTType buildType(String name, int occurrence, ICompilationUnit cu) {
- return this.buildType(null, name, occurrence, cu);
- }
-
- protected JDTType buildType(Type declaringType, String name, int occurrence, ICompilationUnit cu) {
- return new JDTType(declaringType, name, occurrence, cu);
- }
-
- protected JDTFieldAttribute idField(ICompilationUnit cu) {
- return this.buildField("id", cu);
- }
-
- protected JDTFieldAttribute nameField(ICompilationUnit cu) {
- return this.buildField("name", cu);
- }
-
- protected JDTFieldAttribute buildField(String name, ICompilationUnit cu) {
- return this.buildField(name, 1, cu);
- }
-
- protected JDTFieldAttribute buildField(String name, int occurrence, ICompilationUnit cu) {
- return this.buildField(this.testType(cu), name, occurrence, cu);
- }
-
- protected JDTFieldAttribute buildField(Type declaringType, String name, int occurrence, ICompilationUnit cu) {
- return new JDTFieldAttribute(declaringType, name, occurrence, cu);
- }
-
- protected JDTMethodAttribute idGetMethod(ICompilationUnit cu) {
- return this.buildMethod("getId", cu);
- }
-
- protected JDTMethodAttribute idSetMethod(ICompilationUnit cu) {
- return this.buildMethod("setId", new String[] {"int"}, cu);
- }
-
- protected JDTMethodAttribute nameGetMethod(ICompilationUnit cu) {
- return this.buildMethod("getName", cu);
- }
-
- protected JDTMethodAttribute buildMethod(String name, ICompilationUnit cu) {
- return this.buildMethod(name, EMPTY_STRING_ARRAY, cu);
- }
-
- protected JDTMethodAttribute buildMethod(String name, String[] parameterTypeNames, ICompilationUnit cu) {
- return this.buildMethod(name, parameterTypeNames, 1, cu);
- }
-
- protected JDTMethodAttribute buildMethod(String name, String[] parameterTypeNames, int occurrence, ICompilationUnit cu) {
- return new JDTMethodAttribute(this.testType(cu), name, parameterTypeNames, occurrence, cu);
- }
-
- protected JDTMethodAttribute buildMethod(Type declaringType, String name, String[] parameterTypeNames, int occurrence, ICompilationUnit cu) {
- return new JDTMethodAttribute(declaringType, name, parameterTypeNames, occurrence, cu);
- }
-
- protected String getSource(ICompilationUnit cu) throws JavaModelException {
- return cu.getBuffer().getContents();
- }
-
- protected CompilationUnit buildASTRoot(ICompilationUnit cu) {
- return ASTTools.buildASTRoot(cu);
- }
-
-
- // ********** test validation **********
-
- protected void assertSourceContains(String s, ICompilationUnit cu) throws JavaModelException {
- String source = this.getSource(cu);
- boolean found = source.indexOf(s) > -1;
- if ( ! found) {
- String msg = "source does not contain the expected string: " + s + " (see System console)";
- System.out.println("*** " + this.getName() + " ****");
- System.out.println(msg);
- System.out.println(source);
- System.out.println();
- fail(msg);
- }
- }
-
- protected void assertSourceDoesNotContain(String s, ICompilationUnit cu) throws JavaModelException {
- String source = this.getSource(cu);
- int pos = source.indexOf(s);
- if (pos != -1) {
- String msg = "unexpected string in source (position: " + pos + "): " + s + " (see System console)";
- System.out.println("*** " + this.getName() + " ****");
- System.out.println(msg);
- System.out.println(source);
- System.out.println();
- fail(msg);
- }
- }
-
-
- // ********** manipulate annotations **********
-
- /**
- * Return the *first* member value pair for the specified annotation element
- * with the specified name.
- * Return null if the annotation has no such element.
- */
- protected MemberValuePair memberValuePair(NormalAnnotation annotation, String elementName) {
- for (MemberValuePair pair : this.values(annotation)) {
- if (pair.getName().getFullyQualifiedName().equals(elementName)) {
- return pair;
- }
- }
- return null;
- }
-
- /**
- * minimize the scope of the suppressed warnings
- */
- @SuppressWarnings("unchecked")
- protected List<MemberValuePair> values(NormalAnnotation na) {
- return na.values();
- }
-
- /**
- * minimize the scope of the suppressed warnings
- */
- @SuppressWarnings("unchecked")
- protected List<EnumConstantDeclaration> enumConstants(EnumDeclaration ed) {
- return ed.enumConstants();
- }
-
- /**
- * check for null member value pair
- */
- protected Expression value_(MemberValuePair pair) {
- return (pair == null) ? null : pair.getValue();
- }
-
- /**
- * Return the value of the *first* annotation element
- * with the specified name.
- * Return null if the annotation has no such element.
- */
- protected Expression annotationElementValue(NormalAnnotation annotation, String elementName) {
- return this.value_(this.memberValuePair(annotation, elementName));
- }
-
- /**
- * Return the value of the *first* annotation element
- * with the specified name.
- * Return null if the annotation has no such element.
- */
- protected Expression annotationElementValue(SingleMemberAnnotation annotation, String elementName) {
- return elementName.equals("value") ? annotation.getValue() : null;
- }
-
- /**
- * Return the value of the *first* annotation element
- * with the specified name.
- * Return null if the annotation has no such element.
- * (An element name of "value" will return the value of a single
- * member annotation.)
- */
- protected Expression annotationElementValue(Annotation annotation, String elementName) {
- if (annotation.isNormalAnnotation()) {
- return this.annotationElementValue((NormalAnnotation) annotation, elementName);
- }
- if (annotation.isSingleMemberAnnotation()) {
- return this.annotationElementValue((SingleMemberAnnotation) annotation, elementName);
- }
- return null;
- }
-
- protected ArrayInitializer newArrayInitializer(AST ast, Expression... expressions) {
- ArrayInitializer arrayInitializer = ast.newArrayInitializer();
- for (Expression expression : expressions) {
- arrayInitializer.expressions().add(expression);
- }
- return arrayInitializer;
- }
-
- /**
- * Build a number literal and set its initial value to the specified literal.
- */
- protected NumberLiteral newNumberLiteral(AST ast, int value) {
- return ast.newNumberLiteral(Integer.toString(value));
- }
-
- /**
- * Build a number literal and set its initial value to the specified literal.
- */
- protected BooleanLiteral newBooleanLiteral(AST ast, boolean value) {
- return ast.newBooleanLiteral(value);
- }
-
- /**
- * Build a string literal and set its initial value.
- */
- protected StringLiteral newStringLiteral(AST ast, String value) {
- StringLiteral stringLiteral = ast.newStringLiteral();
- stringLiteral.setLiteralValue(value);
- return stringLiteral;
- }
-
- protected TypeLiteral newTypeLiteral(AST ast, String typeName) {
- TypeLiteral typeLiteral = ast.newTypeLiteral();
- typeLiteral.setType(this.newSimpleType(ast, typeName));
- return typeLiteral;
- }
-
- protected SimpleType newSimpleType(AST ast, String typeName) {
- return this.newSimpleType(ast, ast.newName(typeName));
- }
-
- protected SimpleType newSimpleType(AST ast, Name typeName) {
- return ast.newSimpleType(typeName);
- }
-
- protected MemberValuePair newMemberValuePair(AST ast, SimpleName name, Expression value) {
- MemberValuePair pair = ast.newMemberValuePair();
- pair.setName(name);
- pair.setValue(value);
- return pair;
- }
-
- protected MemberValuePair newMemberValuePair(AST ast, String name, Expression value) {
- return this.newMemberValuePair(ast, ast.newSimpleName(name), value);
- }
-
- protected MemberValuePair newMemberValuePair(AST ast, String name, String value) {
- return this.newMemberValuePair(ast, name, this.newStringLiteral(ast, value));
- }
-
- protected MemberValuePair newMemberValuePair(AST ast, String name, int value) {
- return this.newMemberValuePair(ast, name, this.newNumberLiteral(ast, value));
- }
-
- protected MemberValuePair newMemberValuePair(AST ast, String name, boolean value) {
- return this.newMemberValuePair(ast, name, this.newBooleanLiteral(ast, value));
- }
-
- protected EnumConstantDeclaration newEnumConstantDeclaration(AST ast, String enumConstantName) {
- EnumConstantDeclaration enumConstantDeclaration = ast.newEnumConstantDeclaration();
- enumConstantDeclaration.setName(ast.newSimpleName(enumConstantName));
- return enumConstantDeclaration;
- }
- /**
- * Add the specified member value pair to the specified annotation.
- * Return the resulting annotation.
- */
- protected NormalAnnotation addMemberValuePair(NormalAnnotation annotation, MemberValuePair pair) {
- this.values(annotation).add(pair);
- return annotation;
- }
-
- /**
- * Add the specified member value pair to the specified annotation.
- * Return the resulting annotation.
- */
- protected NormalAnnotation addMemberValuePair(NormalAnnotation annotation, String name, int value) {
- return this.addMemberValuePair(annotation, this.newMemberValuePair(annotation.getAST(), name, value));
- }
-
- /**
- * Add the specified member value pair to the specified annotation.
- * Return the resulting annotation.
- */
- protected NormalAnnotation addMemberValuePair(NormalAnnotation annotation, String name, String value) {
- return this.addMemberValuePair(annotation, this.newMemberValuePair(annotation.getAST(), name, value));
- }
-
- /**
- * Add the specified member value pair to the marker annotation
- * by first replacing it with a normal annotation.
- * Return the resulting normal annotation.
- */
- protected NormalAnnotation addMemberValuePair(MarkerAnnotation annotation, String name, String value) {
- NormalAnnotation normalAnnotation = this.replaceMarkerAnnotation(annotation);
- this.addMemberValuePair(normalAnnotation, this.newMemberValuePair(annotation.getAST(), name, value));
- return normalAnnotation;
- }
-
- protected NormalAnnotation addMemberValuePair(MarkerAnnotation annotation, String name, boolean value) {
- NormalAnnotation normalAnnotation = this.replaceMarkerAnnotation(annotation);
- this.addMemberValuePair(normalAnnotation, this.newMemberValuePair(annotation.getAST(), name, value));
- return normalAnnotation;
- }
-
- /**
- * Add the specified member value pair to the marker annotation
- * by first replacing it with a normal annotation.
- * Return the resulting normal annotation.
- */
- protected NormalAnnotation addMemberValuePair(MarkerAnnotation annotation, MemberValuePair pair) {
- NormalAnnotation normalAnnotation = this.replaceMarkerAnnotation(annotation);
- return this.addMemberValuePair(normalAnnotation, pair);
- }
-
- protected void setMemberValuePair(ModifiedDeclaration declaration, String annotationName, String value) {
- setMemberValuePair(declaration, annotationName, "value", value);
- }
-
- protected void setMemberValuePair(ModifiedDeclaration declaration, String annotationName, String elementName, String value) {
- Annotation annotation = declaration.getAnnotationNamed(annotationName);
- if (annotation == null) {
- annotation = addNormalAnnotation(declaration.getDeclaration(), annotationName);
- }
- else if (annotation instanceof MarkerAnnotation) {
- annotation = replaceMarkerAnnotation((MarkerAnnotation) annotation);
- }
- setMemberValuePair((NormalAnnotation) annotation, elementName, value);
- }
-
- protected void setMemberValuePair(NormalAnnotation annotation, String elementName, String value) {
- MemberValuePair memberValuePair = this.memberValuePair(annotation, elementName);
- if (memberValuePair == null) {
- addMemberValuePair(annotation, elementName, value);
- }
- else {
- memberValuePair.setValue(newStringLiteral(annotation.getAST(), value));
- }
- }
-
- protected void removeMemberValuePair(ModifiedDeclaration declaration, String annotationName) {
- removeMemberValuePair(declaration, annotationName, "value");
- }
-
- protected void removeMemberValuePair(ModifiedDeclaration declaration, String annotationName, String elementName) {
- NormalAnnotation annotation = (NormalAnnotation) declaration.getAnnotationNamed(annotationName);
- values(annotation).remove(memberValuePair(annotation, elementName));
- }
-
- protected void setEnumMemberValuePair(ModifiedDeclaration declaration, String annotationName, String enumValue) {
- NormalAnnotation annotation = (NormalAnnotation) declaration.getAnnotationNamed(annotationName);
- if (annotation == null) {
- annotation = addNormalAnnotation(declaration.getDeclaration(), annotationName);
- }
- this.setEnumMemberValuePair(annotation, "value", enumValue);
- }
-
- protected void setEnumMemberValuePair(NormalAnnotation annotation, String elementName, String enumValue) {
- MemberValuePair memberValuePair = this.memberValuePair(annotation, elementName);
- if (memberValuePair == null) {
- this.addEnumMemberValuePair(annotation, elementName, enumValue);
- }
- else {
- memberValuePair.setValue(annotation.getAST().newName(enumValue));
- }
- }
-
- protected void addEnumMemberValuePair(MarkerAnnotation markerAnnotation, String elementName, String value) {
- this.addEnumMemberValuePair(this.replaceMarkerAnnotation(markerAnnotation), elementName, value);
- }
-
- protected void addEnumMemberValuePair(NormalAnnotation annotation, String elementName, String value) {
- this.addMemberValuePair(annotation, elementName, annotation.getAST().newName(value));
- }
-
- protected void addMemberValuePair(NormalAnnotation annotation, String elementName, Expression value) {
- MemberValuePair memberValuePair = this.newMemberValuePair(annotation.getAST(), elementName, value);
- this.addMemberValuePair(annotation, memberValuePair);
- }
-
- protected void addMemberValuePair(MarkerAnnotation annotation, String elementName, Expression value) {
- MemberValuePair memberValuePair = this.newMemberValuePair(annotation.getAST(), elementName, value);
- this.addMemberValuePair(annotation, memberValuePair);
- }
-
- protected void addEnumConstant(EnumDeclaration enumDeclaration, String enumConstantName) {
- EnumConstantDeclaration enumConstantDeclaration = this.newEnumConstantDeclaration(enumDeclaration.getAST(), enumConstantName);
- this.enumConstants(enumDeclaration).add(enumConstantDeclaration);
- }
-
- protected void removeEnumConstant(EnumDeclaration enumDeclaration, String enumConstantName) {
- List<EnumConstantDeclaration> enumConstantsList = this.enumConstants(enumDeclaration);
- for (EnumConstantDeclaration constant : enumConstantsList) {
- if (constant.getName().getFullyQualifiedName().equals(enumConstantName)) {
- enumConstantsList.remove(constant);
- break;
- }
- }
- }
-
- protected void changeEnumConstantName(EnumDeclaration enumDeclaration, String oldEnumConstantName, String newEnumConstantName) {
- List<EnumConstantDeclaration> enumConstantsList = this.enumConstants(enumDeclaration);
- for (EnumConstantDeclaration constant : enumConstantsList) {
- if (constant.getName().getFullyQualifiedName().equals(oldEnumConstantName)) {
- this.changeEnumConstantName(constant, newEnumConstantName);
- break;
- }
- }
- }
-
- protected void changeEnumConstantName(EnumConstantDeclaration enumConstantDeclaration, String newEnumConstantName) {
- enumConstantDeclaration.setName(enumConstantDeclaration.getAST().newSimpleName(newEnumConstantName));
- }
-
- /**
- * Add the array element to an annotation that is either a normal annotation or a marker annotation.
- * If it is a marker annotation first make it a normal annotation.
- */
- protected void addArrayElement(ModifiedDeclaration declaration, String annotationName, int index, String elementName, Expression arrayElement) {
- Annotation annotation = declaration.getAnnotationNamed(annotationName);
- NormalAnnotation normalAnnotation;
- if (annotation == null) {
- normalAnnotation = this.addNormalAnnotation(declaration.getDeclaration(), annotationName);
- }
- else if (annotation.getNodeType() == ASTNode.MARKER_ANNOTATION) {
- normalAnnotation = this.replaceMarkerAnnotation((MarkerAnnotation) annotation);
- }
- else {
- normalAnnotation = (NormalAnnotation) annotation;
- }
- this.addArrayElement(normalAnnotation, index, elementName, arrayElement);
- }
-
- /**
- * Add the array element to the given normal annotation's element named elementName.
- * Add a new member value pair if one does not exist.
- * If the member value pair exists but the value is not yet an array, make it an array.
- */
- protected void addArrayElement(NormalAnnotation annotation, int index, String elementName, Expression arrayElement) {
- MemberValuePair pair = this.memberValuePair(annotation, elementName);
- if (pair == null) {
- pair = this.newMemberValuePair(annotation.getAST(), elementName, arrayElement);
- this.addMemberValuePair(annotation, pair);
- }
- else {
- Expression value = pair.getValue();
- if (value.getNodeType() == ASTNode.ARRAY_INITIALIZER) {
- this.expressions((ArrayInitializer) value).add(index, arrayElement);
- }
- else {
- ArrayInitializer arrayInitializer = annotation.getAST().newArrayInitializer();
- pair.setValue(arrayInitializer);
- this.expressions(arrayInitializer).add(value);
- this.expressions(arrayInitializer).add(index, arrayElement);
- }
- }
- }
-
- /**
- * This assumes an element with name elementName exists with an array as its value.
- * Move the array element at sourceIndex to the targetIndex
- */
- protected void moveArrayElement(NormalAnnotation annotation, String elementName, int targetIndex, int sourceIndex) {
- MemberValuePair pair = this.memberValuePair(annotation, elementName);
- ArrayInitializer array = (ArrayInitializer) pair.getValue();
- CollectionTools.move(this.expressions(array), targetIndex, sourceIndex);
- }
-
- /**
- * This assumes an element with name elementName exists with potentially an array as its value.
- * If the value is not an array, then the member value pair is removed.
- * If the array element is removed and there is only 1 array element left, the array itself is removed
- * and the remaining element is set as the value of the member value pair
- */
- protected void removeArrayElement(NormalAnnotation annotation, String elementName, int index) {
- MemberValuePair pair = this.memberValuePair(annotation, elementName);
- if (pair.getValue().getNodeType() == ASTNode.ARRAY_INITIALIZER) {
- ArrayInitializer array = (ArrayInitializer) pair.getValue();
- this.expressions(array).remove(index);
- if (this.expressions(array).size() == 1) {
- pair.setValue(this.expressions(array).remove(0));
- }
- }
- else {
- this.values(annotation).remove(pair);
- }
- }
-
- /**
- * Replace the given marker annotation with a normal annotation.
- * Return the resulting normal annotation.
- */
- protected NormalAnnotation replaceMarkerAnnotation(MarkerAnnotation annotation) {
- List<IExtendedModifier> annotations = this.annotations(annotation.getParent());
- int index = annotations.indexOf(annotation);
- NormalAnnotation normalAnnotation = newNormalAnnotation(annotation.getAST(), annotation.getTypeName().getFullyQualifiedName());
- annotations.set(index, normalAnnotation);
- return normalAnnotation;
- }
-
- /**
- * Build a normal annotation and set its name.
- */
- protected NormalAnnotation newNormalAnnotation(AST ast, String name) {
- NormalAnnotation annotation = ast.newNormalAnnotation();
- annotation.setTypeName(ast.newName(name));
- return annotation;
- }
-
- /**
- * Add the normal annotation to the given AST node.
- * This should be a PackageDeclaration or a BodyDeclaration.
- * Return the resulting normal annotation.
- */
- protected NormalAnnotation addNormalAnnotation(ASTNode astNode, String name) {
- NormalAnnotation annotation = this.newNormalAnnotation(astNode.getAST(), name);
- this.addAnnotation(astNode, annotation);
- return annotation;
- }
-
- /**
- * Add the annotation to the given AST node.
- * This should be a PackageDeclaration or a BodyDeclaration.
- */
- protected void addAnnotation(ASTNode astNode, Annotation annotation) {
- this.annotations(astNode).add(annotation);
- }
-
- /**
- * Build a marker annotation and set its name.
- */
- protected MarkerAnnotation newMarkerAnnotation(AST ast, String name) {
- MarkerAnnotation annotation = ast.newMarkerAnnotation();
- annotation.setTypeName(ast.newName(name));
- return annotation;
- }
-
- /**
- * Add the normal annotation to the given AST node.
- * This should be a PackageDeclaration or a BodyDeclaration.
- * Return the resulting normal annotation.
- */
- protected MarkerAnnotation addMarkerAnnotation(ASTNode astNode, String name) {
- MarkerAnnotation annotation = this.newMarkerAnnotation(astNode.getAST(), name);
- this.addAnnotation(astNode, annotation);
- return annotation;
- }
-
- /**
- * Remove the annotation with the specified name
- */
- protected void removeAnnotation(ModifiedDeclaration declaration, String name) {
- this.removeAnnotation(declaration.getDeclaration(), declaration.getAnnotationNamed(name));
- }
-
- /**
- * Remove the specified annotation from the AST node.
- * This should be a PackageDeclaration or a BodyDeclaration.
- */
- protected void removeAnnotation(ASTNode astNode, Annotation annotation) {
- this.annotations(astNode).remove(annotation);
- }
-
- /**
- * minimize the scope of the suppressed warnings
- */
- @SuppressWarnings("unchecked")
- protected List<IExtendedModifier> annotations(ASTNode astNode) {
- if (astNode instanceof BodyDeclaration) {
- return ((BodyDeclaration) astNode).modifiers();
- }
- else if (astNode instanceof PackageDeclaration) {
- return ((PackageDeclaration) astNode).annotations();
- }
- return Collections.emptyList();
- }
-
- /**
- * minimize the scope of the suppressed warnings
- */
- @SuppressWarnings("unchecked")
- protected List<Expression> expressions(ArrayInitializer arrayInitializer) {
- return arrayInitializer.expressions();
- }
-
-
- // ********** member classes **********
-
- public interface AnnotationWriter {
- Iterator<String> imports();
- void appendPackageAnnotationTo(StringBuilder sb);
- void appendTypeAnnotationTo(StringBuilder sb);
- void appendExtendsImplementsTo(StringBuilder sb);
- void appendIdFieldAnnotationTo(StringBuilder sb);
- void appendNameFieldAnnotationTo(StringBuilder sb);
- void appendGetIdMethodAnnotationTo(StringBuilder sb);
- void appendSetIdMethodAnnotationTo(StringBuilder sb);
- void appendGetNameMethodAnnotationTo(StringBuilder sb);
- void appendSetNameMethodAnnotationTo(StringBuilder sb);
- void appendMemberTypeTo(StringBuilder sb);
- void appendTopLevelTypesTo(StringBuilder sb);
- }
-
- public static class DefaultAnnotationWriter implements AnnotationWriter {
- public Iterator<String> imports() {return EmptyIterator.instance();}
- public void appendPackageAnnotationTo(StringBuilder sb) {/* do nothing */}
- public void appendTypeAnnotationTo(StringBuilder sb) {/* do nothing */}
- public void appendExtendsImplementsTo(StringBuilder sb) {/* do nothing */}
- public void appendIdFieldAnnotationTo(StringBuilder sb) {/* do nothing */}
- public void appendNameFieldAnnotationTo(StringBuilder sb) {/* do nothing */}
- public void appendGetIdMethodAnnotationTo(StringBuilder sb) {/* do nothing */}
- public void appendSetIdMethodAnnotationTo(StringBuilder sb) {/* do nothing */}
- public void appendGetNameMethodAnnotationTo(StringBuilder sb) {/* do nothing */}
- public void appendSetNameMethodAnnotationTo(StringBuilder sb) {/* do nothing */}
- public void appendMemberTypeTo(StringBuilder sb) {/* do nothing */}
- public void appendTopLevelTypesTo(StringBuilder sb) {/* do nothing */}
- }
-
- public static class AnnotationWriterWrapper implements AnnotationWriter {
- private final AnnotationWriter aw;
- public AnnotationWriterWrapper(AnnotationWriter aw) {
- super();
- this.aw = aw;
- }
- public Iterator<String> imports() {return this.aw.imports();}
- public void appendPackageAnnotationTo(StringBuilder sb) {this.aw.appendPackageAnnotationTo(sb);}
- public void appendTypeAnnotationTo(StringBuilder sb) {this.aw.appendTypeAnnotationTo(sb);}
- public void appendExtendsImplementsTo(StringBuilder sb) {this.aw.appendExtendsImplementsTo(sb);}
- public void appendIdFieldAnnotationTo(StringBuilder sb) {this.aw.appendIdFieldAnnotationTo(sb);}
- public void appendNameFieldAnnotationTo(StringBuilder sb) {this.aw.appendNameFieldAnnotationTo(sb);}
- public void appendGetIdMethodAnnotationTo(StringBuilder sb) {this.aw.appendGetIdMethodAnnotationTo(sb);}
- public void appendSetIdMethodAnnotationTo(StringBuilder sb) {this.aw.appendSetIdMethodAnnotationTo(sb);}
- public void appendGetNameMethodAnnotationTo(StringBuilder sb) {this.aw.appendGetNameMethodAnnotationTo(sb);}
- public void appendSetNameMethodAnnotationTo(StringBuilder sb) {this.aw.appendSetNameMethodAnnotationTo(sb);}
- public void appendMemberTypeTo(StringBuilder sb) {this.aw.appendMemberTypeTo(sb);}
- public void appendTopLevelTypesTo(StringBuilder sb) {this.aw.appendTopLevelTypesTo(sb);}
- }
-
- public class AnnotatedSourceWriter
- implements SourceWriter {
-
- private AnnotationWriter annotationWriter;
- private String packageName;
- private String typeName;
-
- public AnnotatedSourceWriter(AnnotationWriter annotationWriter) {
- this(annotationWriter, TYPE_NAME);
- }
-
- public AnnotatedSourceWriter(AnnotationWriter annotationWriter, String typeName) {
- this(annotationWriter, PACKAGE_NAME, typeName);
- }
-
- public AnnotatedSourceWriter(AnnotationWriter annotationWriter, String packageName, String typeName) {
- super();
- this.annotationWriter = annotationWriter;
- this.packageName = packageName;
- this.typeName = typeName;
- }
-
- public void appendSourceTo(StringBuilder sb) {
- if (this.typeName != null) {
- AnnotationTestCase.this.appendSourceTo(sb, this.annotationWriter, this.packageName, this.typeName);
- }
- else {
- AnnotationTestCase.this.appendSourceTo(sb, this.annotationWriter, this.packageName);
- }
- }
- }
-
- public interface EnumAnnotationWriter {
- Iterator<String> imports();
- void appendPackageAnnotationTo(StringBuilder sb);
- void appendEnumAnnotationTo(StringBuilder sb);
- void appendSundayEnumConstantAnnotationTo(StringBuilder sb);
- void appendMondayEnumConstantAnnotationTo(StringBuilder sb);
- }
-
- public static class DefaultEnumAnnotationWriter implements EnumAnnotationWriter {
- public Iterator<String> imports() {return EmptyIterator.instance();}
- public void appendPackageAnnotationTo(StringBuilder sb) {/* do nothing */}
- public void appendEnumAnnotationTo(StringBuilder sb) {/* do nothing */}
- public void appendSundayEnumConstantAnnotationTo(StringBuilder sb) {/* do nothing */}
- public void appendMondayEnumConstantAnnotationTo(StringBuilder sb) {/* do nothing */}
- }
-
- public class EnumAnnotatedSourceWriter
- implements SourceWriter {
-
- private EnumAnnotationWriter annotationWriter;
- private String packageName;
- private String enumName;
-
- public EnumAnnotatedSourceWriter(EnumAnnotationWriter annotationWriter) {
- this(annotationWriter, TYPE_NAME);
- }
-
- public EnumAnnotatedSourceWriter(EnumAnnotationWriter annotationWriter, String enumName) {
- this(annotationWriter, PACKAGE_NAME, enumName);
- }
-
- public EnumAnnotatedSourceWriter(EnumAnnotationWriter annotationWriter, String packageName, String enumName) {
- super();
- this.annotationWriter = annotationWriter;
- this.packageName = packageName;
- this.enumName = enumName;
- }
-
- public void appendSourceTo(StringBuilder sb) {
- AnnotationTestCase.this.appendEnumSourceTo(sb, this.annotationWriter, this.packageName, this.enumName);
- }
- }
-
-}
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/CombinationIndexedDeclarationAnnotationAdapterTests.java b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/CombinationIndexedDeclarationAnnotationAdapterTests.java
deleted file mode 100644
index b4f92fa9a7..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/CombinationIndexedDeclarationAnnotationAdapterTests.java
+++ /dev/null
@@ -1,744 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2010 Oracle. 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:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.core.tests.internal.utility.jdt;
-
-import org.eclipse.core.runtime.Platform;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.dom.Annotation;
-import org.eclipse.jdt.core.dom.NormalAnnotation;
-import org.eclipse.jdt.core.dom.StringLiteral;
-import org.eclipse.jpt.common.core.internal.utility.jdt.CombinationIndexedDeclarationAnnotationAdapter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.ElementAnnotationAdapter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.ElementIndexedAnnotationAdapter;
-import org.eclipse.jpt.common.core.utility.jdt.AnnotationAdapter;
-import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationAdapter;
-import org.eclipse.jpt.common.core.utility.jdt.IndexedAnnotationAdapter;
-import org.eclipse.jpt.common.core.utility.jdt.IndexedDeclarationAnnotationAdapter;
-import org.osgi.framework.Version;
-
-@SuppressWarnings("nls")
-public class CombinationIndexedDeclarationAnnotationAdapterTests extends AnnotationTestCase {
-
- public CombinationIndexedDeclarationAnnotationAdapterTests(String name) {
- super(name);
- }
-
- private void createAnnotationAndMembers(String annotationName, String annotationBody) throws Exception {
- this.javaProject.createCompilationUnit("annot", annotationName + ".java", "public @interface " + annotationName + " { " + annotationBody + " }");
- }
-
- public void testAnnotation1() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumn(name=\"ADDRESS_ID\")");
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", 0);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
- assertEquals("annot.JoinColumn", annotation.getTypeName().getFullyQualifiedName());
- assertTrue(annotation.isNormalAnnotation());
- }
-
- public void testAnnotation2() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumn(name=\"ADDRESS_ID\")");
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", 1);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
- }
-
- public void testAnnotation3() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns(@annot.JoinColumn(name=\"ADDRESS_ID\"))");
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", 0);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
- assertEquals("annot.JoinColumn", annotation.getTypeName().getFullyQualifiedName());
- assertTrue(annotation.isNormalAnnotation());
- }
-
- public void testAnnotation4() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns(@annot.JoinColumn(name=\"ADDRESS_ID\"))");
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", 1);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
- }
-
- public void testAnnotation5() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns({@annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\")})");
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", 1);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
- assertEquals("annot.JoinColumn", annotation.getTypeName().getFullyQualifiedName());
- assertTrue(annotation.isNormalAnnotation());
- String value = ((StringLiteral) this.values((NormalAnnotation) annotation).get(0).getValue()).getLiteralValue();
- assertEquals("ADDRESS_ID2", value);
- }
-
- public void testAnnotation6() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns({@annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\")})");
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 1);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
- }
-
- public void testAnnotation7() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\")})");
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 1);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
- assertEquals("annot.JoinColumn", annotation.getTypeName().getFullyQualifiedName());
- assertTrue(annotation.isNormalAnnotation());
- String value = ((StringLiteral) this.values(((NormalAnnotation) annotation)).get(0).getValue()).getLiteralValue();
- assertEquals("ADDRESS_ID2", value);
- }
-
- public void testAnnotation8() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\")})");
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", 1);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
- }
-
- public void testRemoveAnnotation1() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumn(name=\"ADDRESS_ID\")");
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", 0);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- aa.removeAnnotation();
- this.assertSourceDoesNotContain("JoinColumn", cu);
- }
-
- public void testRemoveAnnotation2() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns(@annot.JoinColumn(name=\"ADDRESS_ID\"))");
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", 0);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- aa.removeAnnotation();
- this.assertSourceDoesNotContain("ADDRESS_ID", cu);
- }
-
- public void testRemoveAnnotation3() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns({@annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\")})");
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", 1);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- aa.removeAnnotation();
- this.assertSourceDoesNotContain("JoinColumns", cu);
- this.assertSourceDoesNotContain("ADDRESS_ID2", cu);
- this.assertSourceContains("@JoinColumn(name=\"ADDRESS_ID1\")", cu);
- }
-
- public void testRemoveAnnotation4() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\")})");
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 1);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- aa.removeAnnotation();
- this.assertSourceDoesNotContain("JoinColumns", cu);
- this.assertSourceDoesNotContain("ADDRESS_ID2", cu);
- this.assertSourceContains("@JoinColumn(name=\"ADDRESS_ID1\")", cu);
- }
-
- public void testRemoveAnnotation5() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "String comment(); JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns(comment=\"test\",columns={@annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\")})");
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 1);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- aa.removeAnnotation();
- this.assertSourceContains("@annot.JoinColumns(comment=\"test\",columns=@annot.JoinColumn(name=\"ADDRESS_ID1\"))", cu);
- }
-
- public void testRemoveAnnotation6() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns(null)");
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", 0);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- aa.removeAnnotation();
- this.assertSourceContains("@annot.JoinColumns(null)", cu);
- }
-
- public void testRemoveAnnotation12() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns({@annot.JoinColumn(name=\"ADDRESS_ID0\"), null, @annot.JoinColumn(name=\"ADDRESS_ID2\")})");
- String expected = "@JoinColumn(name=\"ADDRESS_ID0\")";
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "value", 2);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa.removeAnnotation();
- this.assertSourceContains(expected, cu);
- this.assertSourceDoesNotContain("JoinColumns", cu);
- }
-
- public void testRemoveAnnotation13() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns({null, @annot.JoinColumn(name=\"ADDRESS_ID1\")})");
- this.assertSourceContains("@annot.JoinColumn", cu);
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "value", 1);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa.removeAnnotation();
- this.assertSourceDoesNotContain("ADDRESS_ID", cu);
- }
-
- public void testRemoveAnnotation14() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns({@annot.JoinColumn(name=\"ADDRESS_ID0\"), null, @annot.JoinColumn(name=\"ADDRESS_ID2\"), null})");
- String expected = "@JoinColumn(name=\"ADDRESS_ID0\")";
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "value", 2);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa.removeAnnotation();
- this.assertSourceContains(expected, cu);
- }
-
- public void testRemoveAnnotation15() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns({@annot.JoinColumn(name=\"ADDRESS_ID0\"), null, @annot.JoinColumn(name=\"ADDRESS_ID2\"), @annot.JoinColumn(name=\"ADDRESS_ID3\")})");
- String expected = "@annot.JoinColumns({@annot.JoinColumn(name=\"ADDRESS_ID0\"), null, null, @annot.JoinColumn(name=\"ADDRESS_ID3\")})";
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "value", 2);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa.removeAnnotation();
- this.assertSourceContains(expected, cu);
- }
-
- public void testRemoveAnnotation16() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns({@annot.JoinColumn(name=\"ADDRESS_ID0\"), null, @annot.JoinColumn(name=\"ADDRESS_ID2\"), @annot.JoinColumn(name=\"ADDRESS_ID3\")})");
- String expected = "@annot.JoinColumns({@annot.JoinColumn(name=\"ADDRESS_ID0\"), null, @annot.JoinColumn(name=\"ADDRESS_ID2\")})";
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "value", 3);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa.removeAnnotation();
- this.assertSourceContains(expected, cu);
- }
-
- public void testRemoveAnnotation17() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns({null, null, @annot.JoinColumn(name=\"ADDRESS_ID2\")})");
- this.assertSourceContains("@annot.JoinColumn", cu);
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "value", 2);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa.removeAnnotation();
- this.assertSourceDoesNotContain("ADDRESS_ID2", cu);
- }
-
- public void testNewMarkerAnnotation1() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain("JoinColumn", cu);
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 0);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains("JoinColumn", cu);
- this.assertSourceDoesNotContain("JoinColumns", cu);
- }
-
- public void testNewMarkerAnnotation2() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumn");
- this.assertSourceDoesNotContain("JoinColumns", cu);
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 1);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains("@JoinColumns(columns = { @JoinColumn, @JoinColumn })", cu);
- }
-
- public void testNewMarkerAnnotation3() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn, @annot.JoinColumn})");
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 2);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains("@annot.JoinColumns(columns={@annot.JoinColumn, @annot.JoinColumn," + CR + " @JoinColumn})", cu);
- }
-
- public void testNewMarkerAnnotation4() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumn(77)");
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 0);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains("JoinColumn", cu);
- this.assertSourceDoesNotContain("JoinColumns", cu);
- this.assertSourceDoesNotContain("77", cu);
- }
-
- public void testNewMarkerAnnotation5() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns=@annot.JoinColumn(77))");
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 0);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains("@annot.JoinColumns(columns=@JoinColumn)", cu);
- this.assertSourceDoesNotContain("77", cu);
- }
-
- public void testNewMarkerAnnotation6() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns=@annot.JoinColumn(77))");
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 1);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains("@annot.JoinColumns(columns={@annot.JoinColumn(77),@JoinColumn})", cu);
- }
-
- public void testNewMarkerAnnotation7() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumn(77)");
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 1);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains("@JoinColumns(columns = { @JoinColumn(77), @JoinColumn })", cu);
- }
-
- public void testNewMarkerAnnotation8() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(77),@annot.JoinColumn(88)})");
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 1);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains("@annot.JoinColumns(columns={@annot.JoinColumn(77),@JoinColumn})", cu);
- }
-
- public void testNewMarkerAnnotation9() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name(); String text(); int num();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumn(text=\"blah\",num=42)");
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 1);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains("@JoinColumns(columns = { @JoinColumn(text = \"blah\", num = 42), @JoinColumn })", cu);
- }
-
- public void testNewMarkerAnnotation23() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name(); String text(); int num();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumn(text=\"b\",num=4)");
- String expected1 = "@JoinColumns(columns = { @JoinColumn(text = \"b\", num = 4), null,";
- String expected2 = "@JoinColumn })";
- this.assertSourceDoesNotContain(expected1, cu);
- this.assertSourceDoesNotContain(expected2, cu);
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 2);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected1, cu);
- this.assertSourceContains(expected2, cu);
- }
-
- public void testNewMarkerAnnotation24() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name(); String text(); int num();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumn(text=\"blah\",num=42)");
-
- //Use old formatting if jdt core version is 3.5 or below - see bug 285604
- Version version = Platform.getBundle("org.eclipse.jdt.core").getVersion();
- int majorVersion = version.getMajor();
- int minorVersion = version.getMinor();
- //This condition should be removed and test updated after Dali 3.0 branches
- String expected1;
- if (majorVersion == 3 && minorVersion <= 5) {
- expected1 = "@JoinColumns( {";
- }
- else expected1 = "@JoinColumns({";
-
- String expected2 = "@JoinColumn(text = \"blah\", num = 42), null,";
- String expected3 = "@JoinColumn " + CR + " })";
- this.assertSourceDoesNotContain(expected1, cu);
- this.assertSourceDoesNotContain(expected2, cu);
- this.assertSourceDoesNotContain(expected3, cu);
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "value", 2);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected1, cu);
- this.assertSourceContains(expected2, cu);
- this.assertSourceContains(expected3, cu);
- }
-
- public void testNewMarkerAnnotation25() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\")})");
- String expected1 = "@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\"), null, null,"; // the line gets split
- String expected2 = "@JoinColumn})";
- this.assertSourceDoesNotContain(expected1, cu);
- this.assertSourceDoesNotContain(expected2, cu);
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 4);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected1, cu);
- this.assertSourceContains(expected2, cu);
- }
-
- public void testNewMarkerAnnotation26() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns({@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\")})");
- String expected1 = "@annot.JoinColumns({@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\"), null, null,"; // the line gets split
- String expected2 = "@JoinColumn})";
- this.assertSourceDoesNotContain(expected1, cu);
- this.assertSourceDoesNotContain(expected2, cu);
- DeclarationAnnotationAdapter daa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "value", 4);
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected1, cu);
- this.assertSourceContains(expected2, cu);
- }
-
- public void testMoveAnnotation1() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumn(name=\"ADDRESS_ID0\")");
- String expected = "@JoinColumns(columns = { null, @JoinColumn(name = \"ADDRESS_ID0\") })";
- this.assertSourceDoesNotContain(expected, cu);
- IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 0);
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), cidaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- iaa.moveAnnotation(1);
- this.assertSourceContains(expected, cu);
- }
-
- public void testMoveAnnotation2() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={null,@annot.JoinColumn(name=\"ADDRESS_ID1\")})");
- String expected = "@JoinColumn(name=\"ADDRESS_ID1\")";
- IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 1);
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), cidaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- iaa.moveAnnotation(0);
- this.assertSourceContains(expected, cu);
- this.assertSourceDoesNotContain("JoinColumns", cu);
- }
-
- public void testMoveAnnotation2a() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns({null,@annot.JoinColumn(name=\"ADDRESS_ID1\")})");
- String expected = "@JoinColumn(name=\"ADDRESS_ID1\")";
- IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "value", 1);
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), cidaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- iaa.moveAnnotation(0);
- this.assertSourceContains(expected, cu);
- this.assertSourceDoesNotContain("JoinColumns", cu);
- }
-
- public void testMoveAnnotation3() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\"), @annot.JoinColumn(name=\"ADDRESS_ID3\")})");
- String expected = "@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID3\"), @annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\")})";
- this.assertSourceDoesNotContain(expected, cu);
- IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 3);
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), cidaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- iaa.moveAnnotation(0);
- this.assertSourceContains(expected, cu);
- }
-
- public void testMoveAnnotation4() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\"), @annot.JoinColumn(name=\"ADDRESS_ID3\"), @annot.JoinColumn(name=\"ADDRESS_ID4\")})");
- String expected = "@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID3\"), @annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\"), null, @annot.JoinColumn(name=\"ADDRESS_ID4\")})";
- this.assertSourceDoesNotContain(expected, cu);
- IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 3);
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), cidaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- iaa.moveAnnotation(0);
- this.assertSourceContains(expected, cu);
- }
-
- public void testMoveAnnotation5() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\")})");
- String expected = "@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\"), null, @annot.JoinColumn(name=\"ADDRESS_ID2\")})";
- this.assertSourceDoesNotContain(expected, cu);
- IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 2);
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), cidaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- iaa.moveAnnotation(3);
- this.assertSourceContains(expected, cu);
- }
-
- public void testMoveAnnotation6() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\")})");
- String expected = "@annot.JoinColumns(columns={null, @annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\"), @annot.JoinColumn(name=\"ADDRESS_ID0\")})";
- this.assertSourceDoesNotContain(expected, cu);
- IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 0);
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), cidaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- iaa.moveAnnotation(3);
- this.assertSourceContains(expected, cu);
- }
-
- public void testMoveAnnotation7() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\")})");
- String expected = "@annot.JoinColumns(columns={null, @annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\")})";
- this.assertSourceDoesNotContain(expected, cu);
- IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 3);
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), cidaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- iaa.moveAnnotation(0);
- this.assertSourceContains(expected, cu);
- }
-
- public void testMoveAnnotation8() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\"), null, @annot.JoinColumn(name=\"ADDRESS_ID4\")})");
- String expected = "@annot.JoinColumns(columns={null, @annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\"), null, @annot.JoinColumn(name=\"ADDRESS_ID4\")})";
- this.assertSourceDoesNotContain(expected, cu);
- IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 3);
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), cidaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- iaa.moveAnnotation(0);
- this.assertSourceContains(expected, cu);
- }
-
- public void testMoveAnnotation9() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- String expected = "@annot.JoinColumns(columns={null, @annot.JoinColumn(name=\"ADDRESS_ID1\"), @annot.JoinColumn(name=\"ADDRESS_ID2\")})";
- ICompilationUnit cu = this.createTestType(expected); // the source should be unchanged
- IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 0);
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), cidaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- iaa.moveAnnotation(3);
- this.assertSourceContains(expected, cu);
- }
-
- public void testMoveAnnotation10() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\")})");
- String expected = "@JoinColumn(name=\"ADDRESS_ID0\")";
- IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 2);
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), cidaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- iaa.moveAnnotation(1);
- this.assertSourceContains(expected, cu);
- this.assertSourceDoesNotContain("@annot.JoinColumns", cu);
- }
-
- public void testMoveAnnotation10a() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] value();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns({@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\")})");
- String expected = "@JoinColumn(name=\"ADDRESS_ID0\")";
- IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "value", 2);
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), cidaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- iaa.moveAnnotation(1);
- this.assertSourceContains(expected, cu);
- this.assertSourceDoesNotContain("@annot.JoinColumns", cu);
- }
-
- public void testMoveAnnotation11() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumn(name=\"ADDRESS_ID0\")");
- IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 1);
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), cidaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- iaa.moveAnnotation(0);
- this.assertSourceDoesNotContain("JoinColumn", cu);
- }
-
- public void testMoveAnnotation12() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID0\"), null, @annot.JoinColumn(name=\"ADDRESS_ID2\")})");
- String expected = "@JoinColumn(name=\"ADDRESS_ID2\")";
- IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 2);
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), cidaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- iaa.moveAnnotation(0);
- this.assertSourceContains(expected, cu);
- this.assertSourceDoesNotContain("@annot.JoinColumns", cu);
- }
-
- public void testMoveAnnotation13() throws Exception {
- this.createAnnotationAndMembers("JoinColumn", "String name();");
- this.createAnnotationAndMembers("JoinColumns", "JoinColumn[] columns();");
- ICompilationUnit cu = this.createTestType("@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID0\"), @annot.JoinColumn(name=\"ADDRESS_ID1\"), null, @annot.JoinColumn(name=\"ADDRESS_ID3\")})");
- String expected = "@annot.JoinColumns(columns={@annot.JoinColumn(name=\"ADDRESS_ID3\"), @annot.JoinColumn(name=\"ADDRESS_ID1\")})";
- IndexedDeclarationAnnotationAdapter cidaa = new CombinationIndexedDeclarationAnnotationAdapter(
- "annot.JoinColumn", "annot.JoinColumns", "columns", 3);
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), cidaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- iaa.moveAnnotation(0);
- this.assertSourceContains(expected, cu);
- }
-
-}
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/DefaultAnnotationEditFormatterTests.java b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/DefaultAnnotationEditFormatterTests.java
deleted file mode 100644
index 1237cc9bf1..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/DefaultAnnotationEditFormatterTests.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007, 2010 Oracle. 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:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.core.tests.internal.utility.jdt;
-
-import org.eclipse.jpt.common.core.internal.utility.jdt.DefaultAnnotationEditFormatter;
-import org.eclipse.jpt.common.utility.internal.ReflectionTools;
-
-@SuppressWarnings("nls")
-public class DefaultAnnotationEditFormatterTests extends AnnotationTestCase {
-
-
- // ********** TestCase behavior **********
-
- public DefaultAnnotationEditFormatterTests(String name) {
- super(name);
- }
-
-
- // ********** tests **********
-
- public void testCommaLength() throws Exception {
- assertEquals(1, this.commaLength(","));
- assertEquals(1, this.commaLength(", "));
- assertEquals(1, this.commaLength(", "));
-
- assertEquals(2, this.commaLength(" ,"));
- assertEquals(2, this.commaLength(" , "));
- assertEquals(2, this.commaLength(" , "));
-
- assertEquals(3, this.commaLength(" ,"));
- assertEquals(3, this.commaLength(" , "));
- assertEquals(3, this.commaLength(" , "));
-
- assertEquals(0, this.commaLength(" ,,,"));
- assertEquals(0, this.commaLength(" ,,, "));
- assertEquals(0, this.commaLength(" , ,"));
-
- assertEquals(0, this.commaLength(" ,x"));
- assertEquals(0, this.commaLength(" ,x "));
- assertEquals(0, this.commaLength(" , x"));
-
- assertEquals(0, this.commaLength("x ,"));
- assertEquals(0, this.commaLength("x , "));
- assertEquals(0, this.commaLength("x , "));
- }
-
- private int commaLength(String s) {
- Integer len = (Integer) ReflectionTools.executeMethod(DefaultAnnotationEditFormatter.instance(), "commaLength", String.class, s);
- return len.intValue();
- }
-
- public void testStringIsAnnotation() throws Exception {
- assertTrue(this.stringIsAnnotation("@F"));
- assertTrue(this.stringIsAnnotation("@Foo"));
- assertTrue(this.stringIsAnnotation("@org.bar.Foo"));
-
- assertFalse(this.stringIsAnnotation(""));
- assertFalse(this.stringIsAnnotation("@"));
- assertFalse(this.stringIsAnnotation("Foo"));
- assertFalse(this.stringIsAnnotation("Foo@"));
- }
-
- private boolean stringIsAnnotation(String s) {
- Boolean b = (Boolean) ReflectionTools.executeMethod(DefaultAnnotationEditFormatter.instance(), "stringIsAnnotation", String.class, s);
- return b.booleanValue();
- }
-
-}
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/JDTToolsTests.java b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/JDTToolsTests.java
deleted file mode 100644
index 0fddcce6f7..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/JDTToolsTests.java
+++ /dev/null
@@ -1,65 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2011 Oracle. 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:
- * Oracle - initial API and implementation
- *******************************************************************************/
-package org.eclipse.jpt.common.core.tests.internal.utility.jdt;
-
-import java.util.AbstractCollection;
-import java.util.AbstractList;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.LinkedList;
-import java.util.List;
-import java.util.Map;
-import java.util.SortedSet;
-import java.util.TreeSet;
-import java.util.Vector;
-import org.eclipse.jdt.core.IJavaProject;
-import org.eclipse.jpt.common.core.internal.utility.JDTTools;
-
-
-public class JDTToolsTests
- extends AnnotationTestCase {
-
- public JDTToolsTests(String name) {
- super(name);
- }
-
-
- public void testTypeIsSubtype() throws Exception {
- IJavaProject jProj = getJavaProject().getJavaProject();
-
- // same type
- assertTrue(JDTTools.typeIsSubType(jProj, ArrayList.class.getName(), ArrayList.class.getName()));
- assertTrue(JDTTools.typeIsSubType(jProj, List.class.getName(), List.class.getName()));
-
- // concrete type is subtype of interface
- assertTrue(JDTTools.typeIsSubType(jProj, ArrayList.class.getName(), List.class.getName()));
- assertTrue(JDTTools.typeIsSubType(jProj, TreeSet.class.getName(), Iterable.class.getName()));
-
- // concrete type is not subtype of interface
- assertFalse(JDTTools.typeIsSubType(jProj, ArrayList.class.getName(), Map.class.getName()));
- assertFalse(JDTTools.typeIsSubType(jProj, TreeSet.class.getName(), Map.class.getName()));
-
- // interface is subtype of interface
- assertTrue(JDTTools.typeIsSubType(jProj, List.class.getName(), Collection.class.getName()));
- assertTrue(JDTTools.typeIsSubType(jProj, SortedSet.class.getName(), Iterable.class.getName()));
-
- // interface is not subtype of interface
- assertFalse(JDTTools.typeIsSubType(jProj, List.class.getName(), Map.class.getName()));
- assertFalse(JDTTools.typeIsSubType(jProj, SortedSet.class.getName(), Map.class.getName()));
-
- // concrete type is subtype of concrete type
- assertTrue(JDTTools.typeIsSubType(jProj, ArrayList.class.getName(), AbstractList.class.getName()));
- assertTrue(JDTTools.typeIsSubType(jProj, LinkedList.class.getName(), AbstractCollection.class.getName()));
-
- // concrete type is not subtype of concrete type
- assertFalse(JDTTools.typeIsSubType(jProj, ArrayList.class.getName(), Vector.class.getName()));
- assertFalse(JDTTools.typeIsSubType(jProj, LinkedList.class.getName(), Vector.class.getName()));
- }
-}
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/JptCommonCoreUtilityJdtTests.java b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/JptCommonCoreUtilityJdtTests.java
deleted file mode 100644
index 0f485953b4..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/JptCommonCoreUtilityJdtTests.java
+++ /dev/null
@@ -1,36 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2010 Oracle. 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:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.core.tests.internal.utility.jdt;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-public class JptCommonCoreUtilityJdtTests {
-
- public static Test suite() {
- TestSuite suite = new TestSuite(JptCommonCoreUtilityJdtTests.class.getPackage().getName());
- suite.addTestSuite(CombinationIndexedDeclarationAnnotationAdapterTests.class);
- suite.addTestSuite(DefaultAnnotationEditFormatterTests.class);
- suite.addTestSuite(ASTToolsTests.class);
- suite.addTestSuite(JDTToolsTests.class);
- suite.addTestSuite(MemberAnnotationElementAdapterTests.class);
- suite.addTestSuite(NestedDeclarationAnnotationAdapterTests.class);
- suite.addTestSuite(NestedIndexedDeclarationAnnotationAdapterTests.class);
- suite.addTestSuite(SimpleDeclarationAnnotationAdapterTests.class);
- suite.addTestSuite(TypeTests.class);
- return suite;
- }
-
- private JptCommonCoreUtilityJdtTests() {
- super();
- throw new UnsupportedOperationException();
- }
-
-}
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/MemberAnnotationElementAdapterTests.java b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/MemberAnnotationElementAdapterTests.java
deleted file mode 100644
index b4f2fa7afa..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/MemberAnnotationElementAdapterTests.java
+++ /dev/null
@@ -1,1298 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2011 Oracle. 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:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.core.tests.internal.utility.jdt;
-
-import java.util.Arrays;
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jpt.common.core.internal.utility.jdt.ASTTools;
-import org.eclipse.jpt.common.core.internal.utility.jdt.AnnotatedElementAnnotationElementAdapter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.AnnotationStringArrayExpressionConverter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.BooleanExpressionConverter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.CharacterStringExpressionConverter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.ConversionDeclarationAnnotationElementAdapter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.EnumArrayDeclarationAnnotationElementAdapter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.EnumDeclarationAnnotationElementAdapter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.IndexedConversionDeclarationAnnotationElementAdapter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.NestedDeclarationAnnotationAdapter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.NumberIntegerExpressionConverter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.PrimitiveTypeStringExpressionConverter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.SimpleTypeStringExpressionConverter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.StringExpressionConverter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.TypeStringExpressionConverter;
-import org.eclipse.jpt.common.core.utility.TextRange;
-import org.eclipse.jpt.common.core.utility.jdt.AnnotationElementAdapter;
-import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationAdapter;
-import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationElementAdapter;
-import org.eclipse.jpt.common.core.utility.jdt.IndexedExpressionConverter;
-
-@SuppressWarnings("nls")
-public class MemberAnnotationElementAdapterTests extends AnnotationTestCase {
-
- public MemberAnnotationElementAdapterTests(String name) {
- super(name);
- }
-
- private void createAnnotationAndMembers(String annotationName, String annotationBody) throws Exception {
- this.javaProject.createCompilationUnit("annot", annotationName + ".java", "public @interface " + annotationName + " { " + annotationBody + " }");
- }
-
- private void createEnum(String enumName, String enumBody) throws Exception {
- this.createEnum("enums", enumName, enumBody);
- }
-
- private void createEnum(String packageName, String enumName, String enumBody) throws Exception {
- this.javaProject.createCompilationUnit(packageName, enumName + ".java", "public enum " + enumName + " { " + enumBody + " }");
- }
-
- public void testValue1() throws Exception {
- this.createAnnotationAndMembers("Foo", "String bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=\"xxx\")");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertEquals("xxx", aea.getValue());
- }
-
- public void testValue2() throws Exception {
- this.createAnnotationAndMembers("Foo", "int bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=48)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<Integer> daea = new ConversionDeclarationAnnotationElementAdapter<Integer>(daa, "bar", NumberIntegerExpressionConverter.instance());
- AnnotationElementAdapter<Integer> aea = new AnnotatedElementAnnotationElementAdapter<Integer>(this.idField(cu), daea);
- assertEquals(Integer.valueOf(48), aea.getValue());
- }
-
- public void testValue3() throws Exception {
- this.createAnnotationAndMembers("Foo", "char bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar='c')");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = new ConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", CharacterStringExpressionConverter.instance());
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertEquals("c", aea.getValue());
- }
-
- public void testValue4() throws Exception {
- this.createAnnotationAndMembers("Foo", "boolean bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=false)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<Boolean> daea = new ConversionDeclarationAnnotationElementAdapter<Boolean>(daa, "bar", BooleanExpressionConverter.instance());
- AnnotationElementAdapter<Boolean> aea = new AnnotatedElementAnnotationElementAdapter<Boolean>(this.idField(cu), daea);
- assertEquals(Boolean.FALSE, aea.getValue());
- }
-
- public void testValue5() throws Exception {
- this.createAnnotationAndMembers("Baz", "boolean fred();");
- this.createAnnotationAndMembers("Bar", "annot.Baz jimmy();");
- this.createAnnotationAndMembers("Foo", "annot.Bar value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(@annot.Bar(jimmy=@annot.Baz(fred=false)))");
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationAdapter daa2 = new NestedDeclarationAnnotationAdapter(daa1, "value", "annot.Bar");
- DeclarationAnnotationAdapter daa3 = new NestedDeclarationAnnotationAdapter(daa2, "jimmy", "annot.Baz");
- DeclarationAnnotationElementAdapter<Boolean> daea = new ConversionDeclarationAnnotationElementAdapter<Boolean>(daa3, "fred", BooleanExpressionConverter.instance());
- AnnotationElementAdapter<Boolean> aea = new AnnotatedElementAnnotationElementAdapter<Boolean>(this.idField(cu), daea);
- assertEquals(Boolean.FALSE, aea.getValue());
- }
-
- public void testValue6() throws Exception {
- this.createAnnotationAndMembers("Foo", "boolean value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(false)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<Boolean> daea = new ConversionDeclarationAnnotationElementAdapter<Boolean>(daa, BooleanExpressionConverter.instance());
- AnnotationElementAdapter<Boolean> aea = new AnnotatedElementAnnotationElementAdapter<Boolean>(this.idField(cu), daea);
- assertEquals(Boolean.FALSE, aea.getValue());
- }
-
- public void testValueNull1() throws Exception {
- this.createAnnotationAndMembers("Foo", "String bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertNull(aea.getValue());
- }
-
- public void testValueNull2() throws Exception {
- this.createAnnotationAndMembers("Foo", "String bar();");
- ICompilationUnit cu = this.createTestType();
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("Foo");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertNull(aea.getValue());
- }
-
- public void testValueNull3() throws Exception {
- this.createAnnotationAndMembers("Baz", "String fred();");
- this.createAnnotationAndMembers("Bar", "annot.Baz jimmy();");
- this.createAnnotationAndMembers("Foo", "annot.Bar value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(@annot.Bar(jimmy=@annot.Baz))");
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationAdapter daa2 = new NestedDeclarationAnnotationAdapter(daa1, "value", "annot.Bar");
- DeclarationAnnotationAdapter daa3 = new NestedDeclarationAnnotationAdapter(daa2, "jimmy", "annot.Baz");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa3, "fred");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertNull(aea.getValue());
- }
-
- public void testValueStringConcatenation() throws Exception {
- this.createAnnotationAndMembers("Foo", "String bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=\"xxx\" + \"yyy\" + \"zzz\")");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertEquals("xxxyyyzzz", aea.getValue());
- }
-
- public void testValueStringConstant() throws Exception {
- this.createAnnotationAndMembers("Foo", "String bar();");
- // just a bit hacky:
- ICompilationUnit cu = this.createTestType("private static final String FOO_BAR = \"xxx\"; @annot.Foo(bar=FOO_BAR + \"yyy\" + \"zzz\")");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertEquals("xxxyyyzzz", aea.getValue());
- }
-
- public void testValueNumberArithmetic() throws Exception {
- this.createAnnotationAndMembers("Foo", "int bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=47 - 7 + 2 * 1 / 1)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<Integer> daea = ConversionDeclarationAnnotationElementAdapter.forNumbers(daa, "bar");
- AnnotationElementAdapter<Integer> aea = new AnnotatedElementAnnotationElementAdapter<Integer>(this.idField(cu), daea);
- assertEquals(Integer.valueOf(42), aea.getValue());
- }
-
- public void testValueNumberShift() throws Exception {
- this.createAnnotationAndMembers("Foo", "int bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=2 << 2)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<Integer> daea = ConversionDeclarationAnnotationElementAdapter.forNumbers(daa, "bar");
- AnnotationElementAdapter<Integer> aea = new AnnotatedElementAnnotationElementAdapter<Integer>(this.idField(cu), daea);
- assertEquals(Integer.valueOf(8), aea.getValue());
- }
-
- public void testValueNumberConstant() throws Exception {
- this.createAnnotationAndMembers("Foo", "int bar();");
- // just a bit hacky:
- ICompilationUnit cu = this.createTestType("private static final int FOO_BAR = 77; @annot.Foo(bar=FOO_BAR)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<Integer> daea = ConversionDeclarationAnnotationElementAdapter.forNumbers(daa, "bar");
- AnnotationElementAdapter<Integer> aea = new AnnotatedElementAnnotationElementAdapter<Integer>(this.idField(cu), daea);
- assertEquals(Integer.valueOf(77), aea.getValue());
- }
-
- public void testValueCharacterConstant() throws Exception {
- this.createAnnotationAndMembers("Foo", "char bar();");
- // just a bit hacky:
- ICompilationUnit cu = this.createTestType("private static final char FOO_BAR = 'Q'; @annot.Foo(bar=FOO_BAR)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forCharacters(daa, "bar");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertEquals("Q", aea.getValue());
- }
-
- public void testValueCharacterCast() throws Exception {
- this.createAnnotationAndMembers("Foo", "char bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=(char) 0x41)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forCharacters(daa, "bar");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertEquals("A", aea.getValue());
- }
-
- public void testValueBooleanOperator1() throws Exception {
- this.createAnnotationAndMembers("Foo", "boolean bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=7 > 2)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<Boolean> daea = ConversionDeclarationAnnotationElementAdapter.forBooleans(daa, "bar");
- AnnotationElementAdapter<Boolean> aea = new AnnotatedElementAnnotationElementAdapter<Boolean>(this.idField(cu), daea);
- assertEquals(Boolean.TRUE, aea.getValue());
- }
-
- public void testValueBooleanOperator2() throws Exception {
- this.createAnnotationAndMembers("Foo", "boolean bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=7 == 2)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<Boolean> daea = ConversionDeclarationAnnotationElementAdapter.forBooleans(daa, "bar");
- AnnotationElementAdapter<Boolean> aea = new AnnotatedElementAnnotationElementAdapter<Boolean>(this.idField(cu), daea);
- assertEquals(Boolean.FALSE, aea.getValue());
- }
-
- public void testValueBooleanOperator3() throws Exception {
- this.createAnnotationAndMembers("Foo", "boolean bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=(7 != 2) && false)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<Boolean> daea = ConversionDeclarationAnnotationElementAdapter.forBooleans(daa, "bar");
- AnnotationElementAdapter<Boolean> aea = new AnnotatedElementAnnotationElementAdapter<Boolean>(this.idField(cu), daea);
- assertEquals(Boolean.FALSE, aea.getValue());
- }
-
- public void testValueBooleanOperator4() throws Exception {
- this.createAnnotationAndMembers("Foo", "boolean bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=(7 != 2) ? false : true)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<Boolean> daea = ConversionDeclarationAnnotationElementAdapter.forBooleans(daa, "bar");
- AnnotationElementAdapter<Boolean> aea = new AnnotatedElementAnnotationElementAdapter<Boolean>(this.idField(cu), daea);
- assertEquals(Boolean.FALSE, aea.getValue());
- }
-
- public void testValueInvalidValue1() throws Exception {
- this.createAnnotationAndMembers("Foo", "String bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=77)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertNull(aea.getValue());
- }
-
- public void testValueInvalidValue2() throws Exception {
- this.createAnnotationAndMembers("Foo", "String bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=bazzzz)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertNull(aea.getValue());
- }
-
- public void testValueInvalidValue3() throws Exception {
- this.createAnnotationAndMembers("Foo", "boolean bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=bazzzz)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<Boolean> daea = ConversionDeclarationAnnotationElementAdapter.forBooleans(daa, "bar");
- AnnotationElementAdapter<Boolean> aea = new AnnotatedElementAnnotationElementAdapter<Boolean>(this.idField(cu), daea);
- assertNull(aea.getValue());
- }
-
- public void testValueInvalidValue4() throws Exception {
- this.createAnnotationAndMembers("Foo", "char bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=\"bazzzz\")");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forCharacters(daa, "bar");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertNull(aea.getValue());
- }
-
- public void testValueInvalidValue5() throws Exception {
- this.createAnnotationAndMembers("Foo", "Class bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=\"java.lang.Object\")");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = new ConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", SimpleTypeStringExpressionConverter.instance());
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertNull(aea.getValue());
- }
-
- public void testValueInvalidValue6() throws Exception {
- this.createEnum("TestEnum", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums.TestEnum bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=enums.TestEnum.class)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = new EnumDeclarationAnnotationElementAdapter(daa, "bar");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertNull(aea.getValue());
- }
-
- public void testValueInvalidValue7() throws Exception {
- this.createAnnotationAndMembers("Baz", "boolean fred();");
- this.createAnnotationAndMembers("Bar", "annot.Baz jimmy();");
- this.createAnnotationAndMembers("Foo", "annot.Bar value();");
- String value = "\"false\"";
- String element = "fred=" + value;
- String annotation = "@annot.Foo(@annot.Bar(jimmy=@annot.Baz(" + element + ")))";
- ICompilationUnit cu = this.createTestType(annotation);
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationAdapter daa2 = new NestedDeclarationAnnotationAdapter(daa1, "value", "annot.Bar");
- DeclarationAnnotationAdapter daa3 = new NestedDeclarationAnnotationAdapter(daa2, "jimmy", "annot.Baz");
- DeclarationAnnotationElementAdapter<Boolean> daea = new ConversionDeclarationAnnotationElementAdapter<Boolean>(daa3, "fred", BooleanExpressionConverter.instance());
- AnnotationElementAdapter<Boolean> aea = new AnnotatedElementAnnotationElementAdapter<Boolean>(this.idField(cu), daea);
- assertNull(aea.getValue());
- }
-
- public void testValueInvalidValue8() throws Exception {
- this.createAnnotationAndMembers("Foo", "String[] bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar={true, false})");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String[]> daea = new ConversionDeclarationAnnotationElementAdapter<String[]>(daa, "bar", AnnotationStringArrayExpressionConverter.forStrings());
- AnnotationElementAdapter<String[]> aea = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea);
- assertTrue(Arrays.equals(new String[] {null, null}, aea.getValue()));
- }
-
- public void testValueInvalidValue9() throws Exception {
- this.createAnnotationAndMembers("Foo", "String[] bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=77)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String[]> daea = new ConversionDeclarationAnnotationElementAdapter<String[]>(daa, "bar", AnnotationStringArrayExpressionConverter.forStrings());
- AnnotationElementAdapter<String[]> aea = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea);
- assertTrue(Arrays.equals(new String[0], aea.getValue()));
- }
-
- public void testASTNode1() throws Exception {
- this.createAnnotationAndMembers("Foo", "String bar();");
- String value = "\"xxx\"";
- String element = "bar=" + value;
- String annotation = "@annot.Foo(" + element + ")";
- ICompilationUnit cu = this.createTestType(annotation);
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
-
- TextRange textRange = ASTTools.buildTextRange(aea.getAstNode(this.buildASTRoot(cu)));
- assertEquals(this.getSource(cu).indexOf(value), textRange.getOffset());
- assertEquals(value.length(), textRange.getLength());
- assertEquals(7, textRange.getLineNumber());
- }
-
- public void testASTNode2() throws Exception {
- this.createAnnotationAndMembers("Baz", "boolean fred();");
- this.createAnnotationAndMembers("Bar", "annot.Baz jimmy();");
- this.createAnnotationAndMembers("Foo", "annot.Bar value();");
- String value = "false";
- String element = "fred=" + value;
- String annotation = "@annot.Foo(@annot.Bar(jimmy=@annot.Baz(" + element + ")))";
- ICompilationUnit cu = this.createTestType(annotation);
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationAdapter daa2 = new NestedDeclarationAnnotationAdapter(daa1, "value", "annot.Bar");
- DeclarationAnnotationAdapter daa3 = new NestedDeclarationAnnotationAdapter(daa2, "jimmy", "annot.Baz");
- DeclarationAnnotationElementAdapter<Boolean> daea = new ConversionDeclarationAnnotationElementAdapter<Boolean>(daa3, "fred", BooleanExpressionConverter.instance());
- AnnotationElementAdapter<Boolean> aea = new AnnotatedElementAnnotationElementAdapter<Boolean>(this.idField(cu), daea);
- assertEquals(Boolean.FALSE, aea.getValue());
- TextRange textRange = ASTTools.buildTextRange(aea.getAstNode(this.buildASTRoot(cu)));
- assertEquals(value.length(), textRange.getLength());
- }
-
- public void testASTNode3() throws Exception {
- this.createAnnotationAndMembers("Foo", "String value();");
- String element = "\"xxx\"";
- String annotation = "@annot.Foo(" + element + ")";
- ICompilationUnit cu = this.createTestType(annotation);
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa);
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
-
- TextRange textRange = ASTTools.buildTextRange(aea.getAstNode(this.buildASTRoot(cu)));
- assertEquals(this.getSource(cu).indexOf(element), textRange.getOffset());
- assertEquals(element.length(), textRange.getLength());
- }
-
- public void testASTNode4() throws Exception {
- this.createAnnotationAndMembers("Foo", "String value();");
- String annotation = "@annot.Foo";
- ICompilationUnit cu = this.createTestType(annotation);
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa);
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
-
- TextRange textRange = ASTTools.buildTextRange(aea.getAstNode(this.buildASTRoot(cu)));
- assertEquals(this.getSource(cu).indexOf(annotation), textRange.getOffset());
- assertEquals(annotation.length(), textRange.getLength());
- }
-
- public void testSetValue1() throws Exception {
- this.createAnnotationAndMembers("Foo", "String bar();");
- String annotation = "@annot.Foo(bar=\"xxx\")";
- ICompilationUnit cu = this.createTestType(annotation);
- this.assertSourceContains(annotation, cu);
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
-
- aea.setValue(null);
- this.assertSourceDoesNotContain("bar", cu);
- }
-
- public void testSetValue2() throws Exception {
- this.createAnnotationAndMembers("Foo", "String bar();");
- String annotation = "@annot.Foo(bar=\"xxx\")";
- ICompilationUnit cu = this.createTestType(annotation);
- this.assertSourceContains(annotation, cu);
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
-
- aea.setValue(null);
- this.assertSourceDoesNotContain(annotation, cu);
- this.assertSourceContains("@Foo", cu);
- }
-
- public void testSetValue3() throws Exception {
- this.createAnnotationAndMembers("Baz", "boolean fred();");
- this.createAnnotationAndMembers("Bar", "annot.Baz jimmy();");
- this.createAnnotationAndMembers("Foo", "annot.Bar value();");
- String annotation = "@annot.Foo(@annot.Bar(jimmy=@annot.Baz(fred=false)))";
- ICompilationUnit cu = this.createTestType(annotation);
- this.assertSourceContains(annotation, cu);
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationAdapter daa2 = new NestedDeclarationAnnotationAdapter(daa1, "value", "annot.Bar");
- DeclarationAnnotationAdapter daa3 = new NestedDeclarationAnnotationAdapter(daa2, "jimmy", "annot.Baz");
- DeclarationAnnotationElementAdapter<Boolean> daea = new ConversionDeclarationAnnotationElementAdapter<Boolean>(daa3, "fred", BooleanExpressionConverter.instance());
- AnnotationElementAdapter<Boolean> aea = new AnnotatedElementAnnotationElementAdapter<Boolean>(this.idField(cu), daea);
-
- aea.setValue(null);
- this.assertSourceDoesNotContain(annotation, cu);
- this.assertSourceDoesNotContain("fred", cu);
- }
-
- public void testSetValue3a() throws Exception {
- this.createAnnotationAndMembers("Baz", "boolean fred();");
- this.createAnnotationAndMembers("Bar", "annot.Baz jimmy();");
- this.createAnnotationAndMembers("Foo", "annot.Bar value();");
- String annotation = "@annot.Foo(@annot.Bar(jimmy=@annot.Baz(fred=false)))";
- ICompilationUnit cu = this.createTestType(annotation);
- this.assertSourceContains(annotation, cu);
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationAdapter daa2 = new NestedDeclarationAnnotationAdapter(daa1, "value", "annot.Bar");
- DeclarationAnnotationAdapter daa3 = new NestedDeclarationAnnotationAdapter(daa2, "jimmy", "annot.Baz");
- DeclarationAnnotationElementAdapter<Boolean> daea = new ConversionDeclarationAnnotationElementAdapter<Boolean>(daa3, "fred", BooleanExpressionConverter.instance());
- AnnotationElementAdapter<Boolean> aea = new AnnotatedElementAnnotationElementAdapter<Boolean>(this.idField(cu), daea);
-
- aea.setValue(null);
- this.assertSourceDoesNotContain(annotation, cu);
- this.assertSourceDoesNotContain("fred", cu);
- this.assertSourceContains("@annot.Foo(@annot.Bar(jimmy=@Baz))", cu);
- }
-
- public void testSetValue4() throws Exception {
- this.createAnnotationAndMembers("Foo", "String bar();");
- ICompilationUnit cu = this.createTestType();
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("Foo");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
-
- aea.setValue("xxx");
- this.assertSourceContains("@Foo(bar = \"xxx\")", cu);
- }
-
- public void testSetValue5() throws Exception {
- this.createAnnotationAndMembers("Baz", "boolean fred();");
- this.createAnnotationAndMembers("Bar", "annot.Baz jimmy();");
- this.createAnnotationAndMembers("Foo", "annot.Bar value();");
- String annotation = "@annot.Foo(@annot.Bar(jimmy=@annot.Baz(fred=false)))";
- ICompilationUnit cu = this.createTestType(annotation);
- this.assertSourceContains(annotation, cu);
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationAdapter daa2 = new NestedDeclarationAnnotationAdapter(daa1, "value", "annot.Bar");
- DeclarationAnnotationAdapter daa3 = new NestedDeclarationAnnotationAdapter(daa2, "jimmy", "annot.Baz");
- DeclarationAnnotationElementAdapter<Boolean> daea = new ConversionDeclarationAnnotationElementAdapter<Boolean>(daa3, "fred", BooleanExpressionConverter.instance());
- AnnotationElementAdapter<Boolean> aea = new AnnotatedElementAnnotationElementAdapter<Boolean>(this.idField(cu), daea);
-
- aea.setValue(Boolean.TRUE);
- this.assertSourceDoesNotContain(annotation, cu);
- this.assertSourceContains("@annot.Foo(@annot.Bar(jimmy=@annot.Baz(fred=true)))", cu);
- }
-
- public void testSetValue6() throws Exception {
- this.createAnnotationAndMembers("Baz", "boolean fred();");
- this.createAnnotationAndMembers("Bar", "annot.Baz jimmy();");
- this.createAnnotationAndMembers("Foo", "annot.Bar value();");
- ICompilationUnit cu = this.createTestType();
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationAdapter daa2 = new NestedDeclarationAnnotationAdapter(daa1, "value", "annot.Bar");
- DeclarationAnnotationAdapter daa3 = new NestedDeclarationAnnotationAdapter(daa2, "jimmy", "annot.Baz");
- DeclarationAnnotationElementAdapter<Boolean> daea = new ConversionDeclarationAnnotationElementAdapter<Boolean>(daa3, "fred", BooleanExpressionConverter.instance());
- AnnotationElementAdapter<Boolean> aea = new AnnotatedElementAnnotationElementAdapter<Boolean>(this.idField(cu), daea);
-
- aea.setValue(Boolean.TRUE);
- this.assertSourceContains("@Foo(@Bar(jimmy = @Baz(fred = true)))", cu);
- }
-
- public void testSetValue7() throws Exception {
- this.createAnnotationAndMembers("Foo", "String bar();");
- String annotation = "@annot.Foo(bar=\"xxx\")";
- ICompilationUnit cu = this.createTestType(annotation);
- this.assertSourceContains(annotation, cu);
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
-
- aea.setValue("yyy");
- this.assertSourceDoesNotContain(annotation, cu);
- this.assertSourceContains("@annot.Foo(bar=\"yyy\")", cu);
- }
-
- public void testSetValue8() throws Exception {
- this.createAnnotationAndMembers("Foo", "String bar();");
- String annotation = "@annot.Foo";
- ICompilationUnit cu = this.createTestType(annotation);
- this.assertSourceContains(annotation, cu);
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
-
- aea.setValue("xxx");
- this.assertSourceContains("@Foo(bar = \"xxx\")", cu);
- }
-
- public void testSetValue9() throws Exception {
- this.createAnnotationAndMembers("Foo", "String value(); String bar();");
- String annotation = "@annot.Foo(\"zzz\")";
- ICompilationUnit cu = this.createTestType(annotation);
- this.assertSourceContains(annotation, cu);
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "bar");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
-
- aea.setValue("xxx");
- this.assertSourceDoesNotContain(annotation, cu);
- this.assertSourceContains("@Foo(value = \"zzz\", bar = \"xxx\")", cu);
- }
-
- public void testSetValue10() throws Exception {
- this.createAnnotationAndMembers("Foo", "String bar(); String baz();");
- String annotation = "@annot.Foo(bar=\"xxx\")";
- ICompilationUnit cu = this.createTestType(annotation);
- this.assertSourceContains(annotation, cu);
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "baz");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
-
- aea.setValue("yyy");
- this.assertSourceDoesNotContain(annotation, cu);
- this.assertSourceContains("@annot.Foo(bar=\"xxx\", baz = \"yyy\")", cu);
- }
-
- public void testSetValue11() throws Exception {
- this.createAnnotationAndMembers("Baz", "int fred();");
- this.createAnnotationAndMembers("Bar", "annot.Baz[] jimmy();");
- this.createAnnotationAndMembers("Foo", "annot.Bar value();");
- String annotation = "@annot.Foo(@annot.Bar(jimmy={@annot.Baz(fred=0), @annot.Baz(fred=1), @annot.Baz(fred=2), @annot.Baz(fred=3)}))";
- ICompilationUnit cu = this.createTestType(annotation);
- this.assertSourceContains(annotation, cu);
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationAdapter daa2 = new NestedDeclarationAnnotationAdapter(daa1, "value", "annot.Bar");
- DeclarationAnnotationAdapter daa3 = new NestedIndexedDeclarationAnnotationAdapter(daa2, "jimmy", 2, "annot.Baz");
- DeclarationAnnotationElementAdapter<Integer> daea = new ConversionDeclarationAnnotationElementAdapter<Integer>(daa3, "fred", NumberIntegerExpressionConverter.instance());
- AnnotationElementAdapter<Integer> aea = new AnnotatedElementAnnotationElementAdapter<Integer>(this.idField(cu), daea);
-
- assertEquals(Integer.valueOf(2), aea.getValue());
- aea.setValue(Integer.valueOf(48));
- this.assertSourceContains("@annot.Foo(@annot.Bar(jimmy={@annot.Baz(fred=0), @annot.Baz(fred=1), @annot.Baz(fred=48), @annot.Baz(fred=3)}))", cu);
- }
-
- public void testSetValue12() throws Exception {
- this.createAnnotationAndMembers("Foo", "String value();");
- String annotation = "@annot.Foo";
- ICompilationUnit cu = this.createTestType(annotation);
- this.assertSourceContains(annotation, cu);
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "value");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
-
- aea.setValue("xxx");
- this.assertSourceContains("@Foo(\"xxx\")", cu);
- }
-
- public void testSetValue13() throws Exception {
- this.createAnnotationAndMembers("Foo", "String value();");
- String annotation = "@annot.Foo(\"zzz\")";
- ICompilationUnit cu = this.createTestType(annotation);
- this.assertSourceContains(annotation, cu);
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = ConversionDeclarationAnnotationElementAdapter.forStrings(daa, "value");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
-
- aea.setValue("xxx");
- this.assertSourceDoesNotContain(annotation, cu);
- this.assertSourceContains("@annot.Foo(\"xxx\")", cu);
- }
-
- public void testSimpleTypeLiteral1() throws Exception {
- this.createAnnotationAndMembers("Foo", "Class bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=java.lang.Object.class)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = new ConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", SimpleTypeStringExpressionConverter.instance());
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertEquals("java.lang.Object", aea.getValue());
- }
-
- public void testSimpleTypeLiteral2() throws Exception {
- this.createAnnotationAndMembers("Foo", "Class bar();");
- ICompilationUnit cu = this.createTestType();
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = new ConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", SimpleTypeStringExpressionConverter.instance());
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- aea.setValue("java.lang.Object");
- this.assertSourceContains("@Foo(bar = java.lang.Object.class)", cu);
- }
-
- public void testSimpleTypeLiteral3() throws Exception {
- this.createAnnotationAndMembers("Foo", "Class bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=int.class)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = new ConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", SimpleTypeStringExpressionConverter.instance());
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertNull(aea.getValue());
- }
-
- public void testSimpleTypeLiteral4() throws Exception {
- this.createAnnotationAndMembers("Foo", "Class bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=java.util.Map.Entry.class)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = new ConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", SimpleTypeStringExpressionConverter.instance());
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertEquals("java.util.Map.Entry", aea.getValue());
- }
-
- public void testPrimitiveTypeLiteral1() throws Exception {
- this.createAnnotationAndMembers("Foo", "Class bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=int.class)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = new ConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", PrimitiveTypeStringExpressionConverter.instance());
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertEquals("int", aea.getValue());
- }
-
- public void testPrimitiveTypeLiteral2() throws Exception {
- this.createAnnotationAndMembers("Foo", "Class bar();");
- ICompilationUnit cu = this.createTestType();
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = new ConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", PrimitiveTypeStringExpressionConverter.instance());
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- aea.setValue("int");
- this.assertSourceContains("@Foo(bar = int.class)", cu);
- }
-
- public void testPrimitiveTypeLiteral3() throws Exception {
- this.createAnnotationAndMembers("Foo", "Class bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=java.lang.Object.class)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = new ConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", PrimitiveTypeStringExpressionConverter.instance());
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertNull(aea.getValue());
- }
-
- public void testPrimitiveTypeLiteral4() throws Exception {
- this.createAnnotationAndMembers("Foo", "Class bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=void.class)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = new ConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", PrimitiveTypeStringExpressionConverter.instance());
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertEquals("void", aea.getValue());
- }
-
- public void testTypeLiteral1() throws Exception {
- this.createAnnotationAndMembers("Foo", "Class bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=java.lang.Object.class)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = new ConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", TypeStringExpressionConverter.instance());
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertEquals("java.lang.Object", aea.getValue());
- }
-
- public void testTypeLiteral2() throws Exception {
- this.createAnnotationAndMembers("Foo", "Class bar();");
- ICompilationUnit cu = this.createTestType();
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = new ConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", TypeStringExpressionConverter.instance());
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- aea.setValue("java.lang.Object");
- this.assertSourceContains("@Foo(bar = java.lang.Object.class)", cu);
- }
-
- public void testTypeLiteral3() throws Exception {
- this.createAnnotationAndMembers("Foo", "Class bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=java.util.Map.Entry.class)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = new ConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", TypeStringExpressionConverter.instance());
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertEquals("java.util.Map.Entry", aea.getValue());
- }
-
- public void testTypeLiteral14() throws Exception {
- this.createAnnotationAndMembers("Foo", "Class bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=int.class)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = new ConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", TypeStringExpressionConverter.instance());
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertEquals("int", aea.getValue());
- }
-
- public void testTypeLiteral5() throws Exception {
- this.createAnnotationAndMembers("Foo", "Class bar();");
- ICompilationUnit cu = this.createTestType();
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = new ConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", TypeStringExpressionConverter.instance());
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- aea.setValue("int");
- this.assertSourceContains("@Foo(bar = int.class)", cu);
- }
-
- public void testTypeLiteral6() throws Exception {
- this.createAnnotationAndMembers("Foo", "Class bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=void.class)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = new ConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", TypeStringExpressionConverter.instance());
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertEquals("void", aea.getValue());
- }
-
- public void testValueEnum1() throws Exception {
- this.createEnum("TestEnum", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums.TestEnum bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=enums.TestEnum.XXX)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = new EnumDeclarationAnnotationElementAdapter(daa, "bar");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertEquals("enums.TestEnum.XXX", aea.getValue());
- }
-
- public void testValueEnum2() throws Exception {
- this.createEnum("TestEnum", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums.TestEnum bar();");
- ICompilationUnit cu = this.createTestType("static enums.TestEnum.XXX", "@annot.Foo(bar=XXX)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = new EnumDeclarationAnnotationElementAdapter(daa, "bar");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertEquals("enums.TestEnum.XXX", aea.getValue());
- }
-
- public void testValueEnum3() throws Exception {
- this.createEnum("TestEnum", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums.TestEnum bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = new EnumDeclarationAnnotationElementAdapter(daa, "bar");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertNull(aea.getValue());
- }
-
- public void testValueEnum4() throws Exception {
- this.createEnum("TestEnum", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums.TestEnum bar();");
- ICompilationUnit cu = this.createTestType("enums.TestEnum", "@annot.Foo(bar=TestEnum.XXX)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = new EnumDeclarationAnnotationElementAdapter(daa, "bar");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- assertEquals("enums.TestEnum.XXX", aea.getValue());
- }
-
- public void testSetValueEnum1() throws Exception {
- this.createEnum("TestEnum", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums.TestEnum bar();");
- String expected = "@annot.Foo(bar=XXX)";
- ICompilationUnit cu = this.createTestType("static enums.TestEnum.XXX", expected);
- this.assertSourceContains(expected, cu);
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = new EnumDeclarationAnnotationElementAdapter(daa, "bar");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- aea.setValue(null);
- this.assertSourceDoesNotContain("bar", cu);
- }
-
- public void testSetValueEnum2() throws Exception {
- this.createEnum("TestEnum", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums.TestEnum bar();");
- String expected = "@Foo(bar = XXX)";
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain(expected, cu);
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String> daea = new EnumDeclarationAnnotationElementAdapter(daa, "bar");
- AnnotationElementAdapter<String> aea = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea);
- aea.setValue("enums.TestEnum.XXX");
- this.assertSourceContains("import static enums.TestEnum.XXX;", cu);
- this.assertSourceContains(expected, cu);
- }
-
- public void testSetValueEnumImportCollision1() throws Exception {
- this.createEnum("enums1", "TestEnum", "XXX, YYY, ZZZ");
- this.createEnum("enums2", "TestEnum", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums1.TestEnum bar1(); enums2.TestEnum bar2();");
- String expected = "@Foo(bar1 = XXX, bar2 = TestEnum.XXX)";
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
-
- DeclarationAnnotationElementAdapter<String> daea1 = new EnumDeclarationAnnotationElementAdapter(daa, "bar1");
- AnnotationElementAdapter<String> aea1 = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea1);
- aea1.setValue("enums1.TestEnum.XXX");
-
- DeclarationAnnotationElementAdapter<String> daea2 = new EnumDeclarationAnnotationElementAdapter(daa, "bar2");
- AnnotationElementAdapter<String> aea2 = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea2);
- aea2.setValue("enums2.TestEnum.XXX");
-
- this.assertSourceContains("import static enums1.TestEnum.XXX;", cu);
- this.assertSourceDoesNotContain("import static enums2.TestEnum.XXX;", cu);
- this.assertSourceContains("import enums2.TestEnum;", cu);
- this.assertSourceContains(expected, cu);
- }
-
- public void testSetValueEnumImportCollision2() throws Exception {
- this.createEnum("enums1", "TestEnum", "XXX, YYY, ZZZ");
- this.createEnum("enums2", "TestEnum", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums1.TestEnum bar1(); enums2.TestEnum bar2();");
- String expected = "@annot.Foo(bar1=XXX, bar2 = TestEnum.XXX)";
- ICompilationUnit cu = this.createTestType("static enums1.TestEnum.*", "@annot.Foo(bar1=XXX)");
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
-
- DeclarationAnnotationElementAdapter<String> daea1 = new EnumDeclarationAnnotationElementAdapter(daa, "bar1");
- AnnotationElementAdapter<String> aea1 = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea1);
- assertNotNull(aea1.getValue());
-
- DeclarationAnnotationElementAdapter<String> daea2 = new EnumDeclarationAnnotationElementAdapter(daa, "bar2");
- AnnotationElementAdapter<String> aea2 = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea2);
- aea2.setValue("enums2.TestEnum.XXX");
-
- this.assertSourceContains("import static enums1.TestEnum.*;", cu);
- this.assertSourceDoesNotContain("import static enums2.TestEnum.XXX;", cu);
- this.assertSourceContains("import enums2.TestEnum;", cu);
- this.assertSourceContains(expected, cu);
- }
-
- public void testSetValueEnumImportCollision3() throws Exception {
- this.createEnum("TestEnum1", "XXX, YYY, ZZZ");
- this.createEnum("TestEnum2", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums.TestEnum1 bar1(); enums.TestEnum2 bar2();");
- String expected = "@Foo(bar1 = XXX, bar2 = TestEnum2.XXX)";
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
-
- DeclarationAnnotationElementAdapter<String> daea1 = new EnumDeclarationAnnotationElementAdapter(daa, "bar1");
- AnnotationElementAdapter<String> aea1 = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea1);
- aea1.setValue("enums.TestEnum1.XXX");
-
- DeclarationAnnotationElementAdapter<String> daea2 = new EnumDeclarationAnnotationElementAdapter(daa, "bar2");
- AnnotationElementAdapter<String> aea2 = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea2);
- aea2.setValue("enums.TestEnum2.XXX");
-
- this.assertSourceContains("import static enums.TestEnum1.XXX;", cu);
- this.assertSourceContains("import enums.TestEnum2;", cu);
- this.assertSourceContains(expected, cu);
- }
-
- public void testSetValueEnumImportCollision4() throws Exception {
- this.createEnum("TestEnum1", "XXX, YYY, ZZZ");
- this.createEnum("TestEnum2", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums.TestEnum1 bar1(); enums.TestEnum2 bar2();");
- String expected = "@annot.Foo(bar1=XXX, bar2 = TestEnum2.XXX)";
- ICompilationUnit cu = this.createTestType("static enums.TestEnum1.*", "@annot.Foo(bar1=XXX)");
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
-
- DeclarationAnnotationElementAdapter<String> daea1 = new EnumDeclarationAnnotationElementAdapter(daa, "bar1");
- AnnotationElementAdapter<String> aea1 = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea1);
- assertNotNull(aea1.getValue());
-
- DeclarationAnnotationElementAdapter<String> daea2 = new EnumDeclarationAnnotationElementAdapter(daa, "bar2");
- AnnotationElementAdapter<String> aea2 = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea2);
- aea2.setValue("enums.TestEnum2.XXX");
-
- this.assertSourceContains("import static enums.TestEnum1.*;", cu);
- this.assertSourceContains("import enums.TestEnum2;", cu);
- this.assertSourceContains(expected, cu);
- }
-
- /**
- * not sure this is exactly what we want...
- * it would be nice if we just skip the static import; but it's a matter of taste...
- */
- public void testSetValueEnumImportCollision5() throws Exception {
- this.createEnum("TestEnum1", "XXX, YYY, ZZZ");
- this.createEnum("TestEnum2", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums.TestEnum1 bar1(); enums.TestEnum2 bar2();");
- String expected = "@Foo(bar1 = XXX, bar2 = TestEnum2.XXX)";
- ICompilationUnit cu = this.createTestType("enums.*", "");
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
-
- DeclarationAnnotationElementAdapter<String> daea1 = new EnumDeclarationAnnotationElementAdapter(daa, "bar1");
- AnnotationElementAdapter<String> aea1 = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea1);
- aea1.setValue("enums.TestEnum1.XXX");
-
- DeclarationAnnotationElementAdapter<String> daea2 = new EnumDeclarationAnnotationElementAdapter(daa, "bar2");
- AnnotationElementAdapter<String> aea2 = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea2);
- aea2.setValue("enums.TestEnum2.XXX");
-
- this.assertSourceContains("import enums.*;", cu);
- this.assertSourceContains("import static enums.TestEnum1.XXX;", cu);
- this.assertSourceDoesNotContain("import enums.TestEnum2;", cu);
- this.assertSourceContains(expected, cu);
- }
-
- public void testSetValueEnumImportCollision6() throws Exception {
- this.createEnum("enums1", "TestEnum", "XXX, YYY, ZZZ");
- this.createEnum("enums2", "TestEnum", "XXX, YYY, ZZZ");
- this.createEnum("enums3", "TestEnum", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums1.TestEnum bar1(); enums2.TestEnum bar2(); enums3.TestEnum bar3();");
- String expected = "@Foo(bar1 = XXX, bar2 = TestEnum.XXX, bar3 = enums3.TestEnum.XXX)";
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
-
- DeclarationAnnotationElementAdapter<String> daea1 = new EnumDeclarationAnnotationElementAdapter(daa, "bar1");
- AnnotationElementAdapter<String> aea1 = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea1);
- aea1.setValue("enums1.TestEnum.XXX");
-
- DeclarationAnnotationElementAdapter<String> daea2 = new EnumDeclarationAnnotationElementAdapter(daa, "bar2");
- AnnotationElementAdapter<String> aea2 = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea2);
- aea2.setValue("enums2.TestEnum.XXX");
-
- DeclarationAnnotationElementAdapter<String> daea3 = new EnumDeclarationAnnotationElementAdapter(daa, "bar3");
- AnnotationElementAdapter<String> aea3 = new AnnotatedElementAnnotationElementAdapter<String>(this.idField(cu), daea3);
- aea3.setValue("enums3.TestEnum.XXX");
-
- this.assertSourceContains("import static enums1.TestEnum.XXX;", cu);
- this.assertSourceDoesNotContain("import static enums2.TestEnum.XXX;", cu);
- this.assertSourceContains("import enums2.TestEnum;", cu);
- this.assertSourceDoesNotContain("import static enums3", cu);
- this.assertSourceDoesNotContain("import enums3", cu);
- this.assertSourceContains(expected, cu);
- }
-
- public void testValueStringArray() throws Exception {
- this.createAnnotationAndMembers("Foo", "String[] bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar={\"string0\", \"string1\"})");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String[]> daea = new ConversionDeclarationAnnotationElementAdapter<String[]>(daa, "bar", AnnotationStringArrayExpressionConverter.forStrings());
- AnnotationElementAdapter<String[]> aea = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea);
- assertTrue(Arrays.equals(new String[] {"string0", "string1"}, aea.getValue()));
- }
-
- public void testValueStringArrayConcatenation() throws Exception {
- this.createAnnotationAndMembers("Foo", "String[] bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar={\"stri\" + \"ng0\", \"s\" + \"tring1\"})");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String[]> daea = new ConversionDeclarationAnnotationElementAdapter<String[]>(daa, "bar", AnnotationStringArrayExpressionConverter.forStrings());
- AnnotationElementAdapter<String[]> aea = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea);
- assertTrue(Arrays.equals(new String[] {"string0", "string1"}, aea.getValue()));
- }
-
- public void testValueStringArrayEmpty() throws Exception {
- this.createAnnotationAndMembers("Foo", "String[] bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar={})");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String[]> daea = new ConversionDeclarationAnnotationElementAdapter<String[]>(daa, "bar", AnnotationStringArrayExpressionConverter.forStrings());
- AnnotationElementAdapter<String[]> aea = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea);
- assertTrue(Arrays.equals(new String[0], aea.getValue()));
- }
-
- public void testValueStringArraySingleElement() throws Exception {
- this.createAnnotationAndMembers("Foo", "String[] bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=\"string0\")");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String[]> daea = new ConversionDeclarationAnnotationElementAdapter<String[]>(daa, "bar", AnnotationStringArrayExpressionConverter.forStrings());
- AnnotationElementAdapter<String[]> aea = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea);
- assertTrue(Arrays.equals(new String[] {"string0"}, aea.getValue()));
- }
-
- public void testValueNullStringArray() throws Exception {
- this.createAnnotationAndMembers("Foo", "String[] bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo()");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String[]> daea = new IndexedConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", AnnotationStringArrayExpressionConverter.forStrings());
- AnnotationElementAdapter<String[]> aea = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea);
- assertTrue(Arrays.equals(new String[0], aea.getValue()));
- }
-
- public void testSetValueStringArray() throws Exception {
- this.createAnnotationAndMembers("Foo", "String[] bar();");
- String expected = "@Foo(bar = { \"string0\", \"string1\" })";
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain(expected, cu);
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String[]> daea = new IndexedConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", AnnotationStringArrayExpressionConverter.forStrings());
- AnnotationElementAdapter<String[]> aea = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea);
- aea.setValue(new String[] {"string0", "string1"});
- this.assertSourceContains(expected, cu);
- }
-
- public void testSetValueStringArrayEmptyRemove() throws Exception {
- this.createAnnotationAndMembers("Foo", "String[] bar();");
- String expected = "@Foo";
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain(expected, cu);
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String[]> daea = new IndexedConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", AnnotationStringArrayExpressionConverter.forStrings());
- AnnotationElementAdapter<String[]> aea = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea);
- aea.setValue(new String[0]);
- this.assertSourceDoesNotContain(expected, cu);
- }
-
- public void testSetValueStringArrayEmpty() throws Exception {
- this.createAnnotationAndMembers("Foo", "String[] bar();");
- String expected = "@Foo(bar = {})";
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain(expected, cu);
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- IndexedExpressionConverter<String> expressionConverter = new AnnotationStringArrayExpressionConverter(StringExpressionConverter.instance(), false);
- DeclarationAnnotationElementAdapter<String[]> daea = new IndexedConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", expressionConverter);
- AnnotationElementAdapter<String[]> aea = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea);
- aea.setValue(new String[0]);
- this.assertSourceContains(expected, cu);
- }
-
- public void testSetValueStringArraySingleElement() throws Exception {
- this.createAnnotationAndMembers("Foo", "String[] bar();");
- String annotation = "@Foo(bar = \"string0\")";
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain(annotation, cu);
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String[]> daea = new IndexedConversionDeclarationAnnotationElementAdapter<String>(daa, "bar", AnnotationStringArrayExpressionConverter.forStrings());
- AnnotationElementAdapter<String[]> aea = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea);
- aea.setValue(new String[] {"string0"});
- this.assertSourceContains(annotation, cu);
- }
-
- public void testValueEnumArray() throws Exception {
- this.createEnum("TestEnum", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums.TestEnum[] bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar={enums.TestEnum.XXX, enums.TestEnum.YYY})");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String[]> daea = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar");
- AnnotationElementAdapter<String[]> aea = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea);
- assertTrue(Arrays.equals(new String[] {"enums.TestEnum.XXX", "enums.TestEnum.YYY"}, aea.getValue()));
- }
-
- public void testValueEnumArrayInvalidEntry() throws Exception {
- this.createEnum("TestEnum", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums.TestEnum[] bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar={enums.TestEnum.XXX, 88})");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String[]> daea = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar");
- AnnotationElementAdapter<String[]> aea = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea);
- assertTrue(Arrays.equals(new String[] {"enums.TestEnum.XXX", null}, aea.getValue()));
- }
-
- public void testValueEnumArrayEmpty() throws Exception {
- this.createEnum("TestEnum", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums.TestEnum[] bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar={})");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String[]> daea = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar");
- AnnotationElementAdapter<String[]> aea = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea);
- assertTrue(Arrays.equals(new String[0], aea.getValue()));
- }
-
- public void testValueEnumArraySingleElement() throws Exception {
- this.createEnum("TestEnum", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums.TestEnum[] bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=enums.TestEnum.XXX)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String[]> daea = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar");
- AnnotationElementAdapter<String[]> aea = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea);
- assertTrue(Arrays.equals(new String[] {"enums.TestEnum.XXX"}, aea.getValue()));
- }
-
- public void testValueEnumArraySingleElementInvalid() throws Exception {
- this.createEnum("TestEnum", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums.TestEnum[] bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(bar=\"\")");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String[]> daea = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar");
- AnnotationElementAdapter<String[]> aea = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea);
- assertTrue(Arrays.equals(new String[] {null}, aea.getValue()));
- }
-
- public void testValueNullEnumArray() throws Exception {
- this.createEnum("TestEnum", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums.TestEnum[] bar();");
- ICompilationUnit cu = this.createTestType("@annot.Foo()");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String[]> daea = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar");
- AnnotationElementAdapter<String[]> aea = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea);
- assertTrue(Arrays.equals(new String[0], aea.getValue()));
- }
-
- public void testSetValueEnumArray() throws Exception {
- this.createEnum("TestEnum", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums.TestEnum[] bar();");
- String expected = "@Foo(bar = { XXX, YYY })";
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain(expected, cu);
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String[]> daea = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar");
- AnnotationElementAdapter<String[]> aea = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea);
- aea.setValue(new String[] {"enums.TestEnum.XXX", "enums.TestEnum.YYY"});
- this.assertSourceContains("import static enums.TestEnum.XXX;", cu);
- this.assertSourceContains("import static enums.TestEnum.YYY;", cu);
- this.assertSourceContains(expected, cu);
- }
-
- public void testSetValueEnumArrayEmptyRemove() throws Exception {
- this.createEnum("TestEnum", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums.TestEnum[] bar();");
- String expected = "@Foo";
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain(expected, cu);
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String[]> daea = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar");
- AnnotationElementAdapter<String[]> aea = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea);
- aea.setValue(new String[0]);
- this.assertSourceDoesNotContain(expected, cu);
- }
-
- public void testSetValueEnumArrayEmpty() throws Exception {
- this.createEnum("TestEnum", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums.TestEnum[] bar();");
- String expected = "@Foo(bar = {})";
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain(expected, cu);
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String[]> daea = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar", false);
- AnnotationElementAdapter<String[]> aea = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea);
- aea.setValue(new String[0]);
- this.assertSourceContains(expected, cu);
- }
-
- public void testSetValueEnumArraySingleElement() throws Exception {
- this.createEnum("TestEnum", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums.TestEnum[] bar();");
- String expected = "@Foo(bar = XXX)";
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain(expected, cu);
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationElementAdapter<String[]> daea = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar");
- AnnotationElementAdapter<String[]> aea = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea);
- aea.setValue(new String[] {"enums.TestEnum.XXX"});
- this.assertSourceContains("import static enums.TestEnum.XXX;", cu);
- this.assertSourceContains(expected, cu);
- }
-
- public void testSetValueEnumArrayImportCollision1() throws Exception {
- this.createEnum("enums1", "TestEnum", "XXX, YYY, ZZZ");
- this.createEnum("enums2", "TestEnum", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums1.TestEnum[] bar1(); enums2.TestEnum[] bar2();");
- String expected = "@Foo(bar1 = { XXX, YYY }, bar2 = { TestEnum.XXX, TestEnum.YYY })";
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
-
- DeclarationAnnotationElementAdapter<String[]> daea1 = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar1");
- AnnotationElementAdapter<String[]> aea1 = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea1);
- aea1.setValue(new String[] {"enums1.TestEnum.XXX", "enums1.TestEnum.YYY"});
-
- DeclarationAnnotationElementAdapter<String[]> daea2 = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar2");
- AnnotationElementAdapter<String[]> aea2 = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea2);
- aea2.setValue(new String[] {"enums2.TestEnum.XXX", "enums2.TestEnum.YYY"});
-
- this.assertSourceContains("import static enums1.TestEnum.XXX;", cu);
- this.assertSourceContains("import static enums1.TestEnum.YYY;", cu);
- this.assertSourceDoesNotContain("import static enums2.TestEnum.XXX;", cu);
- this.assertSourceDoesNotContain("import static enums2.TestEnum.YYY;", cu);
- this.assertSourceContains("import enums2.TestEnum;", cu);
- this.assertSourceContains(expected, cu);
- }
-
- public void testSetValueEnumArrayImportCollision2() throws Exception {
- this.createEnum("enums1", "TestEnum", "XXX, YYY, ZZZ");
- this.createEnum("enums2", "TestEnum", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums1.TestEnum[] bar1(); enums2.TestEnum[] bar2();");
- String expected = "@annot.Foo(bar1={XXX,YYY}, bar2 = { TestEnum.XXX, TestEnum.YYY })";
- ICompilationUnit cu = this.createTestType("static enums1.TestEnum.*", "@annot.Foo(bar1={XXX,YYY})");
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
-
- DeclarationAnnotationElementAdapter<String[]> daea1 = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar1");
- AnnotationElementAdapter<String[]> aea1 = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea1);
- assertNotNull(aea1.getValue());
-
- DeclarationAnnotationElementAdapter<String[]> daea2 = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar2");
- AnnotationElementAdapter<String[]> aea2 = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea2);
- aea2.setValue(new String[] {"enums2.TestEnum.XXX", "enums2.TestEnum.YYY"});
-
- this.assertSourceContains("import static enums1.TestEnum.*;", cu);
- this.assertSourceDoesNotContain("import static enums2.TestEnum.XXX;", cu);
- this.assertSourceDoesNotContain("import static enums2.TestEnum.YYY;", cu);
- this.assertSourceContains("import enums2.TestEnum;", cu);
- this.assertSourceContains(expected, cu);
- }
-
- public void testSetValueEnumArrayImportCollision3() throws Exception {
- this.createEnum("TestEnum1", "XXX, YYY, ZZZ");
- this.createEnum("TestEnum2", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums.TestEnum1[] bar1(); enums.TestEnum2[] bar2();");
- String expected = "@Foo(bar1 = { XXX, YYY }, bar2 = { TestEnum2.XXX, TestEnum2.YYY })";
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
-
- DeclarationAnnotationElementAdapter<String[]> daea1 = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar1");
- AnnotationElementAdapter<String[]> aea1 = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea1);
- aea1.setValue(new String[] {"enums.TestEnum1.XXX", "enums.TestEnum1.YYY"});
-
- DeclarationAnnotationElementAdapter<String[]> daea2 = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar2");
- AnnotationElementAdapter<String[]> aea2 = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea2);
- aea2.setValue(new String[] {"enums.TestEnum2.XXX", "enums.TestEnum2.YYY"});
-
- this.assertSourceContains("import static enums.TestEnum1.XXX;", cu);
- this.assertSourceContains("import static enums.TestEnum1.YYY;", cu);
- this.assertSourceDoesNotContain("import static enums.TestEnum2.XXX;", cu);
- this.assertSourceDoesNotContain("import static enums.TestEnum2.YYY;", cu);
- this.assertSourceContains("import enums.TestEnum2;", cu);
- this.assertSourceContains(expected, cu);
- }
-
- public void testSetValueEnumArrayImportCollision4() throws Exception {
- this.createEnum("TestEnum1", "XXX, YYY, ZZZ");
- this.createEnum("TestEnum2", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums.TestEnum1[] bar1(); enums.TestEnum2[] bar2();");
- String expected = "@annot.Foo(bar1={XXX,YYY}, bar2 = { TestEnum2.XXX, TestEnum2.YYY })";
- ICompilationUnit cu = this.createTestType("static enums.TestEnum1.*", "@annot.Foo(bar1={XXX,YYY})");
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
-
- DeclarationAnnotationElementAdapter<String[]> daea1 = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar1");
- AnnotationElementAdapter<String[]> aea1 = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea1);
- assertNotNull(aea1.getValue());
-
- DeclarationAnnotationElementAdapter<String[]> daea2 = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar2");
- AnnotationElementAdapter<String[]> aea2 = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea2);
- aea2.setValue(new String[] {"enums.TestEnum2.XXX", "enums.TestEnum2.YYY"});
-
- this.assertSourceContains("import static enums.TestEnum1.*;", cu);
- this.assertSourceDoesNotContain("import static enums.TestEnum2.XXX;", cu);
- this.assertSourceDoesNotContain("import static enums.TestEnum2.YYY;", cu);
- this.assertSourceContains("import enums.TestEnum2;", cu);
- this.assertSourceContains(expected, cu);
- }
-
- public void testSetValueEnumArrayImportCollision6() throws Exception {
- this.createEnum("enums1", "TestEnum", "XXX, YYY, ZZZ");
- this.createEnum("enums2", "TestEnum", "XXX, YYY, ZZZ");
- this.createEnum("enums3", "TestEnum", "XXX, YYY, ZZZ");
- this.createAnnotationAndMembers("Foo", "enums1.TestEnum[] bar1(); enums2.TestEnum[] bar2(); enums3.TestEnum[] bar3();");
- String expected = "@Foo(bar1 = { XXX, YYY }, bar2 = { TestEnum.XXX, TestEnum.YYY }, bar3 = { enums3.TestEnum.XXX, enums3.TestEnum.YYY })";
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
-
- DeclarationAnnotationElementAdapter<String[]> daea1 = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar1");
- AnnotationElementAdapter<String[]> aea1 = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea1);
- aea1.setValue(new String[] {"enums1.TestEnum.XXX", "enums1.TestEnum.YYY"});
-
- DeclarationAnnotationElementAdapter<String[]> daea2 = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar2");
- AnnotationElementAdapter<String[]> aea2 = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea2);
- aea2.setValue(new String[] {"enums2.TestEnum.XXX", "enums2.TestEnum.YYY"});
-
- DeclarationAnnotationElementAdapter<String[]> daea3 = new EnumArrayDeclarationAnnotationElementAdapter(daa, "bar3");
- AnnotationElementAdapter<String[]> aea3 = new AnnotatedElementAnnotationElementAdapter<String[]>(this.idField(cu), daea3);
- aea3.setValue(new String[] {"enums3.TestEnum.XXX", "enums3.TestEnum.YYY"});
-
- this.assertSourceContains("import static enums1.TestEnum.XXX;", cu);
- this.assertSourceContains("import static enums1.TestEnum.YYY;", cu);
- this.assertSourceDoesNotContain("import static enums2", cu);
- this.assertSourceContains("import enums2.TestEnum;", cu);
- this.assertSourceDoesNotContain("import static enums3", cu);
- this.assertSourceDoesNotContain("import enums3", cu);
- this.assertSourceContains(expected, cu);
- }
-
-}
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/MiscTests.java b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/MiscTests.java
deleted file mode 100644
index 77ef53aa9b..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/MiscTests.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2009 Oracle. 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:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.core.tests.internal.utility.jdt;
-
-import org.eclipse.jdt.core.IField;
-import org.eclipse.jdt.core.IType;
-import org.eclipse.jdt.core.Signature;
-
-@SuppressWarnings("nls")
-public class MiscTests extends AnnotationTestCase {
-
- public MiscTests(String name) {
- super(name);
- }
-
- /*
- * Signature.toString(...) returns a dot-qualified name for member types
- */
- public void testSignature() throws Exception {
- IType hashTableType = this.getJavaProject().getJavaProject().findType("java.util.Hashtable");
- IField tableField = hashTableType.getField("table");
- String tableFieldTypeSignature = tableField.getTypeSignature();
- String tableFieldTypeName = Signature.toString(tableFieldTypeSignature);
- assertEquals(tableFieldTypeName, "java.util.Hashtable.Entry[]");
- }
-
- /*
- * IType.getFullyQualifiedName() returns a dollar-qualified name for member types
- * (but the lookup on IJavaProject takes a dot-qualified name!)
- */
- public void testITypeName() throws Exception {
- IType hashTableEntryType = this.getJavaProject().getJavaProject().findType("java.util.Hashtable.Entry");
- assertEquals(hashTableEntryType.getFullyQualifiedName(), "java.util.Hashtable$Entry");
- }
-
- public void testITypeParameterizedName() throws Exception {
- IType mapType = this.getJavaProject().getJavaProject().findType("java.util.Map");
- assertEquals(mapType.getFullyQualifiedParameterizedName(), "java.util.Map<K extends java.lang.Object, V extends java.lang.Object>");
- }
-
-}
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/NestedDeclarationAnnotationAdapterTests.java b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/NestedDeclarationAnnotationAdapterTests.java
deleted file mode 100644
index f92e2d832f..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/NestedDeclarationAnnotationAdapterTests.java
+++ /dev/null
@@ -1,763 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2010 Oracle. 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:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.core.tests.internal.utility.jdt;
-
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.dom.Annotation;
-import org.eclipse.jdt.core.dom.NormalAnnotation;
-import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
-import org.eclipse.jdt.core.dom.StringLiteral;
-import org.eclipse.jpt.common.core.internal.utility.jdt.ElementAnnotationAdapter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.NestedDeclarationAnnotationAdapter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
-import org.eclipse.jpt.common.core.utility.jdt.AnnotationAdapter;
-import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationAdapter;
-import org.eclipse.jpt.common.core.utility.jdt.Member;
-import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration;
-
-@SuppressWarnings("nls")
-public class NestedDeclarationAnnotationAdapterTests extends AnnotationTestCase {
-
- public NestedDeclarationAnnotationAdapterTests(String name) {
- super(name);
- }
-
- private void createAnnotationAndMembers(String annotationName, String annotationBody) throws Exception {
- this.javaProject.createCompilationUnit("annot", annotationName + ".java", "public @interface " + annotationName + " { " + annotationBody + " }");
- }
-
- public void testAnnotation1() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotation=@annot.Bar)");
-
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
- assertEquals("annot.Bar", annotation.getTypeName().getFullyQualifiedName());
- assertTrue(annotation.isMarkerAnnotation());
- }
-
- public void testAnnotation2() throws Exception {
- this.createAnnotationAndMembers("Baz", "String value();");
- this.createAnnotationAndMembers("Bar", "annot.Baz yana();");
- this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotation=@annot.Bar(yana=@annot.Baz))");
-
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationAdapter daa2 = new NestedDeclarationAnnotationAdapter(daa1, "nestedAnnotation", "annot.Bar");
- DeclarationAnnotationAdapter daa3 = new NestedDeclarationAnnotationAdapter(daa2, "yana", "annot.Baz");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa3);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
- assertEquals("annot.Baz", annotation.getTypeName().getFullyQualifiedName());
- assertTrue(annotation.isMarkerAnnotation());
- }
-
- public void testAnnotationNull1() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();");
- ICompilationUnit cu = this.createTestType("@annot.Foo()");
-
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
- }
-
- public void testAnnotationNull2() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();");
- ICompilationUnit cu = this.createTestType();
-
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
- }
-
- public void testAnnotationNull3() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Foo", "String nestedAnnotation();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotation=\"annot.Bar\")");
-
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
- }
-
- public void testAnnotationNull4() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Bar2", "String value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar2 nestedAnnotation();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotation=@annot.Bar2)");
-
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
- }
-
- public void testRemoveAnnotation1() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();");
- String na = "@annot.Foo(nestedAnnotation=@annot.Bar)";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa.removeAnnotation();
- this.assertSourceDoesNotContain(na, cu);
- this.assertSourceDoesNotContain("nestedAnnotation", cu);
- }
-
- public void testRemoveAnnotation1a() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();");
- String na = "@annot.Foo(nestedAnnotation=@annot.Bar)";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa.removeAnnotation();
- this.assertSourceDoesNotContain(na, cu);
- this.assertSourceContains("Foo", cu);
- }
-
- public void testRemoveAnnotation2() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();");
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain("Foo", cu);
-
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.removeAnnotation();
- this.assertSourceDoesNotContain("Foo", cu);
- }
-
- public void testRemoveAnnotation3() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Foo", "String nestedAnnotation();");
- String na = "@annot.Foo(nestedAnnotation=\"annot.Bar\")";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.removeAnnotation();
- this.assertSourceContains(na, cu);
- }
-
- public void testRemoveAnnotation4() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Bar2", "String value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar2 nestedAnnotation();");
- String na = "@annot.Foo(nestedAnnotation=@annot.Bar2)";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.removeAnnotation();
- this.assertSourceContains(na, cu);
- }
-
- public void testRemoveAnnotation5() throws Exception {
- this.createAnnotationAndMembers("Baz", "String value();");
- this.createAnnotationAndMembers("Bar", "annot.Baz nestedAnnotation2();");
- this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation1();");
- String na = "@annot.Foo(nestedAnnotation1=@annot.Bar(nestedAnnotation2=@annot.Baz))";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daaFoo = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationAdapter daaBar = new NestedDeclarationAnnotationAdapter(daaFoo, "nestedAnnotation1", "annot.Bar");
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(daaBar, "nestedAnnotation2", "annot.Baz");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa.removeAnnotation();
- this.assertSourceDoesNotContain(na, cu);
- this.assertSourceDoesNotContain("Baz", cu);
- }
-
- public void testRemoveAnnotation5a() throws Exception {
- this.createAnnotationAndMembers("Baz", "String value();");
- this.createAnnotationAndMembers("Bar", "annot.Baz nestedAnnotation2();");
- this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation1();");
- String na = "@annot.Foo(nestedAnnotation1=@annot.Bar(nestedAnnotation2=@annot.Baz))";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daaFoo = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationAdapter daaBar = new NestedDeclarationAnnotationAdapter(daaFoo, "nestedAnnotation1", "annot.Bar");
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(daaBar, "nestedAnnotation2", "annot.Baz");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa.removeAnnotation();
- this.assertSourceDoesNotContain(na, cu);
- this.assertSourceContains("@annot.Foo(nestedAnnotation1=@Bar)", cu);
- }
-
- public void testNewMarkerAnnotation1() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();");
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain("Foo", cu);
-
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains("@Foo(nestedAnnotation = @Bar)", cu);
- }
-
- public void testNewMarkerAnnotation2() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar value();");
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain("Foo", cu);
-
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains("@Foo(@Bar)", cu);
- }
-
- public void testNewMarkerAnnotation3() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();");
- ICompilationUnit cu = this.createTestType("@annot.Foo");
- String expected = "@Foo(nestedAnnotation = @Bar)";
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected, cu);
- }
-
- public void testNewMarkerAnnotation4() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo");
- String expected = "@Foo(@Bar)";
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected, cu);
- }
-
- public void testNewMarkerAnnotation5() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation(); String value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")");
- String expected = "@Foo(value = \"something\", nestedAnnotation = @Bar)";
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected, cu);
- }
-
- public void testNewMarkerAnnotation6() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Foo", "Object value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")");
- String expected = "@annot.Foo(@Bar)";
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected, cu);
- }
-
- public void testNewMarkerAnnotation7() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Foo", "String xxx(); annot.Bar nestedAnnotation();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(xxx=\"something\")");
- String expected = "@annot.Foo(xxx=\"something\", nestedAnnotation = @Bar)";
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected, cu);
- }
-
- public void testNewMarkerAnnotation8() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Foo", "String xxx(); annot.Bar value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(xxx=\"something\")");
- String expected = "@annot.Foo(xxx=\"something\", value = @Bar)";
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected, cu);
- }
-
- public void testNewSingleMemberAnnotation1() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();");
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain("Foo", cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation1(declaration);
- }
- });
- this.assertSourceContains("@Foo(nestedAnnotation = @Bar(\"test string literal\"))", cu);
- }
-
- void editNewSingleMemberAnnotation1(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar");
- SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newSingleMemberAnnotation(declaration);
- StringLiteral stringLiteral = annotation.getAST().newStringLiteral();
- stringLiteral.setLiteralValue("test string literal");
- annotation.setValue(stringLiteral);
- }
-
- public void testNewSingleMemberAnnotation2() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();");
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain("Foo", cu);
-
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- SingleMemberAnnotation annotation = (SingleMemberAnnotation) aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation2(declaration);
- }
- });
- this.assertSourceContains("@Foo(@Bar(\"test string literal\"))", cu);
- }
-
- void editNewSingleMemberAnnotation2(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", "annot.Bar");
- SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newSingleMemberAnnotation(declaration);
- StringLiteral stringLiteral = annotation.getAST().newStringLiteral();
- stringLiteral.setLiteralValue("test string literal");
- annotation.setValue(stringLiteral);
- }
-
- public void testNewSingleMemberAnnotation3() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();");
- ICompilationUnit cu = this.createTestType("@annot.Foo");
- String expected = "@Foo(nestedAnnotation = @Bar(\"test string literal\"))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation3(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewSingleMemberAnnotation3(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar");
- SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newSingleMemberAnnotation(declaration);
- StringLiteral stringLiteral = annotation.getAST().newStringLiteral();
- stringLiteral.setLiteralValue("test string literal");
- annotation.setValue(stringLiteral);
- }
-
- public void testNewSingleMemberAnnotation4() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo");
- String expected = "@Foo(@Bar(\"test string literal\"))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation4(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewSingleMemberAnnotation4(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", "annot.Bar");
- SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newSingleMemberAnnotation(declaration);
- StringLiteral stringLiteral = annotation.getAST().newStringLiteral();
- stringLiteral.setLiteralValue("test string literal");
- annotation.setValue(stringLiteral);
- }
-
- public void testNewSingleMemberAnnotation5() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation(); String value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")");
- String expected = "@Foo(value = \"something\", nestedAnnotation = @Bar(\"test string literal\"))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation5(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewSingleMemberAnnotation5(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar");
- SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newSingleMemberAnnotation(declaration);
- StringLiteral stringLiteral = annotation.getAST().newStringLiteral();
- stringLiteral.setLiteralValue("test string literal");
- annotation.setValue(stringLiteral);
- }
-
- public void testNewSingleMemberAnnotation6() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Foo", "Object value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")");
- String expected = "@annot.Foo(@Bar(\"test string literal\"))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation6(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewSingleMemberAnnotation6(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", "annot.Bar");
- SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newSingleMemberAnnotation(declaration);
- StringLiteral stringLiteral = annotation.getAST().newStringLiteral();
- stringLiteral.setLiteralValue("test string literal");
- annotation.setValue(stringLiteral);
- }
-
- public void testNewSingleMemberAnnotation7() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation(); String xxx();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(xxx=\"something\")");
- String expected = "@annot.Foo(xxx=\"something\", nestedAnnotation = @Bar(\"test string literal\"))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation7(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewSingleMemberAnnotation7(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar");
- SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newSingleMemberAnnotation(declaration);
- StringLiteral stringLiteral = annotation.getAST().newStringLiteral();
- stringLiteral.setLiteralValue("test string literal");
- annotation.setValue(stringLiteral);
- }
-
- public void testNewSingleMemberAnnotation8() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar value(); String xxx();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(xxx=\"something\")");
- String expected = "@annot.Foo(xxx=\"something\", value = @Bar(\"test string literal\"))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation8(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewSingleMemberAnnotation8(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", "annot.Bar");
- SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newSingleMemberAnnotation(declaration);
- StringLiteral stringLiteral = annotation.getAST().newStringLiteral();
- stringLiteral.setLiteralValue("test string literal");
- annotation.setValue(stringLiteral);
- }
-
- public void testNewNormalAnnotation1() throws Exception {
- this.createAnnotationAndMembers("Bar", "String yyy();");
- this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();");
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain("Foo", cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation1(declaration);
- }
- });
- this.assertSourceContains("@Foo(nestedAnnotation = @Bar(yyy = \"test string literal\"))", cu);
- }
-
- void editNewNormalAnnotation1(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar");
- NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newNormalAnnotation(declaration);
- this.addMemberValuePair(annotation, "yyy", "test string literal");
- }
-
- public void testNewNormalAnnotation2() throws Exception {
- this.createAnnotationAndMembers("Bar", "String yyy();");
- this.createAnnotationAndMembers("Foo", "annot.Bar value();");
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain("Foo", cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation2(declaration);
- }
- });
- this.assertSourceContains("@Foo(@Bar(yyy = \"test string literal\"))", cu);
- }
-
- void editNewNormalAnnotation2(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", "annot.Bar");
- NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newNormalAnnotation(declaration);
- this.addMemberValuePair(annotation, "yyy", "test string literal");
- }
-
- public void testNewNormalAnnotation3() throws Exception {
- this.createAnnotationAndMembers("Bar", "String yyy();");
- this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation();");
- ICompilationUnit cu = this.createTestType("@annot.Foo");
- String expected = "@Foo(nestedAnnotation = @Bar(yyy = \"test string literal\"))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation3(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewNormalAnnotation3(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar");
- NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newNormalAnnotation(declaration);
- this.addMemberValuePair(annotation, "yyy", "test string literal");
- }
-
- public void testNewNormalAnnotation4() throws Exception {
- this.createAnnotationAndMembers("Bar", "String yyy();");
- this.createAnnotationAndMembers("Foo", "annot.Bar value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo");
- String expected = "@Foo(@Bar(yyy = \"test string literal\"))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation4(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewNormalAnnotation4(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", "annot.Bar");
- NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newNormalAnnotation(declaration);
- this.addMemberValuePair(annotation, "yyy", "test string literal");
- }
-
- public void testNewNormalAnnotation5() throws Exception {
- this.createAnnotationAndMembers("Bar", "String yyy();");
- this.createAnnotationAndMembers("Foo", "annot.Bar nestedAnnotation(); String value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")");
- String expected = "@Foo(value = \"something\", nestedAnnotation = @Bar(yyy = \"test string literal\"))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation5(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewNormalAnnotation5(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar");
- NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newNormalAnnotation(declaration);
- this.addMemberValuePair(annotation, "yyy", "test string literal");
- }
-
- public void testNewNormalAnnotation6() throws Exception {
- this.createAnnotationAndMembers("Bar", "String yyy();");
- this.createAnnotationAndMembers("Foo", "Object value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")");
- String expected = "@annot.Foo(@Bar(yyy = \"test string literal\"))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation6(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewNormalAnnotation6(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", "annot.Bar");
- NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newNormalAnnotation(declaration);
- this.addMemberValuePair(annotation, "yyy", "test string literal");
- }
-
- public void testNewNormalAnnotation7() throws Exception {
- this.createAnnotationAndMembers("Bar", "String yyy();");
- this.createAnnotationAndMembers("Foo", "String xxx(); annot.Bar nestedAnnotation();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(xxx=\"something\")");
- String expected = "@annot.Foo(xxx=\"something\", nestedAnnotation = @Bar(yyy = \"test string literal\"))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation7(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewNormalAnnotation7(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotation", "annot.Bar");
- NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newNormalAnnotation(declaration);
- this.addMemberValuePair(annotation, "yyy", "test string literal");
- }
-
- public void testNewNormalAnnotation8() throws Exception {
- this.createAnnotationAndMembers("Bar", "String yyy();");
- this.createAnnotationAndMembers("Foo", "String xxx(); annot.Bar value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(xxx=\"something\")");
- String expected = "@annot.Foo(xxx=\"something\", value = @Bar(yyy = \"test string literal\"))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation8(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewNormalAnnotation8(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", "annot.Bar");
- NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newNormalAnnotation(declaration);
- this.addMemberValuePair(annotation, "yyy", "test string literal");
- }
-
-}
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/NestedIndexedDeclarationAnnotationAdapterTests.java b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/NestedIndexedDeclarationAnnotationAdapterTests.java
deleted file mode 100644
index ae4f0f9788..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/NestedIndexedDeclarationAnnotationAdapterTests.java
+++ /dev/null
@@ -1,2229 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2010 Oracle. 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:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.core.tests.internal.utility.jdt;
-
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.dom.ASTNode;
-import org.eclipse.jdt.core.dom.Annotation;
-import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.dom.NormalAnnotation;
-import org.eclipse.jdt.core.dom.NumberLiteral;
-import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
-import org.eclipse.jpt.common.core.internal.utility.jdt.ElementAnnotationAdapter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.ElementIndexedAnnotationAdapter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.NestedIndexedDeclarationAnnotationAdapter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
-import org.eclipse.jpt.common.core.utility.jdt.AnnotationAdapter;
-import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationAdapter;
-import org.eclipse.jpt.common.core.utility.jdt.IndexedAnnotationAdapter;
-import org.eclipse.jpt.common.core.utility.jdt.IndexedDeclarationAnnotationAdapter;
-import org.eclipse.jpt.common.core.utility.jdt.Member;
-import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration;
-
-@SuppressWarnings("nls")
-public class NestedIndexedDeclarationAnnotationAdapterTests extends AnnotationTestCase {
-
- public NestedIndexedDeclarationAnnotationAdapterTests(String name) {
- super(name);
- }
-
- private void createAnnotation(String annotationName) throws Exception {
- this.createAnnotationAndMembers(annotationName, "");
- }
-
- private void createAnnotationAndMembers(String annotationName, String annotationBody) throws Exception {
- this.javaProject.createCompilationUnit("annot", annotationName + ".java", "public @interface " + annotationName + " { " + annotationBody + " }");
- }
-
- public void testAnnotation1() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations={@annot.Bar, @annot.Bar(\"two\")})");
- // 0
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- CompilationUnit astRoot = this.buildASTRoot(cu);
- Annotation annotation = aa.getAnnotation(astRoot);
- assertNotNull(annotation);
- assertEquals("annot.Bar", annotation.getTypeName().getFullyQualifiedName());
- assertTrue(annotation.isMarkerAnnotation());
-
- // 1
- daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 1, "annot.Bar");
- aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- annotation = aa.getAnnotation(astRoot);
- assertNotNull(annotation);
- assertEquals("annot.Bar", annotation.getTypeName().getFullyQualifiedName());
- assertTrue(annotation.isSingleMemberAnnotation());
- }
-
- public void testAnnotation2() throws Exception {
- this.createAnnotation("Baz");
- this.createAnnotationAndMembers("Bar", "annot.Baz[] yana();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=@annot.Bar(yana=@annot.Baz))");
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "nestedAnnotations", 0, "annot.Bar");
- DeclarationAnnotationAdapter daa3 = new NestedIndexedDeclarationAnnotationAdapter(daa2, "yana", 0, "annot.Baz");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa3);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
- assertEquals("annot.Baz", annotation.getTypeName().getFullyQualifiedName());
- assertTrue(annotation.isMarkerAnnotation());
- }
-
- public void testAnnotation3() throws Exception {
- this.createAnnotation("Baz");
- this.createAnnotationAndMembers("Bar", "annot.Baz[] yana();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=@annot.Bar(yana={@annot.Baz}))");
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "nestedAnnotations", 0, "annot.Bar");
- DeclarationAnnotationAdapter daa3 = new NestedIndexedDeclarationAnnotationAdapter(daa2, "yana", 0, "annot.Baz");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa3);
- CompilationUnit astRoot = this.buildASTRoot(cu);
- Annotation annotation = aa.getAnnotation(astRoot);
- assertNotNull(annotation);
- assertEquals("annot.Baz", annotation.getTypeName().getFullyQualifiedName());
- assertTrue(annotation.isMarkerAnnotation());
-
- // name mismatch
- daa3 = new NestedIndexedDeclarationAnnotationAdapter(daa2, "yana", 0, "annot.Xyz");
- aa = new ElementAnnotationAdapter(this.idField(cu), daa3);
- annotation = aa.getAnnotation(astRoot);
- assertNull(annotation);
- }
-
- public void testAnnotationNull1() throws Exception {
- this.createAnnotation("Bar");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo()");
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
- }
-
- public void testAnnotationNull2() throws Exception {
- this.createAnnotation("Bar");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType();
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
- }
-
- public void testAnnotationNull3() throws Exception {
- this.createAnnotation("Bar");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=\"annot.Bar\")");
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
- }
-
- public void testAnnotationNull4() throws Exception {
- this.createAnnotation("NotBar");
- this.createAnnotation("Bar");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=@annot.NotBar)");
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
- }
-
- public void testAnnotationNull5() throws Exception {
- this.createAnnotationAndMembers("Bar", "String value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations={@annot.Bar, @annot.Bar(\"two\")})");
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 2, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
- }
-
- public void testAnnotationNull6() throws Exception {
- this.createAnnotation("Xyz");
- this.createAnnotation("Baz");
- this.createAnnotationAndMembers("Bar", "annot.Baz[] yana();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=@annot.Bar(yana={@annot.Baz}))");
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("Foo");
- DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "nestedAnnotations", 0, "annot.Bar");
- DeclarationAnnotationAdapter daa3 = new NestedIndexedDeclarationAnnotationAdapter(daa2, "yana", 0, "annot.Xyz");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa3);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
- }
-
- public void testRemoveAnnotation1() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- String na = "@annot.Foo(nestedAnnotations={@annot.Bar(0), @annot.Bar(1)})";
- String expected = "@annot.Foo(nestedAnnotations={null, @annot.Bar(1)})";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceDoesNotContain(expected, cu);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "nestedAnnotations", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa2);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa.removeAnnotation();
- this.assertSourceDoesNotContain(na, cu);
- this.assertSourceContains(expected, cu);
- }
-
- public void testRemoveAnnotation2() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain("Foo", cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.removeAnnotation();
- this.assertSourceDoesNotContain("Foo", cu);
- }
-
- public void testRemoveAnnotation3() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "String[] nestedAnnotations();");
- String na = "@annot.Foo(nestedAnnotations={\"annot.Bar1\", \"annot.Bar2\", \"annot.Bar3\"})";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.removeAnnotation();
- this.assertSourceContains(na, cu);
- }
-
- public void testRemoveAnnotation4() throws Exception {
- this.createAnnotationAndMembers("NotBar", "int value();");
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.NotBar[] nestedAnnotations();");
- String na = "@annot.Foo(nestedAnnotations={@annot.NotBar(0), @annot.NotBar(1)})";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.removeAnnotation();
- this.assertSourceContains(na, cu);
- }
-
- public void testRemoveAnnotation5() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- String na = "@annot.Foo(nestedAnnotations=@annot.Bar)";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "nestedAnnotations", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa2);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa.removeAnnotation();
- assertNull(aa.getAnnotation(this.buildASTRoot(cu)));
- this.assertSourceDoesNotContain(na, cu);
- this.assertSourceDoesNotContain("nestedAnnotations", cu);
- }
-
- public void testRemoveAnnotation5a() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- String na = "@annot.Foo(nestedAnnotations=@annot.Bar)";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- AnnotationAdapter aa1 = new ElementAnnotationAdapter(this.idField(cu), daa1);
- DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "nestedAnnotations", 0, "annot.Bar");
- AnnotationAdapter aa2 = new ElementAnnotationAdapter(this.idField(cu), daa2);
- Annotation annotation = aa2.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa2.removeAnnotation();
- assertTrue(aa1.getAnnotation(this.buildASTRoot(cu)).isMarkerAnnotation());
- this.assertSourceDoesNotContain(na, cu);
- this.assertSourceContains("import annot.Foo;", cu);
- this.assertSourceContains("@Foo", cu);
- }
-
- public void testRemoveAnnotation6() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "String[] nestedAnnotations();");
- String na = "@annot.Foo(nestedAnnotations=\"annot.Bar\")";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.removeAnnotation();
- this.assertSourceContains(na, cu);
- }
-
- public void testRemoveAnnotation7() throws Exception {
- this.createAnnotationAndMembers("NotBar", "int value();");
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.NotBar[] nestedAnnotations();");
- String na = "@annot.Foo(nestedAnnotations=@annot.NotBar)";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.removeAnnotation();
- this.assertSourceContains(na, cu);
- }
-
- public void testRemoveAnnotation8() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- String na = "@annot.Foo(nestedAnnotations={@annot.Bar(0), @annot.Bar(1), @annot.Bar(2), @annot.Bar(3)})";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- AnnotationAdapter aa1 = new ElementAnnotationAdapter(this.idField(cu), daa1);
- DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "nestedAnnotations", 2, "annot.Bar");
- AnnotationAdapter aa2 = new ElementAnnotationAdapter(this.idField(cu), daa2);
- CompilationUnit astRoot = this.buildASTRoot(cu);
- Annotation annotation = aa2.getAnnotation(astRoot);
- assertNotNull(annotation);
-
- aa2.removeAnnotation();
- assertTrue(aa1.getAnnotation(astRoot).isNormalAnnotation());
- assertEquals(ASTNode.ARRAY_INITIALIZER, this.annotationElementValue(aa1.getAnnotation(astRoot), "nestedAnnotations").getNodeType());
- this.assertSourceDoesNotContain(na, cu);
- this.assertSourceContains("@annot.Foo(nestedAnnotations={@annot.Bar(0), @annot.Bar(1), null, @annot.Bar(3)})", cu);
- }
-
- public void testRemoveAnnotation9() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- String na = "@annot.Foo({@annot.Bar(0), @annot.Bar(1), @annot.Bar(2), @annot.Bar(3)})";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- AnnotationAdapter aa1 = new ElementAnnotationAdapter(this.idField(cu), daa1);
- DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "value", 2, "annot.Bar");
- AnnotationAdapter aa2 = new ElementAnnotationAdapter(this.idField(cu), daa2);
- CompilationUnit astRoot = this.buildASTRoot(cu);
- Annotation annotation = aa2.getAnnotation(astRoot);
- assertNotNull(annotation);
-
- aa2.removeAnnotation();
- assertTrue(aa1.getAnnotation(astRoot).isSingleMemberAnnotation());
- assertEquals(ASTNode.ARRAY_INITIALIZER, this.annotationElementValue(aa1.getAnnotation(astRoot), "value").getNodeType());
- this.assertSourceDoesNotContain(na, cu);
- this.assertSourceContains("@annot.Foo({@annot.Bar(0), @annot.Bar(1), null, @annot.Bar(3)})", cu);
- }
-
- public void testRemoveAnnotation10() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- String na = "@annot.Foo({@annot.Bar(0), @annot.Bar(1)})";
- String expected = "@annot.Foo({null, @annot.Bar(1)})";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceDoesNotContain(expected, cu);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "value", 0, "annot.Bar");
- AnnotationAdapter aa2 = new ElementAnnotationAdapter(this.idField(cu), daa2);
- Annotation annotation = aa2.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa2.removeAnnotation();
- this.assertSourceDoesNotContain(na, cu);
- this.assertSourceContains(expected, cu);
- }
-
- public void testRemoveAnnotation11() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- String na = "@annot.Foo({@annot.Bar(0), @annot.Bar(1)})";
- String expected = "@annot.Foo(@annot.Bar(0))";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceDoesNotContain(expected, cu);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- AnnotationAdapter aa1 = new ElementAnnotationAdapter(this.idField(cu), daa1);
- DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "value", 1, "annot.Bar");
- AnnotationAdapter aa2 = new ElementAnnotationAdapter(this.idField(cu), daa2);
- Annotation annotation = aa2.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa2.removeAnnotation();
- assertEquals(ASTNode.SINGLE_MEMBER_ANNOTATION, this.annotationElementValue(aa1.getAnnotation(this.buildASTRoot(cu)), "value").getNodeType());
- this.assertSourceDoesNotContain(na, cu);
- this.assertSourceContains(expected, cu);
- }
-
- public void testRemoveAnnotation12() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- String na = "@annot.Foo({@annot.Bar(0), null, @annot.Bar(2)})";
- String expected = "@annot.Foo(@annot.Bar(0))";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceDoesNotContain(expected, cu);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- AnnotationAdapter aa1 = new ElementAnnotationAdapter(this.idField(cu), daa1);
- DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "value", 2, "annot.Bar");
- AnnotationAdapter aa2 = new ElementAnnotationAdapter(this.idField(cu), daa2);
- Annotation annotation = aa2.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa2.removeAnnotation();
- assertEquals(ASTNode.SINGLE_MEMBER_ANNOTATION, this.annotationElementValue(aa1.getAnnotation(this.buildASTRoot(cu)), "value").getNodeType());
- this.assertSourceDoesNotContain(na, cu);
- this.assertSourceContains(expected, cu);
- }
-
- public void testRemoveAnnotation13() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- String na = "@annot.Foo({null, @annot.Bar(1)})";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "value", 1, "annot.Bar");
- AnnotationAdapter aa2 = new ElementAnnotationAdapter(this.idField(cu), daa2);
- Annotation annotation = aa2.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa2.removeAnnotation();
- this.assertSourceDoesNotContain("Bar", cu);
- }
-
- public void testRemoveAnnotation14() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- String na = "@annot.Foo({@annot.Bar(0), null, @annot.Bar(2), null})";
- String expected = "@annot.Foo(@annot.Bar(0))";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceDoesNotContain(expected, cu);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- AnnotationAdapter aa1 = new ElementAnnotationAdapter(this.idField(cu), daa1);
- DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "value", 2, "annot.Bar");
- AnnotationAdapter aa2 = new ElementAnnotationAdapter(this.idField(cu), daa2);
- Annotation annotation = aa2.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa2.removeAnnotation();
- assertEquals(ASTNode.SINGLE_MEMBER_ANNOTATION, this.annotationElementValue(aa1.getAnnotation(this.buildASTRoot(cu)), "value").getNodeType());
- this.assertSourceDoesNotContain(na, cu);
- this.assertSourceContains(expected, cu);
- }
-
- public void testRemoveAnnotation15() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- String na = "@annot.Foo({@annot.Bar(0), null, @annot.Bar(2), @annot.Bar(3)})";
- String expected = "@annot.Foo({@annot.Bar(0), null, null, @annot.Bar(3)})";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceDoesNotContain(expected, cu);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- AnnotationAdapter aa1 = new ElementAnnotationAdapter(this.idField(cu), daa1);
- DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "value", 2, "annot.Bar");
- AnnotationAdapter aa2 = new ElementAnnotationAdapter(this.idField(cu), daa2);
- CompilationUnit astRoot = this.buildASTRoot(cu);
- Annotation annotation = aa2.getAnnotation(astRoot);
- assertNotNull(annotation);
-
- aa2.removeAnnotation();
- assertEquals(ASTNode.ARRAY_INITIALIZER, this.annotationElementValue(aa1.getAnnotation(astRoot), "value").getNodeType());
- this.assertSourceDoesNotContain(na, cu);
- this.assertSourceContains(expected, cu);
- }
-
- public void testRemoveAnnotation16() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- String na = "@annot.Foo({@annot.Bar(0), null, @annot.Bar(2), @annot.Bar(3)})";
- String expected = "@annot.Foo({@annot.Bar(0), null, @annot.Bar(2)})";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceDoesNotContain(expected, cu);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- AnnotationAdapter aa1 = new ElementAnnotationAdapter(this.idField(cu), daa1);
- DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "value", 3, "annot.Bar");
- AnnotationAdapter aa2 = new ElementAnnotationAdapter(this.idField(cu), daa2);
- CompilationUnit astRoot = this.buildASTRoot(cu);
- Annotation annotation = aa2.getAnnotation(astRoot);
- assertNotNull(annotation);
-
- aa2.removeAnnotation();
- assertEquals(ASTNode.ARRAY_INITIALIZER, this.annotationElementValue(aa1.getAnnotation(astRoot), "value").getNodeType());
- this.assertSourceDoesNotContain(na, cu);
- this.assertSourceContains(expected, cu);
- }
-
- public void testRemoveAnnotation17() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- String na = "@annot.Foo(nestedAnnotations={@annot.Bar(0), null, @annot.Bar(2)})";
- String expected = "@annot.Foo(nestedAnnotations=@annot.Bar(0))";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceDoesNotContain(expected, cu);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- AnnotationAdapter aa1 = new ElementAnnotationAdapter(this.idField(cu), daa1);
- DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "nestedAnnotations", 2, "annot.Bar");
- AnnotationAdapter aa2 = new ElementAnnotationAdapter(this.idField(cu), daa2);
- Annotation annotation = aa2.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa2.removeAnnotation();
- assertEquals(ASTNode.SINGLE_MEMBER_ANNOTATION, this.annotationElementValue(aa1.getAnnotation(this.buildASTRoot(cu)), "nestedAnnotations").getNodeType());
- this.assertSourceDoesNotContain(na, cu);
- this.assertSourceContains(expected, cu);
- }
-
- public void testRemoveAnnotation18() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- String na = "@annot.Foo(nestedAnnotations={null, @annot.Bar(1)})";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "nestedAnnotations", 1, "annot.Bar");
- AnnotationAdapter aa2 = new ElementAnnotationAdapter(this.idField(cu), daa2);
- Annotation annotation = aa2.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa2.removeAnnotation();
- this.assertSourceDoesNotContain("nestedAnnotations", cu);
- }
-
- public void testRemoveAnnotation19() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- String na = "@annot.Foo(nestedAnnotations={@annot.Bar(0), null, @annot.Bar(2), null})";
- String expected = "@annot.Foo(nestedAnnotations=@annot.Bar(0))";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceDoesNotContain(expected, cu);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- AnnotationAdapter aa1 = new ElementAnnotationAdapter(this.idField(cu), daa1);
- DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "nestedAnnotations", 2, "annot.Bar");
- AnnotationAdapter aa2 = new ElementAnnotationAdapter(this.idField(cu), daa2);
- Annotation annotation = aa2.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa2.removeAnnotation();
- assertEquals(ASTNode.SINGLE_MEMBER_ANNOTATION, this.annotationElementValue(aa1.getAnnotation(this.buildASTRoot(cu)), "nestedAnnotations").getNodeType());
- this.assertSourceDoesNotContain(na, cu);
- this.assertSourceContains(expected, cu);
- }
-
- public void testRemoveAnnotation20() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- String na = "@annot.Foo(nestedAnnotations={@annot.Bar(0), null, @annot.Bar(2), @annot.Bar(3)})";
- String expected = "@annot.Foo(nestedAnnotations={@annot.Bar(0), null, null, @annot.Bar(3)})";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceDoesNotContain(expected, cu);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- AnnotationAdapter aa1 = new ElementAnnotationAdapter(this.idField(cu), daa1);
- DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "nestedAnnotations", 2, "annot.Bar");
- AnnotationAdapter aa2 = new ElementAnnotationAdapter(this.idField(cu), daa2);
- CompilationUnit astRoot = this.buildASTRoot(cu);
- Annotation annotation = aa2.getAnnotation(astRoot);
- assertNotNull(annotation);
-
- aa2.removeAnnotation();
- assertEquals(ASTNode.ARRAY_INITIALIZER, this.annotationElementValue(aa1.getAnnotation(astRoot), "nestedAnnotations").getNodeType());
- this.assertSourceDoesNotContain(na, cu);
- this.assertSourceContains(expected, cu);
- }
-
- public void testRemoveAnnotation21() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- String na = "@annot.Foo(nestedAnnotations={@annot.Bar(0), null, @annot.Bar(2), @annot.Bar(3)})";
- String expected = "@annot.Foo(nestedAnnotations={@annot.Bar(0), null, @annot.Bar(2)})";
- ICompilationUnit cu = this.createTestType(na);
- this.assertSourceDoesNotContain(expected, cu);
- this.assertSourceContains(na, cu);
-
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- AnnotationAdapter aa1 = new ElementAnnotationAdapter(this.idField(cu), daa1);
- DeclarationAnnotationAdapter daa2 = new NestedIndexedDeclarationAnnotationAdapter(daa1, "nestedAnnotations", 3, "annot.Bar");
- AnnotationAdapter aa2 = new ElementAnnotationAdapter(this.idField(cu), daa2);
- CompilationUnit astRoot = this.buildASTRoot(cu);
- Annotation annotation = aa2.getAnnotation(astRoot);
- assertNotNull(annotation);
-
- aa2.removeAnnotation();
- assertEquals(ASTNode.ARRAY_INITIALIZER, this.annotationElementValue(aa1.getAnnotation(astRoot), "nestedAnnotations").getNodeType());
- this.assertSourceDoesNotContain(na, cu);
- this.assertSourceContains(expected, cu);
- }
-
- public void testNewMarkerAnnotation1() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain("Foo", cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains("@Foo(nestedAnnotations = @Bar)", cu);
- }
-
- public void testNewMarkerAnnotation2() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain("Foo", cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains("@Foo(@Bar)", cu);
- }
-
- public void testNewMarkerAnnotation3() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo");
- String expected = "@Foo(nestedAnnotations = @Bar)";
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected, cu);
- }
-
- public void testNewMarkerAnnotation4() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo");
- String expected = "@Foo(@Bar)";
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected, cu);
- }
-
- public void testNewMarkerAnnotation5() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "String value(); annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")");
- String expected = "@Foo(value = \"something\", nestedAnnotations = @Bar)";
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected, cu);
- }
-
- public void testNewMarkerAnnotation6() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")");
- String expected = "@annot.Foo(@Bar)";
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected, cu);
- }
-
- public void testNewMarkerAnnotation7() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "String xxx(); annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(xxx=\"something\")");
- String expected = "@annot.Foo(xxx=\"something\", nestedAnnotations = @Bar)";
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected, cu);
- }
-
- public void testNewMarkerAnnotation8() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "String xxx(); annot.Bar[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(xxx=\"something\")");
- String expected = "@annot.Foo(xxx=\"something\", value = @Bar)";
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected, cu);
- }
-
- public void testNewMarkerAnnotation9() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType();
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 5, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- assertNull(aa.getAnnotation(this.buildASTRoot(cu)));
-
- aa.newMarkerAnnotation();
- this.assertSourceContains("@Foo(nestedAnnotations = { null, null, null, null, null, @Bar })", cu);
- }
-
- public void testNewMarkerAnnotation10() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "String value(); annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")");
- String expected1 = "@Foo(value = \"something\", nestedAnnotations = { null, null, null, null,";
- String expected2 = "null, @Bar })";
- this.assertSourceDoesNotContain("Bar", cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 5, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected1, cu);
- this.assertSourceContains(expected2, cu);
- }
-
- public void testNewMarkerAnnotation11() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "Object[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo({\"one\", \"two\"})");
- String expected = "@annot.Foo({@Bar, \"two\"})";
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected, cu);
- }
-
- public void testNewMarkerAnnotation12() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "Object[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo({\"one\", \"two\"})");
- this.assertSourceDoesNotContain("Bar", cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 5, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains("Bar})", cu); // split line
- }
-
- public void testNewMarkerAnnotation13() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(7)");
- String expected = "@annot.Foo(@Bar)";
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected, cu);
- }
-
- public void testNewMarkerAnnotation14() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(7)");
- this.assertSourceDoesNotContain("Bar", cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 5, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains("@annot.Foo({7,null,null,null,null,@Bar})", cu);
- }
-
- public void testNewMarkerAnnotation15() throws Exception {
- this.createAnnotationAndMembers("NotBar", "int value();");
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(@annot.NotBar)");
- String expected = "@annot.Foo(@Bar)";
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected, cu);
- }
-
- public void testNewMarkerAnnotation16() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(@annot.Bar(55))");
- String expected = "@annot.Foo({@annot.Bar(55),@Bar})";
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 1, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected, cu);
- }
-
- public void testNewMarkerAnnotation17() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations={\"something\"})");
- String expected = "@annot.Foo(nestedAnnotations={@Bar})";
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected, cu);
- }
-
- public void testNewMarkerAnnotation18() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations={\"something\"})");
- this.assertSourceDoesNotContain("Bar", cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 5, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains("Bar})", cu); // split line
- }
-
- public void testNewMarkerAnnotation19() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=\"something\")");
- String expected = "@annot.Foo(nestedAnnotations=@Bar)";
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected, cu);
- }
-
- public void testNewMarkerAnnotation20() throws Exception {
- this.createAnnotationAndMembers("NotBar", "int value();");
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=@annot.NotBar)");
- String expected = "@annot.Foo(nestedAnnotations=@Bar)";
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected, cu);
- }
-
- public void testNewMarkerAnnotation21() throws Exception {
- this.createAnnotationAndMembers("NotBar", "int value();");
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=@annot.NotBar)");
- this.assertSourceDoesNotContain("@Bar", cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 5, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains("@annot.Foo(nestedAnnotations={@annot.NotBar,null,null,null,null,@Bar})", cu);
- }
-
- public void testNewMarkerAnnotation22() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=@annot.Bar(88))");
- String expected = "@annot.Foo(nestedAnnotations=@Bar)";
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected, cu);
- }
-
- public void testNewMarkerAnnotation23() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=@annot.Bar(88))");
- String expected = "@annot.Foo(nestedAnnotations={@annot.Bar(88),null,@Bar})";
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 2, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected, cu);
- }
-
- public void testNewMarkerAnnotation24() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "Object[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(@annot.Bar(88))");
- String expected = "@annot.Foo({@annot.Bar(88),null,@Bar})";
- this.assertSourceDoesNotContain(expected, cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 2, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected, cu);
- }
-
- public void testNewMarkerAnnotation25() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations={@annot.Bar(88), @annot.Bar(77)})");
- String expected1 = "@annot.Foo(nestedAnnotations={@annot.Bar(88), @annot.Bar(77), null, null,"; // the line gets split
- String expected2 = "@Bar})";
- this.assertSourceDoesNotContain(expected1, cu);
- this.assertSourceDoesNotContain(expected2, cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 4, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected1, cu);
- this.assertSourceContains(expected2, cu);
- }
-
- public void testNewMarkerAnnotation26() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "Object[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo({@annot.Bar(88), @annot.Bar(77)})");
- String expected1 = "@annot.Foo({@annot.Bar(88), @annot.Bar(77), null, null,"; // the line gets split
- String expected2 = "@Bar})";
- this.assertSourceDoesNotContain(expected1, cu);
- this.assertSourceDoesNotContain(expected2, cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 4, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- aa.newMarkerAnnotation();
- this.assertSourceContains(expected1, cu);
- this.assertSourceContains(expected2, cu);
- }
-
- public void testNewSingleMemberAnnotation1() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain("@Foo", cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation1(declaration);
- }
- });
- this.assertSourceContains("@Foo(nestedAnnotations = @Bar(88))", cu);
- }
-
- void editNewSingleMemberAnnotation1(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newSingleMemberAnnotation(declaration);
- NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral();
- numberLiteral.setToken("88");
- annotation.setValue(numberLiteral);
- }
-
- public void testNewSingleMemberAnnotation2() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain("@Foo", cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation2(declaration);
- }
- });
- this.assertSourceContains("@Foo(@Bar(88))", cu);
- }
-
- void editNewSingleMemberAnnotation2(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar");
- SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newSingleMemberAnnotation(declaration);
- NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral();
- numberLiteral.setToken("88");
- annotation.setValue(numberLiteral);
- }
-
- public void testNewSingleMemberAnnotation3() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo");
- String expected = "@Foo(nestedAnnotations = @Bar(88))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation3(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewSingleMemberAnnotation3(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newSingleMemberAnnotation(declaration);
- NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral();
- numberLiteral.setToken("88");
- annotation.setValue(numberLiteral);
- }
-
- public void testNewSingleMemberAnnotation4() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo");
- String expected = "@Foo(@Bar(88))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation4(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewSingleMemberAnnotation4(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar");
- SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newSingleMemberAnnotation(declaration);
- NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral();
- numberLiteral.setToken("88");
- annotation.setValue(numberLiteral);
- }
-
- public void testNewSingleMemberAnnotation5() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "String value(); annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")");
- String expected = "@Foo(value = \"something\", nestedAnnotations = @Bar(88))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation5(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewSingleMemberAnnotation5(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newSingleMemberAnnotation(declaration);
- NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral();
- numberLiteral.setToken("88");
- annotation.setValue(numberLiteral);
- }
-
- public void testNewSingleMemberAnnotation6() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "Object[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")");
- String expected = "@annot.Foo(@Bar(88))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation6(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewSingleMemberAnnotation6(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar");
- SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newSingleMemberAnnotation(declaration);
- NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral();
- numberLiteral.setToken("88");
- annotation.setValue(numberLiteral);
- }
-
- public void testNewSingleMemberAnnotation7() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "String xxx(); annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(xxx=\"something\")");
- String expected = "@annot.Foo(xxx=\"something\", nestedAnnotations = @Bar(88))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation7(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewSingleMemberAnnotation7(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newSingleMemberAnnotation(declaration);
- NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral();
- numberLiteral.setToken("88");
- annotation.setValue(numberLiteral);
- }
-
- public void testNewSingleMemberAnnotation8() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "String xxx(); annot.Bar[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(xxx=\"something\")");
- String expected = "@annot.Foo(xxx=\"something\", value = @Bar(88))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation8(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewSingleMemberAnnotation8(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar");
- SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newSingleMemberAnnotation(declaration);
- NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral();
- numberLiteral.setToken("88");
- annotation.setValue(numberLiteral);
- }
-
- public void testNewSingleMemberAnnotation9() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain("@Bar", cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 5, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newSingleMemberAnnotation();
- this.assertSourceContains("@Foo(nestedAnnotations = { null, null, null, null, null, @Bar(MISSING) })", cu); // ???
- }
-
- public void testNewSingleMemberAnnotation10() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "String value(); annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")");
- String expected1 = "@Foo(value = \"something\", nestedAnnotations = { null, null, null, null,";
- String expected2 = "null, @Bar(MISSING) })"; // ???
- this.assertSourceDoesNotContain("@Bar", cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 5, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newSingleMemberAnnotation();
- this.assertSourceContains(expected1, cu);
- this.assertSourceContains(expected2, cu);
- }
-
- public void testNewSingleMemberAnnotation11() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "Object[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo({\"one\", \"two\"})");
- String expected = "@annot.Foo({@Bar(88), \"two\"})";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation11(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewSingleMemberAnnotation11(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar");
- SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newSingleMemberAnnotation(declaration);
- NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral();
- numberLiteral.setToken("88");
- annotation.setValue(numberLiteral);
- }
-
- public void testNewSingleMemberAnnotation12() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "Object[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo({\"one\", \"two\"})");
- this.assertSourceDoesNotContain("@Bar", cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 5, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newSingleMemberAnnotation();
- this.assertSourceContains("@Bar(MISSING)})", cu); // split line
- }
-
- public void testNewSingleMemberAnnotation13() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "Object[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(7)");
- String expected = "@annot.Foo(@Bar(88))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation13(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewSingleMemberAnnotation13(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar");
- SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newSingleMemberAnnotation(declaration);
- NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral();
- numberLiteral.setToken("88");
- annotation.setValue(numberLiteral);
- }
-
- public void testNewSingleMemberAnnotation14() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "Object[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(7)");
- this.assertSourceDoesNotContain("@Bar", cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 5, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newSingleMemberAnnotation();
- this.assertSourceContains("@annot.Foo({7,null,null,null,null,@Bar(MISSING)})", cu);
- }
-
- public void testNewSingleMemberAnnotation15() throws Exception {
- this.createAnnotationAndMembers("NotBar", "int value();");
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "Object[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(@annot.NotBar)");
- String expected = "@annot.Foo(@Bar(88))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation15(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewSingleMemberAnnotation15(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar");
- SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newSingleMemberAnnotation(declaration);
- NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral();
- numberLiteral.setToken("88");
- annotation.setValue(numberLiteral);
- }
-
- public void testNewSingleMemberAnnotation16() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(@annot.Bar(55))");
- String expected = "@annot.Foo({@annot.Bar(55),@Bar(88)})";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation16(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewSingleMemberAnnotation16(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 1, "annot.Bar");
- SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newSingleMemberAnnotation(declaration);
- NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral();
- numberLiteral.setToken("88");
- annotation.setValue(numberLiteral);
- }
-
- public void testNewSingleMemberAnnotation17() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations={\"something\"})");
- String expected = "@annot.Foo(nestedAnnotations={@Bar(88)})";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation17(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewSingleMemberAnnotation17(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newSingleMemberAnnotation(declaration);
- NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral();
- numberLiteral.setToken("88");
- annotation.setValue(numberLiteral);
- }
-
- public void testNewSingleMemberAnnotation18() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations={\"something\"})");
- this.assertSourceDoesNotContain("@Bar", cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 5, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newSingleMemberAnnotation();
- this.assertSourceContains("@Bar(MISSING)})", cu); // ???
- }
-
- public void testNewSingleMemberAnnotation19() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=\"something\")");
- String expected = "@annot.Foo(nestedAnnotations=@Bar(88))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation19(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewSingleMemberAnnotation19(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newSingleMemberAnnotation(declaration);
- NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral();
- numberLiteral.setToken("88");
- annotation.setValue(numberLiteral);
- }
-
- public void testNewSingleMemberAnnotation20() throws Exception {
- this.createAnnotationAndMembers("NotBar", "int value();");
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=@annot.NotBar)");
- String expected = "@annot.Foo(nestedAnnotations=@Bar(88))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation20(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewSingleMemberAnnotation20(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newSingleMemberAnnotation(declaration);
- NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral();
- numberLiteral.setToken("88");
- annotation.setValue(numberLiteral);
- }
-
- public void testNewSingleMemberAnnotation21() throws Exception {
- this.createAnnotationAndMembers("NotBar", "int value();");
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=@annot.NotBar)");
- this.assertSourceDoesNotContain("@Bar", cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 5, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newSingleMemberAnnotation();
- this.assertSourceContains("@annot.Foo(nestedAnnotations={@annot.NotBar,null,null,null,null,@Bar(MISSING)})", cu);
- }
-
- public void testNewSingleMemberAnnotation22() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=@annot.Bar(77))");
- String expected = "@annot.Foo(nestedAnnotations=@Bar(88))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation22(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewSingleMemberAnnotation22(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- SingleMemberAnnotation annotation = daa.newSingleMemberAnnotation(declaration);
- NumberLiteral numberLiteral = annotation.getAST().newNumberLiteral();
- numberLiteral.setToken("88");
- annotation.setValue(numberLiteral);
- }
-
- public void testNewNormalAnnotation1() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain("@Foo", cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation1(declaration);
- }
- });
- this.assertSourceContains("@Foo(nestedAnnotations = @Bar(xxx = 88))", cu);
- }
-
- void editNewNormalAnnotation1(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newNormalAnnotation(declaration);
- this.addMemberValuePair(annotation, "xxx", 88);
- }
-
- public void testNewNormalAnnotation2() throws Exception {
- this.createAnnotationAndMembers("Bar", "int xxx();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain("@Foo", cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation2(declaration);
- }
- });
- this.assertSourceContains("@Foo(@Bar(xxx = 88))", cu);
- }
-
- void editNewNormalAnnotation2(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar");
- NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newNormalAnnotation(declaration);
- this.addMemberValuePair(annotation, "xxx", 88);
- }
-
- public void testNewNormalAnnotation3() throws Exception {
- this.createAnnotationAndMembers("Bar", "int xxx();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo");
- String expected = "@Foo(nestedAnnotations = @Bar(xxx = 88))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation3(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewNormalAnnotation3(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newNormalAnnotation(declaration);
- this.addMemberValuePair(annotation, "xxx", 88);
- }
-
- public void testNewNormalAnnotation4() throws Exception {
- this.createAnnotationAndMembers("Bar", "int xxx();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo");
- String expected = "@Foo(@Bar(xxx = 88))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation4(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewNormalAnnotation4(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar");
- NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newNormalAnnotation(declaration);
- this.addMemberValuePair(annotation, "xxx", 88);
- }
-
- public void testNewNormalAnnotation5() throws Exception {
- this.createAnnotationAndMembers("Bar", "int xxx();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations(); String value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")");
- String expected = "@Foo(value = \"something\", nestedAnnotations = @Bar(xxx = 88))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation5(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewNormalAnnotation5(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newNormalAnnotation(declaration);
- this.addMemberValuePair(annotation, "xxx", 88);
- }
-
- public void testNewNormalAnnotation6() throws Exception {
- this.createAnnotationAndMembers("Bar", "int xxx();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")");
- String expected = "@annot.Foo(@Bar(xxx = 88))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation6(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewNormalAnnotation6(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar");
- NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newNormalAnnotation(declaration);
- this.addMemberValuePair(annotation, "xxx", 88);
- }
-
- public void testNewNormalAnnotation7() throws Exception {
- this.createAnnotationAndMembers("Bar", "int xxx();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations(); String xxx();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(xxx=\"something\")");
- String expected = "@annot.Foo(xxx=\"something\", nestedAnnotations = @Bar(xxx = 88))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation7(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewNormalAnnotation7(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newNormalAnnotation(declaration);
- this.addMemberValuePair(annotation, "xxx", 88);
- }
-
- public void testNewNormalAnnotation8() throws Exception {
- this.createAnnotationAndMembers("Bar", "int xxx();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value(); String xxx();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(xxx=\"something\")");
- String expected = "@annot.Foo(xxx=\"something\", value = @Bar(xxx = 88))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation8(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewNormalAnnotation8(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar");
- NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newNormalAnnotation(declaration);
- this.addMemberValuePair(annotation, "xxx", 88);
- }
-
- public void testNewNormalAnnotation9() throws Exception {
- this.createAnnotationAndMembers("Bar", "int xxx();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations(); String xxx();");
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain("@Bar", cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 5, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newNormalAnnotation();
- this.assertSourceContains("@Foo(nestedAnnotations = { null, null, null, null, null, @Bar() })", cu);
- }
-
- public void testNewNormalAnnotation10() throws Exception {
- this.createAnnotationAndMembers("Bar", "int xxx();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] nestedAnnotations(); String value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(\"something\")");
- String expected1 = "@Foo(value = \"something\", nestedAnnotations = { null, null, null, null,";
- String expected2 = "null, @Bar() })";
- this.assertSourceDoesNotContain("@Bar", cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 5, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newNormalAnnotation();
- this.assertSourceContains(expected1, cu);
- this.assertSourceContains(expected2, cu);
- }
-
- public void testNewNormalAnnotation11() throws Exception {
- this.createAnnotationAndMembers("Bar", "int xxx();");
- this.createAnnotationAndMembers("Foo", "Object[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo({ \"one\", \"two\" })");
- String expected = "@annot.Foo({ @Bar(xxx = 88), \"two\" })";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation11(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewNormalAnnotation11(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar");
- NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newNormalAnnotation(declaration);
- this.addMemberValuePair(annotation, "xxx", 88);
- }
-
- public void testNewNormalAnnotation12() throws Exception {
- this.createAnnotationAndMembers("Bar", "int xxx();");
- this.createAnnotationAndMembers("Foo", "Object[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo({\"one\", \"two\"})");
- this.assertSourceDoesNotContain("@Bar", cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 5, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newNormalAnnotation();
- this.assertSourceContains("@Bar()})", cu); // split line
- }
-
- public void testNewNormalAnnotation13() throws Exception {
- this.createAnnotationAndMembers("Bar", "int xxx();");
- this.createAnnotationAndMembers("Foo", "Object[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(7)");
- String expected = "@annot.Foo(@Bar(xxx = 88))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation13(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewNormalAnnotation13(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar");
- NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newNormalAnnotation(declaration);
- this.addMemberValuePair(annotation, "xxx", 88);
- }
-
- public void testNewNormalAnnotation14() throws Exception {
- this.createAnnotationAndMembers("Bar", "int xxx();");
- this.createAnnotationAndMembers("Foo", "Object[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(7)");
- this.assertSourceDoesNotContain("@Bar", cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 5, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newNormalAnnotation();
- this.assertSourceContains("@annot.Foo({7,null,null,null,null,@Bar()})", cu);
- }
-
- public void testNewNormalAnnotation15() throws Exception {
- this.createAnnotationAndMembers("NotBar", "int xxx();");
- this.createAnnotationAndMembers("Bar", "int xxx();");
- this.createAnnotationAndMembers("Foo", "Object[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(@annot.NotBar)");
- String expected = "@annot.Foo(@Bar(xxx = 88))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation15(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewNormalAnnotation15(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar");
- NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newNormalAnnotation(declaration);
- this.addMemberValuePair(annotation, "xxx", 88);
- }
-
- public void testNewNormalAnnotation16() throws Exception {
- this.createAnnotationAndMembers("Bar", "int xxx();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(@annot.Bar(55))");
- String expected = "@annot.Foo({@annot.Bar(55),@Bar(xxx=88)})";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation16(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewNormalAnnotation16(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 1, "annot.Bar");
- NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newNormalAnnotation(declaration);
- this.addMemberValuePair(annotation, "xxx", 88);
- }
-
- public void testNewNormalAnnotation17() throws Exception {
- this.createAnnotationAndMembers("Bar", "int xxx();");
- this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations = { \"something\" })");
- String expected = "@annot.Foo(nestedAnnotations = { @Bar(xxx = 88) })";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation17(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewNormalAnnotation17(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newNormalAnnotation(declaration);
- this.addMemberValuePair(annotation, "xxx", 88);
- }
-
- public void testNewNormalAnnotation18() throws Exception {
- this.createAnnotationAndMembers("Bar", "int xxx();");
- this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations={\"something\"})");
- this.assertSourceDoesNotContain("@Bar", cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 5, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newNormalAnnotation();
- this.assertSourceContains("@Bar()})", cu); // split line
- }
-
- public void testNewNormalAnnotation19() throws Exception {
- this.createAnnotationAndMembers("Bar", "int xxx();");
- this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations = \"something\")");
- String expected = "@annot.Foo(nestedAnnotations = @Bar(xxx = 88))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation19(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewNormalAnnotation19(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newNormalAnnotation(declaration);
- this.addMemberValuePair(annotation, "xxx", 88);
- }
-
- public void testNewNormalAnnotation20() throws Exception {
- this.createAnnotationAndMembers("NotBar", "int xxx();");
- this.createAnnotationAndMembers("Bar", "int xxx();");
- this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations = @annot.NotBar)");
- String expected = "@annot.Foo(nestedAnnotations = @Bar(xxx = 88))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation20(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewNormalAnnotation20(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newNormalAnnotation(declaration);
- this.addMemberValuePair(annotation, "xxx", 88);
- }
-
- public void testNewNormalAnnotation21() throws Exception {
- this.createAnnotationAndMembers("NotBar", "int xxx();");
- this.createAnnotationAndMembers("Bar", "int xxx();");
- this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations=@annot.NotBar)");
- this.assertSourceDoesNotContain("@Bar", cu);
-
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 5, "annot.Bar");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newNormalAnnotation();
- this.assertSourceContains("@annot.Foo(nestedAnnotations={@annot.NotBar,null,null,null,null,@Bar()})", cu);
- }
-
- public void testNewNormalAnnotation22() throws Exception {
- this.createAnnotationAndMembers("Bar", "int xxx();");
- this.createAnnotationAndMembers("Foo", "Object[] nestedAnnotations();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(nestedAnnotations = @annot.Bar(77))");
- String expected = "@annot.Foo(nestedAnnotations = @Bar(xxx = 88))";
- this.assertSourceDoesNotContain(expected, cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- NestedIndexedDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation22(declaration);
- }
- });
- this.assertSourceContains(expected, cu);
- }
-
- void editNewNormalAnnotation22(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "nestedAnnotations", 0, "annot.Bar");
- NormalAnnotation annotation = daa.newNormalAnnotation(declaration);
- this.addMemberValuePair(annotation, "xxx", 88);
- }
-
- public void testMoveAnnotation1() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(@annot.Bar(00))");
- String expected = "@annot.Foo({null,@annot.Bar(00)})";
- this.assertSourceDoesNotContain(expected, cu);
-
- IndexedDeclarationAnnotationAdapter idaa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar");
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), idaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- iaa.moveAnnotation(1);
- this.assertSourceContains(expected, cu);
- }
-
- public void testMoveAnnotation2() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo({null, @annot.Bar(11)})");
- String expected = "@annot.Foo(@annot.Bar(11))";
- this.assertSourceDoesNotContain(expected, cu);
-
- IndexedDeclarationAnnotationAdapter idaa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 1, "annot.Bar");
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), idaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- iaa.moveAnnotation(0);
- this.assertSourceContains(expected, cu);
- }
-
- public void testMoveAnnotation3() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo({@annot.Bar(00), @annot.Bar(11), @annot.Bar(22), @annot.Bar(33)})");
- String expected = "@annot.Foo({@annot.Bar(33), @annot.Bar(11), @annot.Bar(22)})";
- this.assertSourceDoesNotContain(expected, cu);
-
- IndexedDeclarationAnnotationAdapter idaa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 3, "annot.Bar");
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), idaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- iaa.moveAnnotation(0);
- this.assertSourceContains(expected, cu);
- }
-
- public void testMoveAnnotation4() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo({@annot.Bar(00), @annot.Bar(11), @annot.Bar(22), @annot.Bar(33), @annot.Bar(44)})");
- String expected = "@annot.Foo({@annot.Bar(33), @annot.Bar(11), @annot.Bar(22), null, @annot.Bar(44)})";
- this.assertSourceDoesNotContain(expected, cu);
-
- IndexedDeclarationAnnotationAdapter idaa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 3, "annot.Bar");
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), idaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- iaa.moveAnnotation(0);
- this.assertSourceContains(expected, cu);
- }
-
- public void testMoveAnnotation5() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo({@annot.Bar(00), @annot.Bar(11), @annot.Bar(22)})");
- String expected = "@annot.Foo({@annot.Bar(00), @annot.Bar(11), null, @annot.Bar(22)})";
- this.assertSourceDoesNotContain(expected, cu);
-
- IndexedDeclarationAnnotationAdapter idaa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 2, "annot.Bar");
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), idaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- iaa.moveAnnotation(3);
- this.assertSourceContains(expected, cu);
- }
-
- public void testMoveAnnotation6() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo({@annot.Bar(00), @annot.Bar(11), @annot.Bar(22)})");
- String expected = "@annot.Foo({null, @annot.Bar(11), @annot.Bar(22), @annot.Bar(00)})";
- this.assertSourceDoesNotContain(expected, cu);
-
- IndexedDeclarationAnnotationAdapter idaa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar");
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), idaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- iaa.moveAnnotation(3);
- this.assertSourceContains(expected, cu);
- }
-
- public void testMoveAnnotation7() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo({@annot.Bar(00), @annot.Bar(11), @annot.Bar(22)})");
- String expected = "@annot.Foo({null, @annot.Bar(11), @annot.Bar(22)})";
- this.assertSourceDoesNotContain(expected, cu);
-
- IndexedDeclarationAnnotationAdapter idaa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 3, "annot.Bar");
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), idaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- iaa.moveAnnotation(0);
- this.assertSourceContains(expected, cu);
- }
-
- public void testMoveAnnotation8() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo({@annot.Bar(00), @annot.Bar(11), @annot.Bar(22), null, @annot.Bar(44)})");
- String expected = "@annot.Foo({null, @annot.Bar(11), @annot.Bar(22), null, @annot.Bar(44)})";
- this.assertSourceDoesNotContain(expected, cu);
-
- IndexedDeclarationAnnotationAdapter idaa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 3, "annot.Bar");
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), idaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- iaa.moveAnnotation(0);
- this.assertSourceContains(expected, cu);
- }
-
- public void testMoveAnnotation9() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- String expected = "@annot.Foo({null, @annot.Bar(11), @annot.Bar(22)})";
- ICompilationUnit cu = this.createTestType(expected); // the source should be unchanged
-
- IndexedDeclarationAnnotationAdapter idaa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 0, "annot.Bar");
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), idaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- iaa.moveAnnotation(3);
- this.assertSourceContains(expected, cu);
- }
-
- public void testMoveAnnotation10() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo({@annot.Bar(00), @annot.Bar(11)})");
- String expected = "@annot.Foo(@annot.Bar(00))";
-
- IndexedDeclarationAnnotationAdapter idaa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 2, "annot.Bar");
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), idaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
- iaa.moveAnnotation(1);
- this.assertSourceContains(expected, cu);
- }
-
- public void testMoveAnnotation11() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo(@annot.Bar(00))");
-
- IndexedDeclarationAnnotationAdapter idaa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 1, "annot.Bar");
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), idaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- iaa.moveAnnotation(0);
- this.assertSourceDoesNotContain("Bar", cu);
- }
-
- public void testMoveAnnotation12() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo({@annot.Bar(00), null, @annot.Bar(22)})");
- String expected = "@annot.Foo(@annot.Bar(22))";
-
- IndexedDeclarationAnnotationAdapter idaa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 2, "annot.Bar");
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), idaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- iaa.moveAnnotation(0);
- this.assertSourceContains(expected, cu);
- }
-
- public void testMoveAnnotation13() throws Exception {
- this.createAnnotationAndMembers("Bar", "int value();");
- this.createAnnotationAndMembers("Foo", "annot.Bar[] value();");
- ICompilationUnit cu = this.createTestType("@annot.Foo({@annot.Bar(00), @annot.Bar(11), null, @annot.Bar(33)})");
- String expected = "@annot.Foo({@annot.Bar(33), @annot.Bar(11)})";
-
- IndexedDeclarationAnnotationAdapter idaa = new NestedIndexedDeclarationAnnotationAdapter(
- new SimpleDeclarationAnnotationAdapter("annot.Foo"), "value", 3, "annot.Bar");
- IndexedAnnotationAdapter iaa = new ElementIndexedAnnotationAdapter(this.idField(cu), idaa);
- Annotation annotation = iaa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- iaa.moveAnnotation(0);
- this.assertSourceContains(expected, cu);
- }
-
-}
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/SimpleDeclarationAnnotationAdapterTests.java b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/SimpleDeclarationAnnotationAdapterTests.java
deleted file mode 100644
index 8c86b93406..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/SimpleDeclarationAnnotationAdapterTests.java
+++ /dev/null
@@ -1,274 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2010 Oracle. 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:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.core.tests.internal.utility.jdt;
-
-import org.eclipse.jdt.core.ICompilationUnit;
-import org.eclipse.jdt.core.dom.ASTNode;
-import org.eclipse.jdt.core.dom.Annotation;
-import org.eclipse.jdt.core.dom.Expression;
-import org.eclipse.jdt.core.dom.MemberValuePair;
-import org.eclipse.jdt.core.dom.NormalAnnotation;
-import org.eclipse.jdt.core.dom.NumberLiteral;
-import org.eclipse.jdt.core.dom.SingleMemberAnnotation;
-import org.eclipse.jdt.core.dom.StringLiteral;
-import org.eclipse.jpt.common.core.internal.utility.jdt.ElementAnnotationAdapter;
-import org.eclipse.jpt.common.core.internal.utility.jdt.SimpleDeclarationAnnotationAdapter;
-import org.eclipse.jpt.common.core.utility.jdt.AnnotationAdapter;
-import org.eclipse.jpt.common.core.utility.jdt.DeclarationAnnotationAdapter;
-import org.eclipse.jpt.common.core.utility.jdt.Member;
-import org.eclipse.jpt.common.core.utility.jdt.ModifiedDeclaration;
-
-@SuppressWarnings("nls")
-public class SimpleDeclarationAnnotationAdapterTests extends AnnotationTestCase {
-
- public SimpleDeclarationAnnotationAdapterTests(String name) {
- super(name);
- }
-
- private void createAnnotation(String annotationName) throws Exception {
- this.createAnnotation("annot", annotationName);
- }
-
- private void createAnnotation(String packageName, String annotationName) throws Exception {
- this.javaProject.createCompilationUnit(packageName, annotationName + ".java", "public @interface " + annotationName + " {}");
- }
-
- public void testAnnotation1() throws Exception {
- this.createAnnotation("Foo");
- ICompilationUnit cu = this.createTestType("@annot.Foo");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
- assertEquals("annot.Foo", annotation.getTypeName().getFullyQualifiedName());
- assertTrue(annotation.isMarkerAnnotation());
- }
-
- public void testAnnotation2() throws Exception {
- this.createAnnotation("Foo");
- ICompilationUnit cu = this.createTestType("@annot.Foo(1) @annot.Foo(2)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
- assertEquals("annot.Foo", annotation.getTypeName().getFullyQualifiedName());
- assertTrue(annotation.isSingleMemberAnnotation());
- Expression value = ((SingleMemberAnnotation) annotation).getValue();
- assertEquals(ASTNode.NUMBER_LITERAL, value.getNodeType());
- assertEquals("1", ((NumberLiteral) value).getToken());
- }
-
- public void testAnnotation3() throws Exception {
- this.createAnnotation("Foo");
- ICompilationUnit cu = this.createTestType("annot.Foo", "@Foo");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
- assertEquals("Foo", annotation.getTypeName().getFullyQualifiedName());
- assertTrue(annotation.isMarkerAnnotation());
- }
-
- public void testAnnotationNull1() throws Exception {
- this.createAnnotation("Foo");
- ICompilationUnit cu = this.createTestType();
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
- }
-
- public void testAnnotationNull2() throws Exception {
- this.createAnnotation("Foo");
- this.createAnnotation("Fop");
- ICompilationUnit cu = this.createTestType("@annot.Fop");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
- this.assertSourceContains("@annot.Fop", cu);
- }
-
- public void testAnnotationNull3() throws Exception {
- this.createAnnotation("Foo");
- ICompilationUnit cu = this.createTestType("@annot.Foo");
- // un-qualified name
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("Foo");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
- this.assertSourceContains("@annot.Foo", cu);
- }
-
- public void testRemoveAnnotation1() throws Exception {
- this.createAnnotation("Foo");
- ICompilationUnit cu = this.createTestType("@annot.Foo");
- this.assertSourceContains("@annot.Foo", cu);
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa.removeAnnotation();
- this.assertSourceDoesNotContain("@annot.Foo", cu);
- }
-
- public void testRemoveAnnotation2() throws Exception {
- this.createAnnotation("Foo");
- ICompilationUnit cu = this.createTestType("@annot.Foo(1) @annot.Foo(2)");
- this.assertSourceContains("@annot.Foo(1) @annot.Foo(2)", cu);
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa.removeAnnotation();
- this.assertSourceDoesNotContain("@annot.Foo(1)", cu);
- this.assertSourceContains("@annot.Foo(2)", cu);
- }
-
- public void testNewMarkerAnnotation1() throws Exception {
- this.createAnnotation("Foo");
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain("import annot.Foo;", cu);
- this.assertSourceDoesNotContain("@Foo", cu);
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains("import annot.Foo;", cu);
- this.assertSourceContains("@Foo", cu);
- }
-
- public void testNewMarkerAnnotation2() throws Exception {
- this.createAnnotation("Foo");
- ICompilationUnit cu = this.createTestType("@annot.Foo(88)");
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- AnnotationAdapter aa = new ElementAnnotationAdapter(this.idField(cu), daa);
- Annotation annotation = aa.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation);
-
- aa.newMarkerAnnotation();
- this.assertSourceContains("import annot.Foo;", cu);
- this.assertSourceContains("@Foo", cu);
- this.assertSourceDoesNotContain("@annot.Foo(88)", cu);
- }
-
- public void testNewSingleMemberAnnotation() throws Exception {
- this.createAnnotation("Foo");
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain("@Foo", cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- SimpleDeclarationAnnotationAdapterTests.this.editNewSingleMemberAnnotation(declaration);
- }
- });
- this.assertSourceContains("import annot.Foo;", cu);
- this.assertSourceContains("@Foo(\"test string literal\")", cu);
- }
-
- void editNewSingleMemberAnnotation(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- SingleMemberAnnotation annotation = (SingleMemberAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newSingleMemberAnnotation(declaration);
- StringLiteral stringLiteral = annotation.getAST().newStringLiteral();
- stringLiteral.setLiteralValue("test string literal");
- annotation.setValue(stringLiteral);
- }
-
- public void testNewNormalAnnotation() throws Exception {
- this.createAnnotation("Foo");
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain("@Foo", cu);
- this.idField(cu).edit(new Member.Editor() {
- public void edit(ModifiedDeclaration declaration) {
- SimpleDeclarationAnnotationAdapterTests.this.editNewNormalAnnotation(declaration);
- }
- });
- this.assertSourceContains("import annot.Foo;", cu);
- this.assertSourceContains("@Foo(bar = \"test string literal\")", cu);
- }
-
- void editNewNormalAnnotation(ModifiedDeclaration declaration) {
- DeclarationAnnotationAdapter daa = new SimpleDeclarationAnnotationAdapter("annot.Foo");
- NormalAnnotation annotation = (NormalAnnotation) daa.getAnnotation(declaration);
- assertNull(annotation);
- annotation = daa.newNormalAnnotation(declaration);
- MemberValuePair mvp = this.newMemberValuePair(annotation.getAST(), "bar", "test string literal");
- this.values(annotation).add(mvp);
- }
-
- public void testImportCollision1() throws Exception {
- this.createAnnotation("annot1", "Foo");
- this.createAnnotation("annot2", "Foo");
- ICompilationUnit cu = this.createTestType();
- this.assertSourceDoesNotContain("@Foo", cu);
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot1.Foo");
- DeclarationAnnotationAdapter daa2 = new SimpleDeclarationAnnotationAdapter("annot2.Foo");
-
- AnnotationAdapter aa1 = new ElementAnnotationAdapter(this.idField(cu), daa1);
- Annotation annotation1 = aa1.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation1);
-
- AnnotationAdapter aa2 = new ElementAnnotationAdapter(this.idField(cu), daa2);
- Annotation annotation2 = aa2.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation2);
-
- aa1.newMarkerAnnotation();
- this.assertSourceContains("import annot1.Foo;", cu);
- this.assertSourceContains("@Foo", cu);
-
- aa2.newMarkerAnnotation();
- this.assertSourceDoesNotContain("import annot2.Foo;", cu);
- this.assertSourceContains("@annot2.Foo", cu);
- }
-
- public void testImportCollision2() throws Exception {
- this.createAnnotation("annot1", "Foo");
- this.createAnnotation("annot2", "Foo");
- ICompilationUnit cu = this.createTestType("annot1.*", "@Foo");
- this.assertSourceContains("import annot1.*;", cu);
- this.assertSourceContains("@Foo", cu);
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot1.Foo");
- DeclarationAnnotationAdapter daa2 = new SimpleDeclarationAnnotationAdapter("annot2.Foo");
-
- AnnotationAdapter aa1 = new ElementAnnotationAdapter(this.idField(cu), daa1);
- Annotation annotation1 = aa1.getAnnotation(this.buildASTRoot(cu));
- assertNotNull(annotation1);
-
- AnnotationAdapter aa2 = new ElementAnnotationAdapter(this.idField(cu), daa2);
- Annotation annotation2 = aa2.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation2);
-
- aa2.newMarkerAnnotation();
- this.assertSourceDoesNotContain("import annot2.Foo;", cu);
- this.assertSourceContains("@annot2.Foo", cu);
- }
-
- public void testImportWildCard() throws Exception {
- this.createAnnotation("Foo");
- ICompilationUnit cu = this.createTestType("annot.*", "");
- this.assertSourceContains("import annot.*;", cu);
- this.assertSourceDoesNotContain("@Foo", cu);
- DeclarationAnnotationAdapter daa1 = new SimpleDeclarationAnnotationAdapter("annot.Foo");
-
- AnnotationAdapter aa1 = new ElementAnnotationAdapter(this.idField(cu), daa1);
- Annotation annotation1 = aa1.getAnnotation(this.buildASTRoot(cu));
- assertNull(annotation1);
-
- aa1.newMarkerAnnotation();
- this.assertSourceDoesNotContain("import annot.Foo;", cu);
- this.assertSourceContains("@Foo", cu);
- }
-
-}
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/TypeTests.java b/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/TypeTests.java
deleted file mode 100644
index ebd80a401f..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/src/org/eclipse/jpt/common/core/tests/internal/utility/jdt/TypeTests.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2006, 2008 Oracle. 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:
- * Oracle - initial API and implementation
- ******************************************************************************/
-package org.eclipse.jpt.common.core.tests.internal.utility.jdt;
-
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jdt.core.ICompilationUnit;
-
-@SuppressWarnings("nls")
-public class TypeTests extends AnnotationTestCase {
-
- public TypeTests(String name) {
- super(name);
- }
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- }
-
- protected ICompilationUnit createCompilationUnit(String source) throws CoreException {
- return this.javaProject.createCompilationUnit(PACKAGE_NAME, FILE_NAME, source);
- }
-
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
- }
-
- public void test1() throws Exception {
- ICompilationUnit jdtCompilationUnit = this.createCompilationUnit(this.buildTest1Source());
- assertNotNull(jdtCompilationUnit);
- }
-
- private String buildTest1Source() {
- StringBuilder sb = new StringBuilder();
- sb.append("public class ").append(TYPE_NAME).append(" {").append(CR);
- sb.append(" private int id;").append(CR);
- sb.append(" public int getId() {").append(CR);
- sb.append(" return this.id;").append(CR);
- sb.append(" }").append(CR);
- sb.append("}").append(CR);
- return sb.toString();
- }
-
-}
diff --git a/common/tests/org.eclipse.jpt.common.core.tests/test.xml b/common/tests/org.eclipse.jpt.common.core.tests/test.xml
deleted file mode 100644
index 0034685b7a..0000000000
--- a/common/tests/org.eclipse.jpt.common.core.tests/test.xml
+++ /dev/null
@@ -1,45 +0,0 @@
-<?xml version="1.0"?> <!--
- Copyright (c) 2007, 2010 Oracle. 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: Oracle - initial API and implementation -->
-
-<project name="testsuite" default="run" basedir=".">
- <!-- The property ${eclipse-home} should be passed into this script -->
- <!-- Set a meaningful default value for when it is not. -->
- <echo message="basedir ${basedir}" />
- <echo message="eclipse place ${eclipse-home}" />
- <!-- sets the properties plugin-name -->
- <property name="plugin-name" value="org.eclipse.jpt.common.core.tests"/> <echo level="debug" message="testRoot: ${testRoot}" />
- <fail message="testRoot must be set" unless="testRoot" />
-
- <!-- This target holds all initialization code that needs to be done for -->
- <!-- all tests that are to be run. Initialization for individual tests -->
- <!-- should be done within the body of the suite target. -->
- <target name="init">
- <tstamp/>
- <delete>
- <fileset dir="${eclipse-home}" includes="org*.xml"/>
- </delete>
- </target>
-
- <!-- This target defines the tests that need to be run. -->
- <target name="suite1">
- <property file="${testRoot}/testServer.properties"/>
- <property name="jpt-folder" value="${eclipse-home}/jpt_folder"/>
- <delete dir="${jpt-folder}" quiet="true"/>
-
- <ant target="core-test" antfile="${library-file}" dir="${eclipse-home}">
- <property name="data-dir" value="${jpt-folder}"/>
- <property name="plugin-name" value="${plugin-name}"/>
- <property name="classname" value="org.eclipse.jpt.common.core.tests.internal.JptCommonCoreTests" />
- <property name="plugin-path" value="${eclipse-home}/plugins/${plugin-name}"/>
- </ant> </target>
- <!-- This target holds code to cleanup the testing environment after -->
- <!-- after all of the tests have been run. You can use this target to -->
- <!-- delete temporary files that have been created. -->
- <target name="cleanup">
- </target>
-
- <!-- This target runs the test suite. Any actions that need to happen -->
- <!-- after all the tests have been run should go here. -->
- <target name="run" depends="init, suite1,cleanup">
- </target>
-</project> \ No newline at end of file

Back to the top