This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 269708
Collapse All | Expand All

(-)a/cnd.api.model/src/org/netbeans/modules/cnd/api/model/util/CsmSortUtilities.java (-1 / +47 lines)
Lines 61-66 Link Here
61
import java.util.Comparator;
61
import java.util.Comparator;
62
import java.util.Iterator;
62
import java.util.Iterator;
63
import java.util.List;
63
import java.util.List;
64
import java.util.regex.Pattern;
64
import org.netbeans.modules.cnd.utils.cache.CharSequenceUtils;
65
import org.netbeans.modules.cnd.utils.cache.CharSequenceUtils;
65
import org.openide.util.CharSequences;
66
import org.openide.util.CharSequences;
66
67
Lines 117-123 Link Here
117
        return n1 >= n2;
118
        return n1 >= n2;
118
    }
119
    }
119
120
120
    
121
    public static boolean startsWith(String theString, String prefix, boolean match, boolean caseSensitive) {
122
        return isCamelCasePrefix(prefix) && !match
123
                ? caseSensitive
124
                        ? startsWithCamelCase(theString, prefix)
125
                        : startsWithCamelCase(theString, prefix) || CsmSortUtilities.matchName(theString, prefix, match, caseSensitive)
126
                : CsmSortUtilities.matchName(theString, prefix, match, caseSensitive);
127
    }
128
129
    public static boolean startsWithCamelCase(String theString, String prefix) {
130
        if (theString == null || theString.length() == 0 || prefix == null || prefix.length() == 0) {
131
            return false;
132
        }
133
        StringBuilder sb = new StringBuilder();
134
        int lastIndex = 0;
135
        int index;
136
        do {
137
            index = findNextUpper(prefix, lastIndex + 1);
138
            String token = prefix.substring(lastIndex, index == -1 ? prefix.length() : index);
139
            sb.append(token);
140
            sb.append(index != -1 ? "[\\p{javaLowerCase}\\p{Digit}_\\$]*" : ".*"); // NOI18N         
141
            lastIndex = index;
142
        } while (index != -1);
143
        return Pattern.compile(sb.toString()).matcher(theString).matches();
144
    }
145
146
    private static int findNextUpper(String text, int offset) {
147
        for (int i = offset; i < text.length(); i++) {
148
            if (Character.isUpperCase(text.charAt(i))) {
149
                return i;
150
            }
151
        }
152
        return -1;
153
    }
154
155
    private static boolean isCamelCasePrefix(String prefix) {
156
        if (prefix == null || prefix.length() < 2 || prefix.charAt(0) == '"') {
157
            return false;
158
        }
159
        for (int i = 1; i < prefix.length(); i++) {
160
            if (Character.isUpperCase(prefix.charAt(i))) {
161
                return true;
162
            }
163
        }
164
        return false;
165
    }
166
121
    public static List<CsmNamedElement> filterList(Collection<? extends CsmDeclaration> list, CharSequence strPrefix, boolean match, boolean caseSensitive) {
167
    public static List<CsmNamedElement> filterList(Collection<? extends CsmDeclaration> list, CharSequence strPrefix, boolean match, boolean caseSensitive) {
122
        return filterList(list.iterator(), strPrefix, match, caseSensitive);
168
        return filterList(list.iterator(), strPrefix, match, caseSensitive);
123
    }
169
    }
(-)a/cnd.completion/src/org/netbeans/modules/cnd/completion/csm/CsmProjectContentResolver.java (-1 / +1 lines)
Lines 1551-1557 Link Here
1551
    }
1551
    }
1552
1552
1553
    private boolean matchName(CharSequence name, String strPrefix, boolean match) {
1553
    private boolean matchName(CharSequence name, String strPrefix, boolean match) {
1554
        return CsmSortUtilities.matchName(name, strPrefix, match, caseSensitive);
1554
        return CsmSortUtilities.startsWith(name.toString(), strPrefix, match, caseSensitive);
1555
    }
1555
    }
