[hg] main-silver: #234585:Problem with searching when sequence o...

  • From: Tomas Zezula < >
  • To: ,
  • Subject: [hg] main-silver: #234585:Problem with searching when sequence o...
  • Date: Thu, 19 Sep 2013 08:40:37 -0700

changeset d89e4b8099e7 in main-silver ((none))
details: http://hg.netbeans.org/main-silver/rev/d89e4b8099e7
description:
        #234585:Problem with searching when sequence of many '*' is entere

diffstat:

 jumpto/src/org/netbeans/modules/jumpto/common/Utils.java               |  
109 ++++++++++
 jumpto/src/org/netbeans/modules/jumpto/file/FileSearchAction.java      |    
8 +-
 jumpto/src/org/netbeans/modules/jumpto/symbol/ContentProviderImpl.java |   
34 +--
 jumpto/src/org/netbeans/modules/jumpto/type/GoToTypeAction.java        |   
32 +--
 4 files changed, 125 insertions(+), 58 deletions(-)

diffs (290 lines):

diff --git a/jumpto/src/org/netbeans/modules/jumpto/common/Utils.java 
b/jumpto/src/org/netbeans/modules/jumpto/common/Utils.java
new file mode 100644
--- /dev/null
+++ b/jumpto/src/org/netbeans/modules/jumpto/common/Utils.java
@@ -0,0 +1,109 @@
+/*
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
+ *
+ * Copyright 2013 Oracle and/or its affiliates. All rights reserved.
+ *
+ * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
+ * Other names may be trademarks of their respective owners.
+ *
+ * The contents of this file are subject to the terms of either the GNU
+ * General Public License Version 2 only ("GPL") or the Common
+ * Development and Distribution License("CDDL") (collectively, the
+ * "License"). You may not use this file except in compliance with the
+ * License. You can obtain a copy of the License at
+ * http://www.netbeans.org/cddl-gplv2.html
+ * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
+ * specific language governing permissions and limitations under the
+ * License.  When distributing the software, include this License Header
+ * Notice in each file and include the License file at
+ * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the GPL Version 2 section of the License file that
+ * accompanied this code. If applicable, add the following below the
+ * License Header, with the fields enclosed by brackets [] replaced by
+ * your own identifying information:
+ * "Portions Copyrighted [year] [name of copyright owner]"
+ *
+ * If you wish your version of this file to be governed by only the CDDL
+ * or only the GPL Version 2, indicate your decision by adding
+ * "[Contributor] elects to include this software in this distribution
+ * under the [CDDL or GPL Version 2] license." If you do not indicate a
+ * single choice of license, a recipient has the option to distribute
+ * your version of this file under either the CDDL, the GPL Version 2 or
+ * to extend the choice of license to its licensees as provided above.
+ * However, if you add GPL Version 2 code and therefore, elected the GPL
+ * Version 2 license, then the option applies only if the new code is
+ * made subject to such option by the copyright holder.
+ *
+ * Contributor(s):
+ *
+ * Portions Copyrighted 2013 Sun Microsystems, Inc.
+ */
+
+package org.netbeans.modules.jumpto.common;
+
+import java.util.regex.Pattern;
+import org.netbeans.api.annotations.common.NonNull;
+
+/**
+ *
+ * @author Tomas Zezula
+ */
+public class Utils {
+
+    private static Pattern camelCasePattern = 
Pattern.compile("(?:\\p{javaUpperCase}(?:\\p{javaLowerCase}|\\p{Digit}|\\.|\\$)*){2,}");
 // NOI18N
+
+    private Utils() {
+        throw new IllegalStateException();
+    }
+
+    public static int containsWildCard( String text ) {
+        for( int i = 0; i < text.length(); i++ ) {
+            if ( text.charAt( i ) == '?' || text.charAt( i ) == '*' ) { // 
NOI18N
+                return i;
+            }
+        }
+        return -1;
+    }
+
+    public static boolean isCamelCase(String text) {
+         return camelCasePattern.matcher(text).matches();
+    }
+
+    public static boolean isAllUpper( String text ) {
+        for( int i = 0; i < text.length(); i++ ) {
+            if ( !Character.isUpperCase( text.charAt( i ) ) ) {
+                return false;
+            }
+        }
+
+        return true;
+    }
+
+    @NonNull
+    public static String removeNonNeededWildCards(@NonNull final String 
text) {
+        final StringBuilder sb = new StringBuilder();
+        boolean  lastAny = false;
+        for (int i = 0; i < text.length(); i++) {
+            char c = text.charAt(i);
+            switch (c) {
+                case '*':   //NOI18N
+                    if (!lastAny) {
+                        sb.append(c);
+                    }
+                    lastAny = true;
+                    break;
+                case '?':   //NOI18N
+                    if (!lastAny) {
+                        sb.append(c);
+                    }
+                    break;
+                default:
+                    sb.append(c);
+                    lastAny = false;
+            }
+        }
+        return sb.toString();
+    }
+
+}
diff --git 
a/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchAction.java 
b/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchAction.java
--- a/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchAction.java
+++ b/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchAction.java
@@ -109,8 +109,8 @@
 import org.netbeans.modules.jumpto.EntitiesListCellRenderer;
 import org.netbeans.modules.jumpto.common.HighlightingNameFormatter;
 import org.netbeans.modules.jumpto.common.Factory;
