public void addAnnotations(List<Annotation> as) { for (Annotation a : as) addAnnotation(a); } public ModifiableElement addAnnotation(Annotation a) {
void moveModifiersOfType(ModifierKind kind, ModifiableElement source, ModifiableElement destination) { List<Modifier> mods = null; for (Modifier m : source.getModifiers()) { if (m.isA(kind)) { if (mods == null) { mods = new ArrayList<Modifier>(); } mods.add(m); } } if (mods != null) { Modifier[] modsArray = mods.toArray(new Modifier[mods.size()]); source.removeModifiers(modsArray); destination.addModifiers(modsArray); } } static Modifier longAlias = ModifierType.Long.resolveAlias(), shortAlias = ModifierType.Short.resolveAlias();
public void setAnnotations(List<Annotation> annotations) { changeValue(this, this.annotations, annotations); }
public ModifiableElement reorganizeModifiers() { setModifiers(new ArrayList<Modifier>(new LinkedHashSet<Modifier>(getModifiers()))); return this; }
public List<Modifier> harvestModifiers() { List<Modifier> mods = new ArrayList<Modifier>(); mods.addAll(getModifiers()); return mods; }
@Override public TypeRef addModifiers(Modifier... mds) { return (TypeRef) super.addModifiers(mds); } public static abstract class TaggedTypeRef extends TypeRef {
public <M extends ModifiableElement> M annotateRawType(M element) throws UnsupportedConversionException { element.addAnnotations(annotations); if (type != null) { switch (type) { case Enum: case Primitive: case Void: break; case NativeLong: element.addAnnotation(new Annotation(typeRef(CLong.class))); break; case NativeSize: element.addAnnotation(new Annotation(typeRef(Ptr.class))); break; case Pointer: element.addAnnotation(new Annotation(typeRef(Ptr.class))); break; case Struct: case ComplexDouble: case FunctionSignature: case Default: case NativeTime: //throw new UnsupportedConversionException(typeRef, "Struct by value not supported yet"); break; default: throw new UnsupportedConversionException(typeRef, "Not supported"); } } return element; }
@Override public Statement clone() { return (Statement)super.clone(); } public static class Throw extends Statement {
public <M extends ModifiableElement> M annotateTypedType(M element, boolean useRawTypes) throws UnsupportedConversionException { element.addAnnotations(annotations); if (type != ConvType.Pointer || useRawTypes) { annotateRawType(element); } return element; } }
@Override public TypeRef importDetails(Element from, boolean move) { return (TypeRef) super.importDetails(from, move); } @Override
@Override public Element getNextChild(Element child) { return getNextSibling(annotations, child); } @Override
@Override public Element getPreviousChild(Element child) { return getPreviousSibling(annotations, child); }
public void visitModifiableElement(ModifiableElement modifiableElement) { visitElement(modifiableElement); visit(modifiableElement.getAnnotations()); }
static List<Modifier> getLongShortModifiers(ModifiableElement e) { List<Modifier> ret = null; for (Modifier mod : e.getModifiers()) { Modifier res = mod.resolveAlias(); if (res.equals(longAlias) || res.equals(shortAlias)) { if (ret == null) { ret = new ArrayList<Modifier>(); } ret.add(mod); } } return ret; }
@Override public Declarator addModifiers(Modifier... mds) { return (Declarator)super.addModifiers(mds); } public abstract MutableByDeclarator mutateType(MutableByDeclarator t);
public <M extends ModifiableElement> M annotateRawType(M element) throws UnsupportedConversionException { element.addAnnotations(annotations); if (type != null) { switch (type) { case Enum: case Primitive: case Void: break; case NativeLong: element.addAnnotation(new Annotation(typeRef(CLong.class))); break; case NativeSize: element.addAnnotation(new Annotation(typeRef(Ptr.class))); break; case Pointer: element.addAnnotation(new Annotation(typeRef(Ptr.class))); break; case Struct: case ComplexDouble: case FunctionSignature: case Default: case NativeTime: //throw new UnsupportedConversionException(typeRef, "Struct by value not supported yet"); break; default: throw new UnsupportedConversionException(typeRef, "Not supported"); } } return element; }
@Override public Declarator clone() { return (Declarator)super.clone(); } public static interface MutableByDeclarator {
public <M extends ModifiableElement> M annotateTypedType(M element, boolean useRawTypes) throws UnsupportedConversionException { element.addAnnotations(annotations); if (type != ConvType.Pointer || useRawTypes) { annotateRawType(element); } return element; } }
void moveModifiersOfType(ModifierKind kind, ModifiableElement source, ModifiableElement destination) { List<Modifier> mods = null; for (Modifier m : source.getModifiers()) { if (m.isA(kind)) { if (mods == null) { mods = new ArrayList<Modifier>(); } mods.add(m); } } if (mods != null) { Modifier[] modsArray = mods.toArray(new Modifier[mods.size()]); source.removeModifiers(modsArray); destination.addModifiers(modsArray); } } static Modifier longAlias = ModifierType.Long.resolveAlias(), shortAlias = ModifierType.Short.resolveAlias();
@Override protected void fillLibraryMapping(Result result, SourceFiles sourceFiles, DeclarationsHolder declarations, DeclarationsHolder implementations, String library, Identifier javaPackage, Expression nativeLibFieldExpr) throws IOException { super.fillLibraryMapping(result, sourceFiles, declarations, implementations, library, javaPackage, nativeLibFieldExpr); if (implementations instanceof ModifiableElement) { ModifiableElement minterf = (ModifiableElement) implementations; List<String> deps = result.config.dependencies.get(library); Map<String, Expression> namedArguments = null; if (deps != null) { List<Expression> depExprs = new ArrayList<Expression>(); for (String dep : deps) depExprs.add(expr(dep)); namedArguments = ImmutableMap.<String, Expression>of( "dependencies", NewArray.newAnnotationArrayValue(depExprs)); } minterf.addAnnotation(new Annotation(typeRef(org.bridj.ann.Library.class), expr(library), namedArguments)); minterf.addAnnotation(new Annotation(typeRef(org.bridj.ann.Runtime.class), classLiteral(result.hasCPlusPlus ? CPPRuntime.class : CRuntime.class))); } }