Bug 15657 - IDOMMethod.getReturnType returns null for all methods
Summary: IDOMMethod.getReturnType returns null for all methods
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 2.0   Edit
Hardware: PC Windows 2000
: P2 normal (vote)
Target Milestone: 2.0 M6   Edit
Assignee: Olivier Thomann CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2002-05-09 14:09 EDT by Naveen Sachdeva CLA
Modified: 2002-06-04 14:27 EDT (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Naveen Sachdeva CLA 2002-05-09 14:09:11 EDT
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
Comment 1 Olivier Thomann CLA 2002-05-13 16:26:18 EDT
I reproduced the problem. I am working on it.
Comment 2 Olivier Thomann CLA 2002-05-13 16:57:08 EDT
Fixed and released in HEAD.
Comment 3 Olivier Thomann CLA 2002-05-13 16:57:19 EDT
Fixed.
Comment 4 Naveen Sachdeva CLA 2002-06-04 14:27:09 EDT
I retested my test case with F2 build and now it works fine.

Thanks for fixing the bug.

Naveen