Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 435633

Summary: Viewpoint specification project activator location package
Product: [Modeling] Sirius Reporter: Boubekeur Zendagui <boubekeur.zendagui>
Component: CoreAssignee: Maxime Porhel <maxime.porhel>
Status: CLOSED FIXED QA Contact:
Severity: normal    
Priority: P3 CC: florian.barbin, maxime.porhel, pierre-charles.david, stephane.thibaudeau
Version: 1.0.0M7Keywords: triaged
Target Milestone: 1.0.1   
Hardware: PC   
OS: Windows XP   
Whiteboard: trivial flash
Bug Depends on:    
Bug Blocks: 441059    
Attachments:
Description Flags
project outline none

Description Boubekeur Zendagui CLA 2014-05-23 09:10:08 EDT
Created attachment 243441 [details]
project outline

When creating a new Viewpoint Specification Project, the plugin activator is created in a java package named "defaultpackage".

It may be interesting to name this package like the project.
Comment 1 Pierre-Charles David CLA 2014-05-23 09:29:19 EDT
The corresponding code is here: http://git.eclipse.org/c/sirius/org.eclipse.sirius.git/tree/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/project/ViewpointSpecificationProject.java?id=7128534330eee84895d474d4bea3a07f56e90364#n335

It should normally use "defaultpackage" only if the project name chosen is not a valid Java identifier (and thus can not be used as a package name for the activator). From your screenshot it looks like you used the default name, so this is surprising. Did you specify any non-default values in the wizard? Or maybe a trailing space (not visible on the screenshot) was added?
Comment 2 Boubekeur Zendagui CLA 2014-05-23 11:48:31 EDT
I didn't change any default data in the wizard. I have the same behaviour if i set project name to org.eclipse.test.sirius for example.

I put a breakpoint on the line 335 (http://git.eclipse.org/c/sirius/org.eclipse.sirius.git/tree/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/project/ViewpointSpecificationProject.java?id=7128534330eee84895d474d4bea3a07f56e90364#n335), the method SourceVersion.isIdentifier(...) consider : 
1- "org.eclipse.test.sirius" as NO Java identifier --> so it use defaultpackage.
2- "orgeclipsetestsirius" as a Java Identifier --> so the project name is used.

ps: in the second case, i only removed "." character from the name given in the first case

(In reply to Pierre-Charles David from comment #1)
> The corresponding code is here:
> http://git.eclipse.org/c/sirius/org.eclipse.sirius.git/tree/plugins/org.
> eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/project/
> ViewpointSpecificationProject.
> java?id=7128534330eee84895d474d4bea3a07f56e90364#n335
> 
> It should normally use "defaultpackage" only if the project name chosen is
> not a valid Java identifier (and thus can not be used as a package name for
> the activator). From your screenshot it looks like you used the default
> name, so this is surprising. Did you specify any non-default values in the
> wizard? Or maybe a trailing space (not visible on the screenshot) was added?
Comment 3 Maxime Porhel CLA 2014-06-05 06:00:18 EDT
See 
 . http://docs.oracle.com/javase/7/docs/api/javax/lang/model/SourceVersion.htm
 . http://docs.oracle.com/javase/7/docs/api/java/lang/Character.html#isJavaIdentifierStart(int)
 . http://docs.oracle.com/javase/7/docs/api/java/lang/Character.html#isJavaIdentifierPart(int)

(See also same uri vith /6/)

A project name containing any '.' will not ba a valid identifier. 

We are looking for a valid package name not a valid sigle identifier. 
We could split the project name if it contains "." and check each segment.
Comment 4 Stéphane Thibaudeau CLA 2014-07-10 09:59:47 EDT
I have done some tests, forcing the package name to be a string containing "." as the default "my.project.design". The remaining code executes as expected and the activator class is created in the right package.
There is even something like 

packageName.replaceAll("\\.", "/")

to be sure that "." are correctly handled.

So, we just have to fix the test so that "my.project.design" would be seen as a valid package name and the ticket will be fixed.
Comment 5 Stéphane Thibaudeau CLA 2014-07-10 12:11:53 EDT
The test with SourceVersion.isIdentifier(project.getName()) just seems to be plain wrong.

'my.project.design' is not a valid name according to this test but
'class' is a valid name and the wizard tries to create a 'class' package which is not valid.

I think that replacing isIdentifier() with isName() would do the trick. So far, I haven't seen any case where isName() would return a wrong result.
Comment 6 Maxime Porhel CLA 2014-07-31 03:47:56 EDT
The javadoc for SourceVersion.isName() confirm your thoughts: "Returns whether or not name is a syntactically valid qualified name in the latest source version. Unlike isIdentifier, this method returns false for keywords and literals."
Comment 7 Maxime Porhel CLA 2014-07-31 11:01:45 EDT
See https://git.eclipse.org/r/30809
Comment 8 Maxime Porhel CLA 2014-08-04 10:16:47 EDT
Corrected on 1.0.x branch by commit 6b91edae4aa0cad872d3f99270bec1bee3b34b7d
Comment 9 Pierre-Charles David CLA 2015-05-20 07:55:33 EDT
Available in Sirius 1.0.1.