Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 2173 Details for
Bug 22208
requesting more options for 'compress package name segments' [package explorer] [browsing]
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
fixed problem in processSegment if segment name was longer than characters kept
PackageNameCompressor.java (text/plain), 9.16 KB, created by
Robert Varga
on 2002-10-11 16:19:08 EDT
(
hide
)
Description:
fixed problem in processSegment if segment name was longer than characters kept
Filename:
MIME Type:
Creator:
Robert Varga
Created:
2002-10-11 16:19:08 EDT
Size:
9.16 KB
patch
obsolete
>package org.eclipse.jdt.internal.ui.viewsupport; > >import java.util.StringTokenizer; >import java.util.Vector; > >/** > * @author robert.varga > */ > >public class PackageNameCompressor { > > > public static void processSegment(StringBuffer buf, String segment, PackageNameCompressionZone zone, > boolean endOfZone, boolean followingSegmentExists) { > > //System.out.println("Processing segment: "+segment); > if (zone==null) { > // not compress this segment > //System.out.print("No zone, not compressing. Output: "+segment); > buf.append(segment); > if (followingSegmentExists) { > buf.append('.'); > //System.out.print('.'); > } > //System.out.println(); > } else { > // compress this segment > //System.out.println("Zone: "+zone); > //System.out.print("Output: "); > if (zone.getKeepCharacters()>0) { > int num=zone.getKeepCharacters(); > if (segment.length()<num) num=segment.length(); > buf.append(segment.substring(0, num)); > //System.out.print(segment.substring(0, zone.getKeepCharacters())); > } > if (segment.length()>zone.getKeepCharacters()) { > if (zone.getReplaceCharacter()!=' ') { > buf.append(zone.getReplaceCharacter()); > //System.out.print(zone.getReplaceCharacter()); > } > } > if (followingSegmentExists) { > if (endOfZone) { > if (zone.isDisplayAfterDot() ) { > buf.append('.'); > //System.out.print('.'); > } > } else { > if (zone.isDisplayMiddleDots() ) { > buf.append('.'); > //System.out.print('.'); > } > } > } > //System.out.println(); > } > } > > public static String compressPackageName(String packageName, PackageNameCompressionZone[] zones) { > > if (zones==null || packageName==null) return packageName; > if (packageName.length()==0 || zones.length==0) return packageName; > > int zoneNum, segNum=0; > if ((zoneNum= packageName.length()-1)>-1) ++segNum; > for (; zoneNum>-1; --zoneNum) if (packageName.charAt(zoneNum)=='.') ++segNum; > zoneNum=zones.length; > > > int processible; > boolean lastNegative=false; > boolean next; > if ((processible=zones[zoneNum-1].getLength())<1) { > > if (segNum<=-processible) return packageName; > > lastNegative=true; > processible+=segNum; > > } else processible=segNum; > > //System.out.println("Zones: "+zoneNum+" LastNegative: "+lastNegative+" Segments: "+segNum+" Processible: "+processible); > > StringBuffer buf=new StringBuffer(packageName.length()); > int zone=0, segment=0, num=0; > StringTokenizer tok= new StringTokenizer(packageName, ".", false); > String actseg; > > > while ((zone<zoneNum) && (segment<processible)) { > //System.out.println("Inside loop: zone #"+zone+": "+zones[zone]+" , segment: "+segment); > > > if (lastNegative && zone==zoneNum-1) { > // last zone and it is negative: process all segments > // System.out.println("Last negative zone"); > while (segment<processible) { > actseg= tok.nextToken(); > ++segment; > processSegment(buf, actseg, zones[zone], segment==processible, segment<segNum); > } > break; > > } else { > //System.out.println("segment: "+segment+" zones[zone].length: "+zones[zone].getLength()+" processible: "+processible); > if ((segment+zones[zone].getLength() > processible)|| > ((segment+zones[zone].getLength()==processible) && !lastNegative)) { >// || (segment+zones[zone].getLength() == segNum)) {// that implies segment+zones[zone].getLength() == processible as well > > // no segments after zone > > if (! zones[zone].isProcessIfNoMore()) { > // should not process if no segments after zone > if (!lastNegative) break; // break away, nothing more should be done ; > > // last zone is negative, go to last zone > zone=zoneNum-1; > continue; > } > } > > // enough segments or forced to process an incomplete positive segment > num=0; > //System.out.println("processing item in loop"); > while (segment<processible && num<zones[zone].getLength()) { > actseg= tok.nextToken(); > ++segment; ++num; > processSegment(buf, actseg, zones[zone], > (segment==processible) || (num==zones[zone].getLength()), segment<segNum); > } > ++zone; > } > } > > // append remaining segments > //System.out.println("appending unprocessed items"); > while (segment<segNum) { > actseg= tok.nextToken(); > ++segment; > processSegment(buf, actseg, null, false, segment<segNum); > } > > return buf.toString(); > } > > public static PackageNameCompressionZone[] parseZones(String pattern) { > if (pattern==null) return null; > if ((pattern=pattern.trim()).length()==0) return null; > > Vector v=new Vector(); > StringTokenizer tok=new StringTokenizer(pattern, " ", false); > PackageNameCompressionZone zone; > String token; > try { > while (tok.hasMoreTokens()) { > token=tok.nextToken(); > int len=-1,keep=0; > boolean middle=false, after=false, process=false; > char replace=' ', dot='!'; > int ind, index; > if (-1==(index=token.lastIndexOf('/'))) if (-1<(index=token.lastIndexOf('\\'))) process=true; > if (index==0) throw new Exception("Zone definition is corrupt. Compression specifier must be present! Zone: "+token); > ind=-1; > if (ind==-1) if (-1<(ind=token.lastIndexOf('!'))) { > dot='!'; > middle=after=false; > } > if (ind==-1) if (-1<(ind=token.lastIndexOf('*'))) { > dot='*'; > middle=false; > after=true; > } > if (ind==-1) if (-1<(ind=token.lastIndexOf('.'))) { > dot='.'; > middle=after=true; > } > if (ind==-1) if (-1<(ind=token.lastIndexOf('|'))) { > dot='|'; > middle=true; > after=false; > } > if ((index==-1) && (ind>-1) && (ind<token.length()-1)) { > throw new Exception("Zone definition is corrupt. Dotchar must be the end of the zone, or it must be followed by a slash or backslash and optionally specifying the length of the zone! Zone: "+token); > } > > if (index>-1 && index<token.length()-1) len=Integer.parseInt(token.substring(index+1),10); > > if (ind>0) { > // there is place before the dotchar > replace= token.charAt(ind-1); > if ((replace<='9')&&(replace>='0')) replace=' '; > else --ind; > } else if (ind==-1) { > if (index==-1) { > replace=token.charAt(token.length()-1); > ind=token.length()-1; > } else { > replace=token.charAt(index-1); > ind=index-1; > } > if ((replace<='9')&&(replace>='0')) replace=' '; > } > > if (ind>0) keep=Integer.parseInt(token.substring(0,ind),10); > else if (ind==-1) { > if (index>-1) keep=Integer.parseInt(token.substring(0, index),10); > else keep=Integer.parseInt(token, 10); > } > > v.add(zone=new PackageNameCompressionZone()); > zone.setDisplayAfterDot(after); > zone.setDisplayMiddleDots(middle); > zone.setLength(len); > zone.setKeepCharacters(keep); > zone.setReplaceCharacter(replace); > zone.setProcessIfNoMore(process); > //System.out.println("New "+zone); > } > } catch (Exception e) { > } > > if (v.size()==0) return null; > > PackageNameCompressionZone[] ret=new PackageNameCompressionZone[v.size()]; > v.copyInto(ret); > return ret; > } > >}
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Raw
Actions:
View
Attachments on
bug 22208
:
2158
|
2159
|
2160
|
2163
| 2173