Bug 399812 - Review issue with having dot (.) in package path
Summary: Review issue with having dot (.) in package path
Status: NEW
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: VJET (show other bugs)
Version: unspecified   Edit
Hardware: Macintosh Mac OS X
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Justin Early CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-02-03 11:06 EST by Justin Early CLA
Modified: 2017-04-11 15:12 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 Justin Early CLA 2013-02-03 11:06:58 EST
originally posted here - https://www.ebayopensource.org/jira/browse/VJET-99

In message https://www.ebayopensource.org/forum/index.php?t=msg&th=184&goto=857&S=a8ce91360fe8d6951df18e1b7a78d1b3#msg_857 huntc reports that file path segments which contain a period (dot) cause an erroneous problem report to be shown in the ide with the message: file path contains unsupported character (dot). 

This is because the function CodeassistUtils.getClassName() builds a class name from the structure of the path. However it assumes the characters after a dot in any segment of the path are the extension of the source file so dumps them all not in just the last one (where the file name will be). 

To protect this flawed routine the path is checked in vjoSourceParser.ModuleDeclaration before getClassName() is called and a problem report created if folder segments of the path contain dots. 

The code below is my suggested alternative implementation of the CodeassistUtils.getClassName() function. After implementation of something like it the guard check in vjoSourceParser.ModuleDeclaration can be removed. 

This implementation only seeks to remove characters after the period (dot) in the last of the segments. The majority of this function is unchanged. The code changed is within the second 'for' loop. 


/** 
* Return class name if the path object contains source folders information. 
* 
* @param sourceFolders 
* list of the {@link IPath} source filders object. 
* @param path 
* path of the resource 
* @return class name. 
*/ 
private static String getClassName(List<IPath> sourceFolders, IPath path) { 

StringBuffer buffer = new StringBuffer(); 

// remove source folder segment 
for (IPath path2 : sourceFolders) { 
if (path2.toString().length() > 0 && path2.isPrefixOf(path)) { 
path = path.removeFirstSegments(path2.segmentCount()); 
break; 
} 
} 

String[] segmStrings = path.segments(); 

for (int i = 0; i < segmStrings.length; i++) { 

if (i > 0) 
buffer.append(DOT); 

String name = segmStrings[i]; 

if (i + 1 == segmStrings.length) { 
// Remove chars after period 
int dotIndex = name.lastIndexOf(DOT); 
if (dotIndex != -1) { 
name = name.substring(0, dotIndex); 
} 
} 

buffer.append(name); 

} 


return buffer.toString(); 
}
Comment 1 Justin Early CLA 2013-02-03 11:19:48 EST
Dot in directory name also causes builder errors such as:

java.lang.NullPointerException
	at org.eclipse.vjet.dsf.jstojava.controller.JstParseController.resolve(JstParseController.java:110)
	at org.eclipse.vjet.eclipse.core.builder.VjetScriptBuilder.buildElements(VjetScriptBuilder.java:1086)
	at org.eclipse.vjet.eclipse.core.builder.VjetScriptBuilder.fullBuild(VjetScriptBuilder.java:706)
	at org.eclipse.vjet.eclipse.core.builder.VjetScriptBuilder.build(VjetScriptBuilder.java:407)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:728)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:199)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:239)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:292)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:295)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:351)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:374)
	at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:143)
	at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:241)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:53)