Numerous code style fixes.
This commit is contained in:
@@ -107,7 +107,7 @@ public final class AnalyzerFacade {
|
||||
private static final class JsConfiguration implements Configuration {
|
||||
|
||||
@NotNull
|
||||
private Project project;
|
||||
private final Project project;
|
||||
|
||||
public static JsConfiguration jsLibConfiguration(@NotNull Project project) {
|
||||
return new JsConfiguration(project);
|
||||
|
||||
@@ -74,7 +74,7 @@ public final class K2JSTranslator {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Config config;
|
||||
private final Config config;
|
||||
|
||||
|
||||
public K2JSTranslator(@NotNull Config config) {
|
||||
@@ -126,7 +126,7 @@ public final class K2JSTranslator {
|
||||
|
||||
|
||||
@NotNull
|
||||
public String generateCallToMain(@NotNull JetFile file, @NotNull String argumentString) {
|
||||
public static String generateCallToMain(@NotNull JetFile file, @NotNull String argumentString) {
|
||||
String namespaceName = getNamespaceName(file);
|
||||
List<String> arguments = parseString(argumentString);
|
||||
return GenerationUtils.generateCallToMain(namespaceName, arguments);
|
||||
|
||||
@@ -40,8 +40,11 @@ public final class CodeGenerator {
|
||||
public void generateToFile(@NotNull JsProgram program, @NotNull File file) throws IOException {
|
||||
generateCode(program);
|
||||
FileWriter writer = new FileWriter(file);
|
||||
writer.write(output.toString());
|
||||
writer.close();
|
||||
try {
|
||||
writer.write(output.toString());
|
||||
} finally {
|
||||
writer.close();
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -36,13 +36,13 @@ public class DynamicContext {
|
||||
|
||||
//TODO: current/block scope logic unclear. is it necessary?
|
||||
@NotNull
|
||||
private NamingScope currentScope;
|
||||
private final NamingScope currentScope;
|
||||
|
||||
@NotNull
|
||||
private NamingScope blockScope;
|
||||
private final NamingScope blockScope;
|
||||
|
||||
@NotNull
|
||||
private JsBlock currentBlock;
|
||||
private final JsBlock currentBlock;
|
||||
|
||||
private DynamicContext(@NotNull NamingScope scope, @NotNull NamingScope blockScope, @NotNull JsBlock block) {
|
||||
this.currentScope = scope;
|
||||
@@ -55,11 +55,6 @@ public class DynamicContext {
|
||||
return new DynamicContext(currentScope.innerScope(scope), blockScope, currentBlock);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public NamingScope getScope() {
|
||||
return blockScope;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DynamicContext innerBlock(@NotNull JsBlock block) {
|
||||
return new DynamicContext(currentScope, currentScope, block);
|
||||
|
||||
@@ -43,6 +43,7 @@ public final class Namer {
|
||||
private static final String KOTLIN_OBJECT_NAME = "Kotlin";
|
||||
private static final String ANONYMOUS_NAMESPACE = "Anonymous";
|
||||
private static final String RECEIVER_PARAMETER_NAME = "receiver";
|
||||
private static final String CLASSES_OBJECT_NAME = "classes";
|
||||
|
||||
@NotNull
|
||||
public static String getReceiverParameterName() {
|
||||
@@ -66,7 +67,7 @@ public final class Namer {
|
||||
|
||||
@NotNull
|
||||
public static String nameForClassesVariable() {
|
||||
return "classes";
|
||||
return CLASSES_OBJECT_NAME;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -46,6 +46,7 @@ public final class NamingScope {
|
||||
return innerScope(innerJsScope);
|
||||
}
|
||||
|
||||
@SuppressWarnings("MethodMayBeStatic")
|
||||
@NotNull
|
||||
public NamingScope innerScope(@NotNull JsScope correspondingScope) {
|
||||
return new NamingScope(correspondingScope);
|
||||
|
||||
@@ -134,11 +134,6 @@ public final class StaticContext {
|
||||
return rootScope;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public StandardClasses getStandardClasses() {
|
||||
return standardClasses;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public NamingScope getScopeForDescriptor(@NotNull DeclarationDescriptor descriptor) {
|
||||
NamingScope namingScope = scopes.get(descriptor);
|
||||
|
||||
@@ -88,12 +88,6 @@ public final class TranslationContext {
|
||||
return staticContext.getScopeForDescriptor(descriptor);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public NamingScope getScopeForElement(@NotNull PsiElement element) {
|
||||
DeclarationDescriptor descriptorForElement = getDescriptorForElement(bindingContext(), element);
|
||||
return getScopeForDescriptor(descriptorForElement);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsName getNameForElement(@NotNull PsiElement element) {
|
||||
DeclarationDescriptor descriptor = getDescriptorForElement(bindingContext(), element);
|
||||
@@ -135,16 +129,6 @@ public final class TranslationContext {
|
||||
return staticContext.getProgram();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private StandardClasses standardClasses() {
|
||||
return staticContext.getStandardClasses();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public NamingScope getScope() {
|
||||
return dynamicContext.getScope();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsScope jsScope() {
|
||||
return dynamicContext.jsScope();
|
||||
|
||||
+2
-2
@@ -161,7 +161,7 @@ public final class ClassDeclarationTranslator extends AbstractTranslator {
|
||||
@NotNull
|
||||
private JsPropertyInitializer getClassNameToClassObject(@NotNull ClassDescriptor classDescriptor) {
|
||||
JsName className = context().getNameForDescriptor(classDescriptor);
|
||||
JsNameRef alreadyDefinedClassReferernce = qualified(className, getDeclarationsObjectName().makeRef());
|
||||
return new JsPropertyInitializer(className.makeRef(), alreadyDefinedClassReferernce);
|
||||
JsNameRef alreadyDefinedClassReference = qualified(className, getDeclarationsObjectName().makeRef());
|
||||
return new JsPropertyInitializer(className.makeRef(), alreadyDefinedClassReference);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ public final class ClassTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private ClassDescriptor findAndRemoveAncestorClass(@NotNull List<ClassDescriptor> superclassDescriptors) {
|
||||
private static ClassDescriptor findAndRemoveAncestorClass(@NotNull List<ClassDescriptor> superclassDescriptors) {
|
||||
ClassDescriptor ancestorClass = findAncestorClass(superclassDescriptors);
|
||||
superclassDescriptors.remove(ancestorClass);
|
||||
return ancestorClass;
|
||||
|
||||
+2
-2
@@ -61,7 +61,7 @@ public final class ClassInitializerTranslator extends AbstractInitializerTransla
|
||||
//TODO: it's inconsistent that we scope for class and function for constructor, currently have problems implementing better way
|
||||
ConstructorDescriptor primaryConstructor = getConstructor();
|
||||
JsFunction result = context().getFunctionObject(primaryConstructor);
|
||||
//NOTE: while we translate constructor parameters we also add property initializer statements
|
||||
//NOTE: while we doTranslate constructor parameters we also add property initializer statements
|
||||
// for properties declared as constructor parameters
|
||||
setParameters(result, translatePrimaryConstructorParameters());
|
||||
mayBeAddCallToSuperMethod();
|
||||
@@ -91,7 +91,7 @@ public final class ClassInitializerTranslator extends AbstractInitializerTransla
|
||||
}
|
||||
|
||||
private void addCallToSuperMethod(@NotNull JetDelegatorToSuperCall superCall) {
|
||||
//TODO: look into
|
||||
//TODO: can be problematic to maintain
|
||||
JsName superMethodName = initializerMethodScope.jsScope().declareName(Namer.superMethodName());
|
||||
superMethodName.setObfuscatable(false);
|
||||
List<JsExpression> arguments = translateArguments(superCall);
|
||||
|
||||
+7
-19
@@ -18,7 +18,6 @@ package org.jetbrains.k2js.translate.initializer;
|
||||
|
||||
import com.google.dart.compiler.backend.js.ast.JsExpression;
|
||||
import com.google.dart.compiler.backend.js.ast.JsInvocation;
|
||||
import com.google.dart.compiler.backend.js.ast.JsName;
|
||||
import com.google.dart.compiler.backend.js.ast.JsStatement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
@@ -28,8 +27,6 @@ import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
import org.jetbrains.k2js.translate.declaration.ClassTranslator;
|
||||
import org.jetbrains.k2js.translate.general.Translation;
|
||||
import org.jetbrains.k2js.translate.general.TranslatorVisitor;
|
||||
import org.jetbrains.k2js.translate.utils.BindingUtils;
|
||||
import org.jetbrains.k2js.translate.utils.TranslationUtils;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
@@ -37,9 +34,11 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.jetbrains.k2js.translate.general.Translation.translateAsStatement;
|
||||
import static org.jetbrains.k2js.translate.utils.BindingUtils.getDeclarationsForNamespace;
|
||||
import static org.jetbrains.k2js.translate.utils.BindingUtils.getPropertyDescriptorForObjectDeclaration;
|
||||
import static org.jetbrains.k2js.translate.utils.PsiUtils.getObjectDeclarationForName;
|
||||
import static org.jetbrains.k2js.translate.utils.TranslationUtils.assignmentToBackingField;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
@@ -60,26 +59,17 @@ public final class InitializerVisitor extends TranslatorVisitor<List<JsStatement
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JsStatement translateInitializer(@NotNull JetProperty property, @NotNull TranslationContext context,
|
||||
@NotNull JetExpression initializer) {
|
||||
private static JsStatement translateInitializer(@NotNull JetProperty property, @NotNull TranslationContext context,
|
||||
@NotNull JetExpression initializer) {
|
||||
JsExpression initExpression = Translation.translateAsExpression(initializer, context);
|
||||
return assignmentToBackingField(property, initExpression, context);
|
||||
}
|
||||
|
||||
//TODO:
|
||||
@NotNull
|
||||
JsStatement assignmentToBackingField(@NotNull JetProperty property, @NotNull JsExpression initExpression,
|
||||
@NotNull TranslationContext context) {
|
||||
|
||||
PropertyDescriptor propertyDescriptor = BindingUtils.getPropertyDescriptor(context.bindingContext(), property);
|
||||
return TranslationUtils.assignmentToBackingField(context, propertyDescriptor, initExpression);
|
||||
return assignmentToBackingField(context, property, initExpression);
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<JsStatement> visitAnonymousInitializer(@NotNull JetClassInitializer initializer,
|
||||
@NotNull TranslationContext context) {
|
||||
return Arrays.asList(Translation.translateAsStatement(initializer.getBody(), context));
|
||||
return Arrays.asList(translateAsStatement(initializer.getBody(), context));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -95,11 +85,9 @@ public final class InitializerVisitor extends TranslatorVisitor<List<JsStatement
|
||||
@NotNull TranslationContext context) {
|
||||
PropertyDescriptor propertyDescriptorForObjectDeclaration
|
||||
= getPropertyDescriptorForObjectDeclaration(context.bindingContext(), objectName);
|
||||
JsName objectPropertyName = context.getNameForDescriptor(propertyDescriptorForObjectDeclaration);
|
||||
JetObjectDeclaration objectDeclaration = getObjectDeclarationForName(objectName);
|
||||
JsInvocation objectValue = ClassTranslator.generateClassCreationExpression(objectDeclaration, context);
|
||||
return singletonList(TranslationUtils.assignmentToBackingField(context,
|
||||
propertyDescriptorForObjectDeclaration, objectValue));
|
||||
return singletonList(assignmentToBackingField(context, propertyDescriptorForObjectDeclaration, objectValue));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -197,6 +197,7 @@ public final class Intrinsics {
|
||||
return equalsIntrinsics.get(descriptor.getOriginal());
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
private final class IntrinsicDeclarationVisitor extends DeclarationDescriptorVisitor<Void, Void> {
|
||||
|
||||
@Override
|
||||
|
||||
+1
@@ -15,6 +15,7 @@ import static org.jetbrains.k2js.translate.utils.JsAstUtils.setQualifier;
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
//TODO: find should be usages
|
||||
public final class BuiltInPropertyIntrinsic implements Intrinsic {
|
||||
|
||||
@NotNull
|
||||
|
||||
-1
@@ -53,7 +53,6 @@ public final class CallStandardMethodIntrinsic implements Intrinsic {
|
||||
@NotNull TranslationContext context) {
|
||||
assert (receiver != null == receiverShouldBeNotNull);
|
||||
assert arguments.size() == expectedParamsNumber;
|
||||
List<JsExpression> args = composeArguments(receiver, arguments);
|
||||
JsNameRef iteratorFunName = AstUtil.newQualifiedNameRef(methodName);
|
||||
return newInvocation(iteratorFunName, composeArguments(receiver, arguments));
|
||||
}
|
||||
|
||||
+1
@@ -48,6 +48,7 @@ public final class PrimitiveRangeToIntrinsic implements Intrinsic {
|
||||
public JsExpression apply(@Nullable JsExpression rangeStart, @NotNull List<JsExpression> arguments,
|
||||
@NotNull TranslationContext context) {
|
||||
assert arguments.size() == 1 : "RangeTo must have one argument.";
|
||||
assert rangeStart != null;
|
||||
JsExpression rangeEnd = arguments.get(0);
|
||||
JsBinaryOperation rangeSize = sum(subtract(rangeEnd, rangeStart),
|
||||
context.program().getNumberLiteral(1));
|
||||
|
||||
+2
-2
@@ -46,9 +46,9 @@ public abstract class AssignmentTranslator extends AbstractTranslator {
|
||||
public static JsExpression translate(@NotNull JetBinaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
if (isIntrinsicOperation(context, expression)) {
|
||||
return IntrinsicAssignmentTranslator.translate(expression, context);
|
||||
return IntrinsicAssignmentTranslator.doTranslate(expression, context);
|
||||
}
|
||||
return OverloadedAssignmentTranslator.translate(expression, context);
|
||||
return OverloadedAssignmentTranslator.doTranslate(expression, context);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
+5
-4
@@ -46,9 +46,9 @@ public abstract class IncrementTranslator extends AbstractTranslator {
|
||||
public static JsExpression translate(@NotNull JetUnaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
if (isIntrinsicOperation(context, expression)) {
|
||||
return IntrinsicIncrementTranslator.translate(expression, context);
|
||||
return IntrinsicIncrementTranslator.doTranslate(expression, context);
|
||||
}
|
||||
return OverloadedIncrementTranslator.translate(expression, context);
|
||||
return OverloadedIncrementTranslator.doTranslate(expression, context);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -73,7 +73,8 @@ public abstract class IncrementTranslator extends AbstractTranslator {
|
||||
}
|
||||
if (isVariableReassignment) {
|
||||
return asPostfixWithReassignment();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return asPostfixWithNoReassignment();
|
||||
}
|
||||
}
|
||||
@@ -100,7 +101,7 @@ public abstract class IncrementTranslator extends AbstractTranslator {
|
||||
TemporaryVariable t2 = context().declareTemporary(t1.reference());
|
||||
JsExpression variableReassignment = variableReassignment(t1.reference());
|
||||
return AstUtil.newSequence(t1.assignmentExpression(), t2.assignmentExpression(),
|
||||
variableReassignment, t2.reference());
|
||||
variableReassignment, t2.reference());
|
||||
}
|
||||
|
||||
//TODO: TEST
|
||||
|
||||
+3
-3
@@ -36,8 +36,8 @@ public final class IntrinsicAssignmentTranslator extends AssignmentTranslator {
|
||||
|
||||
|
||||
@NotNull
|
||||
public static JsExpression translate(@NotNull JetBinaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
public static JsExpression doTranslate(@NotNull JetBinaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
return (new IntrinsicAssignmentTranslator(expression, context)).translate();
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public final class IntrinsicAssignmentTranslator extends AssignmentTranslator {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected JsExpression translate() {
|
||||
private JsExpression translate() {
|
||||
if (isAssignment(getOperationToken(expression))) {
|
||||
return translateAsPlainAssignment();
|
||||
}
|
||||
|
||||
+5
-4
@@ -35,8 +35,8 @@ public final class IntrinsicIncrementTranslator extends IncrementTranslator {
|
||||
|
||||
|
||||
@NotNull
|
||||
public static JsExpression translate(@NotNull JetUnaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
public static JsExpression doTranslate(@NotNull JetUnaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
return (new IntrinsicIncrementTranslator(expression, context))
|
||||
.translate();
|
||||
}
|
||||
@@ -47,7 +47,7 @@ public final class IntrinsicIncrementTranslator extends IncrementTranslator {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected JsExpression translate() {
|
||||
private JsExpression translate() {
|
||||
if (isPrimitiveExpressionIncrement()) {
|
||||
return jsUnaryExpression();
|
||||
}
|
||||
@@ -64,7 +64,8 @@ public final class IntrinsicIncrementTranslator extends IncrementTranslator {
|
||||
JsExpression getExpression = accessTranslator.translateAsGet();
|
||||
if (isPrefix(expression)) {
|
||||
return new JsPrefixOperation(operator, getExpression);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return new JsPostfixOperation(operator, getExpression);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -35,6 +35,9 @@ public final class OperatorTable {
|
||||
private static final Map<JetToken, JsBinaryOperator> binaryOperatorsMap = new HashMap<JetToken, JsBinaryOperator>();
|
||||
private static final Map<JetToken, JsUnaryOperator> unaryOperatorsMap = new HashMap<JetToken, JsUnaryOperator>();
|
||||
|
||||
private OperatorTable() {
|
||||
}
|
||||
|
||||
static {
|
||||
unaryOperatorsMap.put(JetTokens.PLUSPLUS, JsUnaryOperator.INC); //++
|
||||
unaryOperatorsMap.put(JetTokens.MINUSMINUS, JsUnaryOperator.DEC); //--
|
||||
|
||||
+3
-3
@@ -32,8 +32,8 @@ import static org.jetbrains.k2js.translate.utils.TranslationUtils.getMethodRefer
|
||||
public final class OverloadedAssignmentTranslator extends AssignmentTranslator {
|
||||
|
||||
@NotNull
|
||||
public static JsExpression translate(@NotNull JetBinaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
public static JsExpression doTranslate(@NotNull JetBinaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
return (new OverloadedAssignmentTranslator(expression, context)).translate();
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public final class OverloadedAssignmentTranslator extends AssignmentTranslator {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected JsExpression translate() {
|
||||
private JsExpression translate() {
|
||||
if (isVariableReassignment) {
|
||||
return reassignment();
|
||||
}
|
||||
|
||||
+2
-2
@@ -32,8 +32,8 @@ import static org.jetbrains.k2js.translate.utils.TranslationUtils.getMethodRefer
|
||||
public final class OverloadedIncrementTranslator extends IncrementTranslator {
|
||||
|
||||
@NotNull
|
||||
public static JsExpression translate(@NotNull JetUnaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
public static JsExpression doTranslate(@NotNull JetUnaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
return (new OverloadedIncrementTranslator(expression, context))
|
||||
.translate();
|
||||
}
|
||||
|
||||
+3
@@ -34,6 +34,9 @@ import static org.jetbrains.k2js.translate.utils.BindingUtils.getResolvedCall;
|
||||
|
||||
public final class UnaryOperationTranslator {
|
||||
|
||||
private UnaryOperationTranslator() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsExpression translate(@NotNull JetUnaryExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
|
||||
+1
-1
@@ -125,7 +125,7 @@ public final class CallExpressionTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private List<JsExpression> wrapInArrayLiteral(@NotNull List<JsExpression> translatedArgs) {
|
||||
private static List<JsExpression> wrapInArrayLiteral(@NotNull List<JsExpression> translatedArgs) {
|
||||
JsArrayLiteral argsWrappedInArray = new JsArrayLiteral();
|
||||
argsWrappedInArray.getExpressions().addAll(translatedArgs);
|
||||
return Arrays.<JsExpression>asList(argsWrappedInArray);
|
||||
|
||||
@@ -54,9 +54,9 @@ public final class CallTranslator extends AbstractTranslator {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public /*var*/ JsExpression receiver;
|
||||
public final JsExpression receiver;
|
||||
@NotNull
|
||||
public /*var*/ JsExpression functionReference;
|
||||
public final JsExpression functionReference;
|
||||
}
|
||||
|
||||
//NOTE: receiver may mean this object as well
|
||||
|
||||
+1
-1
@@ -37,7 +37,7 @@ public final class KotlinPropertyAccessTranslator extends PropertyAccessTranslat
|
||||
@NotNull
|
||||
private final PropertyDescriptor propertyDescriptor;
|
||||
@NotNull
|
||||
ResolvedCall<?> resolvedCall;
|
||||
private final ResolvedCall<?> resolvedCall;
|
||||
|
||||
//TODO: too many params in constructor
|
||||
/*package*/ KotlinPropertyAccessTranslator(@NotNull PropertyDescriptor descriptor,
|
||||
|
||||
+11
-9
@@ -39,12 +39,13 @@ import static org.jetbrains.k2js.translate.utils.PsiUtils.isBackingFieldReferenc
|
||||
public abstract class PropertyAccessTranslator extends AccessTranslator {
|
||||
|
||||
@NotNull
|
||||
public static PropertyAccessTranslator newInstance(@NotNull PropertyDescriptor descriptor,
|
||||
@NotNull ResolvedCall<?> resolvedCall,
|
||||
@NotNull TranslationContext context) {
|
||||
private static PropertyAccessTranslator newInstance(@NotNull PropertyDescriptor descriptor,
|
||||
@NotNull ResolvedCall<?> resolvedCall,
|
||||
@NotNull TranslationContext context) {
|
||||
if (isNativeObject(descriptor)) {
|
||||
return new NativePropertyAccessTranslator(descriptor, /*qualifier = */ null, context);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return new KotlinPropertyAccessTranslator(descriptor, /*qualifier = */ null, resolvedCall, context);
|
||||
}
|
||||
}
|
||||
@@ -58,7 +59,8 @@ public abstract class PropertyAccessTranslator extends AccessTranslator {
|
||||
PropertyDescriptor propertyDescriptor = getPropertyDescriptor(expression, context);
|
||||
if (isNativeObject(propertyDescriptor) || isBackingFieldReference(expression)) {
|
||||
result = new NativePropertyAccessTranslator(propertyDescriptor, qualifier, context);
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
ResolvedCall<?> resolvedCall = getResolvedCall(context.bindingContext(), expression);
|
||||
result = new KotlinPropertyAccessTranslator(propertyDescriptor, qualifier, resolvedCall, context);
|
||||
}
|
||||
@@ -67,8 +69,8 @@ public abstract class PropertyAccessTranslator extends AccessTranslator {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
/*package*/ static PropertyDescriptor getPropertyDescriptor(@NotNull JetSimpleNameExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
private static PropertyDescriptor getPropertyDescriptor(@NotNull JetSimpleNameExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
DeclarationDescriptor descriptor =
|
||||
getDescriptorForReferenceExpression(context.bindingContext(), expression);
|
||||
assert descriptor instanceof PropertyDescriptor : "Must be a property descriptor.";
|
||||
@@ -95,8 +97,8 @@ public abstract class PropertyAccessTranslator extends AccessTranslator {
|
||||
}
|
||||
|
||||
|
||||
public static boolean canBePropertyGetterCall(@NotNull JetQualifiedExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
private static boolean canBePropertyGetterCall(@NotNull JetQualifiedExpression expression,
|
||||
@NotNull TranslationContext context) {
|
||||
JetSimpleNameExpression selector = getSelectorAsSimpleName(expression);
|
||||
assert selector != null : "Only names are allowed after the dot";
|
||||
return canBePropertyGetterCall(selector, context);
|
||||
|
||||
@@ -40,8 +40,8 @@ public final class AnnotationsUtils {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getAnnotationStringParameter(@NotNull DeclarationDescriptor declarationDescriptor,
|
||||
@NotNull PredefinedAnnotation annotation) {
|
||||
private static String getAnnotationStringParameter(@NotNull DeclarationDescriptor declarationDescriptor,
|
||||
@NotNull PredefinedAnnotation annotation) {
|
||||
AnnotationDescriptor annotationDescriptor = getAnnotationByName(declarationDescriptor, annotation);
|
||||
assert annotationDescriptor != null;
|
||||
//TODO: this is a quick fix for unsupported default args problem
|
||||
@@ -68,8 +68,8 @@ public final class AnnotationsUtils {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static AnnotationDescriptor getAnnotationByName(@NotNull DeclarationDescriptor descriptor,
|
||||
@NotNull PredefinedAnnotation annotation) {
|
||||
private static AnnotationDescriptor getAnnotationByName(@NotNull DeclarationDescriptor descriptor,
|
||||
@NotNull PredefinedAnnotation annotation) {
|
||||
for (AnnotationDescriptor annotationDescriptor : descriptor.getAnnotations()) {
|
||||
String annotationClassFQName = getAnnotationClassFQName(annotationDescriptor);
|
||||
if (annotationClassFQName.equals(annotation.getFQName())) {
|
||||
|
||||
@@ -98,7 +98,7 @@ public final class ClassSorter {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isDerivedClass(@NotNull ClassDescriptor ancestor, @NotNull ClassDescriptor derived) {
|
||||
private static boolean isDerivedClass(@NotNull ClassDescriptor ancestor, @NotNull ClassDescriptor derived) {
|
||||
return (getSuperclassDescriptors(derived).contains(ancestor));
|
||||
}
|
||||
|
||||
|
||||
@@ -67,16 +67,17 @@ public final class DescriptorUtils {
|
||||
Set<FunctionDescriptor> functionDescriptors = scope.getFunctions(name);
|
||||
assert functionDescriptors.size() == 1 :
|
||||
"In scope " + scope + " supposed to be exactly one " + name + " function.\n" +
|
||||
"Found: " + functionDescriptors.size();
|
||||
"Found: " + functionDescriptors.size();
|
||||
//noinspection LoopStatementThatDoesntLoop
|
||||
for (FunctionDescriptor descriptor : functionDescriptors) {
|
||||
return descriptor;
|
||||
}
|
||||
throw new AssertionError("In scope " + scope
|
||||
+ " supposed to be exactly one " + name + " function.");
|
||||
+ " supposed to be exactly one " + name + " function.");
|
||||
}
|
||||
|
||||
//TODO: some stange stuff happening to this method
|
||||
//TODO: some strange stuff happening to this method
|
||||
//TODO: inspect
|
||||
@NotNull
|
||||
public static PropertyDescriptor getPropertyByName(@NotNull JetScope scope,
|
||||
@NotNull String name) {
|
||||
@@ -156,7 +157,7 @@ public final class DescriptorUtils {
|
||||
@NotNull
|
||||
public static String getNameForNamespace(@NotNull NamespaceDescriptor descriptor) {
|
||||
String name = descriptor.getName();
|
||||
if (name.equals("")) {
|
||||
if (name.isEmpty()) {
|
||||
return Namer.getAnonymousNamespaceName();
|
||||
}
|
||||
return name;
|
||||
|
||||
@@ -211,7 +211,7 @@ public final class JsAstUtils {
|
||||
setStatements(block, statementLinkedList);
|
||||
}
|
||||
|
||||
public static void setStatements(@NotNull JsBlock block, @NotNull List<JsStatement> statements) {
|
||||
private static void setStatements(@NotNull JsBlock block, @NotNull List<JsStatement> statements) {
|
||||
List<JsStatement> statementList = block.getStatements();
|
||||
statementList.clear();
|
||||
statementList.addAll(statements);
|
||||
|
||||
@@ -32,7 +32,7 @@ public enum PredefinedAnnotation {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private String fqName;
|
||||
private final String fqName;
|
||||
|
||||
@NotNull
|
||||
public String getFQName() {
|
||||
|
||||
@@ -148,7 +148,7 @@ public final class PsiUtils {
|
||||
JetNamespaceHeader namespaceHeader = psiFile.getNamespaceHeader();
|
||||
String name = namespaceHeader.getName();
|
||||
assert name != null : "NamespaceHeader must have a name";
|
||||
if (name.equals("")) {
|
||||
if (name.isEmpty()) {
|
||||
return Namer.getAnonymousNamespaceName();
|
||||
}
|
||||
return name;
|
||||
|
||||
@@ -221,4 +221,12 @@ public final class TranslationUtils {
|
||||
JsExpression right = translateRightExpression(context, binaryExpression);
|
||||
return intrinsic.apply(left, Arrays.asList(right), context);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JsStatement assignmentToBackingField(@NotNull TranslationContext context, @NotNull JetProperty property,
|
||||
@NotNull JsExpression initExpression) {
|
||||
|
||||
PropertyDescriptor propertyDescriptor = getPropertyDescriptor(context.bindingContext(), property);
|
||||
return assignmentToBackingField(context, propertyDescriptor, initExpression);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,6 +27,9 @@ import java.util.List;
|
||||
*/
|
||||
public final class GenerationUtils {
|
||||
|
||||
private GenerationUtils() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String generateCallToMain(@NotNull String namespaceName, @NotNull List<String> arguments) {
|
||||
String constructArguments = "var args = [];\n";
|
||||
|
||||
@@ -38,8 +38,11 @@ import java.util.List;
|
||||
*/
|
||||
public final class JetFileUtils {
|
||||
|
||||
private JetFileUtils() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String loadFile(@NotNull String path) throws IOException {
|
||||
private static String loadFile(@NotNull String path) throws IOException {
|
||||
return doLoadFile(path);
|
||||
}
|
||||
|
||||
@@ -58,7 +61,7 @@ public final class JetFileUtils {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetFile loadPsiFile(@NotNull String name, @NotNull Project project) {
|
||||
private static JetFile loadPsiFile(@NotNull String name, @NotNull Project project) {
|
||||
try {
|
||||
return createPsiFile(name, loadFile(name), project);
|
||||
} catch (IOException e) {
|
||||
@@ -82,7 +85,7 @@ public final class JetFileUtils {
|
||||
@NotNull Project project) {
|
||||
List<JetFile> psiFiles = new ArrayList<JetFile>();
|
||||
for (String inputFile : inputFiles) {
|
||||
psiFiles.add(JetFileUtils.loadPsiFile(inputFile, project));
|
||||
psiFiles.add(loadPsiFile(inputFile, project));
|
||||
}
|
||||
return psiFiles;
|
||||
}
|
||||
|
||||
@@ -16,21 +16,12 @@
|
||||
|
||||
package org.jetbrains.k2js.utils;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.StandardConfiguration;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.diagnostics.Severity;
|
||||
import org.jetbrains.jet.lang.diagnostics.UnresolvedReferenceDiagnostic;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.AnalyzingUtils;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.BindingTraceContext;
|
||||
import org.jetbrains.jet.util.slicedmap.ReadOnlySlice;
|
||||
import org.jetbrains.jet.util.slicedmap.SlicedMap;
|
||||
import org.jetbrains.jet.util.slicedmap.WritableSlice;
|
||||
@@ -44,9 +35,9 @@ import java.util.Collections;
|
||||
* @author abreslav
|
||||
*/
|
||||
public class JetTestUtils {
|
||||
public static final BindingTrace DUMMY_TRACE = new BindingTrace() {
|
||||
|
||||
|
||||
private static final BindingTrace DUMMY_TRACE = new BindingTrace() {
|
||||
@Override
|
||||
public BindingContext getBindingContext() {
|
||||
return new BindingContext() {
|
||||
@@ -149,8 +140,11 @@ public class JetTestUtils {
|
||||
}
|
||||
};
|
||||
|
||||
private JetTestUtils() {
|
||||
}
|
||||
|
||||
public static void mkdirs(File file) throws IOException {
|
||||
|
||||
private static void mkdirs(File file) throws IOException {
|
||||
if (file.isDirectory()) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user