summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPetya Sabeva2013-01-10 04:29:43 (EST)
committerPetya Sabeva2013-01-10 04:32:11 (EST)
commita46bb1fd29fcc76d7dc37282dd69866a94cad07d (patch)
tree9f5c0ee501d1c1d35266c9b2eb0d7e535877250e
parent0c882a4ac166681870ae002ec9045de56a1b8a1e (diff)
downloadwebtools.dali-a46bb1fd29fcc76d7dc37282dd69866a94cad07d.zip
webtools.dali-a46bb1fd29fcc76d7dc37282dd69866a94cad07d.tar.gz
webtools.dali-a46bb1fd29fcc76d7dc37282dd69866a94cad07d.tar.bz2
Fix some NPEs.
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/DeleteAttributeCommand.java114
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickRemoveAttributeButtonFeature.java3
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java6
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java8
-rw-r--r--jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java9
5 files changed, 24 insertions, 116 deletions
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/DeleteAttributeCommand.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/DeleteAttributeCommand.java
index eb3159a..5c0d7a4 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/DeleteAttributeCommand.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/command/DeleteAttributeCommand.java
@@ -49,110 +49,12 @@ public class DeleteAttributeCommand implements Command {
this.fp = fp;
}
- public void execute() {
-//<<<<<<< OURS
-// synchronized (jpt) {
-// String attrNameWithCapitalLetter = attributeName.substring(0, 1)
-// .toUpperCase(Locale.ENGLISH)
-// + attributeName.substring(1);
-// ICompilationUnit compUnit = fp.getCompilationUnit(jpt);
-// IType javaType = compUnit.findPrimaryType();
-// JavaPersistentAttribute jpa = jpt.getAttributeNamed(attributeName);
-//
-// String typeSignature = null;
-// String getterPrefix = "get"; //$NON-NLS-1$
-// String methodName = getterPrefix + attrNameWithCapitalLetter;
-// IMethod getAttributeMethod = javaType.getMethod(methodName,
-// new String[0]);
-// if (!getAttributeMethod.exists()) {
-//
-// String typeName = jpa.getResourceAttribute().getTypeBinding().getQualifiedName();
-// if ("boolean".equals(typeName)) { //$NON-NLS-1$
-// getterPrefix = "is"; //$NON-NLS-1$
-// methodName = getterPrefix + attrNameWithCapitalLetter;
-// getAttributeMethod = javaType.getMethod(methodName,
-// new String[0]);
-// }
-// try {
-// if ((getAttributeMethod != null) && getAttributeMethod.exists()) {
-// typeSignature = getAttributeMethod.getReturnType();
-// }
-// } catch (JavaModelException e1) {
-// JPADiagramEditorPlugin.logError("Cannot obtain the type of the getter with name " + methodName + "()", e1); //$NON-NLS-1$ //$NON-NLS-2$
-// }
-// }
-// if (typeSignature == null)
-// methodName = null;
-//=======
- boolean isMethodAnnotated = false;
-//>>>>>>> THEIRS
-//
-//<<<<<<< OURS
-// boolean isMethodAnnotated = JpaArtifactFactory.instance()
-// .isMethodAnnotated(jpt);
-// if (isMethodAnnotated) {
-// try {
-// IField attributeField = javaType.getField(attributeName);
-//
-// if ((attributeField != null) && !attributeField.exists())
-// attributeField = javaType.getField(JPAEditorUtil.revertFirstLetterCase(attributeName));
-// if ((attributeField != null) && attributeField.exists())
-// attributeField.delete(true, new NullProgressMonitor());
-// } catch (JavaModelException e) {
-// JPADiagramEditorPlugin.logError("Cannot remove the attribute field with name " + attributeName, e); //$NON-NLS-1$
-// }
-// try {
-// methodName = getterPrefix + attrNameWithCapitalLetter;
-// if (getAttributeMethod != null) {
-// typeSignature = getAttributeMethod.getReturnType();
-// if (getAttributeMethod.exists())
-// getAttributeMethod.delete(true, new NullProgressMonitor());
-// }
-// } catch (JavaModelException e) {
-// JPADiagramEditorPlugin.logError("Cannot remove the attribute getter with name " + methodName + "()", e); //$NON-NLS-1$ //$NON-NLS-2$
-// }
-// } else {
-// try {
-// methodName = getterPrefix + attrNameWithCapitalLetter;
-// if (getAttributeMethod.exists()) {
-// typeSignature = getAttributeMethod.getReturnType();
-// getAttributeMethod.delete(true, new NullProgressMonitor());
-// }
-// } catch (JavaModelException e) {
-// JPADiagramEditorPlugin.logError("Cannot remove the attribute getter with name " + methodName + "()", e); //$NON-NLS-1$ //$NON-NLS-2$
-// }
-// try {
-// IField attributeField = javaType.getField(this.attributeName);
-// if (attributeField != null)
-// if (!attributeField.exists())
-// attributeField = javaType.getField(JPAEditorUtil.revertFirstLetterCase(attributeName));
-// if ((attributeField != null) && attributeField.exists())
-// attributeField.delete(true, new NullProgressMonitor());
-// } catch (JavaModelException e) {
-// JPADiagramEditorPlugin.logError("Cannot remove the attribute field with name " + attributeName, e); //$NON-NLS-1$
-// }
-// }
-// try {
-// methodName = "set" + attrNameWithCapitalLetter; //$NON-NLS-1$
-// IMethod setAttributeMethod = javaType.getMethod(methodName,
-// new String[] { typeSignature });
-// if ((setAttributeMethod != null) && setAttributeMethod.exists())
-// setAttributeMethod.delete(true, new NullProgressMonitor());
-// } catch (Exception e) {
-// JPADiagramEditorPlugin.logError("Cannot remove the attribute setter with name " + methodName + "(...)", e); //$NON-NLS-1$ //$NON-NLS-2$
-// }
-//
-// IWorkbenchSite ws = ((IEditorPart) fp.getDiagramTypeProvider().getDiagramEditor()).getSite();
-// JPAEditorUtil.organizeImports(compUnit, ws);
-//
-// this.jpt.getJavaResourceType().getJavaResourceCompilationUnit().synchronizeWithJavaSource();
-//
-//=======
+ public void execute() {
+ boolean isMethodAnnotated = false;
if(jpt != null) {
unit = fp.getCompilationUnit(jpt);
isMethodAnnotated = JpaArtifactFactory.instance()
.isMethodAnnotated(jpt);
-//>>>>>>> THEIRS
}
IType javaType = unit.findPrimaryType();
@@ -171,7 +73,7 @@ public class DeleteAttributeCommand implements Command {
methodName = getterPrefix + attrNameWithCapitalLetter; //$NON-NLS-1$
getAttributeMethod = javaType.getMethod(methodName, new String[0]);
try {
- if ((getAttributeMethod != null) && getAttributeMethod.exists());
+ if ((getAttributeMethod != null) && getAttributeMethod.exists())
typeSignature = getAttributeMethod.getReturnType();
} catch (JavaModelException e1) {
JPADiagramEditorPlugin.logError("Cannot obtain the type of the getter with name " + methodName + "()", e1); //$NON-NLS-1$ //$NON-NLS-2$
@@ -224,10 +126,12 @@ public class DeleteAttributeCommand implements Command {
}
try {
methodName = "set" + attrNameWithCapitalLetter; //$NON-NLS-1$
- IMethod setAttributeMethod = javaType.getMethod(methodName,
- new String[] { typeSignature });
- if ((setAttributeMethod != null) && setAttributeMethod.exists())
- setAttributeMethod.delete(true, new NullProgressMonitor());
+ if(typeSignature != null) {
+ IMethod setAttributeMethod = javaType.getMethod(methodName,
+ new String[] { typeSignature });
+ if ((setAttributeMethod != null) && setAttributeMethod.exists())
+ setAttributeMethod.delete(true, new NullProgressMonitor());
+ }
} catch (Exception e) {
JPADiagramEditorPlugin.logError("Cannot remove the attribute setter with name " + methodName + "(...)", e); //$NON-NLS-1$ //$NON-NLS-2$
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickRemoveAttributeButtonFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickRemoveAttributeButtonFeature.java
index 578b1b9..4697ef4 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickRemoveAttributeButtonFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/ClickRemoveAttributeButtonFeature.java
@@ -233,7 +233,8 @@ public class ClickRemoveAttributeButtonFeature extends DefaultDeleteFeature {
String fqn = JPAEditorUtil.getAttributeTypeNameWithGenerics(jpa1);
if(isDeleteAttributeAllowed(jpt, fqn)){
JavaPersistentType embeddedJPT = jpaFactory.getContextPersistentType(jpt.getJpaProject(), fqn);
- jpaFactory.deleteAttribute(embeddedJPT, attribName, getFeatureProvider());
+ if(embeddedJPT != null)
+ jpaFactory.deleteAttribute(embeddedJPT, attribName, getFeatureProvider());
}
}
}
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java
index 4d5e954..466449c 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/feature/RefactorEntityFeature.java
@@ -39,11 +39,11 @@ import org.eclipse.graphiti.mm.pictograms.PictogramElement;
import org.eclipse.graphiti.mm.pictograms.Shape;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.jdt.core.ICompilationUnit;
+import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.ui.actions.SelectionDispatchAction;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jpt.common.core.JptResourceModel;
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.JavaResourceCompilationUnit;
import org.eclipse.jpt.common.utility.model.event.CollectionAddEvent;
import org.eclipse.jpt.common.utility.model.event.CollectionChangeEvent;
@@ -290,8 +290,8 @@ public abstract class RefactorEntityFeature extends AbstractCustomFeature {
if (!JavaResourceCompilationUnit.class.isInstance(rm))
return;
JavaResourceCompilationUnit jrcu = (JavaResourceCompilationUnit)rm;
- JavaResourceAbstractType jrt = jrcu.getPrimaryType();
- newJptName = jrt.getTypeBinding().getQualifiedName();
+ IType type = jrcu.getCompilationUnit().findPrimaryType();
+ newJptName = type.getFullyQualifiedName();
s.release();
if ((ats == null) || hasNameAnnotation)
return;
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java
index be28b9b..16d88d4 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JPASolver.java
@@ -59,12 +59,12 @@ import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaElementDelta;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragmentRoot;
+import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.core.PackageFragmentRoot;
import org.eclipse.jpt.common.core.JptResourceModel;
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.JavaResourceCompilationUnit;
import org.eclipse.jpt.common.utility.internal.iterator.ArrayIterator;
import org.eclipse.jpt.common.utility.model.Model;
@@ -1094,8 +1094,10 @@ public class JPASolver implements IResourceChangeListener, IJpaSolver {
if (!JavaResourceCompilationUnit.class.isInstance(jrm))
continue;
JavaResourceCompilationUnit jrcu = (JavaResourceCompilationUnit)jrm;
- JavaResourceAbstractType jrat = jrcu.getPrimaryType();
- String name = jrat.getTypeBinding().getQualifiedName();
+ IType type = jrcu.getCompilationUnit().findPrimaryType();
+ if(type == null)
+ continue;
+ String name = type.getFullyQualifiedName();
JpaProject jpaProject = jpaFile.getJpaProject();
PersistenceUnit pu = JpaArtifactFactory.instance().getPersistenceUnit(jpaProject);
diff --git a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java
index 618e58b..bd28d4a 100644
--- a/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java
+++ b/jpa_diagram_editor/plugins/org.eclipse.jpt.jpadiagrameditor.ui/src/org/eclipse/jpt/jpadiagrameditor/ui/internal/util/JpaArtifactFactory.java
@@ -871,11 +871,12 @@ public class JpaArtifactFactory {
* @return a set of strings of all current annotation names of the given attribute.
*/
public HashSet<String> getAnnotationNames(JavaPersistentAttribute persistentAttribite) {
-
- JavaResourceAttribute jrpt = persistentAttribite.getResourceAttribute();
HashSet<String> res = new HashSet<String>();
- for (Annotation annotation : jrpt.getAnnotations()) {
- res.add(JPAEditorUtil.returnSimpleName(annotation.getAnnotationName()));
+ if(persistentAttribite != null) {
+ JavaResourceAttribute jrpt = persistentAttribite.getResourceAttribute();
+ for (Annotation annotation : jrpt.getAnnotations()) {
+ res.add(JPAEditorUtil.returnSimpleName(annotation.getAnnotationName()));
+ }
}
return res;
}