Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 361071 - AST Flattener - Missing space between annotation and package (with package-info)
Summary: AST Flattener - Missing space between annotation and package (with package-info)
Status: CLOSED WONTFIX
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 4.4   Edit
Hardware: PC Windows Vista
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Ayushman Jain CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2011-10-15 19:17 EDT by André Pankraz CLA
Modified: 2020-01-31 03:27 EST (History)
1 user (show)

See Also:


Attachments
Testcase (2.43 KB, application/octet-stream)
2011-10-17 03:37 EDT, André Pankraz CLA
no flags Details
Testcase 2 (better to see with parameter less annotation) (1.45 KB, application/octet-stream)
2011-10-17 03:40 EDT, André Pankraz CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description André Pankraz CLA 2011-10-15 19:17:47 EDT
Build Identifier: Build id: M20110909-1335

I build an AST with the API.
If I use PackageDeclaration.annotations().add... and CompilationUnit.rewrite() I get invalid source code because of the missing space.

In ASTRewriteFlattener.visit(PackageDeclaration node) is this line wrong:

			visitList(node, PackageDeclaration.ANNOTATIONS_PROPERTY, String.valueOf(' '));

correct:

	public boolean visit(PackageDeclaration node) {
		if (node.getAST().apiLevel() >= AST.JLS3) {
			ASTNode javadoc = getChildNode(node, PackageDeclaration.JAVADOC_PROPERTY);
			if (javadoc != null) {
				javadoc.accept(this);
			}
			visitList(node, PackageDeclaration.ANNOTATIONS_PROPERTY, String.valueOf(' '), Util.EMPTY_STRING, String.valueOf(' '));
		}
		this.result.append("package "); //$NON-NLS-1$
		getChildNode(node, PackageDeclaration.NAME_PROPERTY).accept(this);
		this.result.append(';');
		return false;
	}


Reproducible: Always

Steps to Reproduce:
1. Build AST with API via CU.recordModifications()
2. Add annotation to PackageDeclaration
3. CU.rewriteAST() to document -> result invalid
Comment 1 Ayushman Jain CLA 2011-10-17 01:36:59 EDT
Thanks for the code correction.

Can you please provide a test case that reproduces a problem? Thanks!
Comment 2 André Pankraz CLA 2011-10-17 03:37:42 EDT
Created attachment 205296 [details]
Testcase

there should be a space between annotation and package
Comment 3 André Pankraz CLA 2011-10-17 03:40:41 EDT
Created attachment 205297 [details]
Testcase 2 (better to see with parameter less annotation)
Comment 4 André Pankraz CLA 2013-12-28 14:31:56 EST
This bug is still present in the most recent version (jdk8 beta), now since 3.6?

Please at least try to fix this for the JDK 8 release...this fix is like 20 chars.
Comment 5 Eclipse Genie CLA 2020-01-31 03:27:08 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.