Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provided example not working #26

Open
rishabhrishu opened this issue Mar 26, 2019 · 2 comments
Open

Provided example not working #26

rishabhrishu opened this issue Mar 26, 2019 · 2 comments

Comments

@rishabhrishu
Copy link

I tried to run the provided example, but it gives me errors.
My code-

import com.netflix.rewrite.ast.*;
import com.netflix.rewrite.parse.*;
import com.netflix.rewrite.refactor.*;

public class MainClass {
    public static void main(String[] args) {
        new MainClass().refactorMethodName();
    }
    public void refactorMethodName() {
        Parser parser = new OracleJdkParser(); 
        String a = "class A {{ B.foo(0); }}";
        String b = "class B { static void foo(int n) {} }";

        Tr.CompilationUnit cu = parser.parse(a, /* which depends on */ b);
        Refactor refactor = cu.refactor()
                .changeMethodName(cu.findMethodCalls("B foo(int)"), "bar");
        Tr.CompilationUnit fixed = refactor.fix();
    }
}

The Error I got is -

521 [main] WARN com.netflix.rewrite.parse.OracleJdkParser - Failed symbol entering or attribution
java.lang.NullPointerException
	at jdk.compiler/com.sun.tools.javac.comp.Enter.visitTopLevel(Enter.java:340)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:529)
	at jdk.compiler/com.sun.tools.javac.comp.Enter.classEnter(Enter.java:286)
	at jdk.compiler/com.sun.tools.javac.comp.Enter.classEnter(Enter.java:301)
	at jdk.compiler/com.sun.tools.javac.comp.Enter.complete(Enter.java:576)
	at jdk.compiler/com.sun.tools.javac.comp.Enter.main(Enter.java:560)
	at com.netflix.rewrite.parse.OracleJdkParser.enterAll(OracleJdkParser.kt:122)
	at com.netflix.rewrite.parse.OracleJdkParser.parse(OracleJdkParser.kt:101)
	at com.netflix.rewrite.parse.AbstractParser.parse(Parser.kt:69)
	at com.netflix.rewrite.parse.Parser$DefaultImpls.parse(Parser.kt:58)
	at com.netflix.rewrite.parse.AbstractParser.parse(Parser.kt:65)
	at com.netflix.rewrite.parse.Parser$DefaultImpls.parse(Parser.kt:38)
	at com.netflix.rewrite.parse.AbstractParser.parse(Parser.kt:65)
	at com.netflix.rewrite.parse.Parser$DefaultImpls.parse(Parser.kt:35)
	at com.netflix.rewrite.parse.AbstractParser.parse(Parser.kt:65)
	at MainClass.refactorMethodName(MainClass.java:23)
	at MainClass.main(MainClass.java:15)
Exception in thread "main" java.lang.NoSuchMethodError: com.sun.tools.javac.tree.JCTree$JCCompilationUnit.getPackageName()Lcom/sun/tools/javac/tree/JCTree$JCExpression;
	at com.netflix.rewrite.parse.OracleJdkParserVisitor.visitCompilationUnit(OracleJdkParserVisitor.kt:304)
	at com.netflix.rewrite.parse.OracleJdkParserVisitor.visitCompilationUnit(OracleJdkParserVisitor.kt:40)
	at jdk.compiler/com.sun.tools.javac.tree.JCTree$JCCompilationUnit.accept(JCTree.java:591)
	at jdk.compiler/com.sun.source.util.TreePathScanner.scan(TreePathScanner.java:82)
	at com.netflix.rewrite.parse.OracleJdkParser.parse(OracleJdkParser.kt:112)
	at com.netflix.rewrite.parse.AbstractParser.parse(Parser.kt:69)
	at com.netflix.rewrite.parse.Parser$DefaultImpls.parse(Parser.kt:58)
	at com.netflix.rewrite.parse.AbstractParser.parse(Parser.kt:65)
	at com.netflix.rewrite.parse.Parser$DefaultImpls.parse(Parser.kt:38)
	at com.netflix.rewrite.parse.AbstractParser.parse(Parser.kt:65)
	at com.netflix.rewrite.parse.Parser$DefaultImpls.parse(Parser.kt:35)
	at com.netflix.rewrite.parse.AbstractParser.parse(Parser.kt:65)
	at MainClass.refactorMethodName(MainClass.java:23)
	at MainClass.main(MainClass.java:15)

My gradle script contains following dependencies-

dependencies {
    testCompile group: 'junit', name: 'junit', version: '4.12'
    compile 'com.netflix.devinsight.rewrite:rewrite-core:1.2.0'
    compile 'com.netflix.devinsight.rewrite:rewrite-core:0.18.4:jdkbundle'
    compile "org.slf4j:slf4j-api:1.6.1"
    compile "org.slf4j:slf4j-simple:1.6.1"
}
@rutenkolk
Copy link

This may be a bit old but i recently stumbled over this problem as well.

rewrite:rewrite-core:1.2.0 is the version without the jdk parts
rewrite:rewrite-core:1.2.0:jdkbundle is the version containing the jdk parts (shaded)

specifying both doesn't seem helpful. I would suggest you only need the latter. But apparently there is a newer version in the repos than what is documented here.
My dependencies are:

dependencies {
    compile 'com.netflix.devinsight.rewrite:rewrite-core:1.4.0:jdkbundle'
    compile "org.slf4j:slf4j-api:1.6.1"
    compile "org.slf4j:slf4j-simple:1.6.1"
}

@mccxj
Copy link

mccxj commented Mar 31, 2020

if failed again after add jdkbundle, you can add tools yourself.

        <dependency>
            <groupId>com.sun</groupId>
            <artifactId>tools</artifactId>
            <version>1.8.0_212</version>
            <scope>system</scope>
            <systemPath>${java.home}/../lib/tools.jar</systemPath>
        </dependency>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants