summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNan Li2012-09-26 12:50:32 (EDT)
committerBrian Vosburgh2012-09-26 12:50:32 (EDT)
commitb36be037731ad7e6e7c8ddc3bd24c9c067795c5b (patch)
tree3452a39767a8f134f729585a2390e7c7472f419b
parentc8626e0adc26f2ad38a485cef71a39ef8e57ac4b (diff)
downloadwebtools.dali-b36be037731ad7e6e7c8ddc3bd24c9c067795c5b.zip
webtools.dali-b36be037731ad7e6e7c8ddc3bd24c9c067795c5b.tar.gz
webtools.dali-b36be037731ad7e6e7c8ddc3bd24c9c067795c5b.tar.bz2
[377900] NPE selecting binary class in JPA Content tree
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/Accessor.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaElementReference.java21
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaPersistentAttribute.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaPersistentType.java2
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractAccessor.java3
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentAttribute.java4
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java11
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/FieldAccessor.java14
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/PropertyAccessor.java25
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/VirtualJavaPersistentAttribute.java5
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/VirtualJavaPersistentType.java5
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/OpenJpaResourceAction.java24
-rw-r--r--jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceUnitItemLabelProvider.java9
13 files changed, 121 insertions, 6 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/Accessor.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/Accessor.java
index 1ac7a1b..25bad54 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/Accessor.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/Accessor.java
@@ -30,7 +30,7 @@ import org.eclipse.jpt.jpa.core.internal.context.JptValidator;
* @version 3.3
* @since 3.1
*/
-public interface Accessor extends JpaContextNode
+public interface Accessor extends JpaContextNode, JavaElementReference
{
/**
* Return the <em>resource</em> attribute(field/method) that is to be annotated.
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaElementReference.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaElementReference.java
new file mode 100644
index 0000000..66fbe04
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaElementReference.java
@@ -0,0 +1,21 @@
+/*******************************************************************************
+ * Copyright (c) 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.jpa.core.context.java;
+
+import org.eclipse.jdt.core.IJavaElement;
+
+public interface JavaElementReference
+{
+ /**
+ * Return IType for a persistent type or return IField or IMethod
+ * for a persistent attribute according to its access type
+ */
+ IJavaElement getJavaElement();
+}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaPersistentAttribute.java
index da1b043..a9d7601 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaPersistentAttribute.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaPersistentAttribute.java
@@ -29,7 +29,7 @@ import org.eclipse.jpt.jpa.core.jpa2.resource.java.JPA2_0;
* @since 2.0
*/
public interface JavaPersistentAttribute
- extends PersistentAttribute
+ extends PersistentAttribute, JavaElementReference
{
// ********** covariant overrides **********
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaPersistentType.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaPersistentType.java
index 1cbc71d..9638c03 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaPersistentType.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/context/java/JavaPersistentType.java
@@ -27,7 +27,7 @@ import org.eclipse.jpt.jpa.core.context.PersistentType;
* @since 2.0
*/
public interface JavaPersistentType
- extends PersistentType
+ extends PersistentType, JavaElementReference
{
// ********** covariant overrides **********
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractAccessor.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractAccessor.java
index f43907c..48b85d0 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractAccessor.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractAccessor.java
@@ -33,6 +33,9 @@ public abstract class AbstractAccessor
super(parent);
}
+ public ReadOnlyPersistentAttribute getParent() {
+ return (ReadOnlyPersistentAttribute) super.getParent();
+ }
// ********** unannotated Java resource member **********
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentAttribute.java
index 5eaabae..786dfd4 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentAttribute.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentAttribute.java
@@ -11,6 +11,7 @@ package org.eclipse.jpt.jpa.core.internal.context.java;
import java.util.List;
import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jpt.common.core.internal.utility.JDTTools;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute;
import org.eclipse.jpt.common.core.resource.java.JavaResourceCompilationUnit;
@@ -607,6 +608,9 @@ public abstract class AbstractJavaPersistentAttribute
sb.append(this.getName());
}
+ public IJavaElement getJavaElement() {
+ return this.accessor.getJavaElement();
+ }
// ********** validation **********
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java
index e0ee3e1..4620e37 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/AbstractJavaPersistentType.java
@@ -16,7 +16,9 @@ import java.util.Iterator;
import java.util.List;
import java.util.Vector;
import org.eclipse.core.resources.IResource;
+import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IPackageFragment;
+import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jpt.common.core.resource.java.Annotation;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAbstractType;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement;
@@ -1106,6 +1108,15 @@ public abstract class AbstractJavaPersistentType
sb.append(this.name);
}
+ public IJavaElement getJavaElement() {
+ try {
+ return this.getJpaProject().getJavaProject().findType(this.getName().replace('$', '.'));
+ }
+ catch (JavaModelException e) {
+ JptJpaCorePlugin.instance().logError(e);
+ }
+ return null;
+ }
// ********** Access type **********
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/FieldAccessor.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/FieldAccessor.java
index 137f218..889371c 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/FieldAccessor.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/FieldAccessor.java
@@ -9,6 +9,8 @@
*******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.context.java;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.dom.FieldDeclaration;
import org.eclipse.jdt.core.dom.VariableDeclarationFragment;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute;
@@ -19,6 +21,7 @@ import org.eclipse.jpt.jpa.core.context.AccessType;
import org.eclipse.jpt.jpa.core.context.PersistentAttribute;
import org.eclipse.jpt.jpa.core.context.PersistentType;
import org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.java.JavaElementReference;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.internal.context.JptValidator;
import org.eclipse.jpt.jpa.core.internal.jpa1.context.PersistentFieldValidator;
@@ -113,4 +116,15 @@ public class FieldAccessor
}
}
+ // ********** misc **********
+
+ public IJavaElement getJavaElement() {
+ PersistentType persistentType = this.getParent().getOwningPersistentType();
+ if (persistentType instanceof JavaElementReference) {
+ IType type = (IType)((JavaElementReference)persistentType).getJavaElement();
+ return type== null ? null : type.getField(this.getParent().getName());
+ }
+ return null;
+ }
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/PropertyAccessor.java b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/PropertyAccessor.java
index cb415a6..77bf747 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/PropertyAccessor.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.core/src/org/eclipse/jpt/jpa/core/internal/context/java/PropertyAccessor.java
@@ -9,17 +9,22 @@
*******************************************************************************/
package org.eclipse.jpt.jpa.core.internal.context.java;
+import java.util.List;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute;
import org.eclipse.jpt.common.core.resource.java.JavaResourceField;
import org.eclipse.jpt.common.core.resource.java.JavaResourceMethod;
import org.eclipse.jpt.common.core.utility.TextRange;
import org.eclipse.jpt.common.utility.MethodSignature;
+import org.eclipse.jpt.common.utility.internal.CollectionTools;
import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
import org.eclipse.jpt.jpa.core.context.AccessType;
import org.eclipse.jpt.jpa.core.context.PersistentAttribute;
import org.eclipse.jpt.jpa.core.context.PersistentType;
import org.eclipse.jpt.jpa.core.context.ReadOnlyPersistentAttribute;
+import org.eclipse.jpt.jpa.core.context.java.JavaElementReference;
import org.eclipse.jpt.jpa.core.context.java.JavaPersistentAttribute;
import org.eclipse.jpt.jpa.core.internal.context.JptValidator;
import org.eclipse.jpt.jpa.core.internal.jpa1.context.PersistentPropertyValidator;
@@ -144,4 +149,24 @@ public class PropertyAccessor
}
}
+ // ********** misc **********
+
+ public IJavaElement getJavaElement() {
+ PersistentType persistentType = this.getParent().getOwningPersistentType();
+ if (persistentType instanceof JavaElementReference) {
+ IType type = (IType)((JavaElementReference)persistentType).getJavaElement();
+ if (type != null) {
+ JavaResourceMethod jrm = this.resourceGetter;
+ if (jrm == null) {
+ jrm = this.resourceSetter;
+ }
+ if (jrm != null) {
+ List<String> parameters = CollectionTools.list(jrm.getParameterTypeNames());
+ return type.getMethod(jrm.getMethodName(), parameters.toArray(new String[parameters.size()]));
+ }
+ }
+ }
+ return null;
+ }
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/VirtualJavaPersistentAttribute.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/VirtualJavaPersistentAttribute.java
index 99920a8..d72300a 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/VirtualJavaPersistentAttribute.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/VirtualJavaPersistentAttribute.java
@@ -9,6 +9,7 @@
******************************************************************************/
package org.eclipse.jpt.jpa.eclipselink.core.internal.context.orm;
+import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jpt.common.core.internal.utility.JDTTools;
@@ -420,4 +421,8 @@ public class VirtualJavaPersistentAttribute
public void toString(StringBuilder sb) {
sb.append(this.getName());
}
+
+ public IJavaElement getJavaElement() {
+ return null;
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/VirtualJavaPersistentType.java b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/VirtualJavaPersistentType.java
index d56cec9..4e23dfd 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/VirtualJavaPersistentType.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.eclipselink.core/src/org/eclipse/jpt/jpa/eclipselink/core/internal/context/orm/VirtualJavaPersistentType.java
@@ -14,6 +14,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import org.eclipse.core.resources.IFile;
+import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAnnotatedElement;
import org.eclipse.jpt.common.core.resource.java.JavaResourceAttribute;
@@ -348,4 +349,8 @@ public class VirtualJavaPersistentType
public void dispose() {
//nothing to dispose
}
+
+ public IJavaElement getJavaElement() {
+ return null;
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/OpenJpaResourceAction.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/OpenJpaResourceAction.java
index 32e6e73..e2dd239 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/OpenJpaResourceAction.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/actions/OpenJpaResourceAction.java
@@ -12,16 +12,22 @@ package org.eclipse.jpt.jpa.ui.internal.actions;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.content.IContentType;
+import org.eclipse.jdt.core.IJavaElement;
+import org.eclipse.jdt.core.JavaModelException;
+import org.eclipse.jdt.ui.JavaUI;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jpt.common.core.internal.utility.PlatformTools;
import org.eclipse.jpt.jpa.core.JpaStructureNode;
import org.eclipse.jpt.jpa.core.context.JpaContextNode;
+import org.eclipse.jpt.jpa.core.context.java.JavaElementReference;
import org.eclipse.jpt.jpa.ui.internal.JptUiMessages;
+import org.eclipse.jpt.jpa.ui.internal.plugin.JptJpaUiPlugin;
import org.eclipse.jpt.jpa.ui.selection.JpaSelectionManager;
import org.eclipse.ui.IEditorDescriptor;
import org.eclipse.ui.IEditorRegistry;
import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.BaseSelectionListenerAction;
import org.eclipse.ui.ide.IDE;
@@ -71,6 +77,10 @@ public class OpenJpaResourceAction
selectionManager.setSelection((JpaStructureNode) this.selectedNode);
}
}
+ // handle persistent types and persistent attributes in jar files below
+ else if (this.selectedNode instanceof JavaElementReference) {
+ openEditor(((JavaElementReference) this.selectedNode).getJavaElement());
+ }
}
protected void openEditor(IFile file) {
@@ -90,4 +100,18 @@ public class OpenJpaResourceAction
MessageDialog.openError(page.getWorkbenchWindow().getShell(), JptUiMessages.OpenJpaResourceAction_error, e.getMessage());
}
}
+
+ private void openEditor(IJavaElement element) {
+ if (element != null) {
+ try {
+ JavaUI.openInEditor(element, true, true);
+ }
+ catch (PartInitException e) {
+ JptJpaUiPlugin.instance().logError(e);
+ }
+ catch (JavaModelException e) {
+ JptJpaUiPlugin.instance().logError(e);
+ }
+ }
+ }
}
diff --git a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceUnitItemLabelProvider.java b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceUnitItemLabelProvider.java
index 0e92afb..771577e 100644
--- a/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceUnitItemLabelProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.jpa.ui/src/org/eclipse/jpt/jpa/ui/internal/platform/generic/PersistenceUnitItemLabelProvider.java
@@ -94,7 +94,7 @@ public class PersistenceUnitItemLabelProvider
return new ComponentDescriptionModel(
nodeTextModels,
new TextModel(node.getPersistenceUnit()),
- node.getResource().getFullPath().makeRelative().toString(),
+ node.getResource() == null ? null : node.getResource().getFullPath().makeRelative().toString(),
quote
);
}
@@ -154,8 +154,11 @@ public class PersistenceUnitItemLabelProvider
if (this.quote) {
sb.append('\"');
}
- sb.append(" - "); //$NON-NLS-1$
- sb.append(this.path);
+ if (this.path != null) {
+ sb.append(" - "); //$NON-NLS-1$
+ sb.append(this.path);
+ }
+ sb.append(""); //$NON-NLS-1$
return sb.toString();
}
}