public static TypeMirror getCommonSuperType(ProcessorContext context, Collection<TypeMirror> types) { if (types.isEmpty()) { return context.getType(Object.class); } Iterator<TypeMirror> typesIterator = types.iterator(); TypeMirror prev = typesIterator.next(); while (typesIterator.hasNext()) { prev = getCommonSuperType(context, prev, typesIterator.next()); } return prev; }
BitSet(String name, Object[] objects) { this.name = name; this.objects = objects; this.capacity = computeStateLength(); if (capacity <= 32) { bitSetType = context.getType(int.class); } else if (capacity <= 64) { bitSetType = context.getType(long.class); } else { throw new UnsupportedOperationException("State space too big " + capacity + ". Only <= 64 supported."); } this.allMask = createMask(objects); }
public static TypeMirror getCommonSuperType(ProcessorContext context, Collection<TypeMirror> types) { if (types.isEmpty()) { return context.getType(Object.class); } Iterator<TypeMirror> typesIterator = types.iterator(); TypeMirror prev = typesIterator.next(); while (typesIterator.hasNext()) { prev = getCommonSuperType(context, prev, typesIterator.next()); } return prev; }
@Override protected ParameterSpec createReturnParameterSpec() { return new ParameterSpec("has", getContext().getType(boolean.class)); }
public void visitNegate(Negate negate) { TypeMirror booleanType = context.getType(boolean.class); TypeMirror resolvedType = negate.getResolvedType(); if (!ElementUtils.typeEquals(resolvedType, booleanType)) { throw new InvalidExpressionException(String.format("The operator %s is undefined for the argument type %s.", "!", ElementUtils.getSimpleName(resolvedType))); } }
private void generateSaveOldPolymorphismState(CodeTreeBuilder builder, FrameState frameState) { builder.declaration(state.bitSetType, OLD_STATE, state.createMaskedReference(frameState, reachableSpecializations.toArray())); if (requiresExclude()) { builder.declaration(exclude.bitSetType, OLD_EXCLUDE, "exclude"); } if (requiresCacheCheck()) { builder.declaration(context.getType(int.class), OLD_CACHE_COUNT, "state == 0 ? 0 : " + COUNT_CACHES + "()"); } }
@Override public MethodSpec createSpecification(ExecutableElement method, AnnotationMirror mirror) { MethodSpec spec = new MethodSpec(new ParameterSpec("returnType", getContext().getType(boolean.class))); spec.addRequired(new ParameterSpec("value", getContext().getType(Object.class))); return spec; }
private static CodeVariableElement createNodeChild(ProcessorContext context, TypeMirror type, String name) { CodeVariableElement var = new CodeVariableElement(ElementUtils.modifiers(Modifier.PRIVATE), type, name); var.addAnnotationMirror(new CodeAnnotationMirror((DeclaredType) context.getType(Child.class))); return var; }
@Override public MethodSpec createSpecification(ExecutableElement method, AnnotationMirror mirror) { MethodSpec spec = new MethodSpec(new ParameterSpec("target", getContext().getType(Object.class))); spec.addRequired(new ParameterSpec("source", getContext().getType(Object.class))).setSignature(true); return spec; }
private CodeExecutableElement createIsTypeMethod(TypeMirror type) { if (typeSystem.getCheck(type) != null) { return null; } CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, STATIC), context.getType(boolean.class), TypeSystemCodeGenerator.isTypeMethodName(typeSystem, type)); method.addParameter(new CodeVariableElement(context.getType(Object.class), LOCAL_VALUE)); CodeTreeBuilder body = method.createBuilder(); body.startReturn().tree(check(typeSystem, type, LOCAL_VALUE)).end(); return method; }
private CodeExecutableElement createIsTypeMethod(TypeMirror type) { if (typeSystem.getCheck(type) != null) { return null; } CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, STATIC), context.getType(boolean.class), TypeSystemCodeGenerator.isTypeMethodName(typeSystem, type)); method.addParameter(new CodeVariableElement(context.getType(Object.class), LOCAL_VALUE)); CodeTreeBuilder body = method.createBuilder(); body.startReturn().tree(check(typeSystem, type, LOCAL_VALUE)).end(); return method; }
private void verifyTypes(TypeSystemData typeSystem) { for (TypeMirror type : typeSystem.getLegacyTypes()) { if (isPrimitiveWrapper(type)) { typeSystem.addError("Types must not contain primitive wrapper types."); } if (ElementUtils.typeEquals(type, context.getType(Object.class))) { typeSystem.addError("Types must not contain the generic type java.lang.Object."); } } verifyTypeOrder(typeSystem); }
private void verifyTypes(TypeSystemData typeSystem) { for (TypeMirror type : typeSystem.getLegacyTypes()) { if (isPrimitiveWrapper(type)) { typeSystem.addError("Types must not contain primitive wrapper types."); } if (ElementUtils.typeEquals(type, context.getType(Object.class))) { typeSystem.addError("Types must not contain the generic type java.lang.Object."); } } verifyTypeOrder(typeSystem); }
static CodeTree createTransferToInterpreterAndInvalidate() { ProcessorContext context = ProcessorContext.getInstance(); CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); builder.startStatement().startStaticCall(context.getType(CompilerDirectives.class), "transferToInterpreterAndInvalidate").end().end(); return builder.build(); }
private CodeVariableElement createSingleton(CodeTypeElement clazz) { CodeVariableElement field = new CodeVariableElement(modifiers(PUBLIC, STATIC, FINAL), clazz.asType(), singletonName(typeSystem)); field.createInitBuilder().startNew(clazz.asType()).end(); CodeAnnotationMirror annotationMirror = new CodeAnnotationMirror((DeclaredType) context.getType(Deprecated.class)); field.getAnnotationMirrors().add(annotationMirror); return field; }
private CodeVariableElement createSingleton(CodeTypeElement clazz) { CodeVariableElement field = new CodeVariableElement(modifiers(PUBLIC, STATIC, FINAL), clazz.asType(), singletonName(typeSystem)); field.createInitBuilder().startNew(clazz.asType()).end(); CodeAnnotationMirror annotationMirror = new CodeAnnotationMirror((DeclaredType) context.getType(Deprecated.class)); field.getAnnotationMirrors().add(annotationMirror); return field; }
public static CodeTree createTransferToInterpreterAndInvalidate() { ProcessorContext context = ProcessorContext.getInstance(); CodeTreeBuilder builder = CodeTreeBuilder.createBuilder(); builder.startStatement().startStaticCall(context.getType(CompilerDirectives.class), "transferToInterpreterAndInvalidate").end().end(); return builder.build(); }
@Override public MethodSpec createSpecification(ExecutableElement method, AnnotationMirror mirror) { TypeMirror targetTypeMirror = ElementUtils.getAnnotationValue(TypeMirror.class, mirror, "value"); ParameterSpec returnTypeSpec = new ParameterSpec("returnType", targetTypeMirror); returnTypeSpec.setAllowSubclasses(false); MethodSpec spec = new MethodSpec(returnTypeSpec); spec.addRequired(new ParameterSpec("value", getContext().getType(Object.class))); return spec; }
private CodeTypeElement createBaseSpecialization() { CodeTypeElement clazz = createClass(node, null, modifiers(PRIVATE, ABSTRACT, STATIC), specializationTypeName(null), typeSystem.getContext().getType(SpecializationNode.class)); clazz.addOptional(createSpecializationConstructor(clazz, null, null)); clazz.add(new CodeVariableElement(modifiers(PROTECTED, FINAL), nodeType(node), "root")); clazz.addOptional(createUnsupported()); clazz.add(createGetSuppliedChildrenMethod()); clazz.add(createAcceptAndExecute()); for (ExecutableTypeData type : usedTypes) { clazz.add(createFastPathExecuteMethod(null, type, usedTypes)); } return clazz; }
private CodeExecutableElement createAsTypeMethod(TypeMirror type) { if (typeSystem.getCast(type) != null) { return null; } CodeExecutableElement method = new CodeExecutableElement(modifiers(PUBLIC, STATIC), type, TypeSystemCodeGenerator.asTypeMethodName(typeSystem, type)); method.addParameter(new CodeVariableElement(context.getType(Object.class), LOCAL_VALUE)); CodeTreeBuilder body = method.createBuilder(); String assertMessage = typeName(typeSystem) + "." + asTypeMethodName(typeSystem, type) + ": " + ElementUtils.getSimpleName(type) + " expected"; body.startAssert().tree(check(typeSystem, type, LOCAL_VALUE)).string(" : ").doubleQuote(assertMessage).end(); body.startReturn().tree(cast(typeSystem, type, LOCAL_VALUE)).end(); return method; }