Community
Participate
Working Groups
I have a simple test program which goes through a java file and returns the return type of methods in the java file. I always get the return type as null. The code is as follows - package org.eclipse.examples.helloworld; import java.lang.*; import java.io.*; import java.util.*; import org.eclipse.core.*; import org.eclipse.core.runtime.*; import org.eclipse.core.resources.*; import org.eclipse.jdt.core.*; import org.eclipse.jdt.core.jdom.*; public class Test { public Test() { try{ IPath javaPath = new Path ("Test/org/eclipse/examples/helloworld/Test.java"); IWorkspace workS = ResourcesPlugin.getWorkspace(); IWorkspaceRoot rootP = workS.getRoot(); System.err.println(rootP.getLocation().toString()); IProject testProject = rootP.getProject("Test"); // IJavaProject testProject = JavaCore.create(rootP.getProject ("Test")); // open if necessary if (testProject.exists()) { if(!testProject.isOpen()) { testProject.open(null); System.err.println("Project is opened"); } else System.err.println("Project is already open"); } else { System.err.println("Project does not exist"); return; } // ICompilationUnit compUnit = (ICompilationUnit) testProject.findElement(javaPath); IFile javaFile = rootP.getFile(javaPath); if (!javaFile.exists()) { System.err.println("File does not exist"); return; } ICompilationUnit compUnit = (ICompilationUnit) JavaCore.createCompilationUnitFrom(javaFile); IDOMCompilationUnit dcompUnit = new DOMFactory().createCompilationUnit (compUnit.getSource(), compUnit.getElementName()); if (dcompUnit == null) { System.err.println("dcompUnit is null"); return; } // searching class IDOMType classNode = null; Enumeration children = dcompUnit.getChildren(); if (children == null) { System.err.println("dcompUnit has no children"); return; } while (children.hasMoreElements()) { IDOMNode child = (IDOMNode) children.nextElement(); if (child.getNodeType() == IDOMNode.TYPE) { classNode = (IDOMType)child; System.err.println(classNode.getName()); break; } } if (classNode == null) { System.err.println("classNode is null"); return; } // searching for methods children = classNode.getChildren(); if (children == null) { System.err.println("classNode has no children"); return; } while (children.hasMoreElements()) { IDOMNode child = (IDOMNode) children.nextElement(); if (child.getNodeType() == IDOMNode.METHOD) { IDOMMethod childMethod = (IDOMMethod) child; System.err.println(childMethod.getName()); // returnType is always null; String returnType = childMethod.getReturnType(); if (returnType == null) { System.err.println("returnType is null"); } else System.err.println("returnType is : "+returnType); } } } catch (Exception e) { e.printStackTrace(System.err); } } public static void main(String[] args) { new Test(); } } I use the HelloWorldView to run this code. package org.eclipse.examples.helloworld; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.SWT; import org.eclipse.ui.part.ViewPart; public class HelloWorldView extends ViewPart { Label label; public HelloWorldView() { } public void createPartControl(Composite parent) { label = new Label(parent, SWT.WRAP); Test test = new Test(); label.setText("Hello World"); } public void setFocus() { // set focus to my widget. For a label, this doesn't // make much sense, but for more complex sets of widgets // you would decide which one gets the focus. } } In order to debug the plugin. I created a project Test and placed Test.java under org.eclipse.examples.helloworld package. Test.java looks as follows - package org.eclipse.examples.helloworld; public class Test { public int junk1(int i) { return 0; } public long junk2() { return 0; } } I see the following output in the console - C:/eclipse-sdk/eclipse/runtime-workspace Project is already open Test junk1 returnType is null junk2 returnType is null
I reproduced the problem. I am working on it.
Fixed and released in HEAD.
Fixed.
I retested my test case with F2 build and now it works fine. Thanks for fixing the bug. Naveen