Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkmoore2012-01-05 20:38:23 +0000
committerkmoore2012-01-05 20:38:23 +0000
commite9d9f7a5fb46b9904f2bade8bb964685a0607b3b (patch)
tree6eb959935dabdd692344775aea21a5490178d8e8 /common/plugins
parentf084e6d5c6e20a08394679e05e9f44bd9c4dc508 (diff)
downloadwebtools.dali-e9d9f7a5fb46b9904f2bade8bb964685a0607b3b.tar.gz
webtools.dali-e9d9f7a5fb46b9904f2bade8bb964685a0607b3b.tar.xz
webtools.dali-e9d9f7a5fb46b9904f2bade8bb964685a0607b3b.zip
Bug 236087 - validation for IdClass - patch from Nan
Diffstat (limited to 'common/plugins')
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryMember.java27
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryType.java53
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMember.java23
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceType.java54
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/JDTTools.java4
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceMember.java9
-rw-r--r--common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceType.java18
7 files changed, 180 insertions, 8 deletions
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryMember.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryMember.java
index e0e219abcf..be988599b1 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryMember.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryMember.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2009, 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.
@@ -36,6 +36,7 @@ abstract class BinaryMember
private boolean transient_; // 'transient' is a reserved word
private boolean public_; // 'public' is a reserved word
private boolean static_; // 'static' is a reserved word
+ boolean protected_; // 'protected' is a reserved word
// ********** construction/initialization **********
@@ -46,6 +47,7 @@ abstract class BinaryMember
this.transient_ = this.buildTransient();
this.public_ = this.buildPublic();
this.static_ = this.buildStatic();
+ this.protected_ = this.buildProtected();
}
@@ -58,6 +60,7 @@ abstract class BinaryMember
this.setTransient(this.buildTransient());
this.setPublic(this.buildPublic());
this.setStatic(this.buildStatic());
+ this.setProtected(this.buildProtected());
}
@@ -143,6 +146,25 @@ abstract class BinaryMember
}
}
+ // ***** protected
+ public boolean isProtected() {
+ return this.protected_;
+ }
+
+ private void setProtected(boolean protected_) {
+ boolean old = this.protected_;
+ this.protected_ = protected_;
+ this.firePropertyChanged(PROTECTED_PROPERTY, old, protected_);
+ }
+
+ private boolean buildProtected() {
+ try {
+ return Flags.isProtected(this.getMember().getFlags());
+ } catch (JavaModelException ex) {
+ JptCommonCorePlugin.log(ex);
+ return false;
+ }
+ }
// ********** miscellaneous **********
@@ -250,6 +272,9 @@ abstract class BinaryMember
return names;
}
+ public boolean isPublicOrProtected() {
+ return isPublic() || isProtected();
+ }
// ********** IMember adapter **********
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryType.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryType.java
index 904b9dafc2..c1bc7414c6 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryType.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/binary/BinaryType.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2009, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2009, 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.
@@ -25,6 +25,7 @@ import org.eclipse.jpt.common.core.resource.java.JavaResourceNode;
import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
import org.eclipse.jpt.common.utility.MethodSignature;
import org.eclipse.jpt.common.utility.internal.CollectionTools;
+import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable;
import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneIterable;
@@ -205,6 +206,19 @@ final class BinaryType
return false;
}
+ public boolean hasPublicNoArgConstructor() {
+ Iterable<JavaResourceMethod> constructors = getConstructors();
+ if (CollectionTools.size(constructors) == 0) {
+ return true;
+ }
+ for (JavaResourceMethod constructor : constructors) {
+ if (constructor.getParametersSize() == 0) {
+ return Modifier.isPublic(constructor.getModifiers());
+ }
+ }
+ return false;
+ }
+
protected Iterable<JavaResourceMethod> getConstructors() {
return new FilteringIterable<JavaResourceMethod>(getMethods()) {
@Override
@@ -240,6 +254,43 @@ final class BinaryType
return super.getMember();
}
+ // Two more requirements for a valid equals() method:
+ // 1. It should be public
+ // 2. The return type should be boolean
+ // Both requirements are validated by the compiler so they are excluded here
+ public boolean hasEqualsMethod() {
+ for (JavaResourceMethod method : this.getMethods()) {
+ if (StringTools.stringsAreEqual(method.getMethodName(), "equals")
+ && method.getParametersSize() == 1
+ && StringTools.stringsAreEqual(method.getParameterTypeName(0), Object.class.getName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ // Two more requirements for a valid hashCode() method:
+ // 1. It should be public
+ // 2. The return type should be int
+ // Both requirements are validated by the compiler so they are excluded here
+ public boolean hasHashCodeMethod() {
+ for (JavaResourceMethod method : this.getMethods()) {
+ if (StringTools.stringsAreEqual(method.getMethodName(), "hashCode")
+ && method.getParametersSize() == 0) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public JavaResourceMethod getMethod(String propertyName) {
+ for (JavaResourceMethod method : this.getMethods()) {
+ if (StringTools.stringsAreEqual(method.getMethodName(), propertyName)) {
+ return method;
+ }
+ }
+ return null;
+ }
// ********** fields **********
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMember.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMember.java
index 588efe1a33..7ecfef3165 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMember.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceMember.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 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.
@@ -36,6 +36,7 @@ abstract class SourceMember<M extends Member>
boolean static_; // 'static' is a reserved word
+ boolean protected_; // 'protected' is a reserved word
// ********** construction/initialization **********
@@ -51,6 +52,7 @@ abstract class SourceMember<M extends Member>
this.transient_ = this.buildTransient(binding);
this.public_ = this.buildPublic(binding);
this.static_ = this.buildStatic(binding);
+ this.protected_ = this.buildProtected(binding);
}
@Override
@@ -61,6 +63,7 @@ abstract class SourceMember<M extends Member>
this.syncTransient(this.buildTransient(binding));
this.syncPublic(this.buildPublic(binding));
this.syncStatic(this.buildStatic(binding));
+ this.syncProtected(this.buildProtected(binding));
}
@@ -166,7 +169,21 @@ abstract class SourceMember<M extends Member>
private boolean buildStatic(IBinding binding) {
return (binding == null) ? false : Modifier.isStatic(binding.getModifiers());
}
+
+ // ***** protected
+ public boolean isProtected() {
+ return this.protected_;
+ }
+
+ private void syncProtected(boolean astProtected) {
+ boolean old = this.protected_;
+ this.protected_ = astProtected;
+ this.firePropertyChanged(PROTECTED_PROPERTY, old, astProtected);
+ }
+ private boolean buildProtected(IBinding binding) {
+ return (binding == null) ? false : Modifier.isProtected(binding.getModifiers());
+ }
// ********** miscellaneous **********
@@ -177,4 +194,8 @@ abstract class SourceMember<M extends Member>
public void resolveTypes(CompilationUnit astRoot) {
}
+ public boolean isPublicOrProtected() {
+ return isPublic() || isProtected();
+ }
+
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceType.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceType.java
index 95655600f5..c2769e6e5d 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceType.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/resource/java/source/SourceType.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 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.
@@ -33,6 +33,7 @@ import org.eclipse.jpt.common.core.resource.java.JavaResourceType;
import org.eclipse.jpt.common.core.utility.jdt.Type;
import org.eclipse.jpt.common.utility.MethodSignature;
import org.eclipse.jpt.common.utility.internal.CollectionTools;
+import org.eclipse.jpt.common.utility.internal.StringTools;
import org.eclipse.jpt.common.utility.internal.iterables.FilteringIterable;
import org.eclipse.jpt.common.utility.internal.iterables.LiveCloneIterable;
import org.eclipse.jpt.common.utility.internal.iterables.TreeIterable;
@@ -279,6 +280,19 @@ final class SourceType
return false;
}
+ public boolean hasPublicNoArgConstructor() {
+ Iterable<JavaResourceMethod> constructors = getConstructors();
+ if (CollectionTools.size(constructors) == 0) {
+ return true;
+ }
+ for (JavaResourceMethod constructor : constructors) {
+ if (constructor.getParametersSize() == 0) {
+ return Modifier.isPublic(constructor.getModifiers());
+ }
+ }
+ return false;
+ }
+
protected Iterable<JavaResourceMethod> getConstructors() {
return new FilteringIterable<JavaResourceMethod>(getMethods()) {
@Override
@@ -557,4 +571,42 @@ final class SourceType
}
return false;
}
+
+ // Two more requirements for a valid equals() method:
+ // 1. It should be public
+ // 2. The return type should be boolean
+ // Both requirements are validated by the compiler so they are excluded here
+ public boolean hasEqualsMethod() {
+ for (JavaResourceMethod method : this.getMethods()) {
+ if (StringTools.stringsAreEqual(method.getMethodName(), "equals")
+ && method.getParametersSize() == 1
+ && StringTools.stringsAreEqual(method.getParameterTypeName(0), Object.class.getName())) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ // Two more requirements for a valid hashCode() method:
+ // 1. It should be public
+ // 2. The return type should be int
+ // Both requirements are validated by the compiler so they are excluded here
+ public boolean hasHashCodeMethod() {
+ for (JavaResourceMethod method : this.getMethods()) {
+ if (StringTools.stringsAreEqual(method.getMethodName(), "hashCode")
+ && method.getParametersSize() == 0) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ public JavaResourceMethod getMethod(String propertyName) {
+ for (JavaResourceMethod method : this.getMethods()) {
+ if (StringTools.stringsAreEqual(method.getMethodName(), propertyName)) {
+ return method;
+ }
+ }
+ return null;
+ }
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/JDTTools.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/JDTTools.java
index e42b16a310..c8e2122481 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/JDTTools.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/internal/utility/JDTTools.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2010, 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.
@@ -250,7 +250,7 @@ public final class JDTTools {
return false;
}
- private static final String SERIALIZABLE_CLASS_NAME = java.io.Serializable.class.getName();
+ public static final String SERIALIZABLE_CLASS_NAME = java.io.Serializable.class.getName();
/**
* Return whether the specified type is a valid element type for
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceMember.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceMember.java
index 88062b73e8..6acbee48d2 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceMember.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceMember.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2007, 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.
@@ -56,6 +56,9 @@ public interface JavaResourceMember
boolean isStatic();
String STATIC_PROPERTY = "static"; //$NON-NLS-1$
+ boolean isProtected();
+ String PROTECTED_PROPERTY = "protected"; //$NON-NLS-1$
+
// ********** queries **********
@@ -74,4 +77,8 @@ public interface JavaResourceMember
*/
void resolveTypes(CompilationUnit astRoot);
+ /**
+ * Return whether the Java resource member is public or protected
+ */
+ boolean isPublicOrProtected();
}
diff --git a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceType.java b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceType.java
index a63a6e0e28..d2dd201252 100644
--- a/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceType.java
+++ b/common/plugins/org.eclipse.jpt.common.core/src/org/eclipse/jpt/common/core/resource/java/JavaResourceType.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010, 2011 Oracle. All rights reserved.
+ * Copyright (c) 2010, 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.
@@ -54,6 +54,11 @@ public interface JavaResourceType
* Return whether the type has a public or protected no-arg constructor *or* only the default constructor
*/
boolean hasPublicOrProtectedNoArgConstructor();
+
+ /**
+ * Return whether the type has a public or protected no-arg constructor *or* only the default constructor
+ */
+ boolean hasPublicNoArgConstructor();
/**
* Return whether the type has any field that have relevant annotations
@@ -67,6 +72,16 @@ public interface JavaResourceType
*/
boolean hasAnyAnnotatedMethods();
+ /**
+ * Return whether the type has equals() method
+ */
+ boolean hasEqualsMethod();
+
+ /**
+ * Return whether the type has hashCode() method
+ */
+ boolean hasHashCodeMethod();
+
// ********** fields **********
/**
@@ -84,4 +99,5 @@ public interface JavaResourceType
Iterable<JavaResourceMethod> getMethods();
String METHODS_COLLECTION = "methods"; //$NON-NLS-1$
+ JavaResourceMethod getMethod(String propertyName);
}

Back to the top