Exemplo n.º 1
0
  private String getValue(QualifiedName name, ASTNode astNode, final JstType jstType) {

    TranslateInfo tInfo = TranslateCtx.ctx().getTranslateInfo(jstType);

    String typeName = name.getQualifier().getFullyQualifiedName();
    String fullName = tInfo.getImported(typeName);
    try {
      Class<?> toClass = Class.forName(fullName);
      Field field = toClass.getField(name.getName().toString());
      return (String) field.get(toClass);
    } catch (SecurityException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (NoSuchFieldException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (ClassNotFoundException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IllegalArgumentException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IllegalAccessException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    return null;
  }
Exemplo n.º 2
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;
  }