sdedic commented on code in PR #4091:
URL: https://github.com/apache/netbeans/pull/4091#discussion_r905879985
##########
groovy/groovy.editor/apichanges.xml:
##########
@@ -97,6 +97,20 @@ is the proper place.
</p>
</description>
<class package="org.netbeans.modules.groovy.editor.api.lexer"
name="LexUtilities"/>
+ </change>
+ <change id="GroovyElement.outer">
+ <api name="groovy-parsing"/>
+ <summary>Alternative construction for path more suitable for
expressions, API to resolve types</summary>
+ <version major="1" minor="85"/>
Review Comment:
Bump version in manifest as well ?
##########
groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/language/GroovyTypeSearcher.java:
##########
@@ -59,10 +62,38 @@ public class GroovyTypeSearcher implements IndexSearcher {
@Override
public Set<? extends Descriptor> getSymbols(Project project, String
textForQuery, Kind kind, Helper helper) {
- // TODO - search for methods too!!
+ GroovyIndex index = GroovyIndex.get(QuerySupport.findRoots(project,
Collections.singleton(ClassPath.SOURCE), Collections.<String>emptySet(),
Collections.<String>emptySet()));
- // For now, just at a minimum do the types
- return getTypes(project, textForQuery, kind, helper);
+ kind = adjustKind(kind, textForQuery);
+
+ if (kind == QuerySupport.Kind.CASE_INSENSITIVE_PREFIX /*|| kind ==
QuerySupport.Kind.CASE_INSENSITIVE_REGEXP*/) {
+ textForQuery = textForQuery.toLowerCase(Locale.ENGLISH);
+ }
+
+ Set<GroovyTypeDescriptor> result = new HashSet<GroovyTypeDescriptor>();
+
+
+ if (textForQuery.length() > 0) {
Review Comment:
So fo an empty query (i.e. empty prefix) we do not return any results, but
for `.*` regexp we do. Consistent with Java ?
##########
groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/GroovyIndex.java:
##########
@@ -649,38 +673,35 @@ private IndexedField createField(String signature,
IndexResult map, boolean inhe
//String fqn = map.getValue(GroovyIndexer.FQN_NAME);
- int typeIndex = signature.indexOf(';');
- String name = signature;
- String type = "java.lang.Object";
- if (typeIndex != -1) {
- int endIndex = signature.indexOf(';', typeIndex + 1);
- if (endIndex == -1) {
- endIndex = signature.length();
- }
- type = signature.substring(typeIndex + 1, endIndex);
- name = signature.substring(0, typeIndex);
- }
-
- int attributeIndex = signature.indexOf(';', typeIndex + 1);
- String attributes = null;
- int flags = 0;
-
- if (attributeIndex != -1) {
- flags = IndexedElement.stringToFlag(signature, attributeIndex + 1);
-
- if (signature.length() > attributeIndex + 1) {
- attributes = signature.substring(attributeIndex + 1,
signature.length());
- }
-
- //signature = signature.substring(0, attributeIndex);
- }
-
+ String[] parts = signature.split(";");
+ String name = parts[0];
+ String type = parts[1].isEmpty() ? "java.lang.Object" : parts[1];
+ int flags = parts[2].isEmpty() ? 0 :
IndexedElement.stringToFlag(parts[2], 0);
+ String isProperty = parts[3];
+ String attributes = flags + ";" + isProperty;
+ OffsetRange range = createOffsetRange(parts[4]);
+
IndexedField m = IndexedField.create(type, name, clz, map, attributes,
flags);
m.setInherited(inherited);
-
+ if (range != null) {
+ m.setOffsetRange(range);
+ }
return m;
}
+ private static OffsetRange createOffsetRange(String text) {
+ OffsetRange result = null;
+ int offsetStartIndex = text.indexOf('[');
+ int commaIndex = text.indexOf(',', offsetStartIndex + 1);
+ int offsetLastIndex = text.indexOf(']', commaIndex != -1 ? commaIndex
: offsetStartIndex);
Review Comment:
Nitpick - only if other more important edit is done: The condition
`commaIndex != -1` can be safely removed: it will work for both `commaIndex ==
-1` and other values, and if `commaIndex == -1`, the `offsetLastIndex` won't be
used (condition below)
##########
groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/language/GroovyTypeSearcher.java:
##########
@@ -59,10 +62,38 @@ public class GroovyTypeSearcher implements IndexSearcher {
@Override
public Set<? extends Descriptor> getSymbols(Project project, String
textForQuery, Kind kind, Helper helper) {
- // TODO - search for methods too!!
+ GroovyIndex index = GroovyIndex.get(QuerySupport.findRoots(project,
Collections.singleton(ClassPath.SOURCE), Collections.<String>emptySet(),
Collections.<String>emptySet()));
- // For now, just at a minimum do the types
- return getTypes(project, textForQuery, kind, helper);
+ kind = adjustKind(kind, textForQuery);
+
+ if (kind == QuerySupport.Kind.CASE_INSENSITIVE_PREFIX /*|| kind ==
QuerySupport.Kind.CASE_INSENSITIVE_REGEXP*/) {
Review Comment:
Why not the regexp as well?
##########
groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/GroovyIndexer.java:
##########
@@ -321,6 +323,9 @@ private void indexClass(ASTClass element, IndexDocument
document) {
document.addPair(FQN_NAME, element.getFqn(), true, true);
document.addPair(CLASS_NAME, name, true, true);
document.addPair(CASE_INSENSITIVE_CLASS_NAME, name.toLowerCase(),
true, true);
+ StringBuilder sb = new StringBuilder();
Review Comment:
Wrong theory. Each class gets its own `IndexDocument` although they are all
bound to the same Indexable.
##########
groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/GroovyIndex.java:
##########
@@ -242,7 +243,7 @@ public Set<IndexedMethod> getConstructors(final String
className) {
for (String constructor : constructors) {
String[] parts = constructor.split(";");
- String paramList = parts.length > 1 ? parts[1] : ""; // NOI18N
+ String paramList = parts[1];
Review Comment:
I'd add a sanity check that `parts` has the required (fixed) number of
items; should not happen anyway if the index is consistent & done by this impl.
##########
groovy/groovy.editor/src/org/netbeans/modules/groovy/editor/api/GroovyIndex.java:
##########
@@ -348,6 +358,25 @@ public Set<IndexedMethod> getMethods(final String name,
final String clz, QueryS
return methods;
}
+ private boolean matchInsensitiveCamelCase(String text, String where) {
+ if (text.length() > where.length()) {
+ return false;
+ }
+ String textP = text.toLowerCase();
Review Comment:
Sorry :) I still believe this function is not a proper impl. At least two
bugs here:
`matchInsensitiveCamelCase("RgExPars", "RegExParser")` produces `true`, but
`RgEx` should not match `R`e`gEx`. The culprit is IMHO this lowercase, as we
loose information on the Capital-and-lowercase exact substrings to be searched.
Try in IDE's Goto Type (type `RgExPars`)
The 2nd bug is
```
if (whereP.length() <= (index + 1))
```
That causes same string match (`matchInsensitiveCamelCase("RegExParser",
"RegExParser")`) to return `false` -- the last matching character satisfies
the condition.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists