cur = ((JArrayType)cur).getElementType(); emptyDims = Lists.add(emptyDims, JAbsentArrayDimension.INSTANCE); cur = ((JArrayType) cur).getElementType();
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(JClassLiteral x, Context ctx) { JType refType = translate(x.getRefType()); x.resolve(refType); // ImplementClassLiteralsAsFields: rescue enumType.values()/valueOf(). if (refType instanceof JArrayType) { JType leafType = ((JArrayType) refType).getLeafType(); if (leafType instanceof JReferenceType) { refType = leafType; } } if (refType instanceof JClassType) { JClassType classType = (JClassType) refType; JEnumType enumType = classType.isEnumOrSubclass(); if (enumType != null) { for (JMethod method : enumType.getMethods()) { if (method.isStatic()) { if (method.getSignature().startsWith("values()")) { flowInto(method); } else if (method.getSignature().startsWith("valueOf(Ljava/lang/String;)")) { flowInto(method); } } } } } }
cur = ((JArrayType)cur).getElementType(); emptyDims = Lists.add(emptyDims, JAbsentArrayDimension.INSTANCE); while (cur instanceof JArrayType) { cur = ((JArrayType) cur).getElementType();
@Override public JReferenceType translate(JReferenceType type) { if (type instanceof JNonNullType) { return translate(type.getUnderlyingType()).getNonNull(); } if (type instanceof JArrayType) { JArrayType arrayType = (JArrayType) type; return program.getTypeArray(translate(arrayType.getElementType())); } if (type.isExternal()) { if (type instanceof JDeclaredType) { type = translate((JDeclaredType) type); } else { assert false : "Unknown external type"; } assert !type.isExternal(); } return type; } @Override
while (cur instanceof JArrayType) { dims = Lists.add(dims, JAbsentArrayDimension.INSTANCE); cur = ((JArrayType)cur).getElementType(); JClassLiteral classLit = new JClassLiteral(info.makeChild(), cur); classLits = Lists.add(classLits, classLit); cur = ((JArrayType) cur).getElementType();
while (cur instanceof JArrayType) { dims = Lists.add(dims, JAbsentArrayDimension.INSTANCE); cur = ((JArrayType) cur).getElementType(); cur = arrayType; while (cur instanceof JArrayType) { cur = ((JArrayType) cur).getElementType();