Comments (2)
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.
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)
- error: An unhandled exception was thrown by the Error Prone static analysis plugin. HOT 1
- NPE with StatementSwitchToExpressionSwitch on JDK21EA HOT 1
- Bug when migrating to Java 21 HOT 2
- Add `BugChecker.SwitchExpressionTreeMatcher` to support checking of `switch` expressions HOT 5
- NoSuchMethodError when building under JDK21 HOT 1
- ImmutableEnumChecker in Enum where an attribute is a Record type which is immutatble HOT 1
- java: An unhandled exception was thrown by the Error Prone static analysis plugin. HOT 1
- Index out of bound exception. HOT 1
- DeadException rule throws java.lang.NullPointerException
- error: [DoNotCall] Calling run on Thread runs work on this thread
- Consider using an embedded standalone javac compiler instead of relying on JVM internals
- False positive: FieldCanBeLocal reported when overriding default record constructor HOT 1
- How to avoid "overlaps with existing replacements"
- Patch should identify itself
- Allow DoNotCall annotation on constructors HOT 1
- False positives for OperatorPrecedence bug pattern HOT 3
- IllegalArgumentException with MustBeClosedChecker HOT 1
- NullPointerException in NestedInstanceOfConditions
- NullPointerException in InstanceOfAndCastMatchWrongType
- All checks should treat `String#formatted` the same as `String#format` HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from error-prone.