@Override public void endVisit(JNewInstance x, Context ctx) { flowInto(x.getTarget()); assert !x.getEnclosingType().isExternal() : "External type, "+x.getEnclosingType()+", set to enclose "+x.getTarget() +" for "+x.getTarget().getEnclosingType().toSource(); }
private JMethod createSyntheticMethod(SourceInfo info, String name, JDeclaredType enclosingType, JType returnType, boolean isAbstract, boolean isStatic, boolean isFinal, AccessModifier access) { JMethod method = new JMethod(info, name, enclosingType, returnType, isAbstract, isStatic, isFinal, access); method.freezeParamTypes(); method.setSynthetic(); method.setBody(new JMethodBody(info)); enclosingType.addMethod(method); return method; }
private void implementMethod(JMethod method, JExpression returnValue) { JMethodBody body = (JMethodBody) method.getBody(); JBlock block = body.getBlock(); SourceInfo info; if (block.getStatements().size() > 0) { info = block.getStatements().get(0).getSourceInfo(); } else { info = method.getSourceInfo(); } block.clear(); block.addStmt(new JReturnStatement(info, returnValue)); }
private JMethod createSyntheticMethodFromBinding(SourceInfo info, MethodBinding binding, String[] paramNames) { JMethod method = typeMap.createMethod(info, binding, paramNames); assert !method.isExternal(); method.setBody(new JMethodBody(info)); typeMap.setMethod(binding, method); return method; }
@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(); }
@Override public boolean visit(JClassLiteral x, Context ctx) { result = (JClassType)x.getRefType(); return false; }
@Override public JExpression injectMagic(TreeLogger logger, JMethodCall methodCall, JMethod currentMethod, Context context, UnifyAstView ast) throws UnableToCompleteException { // TODO throw in some kind of property-based "choose your own default" here. return currentMethod.getOriginalReturnType().getDefaultValue(); }
private void writeEnumValuesMethod(JEnumType type, JMethod method, JField valuesField) { // return $VALUES; JFieldRef valuesRef = new JFieldRef(method.getSourceInfo(), null, valuesField, type); implementMethod(method, valuesRef); } }
private JExpression maybeCast(JType expected, JExpression expression) { if (expected != expression.getType()) { // Must be a generic; insert a cast operation. JReferenceType toType = (JReferenceType) expected; return new JCastOperation(expression.getSourceInfo(), toType, expression); } else { return expression; } }
@Override public void endVisit(JConstructor x, Context ctx) { // Process as method. super.endVisit(x, ctx); instantiate(x.getEnclosingType()); }
@Override public void endVisit(JExpression x, Context ctx) { assert !x.getType().isExternal() || errorsFound; }
private boolean isJso(JClassType type) { if (type == null) { return false; } return type == program.getJavaScriptObject() || isJso(type.getSuperClass()); }
@Override public void endVisit(JStringLiteral x, Context ctx) { JClassType stringType = program.getTypeJavaLangString(); x.resolve(stringType); instantiate(stringType); }
@Override public void endVisit(JThisRef x, Context ctx) { assert !x.getType().isExternal(); }
private JDeclarationStatement makeDeclaration(SourceInfo info, JLocal local, JExpression value) { return new JDeclarationStatement(info, new JLocalRef(info, local), value); }
@Override public boolean visit(JReboundEntryPoint x, Context ctx) { pastRebound = true; x.getEntryCalls().get(0).traverse(this, ctx);; return false; }
private void implementMagicMethod(JMethod method, JExpression returnValue) { JMethodBody body = (JMethodBody) method.getBody(); JBlock block = body.getBlock(); SourceInfo info; if (block.getStatements().size() > 0) { info = block.getStatements().get(0).getSourceInfo(); } else { info = method.getSourceInfo(); } block.clear(); block.addStmt(new JReturnStatement(info, returnValue)); }
@Override public boolean visit(JClassLiteral x, Context ctx) { result = (JClassType)x.getRefType(); return false; }