public void setAnnotationClass(TypeRef annotationClass) { this.annotationClass = changeValue(this, this.annotationClass, annotationClass); }
@Override public boolean replaceChild(Element child, Element by) { if (child == getAnnotationClass()) { setAnnotationClass((TypeRef)by); return true; } if (child == getDefaultArgument()) { setDefaultArgument((Expression) by); return true; } return replaceChild(namedArguments, Expression.class, this, child, by) || super.replaceChild(child, by); }
public void visitAnnotation(Annotation annotation) { visitElement(annotation); visit(annotation.getAnnotationClass()); visit(annotation.getDefaultArgument()); visit(annotation.getNamedArguments()); }
public Annotation(TypeRef annotationClass, Expression defaultArgument, Map<String, Expression> namedArguments) { setAnnotationClass(annotationClass); setDefaultArgument(defaultArgument); setNamedArguments(namedArguments); }
@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))); } }
@Override public Element getNextChild(Element child) { return getNextSibling(namedArguments.values(), child); }
@Override public Element getPreviousChild(Element child) { return getPreviousSibling(namedArguments.values(), child); }
@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))); } }
private void addParentNamespaceAnnotation(ModifiableElement dest, Identifier parentNamespace) { if (parentNamespace != null) { dest.addAnnotation(new Annotation(typeRef(org.bridj.ann.Namespace.class), expr(parentNamespace.toString()))); } } }
public void visitAnnotation(Annotation e) { append("@", e.getAnnotationClass()); boolean first = true; boolean hasDefault = e.getDefaultArgument() != null; boolean hasNamed = !e.getNamedArguments().isEmpty(); if (hasDefault || hasNamed) { append("("); if (hasDefault) { if (hasNamed) append("value = "); append(e.getDefaultArgument()); first = false; } for (Map.Entry<String, Expression> entry : e.getNamedArguments().entrySet()) { if (!first) append(", "); append(entry.getKey(), " = ", entry.getValue()); first = false; } append(")"); } space(); }
public void setNamedArguments(Map<String, Expression> namedArguments) { changeValue(this, this.namedArguments, namedArguments); } public Map<String, Expression> getNamedArguments() {
private void addParentNamespaceAnnotation(ModifiableElement dest, Identifier parentNamespace) { if (parentNamespace != null) { dest.addAnnotation(new Annotation(typeRef(org.bridj.ann.Namespace.class), expr(parentNamespace.toString()))); } } }
public void setDefaultArgument(Expression defaultArgument) { this.defaultArgument = changeValue(this, this.defaultArgument, defaultArgument); }
void toDirectFakePointer(Result result, Declaration decl) { decl.setValueType(typeRef(long.class)); decl.addAnnotation(new Annotation(typeRef(Ptr.class))); }
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; }
void toDirectFakePointer(Result result, Declaration decl) { decl.setValueType(typeRef(long.class)); decl.addAnnotation(new Annotation(typeRef(Ptr.class))); }
private void annotateActualName(ModifiableElement e, Identifier name) { e.addAnnotation(new Annotation(result.config.runtime.typeRef(JNAeratorConfig.Runtime.Ann.Name), expr(name.toString()))); }
private void annotateActualName(ModifiableElement e, Identifier name) { e.addAnnotation(new Annotation(result.config.runtime.typeRef(JNAeratorConfig.Runtime.Ann.Name), expr(name.toString()))); }
public void annotateActualName(ModifiableElement e, Identifier name) { e.addAnnotation(new Annotation(typeRef(org.bridj.ann.Name.class), expr(name.toString()))); }
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; }