Commits

Tim Vernum committed f196bc8

Repackage 'convert' module

Comments (0)

Files changed (23)

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

-/* ------------------------------------------------------------------------
- * Copyright 2013 Tim Vernum
- * ------------------------------------------------------------------------
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ------------------------------------------------------------------------
- */
-package org.adjective.syntactic.convert.j7to8;
-
-import org.adjective.syntactic.parser.ast.ASTMethodDeclaration;
-import org.adjective.syntactic.parser.ast.ASTNameList;
-import org.adjective.syntactic.parser.type.JavaType;
-
-public class ASTMethodInfo implements MethodInfo
-{
-    private final ASTMethodDeclaration _method;
-    private final TypeParameterLookup _parameterLookup;
-
-    public ASTMethodInfo(final ASTMethodDeclaration method, final TypeParameterLookup lookup)
-    {
-        _method = method;
-        _parameterLookup = lookup;
-    }
-
-    private JavaType getType(final JavaType type)
-    {
-        final JavaType typeParameter = _parameterLookup.findParameter(type.getTypeName());
-        if (typeParameter != null)
-        {
-            return typeParameter;
-        }
-        else
-        {
-            return type;
-        }
-    }
-
-    private JavaType[] getTypes(final JavaType[] in)
-    {
-        JavaType[] out = new JavaType[in.length];
-        for (int i = 0; i < in.length; i++)
-        {
-            out[i] = getType(in[i]);
-        }
-        return out;
-    }
-
-    @Override
-    public JavaType getReturnType()
-    {
-        return getType(_method.getActualReturnType());
-    }
-
-    @Override
-    public String getName()
-    {
-        return _method.getName().getIdentifier();
-    }
-
-    @Override
-    public JavaType[] getParameterTypes()
-    {
-        return getTypes(_method.getParameters().getParameterTypes());
-    }
-
-    @Override
-    public String[] getParameterNames()
-    {
-        return _method.getParameters().getParameterNames();
-    }
-
-    @Override
-    public Integer[] getClassTypeParameters()
-    {
-        final JavaType[] types = _method.getParameters().getParameterTypes();
-        final Integer[] vals = new Integer[types.length];
-
-        for (int i = 0; i < vals.length; i++)
-        {
-            final int lookup = _parameterLookup.findParameterIndex(types[i].getTypeName());
-            if (lookup != -1)
-            {
-                vals[i] = lookup;
-            }
-        }
-
-        return vals;
-    }
-
-    @Override
-    public boolean isVarArgs()
-    {
-        return _method.getParameters().isVarArgs();
-    }
-
-    @Override
-    public JavaType[] getExceptionTypes()
-    {
-        final ASTNameList exceptions = _method.getThrows();
-        return exceptions == null ? new JavaType[0] : exceptions.getTypes();
-    }
-
-}

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

-/* ------------------------------------------------------------------------
- * Copyright 2013 Tim Vernum
- * ------------------------------------------------------------------------
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ------------------------------------------------------------------------
- */
-package org.adjective.syntactic.convert.j7to8;
-
-import org.adjective.syntactic.parser.ast.*;
-import org.adjective.syntactic.parser.type.JavaType;
-import org.adjective.syntactic.parser.type.MemberType;
-import org.adjective.syntactic.parser.name.TypeParameter;
-
-import java.util.ArrayList;
-import java.util.List;
-
-public class ASTTypeInfo implements TypeInfo, TypeParameterLookup
-{
-    private final ASTClassOrInterfaceDeclaration _declaration;
-    private final TypeParameter[] _parameters;
-    private final ASTMethodInfo[] _methods;
-
-    public ASTTypeInfo(final ASTClassOrInterfaceDeclaration declaration, final TypeParameter[] parameters)
-    {
-        _declaration = declaration;
-        _parameters = parameters;
-        _methods = buildMethods();
-    }
-
-    private ASTMethodInfo[] buildMethods()
-    {
-        final List<ASTMethodInfo> result = new ArrayList<ASTMethodInfo>();
-        for (ASTClassOrInterfaceBodyElement element : _declaration.getBody().getElements())
-        {
-            if (!element.isMember())
-            {
-                continue;
-            }
-            final ASTMember member = element.getMember();
-            if (member.getMember().getMemberType() != MemberType.METHOD)
-            {
-                continue;
-            }
-            result.add(new ASTMethodInfo((ASTMethodDeclaration) member.getMember(), this));
-        }
-        return result.toArray(new ASTMethodInfo[result.size()]);
-    }
-
-    @Override
-    public MethodInfo[] getMethods()
-    {
-        return _methods;
-    }
-
-    @Override
-    public String getName()
-    {
-        return _declaration.getName().getIdentifier();
-    }
-
-    @Override
-    public JavaType findParameter(final String name)
-    {
-        Integer index = findParameterIndex(name);
-        if (index == null)
-        {
-            return null;
-        }
-        else
-        {
-            return _parameters[index].getType();
-        }
-    }
-
-    @Override
-    public Integer findParameterIndex(final String name)
-    {
-        int i = 0;
-        for (ASTTypeParameter parameter : _declaration.getTypeParameters().getParameters())
-        {
-            if (parameter.getIdentifier().getIdentifier().equals(name))
-            {
-                return i;
-            }
-            i++;
-        }
-        return null;
-    }
-
-}

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

