use of dyvilx.tools.compiler.ast.classes.IClass in project Dyvil by Dyvil.
the class Annotation method write.
public void write(AnnotationVisitor writer) {
final IClass iclass = this.type.getTheClass();
final ParameterList parameterList = iclass.getParameters();
for (int i = 0, count = parameterList.size(); i < count; i++) {
final IParameter parameter = parameterList.get(i);
final IValue argument = this.arguments.get(parameter);
if (argument != null) {
argument.writeAnnotationValue(writer, parameter.getName().qualified);
}
}
writer.visitEnd();
}
use of dyvilx.tools.compiler.ast.classes.IClass in project Dyvil by Dyvil.
the class CodeAnnotation method check.
@Override
public void check(MarkerList markers, IContext context, ElementType target) {
super.check(markers, context, target);
if (this.type == null || !this.type.isResolved()) {
return;
}
final IClass theClass = this.type.getTheClass();
if (theClass == null) {
return;
}
if (!theClass.isAnnotation()) {
markers.add(Markers.semanticError(this.position, "annotation.type", this.type.getName()));
return;
}
if (target == null) {
return;
}
final IClassMetadata metadata = theClass.getMetadata();
if (!metadata.isTarget(target)) {
final Marker error = Markers.semanticError(this.position, "annotation.target", this.type.getName());
error.addInfo(Markers.getSemantic("annotation.target.element", target));
error.addInfo(Markers.getSemantic("annotation.target.allowed", metadata.getTargets()));
markers.add(error);
}
}
use of dyvilx.tools.compiler.ast.classes.IClass in project Dyvil by Dyvil.
the class CodeMethod method filterOverride.
private boolean filterOverride(IMethod candidate, MarkerList markers, ITypeContext typeContext) {
final String candidateInternalName = candidate.getInternalName();
final boolean sameName = this.name == candidate.getName();
final boolean sameInternalName = this.getInternalName().equals(candidateInternalName);
if (// same name but different internal name
sameName && !sameInternalName) {
if (this.name.qualified.equals(this.internalName)) // no AutoMangled or BytecodeName annotation, otherwise the user probably knows what they are doing and
// doesn't need a warning
{
final Marker marker = Markers.semantic(this.position, "method.override.mangled_mismatch", this.name, candidateInternalName);
marker.addInfo(Markers.getSemantic("method.override.mangled_mismatch.info", candidateInternalName));
markers.add(marker);
}
return true;
}
if (!sameName && sameInternalName) {
final Marker marker = Markers.semanticError(this.position, "method.override.mangled_clash", this.name, candidate.getName(), candidateInternalName);
marker.addInfo(Markers.getSemantic("method.override.mangled_clash.info"));
// hard error so it doesn't matter if we remove or not - bytecode will never be generated
return true;
}
// sameName && sameInternalName should be true
final IClass enclosingClass = candidate.getEnclosingClass();
boolean errors = true;
for (IMethod method : this.overrideMethods) {
if (method != candidate && method.getEnclosingClass() == enclosingClass) {
// If this method overrides two methods from the same class, we do not produce any parameter label errors
errors = false;
}
}
final ParameterList params = candidate.getParameters();
for (int i = 0, count = params.size(); i < count; i++) {
final IParameter thisParam = this.parameters.get(i);
final Name thisName = thisParam.getLabel();
final Name otherName = params.get(i).getLabel();
if (thisName == otherName || thisName == null || otherName == null) {
// Parameter labels match
continue;
}
if (errors) {
final Marker marker = Markers.semantic(thisParam.getPosition(), "method.override.parameter_label", i + 1, thisName, otherName);
addOverrideInfo(typeContext, candidate, marker);
markers.add(marker);
}
// This method does not properly override the candidate
return true;
}
return false;
}
use of dyvilx.tools.compiler.ast.classes.IClass in project Dyvil by Dyvil.
the class CodeMethod method resolveTypes.
@Override
public void resolveTypes(MarkerList markers, IContext context) {
if (this.thisType != null) {
// Resolve the explicit receiver type, but do not expose type parameters of this method
this.thisType = this.thisType.resolveType(markers, context);
// Check the self type for compatibility
final IType thisType = this.thisType;
final IClass thisClass = thisType.getTheClass();
if (!this.isStatic() && thisClass != null && thisClass != this.enclosingClass) {
final Marker marker = Markers.semanticError(thisType.getPosition(), "method.this_type.incompatible", this.getName());
marker.addInfo(Markers.getSemantic("method.this_type", thisType));
marker.addInfo(Markers.getSemantic("method.enclosing_class", this.enclosingClass.getFullName()));
markers.add(marker);
}
} else {
this.thisType = this.enclosingClass.getThisType();
}
context = context.push(this);
if (this.typeParameters != null) {
this.typeParameters.resolveTypes(markers, context);
}
// Return type has to be resolved after type parameters
super.resolveTypes(markers, context);
this.parameters.resolveTypes(markers, context);
if (this.parameters.isLastVariadic()) {
this.attributes.addFlag(Modifiers.ACC_VARARGS);
}
if (this.exceptions != null) {
this.exceptions.resolveTypes(markers, context);
}
if (this.value != null) {
this.value.resolveTypes(markers, context);
}
context.pop();
}
use of dyvilx.tools.compiler.ast.classes.IClass in project Dyvil by Dyvil.
the class IParameter method writeGetDefaultValue.
default void writeGetDefaultValue(MethodWriter writer) {
final ICallableMember method = this.getMethod();
final IClass enclosingClass = this.getEnclosingClass();
final String name = (method == null ? DEFAULT_PREFIX_INIT : method.getInternalName() + DEFAULT_PREFIX) + this.getInternalName();
final String desc = "()" + this.getDescriptor();
writer.visitMethodInsn(Opcodes.INVOKESTATIC, enclosingClass.getInternalName(), name, desc, enclosingClass.isInterface());
}
Aggregations