use of com.oracle.truffle.object.dsl.processor.model.PropertyBuilder in project graal by oracle.
the class LayoutParser method parseGetter.
private void parseGetter(ExecutableElement methodElement) {
if (methodElement.getParameters().size() != 1) {
processor.reportError(methodElement, "@Layout getter methods must have just one parameter");
}
final VariableElement parameter = methodElement.getParameters().get(0);
final TypeMirror parameterType = parameter.asType();
final String parameterName = parameter.getSimpleName().toString();
final boolean isShapeGetter;
final boolean isObjectTypeGetter;
final String expectedParameterName;
if (isSameType(parameterType, DynamicObject.class)) {
isShapeGetter = false;
isObjectTypeGetter = false;
expectedParameterName = "object";
} else if (isSameType(parameterType, DynamicObjectFactory.class)) {
isShapeGetter = true;
isObjectTypeGetter = false;
expectedParameterName = "factory";
} else if (isSameType(parameterType, ObjectType.class)) {
isShapeGetter = false;
isObjectTypeGetter = true;
expectedParameterName = "objectType";
} else {
isShapeGetter = false;
isObjectTypeGetter = false;
expectedParameterName = null;
processor.reportError(methodElement, "@Layout getter methods must have a parameter of type DynamicObject or, for shape properties, DynamicObjectFactory or ObjectType");
}
if (expectedParameterName != null && !matches(parameterName, expectedParameterName)) {
processor.reportError(methodElement, "@Layout getter method should have a parameter named %s", expectedParameterName);
}
final String propertyName = NameUtils.titleToCamel(methodElement.getSimpleName().toString().substring("get".length()));
final PropertyBuilder property = getProperty(propertyName);
if (isShapeGetter) {
property.setHasShapeGetter(true);
} else if (isObjectTypeGetter) {
property.setHasObjectTypeGetter(true);
} else {
property.setHasGetter(true);
}
setPropertyType(methodElement, property, methodElement.getReturnType());
}
use of com.oracle.truffle.object.dsl.processor.model.PropertyBuilder in project graal by oracle.
the class LayoutParser method parseGetAndSet.
private void parseGetAndSet(ExecutableElement methodElement) {
if (methodElement.getParameters().size() != 2) {
processor.reportError(methodElement, "@Layout get and set methods must have two parameters");
}
final VariableElement objectParameter = methodElement.getParameters().get(0);
final VariableElement newValueParameter = methodElement.getParameters().get(1);
if (!isSameType(objectParameter.asType(), DynamicObject.class)) {
processor.reportError(methodElement, "@Layout get and set method should have a first parameter of type DynamicObject");
}
if (!objectParameter.getSimpleName().toString().equals("object")) {
processor.reportError(methodElement, "@Layout get and set method should have a first parameter named object");
}
if (!newValueParameter.getSimpleName().toString().equals("value")) {
processor.reportError(methodElement, "@Layout get and set method should have a second parameter named value");
}
String propertyName = NameUtils.titleToCamel(methodElement.getSimpleName().toString().substring("getAndSet".length()));
final PropertyBuilder property = getProperty(propertyName);
property.setHasGetAndSet(true);
setPropertyType(methodElement, property, methodElement.getParameters().get(1).asType());
setPropertyType(methodElement, property, methodElement.getReturnType());
}
use of com.oracle.truffle.object.dsl.processor.model.PropertyBuilder in project graal by oracle.
the class LayoutParser method parseSetter.
private void parseSetter(ExecutableElement methodElement) {
if (methodElement.getParameters().size() != 2) {
processor.reportError(methodElement, "@Layout guard methods must have two parameters");
}
final VariableElement parameter = methodElement.getParameters().get(0);
final TypeMirror parameterType = parameter.asType();
final String parameterName = parameter.getSimpleName().toString();
final boolean isShapeSetter;
final String expectedParameterName;
if (isSameType(parameterType, DynamicObject.class)) {
isShapeSetter = false;
expectedParameterName = "object";
} else if (isSameType(parameterType, DynamicObjectFactory.class)) {
isShapeSetter = true;
expectedParameterName = "factory";
} else {
isShapeSetter = false;
expectedParameterName = null;
processor.reportError(methodElement, "@Layout setter methods must have a first parameter of type DynamicObject or, for shape properties, DynamicObjectFactory");
}
if (expectedParameterName != null && !matches(parameterName, expectedParameterName)) {
processor.reportError(methodElement, "@Layout getter method should have a first parameter named %s", expectedParameterName);
}
final VariableElement secondParameter = methodElement.getParameters().get(1);
final String secondParameterName = secondParameter.getSimpleName().toString();
if (!matches(secondParameterName, "value")) {
processor.reportError(methodElement, "@Layout getter method should have a second parameter named value");
}
final boolean isUnsafeSetter = methodElement.getSimpleName().toString().endsWith("Unsafe");
String propertyName = NameUtils.titleToCamel(methodElement.getSimpleName().toString().substring("set".length()));
if (isUnsafeSetter) {
propertyName = propertyName.substring(0, propertyName.length() - "Unsafe".length());
}
final PropertyBuilder property = getProperty(propertyName);
if (isShapeSetter) {
property.setHasShapeSetter(true);
} else {
if (isUnsafeSetter) {
property.setHasUnsafeSetter(isUnsafeSetter);
} else {
property.setHasSetter(true);
}
}
setPropertyType(methodElement, property, methodElement.getParameters().get(1).asType());
}
use of com.oracle.truffle.object.dsl.processor.model.PropertyBuilder in project graal by oracle.
the class LayoutParser method parseCompareAndSet.
private void parseCompareAndSet(ExecutableElement methodElement) {
if (methodElement.getParameters().size() != 3) {
processor.reportError(methodElement, "@Layout compare and set methods must have three parameters");
}
final VariableElement objectParameter = methodElement.getParameters().get(0);
final VariableElement currentValueParameter = methodElement.getParameters().get(1);
final VariableElement newValueParameter = methodElement.getParameters().get(2);
if (!isSameType(objectParameter.asType(), DynamicObject.class)) {
processor.reportError(methodElement, "@Layout compare and set method should have a first parameter of type DynamicObject");
}
if (!objectParameter.getSimpleName().toString().equals("object")) {
processor.reportError(methodElement, "@Layout compare and set method should have a first parameter named object");
}
if (!currentValueParameter.getSimpleName().toString().equals("expectedValue")) {
processor.reportError(methodElement, "@Layout compare and set method should have a second parameter named expectedValue");
}
if (!newValueParameter.getSimpleName().toString().equals("value")) {
processor.reportError(methodElement, "@Layout compare and set method should have a third parameter named value");
}
String propertyName = NameUtils.titleToCamel(methodElement.getSimpleName().toString().substring("compareAndSet".length()));
final PropertyBuilder property = getProperty(propertyName);
property.setHasCompareAndSet(true);
setPropertyType(methodElement, property, methodElement.getParameters().get(1).asType());
setPropertyType(methodElement, property, methodElement.getParameters().get(2).asType());
}
use of com.oracle.truffle.object.dsl.processor.model.PropertyBuilder in project graal by oracle.
the class LayoutParser method addConstructorProperties.
private void addConstructorProperties(ExecutableElement methodElement, List<? extends VariableElement> parameters) {
List<? extends VariableElement> ownParameters = parameters;
if (superLayout != null) {
final List<PropertyModel> superProperties = superLayout.getAllInstanceProperties();
checkSharedParameters(methodElement, parameters, superProperties);
ownParameters = parameters.subList(superProperties.size(), parameters.size());
}
for (VariableElement element : ownParameters) {
final String parameterName = element.getSimpleName().toString();
if (parameterName.equals("factory")) {
processor.reportError(methodElement, "Factory is a confusing name for a property");
}
if (constructorProperties.contains(parameterName)) {
processor.reportError(methodElement, "The property %s is duplicated");
} else {
constructorProperties.add(parameterName);
final PropertyBuilder property = getProperty(parameterName);
setPropertyType(element, property, element.asType());
parseConstructorParameterAnnotations(property, element);
}
}
}
Aggregations