Commits

Tim Vernum committed eaf794c

Lookup type parameters in local (AST) functional interfaces

Comments (0)

Files changed (7)

convert/source/java/main/org/adjective/syntactic/convert/j7to8/ASTMethodInfo.java

 public class ASTMethodInfo implements MethodInfo
 {
     private final ASTMethodDeclaration _method;
+    private final TypeParameterLookup _parameterLookup;
 
-    public ASTMethodInfo(final ASTMethodDeclaration method)
+    public ASTMethodInfo(final ASTMethodDeclaration method, final TypeParameterLookup parameterLookup)
     {
         _method = method;
+        _parameterLookup = parameterLookup;
+    }
+
+    private JavaType getType(final JavaType type)
+    {
+        final JavaType typeParameter = _parameterLookup.findParameter(type.getTypeName());
+        if (typeParameter != null)
+        {
+            return typeParameter;
+        }
+        else
+        {
+            return type;
+        }
     }
 
     @Override
     public JavaType getReturnType()
     {
-        return _method.getActualReturnType();
+        return getType(_method.getActualReturnType());
     }
 
     @Override

convert/source/java/main/org/adjective/syntactic/convert/j7to8/ASTTypeInfo.java

  */
 package org.adjective.syntactic.convert.j7to8;
 
-import org.adjective.syntactic.parser.ast.ASTClassOrInterfaceBodyElement;
-import org.adjective.syntactic.parser.ast.ASTClassOrInterfaceDeclaration;
-import org.adjective.syntactic.parser.ast.ASTMember;
-import org.adjective.syntactic.parser.ast.ASTMethodDeclaration;
+import org.adjective.syntactic.parser.ast.*;
+import org.adjective.syntactic.parser.util.JavaType;
 import org.adjective.syntactic.parser.util.MemberType;
+import org.adjective.syntactic.parser.util.TypeParameter;
 
 import java.util.ArrayList;
 import java.util.List;
 
-public class ASTTypeInfo implements TypeInfo
+public class ASTTypeInfo implements TypeInfo, TypeParameterLookup
 {
     private final ASTClassOrInterfaceDeclaration _declaration;
+    private final TypeParameter[] _parameters;
     private final ASTMethodInfo[] _methods;
 
-    public ASTTypeInfo(final ASTClassOrInterfaceDeclaration declaration)
+    public ASTTypeInfo(final ASTClassOrInterfaceDeclaration declaration, final TypeParameter[] parameters)
     {
         _declaration = declaration;
+        _parameters = parameters;
         _methods = buildMethods();
     }
 
             {
                 continue;
             }
-            result.add(new ASTMethodInfo((ASTMethodDeclaration) member.getMember()));
+            result.add(new ASTMethodInfo((ASTMethodDeclaration) member.getMember(), this));
         }
         return result.toArray(new ASTMethodInfo[result.size()]);
     }
     @Override
     public String getName()
     {
-        return null;  //To change body of implemented methods use File | Settings | File Templates.
+        return _declaration.getName().getIdentifier();
+    }
+
+    @Override
+    public JavaType findParameter(final String name)
+    {
+        int i = 0;
+        for (ASTTypeParameter parameter : _declaration.getTypeParameters().getParameters())
+        {
+            if (parameter.getIdentifier().getIdentifier().equals(name))
+            {
+                return _parameters[i].getType();
+            }
+            i++;
+        }
+        return null;
     }
 }

convert/source/java/main/org/adjective/syntactic/convert/j7to8/ClassFinder.java

         if (cls == null)
         {
             ASTClassOrInterfaceDeclaration local = _localTypes.get(qualifiedName);
-            return getInfo(local);
+            return new ASTTypeInfo(local, parameters);
         }
         return new ClassInfo(cls, parameters);
     }
 
-    private TypeInfo getInfo(ASTClassOrInterfaceDeclaration declaration)
-    {
-        return new ASTTypeInfo(declaration);
-    }
-
     private Class<?> findClass(final String qualifiedName)
     {
         try

convert/source/java/main/org/adjective/syntactic/convert/j7to8/ClassInfo.java

                 return _parameters[i].getType();
             }
         }
-        return new ClassType(Object.class);
+        return null;
     }
 
 }

convert/source/java/main/org/adjective/syntactic/convert/j7to8/ClassMethodInfo.java

 
     private JavaType lookup(final TypeVariable var)
     {
-        return this._parameterLookup.findParameter(var.getName());
+        final JavaType type = this._parameterLookup.findParameter(var.getName());
+        return type != null ? type : new ClassType(Object.class);
     }
 
     @Override

parser/source/java/parser/org/adjective/syntactic/parser/ast/ASTTypeParameter.java

-/* Generated By:JJTree: Do not edit this line. ASTTypeParameter.java Version 4.3 */
-/* JavaCCOptions:MULTI=true,NODE_USES_PARSER=false,VISITOR=true,TRACK_TOKENS=true,NODE_PREFIX=AST,NODE_EXTENDS=,NODE_FACTORY=,SUPPORT_CLASS_VISIBILITY_PUBLIC=true */
 package org.adjective.syntactic.parser.ast;
 
-public
-class ASTTypeParameter extends org.adjective.syntactic.parser.BaseNode {
-  public ASTTypeParameter(int id) {
-    super(id);
-  }
+public class ASTTypeParameter extends org.adjective.syntactic.parser.BaseNode
+{
+    public ASTTypeParameter(int id)
+    {
+        super(id);
+    }
 
+    public <R, T> R jjtAccept(JavaParserVisitor<R, T> visitor, T data)
+    {
+        return visitor.visit(this, data);
+    }
 
-    /** Accept the visitor. **/
-  public <R,T> R jjtAccept(JavaParserVisitor<R,T> visitor, T data) {
-    return visitor.visit(this, data);
-  }
+    public ASTIdentifier getIdentifier()
+    {
+        return getFirstChild().as(ASTIdentifier.class);
+    }
+
+    public ASTTypeBound getTypeBound()
+    {
+        return optionalChild(ASTTypeBound.class);
+    }
 }
-/* JavaCC - OriginalChecksum=9139fc9c42989e2da1335eeeba2257bb (do not edit this line) */

parser/source/java/parser/org/adjective/syntactic/parser/ast/ASTTypeParameters.java

 package org.adjective.syntactic.parser.ast;
 
-public class ASTTypeParameters extends org.adjective.syntactic.parser.BaseNode
+import org.adjective.syntactic.parser.BaseNode;
+
+public class ASTTypeParameters extends BaseNode
 {
     public ASTTypeParameters(int id)
     {
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.