[jboss-cvs] JBossAS SVN: r90103 - in projects/jboss-mdr/branches/Branch_2_0/src: main/java/org/jboss/metadata/plugins/signature and 3 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu Jun 11 13:15:12 EDT 2009
Author: kabir.khan at jboss.com
Date: 2009-06-11 13:15:12 -0400 (Thu, 11 Jun 2009)
New Revision: 90103
Added:
projects/jboss-mdr/branches/Branch_2_0/src/main/java/org/jboss/metadata/plugins/signature/
projects/jboss-mdr/branches/Branch_2_0/src/main/java/org/jboss/metadata/plugins/signature/SignatureNameUtil.java
projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/signature/
projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/signature/SignatureEqualsUnitTestCase.java
Removed:
projects/jboss-mdr/branches/Branch_2_0/src/main/java/org/jboss/metadata/plugins/signature/SignatureNameUtil.java
projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/signature/SignatureEqualsUnitTestCase.java
Modified:
projects/jboss-mdr/branches/Branch_2_0/src/main/java/org/jboss/metadata/spi/signature/DeclaredMethodSignature.java
projects/jboss-mdr/branches/Branch_2_0/src/main/java/org/jboss/metadata/spi/signature/Signature.java
Log:
[JBMDR-57] Make DeclaredMethodSignature.equals() less strict
Copied: projects/jboss-mdr/branches/Branch_2_0/src/main/java/org/jboss/metadata/plugins/signature (from rev 90102, projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/signature)
Deleted: projects/jboss-mdr/branches/Branch_2_0/src/main/java/org/jboss/metadata/plugins/signature/SignatureNameUtil.java
===================================================================
--- projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/signature/SignatureNameUtil.java 2009-06-11 17:11:54 UTC (rev 90102)
+++ projects/jboss-mdr/branches/Branch_2_0/src/main/java/org/jboss/metadata/plugins/signature/SignatureNameUtil.java 2009-06-11 17:15:12 UTC (rev 90103)
@@ -1,41 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source.
-* Copyright 2006, Red Hat Middleware LLC, and individual contributors
-* as indicated by the @author tags. See the copyright.txt file in the
-* distribution for a full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.metadata.plugins.signature;
-
-import java.util.Arrays;
-
-/**
- *
- * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
- * @version $Revision: 1.1 $
- */
-public class SignatureNameUtil
-{
- public static void signatureToString(StringBuilder builder, String name, String[] parameters)
- {
- if (name != null)
- builder.append(name);
- if (parameters != null)
- builder.append(Arrays.asList(parameters));
- }
-
-}
Copied: projects/jboss-mdr/branches/Branch_2_0/src/main/java/org/jboss/metadata/plugins/signature/SignatureNameUtil.java (from rev 90102, projects/jboss-mdr/trunk/src/main/java/org/jboss/metadata/plugins/signature/SignatureNameUtil.java)
===================================================================
--- projects/jboss-mdr/branches/Branch_2_0/src/main/java/org/jboss/metadata/plugins/signature/SignatureNameUtil.java (rev 0)
+++ projects/jboss-mdr/branches/Branch_2_0/src/main/java/org/jboss/metadata/plugins/signature/SignatureNameUtil.java 2009-06-11 17:15:12 UTC (rev 90103)
@@ -0,0 +1,41 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.metadata.plugins.signature;
+
+import java.util.Arrays;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class SignatureNameUtil
+{
+ public static void signatureToString(StringBuilder builder, String name, String[] parameters)
+ {
+ if (name != null)
+ builder.append(name);
+ if (parameters != null)
+ builder.append(Arrays.asList(parameters));
+ }
+
+}
Modified: projects/jboss-mdr/branches/Branch_2_0/src/main/java/org/jboss/metadata/spi/signature/DeclaredMethodSignature.java
===================================================================
--- projects/jboss-mdr/branches/Branch_2_0/src/main/java/org/jboss/metadata/spi/signature/DeclaredMethodSignature.java 2009-06-11 17:11:54 UTC (rev 90102)
+++ projects/jboss-mdr/branches/Branch_2_0/src/main/java/org/jboss/metadata/spi/signature/DeclaredMethodSignature.java 2009-06-11 17:15:12 UTC (rev 90103)
@@ -23,6 +23,7 @@
import java.lang.reflect.Method;
+import org.jboss.metadata.plugins.signature.SignatureNameUtil;
import org.jboss.reflect.spi.MethodInfo;
/**
@@ -38,6 +39,11 @@
/** The method */
private Method method;
+
+ /**
+ * The cached hash code
+ */
+ int cachedHashCode = Integer.MIN_VALUE;
/**
* Create a new Signature.
@@ -121,14 +127,31 @@
{
if (obj == this)
return true;
- if (obj == null || obj instanceof DeclaredMethodSignature == false || super.equals(obj) == false)
+ if (obj == null || super.equals(obj) == false)
return false;
- DeclaredMethodSignature other = (DeclaredMethodSignature) obj;
- return getDeclaringClass().equals(other.getDeclaringClass());
+ if (obj instanceof DeclaredMethodSignature)
+ {
+ DeclaredMethodSignature other = (DeclaredMethodSignature) obj;
+ return getDeclaringClass().equals(other.getDeclaringClass());
+ }
+ return true;
}
@Override
+ public int hashCode()
+ {
+ //Only take the short version of the name into consideration when creating the hashCode
+ if (cachedHashCode == Integer.MIN_VALUE)
+ {
+ StringBuilder builder = new StringBuilder();
+ SignatureNameUtil.signatureToString(builder, getName(), getParameters());
+ cachedHashCode = builder.toString().hashCode();
+ }
+ return cachedHashCode;
+ }
+
+ @Override
protected void internalToString(StringBuilder builder)
{
super.internalToString(builder);
Modified: projects/jboss-mdr/branches/Branch_2_0/src/main/java/org/jboss/metadata/spi/signature/Signature.java
===================================================================
--- projects/jboss-mdr/branches/Branch_2_0/src/main/java/org/jboss/metadata/spi/signature/Signature.java 2009-06-11 17:11:54 UTC (rev 90102)
+++ projects/jboss-mdr/branches/Branch_2_0/src/main/java/org/jboss/metadata/spi/signature/Signature.java 2009-06-11 17:15:12 UTC (rev 90103)
@@ -28,6 +28,7 @@
import java.lang.reflect.Method;
import java.util.Arrays;
+import org.jboss.metadata.plugins.signature.SignatureNameUtil;
import org.jboss.reflect.spi.ConstructorInfo;
import org.jboss.reflect.spi.FieldInfo;
import org.jboss.reflect.spi.MemberInfo;
@@ -438,10 +439,6 @@
*/
protected void internalToString(StringBuilder builder)
{
- if (name != null)
- builder.append(getName());
- String[] parameters = getParameters();
- if (parameters != null)
- builder.append(Arrays.asList(parameters));
+ SignatureNameUtil.signatureToString(builder, name, getParameters());
}
}
Copied: projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/signature (from rev 90102, projects/jboss-mdr/trunk/src/test/java/org/jboss/test/signature)
Deleted: projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/signature/SignatureEqualsUnitTestCase.java
===================================================================
--- projects/jboss-mdr/trunk/src/test/java/org/jboss/test/signature/SignatureEqualsUnitTestCase.java 2009-06-11 17:11:54 UTC (rev 90102)
+++ projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/signature/SignatureEqualsUnitTestCase.java 2009-06-11 17:15:12 UTC (rev 90103)
@@ -1,80 +0,0 @@
-/*
-* JBoss, Home of Professional Open Source.
-* Copyright 2006, Red Hat Middleware LLC, and individual contributors
-* as indicated by the @author tags. See the copyright.txt file in the
-* distribution for a full listing of individual contributors.
-*
-* This is free software; you can redistribute it and/or modify it
-* under the terms of the GNU Lesser General Public License as
-* published by the Free Software Foundation; either version 2.1 of
-* the License, or (at your option) any later version.
-*
-* This software is distributed in the hope that it will be useful,
-* but WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* Lesser General Public License for more details.
-*
-* You should have received a copy of the GNU Lesser General Public
-* License along with this software; if not, write to the Free
-* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
-* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-*/
-package org.jboss.test.signature;
-
-import java.lang.reflect.Method;
-
-import org.jboss.metadata.spi.signature.DeclaredMethodSignature;
-import org.jboss.metadata.spi.signature.MethodSignature;
-
-import junit.framework.TestCase;
-
-/**
- *
- * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
- * @version $Revision: 1.1 $
- */
-public class SignatureEqualsUnitTestCase extends TestCase
-{
- public void testEqualsMethodSignature() throws Exception
- {
- MethodSignature sig1 = getMethodSignature();
- MethodSignature sig2 = getMethodSignature();
- assertEquals(sig1.hashCode(), sig2.hashCode());
- assertTrue(sig1.equals(sig2));
- assertTrue(sig2.equals(sig1));
- }
-
- public void testEqualsDeclaredMethodSignature() throws Exception
- {
- DeclaredMethodSignature sig1 = getDeclaredMethodSignature();
- DeclaredMethodSignature sig2 = getDeclaredMethodSignature();
- assertEquals(sig1.hashCode(), sig2.hashCode());
- assertTrue(sig1.equals(sig2));
- assertTrue(sig2.equals(sig1));
- }
-
- public void testEqualsMethodSignatureAndDeclaredMethodSignature() throws Exception
- {
- MethodSignature ms = getMethodSignature();
- DeclaredMethodSignature ds = getDeclaredMethodSignature();
- assertEquals(ms.hashCode(), ds.hashCode());
- assertTrue(ms.equals(ds));
- assertTrue(ds.equals(ms));
- }
-
- private MethodSignature getMethodSignature() throws Exception
- {
- return new MethodSignature(getMethod());
- }
-
- private DeclaredMethodSignature getDeclaredMethodSignature() throws Exception
- {
- return new DeclaredMethodSignature(getMethod());
- }
-
- private Method getMethod() throws Exception
- {
- Class<?> clazz = this.getClass();
- return clazz.getDeclaredMethod("getMethod");
- }
-}
Copied: projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/signature/SignatureEqualsUnitTestCase.java (from rev 90102, projects/jboss-mdr/trunk/src/test/java/org/jboss/test/signature/SignatureEqualsUnitTestCase.java)
===================================================================
--- projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/signature/SignatureEqualsUnitTestCase.java (rev 0)
+++ projects/jboss-mdr/branches/Branch_2_0/src/test/java/org/jboss/test/signature/SignatureEqualsUnitTestCase.java 2009-06-11 17:15:12 UTC (rev 90103)
@@ -0,0 +1,80 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.signature;
+
+import java.lang.reflect.Method;
+
+import org.jboss.metadata.spi.signature.DeclaredMethodSignature;
+import org.jboss.metadata.spi.signature.MethodSignature;
+
+import junit.framework.TestCase;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class SignatureEqualsUnitTestCase extends TestCase
+{
+ public void testEqualsMethodSignature() throws Exception
+ {
+ MethodSignature sig1 = getMethodSignature();
+ MethodSignature sig2 = getMethodSignature();
+ assertEquals(sig1.hashCode(), sig2.hashCode());
+ assertTrue(sig1.equals(sig2));
+ assertTrue(sig2.equals(sig1));
+ }
+
+ public void testEqualsDeclaredMethodSignature() throws Exception
+ {
+ DeclaredMethodSignature sig1 = getDeclaredMethodSignature();
+ DeclaredMethodSignature sig2 = getDeclaredMethodSignature();
+ assertEquals(sig1.hashCode(), sig2.hashCode());
+ assertTrue(sig1.equals(sig2));
+ assertTrue(sig2.equals(sig1));
+ }
+
+ public void testEqualsMethodSignatureAndDeclaredMethodSignature() throws Exception
+ {
+ MethodSignature ms = getMethodSignature();
+ DeclaredMethodSignature ds = getDeclaredMethodSignature();
+ assertEquals(ms.hashCode(), ds.hashCode());
+ assertTrue(ms.equals(ds));
+ assertTrue(ds.equals(ms));
+ }
+
+ private MethodSignature getMethodSignature() throws Exception
+ {
+ return new MethodSignature(getMethod());
+ }
+
+ private DeclaredMethodSignature getDeclaredMethodSignature() throws Exception
+ {
+ return new DeclaredMethodSignature(getMethod());
+ }
+
+ private Method getMethod() throws Exception
+ {
+ Class<?> clazz = this.getClass();
+ return clazz.getDeclaredMethod("getMethod");
+ }
+}
More information about the jboss-cvs-commits
mailing list