eclipse-jdt

Formatting Source Code programmatically with JDT

自古美人都是妖i 提交于 2019-12-30 06:28:17
问题 I am generating some classes with JDT. Afterwards I would like to format the whole ICompilationUnit, just as if I pressed Ctrl+Shift+F (Source > Format) in an open Editor without a selection. Any pointers for the API in JDT to format the source code programmatically is highly appreciated. Addition: I tried it like this, but the code isn't changed. What am I mssing? private void formatUnitSourceCode(ICompilationUnit targetUnit, IProgressMonitor monitor) throws JavaModelException {

Rewrite method incorrectly rewrite change to ICompilationUnit the second rewrite update

岁酱吖の 提交于 2019-12-25 00:17:35
问题 I have this method UpdateProperty: public void run(ObjectNavigatorModel model, String propertyKey, String propertyValue) { // get reference to CompilationUnit ICompilationUnit cu = model.getICompilationUnit(); try { cu.becomeWorkingCopy(null); } catch (JavaModelException e1) { e1.printStackTrace(); } // unit instance of CompilationUnit CompilationUnit unit = model.getCompilationUnit(); AST ast = unit.getAST(); ASTRewrite rewrite = ASTRewrite.create(ast); // get methods map MethodVisitor

JDT - Bindings are lost after copying subtree

痞子三分冷 提交于 2019-12-24 15:11:47
问题 I have a code that removes all complex (not SimpleName expressions) from if s. It works fine and the code like if(obj.getSomeInt() > 10) { /* body */ } is converted to boolean value = obj.getSomeInt() > 10; if(value) { /* body */ } But before changing AST the call to resolveBinding() and resolveTypeBinding() for obj gives correct results, but after I get null for the both calls. Is that as designed? If yes, please tell how to fix that? My code: if(node instanceof IfStatement) { IfStatement

How to determine if a class has an annotation using JDT, considering the type hierarchy

老子叫甜甜 提交于 2019-12-24 15:07:53
问题 There is a simple way to check if an annotation is present in a ICompilationUnit using Eclipse JDT? I tried to do the code below, but I will have to do the same thing for the super classes. IResource resource = ...; ICompilationUnit cu = (ICompilationUnit) JavaCore.create(resource); // consider only the first class of the compilation unit IType firstClass = cu.getTypes()[0]; // first check if the annotation is pressent by its full id if (firstClass.getAnnotation("java.lang.Deprecated").exists

Eclipse Luna StackOverflow exception at Build Time

落爺英雄遲暮 提交于 2019-12-24 03:09:07
问题 I get this SO exception when building the workspace. !ENTRY org.eclipse.core.jobs 4 2 2014-06-27 16:01:29.327 !MESSAGE An internal error occurred during: "Rebuilding". !STACK 0 java.lang.StackOverflowError at org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding.mentionsAny(ParameterizedTypeBinding.java:915) at org.eclipse.jdt.internal.compiler.lookup.ParameterizedTypeBinding.mentionsAny(ParameterizedTypeBinding.java:915) My workspace has a lot of projects, with a lot of compile

Running an Eclipse Plugin

半世苍凉 提交于 2019-12-24 02:07:01
问题 How do I run the plugin project under Resources [1] here: http://www.eclipse.org/articles/article.php?file=Article-JavaCodeManipulation%5FAST/index.html If I am not wrong, the project starting point is here public class ASTArticleActionDelegate implements IObjectActionDelegate -> public void run(IAction action) public void run(IAction action) { if (selection instanceof IStructuredSelection) { ICompilationUnit lwUnit = (ICompilationUnit) ((IStructuredSelection) selection).getFirstElement();

How does JUnit find the eclipse plug-in being tested?

我是研究僧i 提交于 2019-12-24 01:23:49
问题 I am writing a plug-in (ClassRefactoringPlugin) that examines source code in Eclipse 3.6.1. The plug-in contains a CallData class that examines a Java source file and figures out which Java elements are called from a method using JDT operations. I wrote a JUnit 4 test for this class that also resides in the ClassRefactoringPlugin project. When I ran it as a JUnit plug-in test, I got: Java Model Exception: Java Model Status [ClassRefactoringPlugin does not exist] What have I done wrong? The

Is it possible to load an eclipse Java project using JDT in the headless mode?

家住魔仙堡 提交于 2019-12-23 17:34:01
问题 I have an eclipse Java project and want to get information like project source dir, classpaths, etc. My current implementation parses the .project file. But as I didn't find any official documentation describing the structure of the .project file, I have some concerns for the robustness of this approach. A more convenient and robust way would be to use JDT (headlessly) to load the project and get the relevant information from the IJavaProject object. Although the developer guide of JDT says

How can I add JDT as a Maven dependency?

自闭症网瘾萝莉.ら 提交于 2019-12-23 07:41:05
问题 I'm trying to create a project that depends on JDT core. I was using the entries in Maven central until I realized they were several years out of date. After poking around a little, I came across https://repo.eclipse.org. I found the repository I needed and added it: <repository> <id>eclipse</id> <name>Eclipse Repository</name> <url>https://repo.eclipse.org/content/groups/eclipse/</url> </repository> ... <dependency> <groupId>org.eclipse.jdt</groupId> <artifactId>org.eclipse.jdt.core<

Runtime error using the Eclipse Abstract Syntax Tree

馋奶兔 提交于 2019-12-22 07:20:10
问题 I'm trying to use AST parser in a non-plugin environment. The code compiles, but I get the following runtime error: Exception in thread "main" java.lang.NoClassDefFoundError: org/eclipse/core/resources/IResource at org.eclipse.jdt.core.dom.ASTParser.(ASTParser.java:189) at org.eclipse.jdt.core.dom.ASTParser.newParser(ASTParser.java: 118) Here is the code I'm running: import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.jdt.core.dom.*; public class TestAST { private void