public JMethod getThrowMethod(final TreeLogger logger, final UnifyAstView ast) { if (doThrow == null) { final JDeclaredType gwtReflect = ast.searchForTypeBySource(GwtReflect.class.getName()); for (final JMethod method : gwtReflect.getMethods()) { if (method.getName().equals("doThrow")) { doThrow = method; break; } } } return doThrow; } }
/** * TODO(scottb): move to UnifyAst and only for non-abstract classes. */ private void implementGetClass(JDeclaredType type) { JMethod method = type.getMethods().get(2); assert ("getClass".equals(method.getName())); SourceInfo info = method.getSourceInfo(); if ("com.google.gwt.lang.Array".equals(type.getName())) { /* * Don't implement, fall through to Object.getClass(). Array emulation code * in com.google.gwt.lang.Array invokes Array.getClass() and expects to get the * class literal for the actual runtime type of the array (e.g. Foo[].class) and * not Array.class. */ type.getMethods().remove(2); } else { implementMethod(method, new JClassLiteral(info, type)); } }
private void mapApi(JDeclaredType type) { assert !type.isExternal(); for (JField field : type.getFields()) { String sig = type.getName() + '.' + field.getSignature(); fieldMap.put(sig, field); for (JMethod method : type.getMethods()) { String sig = type.getName() + '.' + method.getSignature(); methodMap.put(sig, method); if (MAGIC_METHOD_CALLS.contains(sig)) {
public static String toSourceName(final JDeclaredType type) { final JDeclaredType enclosing = type.getEnclosingType(); if (enclosing == null) { return type.getName(); } return toSourceName(enclosing) + "." + type.getShortName(); }
@Override public JDeclaredType translate(JDeclaredType type) { if (!type.isExternal()) { return type; } String typeName = type.getName(); JDeclaredType newType = searchForTypeByBinary(typeName); if (newType == null) { assert errorsFound; return type; } assert !newType.isExternal(); return newType; } @Override
private void collectUpRefsInSupers(JDeclaredType type, Map<String, Set<JMethod>> collected) { collectUpRefs(type.getSuperClass(), collected); for (JInterfaceType intfType : type.getImplements()) { collectUpRefs(intfType, collected); } }
final String[] names = type.getShortName().split("[$]"); for (final JMethod method : lazyProvider.getMethods()) { if (method.getName().equals("get")) { final String targetName = "singleton" + type.getShortName().replaceAll("[$]", "_"); for (final JMethod existingMethod : enclosing.getMethods()) { if (existingMethod.getName().equals(existingMethod)) { getSingleton = existingMethod; AccessModifier.PRIVATE); enclosing.addMethod(getSingleton); if (enclosing.getClinitTarget() != null) { final JDeclaredType clinit = enclosing.getClinitTarget(); final JMethod clinitMethod = clinit.getMethods().get(0); assert (JProgram.isClinit(clinitMethod)); final JMethodCall doClinit = new JMethodCall(clinit.getSourceInfo(), null, clinitMethod); body.getBlock().addStmt(doClinit.makeStatement());
final String[] names = type.getShortName().split("[$]"); logger.log(logLevel(), "Rebinding singleton w/ callback: " + type + " -> " + provider.getName()); ast.searchForTypeBySource(type.getName()); ast.searchForTypeBySource(BinaryName.toSourceName(provider.getName())); try { InjectionCallbackArtifact rebindResult; try { logger.log(logLevel(), "Loading injected result: " + provider.getName()); rebindResult = AsyncProxyGenerator.setupAsyncCallback(logger, ctx, ctx.getTypeOracle().findType(BinaryName.toSourceName(type.getName())), ((JDeclaredType)receiverLiteral.getRefType())); } catch (final ClassNotFoundException e) { type.getName() + " has a subclass on the classpath which contains @SingletonOverride or @SingletonDefault annotations."); return null; logger.log(Type.ERROR, "Error trying to generator provider for " + type.getName() + ". " + "\nPlease make sure this class is non-abstract, or that a concrete class on the classpath " + "is annotated with @SingletonOverride or @SingletonDefault", e); for (final JMethod method : answerType.getMethods()) { if (method.getName().equals("go")) {
for (JMethod method : gwtReflect.getMethods()) { if (method.getName().equals("magicClass")) { magicClass = method; methodCall.getTarget().getEnclosingType().addMethod(newMethod); JMethodCall call = new JMethodCall(methodSource, null, newMethod);
private void staticInitialize(JDeclaredType type) { if (type.isExternal()) { assert errorsFound; return; } JMethod clinit = type.getMethods().get(0); if (!liveFieldsAndMethods.contains(clinit)) { flowInto(clinit); if (type.getSuperClass() != null) { staticInitialize(type.getSuperClass()); } for (JNode node : type.getArtificialRescues()) { if (node instanceof JType) { if (node instanceof JDeclaredType) { instantiate((JDeclaredType) node); } } else if (node instanceof JField) { JField field = (JField) node; flowInto(field); if (!field.isFinal()) { field.setVolatile(); } } else if (node instanceof JMethod) { flowInto((JMethod) node); } else { assert false : "Unknown artificial rescue node."; } } } }
private void instantiate(JDeclaredType type) { if (type.isExternal()) { assert errorsFound; return; if (type.getSuperClass() != null) { instantiate(type.getSuperClass()); for (JInterfaceType intf : type.getImplements()) { instantiate(intf); for (JMethod method : type.getMethods()) { if (method.canBePolymorphic()) { String signature = method.getSignature();
private static boolean isGetMagicClass(JMethod target) { return (target.getName().equals("magicClass") && target.getEnclosingType().getName().equals(GwtReflect.class.getName())) || (target.getName().equals("enhanceClass") && target.getEnclosingType().getName().endsWith(ReflectionUtilJava.MAGIC_CLASS_SUFFIX)) ; }
JDeclaredType type = it.next(); boolean isInstantiated = instantiatedTypes.contains(type); for (int i = 0; i < type.getFields().size(); ++i) { JField field = type.getFields().get(i); if (!liveFieldsAndMethods.contains(field) || (!field.isStatic() && !isInstantiated)) { type.removeField(i); --i; JMethod clinit = type.getMethods().get(0); if (!liveFieldsAndMethods.contains(clinit)) { clinit.setBody(new JMethodBody(SourceOrigin.UNKNOWN)); for (int i = 1; i < type.getMethods().size(); ++i) { JMethod method = type.getMethods().get(i); if (!liveFieldsAndMethods.contains(method) || (!method.isStatic() && !isInstantiated)) { type.removeMethod(i); --i;
final String[] names = type.getShortName().split("[$]"); final StandardGeneratorContext ctx = ast.getRebindPermutationOracle().getGeneratorContext(); ast.searchForTypeBySource(type.getName()); try { final RebindResult rebindResult = ctx.runGeneratorIncrementally(logger, generator, type.getName()); type.getName() + " has a subclass on the classpath which contains @SingletonOverride or @SingletonDefault annotations."); throw new UnableToCompleteException(); logger.log(Type.ERROR, "Error trying to generator provider for " + type.getName() + ". " + "\nPlease make sure this class is non-abstract, or that a concrete class on the classpath " + "is annotated with @SingletonOverride or @SingletonDefault", e); throw new UnableToCompleteException(); if (answerType.isAbstract()) { ast.error(methodCall, "Rebind result '" + answer + "' cannot be abstract"); throw new UnableToCompleteException(); logger.log(logLevel(), "Injecting asynchronous singleton for " + type.getName() + " -> " + answerType); return answerType;
private void createMembers(TypeDeclaration x) { SourceTypeBinding binding = x.binding; JDeclaredType type = (JDeclaredType) typeMap.get(binding); SourceInfo info = type.getSourceInfo(); try { assert type.getMethods().size() == 0; createSyntheticMethod(info, "$clinit", type, JPrimitiveType.VOID, false, true, true, AccessModifier.PRIVATE); assert type.getMethods().size() == 1; createSyntheticMethod(info, "$init", type, JPrimitiveType.VOID, false, false, true, AccessModifier.PRIVATE); assert type.getMethods().size() == 2; createSyntheticMethod(info, "getClass", type, javaLangClass, false, false, false, AccessModifier.PUBLIC); assert type.getMethods().size() == 3; MethodBinding valueOfBinding = binding.getExactMethod(VALUE_OF, new TypeBinding[]{x.scope.getJavaLangString()}, assert type.getMethods().size() == 4; MethodBinding valuesBinding = binding.getExactMethod(VALUES, NO_TYPES, curCud.scope); assert valuesBinding != null; StringBuffer sb = new StringBuffer(); x.printHeader(0, sb); ice.addNode(x.getClass().getName(), sb.toString(), type.getSourceInfo()); throw ice;
/** * 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(); } }
public JConstructor findConstructor(final TreeLogger logger, final String sourceTypeName, final String signature, final UnifyAstView ast) throws UnableToCompleteException { JConstructor constructor = constructors.get(signature); if (constructor != null) { return constructor; } final JDeclaredType clazz = ast.searchForTypeBySource(sourceTypeName); if (clazz == null) { logger.log(Type.ERROR, "Unable to find type "+sourceTypeName+" using source name lookup for constructor "+signature); throw new UnableToCompleteException(); } constructor = (JConstructor) clazz.findMethod(signature, false); if (constructor == null) { logger.log(Type.ERROR, "Unable to find constructor " + signature + " in "+sourceTypeName+"\n"+clazz.getMethods()); for (final JMethod method : clazz.getMethods()) { logger.log(Type.ERROR, "Meow "+method.getSignature()); } throw new UnableToCompleteException(); } constructors.put(signature, constructor); return constructor; }
final StandardGeneratorContext ctx = ast.getRebindPermutationOracle().getGeneratorContext(); ast.searchForTypeBySource(type.getName()); JDeclaredType injectedInstance; try { final RebindResult result = ctx.runGeneratorIncrementally(logger, generator, type.getName()); logger.log(Type.ERROR, "Error trying to generate provider for " + type.getName() + ". " + "\nPlease make sure this class is non-abstract, or that a concrete class on the classpath " + "is annotated with @SingletonOverride or @SingletonDefault", e); if (injectedInstance.isAbstract()) { ast.error(x, "Rebind result '" + instanceType + "' cannot be abstract"); throw new InternalCompilerException("Unable to generate instance provider"); final String reqType = BinaryName.toSourceName(injectedInstance.getName()); List<String> answers; try { if (answerType.isAbstract()) { ast.error(x, "Rebind result '" + answer + "' cannot be abstract"); return null; JDeclaredType enclosing = injectedInstance.getEnclosingType(); if (enclosing == null) { enclosing = method.getEnclosingType();
private void resolveType(JDeclaredType type) { assert !type.isExternal(); if (type instanceof JClassType && type.getSuperClass() != null) { ((JClassType) type).setSuperClass(translate(type.getSuperClass())); } List<JInterfaceType> resolvedInterfaces = new ArrayList<JInterfaceType>(); for (JInterfaceType intf : type.getImplements()) { resolvedInterfaces.add((JInterfaceType) translate(intf)); } List<JNode> resolvedRescues = new ArrayList<JNode>(); for (JNode node : type.getArtificialRescues()) { if (node instanceof JType) { node = translate((JType) node); } else if (node instanceof JField) { node = translate((JField) node); } else if (node instanceof JMethod) { node = translate((JMethod) node); } else { assert false : "Unknown artificial rescue node."; } resolvedRescues.add(node); } type.resolve(resolvedInterfaces, resolvedRescues); }
logger.branch(Type.TRACE, "Binding callback " + callbackType.getName() + " to " + singletonType.getQualifiedSourceName()); logger.log(Type.WARN, "Checking " + callbackType.getName() + " : " + callbackType.getJavahSignatureName()); JClassType providerType = context.getTypeOracle().findType(SourceUtil.toSourceName(callbackType.getName())); for (JClassType subtype : providerType.getSubtypes()) { if (winningCallback == null) {