Esempio n. 1
0
  private void process(
      AbstractTypeDeclaration astNode,
      final JstType jstType,
      final Annotation anno,
      final CustomType cType,
      final CustomInfo cInfo) {
    String name;
    String value = null;
    if (anno instanceof NormalAnnotation) {
      List<MemberValuePair> annos = getAnnoMemberPairs(anno);
      if (annos.size() > 0) {
        for (MemberValuePair pair : annos) {
          name = getName(pair);
          if (ANNO_NAME.equals(name) || ANNO_VALUE.equals(name)) {
            if (pair.getValue() instanceof QualifiedName) {
              value = getValue((QualifiedName) pair.getValue(), astNode, jstType);
            } else {
              value = getValue(pair.getValue(), astNode, jstType);
            }
            break;
          }
        }
        cInfo.setName(value);
      }
    } else if (anno instanceof SingleMemberAnnotation) {
      value = getValue(((SingleMemberAnnotation) anno).getValue(), astNode, jstType);
      cInfo.setName(value);
    } else {
      value = astNode.getName().toString();
    }

    if (value == null) {
      return;
    }
    cType.setAttr(cInfo.getAttr());
    cType.setJstName(value);
  }
Esempio n. 2
0
  private void process(
      MethodDeclaration astNode,
      final JstType jstType,
      final Annotation anno,
      final CustomType cType,
      final CustomInfo cInfo) {
    MethodKey mtdKey = MethodKey.genMethodKey(astNode);
    CustomMethod cMtd = cType.getCustomMethod(mtdKey);
    if (cMtd == null) {
      cMtd = new CustomMethod(mtdKey);
      cType.addCustomMethod(cMtd);
    }

    String name;
    String value = null;
    if (anno instanceof NormalAnnotation) {
      List<MemberValuePair> annos = getAnnoMemberPairs(anno);
      if (annos.size() > 0) {
        for (MemberValuePair pair : annos) {
          name = getName(pair);
          if (ANNO_NAME.equals(name) || ANNO_VALUE.equals(name)) {
            if (pair.getValue() instanceof QualifiedName) {
              value = getValue((QualifiedName) pair.getValue(), astNode, jstType);
            } else {
              value = getValue(pair.getValue(), astNode, jstType);
            }
            break;
          }
        }
      }
    } else if (anno instanceof SingleMemberAnnotation) {
      value = getValue(((SingleMemberAnnotation) anno).getValue(), astNode, jstType);
      cInfo.setName(value);
    } else if (cInfo.isMappedToJS() || cInfo.isMappedToVJO()) {
      value = astNode.getName().toString();
    }

    if (value == null) {
      return;
    }

    cMtd.setAttr(cInfo.getAttr());
    int index = value.lastIndexOf(".");
    if (index > 0) {
      cMtd.setJstOwnerTypeName(value.substring(0, index));
      cMtd.setJstName(value.substring(index + 1));
      cInfo.setName(value);
    } else {
      cMtd.setJstName(value);
      cInfo.setName(value);
    }
  }
