Git Product home page Git Product logo

Comments (2)

cushon avatar cushon commented on April 28, 2024

Original comment posted by [email protected] on 2012-08-03 at 10:45 PM


I looked into this a bit. You're right: for plain classes this is easy enough, but when you get into more complex stuff you start rebuilding the parse and attribution phases of the compiler.

What is we provided a TypeBuilder class that lets you build up a type programmatically? So you'd specify something like:
Type t = new TypeBuilder(basetype).setIsArray(true).build();
or
Type t = new TypeBuilder(basetype).setTypeParams(tparam1, tparam2, ...).build();

I would also provide a convenience method for getting simple types like java.lang.Object.


Status: Started
Owner: [email protected]
Labels: Priority-Medium

from error-prone.

cushon avatar cushon commented on April 28, 2024

Original comment posted by [email protected] on 2012-09-07 at 10:29 PM


I committed a fix in revisions 82ee5e6, f56063d, 0fc2db4, and eaeae92. I provided two new instance methods in VisitorState:
getTypeFromString(typeStr) and getType(baseType, isArray, typeParams)

getTypeFromString returns a Type object from a simple (not an array, not generic) type string (e.g., "java.lang.Object"). It returns null if the compiler has not seen that type yet.

getType lets you construct complex types if you already have the baseType and parameter Types. This lets me avoid parsing a type string. For example, to construct the Type ArrayList<String>, you would do this:
Type baseType = getTypeFromString("java.util.ArrayList");
List<Type> typeParams = new ArrayList<Type>();
typeParams.add(getTypeFromString("java.lang.String");
getType(baseType, false, typeParams);


Status: Fixed
CC: [email protected]

from error-prone.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.