Refactoring. Cosmetics.

Access level. Final modifiers. Unused parameters... etc.
This commit is contained in:
Pavel V. Talanov
2012-07-27 20:28:48 +04:00
parent 40c14c6533
commit e291c30f82
22 changed files with 40 additions and 39 deletions
@@ -26,7 +26,8 @@ import java.util.List;
* A Config implementation which is configured with a directory to find the standard library names from
*/
public class ClassPathLibraryDefintionsConfig extends Config {
public static final String META_INF_SERVICES_FILE = "META-INF/services/org.jetbrains.kotlin.js.libraryDefinitions";
@NotNull
private static final String META_INF_SERVICES_FILE = "META-INF/services/org.jetbrains.kotlin.js.libraryDefinitions";
public ClassPathLibraryDefintionsConfig(@NotNull Project project, @NotNull String moduleId, @NotNull EcmaVersion version) {
super(project, moduleId, version);
@@ -20,13 +20,14 @@ import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.JetFile;
import java.util.*;
import java.util.List;
/**
* A helper class to load the kotlin library sources to be compiled to JavaScript as part of a JavaScript build
*/
public class ClassPathLibrarySourcesLoader {
public static final String META_INF_SERVICES_FILE = "META-INF/services/org.jetbrains.kotlin.js.librarySource";
@NotNull
private static final String META_INF_SERVICES_FILE = "META-INF/services/org.jetbrains.kotlin.js.librarySource";
@NotNull private final Project project;
public ClassPathLibrarySourcesLoader(@NotNull Project project) {
@@ -39,8 +39,10 @@ import java.util.zip.ZipFile;
* @author Pavel Talanov
*/
public class LibrarySourcesConfig extends Config {
@NotNull
public static final Key<String> EXTERNAL_MODULE_NAME = new Key<String>("externalModule");
public static final String UNKNOWN_EXTERNAL_MODULE_NAME = "<unknown>";
@NotNull
private static final String UNKNOWN_EXTERNAL_MODULE_NAME = "<unknown>";
private static final Logger LOG = Logger.getInstance("#org.jetbrains.jet.asJava.JetLightClass");
@@ -30,7 +30,8 @@ import java.util.Map;
*/
public class AliasingContext {
private static AliasingContext ROOT = new AliasingContext(null) {
@NotNull
private static final AliasingContext ROOT = new AliasingContext(null) {
@Override
public JsName getAliasForThis(@NotNull DeclarationDescriptor descriptor) {
return null;
@@ -53,13 +53,8 @@ public final class DynamicContext {
@NotNull
public TemporaryVariable declareTemporary(@NotNull JsExpression initExpression) {
return declareTemporary(initExpression, false);
}
@NotNull
public TemporaryVariable declareTemporary(@NotNull JsExpression initExpression, boolean initialize) {
JsName temporaryName = currentScope.declareTemporary();
JsVars temporaryDeclaration = newVar(temporaryName, initialize ? initExpression : null);
JsVars temporaryDeclaration = newVar(temporaryName, /*no value for init expression */ null);
addVarDeclaration(jsBlock(), temporaryDeclaration);
return new TemporaryVariable(temporaryName, initExpression);
}
@@ -85,19 +85,23 @@ public final class Namer {
}
}
public static String getKotlinBackingFieldName(String propertyName) {
@NotNull
public static String getKotlinBackingFieldName(@NotNull String propertyName) {
return getNameWithPrefix(propertyName, BACKING_FIELD_PREFIX);
}
public static String getNameForGetter(String propertyName) {
@NotNull
private static String getNameForGetter(@NotNull String propertyName) {
return getNameWithPrefix(propertyName, GETTER_PREFIX);
}
public static String getNameForSetter(String propertyName) {
@NotNull
private static String getNameForSetter(@NotNull String propertyName) {
return getNameWithPrefix(propertyName, SETTER_PREFIX);
}
private static String getNameWithPrefix(String name, String prefix) {
@NotNull
private static String getNameWithPrefix(@NotNull String name, @NotNull String prefix) {
return prefix + name;
}
@@ -157,11 +157,6 @@ public final class TranslationContext {
return dynamicContext.declareTemporary(initExpression);
}
@NotNull
public TemporaryVariable declareTemporary(@NotNull JsExpression initExpression, boolean initialize) {
return dynamicContext.declareTemporary(initExpression, initialize);
}
@NotNull
public Namer namer() {
return staticContext.getNamer();
@@ -40,7 +40,7 @@ public class JetTestFunctionDetector {
private JetTestFunctionDetector() {
}
public static boolean isTest(@NotNull BindingContext bindingContext, @NotNull JetNamedFunction function) {
private static boolean isTest(@NotNull BindingContext bindingContext, @NotNull JetNamedFunction function) {
FunctionDescriptor functionDescriptor = getNullableDescriptorForFunction(bindingContext, function);
if (functionDescriptor == null) {
return false;
@@ -205,6 +205,7 @@ public final class Translation {
namer.exec(program);
}
//TODO: determine whether should throw exception
@Nullable
private static JsStatement generateCallToMain(@NotNull TranslationContext context, @NotNull Collection<JetFile> files,
@NotNull List<String> arguments) throws MainFunctionNotFoundException {
@@ -53,8 +53,8 @@ public final class FunctionIntrinsics {
register(RangesFIF.INSTANCE);
}
private boolean register(@NotNull FunctionIntrinsicFactory instance) {
return factories.add(instance);
private void register(@NotNull FunctionIntrinsicFactory instance) {
factories.add(instance);
}
@NotNull
@@ -51,7 +51,7 @@ public enum PrimitiveUnaryOperationFIF implements FunctionIntrinsicFactory {
private static final DescriptorPredicate UNARY_OPERATION_FOR_PRIMITIVE_NUMBER =
pattern(PRIMITIVE_NUMBERS, UNARY_OPERATIONS);
@NotNull
public static final Predicate<FunctionDescriptor> PRIMITIVE_UNARY_OPERATION_NAMES =
private static final Predicate<FunctionDescriptor> PRIMITIVE_UNARY_OPERATION_NAMES =
Predicates.or(UNARY_OPERATION_FOR_PRIMITIVE_NUMBER, pattern("Boolean.not"));
@NotNull
private static final DescriptorPredicate NO_PARAMETERS = new DescriptorPredicate() {
@@ -62,7 +62,7 @@ public enum PrimitiveUnaryOperationFIF implements FunctionIntrinsicFactory {
}
};
@NotNull
public static final Predicate<FunctionDescriptor> PATTERN = Predicates.and(PRIMITIVE_UNARY_OPERATION_NAMES, NO_PARAMETERS);
private static final Predicate<FunctionDescriptor> PATTERN = Predicates.and(PRIMITIVE_UNARY_OPERATION_NAMES, NO_PARAMETERS);
@NotNull
@Override
@@ -31,7 +31,8 @@ import java.util.List;
*/
public final class PatternBuilder {
public static final NamePredicate JET = new NamePredicate("jet");
@NotNull
private static final NamePredicate JET = new NamePredicate("jet");
private PatternBuilder() {
}
@@ -64,7 +64,7 @@ public final class UnaryOperationTranslator {
@NotNull
private static JsExpression translateExclExclOperator(@NotNull JetUnaryExpression expression, @NotNull TranslationContext context) {
TemporaryVariable cachedValue = context.declareTemporary(translateAsExpression(getBaseExpression(expression), context), false);
TemporaryVariable cachedValue = context.declareTemporary(translateAsExpression(getBaseExpression(expression), context));
JsBinaryOperation initAndCheckNotNull = AstUtil.newSequence(cachedValue.assignmentExpression(),
notNullCheck(context, cachedValue.reference()));
return new JsConditional(initAndCheckNotNull, cachedValue.reference(), context.namer().throwNPEFunctionCall());
@@ -60,7 +60,7 @@ public abstract class AbstractCallExpressionTranslator extends AbstractTranslato
this.callType = type;
}
abstract public boolean shouldWrapVarargInArray();
protected abstract boolean shouldWrapVarargInArray();
@NotNull
protected List<JsExpression> translateSingleArgument(@NotNull ResolvedValueArgument actualArgument,
@@ -26,13 +26,13 @@ import org.jetbrains.annotations.Nullable;
public final class CallParameters {
@Nullable
private JsExpression receiver;
private final JsExpression receiver;
@NotNull
private JsExpression functionReference;
private final JsExpression functionReference;
@Nullable
private JsExpression thisObject;
private final JsExpression thisObject;
public CallParameters(@Nullable JsExpression receiver,
@NotNull JsExpression functionReference,
@@ -56,7 +56,7 @@ public final class CallParametersResolver {
private final ResolvedCall<? extends CallableDescriptor> resolvedCall;
private final boolean isExtensionCall;
public CallParametersResolver(@Nullable JsExpression qualifier,
private CallParametersResolver(@Nullable JsExpression qualifier,
@Nullable JsExpression callee,
@NotNull CallableDescriptor descriptor,
@NotNull ResolvedCall<? extends CallableDescriptor> call,
@@ -84,7 +84,7 @@ public abstract class PropertyAccessTranslator extends AbstractTranslator implem
return canBePropertyGetterCall(selector, context);
}
public static boolean canBePropertyGetterCall(@NotNull JetSimpleNameExpression expression,
private static boolean canBePropertyGetterCall(@NotNull JetSimpleNameExpression expression,
@NotNull TranslationContext context) {
return (getDescriptorForReferenceExpression
(context.bindingContext(), expression) instanceof PropertyDescriptor);
@@ -26,7 +26,8 @@ import org.jetbrains.annotations.NotNull;
*/
public final class JSRhinoUnitTester extends CommonUnitTester {
public static final JsNameRef TEST_FUN_REF = AstUtil.newQualifiedNameRef("JsTests.test");
@NotNull
private static final JsNameRef TEST_FUN_REF = AstUtil.newQualifiedNameRef("JsTests.test");
@NotNull
@Override
@@ -212,6 +212,7 @@ public final class JsDescriptorUtils {
result.add(current);
if (current.getContainingDeclaration() instanceof NamespaceDescriptor) {
current = (NamespaceDescriptor) current.getContainingDeclaration();
//noinspection ConstantConditions
assert current != null;
}
else {
@@ -16,13 +16,11 @@
package org.jetbrains.k2js.translate.utils.closure;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.descriptors.VariableDescriptor;
import java.util.Collection;
import java.util.List;
import java.util.Set;
/**
@@ -31,7 +29,7 @@ import java.util.Set;
public final class ClosureContext {
@NotNull
private Set<VariableDescriptor> descriptors = Sets.newHashSet();
private final Set<VariableDescriptor> descriptors = Sets.newHashSet();
/*package*/ void put(@NotNull VariableDescriptor descriptor) {
descriptors.add(descriptor);
@@ -87,7 +87,7 @@ public class DangerousData {
}
@NotNull
private List<JetExpression> nodesToBeGeneratedBefore = Lists.newArrayList();
private final List<JetExpression> nodesToBeGeneratedBefore = Lists.newArrayList();
@Nullable
private JetExpression dangerousNode = null;
@@ -20,7 +20,6 @@ import com.google.common.collect.Maps;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.jet.lang.psi.*;
import org.jetbrains.k2js.translate.utils.PsiUtils;
import java.util.Map;
@@ -60,6 +59,7 @@ public final class FindPreviousVisitor extends JetTreeVisitor<DangerousData> {
return null;
}
//TODO: return value not used, wtf?
private static boolean addElement(@NotNull JetElement element, @NotNull DangerousData data) {
if (element instanceof JetExpression) {
data.getNodesToBeGeneratedBefore().add((JetExpression)element);