Esempio n. 3
0
  //
  // Satisfy IAnnoProcessor
  //
  @Override
  public CustomInfo process(final ASTNode astNode, final JstType jstType) {

    List<Annotation> annos = getAnnotations(astNode);
    if (annos.isEmpty()) {
      return null;
    }

    CustomInfo cInfo = new CustomInfo();
    boolean forceFullyQualified = false;

    String annoName;
    for (Annotation anno : annos) {

      annoName = anno.getTypeName().toString();

      if (annoName.equals(AExclude.class.getSimpleName())) {
        cInfo.setAttr(CustomAttr.EXCLUDED);
      } else if (annoName.equals(AJavaOnly.class.getSimpleName())) {
        cInfo.setAttr(CustomAttr.JAVA_ONLY);
      } else if (annoName.equals(AJsProxy.class.getSimpleName())) {
        cInfo.setAttr(CustomAttr.JS_PROXY);
      } else if (annoName.equals(AMappedToJS.class.getSimpleName())) {
        cInfo.setAttr(CustomAttr.MAPPED_TO_JS);
        process(astNode, jstType, anno, cInfo);
      } else if (annoName.equals(AMappedToVJO.class.getSimpleName())) {
        cInfo.setAttr(CustomAttr.MAPPED_TO_VJO);
        process(astNode, jstType, anno, cInfo);
      } else if (annoName.equals(ACustomizedAs.class.getSimpleName())) {
        MemberValuePair mvPair;
        for (Object pair : ((NormalAnnotation) anno).values()) {
          if (pair instanceof MemberValuePair) {
            mvPair = (MemberValuePair) pair;
            if (mvPair.getName().toString().equals("type")) {
              Type asAstType = ((TypeLiteral) mvPair.getValue()).getType();
              IJstType asJstType =
                  TranslateCtx.ctx()
                      .getProvider()
                      .getDataTypeTranslator()
                      .processType(asAstType, jstType);
              cInfo.setAsType(asJstType);
            } else if (mvPair.getName().toString().equals("name")) {
              cInfo.setAsName(((StringLiteral) mvPair.getValue()).getLiteralValue());
            }
          }
        }
      } else if (annoName.equals(ARename.class.getSimpleName())) {
        process(astNode, jstType, anno, cInfo);
      } else if (annoName.equals(AProperty.class.getSimpleName())) {
        if (astNode instanceof MethodDeclaration) {
          genMetaForPty((MethodDeclaration) astNode, jstType, anno);
        }
      } else if (annoName.equals(AForceFullyQualified.class.getSimpleName())) {
        if (astNode instanceof MethodDeclaration) {
          forceFullyQualified = TranslateHelper.isStatic(((MethodDeclaration) astNode).modifiers());
        }
      }
    }

    if (forceFullyQualified) {
      cInfo.setForceFullyQualify(true);
    }

    return cInfo;
  }
Esempio n. 4
0
  private void process(
      FieldDeclaration astNode,
      final JstType jstType,
      final Annotation anno,
      final CustomType cType,
      final CustomInfo cInfo) {

    String value = null;
    if (anno instanceof NormalAnnotation) {
      List<MemberValuePair> annos = getAnnoMemberPairs(anno);
      String name;
      if (annos.size() > 0) {
        for (MemberValuePair pair : annos) {
          name = getName(pair);
          if (ANNO_NAME.equals(name) || ANNO_VALUE.equals(name)) {
            if (pair.getValue() instanceof QualifiedName) {
              value = getValue((QualifiedName) pair.getValue(), astNode, jstType);
            } else {
              value = getValue(pair.getValue(), astNode, jstType);
            }
            cInfo.setName(value);
            break;
          }
        }
      }
    } else if (anno instanceof SingleMemberAnnotation) {
      value = getValue(((SingleMemberAnnotation) anno).getValue(), astNode, jstType);
      cInfo.setName(value);
    }

    if (value == null) {
      return;
    }

    String fName = null;
    String tName = null;

    if (value != null) {
      cInfo.setName(value);
      int index = value.lastIndexOf(".");
      if (index < 0) {
        fName = value;
      } else {
        fName = value.substring(index + 1, value.length());
        tName = value.substring(0, index);
      }
    }

    VariableDeclarationFragment v;
    String vName;
    CustomField cField;
    for (Object o : astNode.fragments()) {
      if (o instanceof VariableDeclarationFragment) {
        v = (VariableDeclarationFragment) o;
        vName = v.getName().toString();
        cField = cType.getCustomField(vName);
        if (cField == null) {
          cField = new CustomField(vName);
          cType.addCustomField(cField);
        }
        cField.setAttr(cInfo.getAttr());
        cField.setJstName(fName);
        cField.setJstOwnerTypeName(tName);
      }
    }
  }