Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3209 from matthiasblaesing/indexability_query
Allow plugins to exclude files from being indexed
- Loading branch information
Showing
10 changed files
with
1,360 additions
and
623 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
84 changes: 84 additions & 0 deletions
84
ide/parsing.indexing/src/org/netbeans/modules/parsing/impl/indexing/FilteringIterable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.netbeans.modules.parsing.impl.indexing; | ||
|
||
import java.util.Iterator; | ||
import java.util.NoSuchElementException; | ||
import java.util.function.Function; | ||
|
||
/** | ||
* Iterable wrapping another iterable, yielding an interator, that only offers | ||
* values, for this the supplied filter returns a true value. | ||
*/ | ||
class FilteringIterable<T> implements Iterable<T> { | ||
private final Iterable<? extends T> delegate; | ||
private final Function<T,Boolean> filter; | ||
|
||
public FilteringIterable(Iterable<? extends T> delegate, Function<T,Boolean> filter) { | ||
this.delegate = delegate; | ||
this.filter = filter; | ||
} | ||
|
||
@Override | ||
public Iterator<T> iterator() { | ||
return new FilteringIterator(delegate.iterator(), filter); | ||
} | ||
|
||
private static class FilteringIterator<T> implements Iterator<T> { | ||
private final Iterator<? extends T> delegate; | ||
private final Function<T,Boolean> filter; | ||
|
||
public FilteringIterator(Iterator<? extends T> delegate, Function<T,Boolean> filter) { | ||
this.delegate = delegate; | ||
this.filter = filter; | ||
} | ||
|
||
private T next; | ||
|
||
@Override | ||
public boolean hasNext() { | ||
fillNextIfPossible(); | ||
return next != null; | ||
} | ||
|
||
@Override | ||
public T next() { | ||
fillNextIfPossible(); | ||
if(next == null) { | ||
throw new NoSuchElementException(); | ||
} | ||
T value = next; | ||
next = null; | ||
return value; | ||
} | ||
|
||
private void fillNextIfPossible() { | ||
if (next == null) { | ||
while (delegate.hasNext()) { | ||
T nextCandiate = delegate.next(); | ||
if(filter.apply(nextCandiate)) { | ||
next = nextCandiate; | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
Oops, something went wrong.