leszekp | 7 Feb 10:57
Gravatar

javac lexer parser rewrite

Hello

Javac scanner and parser now are handwritten. The code, especially in parser is quite messy and
hard to read and modify.
It is possible to rewrite lexer and parser using some kind of java parser generator.
It would improve readability and allows for easier modifications.

There is a project 'compiler grammar' (which seems dormant). Java lexer and parser were rewritten
using antlr. But antrl generated parsers are very slow.

Many lexer and parser generators exists which are able to process 'classic' regular expressions for lexer or
context free grammars for parser and produce fast code (ie. jflex, beaver, jikes parser generator and more)

What do you think about it? Is there a need for such thing? Is it worth the effort?

Regards
Leszek Piotrowicz

Crazy Java | 29 Jan 13:40
Picon

javac pretty printer probable bugs

Hi,
 
 
as part of the javac AST Visualizer project, I have some difficulties with javac's pretty printer. The problem is the fact, that I am doing double compilation (after first compilation I get the textual representation of produced AST and that is in fact used for visualization purposes). Double compilation is needed because I want to visualize all the compiler sugar (default constructor, effectively final variables in ARM, code generated for enum, ...).
 
The problem is that javac's pretty printer (I guess it is pretty printer) after calling CompilationUnitTree.toString() produces in some specific situations code that is not able to compile:
 
1.) it transforms
public class FullClassUsage {
    {
        new <Object> ArrayList<String>(10) {
            {
                add("123");
            }
        };
    }
}
into
public class FullClassUsage {
   
    public FullClassUsage() {
        super();
    }
    {
        new <Object>ArrayList<String>(10){
           
            (int x0) {
                super(x0);
            }
            {
                add("123");
            }
        };
    }
}
the (int x0) is the problem.
 
2.) when using together with enum types it transforms:
public enum SimpleEnum {
    ENUM_CONSTANT_1,
    ENUM_CONSTANT_2
}
into
public enum SimpleEnum {
    /*public static final*/ ENUM_CONSTANT_1 /* = new SimpleEnum() */,
    /*public static final*/ ENUM_CONSTANT_2 /* = new SimpleEnum() */;
   
    private SimpleEnum() {
        super();
    }
}
that is really weird. Not only it generates comments ??? but also a super call causing the code not to compile. I would also assume that it will generate all the enum type code (constructors with n+2 arguments, valueOf() factory method, extending java.lang.Enum, ...).
 
Is there any reason why it produces that weird code?
Is there any better way to get the Textual representation of CompilationUnitTree (using pretty printer) that will compile in both of these examples ?
 
 
//Martin
Crazy Java | 21 Jan 16:39
Picon

javac AST Visualizer on NetBeans Platform

Hi,


I just finished my first NetBeans platform application. It visualizes javac's AST from given java source file.

Maybe some of you might be interested in or provide feedback... I wrote an article about it on my blog.


Cheers

Andrew Phillips | 31 Dec 16:17

Generics compilation failure casting List<? extends Set...> to List<Set...> under Java 7

Hi all

During some recent work to get jclouds to compile under Java 7 I came  
across a generics compilation failure that can be reproduced using the  
following sample code:

classGenericCompilationFailureDemo{
     List<?extendsGenericCompilationFailureDemo>newList(){
         returnnewArrayList<GenericCompilationFailureDemo>();
     };

     voiduseList(){
         List<GenericCompilationFailureDemo>list =
             (List<GenericCompilationFailureDemo>)newList();
     }

     List<?extendsSet<GenericCompilationFailureDemo>>newListOfSpecificSets(){
         returnnewArrayList<Set<GenericCompilationFailureDemo>>();
     };

     voiduseListOfSpecificSets(){
         List<Set<GenericCompilationFailureDemo>>listOfSpecificSets =
             (List<Set<GenericCompilationFailureDemo>>)newListOfSpecificSets();
     }

     List<?extendsSet<?extendsGenericCompilationFailureDemo>>newListOfSets(){
         returnnewArrayList<Set<?extendsGenericCompilationFailureDemo>>();
     };

     voiduseListOfSet(){
         List<Set<?extendsGenericCompilationFailureDemo>>listOfSets =
             (List<Set<?extendsGenericCompilationFailureDemo>>)newListOfSets();
     }
}