-import org.netbeans.modules.jumpto.type.GoToTypeAction;
 import org.netbeans.modules.jumpto.common.Models;
+import org.netbeans.modules.jumpto.common.Utils;
 import org.netbeans.modules.parsing.spi.indexing.support.IndexResult;
 import org.netbeans.modules.parsing.spi.indexing.support.QuerySupport;
 import org.netbeans.spi.jumpto.file.FileDescriptor;
@@ -221,7 +221,7 @@
             return;
         }
 
-        int wildcard = GoToTypeAction.containsWildCard(text);
+        int wildcard = Utils.containsWildCard(text);
         QuerySupport.Kind nameKind;
 
         if (exact) {
@@ -230,8 +230,9 @@
         }
         else if (wildcard != -1) {
             nameKind = panel.isCaseSensitive() ? QuerySupport.Kind.REGEXP : 
QuerySupport.Kind.CASE_INSENSITIVE_REGEXP;
+            text = Utils.removeNonNeededWildCards(text);
         }
-        else if ((GoToTypeAction.isAllUpper(text) && text.length() > 1) || 
GoToTypeAction.isCamelCase(text)) {
+        else if ((Utils.isAllUpper(text) && text.length() > 1) || 
Utils.isCamelCase(text)) {
             nameKind = QuerySupport.Kind.CAMEL_CASE;
         }
         else {
@@ -421,7 +422,6 @@
             // Clean caches
             dialog.dispose();
             this.dialog = null;
-            //GoToTypeAction.this.cache = null;
             FileSearchOptions.flush();
         }
     }
diff --git 
a/jumpto/src/org/netbeans/modules/jumpto/symbol/ContentProviderImpl.java 
b/jumpto/src/org/netbeans/modules/jumpto/symbol/ContentProviderImpl.java
--- a/jumpto/src/org/netbeans/modules/jumpto/symbol/ContentProviderImpl.java
+++ b/jumpto/src/org/netbeans/modules/jumpto/symbol/ContentProviderImpl.java
@@ -75,6 +75,7 @@
 import org.netbeans.modules.jumpto.EntitiesListCellRenderer;
 import org.netbeans.modules.jumpto.common.HighlightingNameFormatter;
 import org.netbeans.modules.jumpto.common.Models;
+import org.netbeans.modules.jumpto.common.Utils;
 import org.netbeans.spi.jumpto.symbol.SymbolDescriptor;
 import org.netbeans.spi.jumpto.symbol.SymbolProvider;
 import org.netbeans.spi.jumpto.type.SearchType;
@@ -512,7 +513,11 @@
                     Level.FINE,
                     "Calling SymbolProvider: {0}", //NOI18N
                     provider);                
-                final SymbolProvider.Context context = 
SymbolProviderAccessor.DEFAULT.createContext(null, text, getSearchType(text, 
exact, isCaseSensitive));
+                final SearchType searchType = getSearchType(text, exact, 
isCaseSensitive);
+                if (searchType == SearchType.REGEXP || searchType == 
SearchType.CASE_INSENSITIVE_REGEXP) {
+                    text = Utils.removeNonNeededWildCards(text);
+                }
+                final SymbolProvider.Context context = 
SymbolProviderAccessor.DEFAULT.createContext(null, text, searchType);
                 final SymbolProvider.Result result = 
SymbolProviderAccessor.DEFAULT.createResult(items, message, context);
                 provider.computeSymbolNames(context, result);
                 current = null;
