public static JProgram construct( TreeLogger logger, CompilationState state, Properties properties, String... entryPoints) throws UnableToCompleteException { PrecompileTaskOptions options = new PrecompileTaskOptionsImpl(); options.setEnableAssertions(true); JProgram jprogram = AstConstructor.construct(logger, state, options, properties); // Add entry methods for entry points. for (String entryPoint : entryPoints) { JDeclaredType entryType = jprogram.getFromTypeMap(entryPoint); for (JMethod method : entryType.getMethods()) { if (method.isStatic() && JProgram.isClinit(method)) { jprogram.addEntryMethod(method); } } } // Tree is now ready to optimize. return jprogram; }
private JMethodCall createClinitCall(JMethodCall x) { JDeclaredType targetType = x.getTarget().getEnclosingType().getClinitTarget(); if (!getCurrentMethod().getEnclosingType().checkClinitTo(targetType)) { // Access from this class to the target class won't trigger a clinit return null; } if (program.isStaticImpl(x.getTarget()) && !x.getTarget().getEnclosingType().isJsoType()) { // No clinit needed; target is really a non-jso instance method. return null; } if (JProgram.isClinit(x.getTarget())) { // This is a clinit call, doesn't need another clinit return null; } JMethod clinit = targetType.getClinitMethod(); // If the clinit is a non-native, empty body we can optimize it out here if (!clinit.isNative() && (((JMethodBody) clinit.getBody())).getStatements().size() == 0) { return null; } return new JMethodCall(x.getSourceInfo(), null, clinit); }