eclipse-jdt

Exception while generating AST using Eclipse JDT SDK in a non-eclipse environment

不想你离开。 提交于 2019-12-12 03:08:27
问题 I'm trying to use the jdt's AST generation feature in a non-eclipse environment(as a plugin for another basic java ide). My program creates the AST correctly when I run it inside eclipse, but when I test the plugin it from the ide I get this exception: Exception in thread "AWT-EventQueue-0" java.lang.NoSuchFieldError: ignoreMethodBodies at org.eclipse.jdt.core.dom.CompilationUnitResolver.parse(CompilationUnitResolver.java:491) at org.eclipse.jdt.core.dom.ASTParser.internalCreateAST(ASTParser

checkNewChild throws error when lowering JDT code

社会主义新天地 提交于 2019-12-12 02:17:56
问题 So in my compilers class we are using JDT to represent our subset of Java. I already have assignment working and so I thought it would be a good idea to implement increment/decrement by lowering it to assignment. I realized while typing this that because the expression being incremented might have an effect this is not 100% valid. Still I want to do something like this for for loops as well. So I have this code @Override public boolean visit(final PostfixExpression node) { //in this we lower

How to count all the method calls in JDK using Eclipse JDT

╄→尐↘猪︶ㄣ 提交于 2019-12-11 16:41:04
问题 I have to count all the methods in JDK, for each class, count the method calls it received; for each method, count the number of times this method is called; Hint: Use Eclipse JDT to create Abstract Syntax tree. Can any body please explain how should I approach this problem. A brief algorithm would be great help. Thanks 回答1: You can approach your problem using the below steps: First convert your java class to a CompilationUnit so that it can be traversed. Then use the ASTVisitor pattern to

Eclipse JDT: How to find JDK MethodInvocation and ClassInstanceCreation

懵懂的女人 提交于 2019-12-11 14:49:07
问题 I am using Eclipse JDT ASTVisitor to find Java method invocations and class instance creations from java source files. Now, I can find all of these. But I can not judge whether these method invocations and class instance creations is from JDK library or not . So, How can I get the JDK library method invocations (eg: InputStream.read()) and class instance (eg: new String())? The following is my code. JdtAstUtil.java import java.io.BufferedInputStream; import java.io.FileInputStream; import

How can I mimic fully compatible ICompilationUnit from standalone Java files?

左心房为你撑大大i 提交于 2019-12-11 06:35:40
问题 I am hacking an Eclipse Plugin that is working perfectly for Java files in Java projects. I want to make it work for Java files in any kind of project. This plugin processes each Java file as a ICompilationUnit . However, in my approach I can only get an instance of File . Upon suggestion in another post, I am manually creating an IJavaElement from any Java file: IJavaElement element = JavaCore.create(file); This seems to work fine, except for some specific cases. E.g., when I try to get the

Get ICompilationUnit/ITypeRoot from standalone java file for Eclipse Plugin

左心房为你撑大大i 提交于 2019-12-11 06:25:45
问题 I am hacking an Eclipse Plugin that is working perfectly for Java files in Java projects. I want to make it work for Java files in any kind of project. This plugin processes each Java file as a ICompilationUnit . However, in my approach I can only get an instance of IFile . How can I create a ICompilationUnit from this IFile object? As alternative a ITypeRoot might also work. I've seen this being created directly from the editor using the following: IJavaElement input= JavaUI

Can I use JDT search engine while parsing a source from JDT AST

為{幸葍}努か 提交于 2019-12-11 05:55:48
问题 I'm using JDT AST to parse a given source. I want to find the references of a given object/variable when it triggers the relavant visitor when using AST. E.g.: Consider the following code: public class SampleClass { public void printMe(){ System.out.println("hello"); } public static void main(String a[]){ SampleClass s =new SampleClass(); // do some other work s.printMe(); } } When I'm parsing the above code, when it comes to the variable declaration of "s", it will call the visitor method of

Eclipse JDT Code Formatter: Indent parameter in IF-Statement

独自空忆成欢 提交于 2019-12-11 03:34:52
问题 I have a questions regarding the Eclipse code formatter in JDT: How can I make Eclipse format the following code in the given way: BEFORE if (objectA.getFoo().equals(objectB.getFoo()) && (objectA.getBar().equals(objectB.getBar()) || resultOfAnotherTest)){ ... } AFTER if (objectA.getFoo().equals(objectB.getFoo()) && (objectA.getBar().equals(objectB.getBar()) || resultOfAnotherTest)){ ... } A second example: BEFORE if (foo1 == foo2 && bar1 == bar2 && blub1 == blub2 && !braindead){ ... } AFTER

Java JDT parser. Get variable type of VariableDeclarationFragment

女生的网名这么多〃 提交于 2019-12-11 02:40:04
问题 I've been implementing a Java parser with JDT and I can't figure out how to get a variable type when its node's type is VariableDeclarationFragment . I found out how to get a variable type only when it comes to VariableDeclaration My code is the following. public boolean visit(VariableDeclarationFragment node) { SimpleName name = node.getName(); System.out.println("Declaration of '" + name + "' of type '??'); return false; // do not continue } Can anyone help me? 回答1: I just figured out how

Tomcat Java Compiler difference

末鹿安然 提交于 2019-12-11 00:13:44
问题 I have two tomcat 5.5 servers. One is for development and one is Production. Both runs on Java 1.6. But recently I had a problem where generics are unable to run on the Production environment but runs smoothly on development. The difference between these two system are in tomcat 5.5/common/lib/ . My development envr contains ecj-3.7.2.jar but the production doesn't have this file instead it contains jasper-compiler-jdt.jar . When I replace jasper-compiler-jdt.jar with ecj-3.7.2.jar , the