Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbvosburgh2008-05-15 05:29:48 +0000
committerbvosburgh2008-05-15 05:29:48 +0000
commitf0f9657d3b820c12d9658ab360947c939e6c75d9 (patch)
tree6ad923f9582ab8dec642dd1a00a74065e6dcb52f /jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility
parent2315456dc5dbd5e45bc382488eac041d0afb6d8d (diff)
downloadwebtools.dali-f0f9657d3b820c12d9658ab360947c939e6c75d9.tar.gz
webtools.dali-f0f9657d3b820c12d9658ab360947c939e6c75d9.tar.xz
webtools.dali-f0f9657d3b820c12d9658ab360947c939e6c75d9.zip
[225885] fix editing annotations with property access
Diffstat (limited to 'jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility')
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/CommandExecutorProvider.java23
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/MethodSignature.java63
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/SimpleJavaType.java5
-rw-r--r--jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/SimpleMethodSignature.java235
4 files changed, 325 insertions, 1 deletions
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/CommandExecutorProvider.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/CommandExecutorProvider.java
index 03b62531e4..ea1f5c68ea 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/CommandExecutorProvider.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/CommandExecutorProvider.java
@@ -27,4 +27,27 @@ public interface CommandExecutorProvider {
*/
CommandExecutor getCommandExecutor();
+
+ /**
+ * Straightforward implementation of the command executor provider
+ * interface the returns the default command executor.
+ */
+ final class Default implements CommandExecutorProvider {
+ public static final CommandExecutorProvider INSTANCE = new Default();
+ public static CommandExecutorProvider instance() {
+ return INSTANCE;
+ }
+ // ensure single instance
+ private Default() {
+ super();
+ }
+ public CommandExecutor getCommandExecutor() {
+ return CommandExecutor.Default.instance();
+ }
+ @Override
+ public String toString() {
+ return "CommandExecutorProvider.Default";
+ }
+ }
+
}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/MethodSignature.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/MethodSignature.java
new file mode 100644
index 0000000000..08fcbc21d3
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/MethodSignature.java
@@ -0,0 +1,63 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.utility;
+
+import java.io.PrintWriter;
+
+/**
+ * This interface describes a Java method signature; i.e. its "name"
+ * and its "parameter types". The parameter types are referenced by name,
+ * allowing us to reference classes that are not (or cannot be) loaded.
+ *
+ * Provisional API: This interface is part of an interim API that is still
+ * under development and expected to change significantly before reaching
+ * stability. It is available at this early stage to solicit feedback from
+ * pioneering adopters on the understanding that any code that uses this API
+ * will almost certainly be broken (repeatedly) as the API evolves.
+ *
+ * This interface is not intended to be implemented by clients.
+ */
+public interface MethodSignature
+ extends Comparable<MethodSignature>
+{
+
+ /**
+ * Return the method's name.
+ */
+ String getName();
+
+ /**
+ * Return the method's parameter types.
+ */
+ JavaType[] getParameterTypes();
+
+ boolean equals(String otherName, JavaType[] otherParameterTypes);
+
+ boolean equals(MethodSignature other);
+
+ /**
+ * Return a string representation of the method signature:
+ * "foo(int, java.lang.String)"
+ */
+ String getSignature();
+
+ /**
+ * Append a string representation of the method signature:
+ * "foo(int, java.lang.String)"
+ */
+ void appendSignatureTo(StringBuilder sb);
+
+ /**
+ * Print a string representation of the method signature:
+ * "foo(int, java.lang.String)"
+ */
+ void printSignatureOn(PrintWriter pw);
+
+}
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/SimpleJavaType.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/SimpleJavaType.java
index faa3177b91..3ec253f142 100644
--- a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/SimpleJavaType.java
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/SimpleJavaType.java
@@ -144,7 +144,7 @@ public final class SimpleJavaType
@Override
public boolean equals(Object o) {
- return (o instanceof JavaType) ? this.equals((JavaType) o) : false;
+ return (this == o) ? true : (o instanceof JavaType) ? this.equals((JavaType) o) : false;
}
@Override
@@ -217,6 +217,9 @@ public final class SimpleJavaType
return sb.toString();
}
+
+ // ********** cloning **********
+
@Override
public Object clone() {
try {
diff --git a/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/SimpleMethodSignature.java b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/SimpleMethodSignature.java
new file mode 100644
index 0000000000..48c5481c47
--- /dev/null
+++ b/jpa/plugins/org.eclipse.jpt.utility/src/org/eclipse/jpt/utility/internal/SimpleMethodSignature.java
@@ -0,0 +1,235 @@
+/*******************************************************************************
+ * Copyright (c) 2008 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.utility.internal;
+
+import java.io.PrintWriter;
+import java.io.Serializable;
+import java.lang.reflect.Method;
+import java.text.Collator;
+import java.util.Arrays;
+
+import org.eclipse.jpt.utility.JavaType;
+import org.eclipse.jpt.utility.MethodSignature;
+
+/**
+ * Straightforward implementation of the MethodSignature interface.
+ */
+public final class SimpleMethodSignature
+ implements MethodSignature, Cloneable, Serializable
+{
+ private final String name;
+
+ /**
+ * store the parameter types as names, so we can reference classes
+ * that are not loaded
+ */
+ private final JavaType[] parameterTypes;
+
+ private static final long serialVersionUID = 1L;
+
+ public static final JavaType[] EMPTY_PARAMETER_TYPES = new JavaType[0];
+
+
+ // ********** constructors **********
+
+ /**
+ * Construct a method signature with the specified name and
+ * no parameter types.
+ */
+ public SimpleMethodSignature(String name) {
+ this(name, EMPTY_PARAMETER_TYPES);
+ }
+
+ /**
+ * Construct a method signature with the specified name and parameter
+ * types.
+ */
+ public SimpleMethodSignature(String name, JavaType... parameterTypes) {
+ super();
+ if ((name == null) || (name.length() == 0)) {
+ throw new IllegalArgumentException("The name is required.");
+ }
+ if (parameterTypes == null) {
+ throw new IllegalArgumentException("The parameter types are required.");
+ }
+ checkParameterTypes(parameterTypes);
+ this.name = name;
+ this.parameterTypes = parameterTypes;
+ }
+
+ private static void checkParameterTypes(JavaType[] parameterTypes) {
+ for (int i = 0; i < parameterTypes.length; i++) {
+ if (parameterTypes[i] == null) {
+ throw new IllegalArgumentException("Missing parameter type: " + i);
+ }
+ if (parameterTypes[i].getElementTypeName().equals(void.class.getName())) {
+ throw new IllegalArgumentException("A parameter type of 'void' is not allowed: " + i);
+ }
+ }
+ }
+
+ /**
+ * Construct a method signature with the specified name and parameter
+ * types.
+ */
+ public SimpleMethodSignature(String name, String... parameterTypeNames) {
+ this(name, buildParameterTypes(parameterTypeNames));
+ }
+
+ private static JavaType[] buildParameterTypes(String[] parameterTypeNames) {
+ if (parameterTypeNames == null) {
+ throw new IllegalArgumentException("The parameter type names are required.");
+ }
+ JavaType[] parameterTypes = new JavaType[parameterTypeNames.length];
+ for (int i = 0; i < parameterTypeNames.length; i++) {
+ if (parameterTypeNames[i] == null) {
+ throw new IllegalArgumentException("Missing parameter type name: " + i);
+ }
+ parameterTypes[i] = new SimpleJavaType(parameterTypeNames[i]);
+ }
+ return parameterTypes;
+ }
+
+ /**
+ * Construct a method signature with the specified name and parameter
+ * types.
+ */
+ public SimpleMethodSignature(String name, Class<?>... parameterJavaClasses) {
+ this(name, buildParameterTypeNames(parameterJavaClasses));
+ }
+
+ private static String[] buildParameterTypeNames(Class<?>[] parameterJavaClasses) {
+ if (parameterJavaClasses == null) {
+ throw new IllegalArgumentException("The parameter Java classes are required.");
+ }
+ String[] parameterTypeNames = new String[parameterJavaClasses.length];
+ for (int i = 0; i < parameterJavaClasses.length; i++) {
+ if (parameterJavaClasses[i] == null) {
+ throw new IllegalArgumentException("Missing parameter Java class: " + i);
+ }
+ parameterTypeNames[i] = parameterJavaClasses[i].getName();
+ }
+ return parameterTypeNames;
+ }
+
+ /**
+ * Construct a method signature for the specified Java method.
+ */
+ public SimpleMethodSignature(Method method) {
+ this(method.getName(), method.getParameterTypes());
+ }
+
+
+ // ********** accessors **********
+
+ public String getName() {
+ return this.name;
+ }
+
+ public JavaType[] getParameterTypes() {
+ return this.parameterTypes;
+ }
+
+
+ // ********** comparison **********
+
+ public boolean equals(String otherName, JavaType[] otherParameterTypes) {
+ return this.name.equals(otherName)
+ && Arrays.equals(this.parameterTypes, otherParameterTypes);
+ }
+
+ public boolean equals(MethodSignature other) {
+ return this.equals(other.getName(), other.getParameterTypes());
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ return (this == o) ? true : (o instanceof MethodSignature) ? this.equals((MethodSignature) o) : false;
+ }
+
+ @Override
+ public int hashCode() {
+ return this.name.hashCode() ^ Arrays.hashCode(this.parameterTypes);
+ }
+
+ public int compareTo(MethodSignature ms) {
+ int compare = Collator.getInstance().compare(this.name, ms.getName());
+ return (compare != 0) ? compare : this.compareParameterTypes(ms.getParameterTypes());
+ }
+
+ private int compareParameterTypes(JavaType[] otherParameterTypes) {
+ int len1 = this.parameterTypes.length;
+ int len2 = otherParameterTypes.length;
+ int min = Math.min(len1, len2);
+ for (int i = 0; i < min; i++) {
+ int compare = this.parameterTypes[i].compareTo(otherParameterTypes[i]);
+ if (compare != 0) {
+ return compare;
+ }
+ }
+ return (len1 == len2) ? 0 : (len1 < len2) ? -1 : 1;
+ }
+
+
+ // ********** printing and displaying **********
+
+ public String getSignature() {
+ StringBuilder sb = new StringBuilder(200);
+ this.appendSignatureTo(sb);
+ return sb.toString();
+ }
+
+ public void appendSignatureTo(StringBuilder sb) {
+ sb.append(this.name);
+ sb.append('(');
+ for (int i = 0; i < this.parameterTypes.length; i++) {
+ if (i != 0) {
+ sb.append(", ");
+ }
+ this.parameterTypes[i].appendDeclarationTo(sb);
+ }
+ sb.append(')');
+ }
+
+ public void printSignatureOn(PrintWriter pw) {
+ pw.print(this.name);
+ pw.print('(');
+ for (int i = 0; i < this.parameterTypes.length; i++) {
+ if (i != 0) {
+ pw.print(", ");
+ }
+ this.parameterTypes[i].printDeclarationOn(pw);
+ }
+ pw.print(')');
+ }
+
+ @Override
+ public String toString() {
+ StringBuilder sb = new StringBuilder(200);
+ sb.append(ClassTools.shortClassNameForObject(this));
+ sb.append('(');
+ this.appendSignatureTo(sb);
+ sb.append(')');
+ return sb.toString();
+ }
+
+
+ // ********** cloning **********
+
+ @Override
+ public Object clone() {
+ try {
+ return super.clone();
+ } catch (CloneNotSupportedException ex) {
+ throw new InternalError();
+ }
+ }
+
+}

Back to the top