-/*
- * ------------------------------------------------------------------------
- *  Copyright 2013 Tim Vernum
- *  ------------------------------------------------------------------------
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *  ------------------------------------------------------------------------
- */
-package org.adjective.syntactic.convert.j7to8;
-
-import org.adjective.syntactic.parser.ast.ASTClassOrInterfaceDeclaration;
-import org.adjective.syntactic.parser.name.TypeParameter;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class ClassFinder
-{
-    private Map<String, ASTClassOrInterfaceDeclaration> _localTypes;
-
-    public ClassFinder()
-    {
-        _localTypes = new HashMap<String, ASTClassOrInterfaceDeclaration>();
-    }
-
-    public boolean hasClass(final String qualifiedName)
-    {
-        return findClass(qualifiedName) != null;
-    }
-
-    public TypeInfo getClass(final String qualifiedName, TypeParameter[] parameters)
-    {
-        final Class<?> cls = findClass(qualifiedName);
-        if (cls == null)
-        {
-            ASTClassOrInterfaceDeclaration local = _localTypes.get(qualifiedName);
-            return new ASTTypeInfo(local, parameters);
-        }
-        return new ClassInfo(cls, parameters);
-    }
-
-    private Class<?> findClass(final String qualifiedName)
-    {
-        try
-        {
-            return Class.forName(qualifiedName);
-        }
-        catch (ClassNotFoundException e)
-        {
-            return null;
-        }
-    }
-
-    public void define(final ASTClassOrInterfaceDeclaration node)
-    {
-        _localTypes.put(node.getName().getIdentifier(), node);
-    }
-}

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

-/*
- * ------------------------------------------------------------------------
- *  Copyright 2013 Tim Vernum
- *  ------------------------------------------------------------------------
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *  ------------------------------------------------------------------------
- */
-package org.adjective.syntactic.convert.j7to8;
-
-import org.adjective.syntactic.parser.type.JavaType;
-import org.adjective.syntactic.parser.name.TypeParameter;
-
-import java.lang.reflect.TypeVariable;
-
-public class ClassInfo implements TypeInfo, TypeParameterLookup
-{
-    private final Class<?> _cls;
-    private final TypeParameter[] _parameters;
-
-    public ClassInfo(final Class<?> cls, final TypeParameter[] parameters)
-    {
-        _cls = cls;
-        _parameters = parameters;
-    }
-
-    @Override
-    public MethodInfo[] getMethods()
-    {
-        return ClassMethodInfo.array(_cls.getMethods(), this);
-    }
-
-    @Override
-    public String getName()
-    {
-        return _cls.getName();
-    }
-
-    @Override
-    public JavaType findParameter(String name)
-    {
-        final Integer index = findParameterIndex(name);
-        return index == null ? null : _parameters[index].getType();
-    }
-
-    @Override
-    public Integer findParameterIndex(final String name)
-    {
-        final TypeVariable<? extends Class<?>>[] typeParameters = _cls.getTypeParameters();
-        for (int i = 0; i < typeParameters.length; i++)
-        {
-            TypeVariable<? extends Class<?>> typeParameter = typeParameters[i];
-            if (typeParameter.getName().equals(name))
-            {
-                return i;
-            }
-        }
-        return null;
-    }
-
-}

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

