public void positionStmtsAfterEnumInitStmts(List<Statement> staticFieldStatements) { MethodNode method = getOrAddStaticConstructorNode(); Statement statement = method.getCode(); if (statement instanceof BlockStatement) { BlockStatement block = (BlockStatement) statement; // add given statements for explicitly declared static fields just after enum-special fields // are found - the $VALUES binary expression marks the end of such fields. List<Statement> blockStatements = block.getStatements(); ListIterator<Statement> litr = blockStatements.listIterator(); while (litr.hasNext()) { Statement stmt = litr.next(); if (stmt instanceof ExpressionStatement && ((ExpressionStatement) stmt).getExpression() instanceof BinaryExpression) { BinaryExpression bExp = (BinaryExpression) ((ExpressionStatement) stmt).getExpression(); if (bExp.getLeftExpression() instanceof FieldExpression) { FieldExpression fExp = (FieldExpression) bExp.getLeftExpression(); if (fExp.getFieldName().equals("$VALUES")) { for (Statement tmpStmt : staticFieldStatements) { litr.add(tmpStmt); } } } } } } }
public Vset checkAmbigName( Environment env, Context ctx, Vset vset, Hashtable exp, UnaryExpression loc) { if (index == null) { vset = right.checkAmbigName(env, ctx, vset, exp, this); if (right.type == Type.tPackage) { FieldExpression.reportFailedPackagePrefix(env, right); return vset; } // Nope. Is this field expression a type? if (right instanceof TypeExpression) { Type atype = Type.tArray(right.type); loc.right = new TypeExpression(where, atype); return vset; } env.error(where, "array.index.required"); return vset; } return super.checkAmbigName(env, ctx, vset, exp, loc); }
public Class checkType(OOEEParsingContext context) throws ParsingException { ExpressionNode type = getChild(0); setValueClass(type.checkType(context)); ExpressionNode expr = getChild(1); Class fromClass = expr.checkType(context); if (!ExpressionUtil.isCastableFrom(valueClass, fromClass)) { throw new ParsingException( ExceptionConstants.EBOS_OOEE_070, new Object[] {fromClass, valueClass}); // throw new ParsingException("inconvertable cast from class " + fromClass + " to " + // valueClass); } // optimization code if (valueClass.isPrimitive() && expr.isConstant()) { super.isConstant = true; Object constantValue = expr.getConstantValue(); if (ExpressionUtil.isNumeric(valueClass)) { constantValue = ExpressionUtil.getNumericReturnObject(constantValue, valueClass); } super.setConstantValue(constantValue); } else { super.isConstant = false; } // fix bug if (expr instanceof FieldExpression && parent instanceof FieldExpression) { boolean isClass = ((FieldExpression) expr).isClass(); ((FieldExpression) parent).setIsClass(isClass); } return valueClass; }
public void visitFieldExpression(FieldExpression expression) { String name = expression.getFieldName(); // TODO: change that to get the correct scope Variable v = checkVariableNameForDeclaration(name, expression); checkVariableContextAccess(v, expression); }