Пример #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);
    }
  }
Пример #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);
    }
  }
Пример #3
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);
  }
Пример #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);
      }
    }
  }