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