use of dyvilx.tools.compiler.ast.member.MemberKind in project Dyvil by Dyvil.
the class StatementList method addMethod.
protected void addMethod(MemberStatement memberStatement, MarkerList markers) {
final IClassMember member = memberStatement.member;
final MemberKind memberKind = member.getKind();
if (memberKind != MemberKind.METHOD) {
markers.add(Markers.semantic(member.getPosition(), "statementlist.declaration.invalid", Util.memberNamed(member)));
return;
}
final IMethod method = (IMethod) member;
if (this.methods == null) {
this.methods = new ArrayList<>();
this.methods.add(method);
return;
}
final Name methodName = method.getName();
final int parameterCount = method.getParameters().size();
final String desc = method.getDescriptor();
for (IMethod candidate : this.methods) {
if (// same name
candidate.getName() == methodName && candidate.getParameters().size() == parameterCount && candidate.getDescriptor().equals(desc)) {
markers.add(Markers.semanticError(memberStatement.getPosition(), "method.duplicate", methodName, desc));
}
}
this.methods.add(method);
}
use of dyvilx.tools.compiler.ast.member.MemberKind in project Dyvil by Dyvil.
the class ModifierUtil method checkModifiers.
public static void checkModifiers(IMember member, MarkerList markers) {
final AttributeList attributes = member.getAttributes();
final MemberKind memberKind = member.getKind();
final int defaultAccess = memberKind.getDefaultAccess(member);
StringBuilder errorBuilder = null;
for (Attribute modifier : attributes) {
if (!memberKind.isAttributeAllowed(modifier)) {
if (errorBuilder == null) {
errorBuilder = new StringBuilder();
} else {
errorBuilder.append(", ");
}
modifier.toString(errorBuilder);
}
final int visibility = modifier.flags() & Modifiers.VISIBILITY_MODIFIERS;
if (visibility != 0 && visibility == defaultAccess) {
markers.add(Markers.semantic(member.getPosition(), "modifiers.visibility.default", Util.memberNamed(member), ModifierUtil.accessModifiersToString(visibility)));
}
}
if (errorBuilder != null) {
markers.add(Markers.semanticError(member.getPosition(), "modifiers.illegal", Util.memberNamed(member), errorBuilder.toString()));
}
if (!attributes.hasAnyFlag(Modifiers.VISIBILITY_MODIFIERS)) {
// If there is no explicit or implicit visibility modifier already, add the default one
attributes.addFlag(defaultAccess);
}
}
Aggregations