Bug 71193 - class literal not recognized by JDT
Summary: class literal not recognized by JDT
Status: RESOLVED INVALID
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 3.0   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-07-30 20:42 EDT by Duffy Gillman CLA
Modified: 2004-10-27 06:57 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Duffy Gillman CLA 2004-07-30 20:42:32 EDT
The UI marks the use of the "class literal" as an "invalid Expression" (literal
message is "Syntax error on token "class", invalid Expression").  The class
literal is a valid Java construct and should not be marked invalid.  The root of
this error is likely at a lower level within the JDT.  The class literal is
defined in the Java Language Specification as follows:

---------
15.8.2 Class Literals
A class literal is an expression consisting of the name of a class, interface,
array, or primitive type followed by a `.' and the token class. The type of a
class literal is Class. It evaluates to the Class object for the named type (or
for void) as defined by the defining class loader of the class of the current
instance.

---------

The following should be valid code:

package foo;

public class bar
{
   static String myVar = class.getName() + " is my fully qualified classname";

   public void printName()
   {
       System.out.println (myVar);
   }
}

The output from calling printName() on a bar instance should be:

foo.bar is my fully qualified classname
Comment 1 Duffy Gillman CLA 2004-07-30 20:45:03 EDT
...more specifically, the Eclipse UI underlines the word "class" in the example
provided, and marks a red "X" in the column next to the line:

  public class bar
  {
X    static String myVar = class.getName() + " is my fully qualified classname";
                           -----
...

Mousing over the X gives the error message reported.
Comment 2 Philipe Mulet CLA 2004-07-31 15:38:44 EDT
Please read closer the spec. Its syntax is a type name + dot + 'class', e.g.
String.class