95 lines
2.3 KiB
Plaintext
95 lines
2.3 KiB
Plaintext
package slangc.model;
|
|
|
|
import slangc.api.Reporter;
|
|
import slangc.parser.Branch;
|
|
|
|
public abstract class MemberModel implements AttributeOwner {
|
|
private TypeModel owner;
|
|
private String name;
|
|
private Branch source;
|
|
private AttributeSet attributes;
|
|
|
|
MemberModel(TypeModel owner, String name, Branch source) {
|
|
this.owner = owner;
|
|
this.name = name;
|
|
this.source = source;
|
|
}
|
|
|
|
public TypeModel getOwner() {
|
|
return owner;
|
|
}
|
|
|
|
public String getName() {
|
|
return name;
|
|
}
|
|
|
|
public boolean matchesName(String[] enabledLanguages, String name) {
|
|
if (getName().equals(name)) {
|
|
return true;
|
|
} else {
|
|
return getAttributes().matchesTranslation(enabledLanguages, name);
|
|
}
|
|
}
|
|
|
|
public Branch getSource() {
|
|
return source;
|
|
}
|
|
|
|
public abstract MemberCategory getCategory();
|
|
|
|
public AttributeSet getAttributes() {
|
|
if (attributes == null) {
|
|
if (source == null) {
|
|
attributes = new AttributeSet(this, null);
|
|
} else {
|
|
attributes = new AttributeSet(this, (Branch) source.getSubnode(0)); // TODO: Consider how this may impact inner classes (attributes will be decoded here and also with the type, may need to combine both sets)
|
|
}
|
|
}
|
|
return attributes;
|
|
}
|
|
|
|
public int getFlags() {
|
|
switch (getCategory()) {
|
|
case MemberCategory.FIELD:
|
|
return getAttributes().getFlags() | Flags.MASK_FIELD;
|
|
case MemberCategory.METHOD:
|
|
return getAttributes().getFlags() | Flags.MASK_METHOD;
|
|
case MemberCategory.INNER_TYPE:
|
|
return getAttributes().getFlags() | Flags.MASK_INNER;
|
|
default:
|
|
throw new Error("Internal error: Bad member category " + getCategory());
|
|
}
|
|
}
|
|
|
|
protected void setAttributes(AttributeSet attributes) {
|
|
this.attributes = attributes;
|
|
}
|
|
|
|
public int resolveTypes() {
|
|
if (attributes == null) {
|
|
getAttributes();
|
|
return 1;
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
public void dump(Reporter reporter, String indent, String incr) {
|
|
reporter.note("DUMP", indent + getCategory() + " '" + getName() + "'" + (isStatic() ? " [static]" : ""));
|
|
}
|
|
|
|
public boolean isStatic() {
|
|
return getAttributes().isStatic();
|
|
}
|
|
|
|
public boolean isPrivate() {
|
|
return getAttributes().isPrivate();
|
|
}
|
|
|
|
public boolean isSynthetic() {
|
|
return source == null;
|
|
}
|
|
|
|
public abstract int resolveExpressions();
|
|
}
|