Esempio n. 1
0
  protected IValue resolveFieldAccess(MarkerList markers, IContext context) {
    IDataMember field = ICall.resolveField(context, this.instance, this.name);
    if (field != null) {
      if (field.isEnumConstant()) {
        EnumValue enumValue = new EnumValue(this.position);
        enumValue.name = this.name;
        enumValue.type = field.getType();
        return enumValue;
      }

      this.field = field;
      return this;
    }

    IMethod method =
        ICall.resolveMethod(context, this.instance, this.name, EmptyArguments.INSTANCE);
    if (method != null) {
      AbstractCall mc = this.toMethodCall(method);
      mc.checkArguments(markers, context);
      return mc;
    }

    if (this.instance == null) {
      IClass iclass = IContext.resolveClass(context, this.name);
      if (iclass != null) {
        return new ClassAccess(this.position, iclass.getType());
      }
    }

    return null;
  }
Esempio n. 2
0
  @Override
  public synchronized IClass resolveClass(Name name) {
    for (IClass iclass : this.classes) {
      if (iclass.getName() == name) {
        return iclass;
      }
    }

    IClass iclass = super.resolveClass(name);
    if (iclass != null) {
      return iclass;
    }
    return this.loadClass(name.qualified);
  }
Esempio n. 3
0
  @Override
  public synchronized IClass resolveClass(String name) {
    Name name1 = Name.getQualified(name);
    for (IClass iclass : this.classes) {
      if (name1 == iclass.getName()) {
        return iclass;
      }
    }

    IClass c = super.resolveClass(name);
    if (c != null) {
      return c;
    }

    return this.loadClass(name);
  }
Esempio n. 4
0
  @Override
  public void writeGet(MethodWriter writer, IValue instance, int lineNumber)
      throws BytecodeException {
    if (this.refType != null) {
      writer.writeVarInsn(Opcodes.ALOAD, this.index);

      IClass c = this.refType.getTheClass();
      IDataMember f = c.getBody().getField(0);
      f.writeGet(writer, null, lineNumber);

      if (c == Types.OBJECT_REF_CLASS) {
        c = this.type.getTheClass();
        if (c != Types.OBJECT_CLASS) {
          writer.writeTypeInsn(Opcodes.CHECKCAST, c.getInternalName());
        }
      }
      return;
    }

    writer.writeVarInsn(this.type.getLoadOpcode(), this.index);
  }
Esempio n. 5
0
  @Override
  public void parse(IParserManager pm, IToken token) throws SyntaxError {
    int type = token.type();
    if (this.isInMode(MODIFIERS)) {
      int i = 0;
      if ((i = ModifierTypes.CLASS.parse(type)) != -1) {
        this.theClass.addModifier(i);
        return;
      }
      if ((i = ModifierTypes.CLASS_TYPE.parse(type)) != -1) {
        this.theClass.addModifier(i);
        this.theClass.setMetadata(
            IClass.getClassMetadata(this.theClass, this.theClass.getModifiers()));
        this.mode = NAME;
        return;
      }
      if (token.nameValue() == Name.at) {
        Annotation annotation = new Annotation(token.raw());
        this.theClass.addAnnotation(annotation);
        pm.pushParser(new AnnotationParser(annotation));
        return;
      }
    }
    if (this.isInMode(NAME)) {
      if (ParserUtil.isIdentifier(type)) {
        this.theClass.setPosition(token.raw());
        this.theClass.setName(token.nameValue());
        this.classList.addClass(this.theClass);
        this.mode = PARAMETERS | GENERICS | EXTENDS | IMPLEMENTS | BODY;
        return;
      }
      throw new SyntaxError(token, "Invalid Class Declaration - Name expected");
    }
    if (this.isInMode(PARAMETERS)) {
      if (type == Symbols.OPEN_PARENTHESIS) {
        pm.pushParser(new ParameterListParser(this.theClass));
        this.mode = PARAMETERS_END;
        return;
      }
    }
    if (this.isInMode(PARAMETERS_END)) {
      this.mode = GENERICS | EXTENDS | IMPLEMENTS | BODY;
      if (type == Symbols.CLOSE_PARENTHESIS) {
        return;
      }
      throw new SyntaxError(token, "Invalid Class Parameter List - ')' expected", true);
    }
    if (this.isInMode(GENERICS)) {
      if (type == Symbols.OPEN_SQUARE_BRACKET) {
        pm.pushParser(new TypeVariableListParser(this.theClass));
        this.theClass.setGeneric();
        this.mode = GENERICS_END;
        return;
      }
    }
    if (this.isInMode(GENERICS_END)) {
      this.mode = PARAMETERS | EXTENDS | IMPLEMENTS | BODY;
      if (type == Symbols.CLOSE_SQUARE_BRACKET) {
        return;
      }
      throw new SyntaxError(token, "Invalid Generic Type Variable List - ']' expected", true);
    }
    if (this.isInMode(EXTENDS)) {
      if (type == Keywords.EXTENDS) {
        if (this.theClass.hasModifier(Modifiers.INTERFACE_CLASS)) {
          pm.pushParser(new TypeListParser(this));
          this.mode = BODY;
          return;
        }

        pm.pushParser(new TypeParser(this));
        this.mode = IMPLEMENTS | BODY;
        return;
      }
    }
    if (this.isInMode(IMPLEMENTS)) {
      if (type == Keywords.IMPLEMENTS) {

        pm.pushParser(new TypeListParser(this));
        this.mode = BODY;

        if (this.theClass.hasModifier(Modifiers.INTERFACE_CLASS)) {
          throw new SyntaxError(
              token, "Interfaces cannot implement other interfaces - Use 'extends' instead");
        }
        return;
      }
    }
    if (this.isInMode(BODY)) {
      if (type == Symbols.OPEN_CURLY_BRACKET) {
        IClassBody body = new ClassBody(this.theClass);
        this.theClass.setBody(body);
        pm.pushParser(new ClassBodyParser(this.theClass, body));
        this.mode = BODY_END;
        return;
      }
      if (ParserUtil.isTerminator(type)) {
        if (token.isInferred()) {
          int nextType = token.next().type();
          switch (nextType) {
            case Keywords.EXTENDS:
              this.mode = EXTENDS;
              return;
            case Keywords.IMPLEMENTS:
              this.mode = IMPLEMENTS;
              return;
            case Symbols.OPEN_SQUARE_BRACKET:
              this.mode = GENERICS;
              return;
            case Symbols.OPEN_PARENTHESIS:
              this.mode = PARAMETERS;
              return;
          }
        }

        pm.popParser();
        this.theClass.expandPosition(token);
        return;
      }
      throw new SyntaxError(token, "Invalid Class Declaration - '{' or ';' expected", true);
    }
    if (this.isInMode(BODY_END)) {
      if (type == Symbols.CLOSE_CURLY_BRACKET) {
        pm.popParser();
        this.theClass.expandPosition(token);
        return;
      }
      throw new SyntaxError(token, "Invalid Class Declaration - '}' expected", true);
    }
  }