-/*
- * ------------------------------------------------------------------------
- *  Copyright 2013 Tim Vernum
- *  ------------------------------------------------------------------------
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *  ------------------------------------------------------------------------
- */
-package org.adjective.syntactic.convert.j7to8;
-
-import org.adjective.syntactic.parser.type.JavaType;
-
-import java.lang.reflect.Method;
-import java.lang.reflect.Type;
-import java.lang.reflect.TypeVariable;
-
-public class ClassMethodInfo implements MethodInfo
-{
-    private final Method _method;
-    private final TypeParameterLookup _parameterLookup;
-
-    public ClassMethodInfo(final Method method, final TypeParameterLookup parameterLookup)
-    {
-        _method = method;
-        _parameterLookup = parameterLookup;
-    }
-
-    public static ClassMethodInfo[] array(final Method[] methods, TypeParameterLookup parameterLookup)
-    {
-        final ClassMethodInfo[] info = new ClassMethodInfo[methods.length];
-        for (int i = 0; i < methods.length; i++)
-        {
-            info[i] = new ClassMethodInfo(methods[i], parameterLookup);
-        }
-        return info;
-    }
-
-    @Override
-    public JavaType getReturnType()
-    {
-        return getJavaType(_method.getGenericReturnType(), _method.getReturnType());
-    }
-
-    @Override
-    public String getName()
-    {
-        return _method.getName();
-    }
-
-    @Override
-    public JavaType[] getParameterTypes()
-    {
-        return getJavaTypes(_method.getGenericParameterTypes(), _method.getParameterTypes());
-    }
-
-    private JavaType[] getJavaTypes(final Type[] genericTypes, final Class<?>[] classes)
-    {
-        final JavaType[] javaTypes = new JavaType[genericTypes.length];
-        for (int i = 0; i < genericTypes.length; i++)
-        {
-            javaTypes[i] = getJavaType(genericTypes[i], classes[i]);
-        }
-        return javaTypes;
-    }
-
-    private JavaType getJavaType(final Type parameter, final Class<?> cls)
-    {
-        final JavaType javaType;
-        if (parameter instanceof TypeVariable)
-        {
-            javaType = lookup((TypeVariable) parameter);
-        }
-        else
-        {
-            javaType = new ClassType(cls);
-        }
-        return javaType;
-    }
-
-    private JavaType lookup(final TypeVariable var)
-    {
-        final JavaType type = this._parameterLookup.findParameter(var.getName());
-        return type != null ? type : new ClassType(Object.class);
-    }
-
-    @Override
-    public String[] getParameterNames()
-    {
-        final String[] names = new String[_method.getParameterTypes().length];
-        for (int i = 0; i < names.length; i++)
-        {
-            names[i] = "p" + (i + 1);
-        }
-        return names;
-    }
-
-    @Override
-    public Integer[] getClassTypeParameters()
-    {
-        final Type[] genericTypes = _method.getGenericParameterTypes();
-        final Integer[] index = new Integer[genericTypes.length];
-        for (int i = 0; i < index.length; i++)
-        {
-            Type parameter = genericTypes[i];
-            if (parameter instanceof TypeVariable)
-            {
-                final TypeVariable var = (TypeVariable) parameter;
-                index[i] = _parameterLookup.findParameterIndex(var.getName());
-            }
-        }
-        return index;
-    }
-
-    @Override
-    public boolean isVarArgs()
-    {
-        return _method.isVarArgs();
-    }
-
-    @Override
-    public JavaType[] getExceptionTypes()
-    {
-        return getJavaTypes(_method.getGenericExceptionTypes(), _method.getExceptionTypes());
-    }
-
-    @Override
-    public String toString()
-    {
-        return _method.toString();
-    }
-}

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

-/* ------------------------------------------------------------------------
- * Copyright 2013 Tim Vernum
- * ------------------------------------------------------------------------
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ------------------------------------------------------------------------
- */
-package org.adjective.syntactic.convert.j7to8;
-
-import org.adjective.syntactic.parser.type.BaseType;
-import org.adjective.syntactic.parser.type.JavaType;
-import org.adjective.syntactic.parser.name.ParameterizedName;
-import org.adjective.syntactic.parser.name.UnparameterizedName;
-
-public class ClassType implements JavaType
-{
-
-    private Class<?> _cls;
-
-    public ClassType(Class<?> cls)
-    {
-        _cls = cls;
-    }
-
-    @Override
-    public BaseType getBaseType()
-    {
-        if (_cls.isPrimitive())
-        {
-            if (_cls == Void.TYPE)
-            {
-                return BaseType.VOID;
-            }
-            if (_cls == Boolean.TYPE)
-            {
-                return BaseType.BOOLEAN;
-            }
-            if (_cls == Byte.TYPE)
-            {
-                return BaseType.BYTE;
-            }
-            if (_cls == Short.TYPE)
-            {
-                return BaseType.SHORT;
-            }
-            if (_cls == Integer.TYPE)
-            {
-                return BaseType.INT;
-            }
-            if (_cls == Long.TYPE)
-            {
-                return BaseType.LONG;
-            }
-            if (_cls == Float.TYPE)
-            {
-                return BaseType.FLOAT;
-            }
-            if (_cls == Double.TYPE)
-            {
-                return BaseType.DOUBLE;
-            }
-            if (_cls == Character.TYPE)
-            {
-                return BaseType.CHAR;
-            }
-        }
-        return BaseType.OBJECT;
-    }
-
-    @Override
-    public String getTypeName()
-    {
-        return _cls.getName();
-    }
-
-    @Override
-    public ParameterizedName[] getParameterizedTypeName()
-    {
-        final String[] parts = getTypeName().split("\\.");
-        final ParameterizedName[] names = new ParameterizedName[parts.length];
-        for (int i = 0; i < names.length; i++)
-        {
-            names[i] = new UnparameterizedName(parts[i]);
-        }
-        return names;
-    }
-
-    @Override
-    public int getArrayDepth()
-    {
-        int depth = 0;
-        for (Class cls = _cls; cls.isArray(); cls = cls.getComponentType())
-        {
-            depth++;
-        }
-        return depth;
-    }
-
-    public static ClassType[] array(final Class<?>... cls)
-    {
-        ClassType[] type = new ClassType[cls.length];
-        for (int i = 0; i < cls.length; i++)
-        {
-            type[i] = new ClassType(cls[i]);
-        }
-        return type;
-    }
-}

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

  */
 package org.adjective.syntactic.convert.j7to8;
 
