Esempio 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;
  }
Esempio n. 2
0
  //
  // API
  //
  public List<JstType> translate() {

    ITranslateTracer tracer = getTracer();
    tracer.startGroup(DECLARATION_PHASE);

    try {
      TranslateCtx ctx = getCtx();
      TranslationMode mode = getMode();

      String srcName;
      CompilationUnit cu;
      BaseTypeVisitor visitor;
      TranslateInfo tInfo;

      List<TypeVisitTask> tasks = new ArrayList<TypeVisitTask>();

      // Create tasks
      for (JstType jstType : getStartingTypes()) {
        if (jstType == null) {
          addError(new TranslateError(TranslateMsgId.NULL_INPUT, "jstType is null"));
          continue;
        }
        // Exclude visited types
        tInfo = ctx.getTranslateInfo(jstType);
        if (mode.hasDeclaration() && tInfo.getMode().hasDeclaration()
            || mode.hasDependency() && tInfo.getMode().hasDependency()) {
          continue;
        }
        cu = AstBindingHelper.getCompilationUnit(jstType);
        srcName = AstBindingHelper.getSourceName(jstType);
        ctx.getTranslateInfo(jstType).addMode(mode);
        visitor = createVisitor(jstType);
        tasks.add(new TypeVisitTask(srcName, cu, visitor, getTracer(jstType), ctx));
      }

      // Execute tasks
      if (tasks.size() == 1 || !ctx.isParallelEnabled()) {
        for (TypeVisitTask task : tasks) {
          task.execute();
          addDependency(task.getVisitor());
          setExceptions(task.getType(), task.getExceptions());
        }
      } else if (tasks.size() > 0) {
        TranslationParallelRunner.getInstance().execute(tasks);
        for (TypeVisitTask task : tasks) {
          addDependency(task.getVisitor());
          setExceptions(task.getType(), task.getExceptions());
        }
      }

      mergeTraces();

      return getDependentTypes();
    } finally {
      tracer.endGroup(DECLARATION_PHASE, getErrors());
    }
  }