Lines 504-509
Link Here
|
504 |
} |
504 |
} |
505 |
|
505 |
|
506 |
/** |
506 |
/** |
|
|
507 |
* Searches for all secondary types in the given scope. |
508 |
* The search can be selecting specific types (given a package or a type name |
509 |
* prefix and match modes). |
510 |
*/ |
511 |
public void searchAllSecondaryTypeNames( |
512 |
IPackageFragmentRoot[] sourceFolders, |
513 |
final IRestrictedAccessTypeRequestor nameRequestor, |
514 |
boolean waitForIndexes, |
515 |
IProgressMonitor progressMonitor) throws JavaModelException { |
516 |
|
517 |
if (VERBOSE) { |
518 |
Util.verbose("BasicSearchEngine.searchAllSecondaryTypeNames(IPackageFragmentRoot[], IRestrictedAccessTypeRequestor, boolean, IProgressMonitor)"); //$NON-NLS-1$ |
519 |
StringBuffer buffer = new StringBuffer(" - source folders: "); //$NON-NLS-1$ |
520 |
int length = sourceFolders.length; |
521 |
for (int i=0; i<length; i++) { |
522 |
if (i==0) { |
523 |
buffer.append('['); |
524 |
} else { |
525 |
buffer.append(','); |
526 |
} |
527 |
buffer.append(sourceFolders[i].getElementName()); |
528 |
} |
529 |
buffer.append("]\n - waitForIndexes: "); //$NON-NLS-1$ |
530 |
buffer.append(waitForIndexes); |
531 |
Util.verbose(buffer.toString()); |
532 |
} |
533 |
|
534 |
IndexManager indexManager = JavaModelManager.getJavaModelManager().getIndexManager(); |
535 |
final TypeDeclarationPattern pattern = new SecondaryTypeDeclarationPattern(); |
536 |
|
537 |
// Get working copy path(s). Store in a single string in case of only one to optimize comparison in requestor |
538 |
final HashSet workingCopyPaths = new HashSet(); |
539 |
String workingCopyPath = null; |
540 |
ICompilationUnit[] copies = getWorkingCopies(); |
541 |
final int copiesLength = copies == null ? 0 : copies.length; |
542 |
if (copies != null) { |
543 |
if (copiesLength == 1) { |
544 |
workingCopyPath = copies[0].getPath().toString(); |
545 |
} else { |
546 |
for (int i = 0; i < copiesLength; i++) { |
547 |
ICompilationUnit workingCopy = copies[i]; |
548 |
workingCopyPaths.add(workingCopy.getPath().toString()); |
549 |
} |
550 |
} |
551 |
} |
552 |
final String singleWkcpPath = workingCopyPath; |
553 |
|
554 |
// Index requestor |
555 |
IndexQueryRequestor searchRequestor = new IndexQueryRequestor(){ |
556 |
public boolean acceptIndexMatch(String documentPath, SearchPattern indexRecord, SearchParticipant participant, AccessRuleSet access) { |
557 |
// Filter unexpected types |
558 |
TypeDeclarationPattern record = (TypeDeclarationPattern)indexRecord; |
559 |
if (!record.secondary) { |
560 |
return true; // filter maint types |
561 |
} |
562 |
if (record.enclosingTypeNames == IIndexConstants.ONE_ZERO_CHAR) { |
563 |
return true; // filter out local and anonymous classes |
564 |
} |
565 |
switch (copiesLength) { |
566 |
case 0: |
567 |
break; |
568 |
case 1: |
569 |
if (singleWkcpPath.equals(documentPath)) { |
570 |
return true; // fliter out *the* working copy |
571 |
} |
572 |
break; |
573 |
default: |
574 |
if (workingCopyPaths.contains(documentPath)) { |
575 |
return true; // filter out working copies |
576 |
} |
577 |
break; |
578 |
} |
579 |
|
580 |
// Accept document path |
581 |
AccessRestriction accessRestriction = null; |
582 |
if (access != null) { |
583 |
// Compute document relative path |
584 |
int pkgLength = (record.pkg==null || record.pkg.length==0) ? 0 : record.pkg.length+1; |
585 |
int nameLength = record.simpleName==null ? 0 : record.simpleName.length; |
586 |
char[] path = new char[pkgLength+nameLength]; |
587 |
int pos = 0; |
588 |
if (pkgLength > 0) { |
589 |
System.arraycopy(record.pkg, 0, path, pos, pkgLength-1); |
590 |
CharOperation.replace(path, '.', '/'); |
591 |
path[pkgLength-1] = '/'; |
592 |
pos += pkgLength; |
593 |
} |
594 |
if (nameLength > 0) { |
595 |
System.arraycopy(record.simpleName, 0, path, pos, nameLength); |
596 |
pos += nameLength; |
597 |
} |
598 |
// Update access restriction if path is not empty |
599 |
if (pos > 0) { |
600 |
accessRestriction = access.getViolatedRestriction(path); |
601 |
} |
602 |
} |
603 |
nameRequestor.acceptType(record.modifiers, record.pkg, record.simpleName, record.enclosingTypeNames, documentPath, accessRestriction); |
604 |
return true; |
605 |
} |
606 |
}; |
607 |
|
608 |
// add type names from indexes |
609 |
if (progressMonitor != null) { |
610 |
progressMonitor.beginTask(Messages.engine_searching, 100); |
611 |
} |
612 |
try { |
613 |
indexManager.performConcurrentJob( |
614 |
new PatternSearchJob( |
615 |
pattern, |
616 |
getDefaultSearchParticipant(), // Java search only |
617 |
createJavaSearchScope(sourceFolders), |
618 |
searchRequestor), |
619 |
waitForIndexes |
620 |
? IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH |
621 |
: IJavaSearchConstants.FORCE_IMMEDIATE_SEARCH, |
622 |
progressMonitor == null ? null : new SubProgressMonitor(progressMonitor, 100)); |
623 |
} |
624 |
catch (OperationCanceledException oce) { |
625 |
// do nothing |
626 |
} |
627 |
} |
628 |
|
629 |
/** |
507 |
* Searches for all top-level types and member types in the given scope. |
630 |
* Searches for all top-level types and member types in the given scope. |
508 |
* The search can be selecting specific types (given a package or a type name |
631 |
* The search can be selecting specific types (given a package or a type name |
509 |
* prefix and match modes). |
632 |
* prefix and match modes). |
Lines 513-520
Link Here
|
513 |
*/ |
636 |
*/ |
514 |
public void searchAllTypeNames( |
637 |
public void searchAllTypeNames( |
515 |
final char[] packageName, |
638 |
final char[] packageName, |
|
|
639 |
final int packageMatchRule, |
516 |
final char[] typeName, |
640 |
final char[] typeName, |
517 |
final int matchRule, |
641 |
final int typeMatchRule, |
518 |
int searchFor, |
642 |
int searchFor, |
519 |
IJavaSearchScope scope, |
643 |
IJavaSearchScope scope, |
520 |
final IRestrictedAccessTypeRequestor nameRequestor, |
644 |
final IRestrictedAccessTypeRequestor nameRequestor, |
Lines 524-531
Link Here
|
524 |
if (VERBOSE) { |
648 |
if (VERBOSE) { |
525 |
Util.verbose("BasicSearchEngine.searchAllTypeNames(char[], char[], int, int, IJavaSearchScope, IRestrictedAccessTypeRequestor, int, IProgressMonitor)"); //$NON-NLS-1$ |
649 |
Util.verbose("BasicSearchEngine.searchAllTypeNames(char[], char[], int, int, IJavaSearchScope, IRestrictedAccessTypeRequestor, int, IProgressMonitor)"); //$NON-NLS-1$ |
526 |
Util.verbose(" - package name: "+(packageName==null?"null":new String(packageName))); //$NON-NLS-1$ //$NON-NLS-2$ |
650 |
Util.verbose(" - package name: "+(packageName==null?"null":new String(packageName))); //$NON-NLS-1$ //$NON-NLS-2$ |
|
|
651 |
Util.verbose(" - match rule: "+getMatchRuleString(packageMatchRule)); //$NON-NLS-1$ |
527 |
Util.verbose(" - type name: "+(typeName==null?"null":new String(typeName))); //$NON-NLS-1$ //$NON-NLS-2$ |
652 |
Util.verbose(" - type name: "+(typeName==null?"null":new String(typeName))); //$NON-NLS-1$ //$NON-NLS-2$ |
528 |
Util.verbose(" - match rule: "+getMatchRuleString(matchRule)); //$NON-NLS-1$ |
653 |
Util.verbose(" - match rule: "+getMatchRuleString(typeMatchRule)); //$NON-NLS-1$ |
529 |
Util.verbose(" - search for: "+searchFor); //$NON-NLS-1$ |
654 |
Util.verbose(" - search for: "+searchFor); //$NON-NLS-1$ |
530 |
Util.verbose(" - scope: "+scope); //$NON-NLS-1$ |
655 |
Util.verbose(" - scope: "+scope); //$NON-NLS-1$ |
531 |
} |
656 |
} |
Lines 533-538
Link Here
|
533 |
// Return on invalid combination of package and type names |
658 |
// Return on invalid combination of package and type names |
534 |
if (packageName == null || packageName.length == 0) { |
659 |
if (packageName == null || packageName.length == 0) { |
535 |
if (typeName != null && typeName.length == 0) { |
660 |
if (typeName != null && typeName.length == 0) { |
|
|
661 |
// TODO (frederic) Throw a JME instead? |
536 |
if (VERBOSE) { |
662 |
if (VERBOSE) { |
537 |
Util.verbose(" => return no result due to invalid empty values for package and type names!"); //$NON-NLS-1$ |
663 |
Util.verbose(" => return no result due to invalid empty values for package and type names!"); //$NON-NLS-1$ |
538 |
} |
664 |
} |
Lines 540-545
Link Here
|
540 |
} |
666 |
} |
541 |
} |
667 |
} |
542 |
|
668 |
|
|
|
669 |
// Create pattern |
543 |
IndexManager indexManager = JavaModelManager.getJavaModelManager().getIndexManager(); |
670 |
IndexManager indexManager = JavaModelManager.getJavaModelManager().getIndexManager(); |
544 |
final char typeSuffix; |
671 |
final char typeSuffix; |
545 |
switch(searchFor){ |
672 |
switch(searchFor){ |
Lines 565-576
Link Here
|
565 |
typeSuffix = IIndexConstants.TYPE_SUFFIX; |
692 |
typeSuffix = IIndexConstants.TYPE_SUFFIX; |
566 |
break; |
693 |
break; |
567 |
} |
694 |
} |
568 |
final TypeDeclarationPattern pattern = new TypeDeclarationPattern( |
695 |
final TypeDeclarationPattern pattern = packageMatchRule == SearchPattern.R_EXACT_MATCH |
569 |
packageName, |
696 |
? new TypeDeclarationPattern( |
570 |
null, // do find member types |
697 |
packageName, |
571 |
typeName, |
698 |
null, |
572 |
typeSuffix, |
699 |
typeName, |
573 |
matchRule); |
700 |
typeSuffix, |
|
|
701 |
typeMatchRule) |
702 |
: new QualifiedTypeDeclarationPattern( |
703 |
packageName, |
704 |
packageMatchRule, |
705 |
typeName, |
706 |
typeSuffix, |
707 |
typeMatchRule); |
574 |
|
708 |
|
575 |
// Get working copy path(s). Store in a single string in case of only one to optimize comparison in requestor |
709 |
// Get working copy path(s). Store in a single string in case of only one to optimize comparison in requestor |
576 |
final HashSet workingCopyPaths = new HashSet(); |
710 |
final HashSet workingCopyPaths = new HashSet(); |
Lines 687-693
Link Here
|
687 |
} else /*if (type.isInterface())*/ { |
821 |
} else /*if (type.isInterface())*/ { |
688 |
kind = TypeDeclaration.INTERFACE_DECL; |
822 |
kind = TypeDeclaration.INTERFACE_DECL; |
689 |
} |
823 |
} |
690 |
if (match(typeSuffix, packageName, typeName, matchRule, kind, packageDeclaration, simpleName)) { |
824 |
if (match(typeSuffix, packageName, typeName, typeMatchRule, kind, packageDeclaration, simpleName)) { |
691 |
nameRequestor.acceptType(type.getFlags(), packageDeclaration, simpleName, enclosingTypeNames, path, null); |
825 |
nameRequestor.acceptType(type.getFlags(), packageDeclaration, simpleName, enclosingTypeNames, path, null); |
692 |
} |
826 |
} |
693 |
} |
827 |
} |
Lines 703-715
Link Here
|
703 |
return false; // no local/anonymous type |
837 |
return false; // no local/anonymous type |
704 |
} |
838 |
} |
705 |
public boolean visit(TypeDeclaration typeDeclaration, CompilationUnitScope compilationUnitScope) { |
839 |
public boolean visit(TypeDeclaration typeDeclaration, CompilationUnitScope compilationUnitScope) { |
706 |
if (match(typeSuffix, packageName, typeName, matchRule, TypeDeclaration.kind(typeDeclaration.modifiers), packageDeclaration, typeDeclaration.name)) { |
840 |
if (match(typeSuffix, packageName, typeName, typeMatchRule, TypeDeclaration.kind(typeDeclaration.modifiers), packageDeclaration, typeDeclaration.name)) { |
707 |
nameRequestor.acceptType(typeDeclaration.modifiers, packageDeclaration, typeDeclaration.name, CharOperation.NO_CHAR_CHAR, path, null); |
841 |
nameRequestor.acceptType(typeDeclaration.modifiers, packageDeclaration, typeDeclaration.name, CharOperation.NO_CHAR_CHAR, path, null); |
708 |
} |
842 |
} |
709 |
return true; |
843 |
return true; |
710 |
} |
844 |
} |
711 |
public boolean visit(TypeDeclaration memberTypeDeclaration, ClassScope classScope) { |
845 |
public boolean visit(TypeDeclaration memberTypeDeclaration, ClassScope classScope) { |
712 |
if (match(typeSuffix, packageName, typeName, matchRule, TypeDeclaration.kind(memberTypeDeclaration.modifiers), packageDeclaration, memberTypeDeclaration.name)) { |
846 |
if (match(typeSuffix, packageName, typeName, typeMatchRule, TypeDeclaration.kind(memberTypeDeclaration.modifiers), packageDeclaration, memberTypeDeclaration.name)) { |
713 |
// compute encloising type names |
847 |
// compute encloising type names |
714 |
TypeDeclaration enclosing = memberTypeDeclaration.enclosingType; |
848 |
TypeDeclaration enclosing = memberTypeDeclaration.enclosingType; |
715 |
char[][] enclosingTypeNames = CharOperation.NO_CHAR_CHAR; |
849 |
char[][] enclosingTypeNames = CharOperation.NO_CHAR_CHAR; |
Lines 740-869
Link Here
|
740 |
} |
874 |
} |
741 |
|
875 |
|
742 |
/** |
876 |
/** |
743 |
* Searches for all top-level types and member types in the given scope. |
|
|
744 |
* The search can be selecting specific types (given a package or a type name |
745 |
* prefix and match modes). |
746 |
* |
747 |
*/ |
748 |
public void searchAllSecondaryTypeNames( |
749 |
IPackageFragmentRoot[] sourceFolders, |
750 |
final IRestrictedAccessTypeRequestor nameRequestor, |
751 |
boolean waitForIndexes, |
752 |
IProgressMonitor progressMonitor) throws JavaModelException { |
753 |
|
754 |
if (VERBOSE) { |
755 |
Util.verbose("BasicSearchEngine.searchAllSecondaryTypeNames(IPackageFragmentRoot[], IRestrictedAccessTypeRequestor, boolean, IProgressMonitor)"); //$NON-NLS-1$ |
756 |
StringBuffer buffer = new StringBuffer(" - source folders: "); //$NON-NLS-1$ |
757 |
int length = sourceFolders.length; |
758 |
for (int i=0; i<length; i++) { |
759 |
if (i==0) { |
760 |
buffer.append('['); |
761 |
} else { |
762 |
buffer.append(','); |
763 |
} |
764 |
buffer.append(sourceFolders[i].getElementName()); |
765 |
} |
766 |
buffer.append("]\n - waitForIndexes: "); //$NON-NLS-1$ |
767 |
buffer.append(waitForIndexes); |
768 |
Util.verbose(buffer.toString()); |
769 |
} |
770 |
|
771 |
IndexManager indexManager = JavaModelManager.getJavaModelManager().getIndexManager(); |
772 |
final TypeDeclarationPattern pattern = new SecondaryTypeDeclarationPattern(); |
773 |
|
774 |
// Get working copy path(s). Store in a single string in case of only one to optimize comparison in requestor |
775 |
final HashSet workingCopyPaths = new HashSet(); |
776 |
String workingCopyPath = null; |
777 |
ICompilationUnit[] copies = getWorkingCopies(); |
778 |
final int copiesLength = copies == null ? 0 : copies.length; |
779 |
if (copies != null) { |
780 |
if (copiesLength == 1) { |
781 |
workingCopyPath = copies[0].getPath().toString(); |
782 |
} else { |
783 |
for (int i = 0; i < copiesLength; i++) { |
784 |
ICompilationUnit workingCopy = copies[i]; |
785 |
workingCopyPaths.add(workingCopy.getPath().toString()); |
786 |
} |
787 |
} |
788 |
} |
789 |
final String singleWkcpPath = workingCopyPath; |
790 |
|
791 |
// Index requestor |
792 |
IndexQueryRequestor searchRequestor = new IndexQueryRequestor(){ |
793 |
public boolean acceptIndexMatch(String documentPath, SearchPattern indexRecord, SearchParticipant participant, AccessRuleSet access) { |
794 |
// Filter unexpected types |
795 |
TypeDeclarationPattern record = (TypeDeclarationPattern)indexRecord; |
796 |
if (!record.secondary) { |
797 |
return true; // filter maint types |
798 |
} |
799 |
if (record.enclosingTypeNames == IIndexConstants.ONE_ZERO_CHAR) { |
800 |
return true; // filter out local and anonymous classes |
801 |
} |
802 |
switch (copiesLength) { |
803 |
case 0: |
804 |
break; |
805 |
case 1: |
806 |
if (singleWkcpPath.equals(documentPath)) { |
807 |
return true; // fliter out *the* working copy |
808 |
} |
809 |
break; |
810 |
default: |
811 |
if (workingCopyPaths.contains(documentPath)) { |
812 |
return true; // filter out working copies |
813 |
} |
814 |
break; |
815 |
} |
816 |
|
817 |
// Accept document path |
818 |
AccessRestriction accessRestriction = null; |
819 |
if (access != null) { |
820 |
// Compute document relative path |
821 |
int pkgLength = (record.pkg==null || record.pkg.length==0) ? 0 : record.pkg.length+1; |
822 |
int nameLength = record.simpleName==null ? 0 : record.simpleName.length; |
823 |
char[] path = new char[pkgLength+nameLength]; |
824 |
int pos = 0; |
825 |
if (pkgLength > 0) { |
826 |
System.arraycopy(record.pkg, 0, path, pos, pkgLength-1); |
827 |
CharOperation.replace(path, '.', '/'); |
828 |
path[pkgLength-1] = '/'; |
829 |
pos += pkgLength; |
830 |
} |
831 |
if (nameLength > 0) { |
832 |
System.arraycopy(record.simpleName, 0, path, pos, nameLength); |
833 |
pos += nameLength; |
834 |
} |
835 |
// Update access restriction if path is not empty |
836 |
if (pos > 0) { |
837 |
accessRestriction = access.getViolatedRestriction(path); |
838 |
} |
839 |
} |
840 |
nameRequestor.acceptType(record.modifiers, record.pkg, record.simpleName, record.enclosingTypeNames, documentPath, accessRestriction); |
841 |
return true; |
842 |
} |
843 |
}; |
844 |
|
845 |
// add type names from indexes |
846 |
if (progressMonitor != null) { |
847 |
progressMonitor.beginTask(Messages.engine_searching, 100); |
848 |
} |
849 |
try { |
850 |
indexManager.performConcurrentJob( |
851 |
new PatternSearchJob( |
852 |
pattern, |
853 |
getDefaultSearchParticipant(), // Java search only |
854 |
createJavaSearchScope(sourceFolders), |
855 |
searchRequestor), |
856 |
waitForIndexes |
857 |
? IJavaSearchConstants.WAIT_UNTIL_READY_TO_SEARCH |
858 |
: IJavaSearchConstants.FORCE_IMMEDIATE_SEARCH, |
859 |
progressMonitor == null ? null : new SubProgressMonitor(progressMonitor, 100)); |
860 |
} |
861 |
catch (OperationCanceledException oce) { |
862 |
// do nothing |
863 |
} |
864 |
} |
865 |
|
866 |
/** |
867 |
* Searches for all top-level types and member types in the given scope using a case sensitive exact match |
877 |
* Searches for all top-level types and member types in the given scope using a case sensitive exact match |
868 |
* with the given qualified names and type names. |
878 |
* with the given qualified names and type names. |
869 |
* |
879 |
* |
Lines 976-982
Link Here
|
976 |
accessRestriction = access.getViolatedRestriction(path); |
986 |
accessRestriction = access.getViolatedRestriction(path); |
977 |
} |
987 |
} |
978 |
} |
988 |
} |
979 |
nameRequestor.acceptType(record.modifiers, record.getPackageName(), record.simpleName, record.getEnclosingTypeNames(), documentPath, accessRestriction); |
989 |
nameRequestor.acceptType(record.modifiers, record.pkg, record.simpleName, record.enclosingTypeNames, documentPath, accessRestriction); |
980 |
return true; |
990 |
return true; |
981 |
} |
991 |
} |
982 |
}; |
992 |
}; |