Esempio n. 1
0
  public Element importDetails(Element from, boolean move) {
    if (from == null) return this;

    if (!from.getNameSpace().isEmpty()) setNameSpace(from.getNameSpace());

    if (from.getElementFile() != null) setElementFile(from.getElementFile());
    if (from.getElementLine() >= 0) setElementLine(from.getElementLine());
    if (from.getCommentBefore() != null) addToCommentBefore(from.getCommentBefore());
    if (from.getCommentAfter() != null) setCommentAfter(from.getCommentAfter());

    if (move) from.stripDetails();
    return this;
  }
  protected void outputNSString(
      String name,
      String value,
      DeclarationsHolder out,
      Signatures signatures,
      Element... elementsToTakeCommentsFrom) {

    if (!signatures.addVariable(name)) return;

    TypeRef tr = typeRef(String.class);
    VariablesDeclaration vd = new VariablesDeclaration(tr, new DirectDeclarator(name, expr(value)));
    if (!result.config.noComments)
      for (Element e : elementsToTakeCommentsFrom) {
        vd.addToCommentBefore(e.getCommentBefore());
        vd.addToCommentBefore(e.getCommentAfter());
      }
    vd.addModifiers(ModifierType.Public);
    out.addDeclaration(vd);
  }
  public Struct convertCallback(
      FunctionSignature functionSignature, Signatures signatures, Identifier callerLibraryName) {
    Identifier name =
        result.typeConverter.inferCallBackName(functionSignature, true, false, callerLibraryName);
    if (name == null) return null;

    name = result.typeConverter.getValidJavaArgumentName(name);

    Function function = functionSignature.getFunction();

    int i = 1;
    Identifier chosenName = name;
    while (!(signatures.addClass(chosenName))) {
      chosenName = ident(name.toString() + (++i));
    }

    Element parent = functionSignature.getParentElement();
    Element comel = parent != null && parent instanceof TypeDef ? parent : functionSignature;

    Struct callbackStruct = new Struct();
    configureCallbackStruct(callbackStruct);
    // callbackStruct.setParents(Arrays.asList(getCallbackType(functionSignature, chosenName)));
    callbackStruct.setTag(ident(chosenName));
    if (!result.config.noComments)
      callbackStruct.addToCommentBefore(
          comel.getCommentBefore(), comel.getCommentAfter(), getFileCommentContent(comel));
    convertFunction(function, new Signatures(), true, callbackStruct, callerLibraryName, -1);
    for (Declaration d : callbackStruct.getDeclarations()) {
      if (d instanceof Function) {
        callbackStruct.addAnnotations(callbackStruct.getAnnotations());
        callbackStruct.setAnnotations(null);
        break;
      }
    }
    return callbackStruct;
  }