This passes under Sun JDK 1.6.0_20 and _24 but fails under Oracle JDK  
1.7.0 and _01 with:

[ERROR]src\main\java\GenericCompilationFailureDemo.java:[56,78]error:inconvertible  
types

The comments and tentative answer to my resulting StackOverflow question

http://stackoverflow.com/questions/8637937/why-does-a-generic-cast-of-a-list-extends-set-to-listset-succeed-on-sun

seem to suggest that this is a compiler bug. We found a simple  
workaround, by the way: do the cast in a separate method (see  
https://github.com/jclouds/jclouds/commit/1ba75f623f03908d87c2fddce46e276098f3db40).

Any comments or suggestion much appreciated! And a belated Merry  
Christmas and Happy New Year, of course ;-)

Regards

Andrew

Jesse Glick | 28 Dec 21:45
Picon
Favicon

Getting langtools into Maven Central

Since official releases of langtools are now available under a permissive license, has any thought been
given to getting it published on Maven Central for various uses?

1. Programs running on JDK 5, or Java 6+ JRE, should be able to use JSR 199/269 just by declaring a dependency
on it.

2. Projects should be able to able to use these APIs in unit tests, e.g. to compile code snippets, without
fear that tools.jar will not be in the test classpath. 
Currently you have to use a system-scope hack [1] which is not portable and can cause fatal errors dealing
with released POMs if you are not careful (e.g. follow the 
recommended idiom, which broke due to the Oracle acquisition [2]).

3. Projects may wish to compile sources using a specific version of javac [3], especially if they use exotic
generics features and so on; some builds of javac contain 
known bugs that were later fixed, but you cannot rely on every developer checking out your project to have
the latest update installed. Would be great to have a 
plexus-compiler-api plugin [4] using JSR 199, where the langtools release could be overridden via <plugin>/<dependencies>.

I did a quick search for existing artifacts; besides JSR 308, the only one I could find is sorcerer-javac
[5], which is from an old snapshot 
(compiler-7-ea-src-b12-06_may_2007.zip).

It would be great to get langtools from OpenJDK 7 (using -target 5) published on Maven Central, probably via
OSSRH [6]. For maximum flexibility it could be split into 
several artifacts, with logical interdependencies (deps on #1 would be marked <optional> since Java 6+
users do not necessarily want them separately):

1. javax.annotation.processing + javax.lang.model + javax.tools
2. com.sun.source >#1
3. com.sun.tools.javac >#2
4+ javadoc, javap, javah, doclets, apt...?

or more simply into javax.** vs. com.sun.** artifacts.

Publishing regular updates would ideally require Ant targets to build the requisite JARs (binary,
sources, javadoc) and deploy them to the staging server, which I guess 
you mean a patch to make/build.xml. Some mapping from OpenJDK Hg tags (jdk7u2-b13) or printed versions
(1.7.0_02) to standard-format Maven versions like 7.0.2 might be 
necessary to make comparisons happy.

Does this sound like a good direction to take? If so, I could try to set up OSSRH for the project and supply a
patch for the build script, though it would be best for 
organizational reasons if an OpenJDK committer working on langtools did the actual publishing on an
ongoing basis.

[1] http://maven.apache.org/general.html#tools-jar-dependency
[2] http://java.net/projects/sezpoz/sources/svn/revision/156
[3] https://jira.codehaus.org/browse/MNG-1867?focusedCommentId=231831&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-231831
[4] http://plexus.codehaus.org/plexus-components/plexus-compiler/plexus-compiler-api/apidocs/index.html
[5] http://search.maven.org/#artifactdetails%7Corg.jvnet.sorcerer%7Csorcerer-javac%7C0.8%7Cjar
[6] https://docs.sonatype.org/display/Repository/Sonatype+OSS+Maven+Repository+Usage+Guide

