Question

The Xtype grammar contains two ways to refer to Java types: JvmType and JvmTypeReference.

I don't understand:

  • why there are two;
  • how they are different;
  • when I should use which.
Was it helpful?

Solution

JvmType is an EMF view on (the declaration of) a Java type. It's subtypes represent the different kinds of types in Java, such as classes and interfaces (JvmGenericType), enums (JvmEnum) and annotation types (JvmAnnotationType) or primitive types (JvmPrimitiveType).

JvmTypeReference is a reference to a declared type. It's cross-reference type points to an JvmType, but it can have additional properties such as type arguments ( JvmParameterizedTypeReferece). Java 8 would call the JvmTypeReference a "type use". most of its subclasses have a more technical nature, e.g. to represent stages of a partly resolved type during type inferrence.

As arrays are in a way hard-wired into Java's typesystem, JvmArrayType inherits from JvmType rather than being a specific JvmTypeReference.

OTHER TIPS

This remotely rings a bell from the time I was doing work with Eclipse's Java AST. There are two options on how deeply you want a Java file processed:

  • just parsing;
  • type binding.

When you use type binding, you get access to the actual Java types being referred to; without that you just get a type reference, which amounts to a parsed Java name.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top