eclipse-jdt

Eclipse JDT ASTParser convert enum declaration node incorrectly

爷,独闯天下 提交于 2020-01-13 03:47:18
问题 I am working on analyzing Java code by using JDT and going to build a standalone analysis tool depend on org.eclipse.jdt.core package instead of an eclipse plug-in. But I found that my tool did not work correctly on enum declaration node which appeared in Java code. In my AST which created by jdt, keyword enum was regarded as a typename instead of an enum declaration. So I want to know how I should be can ensure that my tool can deal the enum declaration correctly. The jdt package that I used

How can I import eclipse JDT classes in a project

让人想犯罪 __ 提交于 2020-01-11 03:16:07
问题 I want to do the following imports in a class. import org.eclipse.jdt.core.dom.*; import org.eclipse.jdt.core.compiler.CharOperation; import org.eclipse.jdt.core.compiler.IProblem; import org.eclipse.jdt.internal.compiler.ClassFile; import org.eclipse.jdt.internal.compiler.CompilationResult; import org.eclipse.jdt.internal.compiler.Compiler; import org.eclipse.jdt.internal.compiler.DefaultErrorHandlingPolicies; import org.eclipse.jdt.internal.compiler.ICompilerRequestor; import org.eclipse

Programmatically setting a Xtend class as super class of a Java class

拈花ヽ惹草 提交于 2020-01-06 19:31:20
问题 I am currently working on an Eclipse plugin. I want to set programmatically a Xtend class as super class of a Java class. If both classes were Java classes I would do that with the JDT API. The problem is that I cannot access the Xtend classes through the Java AST or the Java Model. This is what I tried to access the Xtend classes: using an ASTParser using IJavaProject.findType() Is there a way to set a Xtend class as super class? Is there a way to set a superclass with a string (package +

How could I search references to a field on a AST or a CompilationUnit in eclipse?

会有一股神秘感。 提交于 2020-01-05 08:42:32
问题 Hi, I'm developing an Eclipse plugin. I need to find all the references in the source using AST's or jdt.core.dom or something like that. I need this references like ASTNodes in order to get the parent node and check several things in the expression where references are involved. Thanks beforehand. Edited: I want to concrete a little more, My problem is that I try to catch some references to a constant but... I have not idea how I can do to catch in the matches this references. I need check

Contributing a template to Eclipse via a Plugin to the Java Editor, but should vary based on the context

浪尽此生 提交于 2020-01-05 01:52:06
问题 So I wrote a plugin to contribute a template to the java editor in eclipse by using the extension "org.eclipse.ui.editors.templates". This just adds the template. That's not what I want. I want to replace the existing template with the new one, that too based on a condition. For example, if the file name is "john.java", within that file if I type "sysout", I want my template to show up rather than the default one. Any ideas how I might be able to do this ? 回答1: OK. I finally found a work

How to get the enclosing method node with JDT?

▼魔方 西西 提交于 2020-01-03 16:47:19
问题 When I have a method foo() that calls bar(), how can I get the foo() AST node from MethodInvocation node (or whatever statements/expressions in the method)? For example, I need to know the IMethod foo from b.bar(). public void foo() { b.bar(); } 回答1: In JDT/UI we have a helper method to do this. Take a look at org.eclipse.jdt.internal.corext.dom.ASTNodes.getParent(ASTNode, int) 回答2: I came up with this code, but I expect there are better ways to get the result. public static IMethod

Eclipse “Open Type” dialog restricted to a particular interface

孤者浪人 提交于 2020-01-03 01:38:27
问题 I'm trying to create a JavaUI.createTypeDialog() which restricts the user to selecting only types belonging to a particular interface. How could I do this? 回答1: This answer shows how to obtain the type hierarchy for a particular type. You could use similar processing to obtain the TypeHierarchy for the interface, then populate the list with the resultant types. IProject project; //currently selected project //get the java project and locate the interface type JavaProject javaProject =

JDT - Trying to change superclass of Type. I don't know the Qualified Name of a Super Class

北战南征 提交于 2020-01-02 12:09:26
问题 I have a program that, among other tasks, has to change the super class of some classes using JDT. I have two strings with the qualified name of the superclasses to swap, for example "org.example.John" and "org.example.Smith" and I'm parsing the whole AST searching for classes that extend these ones. My problem happens when I'm trying to find out the qualified name of the super class. I just can't find a way. Given an ICompilationUnit (representing a class), I use a an ASTVisitor to parse the

Why I got no super classes with getAllSuperclasses() in JDT API?

谁都会走 提交于 2020-01-01 12:35:30
问题 I have class A, and class B that inherits A in Eclipse workspace. The issue that I have is that I got nothing when I tried to get the super types of type B using eclipse JDT API. This is the code (I got the code from - List all subclasses with fully qualified names): IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); java.io.File workspaceDirectory = root.getLocation().toFile(); // 1. The name of the project in the workspace IProgressMonitor pm = new NullProgressMonitor();

How to get the sources of JDT of eclipse?

浪尽此生 提交于 2019-12-30 06:30:10
问题 I'm trying to write an Eclipse plugin, but I found that there is no source by default. I searched in www.eclipse.org, but didn't find anything. My eclipse is 3.6.2. Where can I get the source of JDT? 回答1: Assuming that you want to be able to just look at JDT source code (as opposed to edit it), the easiest thing to do is to install the source plugins. Head over to the following update site for Helios: http://download.eclipse.org/releases/helios/ Then look for an entry labeled JDT Source or