forked from highsource/jaxb-tools
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c2aad7f
commit 24a2913
Showing
21 changed files
with
565 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
...n/java/org/jvnet/jaxb2_commons/plugin/simpleequals/generator/BaseEqualsCodeGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package org.jvnet.jaxb2_commons.plugin.simpleequals.generator; | ||
|
||
import org.apache.commons.lang3.Validate; | ||
|
||
import com.sun.codemodel.JCodeModel; | ||
|
||
public abstract class BaseEqualsCodeGenerator implements | ||
EqualsCodeGenerator { | ||
|
||
private final JCodeModel codeModel; | ||
|
||
public BaseEqualsCodeGenerator(JCodeModel codeModel) { | ||
this.codeModel = Validate.notNull(codeModel); | ||
} | ||
|
||
public JCodeModel getCodeModel() { | ||
return codeModel; | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
.../java/org/jvnet/jaxb2_commons/plugin/simpleequals/generator/BasicEqualsCodeGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package org.jvnet.jaxb2_commons.plugin.simpleequals.generator; | ||
|
||
import org.apache.commons.lang3.Validate; | ||
|
||
import com.sun.codemodel.JBlock; | ||
import com.sun.codemodel.JCodeModel; | ||
import com.sun.codemodel.JExpr; | ||
import com.sun.codemodel.JExpression; | ||
import com.sun.codemodel.JOp; | ||
import com.sun.codemodel.JType; | ||
|
||
public abstract class BasicEqualsCodeGenerator implements | ||
EqualsCodeGenerator { | ||
|
||
private final JCodeModel codeModel; | ||
|
||
public BasicEqualsCodeGenerator(JCodeModel codeModel) { | ||
this.codeModel = Validate.notNull(codeModel); | ||
} | ||
|
||
@Override | ||
public void generate(JBlock block, JType type, JExpression left, | ||
JExpression right) { | ||
// if (!(left ==null ? right == null : <comparison>)) | ||
// { return false; } | ||
final JExpression comparison = comparison(left, right); | ||
block._if( | ||
JOp.cond(left.eq(JExpr._null()), right.eq(JExpr._null()), | ||
comparison).not())._then()._return(JExpr.FALSE); | ||
} | ||
|
||
public abstract JExpression comparison(JExpression left, | ||
JExpression right); | ||
} |
17 changes: 17 additions & 0 deletions
17
...java/org/jvnet/jaxb2_commons/plugin/simpleequals/generator/DoubleEqualsCodeGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.jvnet.jaxb2_commons.plugin.simpleequals.generator; | ||
|
||
import com.sun.codemodel.JCodeModel; | ||
import com.sun.codemodel.JExpression; | ||
|
||
public class DoubleEqualsCodeGenerator extends | ||
PrimitiveEqualsCodeGenerator { | ||
public DoubleEqualsCodeGenerator(JCodeModel codeModel) { | ||
super(codeModel); | ||
} | ||
|
||
@Override | ||
public JExpression transform(JExpression expression) { | ||
return getCodeModel().ref(Double.class) | ||
.staticInvoke("doubleToLongBits").arg(expression); | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
.../main/java/org/jvnet/jaxb2_commons/plugin/simpleequals/generator/EqualsCodeGenerator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.jvnet.jaxb2_commons.plugin.simpleequals.generator; | ||
|
||
import org.jvnet.jaxb2_commons.codemodel.generator.CodeGenerator; | ||
|
||
import com.sun.codemodel.JBlock; | ||
import com.sun.codemodel.JExpression; | ||
import com.sun.codemodel.JType; | ||
|
||
public interface EqualsCodeGenerator extends CodeGenerator { | ||
|
||
public void generate(JBlock block, JType type, JExpression left, | ||
JExpression right); | ||
} |
Oops, something went wrong.