Richard Warburton | 7 Dec 01:21
Picon
Gravatar

Broken Link

The OpenGrok link on http://openjdk.java.net/groups/compiler/ is broken.

Not entirely sure if this is the right place to report this, but I 
didn't see an email address listed on 
http://openjdk.java.net/groups/compiler/web-howto.html.

regards,

   Richard

Richard Warburton | 5 Dec 23:36
Picon
Gravatar

Another possible generics bug

>From http://java.sun.com/docs/books/jls/third_edition/html/names.html#6.3.1:

"A declaration d of a type named n shadows the declarations of any other 
types named n that are in scope at the point where d occurs throughout 
the scope of d."

Which suggests to me that in the following example, the inner class T 
should be the type of the field 'q'.

class Test<T> {
     class T { }
     T q;

     public static void main(String[] args) throws Exception {
         System.out.println(Test.class.getDeclaredField("q").getType());
     }

}

This example compiles fine under both ecj and javac.  In ecj Test.T is 
picked as the type for q, in javac the generic parameter <T> is picked.  
Is this a bug, or have I misread the specification?

I'm using the following version:

Javac version = 1.7.0_147
eclipse build number = 20110916-0149 (Indigo service release 1)

regards,

   Richard

Richard Warburton | 5 Dec 23:14
Picon
Gravatar

Possible Generics bug in Javac

I'm not entirely sure whether this is a bug - but it does look like one 
to me, the first example below compiles, and runs as expected, the 
second raises a compile error in javac, but not in ecj.

-----------------------------------
class Test {
     static T q;
     static class T { }

     public static void main(String[] args) throws Exception {
         System.out.println(Test.class.getDeclaredField("q").getType());
     }
}
-----------------------------------
class Test <T> {
     static T q;
     static class T { }

     public static void main(String[] args) throws Exception {
         System.out.println(Test.class.getDeclaredField("q").getType());
     }
}
-----------------------------------

regards,

   Richard

Weijun Wang | 5 Dec 14:19
Picon
Favicon

how to prevent deprecation warning of import?

The com.sun.security.auth.SolarisPrincipal is a deprecated class, 
another class com.sun.security.auth.module.SolarisLoginModule 
referencing it is also deprecated. Because of the "import 
com.sun.security.auth.SolarisPrincipal" line in the latter class, 
compiling it shows a warning. What is the best way to let it disappear?

The only solution I know is to remove the import line and always use the 
full name.

Thanks
Max

Dmeetry Degrave | 3 Dec 19:24
Picon
Favicon

Code review for 7086595: Error message bug: name of initializer is 'null'

Hi,

I'm looking for a code review for 7086595. This is a port from jdk8 to 
7u4 with identical fix.

bug: http://bugs.sun.com/view_bug.do?bug_id=7086595
webrev: http://cr.openjdk.java.net/~dmeetry/7086595/webrev.0/
jdk8: http://hg.openjdk.java.net/jdk8/tl/langtools/rev/ed338593b0b6

thanks,
dmeetry

Dmeetry Degrave | 20 Nov 16:47
Picon
Favicon

Code review for 7097436: "Project Coin: duplicate varargs warnings on method annotated with @SafeVarargs"

hi,

I'm looking for a code review for 7097436. This is a port from jdk8 to 
7u4 with identical fix.

bug: http://bugs.sun.com/view_bug.do?bug_id=7097436
webrev: http://cr.openjdk.java.net/~dmeetry/7097436/webrev.0/
jdk8: http://hg.openjdk.java.net/jdk8/tl/langtools/rev/b5d0b8effc85

javac jtreg tests passed.

thanks,
dmeetry


Gmane