Skip to content

Commit

Permalink
Further adoption for #58
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Dec 13, 2017
1 parent 7782312 commit 0c16e7e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 23 deletions.
30 changes: 16 additions & 14 deletions src/main/java/com/helger/jcodemodel/JDirectClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Objects;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import com.helger.jcodemodel.util.JCHashCodeGenerator;

/**
* A special {@link AbstractJClass} that represents an unknown class (except its
* name.)
Expand Down Expand Up @@ -158,20 +159,21 @@ protected JDirectClass createInnerClass (final int nMods, final EClassType eClas
}

@Override
public boolean equals(Object obj) {
if (this == obj) {
public boolean equals (final Object o)
{
if (o == this)
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final JDirectClass other = (JDirectClass) obj;
if (!Objects.equals(this.m_sFullName, other.m_sFullName)) {

if (o == null || !getClass ().equals (o.getClass ()))
return false;
}
return true;

final JDirectClass rhs = (JDirectClass) o;
return m_sFullName.equals (rhs.m_sFullName);
}

@Override
public int hashCode ()
{
return JCHashCodeGenerator.getHashCode (this, m_sFullName);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,18 +40,17 @@
*/
package com.helger.jcodemodel.supplementary.issues;

import com.helger.jcodemodel.AbstractJType;
import static org.junit.Assert.assertSame;

import org.junit.Test;

import static org.junit.Assert.assertSame;

import com.helger.jcodemodel.AbstractJType;
import com.helger.jcodemodel.JCodeModel;
import com.helger.jcodemodel.JDefinedClass;
import com.helger.jcodemodel.JMethod;

/**
* Test for https://github.com/phax/jcodemodel/issues/57
* Test for https://github.com/phax/jcodemodel/issues/58
*
* @author Flavio Baronti
*/
Expand All @@ -60,10 +59,10 @@ public final class Issue58FuncTest
@Test
public void testIssue () throws Exception
{
JCodeModel generator = new JCodeModel ();
JDefinedClass aClass = generator._class("test.Test");
JMethod aMethod = aClass.method(0, generator.VOID, "name");
aMethod.param(generator.ref("test.UnknownClass"), "p");
assertSame(aMethod, aClass.getMethod("name", new AbstractJType[] { generator.ref("test.UnknownClass") }));
final JCodeModel generator = new JCodeModel ();
final JDefinedClass aClass = generator._class ("test.Test");
final JMethod aMethod = aClass.method (0, generator.VOID, "name");
aMethod.param (generator.ref ("test.UnknownClass"), "p");
assertSame (aMethod, aClass.getMethod ("name", new AbstractJType [] { generator.ref ("test.UnknownClass") }));
}
}

0 comments on commit 0c16e7e

Please sign in to comment.