Bug 88200 - ASTParser is returning incorrect TypeDeclaration
Summary: ASTParser is returning incorrect TypeDeclaration
Status: RESOLVED WORKSFORME
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.1 M6   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-03-16 12:22 EST by Jeffrey Liu CLA
Modified: 2005-03-18 10:19 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jeffrey Liu CLA 2005-03-16 12:22:32 EST
Eclipse 3.1M5

I'm using the org.eclipse.jdt.core.dom.ASTParser to parse my source files, see 
code below:

ASTParser parser = ASTParser.newParser(AST.JLS2);
parser.setSource(...);
ASTNode node = parser.createAST(null);
MyJavadocVisitor visitor = new MyJavadocVisitor();
node.accept(visitor);

When I use the ASTParser to parse the following Java file, my visitor is 
telling me that there's a TypeDeclaration called "is" in the file. However, 
there isn't. I believe the problem is that inside the javadoc section for the 
interface, there's a line...

 * <p>This interface is not intended to be implemented by clients.</p>

ASTParser thought the word "interface" in this case is an interface 
declaration (instead of part of the javadoc). Therefore, the word following it 
("is") is the name of the interface.

/******************************************************************************
*
 * Copyright (c) 2003, 2005 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 * 
 * Contributors:
 *     IBM Corporation - Initial API and implementation
 
*******************************************************************************
/
package org.eclipse.wst.server.core;

import org.eclipse.core.resources.IProject;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.core.runtime.IProgressMonitor;
/**
 * A runtime target handler is used to apply some properties to a project
 * this is being targeted to a given runtime. For instance, the handler
 * might update the classpath of a Java project to include the runtime's
 * classes, add validation for the given runtime, or restrict the type of
 * resources that can be created.
 * 
 * <p>This interface is not intended to be implemented by clients.</p>
 * 
 * @since 1.0
 */
public interface IRuntimeTargetHandler extends IAdaptable {
	/**
	 * Returns the id of this runtime target handler.
	 * Each known runtime target handler has a distinct id. 
	 * Ids are intended to be used internally as keys; they are not
	 * intended to be shown to end users.
	 * 
	 * @return the runtime target handler id
	 */
	public String getId();

	/**
	 * Returns <code>true</code> if this runtime target handler supports
	 * (can work with) the given runtime.
	 * 
	 * @param runtimeType a runtime type
	 * @return <code>true</code> if the handler can accept the given 
runtime type,
	 *    and <code>false</code> otherwise
	 */
	public boolean supportsRuntimeType(IRuntimeType runtimeType);

	/**
	 * Set the runtime target on the given project.
	 * 
	 * @param project the project to set the runtime on
	 * @param runtime the target runtime
	 * @param monitor a progress monitor, or <code>null</code> if progress
	 *    reporting and cancellation are not desired
	 * @throws CoreException thrown if there is a problem setting the 
runtime
	 */
	public void setRuntimeTarget(IProject project, IRuntime runtime, 
IProgressMonitor monitor) throws CoreException;

	/**
	 * Remove the runtime target from the given project. This method will 
undo
	 * all changes made in setRuntimeTarget().
	 * 
	 * @param project the project to remove the runtime from
	 * @param runtime the target runtime
	 * @param monitor a progress monitor, or <code>null</code> if progress
	 *    reporting and cancellation are not desired
	 * @throws CoreException thrown if there is a problem removing the 
runtime
	 */
	public void removeRuntimeTarget(IProject project, IRuntime runtime, 
IProgressMonitor monitor) throws CoreException;
}
Comment 1 Frederic Fusier CLA 2005-03-16 12:36:22 EST
Can you make a try using ASTView 1.0.4 and let us know if the TypeDeclaration is
also incorrect in this view?
You can find this utility on following page:
http://dev.eclipse.org/viewcvs/index.cgi/%7Echeckout%7E/jdt-ui-home/main.html
Thx
Comment 3 Jeffrey Liu CLA 2005-03-16 12:43:53 EST
Type declaration seems to be correct using ASTView.
Comment 4 Frederic Fusier CLA 2005-03-16 12:47:58 EST
Perhaps a problem with your visitor?
Can you attach it to this bug?
Comment 5 Jeffrey Liu CLA 2005-03-16 13:16:12 EST
Here's my visitor (inner class):

  private class MyJavadocVisitor extends ASTVisitor
  {
    public MyJavadocVisitor(String pkg)
    {
    }

    public boolean visit(TypeDeclaration node)
    {
      String name = node.getName().getFullyQualifiedName();
      Javadoc javadoc = node.getJavadoc();
      if (javadoc != null)
        System.out.println(name + " has javadoc");
      else
        System.out.println("Warning! " + name + " does not have any 
javadoc!!!");
      return true;
    }

    public boolean visit(MethodDeclaration node)
    {
      return true;
    }
  }

The console output:

Warning! IOptionalTask does not have any javadoc!!!

For some reason, the blank line trick no longer work. But in any event, I 
removed all the field declaration and the javadocs for the field. Rerun my 
visistor, and here's the console output:

IOptionalTask has javadoc
Comment 6 Frederic Fusier CLA 2005-03-17 06:24:47 EST
IOptionalTask!!!???
I cannot se it in sample provided in comment 0...
Are you sure of your test case?

Cannot reproduce with your visitor *and* sample of comment 0. I get following
output:
IRuntimeTargetHandler has javadoc
Warning! IRuntime does not have any javadoc!!!
Warning! IRuntimeType does not have any javadoc!!!

Two last lines are due to the fact that I've added two lines to your sample to
avoid compiler errors:
interface IRuntime {}
interface IRuntimeType {}

Please verify your test case and reopen when sure of the error, thanks
Comment 7 Frederic Fusier CLA 2005-03-17 06:29:51 EST
Sorry, I realized that IOptionalTask comes from bug 88206...
Comment 8 Frederic Fusier CLA 2005-03-17 06:37:01 EST
However, I still cannot reproduce neither this bug nor bug 88206.
With IOptionalTask, I get:
IOptionalTask has javadoc
Warning! ITask does not have any javadoc!!!

(I've also added interface ITask {} at the end of your sample to avoid compiler
error)

Does your project is a plugin with dependency on org.eclipse.jdt.core?
Comment 9 Frederic Fusier CLA 2005-03-18 10:19:14 EST
Please reopen while provindg requested info and if you find a reproduceable test
case, thanks