/** * Finds an assimilates a class file from the given fully.qualified.Source.Name. * * Make sure you commit any {@link StandardGeneratorContext} before expecting to * find generated types this way. * * @throws NoClassDefFoundError if class is unavailable to gwt classpath */ @Override public JDeclaredType searchForTypeBySource(String sourceTypeName) { JDeclaredType type = program.getFromTypeMap(sourceTypeName); if (type == null) { CompiledClass cc = classFileMapBySource.get(sourceTypeName); if (cc == null) { // TODO: error throw new NoClassDefFoundError(sourceTypeName); } assimilateUnit(cc.getUnit()); type = program.getFromTypeMap(sourceTypeName); assert type != null || errorsFound; } return type; }
this.logger = logger; for (JMethod entryMethod : program.getEntryMethods()) { flowInto(entryMethod); instantiate(program.getTypeJavaLangString()); flowInto(program.getIndexedMethod("Object.toString")); mapApi(program.getTypeJavaLangString()); flowInto(methodMap.get("java.lang.String.valueOf(C)Ljava/lang/String;")); flowInto(program.getIndexedMethod("Enum.obfuscatedName")); flowInto(program.getIndexedMethod("AsyncFragmentLoader.onLoad")); flowInto(program.getIndexedMethod("AsyncFragmentLoader.runAsync")); staticInitialize(program.getTypeClassLiteralHolder()); for (JMethod method : program.getTypeJavaLangClass().getMethods()) { if (method.isStatic() && method.getName().startsWith("createFor")) { flowInto(method); for (Iterator<JDeclaredType> it = program.getDeclaredTypes().iterator(); it.hasNext();) { JDeclaredType type = it.next(); boolean isInstantiated = instantiatedTypes.contains(type);
private JDeclaredType index(final UnifyAstView ast) { if (intToListType != null) { return intToListType; } ast.getProgram().addIndexedTypeName(IntToListGwt.class.getName()); intToListType = ast.searchForTypeBySource(IntToListGwt.class.getName()); for (final JMethod method : intToListType.getMethods()) { if (method.getName().equals("create")) { createMethod = ast.translate(method); if (createForClassMethod != null) { break; } } else if (method.getName().equals("createForClass")) { createForClassMethod = ast.translate(method); if (createMethod != null) { break; } } } return intToListType; }
JMethod newMethod = new JMethod(methodSource, "enhanceAll", methodCall.getTarget().getEnclosingType(), ast.getProgram().getTypeVoid(), false, true, true, AccessModifier.PUBLIC); newMethod.setOriginalTypes(ast.getProgram().getTypeVoid(), methodCall.getTarget().getOriginalParamTypes()); JMethodBody body = new JMethodBody(methodSource); newMethod.setBody(body); JType asType = ast.getProgram().getFromTypeMap(cls.getQualifiedSourceName()); if (asType == null) { continue;
type = prog.getTypeArray(type);
@Override public void onUnifyAstStart(TreeLogger logger, UnifyAstView ast, UnifyVisitor visitor, Queue<JMethod> todo) { for (final JMethod method : ast.getProgram().getEntryMethods()) { if (method.getBody() instanceof JMethodBody) { JMethodBody body = (JMethodBody) method.getBody(); // obtain the entry point EntryPointFinder finder = findEntryPoint(logger); body.traverse(finder, finder.getContext()); // find a default strategy if (finder.result == null) { strategy = MagicClassGenerator.class.getAnnotation(ReflectionStrategy.class); } else { com.google.gwt.core.ext.typeinfo.JClassType type = ast.getTypeOracle().findType(finder.result.getName()); strategy = type.getAnnotation(ReflectionStrategy.class); if (strategy == null) { strategy = type.getPackage().getAnnotation(ReflectionStrategy.class); if (strategy == null) { // Nothing on the entry point or it's package; // use a default instance of the ReflectionStrategy annotation strategy = MagicClassGenerator.class.getAnnotation(ReflectionStrategy.class); } } } assert strategy != null; } } }
program.getDeclaredTypes().stream() .filter(type -> dontPrunePattern.matcher(type.getName()).matches()) .forEach(type -> {
out.setPayload(ast); final JPrimitiveType voidType = ast.getProgram().getTypeVoid(); final SimpleFifo<String> simpleNames = new SimpleFifo<String>();
private void assimilateUnit(CompilationUnit unit) { if (unit.isError()) { if (failedUnits.add(unit)) { CompilationProblemReporter.reportErrors(logger, unit, false); errorsFound = true; } return; } // TODO(zundel): ask for a recompile if deserialization fails? List<JDeclaredType> types = unit.getTypes(); assert containsAllTypes(unit, types); for (JDeclaredType t : types) { program.addType(t); } for (JDeclaredType t : types) { resolveType(t); } /* * Eagerly instantiate any JavaScriptObject subtypes. That way we don't have * to copy the exact semantics of ControlFlowAnalyzer. */ for (JDeclaredType t : types) { if (t instanceof JClassType && isJso((JClassType) t)) { instantiate(t); } } }
ast.getProgram().getTypeVoid(), false, true, true, AccessModifier.PUBLIC); newMethod.setOriginalTypes(ast.getProgram().getTypeVoid(), methodCall .getTarget().getOriginalParamTypes()); final JMethodBody body = new JMethodBody(methodSource); continue; final JType asType = ast.getProgram().getFromTypeMap( cls.getQualifiedSourceName()); if (asType == null) {
@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
@Override public void onUnifyAstStart(final TreeLogger logger, final UnifyAstView ast, final UnifyVisitor visitor, final Queue<JMethod> todo) { for (final JMethod method : ast.getProgram().getEntryMethods()) { if (method.getBody() instanceof JMethodBody) { final JMethodBody body = (JMethodBody) method.getBody(); // obtain the entry point final EntryPointFinder finder = findEntryPoint(logger); body.traverse(finder, finder.getContext()); // find a default strategy if (finder.result == null) { strategy = MagicClassGenerator.class.getAnnotation(ReflectionStrategy.class); } else { final com.google.gwt.core.ext.typeinfo.JClassType type = ast.getTypeOracle().findType(finder.result.getName()); strategy = type.getAnnotation(ReflectionStrategy.class); if (strategy == null) { strategy = type.getPackage().getAnnotation(ReflectionStrategy.class); if (strategy == null) { // Nothing on the entry point or it's package; // use a default instance of the ReflectionStrategy annotation strategy = MagicClassGenerator.class.getAnnotation(ReflectionStrategy.class); } } } assert strategy != null; } } }
/** * Compute all overrides. */ private void computeOverrides() { for (JDeclaredType type : program.getDeclaredTypes()) { Map<String, Set<JMethod>> collected = new HashMap<String, Set<JMethod>>(); for (JMethod method : type.getMethods()) { if (method.canBePolymorphic()) { collected.put(method.getSignature(), new LinkedHashSet<JMethod>()); } } collectUpRefsInSupers(type, collected); for (JMethod method : type.getMethods()) { if (method.canBePolymorphic()) { for (JMethod upref : collected.get(method.getSignature())) { if (canAccessSuperMethod(type, upref)) { method.addOverride(upref); } } } } } }
/** * Finds an assimilates a class file from the given fully.qualified.Binary$Name. * * Make sure you commit any {@link StandardGeneratorContext} before expecting to * find generated types this way. * * @throws NoClassDefFoundError if class is unavailable to gwt classpath */ @Override public JDeclaredType searchForTypeByBinary(String binaryTypeName) { JDeclaredType type = program.getFromTypeMap(binaryTypeName); if (type == null) { CompiledClass cc = classFileMap.get(BinaryName.toInternalName(binaryTypeName)); if (cc == null) { // TODO: error throw new NoClassDefFoundError(binaryTypeName); } assimilateUnit(cc.getUnit()); type = program.getFromTypeMap(binaryTypeName); assert type != null || errorsFound; } return type; }
type = prog.getTypeArray(type);
/** * Special AST construction, useful for tests. Everything is resolved, * translated, and unified. */ public void buildEverything(TreeLogger logger) throws UnableToCompleteException { this.logger = logger; for (String internalName : classFileMap.keySet()) { String typeName = InternalName.toBinaryName(internalName); searchForTypeByBinary(typeName); } for (JDeclaredType type : program.getDeclaredTypes()) { instantiate(type); for (JField field : type.getFields()) { flowInto(field); } for (JMethod method : type.getMethods()) { flowInto(method); } } mainLoop(); computeOverrides(); if (errorsFound) { throw new UnableToCompleteException(); } }
answer = answer.substring(0, answer.lastIndexOf('.') + 1) + "impl.AsyncProxy_" + names[names.length - 1]; JDeclaredType answerType = null; final JDeclaredType knownType = ast.getProgram().getFromTypeMap(answer);
JArrayType arrayType = ast.getProgram().getTypeArray(type);
answer = answer.substring(0, answer.lastIndexOf('.') + 1) + "impl.AsyncFor_" + names[names.length - 1]; JDeclaredType answerType = null; final JDeclaredType knownType = ast.getProgram().getFromTypeMap(answer);
final JArrayType arrayType = ast.getProgram().getTypeArray(type);