Move utilities from 'frontend' to 'util'

They're also used in 'serialization'
This commit is contained in:
Alexander Udalov
2013-09-17 23:06:43 +04:00
parent 3504246983
commit 43596f7450
19 changed files with 30 additions and 22 deletions
@@ -30,7 +30,7 @@ import org.jetbrains.jet.lang.types.*;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.renderer.DescriptorRenderer;
import org.jetbrains.jet.util.lazy.RecursionIntolerantLazyValue;
import org.jetbrains.jet.utils.RecursionIntolerantLazyValue;
import java.util.Collections;
import java.util.List;
@@ -47,8 +47,8 @@ import org.jetbrains.jet.lang.types.expressions.LabelResolver;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.util.Box;
import org.jetbrains.jet.util.lazy.ReenteringLazyValueComputationException;
import org.jetbrains.jet.util.slicedmap.WritableSlice;
import org.jetbrains.jet.utils.ReenteringLazyValueComputationException;
import javax.inject.Inject;
import java.util.*;
@@ -42,8 +42,8 @@ import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.lexer.JetKeywordToken;
import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.util.lazy.RecursionIntolerantLazyValue;
import org.jetbrains.jet.util.lazy.RecursionIntolerantLazyValueWithDefault;
import org.jetbrains.jet.util.RecursionIntolerantLazyValueWithDefault;
import org.jetbrains.jet.utils.RecursionIntolerantLazyValue;
import javax.inject.Inject;
import java.util.*;
@@ -39,7 +39,7 @@ import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.util.CommonSuppliers;
import org.jetbrains.jet.utils.CommonSuppliers;
import javax.inject.Inject;
import java.util.*;
@@ -25,7 +25,7 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.resolve.scopes.LazyScopeAdapter;
import org.jetbrains.jet.lang.types.*;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.util.lazy.RecursionIntolerantLazyValue;
import org.jetbrains.jet.utils.RecursionIntolerantLazyValue;
import javax.inject.Inject;
import java.util.ArrayList;
@@ -21,7 +21,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.TypeUtils;
import org.jetbrains.jet.util.CommonSuppliers;
import org.jetbrains.jet.utils.CommonSuppliers;
import java.util.*;
@@ -35,7 +35,7 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.DeferredType;
import org.jetbrains.jet.lang.types.JetType;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.util.lazy.RecursionIntolerantLazyValue;
import org.jetbrains.jet.utils.RecursionIntolerantLazyValue;
import java.util.Collection;
import java.util.Collections;
@@ -17,7 +17,7 @@
package org.jetbrains.jet.lang.resolve.scopes;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.util.lazy.RecursionIntolerantLazyValue;
import org.jetbrains.jet.utils.RecursionIntolerantLazyValue;
public class LazyScopeAdapter extends AbstractScopeAdapter {
@@ -23,7 +23,7 @@ import org.jetbrains.jet.lang.descriptors.*;
import org.jetbrains.jet.lang.resolve.name.LabelName;
import org.jetbrains.jet.lang.resolve.name.Name;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.util.CommonSuppliers;
import org.jetbrains.jet.utils.CommonSuppliers;
import java.util.*;
@@ -21,8 +21,8 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
import org.jetbrains.jet.lang.resolve.BindingTrace;
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.util.Box;
import org.jetbrains.jet.util.lazy.RecursionIntolerantLazyValue;
import org.jetbrains.jet.util.lazy.ReenteringLazyValueComputationException;
import org.jetbrains.jet.utils.RecursionIntolerantLazyValue;
import org.jetbrains.jet.utils.ReenteringLazyValueComputationException;
import java.util.List;
@@ -22,7 +22,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.util.CommonSuppliers;
import org.jetbrains.jet.utils.CommonSuppliers;
import java.util.HashMap;
import java.util.Iterator;
@@ -33,7 +33,7 @@ import org.jetbrains.jet.lang.resolve.scopes.JetScope;
import org.jetbrains.jet.lang.types.*;
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
import org.jetbrains.jet.util.lazy.RecursionIntolerantLazyValueWithDefault;
import org.jetbrains.jet.util.RecursionIntolerantLazyValueWithDefault;
import org.jetbrains.jet.util.slicedmap.WritableSlice;
import java.util.Collection;
@@ -27,7 +27,7 @@ import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
import org.jetbrains.jet.lang.types.DeferredType;
import org.jetbrains.jet.lang.types.ErrorUtils;
import org.jetbrains.jet.lang.types.JetTypeInfo;
import org.jetbrains.jet.util.lazy.ReenteringLazyValueComputationException;
import org.jetbrains.jet.utils.ReenteringLazyValueComputationException;
import static org.jetbrains.jet.lang.diagnostics.Errors.TYPECHECKER_HAS_RUN_INTO_RECURSIVE_PROBLEM;
@@ -1,68 +0,0 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed 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.jetbrains.jet.util;
import com.google.common.base.Supplier;
import com.google.common.collect.*;
import java.util.Collection;
import java.util.List;
import java.util.Set;
public class CommonSuppliers {
private CommonSuppliers() {}
private static final Supplier<?> ARRAY_LIST_SUPPLIER = new Supplier() {
@Override
public List get() {
return Lists.newArrayList();
}
};
private static final Supplier<?> LINKED_HASH_SET_SUPPLIER = new Supplier() {
@Override
public Set get() {
return Sets.newLinkedHashSet();
}
};
private static final Supplier<?> HASH_SET_SUPPLIER = new Supplier() {
@Override
public Set get() {
return Sets.newHashSet();
}
};
public static <T> Supplier<List<T>> getArrayListSupplier() {
//noinspection unchecked
return (Supplier<List<T>>) ARRAY_LIST_SUPPLIER;
}
public static <T> Supplier<Set<T>> getLinkedHashSetSupplier() {
//noinspection unchecked
return (Supplier<Set<T>>) LINKED_HASH_SET_SUPPLIER;
}
public static <T> Supplier<Set<T>> getHashSetSupplier() {
//noinspection unchecked
return (Supplier<Set<T>>) HASH_SET_SUPPLIER;
}
public static <K, V> SetMultimap<K, V> newLinkedHashSetHashSetMultimap() {
return Multimaps.newSetMultimap(Maps.<K, Collection<V>>newHashMap(), CommonSuppliers.<V>getLinkedHashSetSupplier());
}
}
@@ -14,7 +14,9 @@
* limitations under the License.
*/
package org.jetbrains.jet.util.lazy;
package org.jetbrains.jet.util;
import org.jetbrains.jet.utils.RecursionIntolerantLazyValue;
public abstract class RecursionIntolerantLazyValueWithDefault<T> extends RecursionIntolerantLazyValue<T> {
private final T defaultValue;
@@ -1,61 +0,0 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed 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.jetbrains.jet.util.lazy;
public abstract class RecursionIntolerantLazyValue<T> {
private enum State {
NOT_COMPUTED,
BEING_COMPUTED,
COMPUTED,
ERROR
}
private State state = State.NOT_COMPUTED;
private T value;
protected abstract T compute();
protected T getValueOnErrorReentry() {
throw new ReenteringLazyValueComputationException();
}
public boolean isComputed() {
return state == State.ERROR || state == State.COMPUTED;
}
public final T get() {
switch (state) {
case NOT_COMPUTED:
state = State.BEING_COMPUTED;
value = compute();
state = State.COMPUTED;
return value;
case BEING_COMPUTED:
state = State.ERROR;
throw new ReenteringLazyValueComputationException();
case COMPUTED:
return value;
case ERROR:
return getValueOnErrorReentry();
}
throw new IllegalStateException("Unreachable");
}
}
@@ -1,27 +0,0 @@
/*
* Copyright 2010-2013 JetBrains s.r.o.
*
* Licensed 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.jetbrains.jet.util.lazy;
public class ReenteringLazyValueComputationException extends RuntimeException {
public ReenteringLazyValueComputationException() {
}
@Override
public synchronized Throwable fillInStackTrace() {
return this;
}
}
@@ -21,7 +21,7 @@ import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.Multimaps;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.util.CommonSuppliers;
import org.jetbrains.jet.utils.CommonSuppliers;
import java.util.Collection;
import java.util.HashMap;