Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2011-06-24 11:55:26 +0000
committerkmoore2011-06-24 11:55:26 +0000
commitcb572609e1a66259b16bd2f992067177309a3691 (patch)
tree11b7e1603638af89a0632a992ae68f62166d8f06 /common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt
parentc1a4e793034eafc0d0be46328c1f6ea1b2bd1c0c (diff)
downloadwebtools.dali-cb572609e1a66259b16bd2f992067177309a3691.tar.gz
webtools.dali-cb572609e1a66259b16bd2f992067177309a3691.tar.xz
webtools.dali-cb572609e1a66259b16bd2f992067177309a3691.zip
316022 - NPE refreshing out of sync entity - added null checks
Diffstat (limited to 'common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt')
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/AbstractJDTType.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTEnumConstant.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTFieldAttribute.java8
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTMethodAttribute.java8
4 files changed, 18 insertions, 6 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/AbstractJDTType.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/AbstractJDTType.java
index abbd202f7a..fc9c9e1c19 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/AbstractJDTType.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/AbstractJDTType.java
@@ -113,7 +113,9 @@ public abstract class AbstractJDTType
}
public TextRange getNameTextRange(CompilationUnit astRoot) {
- return new ASTNodeTextRange(this.getBodyDeclaration(astRoot).getName());
+ AbstractTypeDeclaration bodyDeclaration = this.getBodyDeclaration(astRoot);
+ //bodyDeclaration can be null if the resource is out of sync with the file system
+ return bodyDeclaration == null ? null : new ASTNodeTextRange(bodyDeclaration.getName());
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTEnumConstant.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTEnumConstant.java
index 3bedd952bf..fe72ba669b 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTEnumConstant.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTEnumConstant.java
@@ -74,7 +74,9 @@ public class JDTEnumConstant
}
public TextRange getNameTextRange(CompilationUnit astRoot) {
- return new ASTNodeTextRange(this.getBodyDeclaration(astRoot).getName());
+ EnumConstantDeclaration declaration = this.getBodyDeclaration(astRoot);
+ //declaration can be null if the resource is out of sync with the file system
+ return declaration == null ? null : new ASTNodeTextRange(declaration.getName());
}
//As far as I can tell, enum constants are always "persistable",
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTFieldAttribute.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTFieldAttribute.java
index fcce1eed37..6bf6d86747 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTFieldAttribute.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTFieldAttribute.java
@@ -80,7 +80,9 @@ public class JDTFieldAttribute
}
public TextRange getNameTextRange(CompilationUnit astRoot) {
- return new ASTNodeTextRange(this.getFragment(astRoot).getName());
+ VariableDeclarationFragment fragment = this.getFragment(astRoot);
+ //fragment can be null if the resource is out of sync with the file system
+ return fragment == null ? null : new ASTNodeTextRange(fragment.getName());
}
public String getAttributeName() {
@@ -142,7 +144,9 @@ public class JDTFieldAttribute
}
protected FieldDeclaration[] getDeclaringTypeFieldDeclarations(CompilationUnit astRoot) {
- return this.getDeclaringTypeDeclaration(astRoot).getFields();
+ TypeDeclaration typeDeclaration = this.getDeclaringTypeDeclaration(astRoot);
+ //typeDeclaration can be null if the resource is out of sync with the file system
+ return typeDeclaration == null ? new FieldDeclaration[0] : typeDeclaration.getFields();
}
// minimize scope of suppressed warnings
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTMethodAttribute.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTMethodAttribute.java
index cedc01f454..4000b8d341 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTMethodAttribute.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/jdt/JDTMethodAttribute.java
@@ -144,7 +144,9 @@ public class JDTMethodAttribute
}
public TextRange getNameTextRange(CompilationUnit astRoot) {
- return new ASTNodeTextRange(this.getBodyDeclaration(astRoot).getName());
+ MethodDeclaration methodDeclaration = this.getBodyDeclaration(astRoot);
+ //methodDeclaration can be null if the resource is out of sync with the file system
+ return methodDeclaration == null ? null : new ASTNodeTextRange(methodDeclaration.getName());
}
/**
@@ -174,7 +176,9 @@ public class JDTMethodAttribute
}
protected MethodDeclaration[] getDeclaringTypeMethodDeclarations(CompilationUnit astRoot) {
- return this.getDeclaringTypeDeclaration(astRoot).getMethods();
+ TypeDeclaration typeDeclaration = this.getDeclaringTypeDeclaration(astRoot);
+ //typeDeclaration can be null if the resource is out of sync with the file system
+ return typeDeclaration == null ? new MethodDeclaration[0] : typeDeclaration.getMethods();
}

Back to the top