use of org.codehaus.groovy.GroovyBugError in project gcontracts by andresteingress.
the class AnnotationProcessorVisitor method createAnnotationProcessor.
private AnnotationProcessor createAnnotationProcessor(AnnotationNode annotationNode) {
ClassExpression annotationProcessingAnno = null;
List<AnnotationNode> annotations = annotationNode.getClassNode().redirect().getAnnotations();
for (AnnotationNode anno : annotations) {
Class typeClass = anno.getClassNode().getTypeClass();
if (typeClass.getName().equals("org.gcontracts.annotations.meta.AnnotationProcessorImplementation")) {
annotationProcessingAnno = (ClassExpression) anno.getMember("value");
break;
}
}
if (annotationProcessingAnno == null)
throw new GroovyBugError("Annotation processing class could not be found! This indicates a bug in GContracts, please file an issue!");
try {
final Class clz = Class.forName(annotationProcessingAnno.getType().getTypeClass().getName());
return (AnnotationProcessor) clz.newInstance();
} catch (InstantiationException e) {
} catch (IllegalAccessException e) {
} catch (ClassNotFoundException e) {
}
throw new GroovyBugError("Annotation processing class could not be instantiated! This indicates a bug in GContracts, please file an issue!");
}
use of org.codehaus.groovy.GroovyBugError in project grails-core by grails.
the class DelegateAsyncTransformation method visit.
public void visit(ASTNode[] nodes, SourceUnit source) {
if (nodes.length != 2 || !(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
throw new GroovyBugError("Internal error: expecting [AnnotationNode, AnnotatedNode] but got: " + Arrays.asList(nodes));
}
AnnotatedNode parent = (AnnotatedNode) nodes[1];
AnnotationNode annotationNode = (AnnotationNode) nodes[0];
if (parent instanceof ClassNode) {
Expression value = annotationNode.getMember("value");
if (value instanceof ClassExpression) {
ClassNode targetApi = value.getType().getPlainNodeReference();
ClassNode classNode = (ClassNode) parent;
final String fieldName = '$' + Introspector.decapitalize(targetApi.getNameWithoutPackage());
FieldNode fieldNode = classNode.getField(fieldName);
if (fieldNode == null) {
fieldNode = new FieldNode(fieldName, Modifier.PRIVATE, targetApi, classNode, new ConstructorCallExpression(targetApi, NO_ARGS));
classNode.addField(fieldNode);
}
applyDelegateAsyncTransform(classNode, targetApi, fieldName);
}
} else if (parent instanceof FieldNode) {
FieldNode fieldNode = (FieldNode) parent;
ClassNode targetApi = fieldNode.getType().getPlainNodeReference();
ClassNode classNode = fieldNode.getOwner();
applyDelegateAsyncTransform(classNode, targetApi, fieldNode.getName());
}
}
use of org.codehaus.groovy.GroovyBugError in project groovy-core by groovy.
the class GeneratorContext method encodeAsValidClassName.
public static String encodeAsValidClassName(String name) {
final int l = name.length();
StringBuilder b = null;
int lastEscape = -1;
for (int i = 0; i < l; ++i) {
final int encodeIndex = name.charAt(i) - MIN_ENCODING;
if (encodeIndex >= 0 && encodeIndex < CHARACTERS_TO_ENCODE.length) {
if (CHARACTERS_TO_ENCODE[encodeIndex]) {
if (b == null) {
b = new StringBuilder(name.length() + 3);
b.append(name, 0, i);
} else {
b.append(name, lastEscape + 1, i);
}
b.append('_');
lastEscape = i;
}
}
}
if (b == null)
return name.toString();
if (lastEscape == -1)
throw new GroovyBugError("unexpected escape char control flow in " + name);
b.append(name, lastEscape + 1, l);
return b.toString();
}
use of org.codehaus.groovy.GroovyBugError in project groovy-core by groovy.
the class AsmClassGenerator method visitAnnotationDefaultExpression.
void visitAnnotationDefaultExpression(AnnotationVisitor av, ClassNode type, Expression exp) {
if (exp instanceof ClosureExpression) {
ClassNode closureClass = controller.getClosureWriter().getOrAddClosureClass((ClosureExpression) exp, ACC_PUBLIC);
Type t = Type.getType(BytecodeHelper.getTypeDescription(closureClass));
av.visit(null, t);
} else if (type.isArray()) {
ListExpression list = (ListExpression) exp;
AnnotationVisitor avl = av.visitArray(null);
ClassNode componentType = type.getComponentType();
for (Expression lExp : list.getExpressions()) {
visitAnnotationDefaultExpression(avl, componentType, lExp);
}
} else if (ClassHelper.isPrimitiveType(type) || type.equals(ClassHelper.STRING_TYPE)) {
ConstantExpression constExp = (ConstantExpression) exp;
av.visit(null, constExp.getValue());
} else if (ClassHelper.CLASS_Type.equals(type)) {
ClassNode clazz = exp.getType();
Type t = Type.getType(BytecodeHelper.getTypeDescription(clazz));
av.visit(null, t);
} else if (type.isDerivedFrom(ClassHelper.Enum_Type)) {
PropertyExpression pExp = (PropertyExpression) exp;
ClassExpression cExp = (ClassExpression) pExp.getObjectExpression();
String desc = BytecodeHelper.getTypeDescription(cExp.getType());
String name = pExp.getPropertyAsString();
av.visitEnum(null, desc, name);
} else if (type.implementsInterface(ClassHelper.Annotation_TYPE)) {
AnnotationConstantExpression avExp = (AnnotationConstantExpression) exp;
AnnotationNode value = (AnnotationNode) avExp.getValue();
AnnotationVisitor avc = av.visitAnnotation(null, BytecodeHelper.getTypeDescription(avExp.getType()));
visitAnnotationAttributes(value, avc);
} else {
throw new GroovyBugError("unexpected annotation type " + type.getName());
}
av.visitEnd();
}
use of org.codehaus.groovy.GroovyBugError in project groovy-core by groovy.
the class Expression method transformExpressions.
/**
* Transforms the list of expressions, and checks that all transformed expressions have the given type.
*
* @return a new list of transformed expressions
*/
protected <T extends Expression> List<T> transformExpressions(List<? extends Expression> expressions, ExpressionTransformer transformer, Class<T> transformedType) {
List<T> list = new ArrayList<T>(expressions.size());
for (Expression expr : expressions) {
Expression transformed = transformer.transform(expr);
if (!transformedType.isInstance(transformed))
throw new GroovyBugError(String.format("Transformed expression should have type %s but has type %s", transformedType, transformed.getClass()));
list.add(transformedType.cast(transformed));
}
return list;
}
Aggregations