private void collectUpRefs(JDeclaredType type, Map<String, Set<JMethod>> collected) { if (type == null) { return; } for (JMethod method : type.getMethods()) { if (method.canBePolymorphic()) { Set<JMethod> set = collected.get(method.getSignature()); if (set != null) { set.add(method); } } } collectUpRefsInSupers(type, collected); }
/** * 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); } } } } } }
@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); } } } } } }
String sig = type.getName() + '.' + method.getSignature(); methodMap.put(sig, method); if (MAGIC_METHOD_CALLS.contains(sig)) {
@Override public JMethod translate(JMethod method) { if (!method.isExternal()) { return method; } JDeclaredType enclosingType = method.getEnclosingType(); String sig = enclosingType.getName() + '.' + method.getSignature(); JMethod newMethod = methodMap.get(sig); if (newMethod != null) { return newMethod; } enclosingType = translate(enclosingType); if (enclosingType.isExternal()) { assert errorsFound; return method; } mapApi(enclosingType); // Now the method should be there. method = methodMap.get(sig); if (method == null) { // TODO: error logging throw new NoSuchMethodError(sig); } assert !method.isExternal(); return method; } @Override
staticInitialize(method.getEnclosingType()); } else if (method.canBePolymorphic()) { String signature = method.getSignature(); if (!virtualMethodsLive.contains(signature)) { virtualMethodsLive.add(signature);
private JExpression handleMagicMethodCall(JMethodCall x, Context ctx) { JMethod target = x.getTarget(); String sig = target.getEnclosingType().getName() + '.' + target.getSignature(); if (GWT_CREATE.equals(sig) || OLD_GWT_CREATE.equals(sig)) { return handleGwtCreate(x); } else if (IMPL_GET_NAME_OF.equals(sig)) { return handleImplNameOf(x); } else if (magicMethodMap.containsKey(sig)){ MagicMethodGenerator method = magicMethodMap.get(sig); try { JExpression expr = method.injectMagic(logger, x, currentMethod, ctx, UnifyAst.this); if (logger.isLoggable(Type.DEBUG)){ logger.log(Type.DEBUG, "Magic method "+method +" converted:\n"+x+"\ninto: "+expr); } if (expr instanceof JMethodCall) { flowInto(((JMethodCall)expr).getTarget()); } return expr; } catch (Exception e) { logger.log(Type.ERROR, "Fatal error calling magic method "+method+" on "+x, e); throw new InternalCompilerException("Unable to implement magic method "+method+"()", e); } } throw new InternalCompilerException("Unknown magic method error"); } }
String signature = method.getSignature(); if (virtualMethodsLive.contains(signature)) { assert !virtualMethodsPending.containsKey(signature);
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; }
+ "of an IntTo class @ "+enclosingMethod.getSignature());