+import org.adjective.syntactic.convert.j7to8.type.MethodInfo;
+import org.adjective.syntactic.convert.j7to8.type.TypeInfo;
+import org.adjective.syntactic.convert.j7to8.util.ClassFinder;
+import org.adjective.syntactic.convert.j7to8.util.Importer;
+import org.adjective.syntactic.convert.j7to8.util.VariableStack;
 import org.adjective.syntactic.parser.node.BaseNode;
 import org.adjective.syntactic.parser.util.DefaultVisitor;
 import org.adjective.syntactic.parser.ast.*;
 import java.lang.reflect.Method;
 import java.util.*;
 
-public class Convert7To8Visitor extends DefaultVisitor<Object, Object>
+public class    Convert7To8Visitor extends DefaultVisitor<Object, Object>
 {
     private final Stack<String> _className;
     private final VariableStack _vars;

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

-/*
- * ------------------------------------------------------------------------
- *  Copyright 2013 Tim Vernum
- *  ------------------------------------------------------------------------
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *  ------------------------------------------------------------------------
- */
-package org.adjective.syntactic.convert.j7to8;
-
-import org.adjective.syntactic.parser.ast.ASTImportDeclaration;
-import org.adjective.syntactic.parser.ast.ASTQualifiedIdentifier;
-
-import java.util.ArrayList;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-
-public class Importer
-{
-    private final ClassFinder _classFinder;
-    private final Map<String, String> typeImports;
-    private final List<String> typeOnDemandImports;
-
-    public Importer(final ClassFinder classFinder)
-    {
-        _classFinder = classFinder;
-        this.typeImports = new LinkedHashMap<String, String>();
-        this.typeOnDemandImports = new ArrayList<String>();
-    }
-
-    public void add(final ASTImportDeclaration node)
-    {
-        if (node.isStatic())
-        {
-            return;
-        }
-        final ASTQualifiedIdentifier identifier = node.getIdentifier();
-        if (node.isOnDemand())
-        {
-            typeOnDemandImports.add(identifier.getName());
-        }
-        else
-        {
-            typeImports.put(identifier.getLastIdentifier().getIdentifier(), identifier.getName());
-        }
-    }
-
-    public String getQualifiedName(String simpleName)
-    {
-        final String importedName = typeImports.get(simpleName);
-        if (importedName != null)
-        {
-            return importedName;
-        }
-        for (String pkg : typeOnDemandImports)
-        {
-            final String qualifiedName = lookupClass(pkg, simpleName);
-            if (qualifiedName != null)
-            {
-                return qualifiedName;
-            }
-        }
-        return lookupClass("java.lang", simpleName);
-    }
-
-    private String lookupClass(final String pkg, final String simpleName)
-    {
-        final String qualifiedName = pkg + "." + simpleName;
-        if (classExists(qualifiedName))
-        {
-            return qualifiedName;
-        }
-        else
-        {
-            return null;
-        }
-    }
-
-    private boolean classExists(final String qualifiedName)
-    {
-        return _classFinder.hasClass(qualifiedName);
-    }
-}

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

-/*
- * ------------------------------------------------------------------------
- *  Copyright 2013 Tim Vernum
- *  ------------------------------------------------------------------------
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *  ------------------------------------------------------------------------
- */
-package org.adjective.syntactic.convert.j7to8;
-
-import org.adjective.syntactic.parser.type.JavaType;
-
-public interface MethodInfo {
-
-    public JavaType getReturnType();
-    public String getName();
-    public JavaType[] getParameterTypes();
-    public String[] getParameterNames();
-
-    /**
-     * @return An array of integers representing, for each of the parameters of this method, the zero-based index of the enclosing class's type parameters are represented by that method parameter (or null if the method parameter is not a class type parameter)
-     * e.g. For the declaration
-     * <pre>interface C&lt;S,T&gt; {
-     *   void f( String s, T t );
-     * }</pre>
-     * This method would return <code>{ null, 1 }</code>
-     */
-    public Integer[] getClassTypeParameters();
-    public boolean isVarArgs();
-    public JavaType[] getExceptionTypes();
-}

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

-/*
- * ------------------------------------------------------------------------
- *  Copyright 2013 Tim Vernum
- *  ------------------------------------------------------------------------
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *  ------------------------------------------------------------------------
- */
-package org.adjective.syntactic.convert.j7to8;
-
-public interface TypeInfo
-{
-    public MethodInfo[] getMethods();
-    public String getName();
-}

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

-/* ------------------------------------------------------------------------
- * Copyright 2013 Tim Vernum
- * ------------------------------------------------------------------------
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * ------------------------------------------------------------------------
- */
-package org.adjective.syntactic.convert.j7to8;
-
-import org.adjective.syntactic.parser.type.JavaType;
-
-public interface TypeParameterLookup {
-    JavaType findParameter(String name);
-    Integer findParameterIndex(String name);
-}

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

-/*
- * ------------------------------------------------------------------------
- *  Copyright 2013 Tim Vernum
- *  ------------------------------------------------------------------------
- *  Licensed under the Apache License, Version 2.0 (the "License");
- *  you may not use this file except in compliance with the License.
- *  You may obtain a copy of the License at
- *
- *       http://www.apache.org/licenses/LICENSE-2.0
- *
- *  Unless required by applicable law or agreed to in writing, software
- *  distributed under the License is distributed on an "AS IS" BASIS,
- *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- *  See the License for the specific language governing permissions and
- *  limitations under the License.
- *  ------------------------------------------------------------------------
- */
-package org.adjective.syntactic.convert.j7to8;
-
-import org.adjective.syntactic.parser.node.VariableDeclarationNode;
-
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Stack;
-
-public class VariableStack
-{
-    private Stack<Map<String, VariableDeclarationNode>> _stack;
-
-    public VariableStack()
-    {
-        _stack = new Stack<Map<String, VariableDeclarationNode>>();
-    }
-
-    public void pushScope()
-    {
-        _stack.push(new HashMap<String, VariableDeclarationNode>());
-    }
-
-    public void popScope()
-    {
-        _stack.pop();
-    }
-
-    public void store(String name, VariableDeclarationNode var)
-    {
-        final Map<String, VariableDeclarationNode> map = _stack.peek();
-        if (map.containsKey(name))
-        {
-            throw new IllegalArgumentException("Variable '" + name + "' already exists in current scope");
-        }
-        map.put(name, var);
-    }
-
-    public VariableDeclarationNode get(String name)
-    {
-        for (int i = _stack.size() - 1; i >= 0; i--)
-        {
-            final VariableDeclarationNode var = _stack.get(i).get(name);
-            if (var != null)
-            {
-                return var;
-            }
-        }
-        return null;
-    }
-
-}

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

+/* ------------------------------------------------------------------------
+ * Copyright 2013 Tim Vernum
+ * ------------------------------------------------------------------------
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ------------------------------------------------------------------------
+ */
+package org.adjective.syntactic.convert.j7to8.type;
+
+import org.adjective.syntactic.parser.ast.ASTMethodDeclaration;
+import org.adjective.syntactic.parser.ast.ASTNameList;
+import org.adjective.syntactic.parser.type.JavaType;
+
+public class ASTMethodInfo implements MethodInfo
+{
+    private final ASTMethodDeclaration _method;
+    private final TypeParameterLookup _parameterLookup;
+
+    public ASTMethodInfo(final ASTMethodDeclaration method, final TypeParameterLookup lookup)
+    {
+        _method = method;
+        _parameterLookup = lookup;
+    }
+
+    private JavaType getType(final JavaType type)
+    {
+        final JavaType typeParameter = _parameterLookup.findParameter(type.getTypeName());
+        if (typeParameter != null)
+        {
+            return typeParameter;
+        }
+        else
+        {
+            return type;
+        }
+    }
+
+    private JavaType[] getTypes(final JavaType[] in)
+    {
+        JavaType[] out = new JavaType[in.length];
+        for (int i = 0; i < in.length; i++)
+        {
+            out[i] = getType(in[i]);
+        }
+        return out;
+    }
+
+    @Override
+    public JavaType getReturnType()
+    {
+        return getType(_method.getActualReturnType());
+    }
+
+    @Override
+    public String getName()
+    {
+        return _method.getName().getIdentifier();
+    }
+
+    @Override
+    public JavaType[] getParameterTypes()
+    {
+        return getTypes(_method.getParameters().getParameterTypes());
+    }
+
+    @Override
+    public String[] getParameterNames()
+    {
+        return _method.getParameters().getParameterNames();
+    }
+
+    @Override
+    public Integer[] getClassTypeParameters()
+    {
+        final JavaType[] types = _method.getParameters().getParameterTypes();
+        final Integer[] vals = new Integer[types.length];
+
+        for (int i = 0; i < vals.length; i++)
+        {
+            final int lookup = _parameterLookup.findParameterIndex(types[i].getTypeName());
+            if (lookup != -1)
+            {
+                vals[i] = lookup;
+            }
+        }
+
+        return vals;
+    }
+
+    @Override
+    public boolean isVarArgs()
+    {
+        return _method.getParameters().isVarArgs();
+    }
+
+    @Override
+    public JavaType[] getExceptionTypes()
+    {
+        final ASTNameList exceptions = _method.getThrows();
+        return exceptions == null ? new JavaType[0] : exceptions.getTypes();
+    }
+
+}

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

+/* ------------------------------------------------------------------------
+ * Copyright 2013 Tim Vernum
+ * ------------------------------------------------------------------------
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ------------------------------------------------------------------------
+ */
+package org.adjective.syntactic.convert.j7to8.type;
+
+import org.adjective.syntactic.parser.ast.*;
+import org.adjective.syntactic.parser.type.JavaType;
+import org.adjective.syntactic.parser.type.MemberType;
+import org.adjective.syntactic.parser.name.TypeParameter;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class ASTTypeInfo implements TypeInfo, TypeParameterLookup
+{
+    private final ASTClassOrInterfaceDeclaration _declaration;
+    private final TypeParameter[] _parameters;
+    private final ASTMethodInfo[] _methods;
+
+    public ASTTypeInfo(final ASTClassOrInterfaceDeclaration declaration, final TypeParameter[] parameters)
+    {
+        _declaration = declaration;
+        _parameters = parameters;
+        _methods = buildMethods();
+    }
+
+    private ASTMethodInfo[] buildMethods()
+    {
+        final List<ASTMethodInfo> result = new ArrayList<ASTMethodInfo>();
+        for (ASTClassOrInterfaceBodyElement element : _declaration.getBody().getElements())
+        {
+            if (!element.isMember())
+            {
+                continue;
+            }
+            final ASTMember member = element.getMember();
+            if (member.getMember().getMemberType() != MemberType.METHOD)
+            {
+                continue;
+            }
+            result.add(new ASTMethodInfo((ASTMethodDeclaration) member.getMember(), this));
+        }
+        return result.toArray(new ASTMethodInfo[result.size()]);
+    }
+
+    @Override
+    public MethodInfo[] getMethods()
+    {
+        return _methods;
+    }
+
+    @Override
+    public String getName()
+    {
+        return _declaration.getName().getIdentifier();
+    }
+
+    @Override
+    public JavaType findParameter(final String name)
+    {
+        Integer index = findParameterIndex(name);
+        if (index == null)
+        {
+            return null;
+        }
+        else
+        {
+            return _parameters[index].getType();
+        }
+    }
+
+    @Override
+    public Integer findParameterIndex(final String name)
+    {
+        int i = 0;
+        for (ASTTypeParameter parameter : _declaration.getTypeParameters().getParameters())
+        {
+            if (parameter.getIdentifier().getIdentifier().equals(name))
+            {
+                return i;
+            }
+            i++;
+        }
+        return null;
+    }
+
+}

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

+/*
+ * ------------------------------------------------------------------------
+ *  Copyright 2013 Tim Vernum
+ *  ------------------------------------------------------------------------
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *  ------------------------------------------------------------------------
+ */
+package org.adjective.syntactic.convert.j7to8.type;
+
+import org.adjective.syntactic.parser.type.JavaType;
+import org.adjective.syntactic.parser.name.TypeParameter;
+
+import java.lang.reflect.TypeVariable;
+
+public class ClassInfo implements TypeInfo, TypeParameterLookup
+{
+    private final Class<?> _cls;
+    private final TypeParameter[] _parameters;
+
+    public ClassInfo(final Class<?> cls, final TypeParameter[] parameters)
+    {
+        _cls = cls;
+        _parameters = parameters;
+    }
+
+    @Override
+    public MethodInfo[] getMethods()
+    {
+        return ClassMethodInfo.array(_cls.getMethods(), this);
+    }
+
+    @Override
+    public String getName()
+    {
+        return _cls.getName();
+    }
+
+    @Override
+    public JavaType findParameter(String name)
+    {
+        final Integer index = findParameterIndex(name);
+        return index == null ? null : _parameters[index].getType();
+    }
+
+    @Override
+    public Integer findParameterIndex(final String name)
+    {
+        final TypeVariable<? extends Class<?>>[] typeParameters = _cls.getTypeParameters();
+        for (int i = 0; i < typeParameters.length; i++)
+        {
+            TypeVariable<? extends Class<?>> typeParameter = typeParameters[i];
+            if (typeParameter.getName().equals(name))
+            {
+                return i;
+            }
+        }
+        return null;
+    }
+
+}

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

+/*
+ * ------------------------------------------------------------------------
+ *  Copyright 2013 Tim Vernum
+ *  ------------------------------------------------------------------------
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *  ------------------------------------------------------------------------
+ */
+package org.adjective.syntactic.convert.j7to8.type;
+
+import org.adjective.syntactic.parser.type.JavaType;
+
+import java.lang.reflect.Method;
+import java.lang.reflect.Type;
+import java.lang.reflect.TypeVariable;
+
+public class ClassMethodInfo implements MethodInfo
+{
+    private final Method _method;
+    private final TypeParameterLookup _parameterLookup;
+
+    public ClassMethodInfo(final Method method, final TypeParameterLookup parameterLookup)
+    {
+        _method = method;
+        _parameterLookup = parameterLookup;
+    }
+
+    public static ClassMethodInfo[] array(final Method[] methods, TypeParameterLookup parameterLookup)
+    {
+        final ClassMethodInfo[] info = new ClassMethodInfo[methods.length];
+        for (int i = 0; i < methods.length; i++)
+        {
+            info[i] = new ClassMethodInfo(methods[i], parameterLookup);
+        }
+        return info;
+    }
+
+    @Override
+    public JavaType getReturnType()
+    {
+        return getJavaType(_method.getGenericReturnType(), _method.getReturnType());
+    }
+
+    @Override
+    public String getName()
+    {
+        return _method.getName();
+    }
+
+    @Override
+    public JavaType[] getParameterTypes()
+    {
+        return getJavaTypes(_method.getGenericParameterTypes(), _method.getParameterTypes());
+    }
+
+    private JavaType[] getJavaTypes(final Type[] genericTypes, final Class<?>[] classes)
+    {
+        final JavaType[] javaTypes = new JavaType[genericTypes.length];
+        for (int i = 0; i < genericTypes.length; i++)
+        {
+            javaTypes[i] = getJavaType(genericTypes[i], classes[i]);
+        }
+        return javaTypes;
+    }
+
+    private JavaType getJavaType(final Type parameter, final Class<?> cls)
+    {
+        final JavaType javaType;
+        if (parameter instanceof TypeVariable)
+        {
+            javaType = lookup((TypeVariable) parameter);
+        }
+        else
+        {
+            javaType = new ClassType(cls);
+        }
+        return javaType;
+    }
+
+    private JavaType lookup(final TypeVariable var)
+    {
+        final JavaType type = this._parameterLookup.findParameter(var.getName());
+        return type != null ? type : new ClassType(Object.class);
+    }
+
+    @Override
+    public String[] getParameterNames()
+    {
+        final String[] names = new String[_method.getParameterTypes().length];
+        for (int i = 0; i < names.length; i++)
+        {
+            names[i] = "p" + (i + 1);
+        }
+        return names;
+    }
+
+    @Override
+    public Integer[] getClassTypeParameters()
+    {
+        final Type[] genericTypes = _method.getGenericParameterTypes();
+        final Integer[] index = new Integer[genericTypes.length];
+        for (int i = 0; i < index.length; i++)
+        {
+            Type parameter = genericTypes[i];
+            if (parameter instanceof TypeVariable)
+            {
+                final TypeVariable var = (TypeVariable) parameter;
+                index[i] = _parameterLookup.findParameterIndex(var.getName());
+            }
+        }
+        return index;
+    }
+
+    @Override
+    public boolean isVarArgs()
+    {
+        return _method.isVarArgs();
+    }
+
+    @Override
+    public JavaType[] getExceptionTypes()
+    {
+        return getJavaTypes(_method.getGenericExceptionTypes(), _method.getExceptionTypes());
+    }
+
+    @Override
+    public String toString()
+    {
+        return _method.toString();
+    }
+}

convert/source/java/main/org/adjective/syntactic/convert/j7to8/type/ClassType.java

+/* ------------------------------------------------------------------------
+ * Copyright 2013 Tim Vernum
+ * ------------------------------------------------------------------------
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ------------------------------------------------------------------------
+ */
+package org.adjective.syntactic.convert.j7to8.type;
+
+import org.adjective.syntactic.parser.type.BaseType;
+import org.adjective.syntactic.parser.type.JavaType;
+import org.adjective.syntactic.parser.name.ParameterizedName;
+import org.adjective.syntactic.parser.name.UnparameterizedName;
+
+public class ClassType implements JavaType
+{
+
+    private Class<?> _cls;
+
+    public ClassType(Class<?> cls)
+    {
+        _cls = cls;
+    }
+
+    @Override
+    public BaseType getBaseType()
+    {
+        if (_cls.isPrimitive())
+        {
+            if (_cls == Void.TYPE)
+            {
+                return BaseType.VOID;
+            }
+            if (_cls == Boolean.TYPE)
+            {
+                return BaseType.BOOLEAN;
+            }
+            if (_cls == Byte.TYPE)
+            {
+                return BaseType.BYTE;
+            }
+            if (_cls == Short.TYPE)
+            {
+                return BaseType.SHORT;
+            }
+            if (_cls == Integer.TYPE)
+            {
+                return BaseType.INT;
+            }
+            if (_cls == Long.TYPE)
+            {
+                return BaseType.LONG;
+            }
+            if (_cls == Float.TYPE)
+            {
+                return BaseType.FLOAT;
+            }
+            if (_cls == Double.TYPE)
+            {
+                return BaseType.DOUBLE;
+            }
+            if (_cls == Character.TYPE)
+            {
+                return BaseType.CHAR;
+            }
+        }
+        return BaseType.OBJECT;
+    }
+
+    @Override
+    public String getTypeName()
+    {
+        return _cls.getName();
+    }
+
+    @Override
+    public ParameterizedName[] getParameterizedTypeName()
+    {
+        final String[] parts = getTypeName().split("\\.");
+        final ParameterizedName[] names = new ParameterizedName[parts.length];
+        for (int i = 0; i < names.length; i++)
+        {
+            names[i] = new UnparameterizedName(parts[i]);
+        }
+        return names;
+    }
+
+    @Override
+    public int getArrayDepth()
+    {
+        int depth = 0;
+        for (Class cls = _cls; cls.isArray(); cls = cls.getComponentType())
+        {
+            depth++;
+        }
+        return depth;
+    }
+
+    public static ClassType[] array(final Class<?>... cls)
+    {
+        ClassType[] type = new ClassType[cls.length];
+        for (int i = 0; i < cls.length; i++)
+        {
+            type[i] = new ClassType(cls[i]);
+        }
+        return type;
+    }
+}

convert/source/java/main/org/adjective/syntactic/convert/j7to8/type/MethodInfo.java

+/*
+ * ------------------------------------------------------------------------
+ *  Copyright 2013 Tim Vernum
+ *  ------------------------------------------------------------------------
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *  ------------------------------------------------------------------------
+ */
+package org.adjective.syntactic.convert.j7to8.type;
+
+import org.adjective.syntactic.parser.type.JavaType;
+
+public interface MethodInfo {
+
+    public JavaType getReturnType();
+    public String getName();
+    public JavaType[] getParameterTypes();
+    public String[] getParameterNames();
+
+    /**
+     * @return An array of integers representing, for each of the parameters of this method, the zero-based index of the enclosing class's type parameters are represented by that method parameter (or null if the method parameter is not a class type parameter)
+     * e.g. For the declaration
+     * <pre>interface C&lt;S,T&gt; {
+     *   void f( String s, T t );
+     * }</pre>
+     * This method would return <code>{ null, 1 }</code>
+     */
+    public Integer[] getClassTypeParameters();
+    public boolean isVarArgs();
+    public JavaType[] getExceptionTypes();
+}

convert/source/java/main/org/adjective/syntactic/convert/j7to8/type/TypeInfo.java

+/*
+ * ------------------------------------------------------------------------
+ *  Copyright 2013 Tim Vernum
+ *  ------------------------------------------------------------------------
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *  ------------------------------------------------------------------------
+ */
+package org.adjective.syntactic.convert.j7to8.type;
+
+public interface TypeInfo
+{
+    public MethodInfo[] getMethods();
+    public String getName();
+}

convert/source/java/main/org/adjective/syntactic/convert/j7to8/type/TypeParameterLookup.java

+/* ------------------------------------------------------------------------
+ * Copyright 2013 Tim Vernum
+ * ------------------------------------------------------------------------
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ------------------------------------------------------------------------
+ */
+package org.adjective.syntactic.convert.j7to8.type;
+
+import org.adjective.syntactic.parser.type.JavaType;
+
+public interface TypeParameterLookup {
+    JavaType findParameter(String name);
+    Integer findParameterIndex(String name);
+}

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

+/*
+ * ------------------------------------------------------------------------
+ *  Copyright 2013 Tim Vernum
+ *  ------------------------------------------------------------------------
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *  ------------------------------------------------------------------------
+ */
+package org.adjective.syntactic.convert.j7to8.util;
+
+import org.adjective.syntactic.convert.j7to8.type.ASTTypeInfo;
+import org.adjective.syntactic.convert.j7to8.type.ClassInfo;
+import org.adjective.syntactic.convert.j7to8.type.TypeInfo;
+import org.adjective.syntactic.parser.ast.ASTClassOrInterfaceDeclaration;
+import org.adjective.syntactic.parser.name.TypeParameter;
+
+import java.util.HashMap;
+import java.util.Map;
+
+public class ClassFinder
+{
+    private Map<String, ASTClassOrInterfaceDeclaration> _localTypes;
+
+    public ClassFinder()
+    {
+        _localTypes = new HashMap<String, ASTClassOrInterfaceDeclaration>();
+    }
+
+    public boolean hasClass(final String qualifiedName)
+    {
+        return findClass(qualifiedName) != null;
+    }
+
+    public TypeInfo getClass(final String qualifiedName, TypeParameter[] parameters)
+    {
+        final Class<?> cls = findClass(qualifiedName);
+        if (cls == null)
+        {
+            ASTClassOrInterfaceDeclaration local = _localTypes.get(qualifiedName);
+            return new ASTTypeInfo(local, parameters);
+        }
+        return new ClassInfo(cls, parameters);
+    }
+
+    private Class<?> findClass(final String qualifiedName)
+    {
+        try
+        {
+            return Class.forName(qualifiedName);
+        }
+        catch (ClassNotFoundException e)
+        {
+            return null;
+        }
+    }
+
+    public void define(final ASTClassOrInterfaceDeclaration node)
+    {
+        _localTypes.put(node.getName().getIdentifier(), node);
+    }
+}

convert/source/java/main/org/adjective/syntactic/convert/j7to8/util/Importer.java

+/*
+ * ------------------------------------------------------------------------
+ *  Copyright 2013 Tim Vernum
+ *  ------------------------------------------------------------------------
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ *
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ *  ------------------------------------------------------------------------
+ */
+package org.adjective.syntactic.convert.j7to8.util;
+
+import org.adjective.syntactic.parser.ast.ASTImportDeclaration;
+import org.adjective.syntactic.parser.ast.ASTQualifiedIdentifier;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Map;
+
+public class Importer
+{
+    private final ClassFinder _classFinder;
+    private final Map<String, String> typeImports;
+    private final List<String> typeOnDemandImports;
+
+    public Importer(final ClassFinder classFinder)
+    {
+        _classFinder = classFinder;
+        this.typeImports = new LinkedHashMap<String, String>();
+        this.typeOnDemandImports = new ArrayList<String>();
+    }
+
+    public void add(final ASTImportDeclaration node)
+    {
+        if (node.isStatic())
+        {
+            return;
+        }
+        final ASTQualifiedIdentifier identifier = node.getIdentifier();
+        if (node.isOnDemand())
+        {
+            typeOnDemandImports.add(identifier.getName());
+        }
+        else
+        {
+            typeImports.put(identifier.getLastIdentifier().getIdentifier(), identifier.getName());
+        }
+    }
+
+    public String getQualifiedName(String simpleName)
+    {
+        final String importedName = typeImports.get(simpleName);
+        if (importedName != null)
+        {
+            return importedName;
+        }
+        for (String pkg : typeOnDemandImports)
+        {
+            final String qualifiedName = lookupClass(pkg, simpleName);