private JFieldRef makeInstanceFieldRef(SourceInfo info, JField field) { return new JFieldRef(info, makeThisRef(info), field, curClass.classType); }
@Override public void endVisit(JFieldRef x, Context ctx) { JField field = translate(x.getField()); flowInto(field); x.resolve(field); // Should not have an overridden type at this point. assert x.getType() == x.getField().getType(); assert !x.getEnclosingType().isExternal(); }
private JBinaryOperation assignSyntheticField(SourceInfo info, SyntheticArgumentBinding arg) { JParameter param = (JParameter) curMethod.locals.get(arg); assert param != null; JField field = curClass.syntheticFields.get(arg); assert field != null; JFieldRef lhs = makeInstanceFieldRef(info, field); JParameterRef rhs = new JParameterRef(info, param); JBinaryOperation asg = new JBinaryOperation(info, lhs.getType(), JBinaryOperator.ASG, lhs, rhs); return asg; }
com.google.gwt.dev.jjs.ast.JField field = ((JFieldRef)inst).getField(); if (field.isExternal()) { field = ast.translate(field);
private void writeEnumValuesMethod(JEnumType type, JMethod method, JField valuesField) { // return $VALUES; JFieldRef valuesRef = new JFieldRef(method.getSourceInfo(), null, valuesField, type); implementMethod(method, valuesRef); } }
private JField createEnumValuesField(JEnumType type) { // $VALUES = new E[]{A,B,B}; JArrayType enumArrayType = new JArrayType(type); JField valuesField = new JField(type.getSourceInfo(), "$VALUES", type, enumArrayType, true, Disposition.FINAL); type.addField(valuesField); SourceInfo info = type.getSourceInfo(); List<JExpression> initializers = new ArrayList<JExpression>(); for (JEnumField field : type.getEnumList()) { JFieldRef fieldRef = new JFieldRef(info, null, field, type); initializers.add(fieldRef); } JNewArray newExpr = JNewArray.createInitializers(info, enumArrayType, initializers); JFieldRef valuesRef = new JFieldRef(info, null, valuesField, type); JDeclarationStatement declStmt = new JDeclarationStatement(info, valuesRef, newExpr); JBlock clinitBlock = ((JMethodBody) type.getClinitMethod().getBody()).getBlock(); /* * HACKY: the $VALUES array must be initialized immediately after all of * the enum fields, but before any user initialization (which might rely * on $VALUES). The "1 + " is the statement containing the call to * Enum.$clinit(). */ int insertionPoint = 1 + type.getEnumList().size(); assert clinitBlock.getStatements().size() >= initializers.size() + 1; clinitBlock.addStmt(insertionPoint, declStmt); return valuesField; }
@Override public void endVisit(FieldDeclaration x, MethodScope scope) { try { JExpression initialization = pop(x.initialization); JField field = typeMap.get(x.binding); if (field instanceof JEnumField) { // An enum field must be initialized! assert (initialization instanceof JNewInstance); } if (initialization != null) { SourceInfo info = makeSourceInfo(x); JExpression instance = null; if (!x.isStatic()) { instance = makeThisRef(info); } // JDeclarationStatement's ctor sets up the field's initializer. JStatement decl = new JDeclarationStatement(info, new JFieldRef(info, instance, field, curClass.type), initialization); // will either be init or clinit curMethod.body.getBlock().addStmt(decl); } popMethodInfo(); } catch (Throwable e) { throw translateException(x, e); } }
@Override public void endVisit(FieldReference x, BlockScope scope) { try { FieldBinding fieldBinding = x.binding; SourceInfo info = makeSourceInfo(x); JExpression instance = pop(x.receiver); JExpression expr; if (fieldBinding.declaringClass == null) { if (!ARRAY_LENGTH_FIELD.equals(String.valueOf(fieldBinding.name))) { throw new InternalCompilerException("Expected [array].length."); } expr = new JArrayLength(info, instance); } else { JField field = typeMap.get(fieldBinding); expr = new JFieldRef(info, instance, field, curClass.type); } if (x.genericCast != null) { JType castType = typeMap.get(x.genericCast); /* * Note, this may result in an invalid AST due to an LHS cast * operation. We fix this up in FixAssignmentToUnbox. */ expr = maybeCast(castType, expr); } push(expr); } catch (Throwable e) { throw translateException(x, e); } }
} else { JField field = typeMap.get(fieldBinding); curRef = new JFieldRef(info, curRef, field, curClass.type);
call.addArg(new JFieldRef(info, null, valuesField, mapClass)); JFieldRef mapRef = new JFieldRef(info, null, mapField, mapClass); JDeclarationStatement declStmt = new JDeclarationStatement(info, mapRef, call); JMethod clinit = assert valueOfBinding != null; JFieldRef mapRef = new JFieldRef(info, null, mapField, type); JParameterRef nameRef = new JParameterRef(info, method.getParams().get(0)); JMethodCall call = new JMethodCall(info, null, typeMap.get(valueOfBinding));
JField field = typeMap.get(fieldBinding); assert field != null; ref = new JFieldRef(info, ref, field, curClass.classType); type = (ReferenceBinding) fieldBinding.type.erasure();
thisRef = makeThisReference(info, (ReferenceBinding) x.actualReceiverType, false, scope); result = new JFieldRef(info, thisRef, field, curClass.type); } else { return null;
return new JFieldRef(callSite.getSourceInfo().makeChild(), null, field, type);