假设我正在编辑一行......
obj.fooBar(x, y, z);
Run Code Online (Sandbox Code Playgroud)
我想将方法名称更改为fooSomethingElse,但保留大部分参数.如果我删除全部或部分名称,然后使用内容辅助,它会完成方法名称,但会启动一个新的arg列表...
obj.fooSomethingElse(arg1, arg2)(x, y, z)
^---- this arg is highlighted for editing
Run Code Online (Sandbox Code Playgroud)
我经常要删除"(arg1,arg2)".我可以在首选项中关闭"填充方法参数",然后我只需要删除"()",但它仍然很烦人.是否有另一个命令只能完成方法名称.理想情况下,它只是来自通用内容辅助的单独命令和键组合,因此我可以根据需要调用其中一个.
前段时间我写了一个Eclipse插件,它利用JDT进行一些解析.现在我正在考虑制作这个应用程序的命令行版本.当然,我希望重用解析代码,所以我需要让JDT在Eclipse之外工作.有什么方法可以实现这个(可能会构建一些包装器等)?是否有JDT库的任何端口提供相同的API /功能,但独立于Eclipse工作?
任何帮助将不胜感激.谢谢.
我目前尝试在eclipse中浏览JDT源代码:
这是行不通的.
在Eclipse中,如果我尝试将"Generate Delegate Methods"重构应用于Java类,如下所示:
class Foo implements Bar {
Bar bar;
}
Run Code Online (Sandbox Code Playgroud)
Eclipse不会@Override为生成的方法生成注释.这是一个错误还是有充分的理由呢?
我目前正在开发一个Eclipse插件,它可以帮助我编码.基本上是一个String片段库.
在创建一个新的时,我很乐意给它一个Class of Class Class.MethodName.X的ID.
获取编辑器非常简单:
IWorkbenchPage page = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage();
IEditorPart activeEditor = page.getActiveEditor();
if(activeEditor.getClass().getName().endsWith("CompilationUnitEditor")){
// do something
}
Run Code Online (Sandbox Code Playgroud)
现在......有没有办法使用Eclipse jdt API来获取我的文本光标当前所在方法的名称?
编辑:好的.在安德鲁的帮助下,这就是我得到的:
IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
IEditorPart activeEditor = page.getActiveEditor();
if(activeEditor instanceof JavaEditor) {
ICompilationUnit root = (ICompilationUnit) EditorUtility.getEditorInputJavaElement(activeEditor, false);
try {
ITextSelection sel = (ITextSelection) ((JavaEditor) activeEditor)
.getSelectionProvider().getSelection();
int offset = sel.getOffset();
IJavaElement element = root.getElementAt(offset);
if(element.getElementType() == IJavaElement.METHOD){
return element.getElementName());
}
} catch (JavaModelException e) {
e.printStackTrace();
}
}
Run Code Online (Sandbox Code Playgroud)
工作得很好.虽然使用受限制的类是一种肮脏的解决方案.
我想通过Git从源代码构建Eclipse JDT Core.天真地,我克隆git://git.eclipse.org/gitroot/jdt/eclipse.jdt.core.git并尝试mvn validate从Git master分支运行(Maven阶段中最基本的阶段),但这失败了,下面有错误.
我是安装了Maven 3.0.5和JDK 1.7的Debian Linux用户.
我有兴趣破解类ASTParser,它可以解析Java代码.我意识到构建Eclipse项目很难,但我无法在网络上的任何地方找到确定的"配方"页面来构建这个项目.
在我的Eclipse Juno安装中(更新到最新版本),这是我的JDT Core JAR文件:org.eclipse.jdt.core_3.8.3.v20130121-145325.jar.我试图建立这个标签(v20130121-145325),但我得到一个类似的错误.
从mvn validateGit分支登录master:
kca@cwb:~/saveme/git/eclipse.jdt.core$ mvn validate
[INFO] Scanning for projects...
[INFO] Computing target platform for MavenProject: org.eclipse.jdt:org.eclipse.jdt.annotation:1.1.0-SNAPSHOT @ /home/kca/saveme/git/eclipse.jdt.core/org.eclipse.jdt.annotation/pom.xml
[INFO] Adding repository http://download.eclipse.org/tools/orbit/downloads/drops/R20130517111416/repository
[INFO] Adding repository http://download.eclipse.org/tools/orbit/downloads/drops/R20130517111416/repository
[INFO] Adding repository http://download.eclipse.org/rt/ecf/int7/site.p2
[INFO] Adding repository http://download.eclipse.org/rt/ecf/int7/site.p2
[INFO] Adding repository http://download.eclipse.org/jetty/updates/jetty-bundles-8.x/8.1.10.v20130312
[INFO] Adding repository http://download.eclipse.org/jetty/updates/jetty-bundles-8.x/8.1.10.v20130312
[INFO] Adding repository http://download.eclipse.org/modeling/emf/emf/updates/2.9/base/R201305280742
[INFO] Adding repository http://download.eclipse.org/modeling/emf/emf/updates/2.9/base/R201305280742
[INFO] …Run Code Online (Sandbox Code Playgroud) Eclipse自动完成功能不起作用,并且总是只告诉我"No Default Proposals".
无论我是尝试在java.util下还是在我自己的项目中自动完成代码,都是如此.
我正在使用java-6-openjdk在Lucid Lynx上运行Eclipse 3.5.2.
有任何想法吗?
Eclipse可以使用"on-save"操作添加明确的类,但它不会解析静态函数.我并不总是使用自动完成功能,并且返回触发它是很麻烦的.
例如,我经常写代码
printDebug("my value", my_obj);
Run Code Online (Sandbox Code Playgroud)
我想让它自动添加
import static util.DebugOut.printDebug;
Run Code Online (Sandbox Code Playgroud)
注意:重申一下,我不是在寻找(a)需要的任何东西ctrl+space,(b)自动导入课程
我有一个里面有图表的课程.我迭代图形并创建一个构建图形的字符串,然后我将该字符串写入Java文件.有没有更好的方法,我读到JDT和CodeModel,但我真的需要一些如何使用它的提示.
编辑
我正在做一个正则表达式代码生成器,到目前为止,我已将正则表达式转换为有向图中表示的DFA(使用grail库).当我有DFA时,下一步是生成一个有三个方法的类,第一个构建相同的图形(DFA),第二个方法从一个节点移动到另一个节点,第三个方法匹配输入字符串是否被接受.只有第一种方法根据regularrexpression输入而改变,另外两种方法是静态的,并且对于每个生成的java类都是相同的.
我基于字符串的方法如下:
import grail.interfaces.DirectedEdgeInterface;
import grail.interfaces.DirectedGraphInterface;
import grail.interfaces.DirectedNodeInterface;
import grail.interfaces.EdgeInterface;
import grail.iterators.EdgeIterator;
import grail.iterators.NodeIterator;
import grail.properties.GraphProperties;
import grail.setbased.SetBasedDirectedGraph;
public class ClassName {
private SetBasedDirectedGraph graph = new SetBasedDirectedGraph();
private static DirectedNodeInterface state;
private static DirectedNodeInterface currentState;
protected DirectedEdgeInterface edge;
public ClassName() {
buildGraph();
}
protected void buildGraph() {
// Creating Graph Nodes (Automaton States)
state = graph.createNode(3);
state.setProperty(GraphProperties.LABEL, "3");
state.setProperty(GraphProperties.DESCRIPTION, "null");
graph.addNode(state);
state = graph.createNode(2);
state.setProperty(GraphProperties.LABEL, "2");
state.setProperty(GraphProperties.DESCRIPTION, "null");
graph.addNode(state);
state = graph.createNode(1);
state.setProperty(GraphProperties.LABEL, "1");
state.setProperty(GraphProperties.DESCRIPTION, "Accepted");
graph.addNode(state); …Run Code Online (Sandbox Code Playgroud) 我有一个test-foo.jar只有两个文件的简单库:
Foo用一种方法void doStuff()Bar使用单个方法的类void executeFoo(Foo foo),只需调用foo.doStuff()然后我有Eclipse Java项目,FooImpl它有一个实现的类Foo.该项目具有test-foo.jar构建路径条目.我没有附加此JAR的源代码.

现在让我说我对谁实际调用doStuff()方法有点好奇.所以我点击FooImpl#doStuff签名并按Ctrl+ Shift+ G(找到参考).我希望Bar#executeFoo在搜索结果中看到,但结果实际上是空的.

我有点困惑,因为我认为这在Eclipse中有效(现在已经使用Eclipse了几年).但它似乎只适用于附带源代码的图书馆(我之前没有注意到).
有没有办法在没有附加源的情况下在项目库中查找类型(或方法)的引用(或用法)?为什么Eclipse没有索引并显示.class文件中的引用?
附加信息:
.class..class文件.