eclipse-jdt

Simplifying fully qualified names in Eclipse

戏子无情 提交于 2019-12-22 04:43:26
问题 Does someone know a plugin for Eclipse that replaces fully qualified Java class names with the simple one and the corresponding import where possible? It would be even better if it could be performed as a Save Action. 回答1: No. But you can use Add Import command ( Ctrl + Shift + M ) on each fully qualified identifier to convert it to an import + a short name. 回答2: Here's a plugin offering this functionality called Clean Qualified Types Plugin (CQTP): http://blog.mi-ernst.de/projekte/ 来源: https

In Java, can “void” be considered a primitive type?

自古美人都是妖i 提交于 2019-12-19 12:50:26
问题 I've noticed eclipse JDT uses void as a primitive type. Can this be considered correct? 回答1: I find that, in cases like this, you can't beat going to the Java Language Specification. It is pretty clear about the fact that void is not a primitive. First off, void is not in the list of primitive types. Later on, the JLS explicitly states: the Java programming language does not allow a "cast to void" — void is not a type http://java.sun.com/docs/books/jls/third_edition/html/statements.html#5989

Eclipse Plugin - How to get the last worked on editor

廉价感情. 提交于 2019-12-19 03:58:43
问题 I am writing an eclipse plugin which exposes a view to the user with several buttons. On the click of any button, I would like to paste a certain comment into the editor window where the user is currently working and at the cursor location he is pointing to. Once the user clicks the button, the editor window no longer has focus and the following code does not work. workbench.getActiveWorkbenchWindow().getActivePage().getActiveEditor() How can I detect the editor window where the user was

Is there any kind of “line visitor” in Eclipse JDT Java Parser? If there is not, does someone knows a good workaround?

女生的网名这么多〃 提交于 2019-12-13 14:05:56
问题 I wanna visit the nodes in an AST from a Java file and extract some information related to these nodes. But, I wanna pass by the AST guided by the lines in the source code file. I know there is information about the lines associated with each node, but the problem is that the default way to access the nodes is through specific visitors. So: 1. to avoid redundant visits to the nodes, 2. do not generates overhead while trying to enumerate all the possible node types (or visitors), and 3. to

'java.lang.NoSuchFieldError: ignoreMethodBodies' Exception while creating AST

ε祈祈猫儿з 提交于 2019-12-13 07:35:58
问题 While passing a java source code to the below mentioned code, I get an exception and have no idea how to fix this. Kindlly let me know where I am wrong/ any alternative solution... Source Code: char[] source = resultEntryIndustry.text.toCharArray(); ASTParser parser = ASTParser.newParser(AST.JLS3); parser.setSource(source); Map options = JavaCore.getOptions(); JavaCore.setComplianceOptions(JavaCore.VERSION_1_5, options); parser.setCompilerOptions(options); CompilationUnit cUnit =

Saving modified AST in a new file with eclipse plugin

谁说胖子不能爱 提交于 2019-12-13 00:53:28
问题 I have a eclipse plugin code to manipulate a class (smcho.Hello) in a project/workspace. I could create a CompilationUnit and did some modifications on it, but I need to save the result in different file to check the differences between the two version. This is the code how I get the CompilationUnit. IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); IProject project = root.getProject("Hello"); project.open(null); IJavaProject javaProject = JavaCore.create(project); IType lwType

JDT SearchEngine throws a NullPointerException

旧巷老猫 提交于 2019-12-12 15:29:43
问题 I'm trying to use JDT SearchEngine to find references to a given object. But I'm getting a "NullPointerException" while invoking the "search" method of org.eclipse.jdt.core.search.SearchEngine. Following is the error trace: java.lang.NullPointerException at org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:214) at org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:515) at org.eclipse.jdt.core.search.SearchEngine.search

How can I get the method name which has annotation?

邮差的信 提交于 2019-12-12 14:13:30
问题 A class for example Exam has some methods which has annotation. @Override public void add() { int c=12; } How can I get the method name (add) which has @Override annotation using org.eclipse.jdt.core.IAnnotation ? 回答1: The IAnnotation is strongly misleading, please see the documentation. To retrieve the Methods from Class that have some annotation. To do that you have to iterate through all methods and yield only those that have such annotation. public static Collection<Method>

How to skip loops while debugging Java code?

邮差的信 提交于 2019-12-12 07:10:07
问题 This is not a duplicate of How to come out of while loop during debugging. See the comment on this answer https://stackoverflow.com/a/8107702/1391924 by the author of this question. While debugging, we can use short-cut keys like F8 to resume, F7 to step return, F5 to step into, F6 to step over. Is there any short-cut key to skip loops (for,while and do-while) while debugging Java code? In the picture shown below Currently debug cursor is at line no 57. Is there any short cut key when pressed

Eclipse AST not changing class files when changing TypeDeclaration

家住魔仙堡 提交于 2019-12-12 04:34:53
问题 I am trying to edit several Java classes with the Java AST. But my changes wont show in the Java class files. What specifically do I want to do? I want to take an IPackageFragment and visit all the ICompilationUnit s. For every declared class I want to set the super class to a specific class (using the qualified name of the super class, because it is an Xtend class). I also tried applying the edits via the Document class. For example: A class main.model.someClass should inherit from wrappers