Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions ide/csl.api/apichanges.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@
<apidef name="csl.api">Common Scripting Language API</apidef>
</apidefs>
<changes>
<change id="StructureItem.InheritedItem">
<api name="csl.api"/>
<summary>Adding a new StructureItem.InheritedItem interface</summary>
<version major="2" minor="72"/>
<date day="31" month="10" year="2021"/>
<author login="junichi11"/>
<compatibility addition="yes" deletion="no" modification="no" binary="compatible" source="compatible" deprecation="no"/>
<description>
<p>
Adding <code>StructureItem.InheritedItem</code> interface which allows defining whether the StructrureItem is an inherited item.
Adding also <code>StructrureItem.isInherited</code> static method.
</p>
</description>
<class package="org.netbeans.modules.csl.api" name="StructureItem"/>
</change>
<change id="ExtraMockServices">
<summary>Allow subclasses to inject instances to MockLookup</summary>
<version major="2" minor="65"/>
Expand Down
2 changes: 1 addition & 1 deletion ide/csl.api/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.

spec.version.base=2.71.0
spec.version.base=2.72.0
is.autoload=true
javac.source=1.8

Expand Down
38 changes: 37 additions & 1 deletion ide/csl.api/src/org/netbeans/modules/csl/api/StructureItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,27 @@ public interface StructureItem {
long getEndPosition();
/** Icon to use instead of the default implied by the ElementKind */
@CheckForNull ImageIcon getCustomIcon();

@Override
public abstract boolean equals(Object o);
@Override
public abstract int hashCode();

/**
* Check whether the StructureItem is an inherited item.
*
* @since 2.72.0
* @param structureItem the structure item
* @return {@code true} if it is an inherited item (a class doesn't override
* that member), otherwise {@code false} (a class declares it as an
* overriding member)
*/
public static boolean isInherited(StructureItem structureItem) {
// see also http://wiki.apidesign.org/wiki/ExtendingInterfaces
return structureItem instanceof StructureItem.InheritedItem
&& ((StructureItem.InheritedItem) structureItem).isInherited();
}

public interface CollapsedDefault extends StructureItem {

/**
Expand All @@ -60,4 +75,25 @@ public interface CollapsedDefault extends StructureItem {

}

public interface InheritedItem extends StructureItem {

/**
* Check whether this StructureItem is an inherited item.
*
* @since 2.72.0
* @return {@code true} if it is an inherited item (a class doesn't
* override that member), otherwise {@code false} (a class declares it
* as an overriding member)
*/
boolean isInherited();
Comment thread
sdedic marked this conversation as resolved.

/**
* Get the declaring element handle. e.g. class
*
* @since 2.72.0
* @return the declaring element handle of the inherited item
*/
@NonNull
ElementHandle getDeclaringElement();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally, I suppose this doesn't return null.

}
}
154 changes: 81 additions & 73 deletions ide/csl.api/src/org/netbeans/modules/csl/api/UiUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,11 @@
import org.openide.text.NbDocument;
import org.openide.util.NbBundle;


