Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2010-10-14 15:34:01 +0000
committerkmoore2010-10-14 15:34:01 +0000
commit51d3bd11b31b795e6cddecdf3dbc1658cdfb59b8 (patch)
tree63b37f78d4a0f6cb0d33a653bbf758195737ff87
parentfdb5b12e97c55c612bb5181f3728287d1ab6443b (diff)
downloadwebtools.dali-51d3bd11b31b795e6cddecdf3dbc1658cdfb59b8.tar.gz
webtools.dali-51d3bd11b31b795e6cddecdf3dbc1658cdfb59b8.tar.xz
webtools.dali-51d3bd11b31b795e6cddecdf3dbc1658cdfb59b8.zip
265087 - package-level annotation support
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/plugin.properties1
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/plugin.xml10
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaAnnotationDefinitionProvider.java7
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaAnnotationProvider.java54
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaProject.java13
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JptCorePlugin.java12
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaAnnotationDefintionProvider.java29
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaProject.java41
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaAnnotationProvider.java42
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JavaPackageInfoResourceModelProvider.java57
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JavaResourceModelProvider.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceCompilationUnit.java129
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePackage.java118
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePackageInfoCompilationUnit.java121
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceTypeCompilationUnit.java167
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTPackage.java65
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePackage.java35
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePackageInfoCompilationUnit.java30
-rw-r--r--jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/utility/jdt/Package.java40
-rw-r--r--jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourceModelTestCase.java4
20 files changed, 836 insertions, 143 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.core/plugin.properties b/jpa/plugins/org.eclipse.jpt.core/plugin.properties
index 0ed9645f29..01679481ac 100644
--- a/jpa/plugins/org.eclipse.jpt.core/plugin.properties
+++ b/jpa/plugins/org.eclipse.jpt.core/plugin.properties
@@ -35,6 +35,7 @@ PERSISTENCE_XML_CONTENT = JPA persistence.xml files
MAPPING_FILE_CONTENT = Base content for JPA XML mapping files
ORM_XML_CONTENT = JPA orm.xml mapping files
JAR_CONTENT = JAR Content
+JAVA_PACKAGE_INFO_CONTENT = package-info.java
GENERIC_PLATFORM_GROUP_LABEL=Generic
GENERIC_1_0_PLATFORM_LABEL=Generic 1.0
diff --git a/jpa/plugins/org.eclipse.jpt.core/plugin.xml b/jpa/plugins/org.eclipse.jpt.core/plugin.xml
index dc19038038..7c93fa52bb 100644
--- a/jpa/plugins/org.eclipse.jpt.core/plugin.xml
+++ b/jpa/plugins/org.eclipse.jpt.core/plugin.xml
@@ -89,6 +89,14 @@
<parameter name="signature" value="50 4B 03 04"/>
</describer>
</content-type>
+ <content-type
+ base-type="org.eclipse.jdt.core.javaSource"
+ file-extensions=".java"
+ file-names="package-info.java"
+ id="org.eclipse.jpt.core.content.javaPackageInfo"
+ name="%JAVA_PACKAGE_INFO_CONTENT"
+ priority="normal">
+ </content-type>
</extension>
@@ -628,7 +636,7 @@
</include>
<include>
<rules>
- <contentType id="org.eclipse.jdt.core.javaSource"/>
+ <contentType id="org.eclipse.jdt.core.javaSource" exactMatch="false"/>
<contentType id="org.eclipse.jpt.core.content.jar"/>
<contentType id="org.eclipse.jpt.core.content.baseJpaContent" exactMatch="false"/>
</rules>
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaAnnotationDefinitionProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaAnnotationDefinitionProvider.java
index f48c8eeba3..73d823fba5 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaAnnotationDefinitionProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaAnnotationDefinitionProvider.java
@@ -22,7 +22,7 @@ import org.eclipse.jpt.core.resource.java.AnnotationDefinition;
* pioneering adopters on the understanding that any code that uses this API
* will almost certainly be broken (repeatedly) as the API evolves.
*
- * @version 2.3
+ * @version 3.0
* @since 2.2
*/
public interface JpaAnnotationDefinitionProvider
@@ -43,4 +43,9 @@ public interface JpaAnnotationDefinitionProvider
* Return all annotation definitions which can appear on an attribute
*/
Iterator<AnnotationDefinition> attributeAnnotationDefinitions();
+
+ /**
+ * Return all annotation definitions which can appear on a package.
+ */
+ Iterator<AnnotationDefinition> packageAnnotationDefinitions();
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaAnnotationProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaAnnotationProvider.java
index a26aaf80d4..83f98f13a2 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaAnnotationProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaAnnotationProvider.java
@@ -13,8 +13,10 @@ import java.util.Iterator;
import org.eclipse.jdt.core.IAnnotation;
import org.eclipse.jpt.core.resource.java.Annotation;
import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute;
+import org.eclipse.jpt.core.resource.java.JavaResourcePackage;
import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
import org.eclipse.jpt.core.utility.jdt.Attribute;
+import org.eclipse.jpt.core.utility.jdt.Package;
import org.eclipse.jpt.core.utility.jdt.Type;
/**
@@ -27,7 +29,7 @@ import org.eclipse.jpt.core.utility.jdt.Type;
* JpaAnnotationDefinitionProvider to extend the list of supported annotation definitions.
*
* @see JpaAnnotationDefinitionProvider
- * @version 2.3
+ * @version 3.0
* @since 2.0?
*
* Provisional API: This interface is part of an interim API that is still
@@ -44,14 +46,14 @@ public interface JpaAnnotationProvider
* Return the names of the annotations that can appear on a type.
*/
Iterator<String> typeAnnotationNames();
-
+
/**
* Return the names of the annotations that can appear on a type and are used to
* determine whether and how the type is persisted (how it is "mapped").
* This should be a subset of {@link #typeAnnotationNames()}.
*/
Iterator<String> typeMappingAnnotationNames();
-
+
/**
* Build a type annotation with the specified name.
* Throw an IllegalArgumentException if the specified name is unsupported.
@@ -59,7 +61,7 @@ public interface JpaAnnotationProvider
*/
Annotation buildTypeAnnotation(
JavaResourcePersistentType parent, Type type, String annotationName);
-
+
/**
* Build a type annotation for the specified JDT annotation.
* Throw an IllegalArgumentException if the specified annotation is unsupported.
@@ -67,7 +69,7 @@ public interface JpaAnnotationProvider
*/
Annotation buildTypeAnnotation(
JavaResourcePersistentType parent, IAnnotation jdtAnnotation);
-
+
/**
* Build a null type annotation with the specified name.
* Throw an IllegalArgumentException if the specified annotation is unsupported.
@@ -75,15 +77,15 @@ public interface JpaAnnotationProvider
*/
Annotation buildNullTypeAnnotation(
JavaResourcePersistentType parent, String annotationName);
-
-
+
+
// ********** attribute annotations **********
/**
* Return the names of the annotations that can appear on an attribute.
*/
Iterator<String> attributeAnnotationNames();
-
+
/**
* Build an attribute annotation with the specified name.
* Throw an IllegalArgumentException if the specified name is unsupported.
@@ -91,7 +93,7 @@ public interface JpaAnnotationProvider
*/
Annotation buildAttributeAnnotation(
JavaResourcePersistentAttribute parent, Attribute attribute, String annotationName);
-
+
/**
* Build an attribute annotation for the specified JDT annotation.
* Throw an IllegalArgumentException if the specified annotation is unsupported.
@@ -99,7 +101,7 @@ public interface JpaAnnotationProvider
*/
Annotation buildAttributeAnnotation(
JavaResourcePersistentAttribute parent, IAnnotation jdtAnnotation);
-
+
/**
* Build a null attribute annotation with the specified name.
* Throw an IllegalArgumentException if the specified annotation is unsupported.
@@ -107,4 +109,36 @@ public interface JpaAnnotationProvider
*/
Annotation buildNullAttributeAnnotation(
JavaResourcePersistentAttribute parent, String annotationName);
+
+
+ // ********** package annotations **********
+
+ /**
+ * Return the names of the annotations that can appear on a package.
+ */
+ Iterator<String> packageAnnotationNames();
+
+ /**
+ * Build an package annotation with the specified name.
+ * Throw an IllegalArgumentException if the specified name is unsupported.
+ * @see #packageAnnotationNames()
+ */
+ Annotation buildPackageAnnotation(
+ JavaResourcePackage parent, Package pack, String annotationName);
+
+ /**
+ * Build a package annotation for the specified JDT annotation.
+ * Throw an IllegalArgumentException if the specified name is unsupported.
+ * @see #packageAnnotationNames()
+ */
+ Annotation buildPackageAnnotation(
+ JavaResourcePackage parent, IAnnotation jdtAnnotation);
+
+ /**
+ * Build a null package annotation with the specified name.
+ * Throw an IllegalArgumentException if the specified annotation is unsupported.
+ * @see #packageAnnotationNames()
+ */
+ Annotation buildNullPackageAnnotation(
+ JavaResourcePackage parent, String annotationName);
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaProject.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaProject.java
index b5f26a8034..d5fb9458e9 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaProject.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JpaProject.java
@@ -21,6 +21,7 @@ import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jpt.core.context.JpaRootContextNode;
import org.eclipse.jpt.core.resource.java.JavaResourceCompilationUnit;
import org.eclipse.jpt.core.resource.java.JavaResourcePackageFragmentRoot;
+import org.eclipse.jpt.core.resource.java.JavaResourcePackage;
import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
import org.eclipse.jpt.core.resource.java.JavaResourcePersistentTypeCache;
import org.eclipse.jpt.core.resource.xml.JpaXmlResource;
@@ -194,6 +195,18 @@ public interface JpaProject
JavaResourcePersistentType getJavaResourcePersistentType(String typeName);
/**
+ * Return the Java resource package for the specified package.
+ * Return null if invalid or absent.
+ */
+ JavaResourcePackage getJavaResourcePackage(String packageName);
+
+ /**
+ * Return the Java resource packages for the project.
+ * Return null if invalid or absent.
+ */
+ Iterable<JavaResourcePackage> getJavaResourcePackages();
+
+ /**
* Return the Java resource package fragement root for the specified JAR.
* Return null if absent.
*/
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JptCorePlugin.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JptCorePlugin.java
index 5bce843d99..3db6ddb406 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JptCorePlugin.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/JptCorePlugin.java
@@ -163,7 +163,17 @@ public class JptCorePlugin extends Plugin {
* The resource type for Java source code files
*/
public static final JpaResourceType JAVA_SOURCE_RESOURCE_TYPE = new JpaResourceType(JAVA_SOURCE_CONTENT_TYPE);
-
+
+ /**
+ * The content type for package-info Java code files.
+ */
+ public static final IContentType JAVA_SOURCE_PACKAGE_INFO_CONTENT_TYPE = getJpaContentType("javaPackageInfo"); //$NON-NLS-1$
+
+ /**
+ * The resource type for package-info Java code files
+ */
+ public static final JpaResourceType JAVA_SOURCE_PACKAGE_INFO_RESOURCE_TYPE = new JpaResourceType(JAVA_SOURCE_PACKAGE_INFO_CONTENT_TYPE);
+
/**
* The content type for <code>persistence.xml</code> files.
*/
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaAnnotationDefintionProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaAnnotationDefintionProvider.java
index 90bc29d85a..40500ad355 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaAnnotationDefintionProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaAnnotationDefintionProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 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.
@@ -12,6 +12,7 @@ package org.eclipse.jpt.core.internal;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.ListIterator;
import org.eclipse.jpt.core.JpaAnnotationDefinitionProvider;
import org.eclipse.jpt.core.resource.java.AnnotationDefinition;
import org.eclipse.jpt.utility.internal.iterators.ArrayIterator;
@@ -26,6 +27,8 @@ public abstract class AbstractJpaAnnotationDefintionProvider
private AnnotationDefinition[] attributeAnnotationDefinitions;
+ private AnnotationDefinition[] packageAnnotationDefinitions;
+
protected AbstractJpaAnnotationDefintionProvider() {
super();
@@ -98,4 +101,28 @@ public abstract class AbstractJpaAnnotationDefintionProvider
protected void addAttributeAnnotationDefinitionsTo(@SuppressWarnings("unused") List<AnnotationDefinition> definitions) {
// no op
}
+
+
+ // ********** package annotation definitions **********
+
+ public synchronized ListIterator<AnnotationDefinition> packageAnnotationDefinitions() {
+ if (this.packageAnnotationDefinitions == null) {
+ this.packageAnnotationDefinitions = this.buildPackageAnnotationDefinitions();
+ }
+ return new ArrayListIterator<AnnotationDefinition>(this.packageAnnotationDefinitions);
+ }
+
+ protected AnnotationDefinition[] buildPackageAnnotationDefinitions() {
+ ArrayList<AnnotationDefinition> definitions = new ArrayList<AnnotationDefinition>();
+ this.addPackageAnnotationDefinitionsTo(definitions);
+ return definitions.toArray(new AnnotationDefinition[definitions.size()]);
+ }
+
+ /**
+ * Subclasses must override this to specify package annotation
+ * definitions. No package annotation definitions by default.
+ */
+ protected void addPackageAnnotationDefinitionsTo(@SuppressWarnings("unused") List<AnnotationDefinition> definitions) {
+ // no op
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaProject.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaProject.java
index ba2d5831eb..fb62c6f411 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaProject.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/AbstractJpaProject.java
@@ -48,7 +48,7 @@ import org.eclipse.jpt.core.JpaResourceModelListener;
import org.eclipse.jpt.core.JptCorePlugin;
import org.eclipse.jpt.core.context.JpaRootContextNode;
import org.eclipse.jpt.core.internal.resource.java.binary.BinaryPersistentTypeCache;
-import org.eclipse.jpt.core.internal.resource.java.source.SourceCompilationUnit;
+import org.eclipse.jpt.core.internal.resource.java.source.SourceTypeCompilationUnit;
import org.eclipse.jpt.core.internal.utility.PlatformTools;
import org.eclipse.jpt.core.internal.validation.DefaultJpaValidationMessages;
import org.eclipse.jpt.core.internal.validation.JpaValidationMessages;
@@ -59,6 +59,8 @@ import org.eclipse.jpt.core.resource.ResourceLocator;
import org.eclipse.jpt.core.resource.java.JavaResourceCompilationUnit;
import org.eclipse.jpt.core.resource.java.JavaResourceNode;
import org.eclipse.jpt.core.resource.java.JavaResourcePackageFragmentRoot;
+import org.eclipse.jpt.core.resource.java.JavaResourcePackage;
+import org.eclipse.jpt.core.resource.java.JavaResourcePackageInfoCompilationUnit;
import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
import org.eclipse.jpt.core.resource.java.JavaResourcePersistentTypeCache;
import org.eclipse.jpt.core.resource.xml.JpaXmlResource;
@@ -680,7 +682,7 @@ public abstract class AbstractJpaProject
}
protected JavaResourceCompilationUnit buildJavaResourceCompilationUnit(ICompilationUnit jdtCompilationUnit) {
- return new SourceCompilationUnit(
+ return new SourceTypeCompilationUnit(
jdtCompilationUnit,
this.jpaPlatform.getAnnotationProvider(),
this.jpaPlatform.getAnnotationEditFormatter(),
@@ -919,6 +921,41 @@ public abstract class AbstractJpaProject
}
+ // ********** Java resource persistent package look-up **********
+
+ public JavaResourcePackage getJavaResourcePackage(String packName) {
+ for (JavaResourcePackage jrpp : this.getJavaResourcePackages()) {
+ if (jrpp.getName().equals(packName)) {
+ return jrpp;
+ }
+ }
+ return null;
+ }
+
+ public Iterable<JavaResourcePackage> getJavaResourcePackages(){
+ return new FilteringIterable<JavaResourcePackage>(
+ new TransformationIterable<JpaFile, JavaResourcePackage>(this.getPackageInfoSourceJpaFiles()) {
+ @Override
+ protected JavaResourcePackage transform(JpaFile jpaFile) {
+ return ((JavaResourcePackageInfoCompilationUnit) jpaFile.getResourceModel()).getPackage();
+ }
+ })
+ {
+ @Override
+ protected boolean accept(JavaResourcePackage packageInfo) {
+ return packageInfo != null;
+ }
+ };
+ }
+
+ /**
+ * return JPA files with package-info source "content"
+ */
+ protected Iterable<JpaFile> getPackageInfoSourceJpaFiles() {
+ return this.getJpaFiles(JptCorePlugin.JAVA_SOURCE_PACKAGE_INFO_CONTENT_TYPE);
+ }
+
+
// ********** JARs **********
// TODO
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaAnnotationProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaAnnotationProvider.java
index 07794ca782..32b0e75cb3 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaAnnotationProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/GenericJpaAnnotationProvider.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009 Oracle. All rights reserved.
+ * Copyright (c) 2009, 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.
@@ -17,8 +17,10 @@ import org.eclipse.jpt.core.JpaAnnotationProvider;
import org.eclipse.jpt.core.resource.java.Annotation;
import org.eclipse.jpt.core.resource.java.AnnotationDefinition;
import org.eclipse.jpt.core.resource.java.JavaResourcePersistentAttribute;
+import org.eclipse.jpt.core.resource.java.JavaResourcePackage;
import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
import org.eclipse.jpt.core.utility.jdt.Attribute;
+import org.eclipse.jpt.core.utility.jdt.Package;
import org.eclipse.jpt.core.utility.jdt.Type;
import org.eclipse.jpt.utility.internal.iterators.ArrayListIterator;
import org.eclipse.jpt.utility.internal.iterators.CompositeIterator;
@@ -160,4 +162,42 @@ public class GenericJpaAnnotationProvider
return annotationDefinition;
}
+
+ // ********** package annotations **********
+
+ public Iterator<String> packageAnnotationNames() {
+ return annotationNames(packageAnnotationDefinitions());
+ }
+
+ protected Iterator<AnnotationDefinition> packageAnnotationDefinitions() {
+ return new CompositeIterator<AnnotationDefinition> (
+ new TransformationIterator<JpaAnnotationDefinitionProvider, Iterator<AnnotationDefinition>>(this.annotationDefinitionProviders()) {
+ @Override
+ protected Iterator<AnnotationDefinition> transform(JpaAnnotationDefinitionProvider annotationDefinitionProvider) {
+ return annotationDefinitionProvider.packageAnnotationDefinitions();
+ }
+ }
+ );
+ }
+
+ public Annotation buildPackageAnnotation(JavaResourcePackage parent, Package pack, String annotationName) {
+ return this.getPackageAnnotationDefinition(annotationName).buildAnnotation(parent, pack);
+ }
+
+ public Annotation buildPackageAnnotation(JavaResourcePackage parent, IAnnotation jdtAnnotation) {
+ return this.getPackageAnnotationDefinition(jdtAnnotation.getElementName()).buildAnnotation(parent, jdtAnnotation);
+ }
+
+ public Annotation buildNullPackageAnnotation(JavaResourcePackage parent, String annotationName) {
+ return this.getPackageAnnotationDefinition(annotationName).buildNullAnnotation(parent);
+ }
+
+ protected AnnotationDefinition getPackageAnnotationDefinition(String annotationName) {
+ AnnotationDefinition annotationDefinition = this.selectAnnotationDefinition(this.packageAnnotationDefinitions(), annotationName);
+ if (annotationDefinition == null) {
+ throw new IllegalArgumentException("unsupported package mapping annotation: " + annotationName); //$NON-NLS-1$
+ }
+ return annotationDefinition;
+ }
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JavaPackageInfoResourceModelProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JavaPackageInfoResourceModelProvider.java
new file mode 100644
index 0000000000..e51d6536a6
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JavaPackageInfoResourceModelProvider.java
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Copyright (c) 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.core.internal;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jpt.core.JpaProject;
+import org.eclipse.jpt.core.JpaResourceModelProvider;
+import org.eclipse.jpt.core.JptCorePlugin;
+import org.eclipse.jpt.core.internal.resource.java.source.SourcePackageInfoCompilationUnit;
+import org.eclipse.jpt.core.resource.java.JavaResourceCompilationUnit;
+
+/**
+ * Java package-info.java source code
+ */
+public class JavaPackageInfoResourceModelProvider
+ implements JpaResourceModelProvider
+{
+ // singleton
+ private static final JpaResourceModelProvider INSTANCE = new JavaPackageInfoResourceModelProvider();
+
+ /**
+ * Return the singleton.
+ */
+ public static JpaResourceModelProvider instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Ensure single instance.
+ */
+ private JavaPackageInfoResourceModelProvider() {
+ super();
+ }
+
+ public IContentType getContentType() {
+ return JptCorePlugin.JAVA_SOURCE_PACKAGE_INFO_CONTENT_TYPE;
+ }
+
+ public JavaResourceCompilationUnit buildResourceModel(JpaProject jpaProject, IFile file) {
+ return new SourcePackageInfoCompilationUnit(
+ JavaCore.createCompilationUnitFrom(file),
+ jpaProject.getJpaPlatform().getAnnotationProvider(),
+ jpaProject.getJpaPlatform().getAnnotationEditFormatter(),
+ jpaProject.getModifySharedDocumentCommandExecutor()
+ );
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JavaResourceModelProvider.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JavaResourceModelProvider.java
index 5d87c03086..e1b5e49a77 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JavaResourceModelProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/JavaResourceModelProvider.java
@@ -15,7 +15,7 @@ import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jpt.core.JpaProject;
import org.eclipse.jpt.core.JpaResourceModelProvider;
import org.eclipse.jpt.core.JptCorePlugin;
-import org.eclipse.jpt.core.internal.resource.java.source.SourceCompilationUnit;
+import org.eclipse.jpt.core.internal.resource.java.source.SourceTypeCompilationUnit;
import org.eclipse.jpt.core.resource.java.JavaResourceCompilationUnit;
/**
@@ -46,7 +46,7 @@ public class JavaResourceModelProvider
}
public JavaResourceCompilationUnit buildResourceModel(JpaProject jpaProject, IFile file) {
- return new SourceCompilationUnit(
+ return new SourceTypeCompilationUnit(
JavaCore.createCompilationUnitFrom(file),
jpaProject.getJpaPlatform().getAnnotationProvider(),
jpaProject.getJpaPlatform().getAnnotationEditFormatter(),
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceCompilationUnit.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceCompilationUnit.java
index d7264195d0..cfe7a4c1e7 100644
--- a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceCompilationUnit.java
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceCompilationUnit.java
@@ -9,37 +9,28 @@
******************************************************************************/
package org.eclipse.jpt.core.internal.resource.java.source;
-import java.util.Iterator;
-import java.util.List;
import org.eclipse.core.resources.IFile;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.JavaModelException;
-import org.eclipse.jdt.core.dom.ASTNode;
-import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jpt.core.JpaAnnotationProvider;
import org.eclipse.jpt.core.JpaResourceModelListener;
-import org.eclipse.jpt.core.JpaResourceType;
-import org.eclipse.jpt.core.JptCorePlugin;
import org.eclipse.jpt.core.internal.utility.jdt.ASTTools;
import org.eclipse.jpt.core.resource.java.JavaResourceCompilationUnit;
-import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
import org.eclipse.jpt.core.utility.TextRange;
import org.eclipse.jpt.core.utility.jdt.AnnotationEditFormatter;
import org.eclipse.jpt.utility.CommandExecutor;
import org.eclipse.jpt.utility.internal.ListenerList;
-import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
/**
* Java compilation unit (source file)
*/
-public final class SourceCompilationUnit
+public abstract class SourceCompilationUnit
extends SourceNode
implements JavaResourceCompilationUnit
{
/** JDT compilation unit */
- private final ICompilationUnit compilationUnit;
+ final ICompilationUnit compilationUnit;
/** pluggable annotation provider */
private final JpaAnnotationProvider annotationProvider;
@@ -53,19 +44,10 @@ public final class SourceCompilationUnit
/** listeners notified whenever the resource model changes */
private final ListenerList<JpaResourceModelListener> resourceModelListenerList;
- /**
- * The primary type of the AST compilation unit. We are not going to handle
- * multiple types defined in a single compilation unit. Entities must have
- * a public/protected no-arg constructor, and there is no way to access
- * the constructor in a package class (which is what all top-level,
- * non-primary classes must be).
- */
- private JavaResourcePersistentType persistentType;
-
// ********** construction **********
- public SourceCompilationUnit(
+ protected SourceCompilationUnit(
ICompilationUnit compilationUnit,
JpaAnnotationProvider annotationProvider,
AnnotationEditFormatter annotationEditFormatter,
@@ -76,21 +58,13 @@ public final class SourceCompilationUnit
this.annotationEditFormatter = annotationEditFormatter;
this.modifySharedDocumentCommandExecutor = modifySharedDocumentCommandExecutor;
this.resourceModelListenerList = new ListenerList<JpaResourceModelListener>(JpaResourceModelListener.class);
- this.persistentType = this.buildPersistentType();
}
public void initialize(CompilationUnit astRoot) {
// never called?
}
- private JavaResourcePersistentType buildPersistentType() {
- this.openCompilationUnit();
- CompilationUnit astRoot = this.buildASTRoot();
- this.closeCompilationUnit();
- return this.buildPersistentType(astRoot);
- }
-
- private void openCompilationUnit() {
+ void openCompilationUnit() {
try {
this.compilationUnit.open(null);
} catch (JavaModelException ex) {
@@ -98,7 +72,7 @@ public final class SourceCompilationUnit
}
}
- private void closeCompilationUnit() {
+ void closeCompilationUnit() {
try {
this.compilationUnit.close();
} catch (JavaModelException ex) {
@@ -132,10 +106,6 @@ public final class SourceCompilationUnit
// ********** JavaResourceNode implementation **********
- public void synchronizeWith(CompilationUnit astRoot) {
- this.syncPersistentType(astRoot);
- }
-
public TextRange getTextRange(CompilationUnit astRoot) {
return null;
}
@@ -143,15 +113,6 @@ public final class SourceCompilationUnit
// ********** JavaResourceNode.Root implementation **********
- /**
- * NB: return *all* the persistent types since we build them all
- */
- public Iterator<JavaResourcePersistentType> persistentTypes() {
- return (this.persistentType == null) ?
- EmptyIterator.<JavaResourcePersistentType>instance() :
- this.persistentType.allTypes();
- }
-
public void resourceModelChanged() {
for (JpaResourceModelListener listener : this.resourceModelListenerList.getListeners()) {
listener.resourceModelChanged(this);
@@ -165,12 +126,6 @@ public final class SourceCompilationUnit
return this.compilationUnit;
}
- public void resolveTypes() {
- if (this.persistentType != null) {
- this.persistentType.resolveTypes(this.buildASTRoot());
- }
- }
-
public CommandExecutor getModifySharedDocumentCommandExecutor() {
return this.modifySharedDocumentCommandExecutor;
}
@@ -184,39 +139,7 @@ public final class SourceCompilationUnit
}
- // ********** persistent type **********
-
- private JavaResourcePersistentType buildPersistentType(CompilationUnit astRoot) {
- TypeDeclaration td = this.getPrimaryTypeDeclaration(astRoot);
- return (td == null) ? null : this.buildPersistentType(astRoot, td);
- }
-
-
- private void syncPersistentType(CompilationUnit astRoot) {
- TypeDeclaration td = this.getPrimaryTypeDeclaration(astRoot);
- if (td == null) {
- this.syncPersistentType_(null);
- } else {
- if (this.persistentType == null) {
- this.syncPersistentType_(this.buildPersistentType(astRoot, td));
- } else {
- this.persistentType.synchronizeWith(astRoot);
- }
- }
- }
-
- private void syncPersistentType_(JavaResourcePersistentType astPersistentType) {
- JavaResourcePersistentType old = this.persistentType;
- this.persistentType = astPersistentType;
- this.firePropertyChanged(PERSISTENT_TYPES_COLLECTION, old, astPersistentType);
- }
-
-
// ********** JpaResourceModel implementation **********
-
- public JpaResourceType getResourceType() {
- return JptCorePlugin.JAVA_SOURCE_RESOURCE_TYPE;
- }
public void addResourceModelListener(JpaResourceModelListener listener) {
this.resourceModelListenerList.add(listener);
@@ -236,45 +159,7 @@ public final class SourceCompilationUnit
// ********** internal **********
- private JavaResourcePersistentType buildPersistentType(CompilationUnit astRoot, TypeDeclaration typeDeclaration) {
- return SourcePersistentType.newInstance(this, typeDeclaration, astRoot);
- }
-
- /**
- * i.e. the type with the same name as the compilation unit;
- * return the first class or interface (ignore annotations and enums) with
- * the same name as the compilation unit (file);
- * NB: this type could be in error if there is an annotation or enum
- * with the same name preceding it in the compilation unit
- *
- * Return null if the parser did not resolve the type declaration's binding.
- * This can occur if the project JRE is removed (bug 225332).
- */
- private TypeDeclaration getPrimaryTypeDeclaration(CompilationUnit astRoot) {
- String primaryTypeName = this.getPrimaryTypeName();
- for (AbstractTypeDeclaration atd : this.types(astRoot)) {
- if (this.nodeIsPrimaryTypeDeclaration(atd, primaryTypeName)) {
- return (atd.resolveBinding() == null) ? null : (TypeDeclaration) atd;
- }
- }
- return null;
- }
-
- private boolean nodeIsPrimaryTypeDeclaration(AbstractTypeDeclaration atd, String primaryTypeName) {
- return (atd.getNodeType() == ASTNode.TYPE_DECLARATION) &&
- atd.getName().getFullyQualifiedName().equals(primaryTypeName);
- }
-
- // minimize scope of suppressed warnings
- @SuppressWarnings("unchecked")
- private List<AbstractTypeDeclaration> types(CompilationUnit astRoot) {
- return astRoot.types();
- }
-
- /**
- * i.e. the name of the compilation unit
- */
- private String getPrimaryTypeName() {
+ String getCompilationUnitName() {
return this.removeJavaExtension(this.compilationUnit.getElementName());
}
@@ -285,7 +170,7 @@ public final class SourceCompilationUnit
@Override
public void toString(StringBuilder sb) {
- sb.append(this.getPrimaryTypeName());
+ sb.append(this.getCompilationUnitName());
}
}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePackage.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePackage.java
new file mode 100644
index 0000000000..6d0a1dd772
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePackage.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.core.internal.resource.java.source;
+
+import java.util.Iterator;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.IPackageBinding;
+import org.eclipse.jdt.core.dom.PackageDeclaration;
+import org.eclipse.jpt.core.internal.utility.jdt.JDTPackage;
+import org.eclipse.jpt.core.resource.java.Annotation;
+import org.eclipse.jpt.core.resource.java.JavaResourceCompilationUnit;
+import org.eclipse.jpt.core.resource.java.JavaResourcePackage;
+import org.eclipse.jpt.core.utility.jdt.Package;
+
+/**
+ * @author Dmitry Geraskov
+ * Source package-info.java
+ *
+ */
+public final class SourcePackage
+ extends SourceAnnotatedElement<Package>
+ implements JavaResourcePackage {
+
+ private String name;
+
+ /**
+ * construct package info
+ */
+ public static JavaResourcePackage newInstance(
+ JavaResourceCompilationUnit parent,
+ PackageDeclaration declaringPackage,
+ CompilationUnit astRoot) {
+ Package pack = new JDTPackage(
+ declaringPackage,
+ parent.getCompilationUnit(),
+ parent.getModifySharedDocumentCommandExecutor(),
+ parent.getAnnotationEditFormatter());
+ JavaResourcePackage jrpp = new SourcePackage(parent, pack);
+ jrpp.initialize(astRoot);
+ return jrpp;
+ }
+
+ private SourcePackage(
+ JavaResourceCompilationUnit parent,
+ Package pack){
+ super(parent, pack);
+ }
+
+ @Override
+ public void initialize(CompilationUnit astRoot) {
+ super.initialize(astRoot);
+ this.name = this.buildName(astRoot);
+ }
+
+
+ // ********** JavaResourcePackageInfo implementation **********
+
+ // ***** name
+ public String getName() {
+ return this.name;
+ }
+
+ private void syncName(String astName) {
+ if (valuesAreDifferent(astName, this.name)){
+ String old = this.name;
+ this.name = astName;
+ this.firePropertyChanged(NAME_PROPERTY, old, astName);
+ }
+ }
+
+ private String buildName(CompilationUnit astRoot) {
+ IPackageBinding binding = this.annotatedElement.getBinding(astRoot);
+ return (binding == null) ? null : binding.getName();
+ }
+
+
+ // ********** Java changes **********
+
+ @Override
+ public void synchronizeWith(CompilationUnit astRoot) {
+ super.synchronizeWith(astRoot);
+ this.syncName(this.buildName(astRoot));
+ }
+
+ // ********** SourceAnnotatedElement implementation **********
+
+ @Override
+ Iterator<String> validAnnotationNames() {
+ return this.getAnnotationProvider().packageAnnotationNames();
+ }
+
+
+ @Override
+ Annotation buildAnnotation(String annotationName) {
+ return this.getAnnotationProvider().buildPackageAnnotation(this, this.annotatedElement, annotationName);
+ }
+
+ @Override
+ Annotation buildNullAnnotation(String annotationName) {
+ return this.getAnnotationProvider().buildNullPackageAnnotation(this, annotationName);
+ }
+
+
+ @Override
+ public void toString(StringBuilder sb) {
+ sb.append(this.name);
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePackageInfoCompilationUnit.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePackageInfoCompilationUnit.java
new file mode 100644
index 0000000000..67b97ebcef
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourcePackageInfoCompilationUnit.java
@@ -0,0 +1,121 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.core.internal.resource.java.source;
+
+import java.util.Iterator;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.PackageDeclaration;
+import org.eclipse.jpt.core.JpaAnnotationProvider;
+import org.eclipse.jpt.core.JpaResourceType;
+import org.eclipse.jpt.core.JptCorePlugin;
+import org.eclipse.jpt.core.resource.java.JavaResourcePackage;
+import org.eclipse.jpt.core.resource.java.JavaResourcePackageInfoCompilationUnit;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.core.utility.jdt.AnnotationEditFormatter;
+import org.eclipse.jpt.utility.CommandExecutor;
+import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
+
+/**
+ * @author Dmitry Geraskov
+ * Source package-info.java
+ *
+ */
+public final class SourcePackageInfoCompilationUnit
+ extends SourceCompilationUnit
+ implements JavaResourcePackageInfoCompilationUnit {
+
+ private JavaResourcePackage package_;
+
+ public SourcePackageInfoCompilationUnit(
+ ICompilationUnit compilationUnit,
+ JpaAnnotationProvider annotationProvider,
+ AnnotationEditFormatter annotationEditFormatter,
+ CommandExecutor modifySharedDocumentCommandExecutor) {
+ super(compilationUnit, annotationProvider, annotationEditFormatter, modifySharedDocumentCommandExecutor); // the JPA compilation unit is the root of its sub-tree
+ this.package_ = this.buildPackage();
+ }
+
+
+ private JavaResourcePackage buildPackage() {
+ this.openCompilationUnit();
+ CompilationUnit astRoot = this.buildASTRoot();
+ this.closeCompilationUnit();
+ return this.buildPackage(astRoot);
+ }
+
+
+ // ********** JavaResourceNode.Root implementation **********
+
+ public Iterator<JavaResourcePersistentType> persistentTypes() {
+ return EmptyIterator.instance();
+ }
+
+
+ // ********** JpaResourceModel implementation **********
+
+ public JpaResourceType getResourceType() {
+ return JptCorePlugin.JAVA_SOURCE_PACKAGE_INFO_RESOURCE_TYPE;
+ }
+
+
+ // ********** Java changes **********
+
+ public void synchronizeWith(CompilationUnit astRoot) {
+ this.syncPackage(astRoot);
+ }
+
+
+ // ********** JavaResourceCompilationUnit implementation **********
+
+ public void resolveTypes() {
+ //no-op
+ }
+
+ // ********** package-info **********
+
+ public JavaResourcePackage getPackage() {
+ return this.package_;
+ }
+
+ private JavaResourcePackage buildPackage(CompilationUnit astRoot) {
+ return this.buildPackage(astRoot, this.getPackageDeclaration(astRoot));
+ }
+
+ private void syncPackage(CompilationUnit astRoot) {
+ PackageDeclaration pd = this.getPackageDeclaration(astRoot);
+ if (pd == null) {
+ this.syncPackage_(null);
+ } else {
+ if (this.package_ == null) {
+ this.syncPackage_(this.buildPackage(astRoot, pd));
+ } else {
+ this.package_.synchronizeWith(astRoot);
+ }
+ }
+ }
+
+ private PackageDeclaration getPackageDeclaration(CompilationUnit astRoot) {
+ return astRoot.getPackage();
+ }
+
+ private void syncPackage_(JavaResourcePackage astPackage) {
+ JavaResourcePackage old = this.package_;
+ this.package_ = astPackage;
+ this.firePropertyChanged(PACKAGE, old, astPackage);
+ }
+
+ private JavaResourcePackage buildPackage(CompilationUnit astRoot, PackageDeclaration packageDeclaration) {
+ return SourcePackage.newInstance(this, packageDeclaration, astRoot);
+ }
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceTypeCompilationUnit.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceTypeCompilationUnit.java
new file mode 100644
index 0000000000..d6dc5b48fe
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/resource/java/source/SourceTypeCompilationUnit.java
@@ -0,0 +1,167 @@
+/*******************************************************************************
+ * 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.core.internal.resource.java.source;
+
+import java.util.Iterator;
+import java.util.List;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.dom.ASTNode;
+import org.eclipse.jdt.core.dom.AbstractTypeDeclaration;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
+import org.eclipse.jpt.core.JpaAnnotationProvider;
+import org.eclipse.jpt.core.JpaResourceType;
+import org.eclipse.jpt.core.JptCorePlugin;
+import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
+import org.eclipse.jpt.core.utility.jdt.AnnotationEditFormatter;
+import org.eclipse.jpt.utility.CommandExecutor;
+import org.eclipse.jpt.utility.internal.iterators.EmptyIterator;
+
+/**
+ * Java compilation unit (source file)
+ * non package-info.java file
+ */
+public final class SourceTypeCompilationUnit
+ extends SourceCompilationUnit
+{
+
+ /**
+ * The primary type of the AST compilation unit. We are not going to handle
+ * multiple types defined in a single compilation unit. Entities must have
+ * a public/protected no-arg constructor, and there is no way to access
+ * the constructor in a package class (which is what all top-level,
+ * non-primary classes must be).
+ */
+ private JavaResourcePersistentType persistentType;
+
+
+ // ********** construction **********
+
+ public SourceTypeCompilationUnit(
+ ICompilationUnit compilationUnit,
+ JpaAnnotationProvider annotationProvider,
+ AnnotationEditFormatter annotationEditFormatter,
+ CommandExecutor modifySharedDocumentCommandExecutor) {
+ super(compilationUnit, annotationProvider, annotationEditFormatter, modifySharedDocumentCommandExecutor); // the JPA compilation unit is the root of its sub-tree
+ this.persistentType = this.buildPersistentType();
+ }
+
+ private JavaResourcePersistentType buildPersistentType() {
+ this.openCompilationUnit();
+ CompilationUnit astRoot = this.buildASTRoot();
+ this.closeCompilationUnit();
+ return this.buildPersistentType(astRoot);
+ }
+
+
+ // ********** JavaResourceNode implementation **********
+
+ public void synchronizeWith(CompilationUnit astRoot) {
+ this.syncPersistentType(astRoot);
+ }
+
+
+ // ********** JavaResourceNode.Root implementation **********
+
+ /**
+ * NB: return *all* the persistent types since we build them all
+ */
+ public Iterator<JavaResourcePersistentType> persistentTypes() {
+ return (this.persistentType == null) ?
+ EmptyIterator.<JavaResourcePersistentType>instance() :
+ this.persistentType.allTypes();
+ }
+
+
+ // ********** JpaResourceModel implementation **********
+
+ public JpaResourceType getResourceType() {
+ return JptCorePlugin.JAVA_SOURCE_RESOURCE_TYPE;
+ }
+
+
+ // ********** JavaResourceCompilationUnit implementation **********
+
+ public void resolveTypes() {
+ if (this.persistentType != null) {
+ this.persistentType.resolveTypes(this.buildASTRoot());
+ }
+ }
+
+
+ // ********** persistent type **********
+
+ private JavaResourcePersistentType buildPersistentType(CompilationUnit astRoot) {
+ TypeDeclaration td = this.getPrimaryTypeDeclaration(astRoot);
+ return (td == null) ? null : this.buildPersistentType(astRoot, td);
+ }
+
+
+ private void syncPersistentType(CompilationUnit astRoot) {
+ TypeDeclaration td = this.getPrimaryTypeDeclaration(astRoot);
+ if (td == null) {
+ this.syncPersistentType_(null);
+ } else {
+ if (this.persistentType == null) {
+ this.syncPersistentType_(this.buildPersistentType(astRoot, td));
+ } else {
+ this.persistentType.synchronizeWith(astRoot);
+ }
+ }
+ }
+
+ private void syncPersistentType_(JavaResourcePersistentType astPersistentType) {
+ JavaResourcePersistentType old = this.persistentType;
+ this.persistentType = astPersistentType;
+ this.firePropertyChanged(PERSISTENT_TYPES_COLLECTION, old, astPersistentType);
+ }
+
+
+ // ********** internal **********
+
+ private JavaResourcePersistentType buildPersistentType(CompilationUnit astRoot, TypeDeclaration typeDeclaration) {
+ return SourcePersistentType.newInstance(this, typeDeclaration, astRoot);
+ }
+
+ /**
+ * i.e. the type with the same name as the compilation unit;
+ * return the first class or interface (ignore annotations and enums) with
+ * the same name as the compilation unit (file);
+ * NB: this type could be in error if there is an annotation or enum
+ * with the same name preceding it in the compilation unit
+ *
+ * Return null if the parser did not resolve the type declaration's binding.
+ * This can occur if the project JRE is removed (bug 225332).
+ */
+ private TypeDeclaration getPrimaryTypeDeclaration(CompilationUnit astRoot) {
+ String primaryTypeName = this.getPrimaryTypeName();
+ for (AbstractTypeDeclaration atd : this.types(astRoot)) {
+ if (this.nodeIsPrimaryTypeDeclaration(atd, primaryTypeName)) {
+ return (atd.resolveBinding() == null) ? null : (TypeDeclaration) atd;
+ }
+ }
+ return null;
+ }
+
+ private boolean nodeIsPrimaryTypeDeclaration(AbstractTypeDeclaration atd, String primaryTypeName) {
+ return (atd.getNodeType() == ASTNode.TYPE_DECLARATION) &&
+ atd.getName().getFullyQualifiedName().equals(primaryTypeName);
+ }
+
+ private String getPrimaryTypeName() {
+ return this.getCompilationUnitName();
+ }
+
+ // minimize scope of suppressed warnings
+ @SuppressWarnings("unchecked")
+ private List<AbstractTypeDeclaration> types(CompilationUnit astRoot) {
+ return astRoot.types();
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTPackage.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTPackage.java
new file mode 100644
index 0000000000..8c30dc0b8f
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/internal/utility/jdt/JDTPackage.java
@@ -0,0 +1,65 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.core.internal.utility.jdt;
+
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.IPackageBinding;
+import org.eclipse.jdt.core.dom.PackageDeclaration;
+import org.eclipse.jpt.core.utility.TextRange;
+import org.eclipse.jpt.core.utility.jdt.AnnotationEditFormatter;
+import org.eclipse.jpt.core.utility.jdt.ModifiedDeclaration;
+import org.eclipse.jpt.core.utility.jdt.Package;
+import org.eclipse.jpt.utility.CommandExecutor;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+
+public class JDTPackage extends JDTAnnotatedElement implements Package {
+
+
+ protected JDTPackage(PackageDeclaration declaringPackage,
+ ICompilationUnit compilationUnit,
+ CommandExecutor modifySharedDocumentCommandExecutor) {
+ super(declaringPackage.getName().getFullyQualifiedName(),
+ compilationUnit,
+ modifySharedDocumentCommandExecutor);
+ }
+
+ public JDTPackage(
+ PackageDeclaration declaringPackage,
+ ICompilationUnit compilationUnit,
+ CommandExecutor modifySharedDocumentCommandExecutor,
+ AnnotationEditFormatter annotationEditFormatter) {
+ super(declaringPackage.getName().getFullyQualifiedName(),
+ compilationUnit, modifySharedDocumentCommandExecutor, annotationEditFormatter);
+ }
+
+ @Override
+ public ModifiedDeclaration getModifiedDeclaration(CompilationUnit astRoot) {
+ return new JDTModifiedDeclaration(this.getBodyDeclaration(astRoot));
+ }
+
+ public IPackageBinding getBinding(CompilationUnit astRoot) {
+ PackageDeclaration pd = this.getBodyDeclaration(astRoot);
+ return (pd == null) ? null : pd.resolveBinding();
+ }
+
+ public PackageDeclaration getBodyDeclaration(CompilationUnit astRoot) {
+ return astRoot.getPackage();
+ }
+
+ public TextRange getNameTextRange(CompilationUnit astRoot) {
+ return new ASTNodeTextRange(this.getBodyDeclaration(astRoot).getName());
+ }
+}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePackage.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePackage.java
new file mode 100644
index 0000000000..a3ced23fdd
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePackage.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.core.resource.java;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ * Java source code of package-info
+ * <p>
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ */
+public interface JavaResourcePackage
+ extends
+ JavaResourceAnnotatedElement
+{
+
+ /**
+ * The Java resource persistent package's name.
+ */
+ String getName();
+ String NAME_PROPERTY = "name"; //$NON-NLS-1$
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePackageInfoCompilationUnit.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePackageInfoCompilationUnit.java
new file mode 100644
index 0000000000..2ea130ad09
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/resource/java/JavaResourcePackageInfoCompilationUnit.java
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 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.core.resource.java;
+
+/**
+ * Dali resource for JDT compilation unit named package-info.java.
+ *
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * @version 3.0
+ * @since 3.0
+ */
+public interface JavaResourcePackageInfoCompilationUnit
+ extends JavaResourceCompilationUnit
+{
+ JavaResourcePackage getPackage();
+ String PACKAGE = "package"; //$NON-NLS-1$
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/utility/jdt/Package.java b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/utility/jdt/Package.java
new file mode 100644
index 0000000000..a275750e02
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.core/src/org/eclipse/jpt/core/utility/jdt/Package.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * Copyright (c) 2010 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is 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
+ *
+ * Contributor:
+ * Red Hat, Inc. - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.jpt.core.utility.jdt;
+
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.IPackageBinding;
+import org.eclipse.jdt.core.dom.PackageDeclaration;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * This interface is not intended to be implemented by clients.
+ */
+public interface Package extends AnnotatedElement {
+
+ /**
+ * Covariant override.
+ */
+ IPackageBinding getBinding(CompilationUnit astRoot);
+
+ /**
+ * Covariant override.
+ */
+ PackageDeclaration getBodyDeclaration(CompilationUnit astRoot);
+
+}
diff --git a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourceModelTestCase.java b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourceModelTestCase.java
index cf144d9975..289e80cb11 100644
--- a/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourceModelTestCase.java
+++ b/jpa/tests/org.eclipse.jpt.core.tests/src/org/eclipse/jpt/core/tests/internal/resource/java/JavaResourceModelTestCase.java
@@ -19,7 +19,7 @@ import org.eclipse.jpt.core.JpaAnnotationDefinitionProvider;
import org.eclipse.jpt.core.JpaAnnotationProvider;
import org.eclipse.jpt.core.internal.GenericJpaAnnotationDefinitionProvider;
import org.eclipse.jpt.core.internal.GenericJpaAnnotationProvider;
-import org.eclipse.jpt.core.internal.resource.java.source.SourceCompilationUnit;
+import org.eclipse.jpt.core.internal.resource.java.source.SourceTypeCompilationUnit;
import org.eclipse.jpt.core.internal.utility.jdt.NullAnnotationEditFormatter;
import org.eclipse.jpt.core.resource.java.JavaResourceCompilationUnit;
import org.eclipse.jpt.core.resource.java.JavaResourcePersistentType;
@@ -152,7 +152,7 @@ public class JavaResourceModelTestCase extends AnnotationTestCase
if (this.javaResourceCompilationUnit != null) {
throw new IllegalStateException();
}
- return new SourceCompilationUnit(
+ return new SourceTypeCompilationUnit(
cu,
this.buildAnnotationProvider(),
NullAnnotationEditFormatter.instance(),

Back to the top