コード例 #1
0
ファイル: Java5.java プロジェクト: bodiam/discobot
 private void configureAnnotationFromDefinition(AnnotationNode definition, AnnotationNode root) {
   ClassNode type = definition.getClassNode();
   if (!type.isResolved()) return;
   Class clazz = type.getTypeClass();
   if (clazz == Retention.class) {
     Expression exp = definition.getMember("value");
     if (!(exp instanceof PropertyExpression)) return;
     PropertyExpression pe = (PropertyExpression) exp;
     String name = pe.getPropertyAsString();
     RetentionPolicy policy = RetentionPolicy.valueOf(name);
     setRetentionPolicy(policy, root);
   } else if (clazz == Target.class) {
     Expression exp = definition.getMember("value");
     if (!(exp instanceof ListExpression)) return;
     ListExpression le = (ListExpression) exp;
     int bitmap = 0;
     for (Expression e : le.getExpressions()) {
       PropertyExpression element = (PropertyExpression) e;
       String name = element.getPropertyAsString();
       ElementType value = ElementType.valueOf(name);
       bitmap |= getElementCode(value);
     }
     root.setAllowedTargets(bitmap);
   }
 }
コード例 #2
0
  private Expression transformInlineConstants(Expression exp) {
    if (exp instanceof PropertyExpression) {
      PropertyExpression pe = (PropertyExpression) exp;
      if (pe.getObjectExpression() instanceof ClassExpression) {
        ClassExpression ce = (ClassExpression) pe.getObjectExpression();
        ClassNode type = ce.getType();
        if (type.isEnum()) return exp;
        Expression constant = findConstant(type.getField(pe.getPropertyAsString()));
        // GRECLIPSE edit
        // if (constant != null) return constant;
        if (constant != null) {
          String name = pe.getText().replace('$', '.');
          Object alias = pe.getNodeMetaData("static.import.alias");
          if (alias != null && !alias.equals(pe.getPropertyAsString())) {
            name += " as " + alias;
          }
          // store the qualified name to facilitate organizing static imports
          constant.setNodeMetaData("static.import", name);

          return constant;
        }
        // GRECLIPSE end
      }
    } else if (exp instanceof ListExpression) {
      ListExpression le = (ListExpression) exp;
      ListExpression result = new ListExpression();
      for (Expression e : le.getExpressions()) {
        result.addExpression(transformInlineConstants(e));
      }
      return result;
    }

    return exp;
  }
コード例 #3
0
 /**
  * a property on "this", like this.x is transformed to a direct field access, so we need to check
  * the static context here
  *
  * @param pe the property expression to check
  */
 private void checkPropertyOnExplicitThis(PropertyExpression pe) {
   if (!currentScope.isInStaticContext()) return;
   Expression object = pe.getObjectExpression();
   if (!(object instanceof VariableExpression)) return;
   VariableExpression ve = (VariableExpression) object;
   if (!ve.getName().equals("this")) return;
   String name = pe.getPropertyAsString();
   if (name == null || name.equals("class")) return;
   Variable member = findClassMember(currentClass, name);
   if (member == null) return;
   checkVariableContextAccess(member, pe);
 }
コード例 #4
0
  @SuppressWarnings("unchecked")
  public <T extends Enum> T getEnumMemberValue(
      AnnotationNode node, String name, Class<T> type, T defaultValue) {
    if (node == null) return defaultValue;

    final PropertyExpression member = (PropertyExpression) node.getMember(name);
    if (member == null) return defaultValue;

    if (!type.equals(member.getObjectExpression().getType().getTypeClass())) return defaultValue;

    try {
      String value = member.getPropertyAsString();
      Method fromString = type.getMethod("valueOf", String.class);
      return (T) fromString.invoke(null, value);
    } catch (Exception e) {
      return defaultValue;
    }
  }
コード例 #5
0
  private Expression transformInlineConstants(Expression exp) {
    if (exp instanceof PropertyExpression) {
      PropertyExpression pe = (PropertyExpression) exp;
      if (pe.getObjectExpression() instanceof ClassExpression) {
        ClassExpression ce = (ClassExpression) pe.getObjectExpression();
        ClassNode type = ce.getType();
        if (type.isEnum()) return exp;
        Expression constant = findConstant(type.getField(pe.getPropertyAsString()));
        if (constant != null) return constant;
      }
    } else if (exp instanceof ListExpression) {
      ListExpression le = (ListExpression) exp;
      ListExpression result = new ListExpression();
      for (Expression e : le.getExpressions()) {
        result.addExpression(transformInlineConstants(e));
      }
      return result;
    }

    return exp;
  }