@@ -533,11 +538,11 @@
             @NonNull final String text,
             final boolean exact,
             final boolean isCaseSensitive) {
-        int wildcard = containsWildCard(text);
+        int wildcard = Utils.containsWildCard(text);
         if (exact) {
             //nameKind = isCaseSensitive ? SearchType.EXACT_NAME : 
SearchType.CASE_INSENSITIVE_EXACT_NAME;
             return SearchType.EXACT_NAME;
-        } else if ((isAllUpper(text) && text.length() > 1) || 
isCamelCase(text)) {
+        } else if ((Utils.isAllUpper(text) && text.length() > 1) || 
Utils.isCamelCase(text)) {
             return SearchType.CAMEL_CASE;
         } else if (wildcard != -1) {
             return isCaseSensitive ? SearchType.REGEXP : 
SearchType.CASE_INSENSITIVE_REGEXP;
@@ -545,27 +550,4 @@
             return isCaseSensitive ? SearchType.PREFIX : 
SearchType.CASE_INSENSITIVE_PREFIX;
         }
     }
-
-    private static boolean isAllUpper( String text ) {
-    for( int i = 0; i < text.length(); i++ ) {
-        if ( !Character.isUpperCase( text.charAt( i ) ) ) {
-            return false;
         }
-    }
-
-    return true;
-    }
-
-    private static int containsWildCard( String text ) {
-        for( int i = 0; i < text.length(); i++ ) {
-            if ( text.charAt( i ) == '?' || text.charAt( i ) == '*' ) { // 
NOI18N
-                return i;
-            }
-        }
-        return -1;
-    }
-
-    private static boolean isCamelCase(String text) {
-         return camelCasePattern.matcher(text).matches();
-    }
-}
diff --git a/jumpto/src/org/netbeans/modules/jumpto/type/GoToTypeAction.java 
b/jumpto/src/org/netbeans/modules/jumpto/type/GoToTypeAction.java
--- a/jumpto/src/org/netbeans/modules/jumpto/type/GoToTypeAction.java
+++ b/jumpto/src/org/netbeans/modules/jumpto/type/GoToTypeAction.java
@@ -99,6 +99,7 @@
 import org.netbeans.editor.JumpList;
 import org.netbeans.modules.jumpto.EntitiesListCellRenderer;
 import org.netbeans.modules.jumpto.common.HighlightingNameFormatter;
+import org.netbeans.modules.jumpto.common.Utils;
 import org.netbeans.modules.jumpto.file.LazyListModel;
 import org.netbeans.modules.sampler.Sampler;
 import org.openide.DialogDescriptor;
@@ -285,14 +286,14 @@
             return;
         }
         
-        int wildcard = containsWildCard(text);
+        int wildcard = Utils.containsWildCard(text);
                 
         if (exact) {
             nameKinds = Collections.singleton(
                 panel.isCaseSensitive() ?
                     SearchType.EXACT_NAME :
                     SearchType.CASE_INSENSITIVE_EXACT_NAME);
-        } else if ((isAllUpper(text) && text.length() > 1) || 
isCamelCase(text)) {
+        } else if ((Utils.isAllUpper(text) && text.length() > 1) || 
Utils.isCamelCase(text)) {
             nameKinds = Arrays.asList(
                 new SearchType[] {
                     SearchType.CAMEL_CASE,
@@ -304,6 +305,7 @@
                 panel.isCaseSensitive() ?
                     SearchType.REGEXP :
                     SearchType.CASE_INSENSITIVE_REGEXP);
+            text = Utils.removeNonNeededWildCards(text);
         } else {
             nameKinds = Collections.singleton(
                 panel.isCaseSensitive() ?
@@ -336,32 +338,6 @@
     
     // Private methods 
---------------------------------------------------------
         
-    public static boolean isAllUpper( String text ) {
-        for( int i = 0; i < text.length(); i++ ) {
-            if ( !Character.isUpperCase( text.charAt( i ) ) ) {
-                return false;
-            }
-        }
-        
-        return true;
-    }
-    
-    public static int containsWildCard( String text ) {
-        for( int i = 0; i < text.length(); i++ ) {
-            if ( text.charAt( i ) == '?' || text.charAt( i ) == '*' ) { // 
NOI18N
-                return i;                
-            }
-        }        
-        return -1;
-    }
-    
-    private static Pattern camelCasePattern = 
Pattern.compile("(?:\\p{javaUpperCase}(?:\\p{javaLowerCase}|\\p{Digit}|\\.|\\$)*){2,}");
 // NOI18N
-    
-    public static boolean isCamelCase(String text) {
-         return camelCasePattern.matcher(text).matches();
-    }
-    
-    
     /** Creates the dialog to show
      */
    private Dialog createDialog( final GoToPanel panel) {

[hg] main-silver: #234585:Problem with searching when sequence o...

Tomas Zezula 09/19/2013

Project Features

About this Project

Editor was started in November 2009, is owned by Martin Ryzl, and has 147 members.
By use of this website, you agree to the NetBeans Policies and Terms of Use (revision 20131025.e7cbc9d). © 2013, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo
 
 
Close
loading
Please Confirm
Close