mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
notnull, cleanup
This commit is contained in:
+1
-1
@@ -107,7 +107,7 @@ public static void searchOptimized(final PsiMethod method, SearchScope scope, fi
|
||||
return search(method, true);
|
||||
}
|
||||
|
||||
private static UniqueResultsQuery<PsiReference, ReferenceDescriptor> uniqueResults(Query<PsiReference> composite) {
|
||||
private static UniqueResultsQuery<PsiReference, ReferenceDescriptor> uniqueResults(@NotNull Query<PsiReference> composite) {
|
||||
return new UniqueResultsQuery<PsiReference, ReferenceDescriptor>(composite, ContainerUtil.<ReferenceDescriptor>canonicalStrategy(), ReferenceDescriptor.MAPPER);
|
||||
}
|
||||
}
|
||||
@@ -59,8 +59,9 @@ public abstract class AbstractQuery<Result> implements Query<Result> {
|
||||
assert !myIsProcessing : "Operation is not allowed while query is being processed";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Result[] toArray(Result[] a) {
|
||||
public Result[] toArray(@NotNull Result[] a) {
|
||||
assertNotProcessing();
|
||||
|
||||
final Collection<Result> all = findAll();
|
||||
@@ -80,6 +81,7 @@ public abstract class AbstractQuery<Result> implements Query<Result> {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public AsyncFuture<Boolean> forEachAsync(@NotNull Processor<Result> consumer) {
|
||||
assertNotProcessing();
|
||||
|
||||
@@ -32,23 +32,28 @@ import java.util.Iterator;
|
||||
public class ArrayQuery<T> implements Query<T> {
|
||||
private final T[] myArray;
|
||||
|
||||
public ArrayQuery(final T... array) {
|
||||
public ArrayQuery(@NotNull T... array) {
|
||||
myArray = array;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<T> findAll() {
|
||||
return Arrays.asList(myArray);
|
||||
}
|
||||
|
||||
@Override
|
||||
public T findFirst() {
|
||||
return myArray.length > 0 ? myArray[0] : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forEach(@NotNull final Processor<T> consumer) {
|
||||
return ContainerUtil.process(myArray, consumer);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public AsyncFuture<Boolean> forEachAsync(@NotNull final Processor<T> consumer) {
|
||||
final AsyncFutureResult<Boolean> result = AsyncFutureFactory.getInstance().createAsyncFutureResult();
|
||||
try {
|
||||
@@ -60,10 +65,13 @@ public class ArrayQuery<T> implements Query<T> {
|
||||
}
|
||||
|
||||
|
||||
public T[] toArray(final T[] a) {
|
||||
@NotNull
|
||||
@Override
|
||||
public T[] toArray(@NotNull final T[] a) {
|
||||
return myArray;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return Arrays.asList(myArray).iterator();
|
||||
}
|
||||
|
||||
@@ -52,6 +52,7 @@ public class CollectionQuery<T> implements Query<T> {
|
||||
return ContainerUtil.process(myCollection, consumer);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public AsyncFuture<Boolean> forEachAsync(@NotNull Processor<T> consumer) {
|
||||
AsyncFutureResult<Boolean> result = AsyncFutureFactory.getInstance().createAsyncFutureResult();
|
||||
@@ -63,8 +64,9 @@ public class CollectionQuery<T> implements Query<T> {
|
||||
return result;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public T[] toArray(final T[] a) {
|
||||
public T[] toArray(@NotNull final T[] a) {
|
||||
return findAll().toArray(a);
|
||||
}
|
||||
|
||||
|
||||
@@ -48,11 +48,13 @@ public class FilteredQuery<T> implements Query<T> {
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public AsyncFuture<Boolean> forEachAsync(@NotNull Processor<T> consumer) {
|
||||
return myOriginal.forEachAsync(new MyProcessor(consumer));
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<T> findAll() {
|
||||
CommonProcessors.CollectProcessor<T> processor = new CommonProcessors.CollectProcessor<T>();
|
||||
@@ -60,8 +62,9 @@ public class FilteredQuery<T> implements Query<T> {
|
||||
return processor.getResults();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public T[] toArray(final T[] a) {
|
||||
public T[] toArray(@NotNull final T[] a) {
|
||||
return findAll().toArray(a);
|
||||
}
|
||||
|
||||
@@ -77,6 +80,7 @@ public class FilteredQuery<T> implements Query<T> {
|
||||
myConsumer = consumer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(final T t) {
|
||||
if (!myFilter.value(t)) return true;
|
||||
if (!myConsumer.process(t)) return false;
|
||||
|
||||
@@ -205,7 +205,7 @@ public class IconUtil {
|
||||
final int w = icon.getIconWidth();
|
||||
final int h = icon.getIconHeight();
|
||||
final BufferedImage image = GraphicsEnvironment.getLocalGraphicsEnvironment()
|
||||
.getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(w, h, Color.TRANSLUCENT);
|
||||
.getDefaultScreenDevice().getDefaultConfiguration().createCompatibleImage(w, h, Transparency.TRANSLUCENT);
|
||||
final Graphics2D g = image.createGraphics();
|
||||
icon.paintIcon(null, g, 0, 0);
|
||||
g.dispose();
|
||||
|
||||
@@ -31,6 +31,7 @@ public class InstanceofQuery<T> implements Query<T> {
|
||||
myDelegate = delegate;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<T> findAll() {
|
||||
ArrayList<T> result = new ArrayList<T>();
|
||||
@@ -45,26 +46,32 @@ public class InstanceofQuery<T> implements Query<T> {
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T findFirst() {
|
||||
final CommonProcessors.FindFirstProcessor<T> processor = new CommonProcessors.FindFirstProcessor<T>();
|
||||
forEach(processor);
|
||||
return processor.getFoundValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forEach(@NotNull final Processor<T> consumer) {
|
||||
return myDelegate.forEach(new MyProcessor(consumer));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public AsyncFuture<Boolean> forEachAsync(@NotNull Processor<T> consumer) {
|
||||
return myDelegate.forEachAsync(new MyProcessor(consumer));
|
||||
}
|
||||
|
||||
public T[] toArray(T[] a) {
|
||||
@NotNull
|
||||
@Override
|
||||
public T[] toArray(@NotNull T[] a) {
|
||||
final Collection<T> all = findAll();
|
||||
return all.toArray(a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return new UnmodifiableIterator<T>(findAll().iterator());
|
||||
}
|
||||
@@ -76,6 +83,7 @@ public class InstanceofQuery<T> implements Query<T> {
|
||||
myConsumer = consumer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean process(T o) {
|
||||
for (Class aClass : myClasses) {
|
||||
if (aClass.isInstance(o)) {
|
||||
|
||||
@@ -26,6 +26,7 @@ import java.util.Iterator;
|
||||
*/
|
||||
public abstract class LazyQuery<T> implements Query<T> {
|
||||
private final NotNullLazyValue<Query<T>> myQuery = new NotNullLazyValue<Query<T>>() {
|
||||
@Override
|
||||
@NotNull
|
||||
protected Query<T> compute() {
|
||||
return computeQuery();
|
||||
@@ -34,23 +35,29 @@ public abstract class LazyQuery<T> implements Query<T> {
|
||||
|
||||
@NotNull protected abstract Query<T> computeQuery();
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<T> findAll() {
|
||||
return myQuery.getValue().findAll();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T findFirst() {
|
||||
return myQuery.getValue().findFirst();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forEach(@NotNull final Processor<T> consumer) {
|
||||
return myQuery.getValue().forEach(consumer);
|
||||
}
|
||||
|
||||
public T[] toArray(final T[] a) {
|
||||
@NotNull
|
||||
@Override
|
||||
public T[] toArray(@NotNull final T[] a) {
|
||||
return myQuery.getValue().toArray(a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return myQuery.getValue().iterator();
|
||||
}
|
||||
|
||||
@@ -36,6 +36,7 @@ public class MergeQuery<T> implements Query<T>{
|
||||
myQuery2 = query2;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<T> findAll() {
|
||||
List<T> results = new ArrayList<T>();
|
||||
@@ -43,16 +44,20 @@ public class MergeQuery<T> implements Query<T>{
|
||||
return results;
|
||||
}
|
||||
|
||||
@Override
|
||||
public T findFirst() {
|
||||
final CommonProcessors.FindFirstProcessor<T> processor = new CommonProcessors.FindFirstProcessor<T>();
|
||||
forEach(processor);
|
||||
return processor.getFoundValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean forEach(@NotNull final Processor<T> consumer) {
|
||||
return processSubQuery(consumer, myQuery1) && processSubQuery(consumer, myQuery2);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public AsyncFuture<Boolean> forEachAsync(@NotNull final Processor<T> consumer) {
|
||||
final AsyncFutureResult<Boolean> result = AsyncFutureFactory.getInstance().createAsyncFutureResult();
|
||||
|
||||
@@ -76,6 +81,7 @@ public class MergeQuery<T> implements Query<T>{
|
||||
|
||||
private <V extends T> boolean processSubQuery(final Processor<T> consumer, Query<V> query1) {
|
||||
return query1.forEach(new Processor<V>() {
|
||||
@Override
|
||||
public boolean process(final V t) {
|
||||
return consumer.process(t);
|
||||
}
|
||||
@@ -84,17 +90,21 @@ public class MergeQuery<T> implements Query<T>{
|
||||
|
||||
private <V extends T> AsyncFuture<Boolean> processSubQueryAsync(final Processor<T> consumer, Query<V> query1) {
|
||||
return query1.forEachAsync(new Processor<V>() {
|
||||
@Override
|
||||
public boolean process(final V t) {
|
||||
return consumer.process(t);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public T[] toArray(final T[] a) {
|
||||
@NotNull
|
||||
@Override
|
||||
public T[] toArray(@NotNull final T[] a) {
|
||||
final Collection<T> results = findAll();
|
||||
return results.toArray(a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterator<T> iterator() {
|
||||
return findAll().iterator();
|
||||
}
|
||||
|
||||
@@ -38,18 +38,21 @@ public class PathsList {
|
||||
private final Set<String> myPathSet = new HashSet<String>();
|
||||
|
||||
private static final Function<String, VirtualFile> PATH_TO_LOCAL_VFILE = new NullableFunction<String, VirtualFile>() {
|
||||
@Override
|
||||
public VirtualFile fun(String path) {
|
||||
return StandardFileSystems.local().findFileByPath(path.replace(File.separatorChar, '/'));
|
||||
}
|
||||
};
|
||||
|
||||
private static final Function<VirtualFile, String> LOCAL_PATH = new Function<VirtualFile, String>() {
|
||||
@Override
|
||||
public String fun(VirtualFile file) {
|
||||
return PathUtil.getLocalPath(file);
|
||||
}
|
||||
};
|
||||
|
||||
private static final Function<String, VirtualFile> PATH_TO_DIR = new NullableFunction<String, VirtualFile>() {
|
||||
@Override
|
||||
public VirtualFile fun(String s) {
|
||||
final FileType fileType = FileTypeRegistry.getInstance().getFileTypeByFileName(s);
|
||||
final VirtualFile localFile = PATH_TO_LOCAL_VFILE.fun(s);
|
||||
@@ -98,18 +101,21 @@ public class PathsList {
|
||||
final StringTokenizer tokenizer = new StringTokenizer(path, File.pathSeparator);
|
||||
// in JDK 1.5 StringTokenizer implements Enumeration<Object> rather then Enumeration<String>, need to convert
|
||||
final Enumeration<String> en = new Enumeration<String>() {
|
||||
@Override
|
||||
public boolean hasMoreElements() {
|
||||
return tokenizer.hasMoreElements();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String nextElement() {
|
||||
return (String)tokenizer.nextElement();
|
||||
}
|
||||
};
|
||||
return FilteringIterator.create(iterate(en), new Condition<String>() {
|
||||
@Override
|
||||
public boolean value(String element) {
|
||||
element = element.trim();
|
||||
return element.length() != 0 && !myPathSet.contains(element);
|
||||
return !element.isEmpty() && !myPathSet.contains(element);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -47,7 +47,9 @@ public interface Query<Result> extends Iterable<Result> {
|
||||
*/
|
||||
boolean forEach(@NotNull Processor<Result> consumer);
|
||||
|
||||
@NotNull
|
||||
AsyncFuture<Boolean> forEachAsync(@NotNull Processor<Result> consumer);
|
||||
|
||||
Result[] toArray(Result[] a);
|
||||
@NotNull
|
||||
Result[] toArray(@NotNull Result[] a);
|
||||
}
|
||||
|
||||
@@ -38,6 +38,7 @@ public class QueryFactory<Result, Parameters> {
|
||||
/**
|
||||
* @return query to perform the search. @param parameters of the search
|
||||
*/
|
||||
@NotNull
|
||||
public final Query<Result> createQuery(@NotNull Parameters parameters) {
|
||||
return new ExecutorsQuery<Result, Parameters>(parameters, getExecutors());
|
||||
}
|
||||
@@ -65,7 +66,7 @@ public class QueryFactory<Result, Parameters> {
|
||||
* @param parameters of the search
|
||||
* @param hashingStrategy strategy to factor results
|
||||
*/
|
||||
public final Query<Result> createUniqueResultsQuery(@NotNull Parameters parameters, TObjectHashingStrategy<Result> hashingStrategy) {
|
||||
public final Query<Result> createUniqueResultsQuery(@NotNull Parameters parameters, @NotNull TObjectHashingStrategy<Result> hashingStrategy) {
|
||||
return new UniqueResultsQuery<Result, Result>(createQuery(parameters), hashingStrategy);
|
||||
}
|
||||
|
||||
@@ -76,8 +77,8 @@ public class QueryFactory<Result, Parameters> {
|
||||
* @param mapper function that maps results to their mapping counterparts.
|
||||
*/
|
||||
public final <T> Query<Result> createUniqueResultsQuery(@NotNull Parameters parameters,
|
||||
TObjectHashingStrategy<T> hashingStrategy,
|
||||
Function<Result, T> mapper) {
|
||||
@NotNull TObjectHashingStrategy<T> hashingStrategy,
|
||||
@NotNull Function<Result, T> mapper) {
|
||||
return new UniqueResultsQuery<Result, T>(createQuery(parameters), hashingStrategy, mapper);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,15 +32,15 @@ public class UniqueResultsQuery<T, M> implements Query<T> {
|
||||
private final TObjectHashingStrategy<M> myHashingStrategy;
|
||||
private final Function<T, M> myMapper;
|
||||
|
||||
public UniqueResultsQuery(final Query<T> original) {
|
||||
public UniqueResultsQuery(@NotNull Query<T> original) {
|
||||
this(original, ContainerUtil.<M>canonicalStrategy(), (Function<T, M>)FunctionUtil.<M>id());
|
||||
}
|
||||
|
||||
public UniqueResultsQuery(final Query<T> original, TObjectHashingStrategy<M> hashingStrategy) {
|
||||
public UniqueResultsQuery(@NotNull Query<T> original, @NotNull TObjectHashingStrategy<M> hashingStrategy) {
|
||||
this(original, hashingStrategy, (Function<T, M>)FunctionUtil.<M>id());
|
||||
}
|
||||
|
||||
public UniqueResultsQuery(final Query<T> original, TObjectHashingStrategy<M> hashingStrategy, Function<T, M> mapper) {
|
||||
public UniqueResultsQuery(@NotNull Query<T> original, @NotNull TObjectHashingStrategy<M> hashingStrategy, @NotNull Function<T, M> mapper) {
|
||||
myOriginal = original;
|
||||
myHashingStrategy = hashingStrategy;
|
||||
myMapper = mapper;
|
||||
@@ -56,6 +56,7 @@ public class UniqueResultsQuery<T, M> implements Query<T> {
|
||||
return process(consumer, Collections.synchronizedSet(new THashSet<M>(myHashingStrategy)));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public AsyncFuture<Boolean> forEachAsync(@NotNull Processor<T> consumer) {
|
||||
return processAsync(consumer, Collections.synchronizedSet(new THashSet<M>(myHashingStrategy)));
|
||||
@@ -86,8 +87,9 @@ public class UniqueResultsQuery<T, M> implements Query<T> {
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public T[] toArray(final T[] a) {
|
||||
public T[] toArray(@NotNull final T[] a) {
|
||||
return findAll().toArray(a);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user