Author: dgeraskov
Date: 2011-08-02 07:11:19 -0400 (Tue, 02 Aug 2011)
New Revision: 33447
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/JavaPackageInfoResourceModelProviderPatched.java
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaPlatformProvider.java
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/jpa2/HibernateJpa2_0PlatformProvider.java
Log:
https://issues.jboss.org/browse/JBIDE-9438
Fix NPE for package-info placed in default package
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaPlatformProvider.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaPlatformProvider.java 2011-08-02
10:29:43 UTC (rev 33446)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/HibernateJpaPlatformProvider.java 2011-08-02
11:11:19 UTC (rev 33447)
@@ -25,7 +25,6 @@
import org.eclipse.jpt.jpa.core.context.java.JavaTypeMappingDefinition;
import org.eclipse.jpt.jpa.core.internal.AbstractJpaPlatformProvider;
import org.eclipse.jpt.jpa.core.internal.JarResourceModelProvider;
-import org.eclipse.jpt.jpa.core.internal.JavaPackageInfoResourceModelProvider;
import org.eclipse.jpt.jpa.core.internal.JavaResourceModelProvider;
import org.eclipse.jpt.jpa.core.internal.OrmResourceModelProvider;
import org.eclipse.jpt.jpa.core.internal.PersistenceResourceModelProvider;
@@ -103,7 +102,7 @@
// order should not be important here
protected static final JpaResourceModelProvider[] RESOURCE_MODEL_PROVIDERS = new
JpaResourceModelProvider[] {
- JavaPackageInfoResourceModelProvider.instance(),
+ JavaPackageInfoResourceModelProviderPatched.instance(),//replace with original when NPE
will be fixed
JavaResourceModelProvider.instance(),
JarResourceModelProvider.instance(),
PersistenceResourceModelProvider.instance(),
Added:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/JavaPackageInfoResourceModelProviderPatched.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/JavaPackageInfoResourceModelProviderPatched.java
(rev 0)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/JavaPackageInfoResourceModelProviderPatched.java 2011-08-02
11:11:19 UTC (rev 33447)
@@ -0,0 +1,72 @@
+/*******************************************************************************
+ * Copyright (c) 2011 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.jboss.tools.hibernate.jpt.core.internal;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.JavaCore;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jpt.common.core.JptCommonCorePlugin;
+import org.eclipse.jpt.jpa.core.JpaProject;
+import org.eclipse.jpt.jpa.core.JpaResourceModelProvider;
+import
org.eclipse.jpt.jpa.core.internal.resource.java.source.SourcePackageInfoCompilationUnit;
+import org.eclipse.jpt.jpa.core.resource.java.JavaResourceCompilationUnit;
+
+/**
+ * @author Dmitry Geraskov
+ *
+ */
+public class JavaPackageInfoResourceModelProviderPatched implements
+ JpaResourceModelProvider {
+ // singleton
+ private static final JpaResourceModelProvider INSTANCE = new
JavaPackageInfoResourceModelProviderPatched();
+
+ /**
+ * Return the singleton.
+ */
+ public static JpaResourceModelProvider instance() {
+ return INSTANCE;
+ }
+
+ /**
+ * Ensure single instance.
+ */
+ private JavaPackageInfoResourceModelProviderPatched() {
+ super();
+ }
+
+ public IContentType getContentType() {
+ return JptCommonCorePlugin.JAVA_SOURCE_PACKAGE_INFO_CONTENT_TYPE;
+ }
+
+ public JavaResourceCompilationUnit buildResourceModel(
+ JpaProject jpaProject, IFile file) {
+ ICompilationUnit cu = JavaCore.createCompilationUnitFrom(file);
+ try {
+ if (cu.getPackageDeclarations().length > 0){
+ return new SourcePackageInfoCompilationUnit(
+ cu,
+ jpaProject.getJpaPlatform().getAnnotationProvider(),
+ jpaProject.getJpaPlatform().getAnnotationEditFormatter(),
+ jpaProject.getModifySharedDocumentCommandExecutor());
+ } else {
+ //ignore package-info placed in default package as
+ //it doesn't have package declaration and can't hold annotations
+ return null;
+ }
+ } catch (JavaModelException e) {
+ // Ignore -- project is in a bad state. This will get recalled if necessary
+ return null;
+ }
+ }
+
+}
Modified:
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/jpa2/HibernateJpa2_0PlatformProvider.java
===================================================================
---
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/jpa2/HibernateJpa2_0PlatformProvider.java 2011-08-02
10:29:43 UTC (rev 33446)
+++
trunk/hibernatetools/plugins/org.jboss.tools.hibernate.jpt.core/src/org/jboss/tools/hibernate/jpt/core/internal/jpa2/HibernateJpa2_0PlatformProvider.java 2011-08-02
11:11:19 UTC (rev 33447)
@@ -25,7 +25,6 @@
import org.eclipse.jpt.jpa.core.context.java.JavaTypeMappingDefinition;
import org.eclipse.jpt.jpa.core.internal.AbstractJpaPlatformProvider;
import org.eclipse.jpt.jpa.core.internal.JarResourceModelProvider;
-import org.eclipse.jpt.jpa.core.internal.JavaPackageInfoResourceModelProvider;
import org.eclipse.jpt.jpa.core.internal.JavaResourceModelProvider;
import org.eclipse.jpt.jpa.core.internal.OrmResourceModelProvider;
import org.eclipse.jpt.jpa.core.internal.PersistenceResourceModelProvider;
@@ -37,6 +36,7 @@
import
org.eclipse.jpt.jpa.core.internal.jpa2.context.java.JavaElementCollectionMappingDefinition2_0;
import
org.eclipse.jpt.jpa.core.internal.jpa2.context.java.JavaEmbeddedMappingDefinition2_0;
import
org.eclipse.jpt.jpa.core.internal.jpa2.context.java.JavaOneToManyMappingDefinition2_0;
+import
org.jboss.tools.hibernate.jpt.core.internal.JavaPackageInfoResourceModelProviderPatched;
import
org.jboss.tools.hibernate.jpt.core.internal.context.definition.HibernateJavaBasicMappingDefinition;
import
org.jboss.tools.hibernate.jpt.core.internal.context.definition.HibernateJavaEntityDefinition;
import
org.jboss.tools.hibernate.jpt.core.internal.context.orm.HibernateOrmXmlDefinition;
@@ -106,7 +106,7 @@
// order should not be important here
protected static final JpaResourceModelProvider[] RESOURCE_MODEL_PROVIDERS = new
JpaResourceModelProvider[] {
- JavaPackageInfoResourceModelProvider.instance(),
+ JavaPackageInfoResourceModelProviderPatched.instance(),//replace with original when NPE
will be fixed
JavaResourceModelProvider.instance(),
JarResourceModelProvider.instance(),
PersistenceResourceModelProvider.instance(),