1556
1556
1557
    public boolean matchVisibility(CsmMember member, CsmVisibility minVisibility) {
1557
    public boolean matchVisibility(CsmMember member, CsmVisibility minVisibility) {
(-)a/cnd.completion/test/unit/data/goldenfiles/org/netbeans/modules/cnd/completion/CamelCaseCompletionTestCase/testAllCapital.ref (+1 lines)
Line 0 Link Here
1
UID() void	$	   UID()
(-)a/cnd.completion/test/unit/data/goldenfiles/org/netbeans/modules/cnd/completion/CamelCaseCompletionTestCase/testFirstCapitalCamelCase.ref (+1 lines)
Line 0 Link Here
1
GetId() long	$	   GetId()
(-)a/cnd.completion/test/unit/data/goldenfiles/org/netbeans/modules/cnd/completion/CamelCaseCompletionTestCase/testFirstLowCamelCase.ref (+2 lines)
Line 0 Link Here
1
functionAaa() void	$	   functionAaa()
2
functionAaaExtra() void	$	   functionAaaExtra()
(-)a/cnd.completion/test/unit/data/goldenfiles/org/netbeans/modules/cnd/completion/CamelCaseCompletionTestCase/testUnderscore.ref (+3 lines)
Line 0 Link Here
1
add_simple
2
add_simple_long
3
add_somethingToSomething
(-)a/cnd.completion/test/unit/data/org/netbeans/modules/cnd/completion/CamelCaseCompletionTestCase/file.cc (+42 lines)
Line 0 Link Here
1
void functionAaa() {
2
}
3
4
void functionBbb() {
5
}
6
7
void functionAaaExtra() {
8
}
9
10
//////////////////////
11
12
long GetId() {
13
    return 0;
14
}
15
16
long getIdentificator() {
17
    return 0;
18
}
19
20
//////////////////////
21
22
int add_simple(int a, int b) {
23
    return a + b
24
}
25
26
int add_complicated(int a, int b) {
27
    return 42;
28
}
29
30
long add_simple_long(int a, int b) {
31
    return a + b;
32
}
33
34
void add_somethingToSomething(int a, int b) {
35
}
36
37
void UID(){
38
}
39
40
int main() {
41
    // <- insert code here
42
}
(-)a/cnd.completion/test/unit/src/org/netbeans/modules/cnd/completion/CamelCaseCompletionTestCase.java (+71 lines)
Line 0 Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright (c) 2017 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 *
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 *
38
 * Contributor(s):
39
 */
40
package org.netbeans.modules.cnd.completion;
41
42
import org.netbeans.modules.cnd.completion.cplusplus.ext.CompletionBaseTestCase;
43
44
/**
45
 *
46
 * @author igromov
47
 */
48
public class CamelCaseCompletionTestCase extends CompletionBaseTestCase {
49
50
    public CamelCaseCompletionTestCase(String testName) {
51
        super(testName, true);
52
    }
53
54
    public void testFirstLowCamelCase() throws Exception {
55
        super.performTest("file.cc", 41, 4, "fA");
56
    }
57
58
    public void testFirstCapitalCamelCase() throws Exception {
59
        super.performTest("file.cc", 41, 4, "GI");
60
    }
61
    
62
    public void testAllCapital() throws Exception {
63
        super.performTest("file.cc", 41, 4, "UID");
64
    }
65
66
    /* Not implemented yet
67
    public void testUnderscore() throws Exception {
68
        super.performTest("file.cc", 38, 4, "aS");
69
    }
70
    */
71
}
(-)a/cnd.modelimpl/src/org/netbeans/modules/cnd/modelimpl/impl/services/SelectImpl.java (-1 / +1 lines)
Lines 487-493 Link Here
487
                    if (allowEmptyName && name.length() == 0) {
487
                    if (allowEmptyName && name.length() == 0) {
488
                        return true;
488
                        return true;
489
                    }
489
                    }
490
                    return CsmSortUtilities.matchName(name, strPrefix, match, caseSensitive);
490
                    return CsmSortUtilities.startsWith(name.toString(), strPrefix.toString(), match, caseSensitive);
491
                }
491
                }
492
                return false;
492
                return false;
493
            }
493
            }

Return to bug 269708