1 19 20 package org.netbeans.modules.javadoc.search; 21 22 import java.util.StringTokenizer ; 23 24 import org.openide.util.RequestProcessor; 25 import org.openide.filesystems.FileObject; 26 27 31 32 public abstract class IndexSearchThread implements Runnable { 33 34 36 38 protected FileObject indexRoot; 40 private DocIndexItemConsumer ddiConsumer; 41 RequestProcessor.Task rpTask = null; 42 protected boolean caseSensitive; 43 44 protected String lastField=""; protected String middleField=""; protected String reminder=""; private int tokens=0; 48 49 private String lastAdd =""; private String lastDeclaring=""; 52 abstract void stopSearch(); 53 54 public IndexSearchThread( String toFind, FileObject fo, DocIndexItemConsumer ddiConsumer, boolean caseSensitive ) { 55 this.ddiConsumer = ddiConsumer; 56 this.indexRoot = fo; 57 this.caseSensitive = caseSensitive; 58 59 62 StringTokenizer st = new StringTokenizer (toFind, "."); tokens = st.countTokens(); 64 66 if( tokens > 1 ){ 67 if( tokens == 2 ){ 68 middleField = st.nextToken(); 69 lastField = st.nextToken(); 70 } 71 else{ 72 for( int i = 0; i < tokens-2; i++){ 73 reminder += st.nextToken(); 74 if( i+1 < tokens-2 ) 75 reminder += '.'; 76 } 77 middleField = st.nextToken(); 78 lastField = st.nextToken(); 79 } 80 } 81 else{ 82 lastField = toFind; 83 } 84 if( !caseSensitive ){ 85 reminder = reminder.toUpperCase(); 86 middleField = middleField.toUpperCase(); 87 lastField = lastField.toUpperCase(); 88 } 89 } 91 92 protected synchronized void insertDocIndexItem( DocIndexItem dii ) { 93 105 String diiField = dii.getField(); 106 String diiDeclaringClass = dii.getDeclaringClass(); 107 String diiPackage = dii.getPackage(); 108 if( !caseSensitive ){ 109 diiField = diiField.toUpperCase(); 110 diiDeclaringClass = diiDeclaringClass.toUpperCase(); 111 diiPackage = diiPackage.toUpperCase(); 112 } 113 114 if( tokens < 2 ){ 115 if( diiField.startsWith( lastField ) ){ 116 if( !lastAdd.equals( diiField ) || !lastDeclaring.equals( diiDeclaringClass )){ 119 ddiConsumer.addDocIndexItem ( dii ); 121 lastAdd = diiField; 122 lastDeclaring = diiDeclaringClass; 123 } 124 } 126 else if( diiDeclaringClass.startsWith( lastField ) && dii.getIconIndex() == DocSearchIcons.ICON_CLASS ) { 127 if( !lastAdd.equals( diiDeclaringClass ) ){ 128 ddiConsumer.addDocIndexItem ( dii ); lastAdd = diiDeclaringClass; 130 } 131 } 132 else if( diiPackage.startsWith( lastField + '.' ) && dii.getIconIndex() == DocSearchIcons.ICON_PACKAGE ) { 133 if( !lastAdd.equals( diiPackage ) ){ 134 ddiConsumer.addDocIndexItem ( dii ); lastAdd = diiPackage; 136 } 137 } 138 } 139 else{ 140 if( tokens == 2 ){ 141 if( diiField.startsWith(lastField) && diiDeclaringClass.equals(middleField) ){ 144 ddiConsumer.addDocIndexItem ( dii ); 145 } 146 else if( diiPackage.startsWith( middleField ) && diiDeclaringClass.equals( lastField ) ){ 147 ddiConsumer.addDocIndexItem ( dii ); 148 } 149 else if( diiPackage.startsWith( (middleField + '.' + lastField) ) && dii.getIconIndex() == DocSearchIcons.ICON_PACKAGE ){ 150 ddiConsumer.addDocIndexItem ( dii ); 151 } 152 } 153 else{ 154 if( diiField.startsWith(lastField) && diiDeclaringClass.equals(middleField) && diiPackage.startsWith( reminder ) ){ 156 ddiConsumer.addDocIndexItem ( dii ); 157 } 158 else if( diiDeclaringClass.startsWith(lastField) && diiPackage.equals( (reminder + '.' + middleField + '.')) ){ 160 ddiConsumer.addDocIndexItem ( dii ); 161 } 162 else if( diiPackage.startsWith( (reminder + '.' + middleField + '.' + lastField) ) && dii.getIconIndex() == DocSearchIcons.ICON_PACKAGE ){ 163 ddiConsumer.addDocIndexItem ( dii ); 164 } 165 } 166 } 167 } 168 169 public void go() { 170 rpTask = RequestProcessor.getDefault().post( this, 0, Thread.NORM_PRIORITY ); 171 } 172 173 public void finish() { 174 if ( !rpTask.isFinished() && !rpTask.cancel() ) 175 stopSearch(); 176 taskFinished(); 177 } 178 179 public void taskFinished() { 180 ddiConsumer.indexSearchThreadFinished( this ); 181 } 182 183 186 187 public static interface DocIndexItemConsumer { 188 189 190 public void addDocIndexItem ( DocIndexItem dii ); 191 192 193 public void indexSearchThreadFinished( IndexSearchThread ist ); 194 195 196 } 197 198 } 199 | Popular Tags |