private List<? extends Element> importPublicStaticMembers(TypeElement importGuardClass, boolean includeConstructors) { // hack to reload type is necessary for incremental compiling in eclipse. // otherwise methods inside of import guard types are just not found. TypeElement typeElement = ElementUtils.fromTypeMirror(context.reloadType(importGuardClass.asType())); List<Element> members = new ArrayList<>(); for (Element importElement : processingEnv.getElementUtils().getAllMembers(typeElement)) { if (!importElement.getModifiers().contains(Modifier.PUBLIC)) { continue; } if (includeConstructors && importElement.getKind() == ElementKind.CONSTRUCTOR) { members.add(importElement); } if (!importElement.getModifiers().contains(Modifier.STATIC)) { continue; } ElementKind kind = importElement.getKind(); if (kind.isField() || kind == ElementKind.METHOD) { members.add(importElement); } } return members; }
public TypeMirror reloadType(TypeMirror type) { if (type instanceof CodeTypeMirror) { return type; } else if (type.getKind().isPrimitive()) { return type; } Types types = getEnvironment().getTypeUtils(); switch (type.getKind()) { case ARRAY: return types.getArrayType(reloadType(((ArrayType) type).getComponentType())); case WILDCARD: return types.getWildcardType(((WildcardType) type).getExtendsBound(), ((WildcardType) type).getSuperBound()); case DECLARED: return reloadTypeElement((TypeElement) (((DeclaredType) type).asElement())); } return type; }
public static boolean isAssignable(TypeMirror from, TypeMirror to) { if (typeEquals(from, to)) { return true; } else if (isVoid(to)) { return true; } else if (isObject(to)) { return true; } ProcessorContext context = ProcessorContext.getInstance(); if (!(from instanceof CodeTypeMirror) && !(to instanceof CodeTypeMirror)) { return context.getEnvironment().getTypeUtils().isAssignable(context.reloadType(from), context.reloadType(to)); } else { return isAssignableImpl(from, to); } }
public TypeMirror reloadType(TypeMirror type) { if (type instanceof CodeTypeMirror) { return type; } else if (type.getKind().isPrimitive()) { return type; } Types types = getEnvironment().getTypeUtils(); switch (type.getKind()) { case ARRAY: return types.getArrayType(reloadType(((ArrayType) type).getComponentType())); case WILDCARD: return types.getWildcardType(((WildcardType) type).getExtendsBound(), ((WildcardType) type).getSuperBound()); case DECLARED: return reloadTypeElement((TypeElement) (((DeclaredType) type).asElement())); } return type; }
public static boolean isAssignable(TypeMirror from, TypeMirror to) { if (typeEquals(from, to)) { return true; } else if (isVoid(to)) { return true; } else if (isObject(to)) { return true; } ProcessorContext context = ProcessorContext.getInstance(); if (!(from instanceof CodeTypeMirror) && !(to instanceof CodeTypeMirror)) { return context.getEnvironment().getTypeUtils().isAssignable(context.reloadType(from), context.reloadType(to)); } else { return isAssignableImpl(from, to); } }
TypeElement typeElement = ElementUtils.fromTypeMirror(context.reloadType(importGuardClass.asType()));
TypeMirror type = receiver.getResolvedType(); if (type.getKind() == TypeKind.DECLARED) { type = context.reloadType(type); // ensure ECJ has the type loaded lookupVariables = new ArrayList<>(); variablesIn(lookupVariables, context.getEnvironment().getElementUtils().getAllMembers((TypeElement) ((DeclaredType) type).asElement()), true);
TypeMirror type = receiver.getResolvedType(); if (type.getKind() == TypeKind.DECLARED) { type = context.reloadType(type); // ensure ECJ has the type loaded lookupVariables = new ArrayList<>(); variablesIn(lookupVariables, context.getEnvironment().getElementUtils().getAllMembers((TypeElement) ((DeclaredType) type).asElement()), true);
TypeMirror type = receiver.getResolvedType(); if (type.getKind() == TypeKind.DECLARED) { type = context.reloadType(type); // ensure ECJ has the type loaded lookupMethods = ElementFilter.methodsIn(context.getEnvironment().getElementUtils().getAllMembers((TypeElement) ((DeclaredType) type).asElement())); } else {
TypeMirror type = receiver.getResolvedType(); if (type.getKind() == TypeKind.DECLARED) { type = context.reloadType(type); // ensure ECJ has the type loaded lookupMethods = ElementFilter.methodsIn(context.getEnvironment().getElementUtils().getAllMembers((TypeElement) ((DeclaredType) type).asElement())); } else {
CodeTypeElement factory = new CodeTypeElement(typeModifiers, ElementKind.CLASS, pack, createWrapperClassName(sourceType)); TypeMirror factoryType = context.reloadType(context.getType(com.oracle.truffle.api.instrumentation.InstrumentableFactory.class)); factory.getImplements().add(new CodeTypeMirror.DeclaredCodeTypeMirror(ElementUtils.fromTypeMirror(factoryType), Arrays.asList(sourceType.asType())));