Skip to content
Permalink
Browse files
refactor FieldNode, LazyFieldNode, PropertyNode and Variable
  • Loading branch information
eric-milles committed May 13, 2022
1 parent ee12bb5 commit 650fbe7750aae638c704c2816cef1d17079bbd65
Showing 4 changed files with 133 additions and 208 deletions.
@@ -23,12 +23,8 @@
import java.lang.reflect.Field;

import static org.objectweb.asm.Opcodes.ACC_ENUM;
import static org.objectweb.asm.Opcodes.ACC_FINAL;
import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
import static org.objectweb.asm.Opcodes.ACC_PROTECTED;
import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
import static org.objectweb.asm.Opcodes.ACC_STATIC;
import static org.objectweb.asm.Opcodes.ACC_VOLATILE;

/**
* Represents a field (member variable)
@@ -65,11 +61,6 @@ public Expression getInitialExpression() {
return initialValueExpression;
}

@Override
public int getModifiers() {
return modifiers;
}

@Override
public String getName() {
return name;
@@ -103,58 +94,20 @@ public boolean isDynamicTyped() {
return dynamicTyped;
}

public void setModifiers(int modifiers) {
this.modifiers = modifiers;
@Override
public int getModifiers() {
return modifiers;
}

/**
* @return true if the field is static
*/
public boolean isStatic() {
return (modifiers & ACC_STATIC) != 0;
public void setModifiers(final int modifiers) {
this.modifiers = modifiers;
}

/**
* @return true if the field is an enum
*/
public boolean isEnum() {
return (modifiers & ACC_ENUM) != 0;
}

/**
* @return true if the field is final
*/
public boolean isFinal() {
return (modifiers & ACC_FINAL) != 0;
}

/**
* @return true if the field is volatile
*/
public boolean isVolatile() {
return (modifiers & ACC_VOLATILE) != 0;
}

/**
* @return true if the field is public
*/
public boolean isPublic() {
return (modifiers & ACC_PUBLIC) != 0;
}

/**
* @return true if the field is protected
*/
public boolean isProtected() {
return (modifiers & ACC_PROTECTED) != 0;
}

/**
* @return true if the field is private
* @since 2.5.0
*/
public boolean isPrivate() {
return (modifiers & ACC_PRIVATE) != 0;
return (getModifiers() & ACC_ENUM) != 0;
}

/**
@@ -182,21 +135,6 @@ public void setInitialValueExpression(Expression initialValueExpression) {
this.initialValueExpression = initialValueExpression;
}

/**
* @deprecated
*/
@Deprecated @Override
public boolean isClosureSharedVariable() {
return false;
}

/**
* @deprecated
*/
@Deprecated @Override
public void setClosureSharedVariable(boolean inClosure) {
}

@Override
public boolean equals(Object obj) {
if (obj != null && obj.getClass().getName().equals("org.codehaus.groovy.ast.decompiled.LazyFieldNode")) {
@@ -23,8 +23,6 @@
import org.codehaus.groovy.ast.stmt.Statement;

import static org.apache.groovy.util.BeanUtils.capitalize;
import static org.objectweb.asm.Opcodes.ACC_PRIVATE;
import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
import static org.objectweb.asm.Opcodes.ACC_STATIC;

/**
@@ -33,44 +31,60 @@
public class PropertyNode extends AnnotatedNode implements Variable {

private FieldNode field;
private int modifiers;

private Statement getterBlock;
private Statement setterBlock;
private String getterName = null;
private String setterName = null;
private int modifiers;
private String getterName;
private String setterName;

public PropertyNode(
String name, int modifiers, ClassNode type, ClassNode owner,
Expression initialValueExpression, Statement getterBlock,
Statement setterBlock) {
public PropertyNode(final String name, final int modifiers, final ClassNode type, final ClassNode owner, final Expression initialValueExpression, final Statement getterBlock, final Statement setterBlock) {
this(new FieldNode(name, modifiers & ACC_STATIC, type, owner, initialValueExpression), modifiers, getterBlock, setterBlock);
}

public PropertyNode(FieldNode field, int modifiers, Statement getterBlock, Statement setterBlock) {
public PropertyNode(final FieldNode field, final int modifiers, final Statement getterBlock, final Statement setterBlock) {
this.field = field;
this.modifiers = modifiers;
this.getterBlock = getterBlock;
this.setterBlock = setterBlock;
}

public Statement getGetterBlock() {
return getterBlock;
public FieldNode getField() {
return field;
}

public void setField(final FieldNode field) {
this.field = field;
}

@Override
public Expression getInitialExpression() {
return field.getInitialExpression();
public int getModifiers() {
return modifiers;
}

public void setModifiers(final int modifiers) {
this.modifiers = modifiers;
}

public Statement getGetterBlock() {
return getterBlock;
}

public void setGetterBlock(Statement getterBlock) {
public void setGetterBlock(final Statement getterBlock) {
this.getterBlock = getterBlock;
}

public void setSetterBlock(Statement setterBlock) {
public Statement getSetterBlock() {
return setterBlock;
}

public void setSetterBlock(final Statement setterBlock) {
this.setterBlock = setterBlock;
}

/**
* @since 4.0.0
*/
public String getGetterName() {
return getterName;
}
@@ -79,6 +93,8 @@ public String getGetterName() {
* If an explicit getterName has been set, return that, otherwise return the default name for the property.
* For a property {@code foo}, the default name is {@code getFoo} except for a boolean property where
* {@code isFoo} is the default if no {@code getFoo} method exists in the declaring class.
*
* @since 4.0.0
*/
public String getGetterNameOrDefault() {
if (getterName != null) return getterName;
@@ -90,73 +106,64 @@ public String getGetterNameOrDefault() {
return defaultName;
}

public void setGetterName(String getterName) {
if (getterName == null || getterName.isEmpty()) {
/**
* @since 4.0.0
*/
public void setGetterName(final String getterName) {
if (getterName == null || getterName.trim().isEmpty()) {
throw new IllegalArgumentException("A non-null non-empty getter name is required");
}
this.getterName = getterName;
this.getterName = getterName.trim();
}

/**
* @since 4.0.0
*/
public String getSetterName() {
return setterName;
}

/**
* @since 4.0.0
*/
public String getSetterNameOrDefault() {
return setterName != null ? setterName : MetaProperty.getSetterName(getName());
}

public void setSetterName(String setterName) {
if (setterName == null || setterName.isEmpty()) {
/**
* @since 4.0.0
*/
public void setSetterName(final String setterName) {
if (setterName == null || setterName.trim().isEmpty()) {
throw new IllegalArgumentException("A non-null non-empty setter name is required");
}
this.setterName = setterName;
this.setterName = setterName.trim();
}

@Override
public int getModifiers() {
return modifiers;
}

public void setModifiers(int modifiers) {
this.modifiers = modifiers;
}
//--------------------------------------------------------------------------

@Override
public String getName() {
return field.getName();
}

public Statement getSetterBlock() {
return setterBlock;
}

@Override
public ClassNode getType() {
return field.getType();
}

public void setType(ClassNode t) {
field.setType(t);
}

public FieldNode getField() {
return field;
}

public void setField(FieldNode fn) {
field = fn;
}

public boolean isPrivate() {
return (modifiers & ACC_PRIVATE) != 0;
@Override
public ClassNode getOriginType() {
return field.getOriginType();
}

public boolean isPublic() {
return (modifiers & ACC_PUBLIC) != 0;
public void setType(final ClassNode t) {
field.setType(t);
}

public boolean isStatic() {
return (modifiers & ACC_STATIC) != 0;
@Override
public Expression getInitialExpression() {
return field.getInitialExpression();
}

@Override
@@ -173,23 +180,4 @@ public boolean isInStaticContext() {
public boolean isDynamicTyped() {
return field.isDynamicTyped();
}

@Override
public boolean isClosureSharedVariable() {
return false;
}

/**
* @deprecated not used anymore, has no effect
*/
@Override
@Deprecated
public void setClosureSharedVariable(boolean inClosure) {
// unused
}

@Override
public ClassNode getOriginType() {
return getType();
}
}

0 comments on commit 650fbe7

Please sign in to comment.