Exemplo n.º 1
0
  private void genMetaForPty(
      MethodDeclaration astNode, final JstType jstType, final Annotation anno) {

    CustomType cType = getCustomType(jstType);
    MethodKey mtdKey = MethodKey.genMethodKey(astNode);
    CustomMethod cMtd = cType.getCustomMethod(mtdKey);
    if (cMtd == null) {
      cMtd = new CustomMethod(mtdKey);
      cType.addCustomMethod(cMtd);
    }

    cMtd.setIsProperty(true);

    if (anno instanceof NormalAnnotation) {
      NormalAnnotation normalAnno = (NormalAnnotation) anno;
      List<?> annos = normalAnno.values();
      MemberValuePair pair = (MemberValuePair) annos.get(0);
      String name = getValue(pair.getValue(), astNode, jstType);
      if (name != null) {
        cMtd.setJstName(name);
        return;
      }
    }

    String mtdName = cMtd.getJstName();
    if (mtdName.startsWith("get")) {
      mtdName = mtdName.substring(3, 4).toLowerCase() + mtdName.substring(4, mtdName.length());
      cMtd.setJstName(mtdName);
    } else if (mtdName.startsWith("set")) {
      mtdName = mtdName.substring(3, 4).toLowerCase() + mtdName.substring(4, mtdName.length());
      cMtd.setJstName(mtdName);
    }
  }
Exemplo 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);
    }
  }