1 11 package org.eclipse.jdt.internal.ui.viewsupport; 12 13 import org.eclipse.core.resources.IResource; 14 import org.eclipse.core.runtime.IAdaptable; 15 import org.eclipse.core.runtime.IPath; 16 17 import org.eclipse.jface.preference.IPreferenceStore; 18 19 import org.eclipse.ui.model.IWorkbenchAdapter; 20 21 import org.eclipse.jdt.core.*; 22 import org.eclipse.jdt.core.IClassFile; 23 import org.eclipse.jdt.core.IClasspathEntry; 24 import org.eclipse.jdt.core.ICompilationUnit; 25 import org.eclipse.jdt.core.IField; 26 import org.eclipse.jdt.core.IInitializer; 27 import org.eclipse.jdt.core.IJavaElement; 28 import org.eclipse.jdt.core.ILocalVariable; 29 import org.eclipse.jdt.core.IMethod; 30 import org.eclipse.jdt.core.IPackageFragment; 31 import org.eclipse.jdt.core.IPackageFragmentRoot; 32 import org.eclipse.jdt.core.IType; 33 import org.eclipse.jdt.core.JavaModelException; 34 import org.eclipse.jdt.core.Signature; 35 36 import org.eclipse.jdt.ui.PreferenceConstants; 37 38 import org.eclipse.jdt.internal.corext.util.JavaModelUtil; 39 40 import org.eclipse.jdt.internal.ui.JavaPlugin; 41 import org.eclipse.jdt.internal.ui.JavaUIMessages; 42 43 public class JavaElementLabels { 44 45 49 public final static int M_PARAMETER_TYPES= 1 << 0; 50 51 55 public final static int M_PARAMETER_NAMES= 1 << 1; 56 57 61 public final static int M_EXCEPTIONS= 1 << 2; 62 63 67 public final static int M_APP_RETURNTYPE= 1 << 3; 68 69 73 public final static int M_PRE_RETURNTYPE= 1 << 4; 74 75 79 public final static int M_FULLY_QUALIFIED= 1 << 5; 80 81 85 public final static int M_POST_QUALIFIED= 1 << 6; 86 87 91 public final static int I_FULLY_QUALIFIED= 1 << 7; 92 93 97 public final static int I_POST_QUALIFIED= 1 << 8; 98 99 103 public final static int F_APP_TYPE_SIGNATURE= 1 << 9; 104 105 109 public final static int F_PRE_TYPE_SIGNATURE= 1 << 10; 110 111 115 public final static int F_FULLY_QUALIFIED= 1 << 11; 116 117 121 public final static int F_POST_QUALIFIED= 1 << 12; 122 123 127 public final static int T_FULLY_QUALIFIED= 1 << 13; 128 129 133 public final static int T_CONTAINER_QUALIFIED= 1 << 14; 134 135 139 public final static int T_POST_QUALIFIED= 1 << 15; 140 141 145 public final static int D_QUALIFIED= 1 << 16; 146 147 151 public final static int D_POST_QUALIFIED= 1 << 17; 152 153 157 public final static int CF_QUALIFIED= 1 << 18; 158 159 163 public final static int CF_POST_QUALIFIED= 1 << 19; 164 165 169 public final static int CU_QUALIFIED= 1 << 20; 170 171 175 public final static int CU_POST_QUALIFIED= 1 << 21; 176 177 181 public final static int P_QUALIFIED= 1 << 22; 182 183 187 public final static int P_POST_QUALIFIED= 1 << 23; 188 189 193 public final static int ROOT_VARIABLE= 1 << 24; 194 195 199 public final static int ROOT_QUALIFIED= 1 << 25; 200 201 205 public final static int ROOT_POST_QUALIFIED= 1 << 26; 206 207 212 public final static int APPEND_ROOT_PATH= 1 << 27; 213 214 219 public final static int PREPEND_ROOT_PATH= 1 << 28; 220 221 225 public final static int P_COMPRESSED= 1 << 29; 226 227 232 public final static int REFERENCED_ROOT_POST_QUALIFIED= 1 << 30; 233 234 237 public final static int ALL_FULLY_QUALIFIED= F_FULLY_QUALIFIED | M_FULLY_QUALIFIED | I_FULLY_QUALIFIED | T_FULLY_QUALIFIED | D_QUALIFIED | CF_QUALIFIED | CU_QUALIFIED | P_QUALIFIED | ROOT_QUALIFIED; 238 239 242 public final static int ALL_POST_QUALIFIED= F_POST_QUALIFIED | M_POST_QUALIFIED | I_POST_QUALIFIED | T_POST_QUALIFIED | D_POST_QUALIFIED | CF_POST_QUALIFIED | CU_POST_QUALIFIED | P_POST_QUALIFIED | ROOT_POST_QUALIFIED; 243 244 247 public final static int ALL_DEFAULT= M_PARAMETER_TYPES; 248 249 252 public final static int DEFAULT_QUALIFIED= F_FULLY_QUALIFIED | M_FULLY_QUALIFIED | I_FULLY_QUALIFIED | T_FULLY_QUALIFIED | D_QUALIFIED | CF_QUALIFIED | CU_QUALIFIED; 253 254 257 public final static int DEFAULT_POST_QUALIFIED= F_POST_QUALIFIED | M_POST_QUALIFIED | I_POST_QUALIFIED | T_POST_QUALIFIED | D_POST_QUALIFIED | CF_POST_QUALIFIED | CU_POST_QUALIFIED; 258 259 262 public final static String CONCAT_STRING= JavaUIMessages.getString("JavaElementLabels.concat_string"); 266 public final static String COMMA_STRING= JavaUIMessages.getString("JavaElementLabels.comma_string"); 270 public final static String DECL_STRING= JavaUIMessages.getString("JavaElementLabels.declseparator_string"); 274 public final static String DEFAULT_PACKAGE= JavaUIMessages.getString("JavaElementLabels.default_package"); 276 279 private static String fgPkgNamePattern= ""; private static String fgPkgNamePrefix; 281 private static String fgPkgNamePostfix; 282 private static int fgPkgNameChars; 283 private static int fgPkgNameLength= -1; 284 285 private JavaElementLabels() { 286 } 287 288 private static boolean getFlag(int flags, int flag) { 289 return (flags & flag) != 0; 290 } 291 292 public static String getTextLabel(Object obj, int flags) { 293 if (obj instanceof IJavaElement) { 294 return getElementLabel((IJavaElement) obj, flags); 295 } else if (obj instanceof IAdaptable) { 296 IWorkbenchAdapter wbadapter= (IWorkbenchAdapter) ((IAdaptable)obj).getAdapter(IWorkbenchAdapter.class); 297 if (wbadapter != null) { 298 return wbadapter.getLabel(obj); 299 } 300 } 301 return ""; } 303 304 307 public static String getElementLabel(IJavaElement element, int flags) { 308 StringBuffer buf= new StringBuffer (60); 309 getElementLabel(element, flags, buf); 310 return buf.toString(); 311 } 312 313 316 public static void getElementLabel(IJavaElement element, int flags, StringBuffer buf) { 317 int type= element.getElementType(); 318 IPackageFragmentRoot root= null; 319 320 if (type != IJavaElement.JAVA_MODEL && type != IJavaElement.JAVA_PROJECT && type != IJavaElement.PACKAGE_FRAGMENT_ROOT) 321 root= JavaModelUtil.getPackageFragmentRoot(element); 322 if (root != null && getFlag(flags, PREPEND_ROOT_PATH)) { 323 getPackageFragmentRootLabel(root, ROOT_QUALIFIED, buf); 324 buf.append(CONCAT_STRING); 325 } 326 327 switch (type) { 328 case IJavaElement.METHOD: 329 getMethodLabel((IMethod) element, flags, buf); 330 break; 331 case IJavaElement.FIELD: 332 getFieldLabel((IField) element, flags, buf); 333 break; 334 case IJavaElement.LOCAL_VARIABLE: 335 getLocalVariableLabel((ILocalVariable) element, flags, buf); 336 break; 337 case IJavaElement.INITIALIZER: 338 getInitializerLabel((IInitializer) element, flags, buf); 339 break; 340 case IJavaElement.TYPE: 341 getTypeLabel((IType) element, flags, buf); 342 break; 343 case IJavaElement.CLASS_FILE: 344 getClassFileLabel((IClassFile) element, flags, buf); 345 break; 346 case IJavaElement.COMPILATION_UNIT: 347 getCompilationUnitLabel((ICompilationUnit) element, flags, buf); 348 break; 349 case IJavaElement.PACKAGE_FRAGMENT: 350 getPackageFragmentLabel((IPackageFragment) element, flags, buf); 351 break; 352 case IJavaElement.PACKAGE_FRAGMENT_ROOT: 353 getPackageFragmentRootLabel((IPackageFragmentRoot) element, flags, buf); 354 break; 355 case IJavaElement.IMPORT_CONTAINER: 356 case IJavaElement.IMPORT_DECLARATION: 357 case IJavaElement.PACKAGE_DECLARATION: 358 getDeclararionLabel(element, flags, buf); 359 break; 360 case IJavaElement.JAVA_PROJECT: 361 case IJavaElement.JAVA_MODEL: 362 buf.append(element.getElementName()); 363 break; 364 default: 365 buf.append(element.getElementName()); 366 } 367 368 if (root != null && getFlag(flags, APPEND_ROOT_PATH)) { 369 buf.append(CONCAT_STRING); 370 getPackageFragmentRootLabel(root, ROOT_QUALIFIED, buf); 371 } 372 } 373 374 377 public static void getMethodLabel(IMethod method, int flags, StringBuffer buf) { 378 try { 379 if (getFlag(flags, M_PRE_RETURNTYPE) && method.exists() && !method.isConstructor()) { 381 buf.append(Signature.getSimpleName(Signature.toString(method.getReturnType()))); 382 buf.append(' '); 383 } 384 385 if (getFlag(flags, M_FULLY_QUALIFIED)) { 387 getTypeLabel(method.getDeclaringType(), T_FULLY_QUALIFIED | (flags & P_COMPRESSED), buf); 388 buf.append('.'); 389 } 390 391 buf.append(method.getElementName()); 392 393 buf.append('('); 395 if (getFlag(flags, M_PARAMETER_TYPES | M_PARAMETER_NAMES)) { 396 397 398 String [] types= getFlag(flags, M_PARAMETER_TYPES) ? method.getParameterTypes() : null; 399 String [] names= (getFlag(flags, M_PARAMETER_NAMES) && method.exists()) ? method.getParameterNames() : null; 400 int nParams= types != null ? types.length : names.length; 401 402 for (int i= 0; i < nParams; i++) { 403 if (i > 0) { 404 buf.append(COMMA_STRING); } 406 if (types != null) { 407 buf.append(Signature.getSimpleName(Signature.toString(types[i]))); 408 } 409 if (names != null) { 410 if (types != null) { 411 buf.append(' '); 412 } 413 buf.append(names[i]); 414 } 415 } 416 } else { 417 if (method.getParameterTypes().length > 0) { 418 buf.append(".."); } 420 } 421 buf.append(')'); 422 423 if (getFlag(flags, M_EXCEPTIONS) && method.exists()) { 424 String [] types= method.getExceptionTypes(); 425 if (types.length > 0) { 426 buf.append(" throws "); for (int i= 0; i < types.length; i++) { 428 if (i > 0) { 429 buf.append(COMMA_STRING); 430 } 431 buf.append(Signature.getSimpleName(Signature.toString(types[i]))); 432 } 433 } 434 } 435 436 if (getFlag(flags, M_APP_RETURNTYPE) && method.exists() && !method.isConstructor()) { 437 buf.append(DECL_STRING); 438 buf.append(Signature.getSimpleName(Signature.toString(method.getReturnType()))); 439 } 440 441 if (getFlag(flags, M_POST_QUALIFIED)) { 443 buf.append(CONCAT_STRING); 444 getTypeLabel(method.getDeclaringType(), T_FULLY_QUALIFIED | (flags & P_COMPRESSED), buf); 445 } 446 447 } catch (JavaModelException e) { 448 JavaPlugin.log(e); } 450 } 451 452 455 public static void getFieldLabel(IField field, int flags, StringBuffer buf) { 456 try { 457 if (getFlag(flags, F_PRE_TYPE_SIGNATURE) && field.exists()) { 458 buf.append(Signature.toString(field.getTypeSignature())); 459 buf.append(' '); 460 } 461 462 if (getFlag(flags, F_FULLY_QUALIFIED)) { 464 getTypeLabel(field.getDeclaringType(), T_FULLY_QUALIFIED | (flags & P_COMPRESSED), buf); 465 buf.append('.'); 466 } 467 buf.append(field.getElementName()); 468 469 if (getFlag(flags, F_APP_TYPE_SIGNATURE) && field.exists()) { 470 buf.append(DECL_STRING); 471 buf.append(Signature.toString(field.getTypeSignature())); 472 } 473 474 if (getFlag(flags, F_POST_QUALIFIED)) { 476 buf.append(CONCAT_STRING); 477 getTypeLabel(field.getDeclaringType(), T_FULLY_QUALIFIED | (flags & P_COMPRESSED), buf); 478 } 479 480 } catch (JavaModelException e) { 481 JavaPlugin.log(e); } 483 } 484 485 490 public static void getLocalVariableLabel(ILocalVariable localVariable, int flags, StringBuffer buf) { 491 buf.append(Signature.toString(localVariable.getTypeSignature())); 492 buf.append(' '); 493 buf.append(localVariable.getElementName()); 494 495 buf.append(CONCAT_STRING); 496 getElementLabel(localVariable.getParent(), M_PARAMETER_TYPES | M_FULLY_QUALIFIED | T_FULLY_QUALIFIED | (flags & P_COMPRESSED), buf); 497 498 } 499 500 503 public static void getInitializerLabel(IInitializer initializer, int flags, StringBuffer buf) { 504 if (getFlag(flags, I_FULLY_QUALIFIED)) { 506 getTypeLabel(initializer.getDeclaringType(), T_FULLY_QUALIFIED | (flags & P_COMPRESSED), buf); 507 buf.append('.'); 508 } 509 buf.append(JavaUIMessages.getString("JavaElementLabels.initializer")); 511 if (getFlag(flags, I_POST_QUALIFIED)) { 513 buf.append(CONCAT_STRING); 514 getTypeLabel(initializer.getDeclaringType(), T_FULLY_QUALIFIED | (flags & P_COMPRESSED), buf); 515 } 516 } 517 518 521 public static void getTypeLabel(IType type, int flags, StringBuffer buf) { 522 if (getFlag(flags, T_FULLY_QUALIFIED)) { 523 IPackageFragment pack= type.getPackageFragment(); 524 if (!pack.isDefaultPackage()) { 525 getPackageFragmentLabel(pack, (flags & P_COMPRESSED), buf); 526 buf.append('.'); 527 } 528 } 529 if (getFlag(flags, T_FULLY_QUALIFIED | T_CONTAINER_QUALIFIED)) { 530 IType declaringType= type.getDeclaringType(); 531 if (declaringType != null) { 532 getTypeLabel(declaringType, T_CONTAINER_QUALIFIED, buf); 533 buf.append('.'); 534 } 535 int parentType= type.getParent().getElementType(); 536 if (parentType == IJavaElement.METHOD || parentType == IJavaElement.FIELD || parentType == IJavaElement.INITIALIZER) { getElementLabel(type.getParent(), 0, buf); 538 buf.append('.'); 539 } 540 } 541 542 String typeName= type.getElementName(); 543 if (typeName.length() == 0) { try { 545 String superclassName= Signature.getSimpleName(type.getSuperclassName()); 546 typeName= JavaUIMessages.getFormattedString("JavaElementLabels.anonym_type" , superclassName); } catch (JavaModelException e) { 548 typeName= JavaUIMessages.getString("JavaElementLabels.anonym"); } 551 } 552 buf.append(typeName); 553 554 if (getFlag(flags, T_POST_QUALIFIED)) { 556 buf.append(CONCAT_STRING); 557 IType declaringType= type.getDeclaringType(); 558 if (declaringType != null) { 559 getTypeLabel(declaringType, T_FULLY_QUALIFIED | (flags & P_COMPRESSED), buf); 560 int parentType= type.getParent().getElementType(); 561 if (parentType == IJavaElement.METHOD || parentType == IJavaElement.FIELD || parentType == IJavaElement.INITIALIZER) { buf.append('.'); 563 getElementLabel(type.getParent(), 0, buf); 564 } 565 } else { 566 getPackageFragmentLabel(type.getPackageFragment(), (flags & P_COMPRESSED), buf); 567 } 568 } 569 } 570 571 574 public static void getDeclararionLabel(IJavaElement declaration, int flags, StringBuffer buf) { 575 if (getFlag(flags, D_QUALIFIED)) { 576 IJavaElement openable= (IJavaElement) declaration.getOpenable(); 577 if (openable != null) { 578 buf.append(getElementLabel(openable, CF_QUALIFIED | CU_QUALIFIED)); 579 buf.append('/'); 580 } 581 } 582 if (declaration.getElementType() == IJavaElement.IMPORT_CONTAINER) { 583 buf.append(JavaUIMessages.getString("JavaElementLabels.import_container")); } else { 585 buf.append(declaration.getElementName()); 586 } 587 if (getFlag(flags, D_POST_QUALIFIED)) { 589 IJavaElement openable= (IJavaElement) declaration.getOpenable(); 590 if (openable != null) { 591 buf.append(CONCAT_STRING); 592 buf.append(getElementLabel(openable, CF_QUALIFIED | CU_QUALIFIED)); 593 } 594 } 595 } 596 597 600 public static void getClassFileLabel(IClassFile classFile, int flags, StringBuffer buf) { 601 if (getFlag(flags, CF_QUALIFIED)) { 602 IPackageFragment pack= (IPackageFragment) classFile.getParent(); 603 if (!pack.isDefaultPackage()) { 604 buf.append(pack.getElementName()); 605 buf.append('.'); 606 } 607 } 608 buf.append(classFile.getElementName()); 609 610 if (getFlag(flags, CF_POST_QUALIFIED)) { 611 buf.append(CONCAT_STRING); 612 getPackageFragmentLabel((IPackageFragment) classFile.getParent(), 0, buf); 613 } 614 } 615 616 619 public static void getCompilationUnitLabel(ICompilationUnit cu, int flags, StringBuffer buf) { 620 if (getFlag(flags, CU_QUALIFIED)) { 621 IPackageFragment pack= (IPackageFragment) cu.getParent(); 622 if (!pack.isDefaultPackage()) { 623 buf.append(pack.getElementName()); 624 buf.append('.'); 625 } 626 } 627 buf.append(cu.getElementName()); 628 629 if (getFlag(flags, CU_POST_QUALIFIED)) { 630 buf.append(CONCAT_STRING); 631 getPackageFragmentLabel((IPackageFragment) cu.getParent(), 0, buf); 632 } 633 } 634 635 638 public static void getPackageFragmentLabel(IPackageFragment pack, int flags, StringBuffer buf) { 639 if (getFlag(flags, P_QUALIFIED)) { 640 getPackageFragmentRootLabel((IPackageFragmentRoot) pack.getParent(), ROOT_QUALIFIED, buf); 641 buf.append('/'); 642 } 643 refreshPackageNamePattern(); 644 if (pack.isDefaultPackage()) { 645 buf.append(DEFAULT_PACKAGE); 646 } else if (getFlag(flags, P_COMPRESSED) && fgPkgNameLength >= 0) { 647 String name= pack.getElementName(); 648 int start= 0; 649 int dot= name.indexOf('.', start); 650 while (dot > 0) { 651 if (dot - start > fgPkgNameLength-1) { 652 buf.append(fgPkgNamePrefix); 653 if (fgPkgNameChars > 0) 654 buf.append(name.substring(start, Math.min(start+ fgPkgNameChars, dot))); 655 buf.append(fgPkgNamePostfix); 656 } else 657 buf.append(name.substring(start, dot + 1)); 658 start= dot + 1; 659 dot= name.indexOf('.', start); 660 } 661 buf.append(name.substring(start)); 662 } else { 663 buf.append(pack.getElementName()); 664 } 665 if (getFlag(flags, P_POST_QUALIFIED)) { 666 buf.append(CONCAT_STRING); 667 getPackageFragmentRootLabel((IPackageFragmentRoot) pack.getParent(), ROOT_QUALIFIED, buf); 668 } 669 } 670 671 674 public static void getPackageFragmentRootLabel(IPackageFragmentRoot root, int flags, StringBuffer buf) { 675 if (root.isArchive()) 676 getArchiveLabel(root, flags, buf); 677 else 678 getFolderLabel(root, flags, buf); 679 } 680 681 private static void getArchiveLabel(IPackageFragmentRoot root, int flags, StringBuffer buf) { 682 if (getFlag(flags, ROOT_VARIABLE) && getVariableLabel(root, flags, buf)) 684 return; 685 boolean external= root.isExternal(); 686 if (external) 687 getExternalArchiveLabel(root, flags, buf); 688 else 689 getInternalArchiveLabel(root, flags, buf); 690 } 691 692 private static boolean getVariableLabel(IPackageFragmentRoot root, int flags, StringBuffer buf) { 693 try { 694 IClasspathEntry rawEntry= root.getRawClasspathEntry(); 695 if (rawEntry != null) { 696 if (rawEntry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) { 697 buf.append(rawEntry.getPath().makeRelative()); 698 buf.append(CONCAT_STRING); 699 if (root.isExternal()) 700 buf.append(root.getPath().toOSString()); 701 else 702 buf.append(root.getPath().makeRelative().toString()); 703 return true; 704 } 705 } 706 } catch (JavaModelException e) { 707 JavaPlugin.log(e); } 709 return false; 710 } 711 712 private static void getExternalArchiveLabel(IPackageFragmentRoot root, int flags, StringBuffer buf) { 713 IPath path= root.getPath(); 714 if (getFlag(flags, REFERENCED_ROOT_POST_QUALIFIED)) { 715 int segements= path.segmentCount(); 716 if (segements > 0) { 717 buf.append(path.segment(segements - 1)); 718 if (segements > 1 || path.getDevice() != null) { 719 buf.append(CONCAT_STRING); 720 buf.append(path.removeLastSegments(1).toOSString()); 721 } 722 } else { 723 buf.append(path.toOSString()); 724 } 725 } else { 726 buf.append(path.toOSString()); 727 } 728 } 729 730 private static void getInternalArchiveLabel(IPackageFragmentRoot root, int flags, StringBuffer buf) { 731 IResource resource= root.getResource(); 732 boolean rootQualified= getFlag(flags, ROOT_QUALIFIED); 733 boolean referencedQualified= getFlag(flags, REFERENCED_ROOT_POST_QUALIFIED) && JavaModelUtil.isReferenced(root) && resource != null; 734 if (rootQualified) { 735 buf.append(root.getPath().makeRelative().toString()); 736 } else { 737 buf.append(root.getElementName()); 738 if (referencedQualified) { 739 buf.append(CONCAT_STRING); 740 buf.append(resource.getParent().getFullPath().makeRelative().toString()); 741 } else if (getFlag(flags, ROOT_POST_QUALIFIED)) { 742 buf.append(CONCAT_STRING); 743 buf.append(root.getParent().getPath().makeRelative().toString()); 744 } 745 } 746 } 747 748 private static void getFolderLabel(IPackageFragmentRoot root, int flags, StringBuffer buf) { 749 IResource resource= root.getResource(); 750 boolean rootQualified= getFlag(flags, ROOT_QUALIFIED); 751 boolean referencedQualified= getFlag(flags, REFERENCED_ROOT_POST_QUALIFIED) && JavaModelUtil.isReferenced(root) && resource != null; 752 if (rootQualified) { 753 buf.append(root.getPath().makeRelative().toString()); 754 } else { 755 if (resource != null) 756 buf.append(resource.getProjectRelativePath().toString()); 757 else 758 buf.append(root.getElementName()); 759 if (referencedQualified) { 760 buf.append(CONCAT_STRING); 761 buf.append(resource.getProject().getName()); 762 } else if (getFlag(flags, ROOT_POST_QUALIFIED)) { 763 buf.append(CONCAT_STRING); 764 buf.append(root.getParent().getElementName()); 765 } 766 } 767 } 768 769 private static void refreshPackageNamePattern() { 770 String pattern= getPkgNamePatternForPackagesView(); 771 if (pattern.equals(fgPkgNamePattern)) 772 return; 773 else if (pattern.equals("")) { fgPkgNamePattern= ""; fgPkgNameLength= -1; 776 return; 777 } 778 fgPkgNamePattern= pattern; 779 int i= 0; 780 fgPkgNameChars= 0; 781 fgPkgNamePrefix= ""; fgPkgNamePostfix= ""; while (i < pattern.length()) { 784 char ch= pattern.charAt(i); 785 if (Character.isDigit(ch)) { 786 fgPkgNameChars= ch-48; 787 if (i > 0) 788 fgPkgNamePrefix= pattern.substring(0, i); 789 if (i >= 0) 790 fgPkgNamePostfix= pattern.substring(i+1); 791 fgPkgNameLength= fgPkgNamePrefix.length() + fgPkgNameChars + fgPkgNamePostfix.length(); 792 return; 793 } 794 i++; 795 } 796 fgPkgNamePrefix= pattern; 797 fgPkgNameLength= pattern.length(); 798 } 799 800 private static String getPkgNamePatternForPackagesView() { 801 IPreferenceStore store= PreferenceConstants.getPreferenceStore(); 802 if (!store.getBoolean(PreferenceConstants.APPEARANCE_COMPRESS_PACKAGE_NAMES)) 803 return ""; return store.getString(PreferenceConstants.APPEARANCE_PKG_NAME_PATTERN_FOR_PKG_VIEW); 805 } 806 807 public static String getContainerEntryLabel(IPath containerPath, IJavaProject project) throws JavaModelException { 808 IClasspathContainer container= JavaCore.getClasspathContainer(containerPath, project); 809 if (container != null) { 810 return container.getDescription(); 811 } 812 ClasspathContainerInitializer initializer= JavaCore.getClasspathContainerInitializer(containerPath.segment(0)); 813 if (initializer != null) { 814 return initializer.getDescription(containerPath, project); 815 } 816 return containerPath.toString(); 817 } 818 819 } 820 | Popular Tags |