/**
* This file is originally from Retouche, the Java Support
/**
* This file is originally from Retouche, the Java Support
* infrastructure in NetBeans. I have modified the file as little
* as possible to make merging Retouche fixes back as simple as
* possible.
* possible.
*
* This class contains various methods bound to visualization of Java model
* elements. It was formerly included under SourceUtils
Expand Down Expand Up @@ -92,7 +91,7 @@ public static boolean open(Source source, ElementHandle handle) {

public static boolean open(final FileObject fo, final int offset) {
assert fo != null;

if (!SwingUtilities.isEventDispatchThread()) {
SwingUtilities.invokeLater(new Runnable() {
public @Override void run() {
Expand All @@ -101,7 +100,7 @@ public static boolean open(final FileObject fo, final int offset) {
});
return true; // not exactly accurate, but....
}

return doOpen(fo, offset);
}

Expand Down Expand Up @@ -240,89 +239,98 @@ private static DeclarationLocation getElementLocation(final Source source, final
if (fileObject != null && fileObject != source.getFileObject()) {
// The element is not in the parse tree for this parse job; it is
// probably something like an indexed element
// NETBEANS-3362 inherited items may be in another file
DeclarationLocation location = getDeclarationLocation(Source.create(fileObject), handle);
if (location != DeclarationLocation.NONE) {
return location;
}
return new DeclarationLocation(fileObject, -1);
}
return getDeclarationLocation(source, handle);
}

final DeclarationLocation[] result = new DeclarationLocation[] { null };
private static DeclarationLocation getDeclarationLocation(final Source source, final ElementHandle handle) {
final DeclarationLocation[] result = new DeclarationLocation[]{null};
final AtomicBoolean cancel = new AtomicBoolean();
final UserTask t = new UserTask() {
public @Override void run(ResultIterator resultIterator) throws ParseException {
if (cancel.get()) {
return;
}
if (resultIterator.getSnapshot().getMimeType().equals(handle.getMimeType())) {
Parser.Result r = resultIterator.getParserResult();
if (r instanceof ParserResult) {
ParserResult info = (ParserResult) r;
OffsetRange range = handle.getOffsetRange(info);
if (range != OffsetRange.NONE && range != null) {
result[0] = new DeclarationLocation(info.getSnapshot().getSource().getFileObject(), range.getStart());
return;
}
@Override
public void run(ResultIterator resultIterator) throws ParseException {
if (cancel.get()) {
return;
}
if (resultIterator.getSnapshot().getMimeType().equals(handle.getMimeType())) {
Parser.Result r = resultIterator.getParserResult();
if (r instanceof ParserResult) {
ParserResult info = (ParserResult) r;
OffsetRange range = handle.getOffsetRange(info);
if (range != OffsetRange.NONE && range != null) {
result[0] = new DeclarationLocation(info.getSnapshot().getSource().getFileObject(), range.getStart());
return;
}
}
}

for(Embedding e : resultIterator.getEmbeddings()) {
run(resultIterator.getResultIterator(e));
if (result[0] != null) {
break;
}
for (Embedding e : resultIterator.getEmbeddings()) {
run(resultIterator.getResultIterator(e));
if (result[0] != null) {
break;
}
}
};

if (IndexingManager.getDefault().isIndexing()) {
int timeout = SwingUtilities.isEventDispatchThread() ? AWT_TIMEOUT : NON_AWT_TIMEOUT;
Future<Void> f;
try {
f = ParserManager.parseWhenScanFinished(Collections.singleton(source), t);
} catch (ParseException ex) {
LOG.log(Level.WARNING, null, ex);
return DeclarationLocation.NONE;
}
}
};

if (IndexingManager.getDefault().isIndexing()) {
int timeout = SwingUtilities.isEventDispatchThread() ? AWT_TIMEOUT : NON_AWT_TIMEOUT;
Future<Void> f;
try {
f = ParserManager.parseWhenScanFinished(Collections.singleton(source), t);
} catch (ParseException ex) {
LOG.log(Level.WARNING, null, ex);
return DeclarationLocation.NONE;
}

try {
f.get(timeout, TimeUnit.MILLISECONDS);
} catch (InterruptedException ex) {
LOG.log(Level.INFO, null, ex);
return DeclarationLocation.NONE;
} catch (ExecutionException ex) {
LOG.log(Level.INFO, null, ex);
return DeclarationLocation.NONE;
} catch (TimeoutException ex) {
f.cancel(true);
LOG.info("Skipping location of element offset within file, Scannig in progress"); // NOI18N
return DeclarationLocation.NONE; //we are opening @ 0 position. Fix #160478
}
try {
f.get(timeout, TimeUnit.MILLISECONDS);
} catch (InterruptedException ex) {
LOG.log(Level.INFO, null, ex);
return DeclarationLocation.NONE;
} catch (ExecutionException ex) {
LOG.log(Level.INFO, null, ex);
return DeclarationLocation.NONE;
} catch (TimeoutException ex) {
f.cancel(true);
LOG.info("Skipping location of element offset within file, Scannig in progress"); // NOI18N
return DeclarationLocation.NONE; //we are opening @ 0 position. Fix #160478
}

if (!f.isDone()) {
f.cancel(true);
LOG.info("Skipping location of element offset within file, Scannig in progress"); // NOI18N
return DeclarationLocation.NONE; //we are opening @ 0 position. Fix #160478
}
} else if (SwingUtilities.isEventDispatchThread()) {
BaseProgressUtils.runOffEventDispatchThread(
if (!f.isDone()) {
f.cancel(true);
LOG.info("Skipping location of element offset within file, Scannig in progress"); // NOI18N
return DeclarationLocation.NONE; //we are opening @ 0 position. Fix #160478
}
} else if (SwingUtilities.isEventDispatchThread()) {
BaseProgressUtils.runOffEventDispatchThread(
new Runnable() {
@Override
public void run() {
try {
ParserManager.parse(Collections.singleton(source), t);
} catch (ParseException ex) {
LOG.log(Level.WARNING, null, ex);
}
}
},
@Override
public void run() {
try {
ParserManager.parse(Collections.singleton(source), t);
} catch (ParseException ex) {
LOG.log(Level.WARNING, null, ex);
}
}
},
NbBundle.getMessage(UiUtils.class, "TXT_CalculatingDeclPos"),
cancel,
false);
} else {
try {
ParserManager.parse(Collections.singleton(source), t);
} catch (ParseException ex) {
LOG.log(Level.WARNING, null, ex);
return DeclarationLocation.NONE;
}
} else {
try {
ParserManager.parse(Collections.singleton(source), t);
} catch (ParseException ex) {
LOG.log(Level.WARNING, null, ex);
return DeclarationLocation.NONE;
}
return result[0] != null ? result[0] : DeclarationLocation.NONE;
}
return result[0] != null ? result[0] : DeclarationLocation.NONE;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ public void run(Result result, SchedulerEvent event) {

while (!todo.isEmpty()) {
StructureItem i = todo.remove(0);
if (i instanceof StructureItem.InheritedItem
&& ((StructureItem.InheritedItem) i).isInherited()) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than spreading these instance checks all over the place, there could be a helper method:

public static boolean isInherited(StructureItem i) {
}

it could actually be in StructureItem interface itself now, when it is possible to have static methods in interfaces.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your review! Will do that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continue;
}

todo.addAll(i.getNestedItems());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,9 @@ private void selectNode(Document doc, StructureItem structureRoot, long id, int
OUTER: while (requestId.get() == id) {
for (Node n : toSelect.getChildren().getNodes(true)) {
StructureItemNode sin = (StructureItemNode) n;

if (StructureItem.isInherited(sin.item)) {
continue;
}
if (sin.item.getPosition() <= caret && caret <= sin.item.getEndPosition()) {
toSelect = sin;
// see #223480, mimetype nodes look ugly in the breadcrumb bar
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public Collection<StructureItem> filter(List<StructureItem> original) {
boolean non_public = filters.isSelected(SHOW_NON_PUBLIC);
boolean statik = filters.isSelected(SHOW_STATIC);
boolean fields = filters.isSelected(SHOW_FIELDS);
// XXX Enable later boolean inherited = filters.isSelected(SHOW_INHERITED);
boolean inherited = filters.isSelected(SHOW_INHERITED);

if (original == null || original.isEmpty()) {
return Collections.EMPTY_LIST;
Expand Down Expand Up @@ -112,7 +112,10 @@ public Collection<StructureItem> filter(List<StructureItem> original) {
continue;
}

// XXX Inherited members
// Inherited members
if (!inherited && StructureItem.isInherited(description)) {
continue;
}

result.add(description);
}
Expand Down Expand Up @@ -140,14 +143,13 @@ public void setNaturalSort( boolean naturalSort ) {
private static FiltersManager createFilters () {
FiltersDescription desc = new FiltersDescription();

// XXX to be enabled later
// desc.addFilter(SHOW_INHERITED,
// NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowInherited"), //NOI18N
// NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowInheritedTip"), //NOI18N
// false,
// new ImageIcon (Utilities.loadImage("org/netbeans/modules/csl/navigation/resources/filterHideInherited.png")), //NOI18N
// null
// );
desc.addFilter(SHOW_INHERITED,
NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowInherited"), //NOI18N
NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowInheritedTip"), //NOI18N
false,
new ImageIcon (ImageUtilities.loadImage("org/netbeans/modules/csl/navigation/resources/filterHideInherited.png")), //NOI18N
null
);
desc.addFilter(SHOW_FIELDS,
NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowFields"), //NOI18N
NbBundle.getMessage(ClassMemberFilters.class, "LBL_ShowFieldsTip"), //NOI18N
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,11 @@ public ElementNode getNodeForOffset(int offset) {
Node[] children = ch.getNodes();
for (int i = 0; i < children.length; i++) {
ElementNode c = (ElementNode) children[i];
if (this.getFileObject() != c.getDescription().getElementHandle().getFileObject()) {
// e.g. inherited items may be in another file
// in such a case, incorrect item is highlighted on the navigator window if the FileObjects are not checked
continue;
}
long start = c.getDescription().getPosition();
if (start <= offset) {
long end = c.getDescription().getEndPosition();
Expand Down
Loading