-
Notifications
You must be signed in to change notification settings - Fork 54
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
f745121
commit c0b41d7
Showing
1 changed file
with
85 additions
and
86 deletions.
There are no files selected for viewing
171 changes: 85 additions & 86 deletions
171
...src/main/java/org/jvnet/jaxb2_commons/xjc/outline/artificial/ConstantPropertyOutline.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 |
---|---|---|
@@ -1,86 +1,85 @@ | ||
package org.jvnet.jaxb2_commons.xjc.outline.artificial; | ||
|
||
import org.apache.commons.lang3.Validate; | ||
import org.jvnet.jaxb2_commons.xjc.outline.MClassOutline; | ||
import org.jvnet.jaxb2_commons.xjc.outline.MPropertyAccessor; | ||
import org.jvnet.jaxb2_commons.xml.bind.model.MPropertyInfo; | ||
|
||
import com.sun.codemodel.JBlock; | ||
import com.sun.codemodel.JExpr; | ||
import com.sun.codemodel.JExpression; | ||
import com.sun.codemodel.JFieldVar; | ||
import com.sun.codemodel.JMod; | ||
import com.sun.codemodel.JType; | ||
import com.sun.codemodel.JVar; | ||
import com.sun.tools.xjc.model.nav.NClass; | ||
import com.sun.tools.xjc.model.nav.NType; | ||
import com.sun.tools.xjc.outline.Outline; | ||
|
||
public abstract class ConstantPropertyOutline extends AbstractPropertyOutline { | ||
|
||
protected final JExpression value; | ||
|
||
protected final JFieldVar field; | ||
|
||
public ConstantPropertyOutline(Outline outline, MClassOutline classOutline, | ||
MPropertyInfo<NType, NClass> target, final JExpression value) { | ||
super(outline, classOutline, target); | ||
Validate.notNull(value); | ||
this.value = value; | ||
this.field = generateField(); | ||
} | ||
|
||
protected JExpression createValue() { | ||
return value; | ||
} | ||
|
||
protected JFieldVar generateField() { | ||
// generate the constant | ||
JExpression value = createValue(); | ||
|
||
JFieldVar field = referenceClass.field(JMod.PUBLIC | JMod.STATIC | ||
| JMod.FINAL, type, propertyInfo.getPublicName(), value); | ||
|
||
annotate(field); | ||
|
||
return field; | ||
} | ||
|
||
public MPropertyAccessor createPropertyAccessor(JExpression target) { | ||
return new PropertyAccessor(target); | ||
} | ||
|
||
public class PropertyAccessor extends | ||
AbstractPropertyOutline.PropertyAccessor { | ||
|
||
public PropertyAccessor(JExpression target) { | ||
super(target); | ||
} | ||
|
||
@Override | ||
public boolean isConstant() { | ||
return true; | ||
} | ||
|
||
public void unset(JBlock body) { | ||
} | ||
|
||
public void set(JBlock block, String uniqueName, JExpression value) { | ||
} | ||
|
||
@Override | ||
public boolean isVirtual() { | ||
return false; | ||
} | ||
|
||
public JExpression isSet() { | ||
return JExpr.TRUE; | ||
} | ||
|
||
public void get(JBlock block, JVar variable) { | ||
block.assign(variable, ConstantPropertyOutline.this.referenceClass | ||
.staticRef(ConstantPropertyOutline.this.field)); | ||
} | ||
|
||
} | ||
} | ||
package org.jvnet.jaxb2_commons.xjc.outline.artificial; | ||
|
||
import org.apache.commons.lang3.Validate; | ||
import org.jvnet.jaxb2_commons.xjc.outline.MClassOutline; | ||
import org.jvnet.jaxb2_commons.xjc.outline.MPropertyAccessor; | ||
import org.jvnet.jaxb2_commons.xml.bind.model.MPropertyInfo; | ||
|
||
import com.sun.codemodel.JBlock; | ||
import com.sun.codemodel.JExpr; | ||
import com.sun.codemodel.JExpression; | ||
import com.sun.codemodel.JFieldVar; | ||
import com.sun.codemodel.JMod; | ||
import com.sun.codemodel.JVar; | ||
import com.sun.tools.xjc.model.nav.NClass; | ||
import com.sun.tools.xjc.model.nav.NType; | ||
import com.sun.tools.xjc.outline.Outline; | ||
|
||
public abstract class ConstantPropertyOutline extends AbstractPropertyOutline { | ||
|
||
protected final JExpression value; | ||
|
||
protected final JFieldVar field; | ||
|
||
public ConstantPropertyOutline(Outline outline, MClassOutline classOutline, | ||
MPropertyInfo<NType, NClass> target, final JExpression value) { | ||
super(outline, classOutline, target); | ||
Validate.notNull(value); | ||
this.value = value; | ||
this.field = generateField(); | ||
} | ||
|
||
protected JExpression createValue() { | ||
return value; | ||
} | ||
|
||
protected JFieldVar generateField() { | ||
// generate the constant | ||
JExpression value = createValue(); | ||
|
||
JFieldVar field = referenceClass.field(JMod.PUBLIC | JMod.STATIC | ||
| JMod.FINAL, type, propertyInfo.getPublicName(), value); | ||
|
||
annotate(field); | ||
|
||
return field; | ||
} | ||
|
||
public MPropertyAccessor createPropertyAccessor(JExpression target) { | ||
return new PropertyAccessor(target); | ||
} | ||
|
||
public class PropertyAccessor extends | ||
AbstractPropertyOutline.PropertyAccessor { | ||
|
||
public PropertyAccessor(JExpression target) { | ||
super(target); | ||
} | ||
|
||
@Override | ||
public boolean isConstant() { | ||
return true; | ||
} | ||
|
||
public void unset(JBlock body) { | ||
} | ||
|
||
public void set(JBlock block, String uniqueName, JExpression value) { | ||
} | ||
|
||
@Override | ||
public boolean isVirtual() { | ||
return false; | ||
} | ||
|
||
public JExpression isSet() { | ||
return JExpr.TRUE; | ||
} | ||
|
||
public void get(JBlock block, JVar variable) { | ||
block.assign(variable, ConstantPropertyOutline.this.referenceClass | ||
.staticRef(ConstantPropertyOutline.this.field)); | ||
} | ||
|
||
} | ||
} |