Drop unused stuff in *Utils.
Adapted from https://github.com/develar/kotlin/commit/a9e0a42fb1347fa8e21c86b5a073ef8a7c873da0.
This commit is contained in:
@@ -112,15 +112,6 @@ public final class AnnotationsUtils {
|
|||||||
return hasAnnotationOrInsideAnnotatedClass(descriptor, PredefinedAnnotation.LIBRARY);
|
return hasAnnotationOrInsideAnnotatedClass(descriptor, PredefinedAnnotation.LIBRARY);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isPredefinedObject(@NotNull DeclarationDescriptor descriptor) {
|
|
||||||
for (PredefinedAnnotation annotation : PredefinedAnnotation.values()) {
|
|
||||||
if (hasAnnotationOrInsideAnnotatedClass(descriptor, annotation)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean hasAnnotationOrInsideAnnotatedClass(@NotNull DeclarationDescriptor descriptor,
|
public static boolean hasAnnotationOrInsideAnnotatedClass(@NotNull DeclarationDescriptor descriptor,
|
||||||
@NotNull PredefinedAnnotation annotation) {
|
@NotNull PredefinedAnnotation annotation) {
|
||||||
return hasAnnotationOrInsideAnnotatedClass(descriptor, annotation.getFQName());
|
return hasAnnotationOrInsideAnnotatedClass(descriptor, annotation.getFQName());
|
||||||
|
|||||||
@@ -17,7 +17,6 @@
|
|||||||
package org.jetbrains.k2js.translate.utils;
|
package org.jetbrains.k2js.translate.utils;
|
||||||
|
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.util.containers.OrderedSet;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
@@ -30,16 +29,11 @@ import org.jetbrains.jet.lang.resolve.calls.VariableAsFunctionResolvedCall;
|
|||||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||||
import org.jetbrains.jet.lang.types.JetType;
|
import org.jetbrains.jet.lang.types.JetType;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collection;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import static org.jetbrains.jet.lang.resolve.BindingContext.INDEXED_LVALUE_GET;
|
import static org.jetbrains.jet.lang.resolve.BindingContext.INDEXED_LVALUE_GET;
|
||||||
import static org.jetbrains.jet.lang.resolve.BindingContext.INDEXED_LVALUE_SET;
|
import static org.jetbrains.jet.lang.resolve.BindingContext.INDEXED_LVALUE_SET;
|
||||||
import static org.jetbrains.k2js.translate.utils.ErrorReportingUtils.message;
|
import static org.jetbrains.k2js.translate.utils.ErrorReportingUtils.message;
|
||||||
import static org.jetbrains.k2js.translate.utils.JsDescriptorUtils.getContainedDescriptorsWhichAreNotPredefined;
|
|
||||||
import static org.jetbrains.k2js.translate.utils.JsDescriptorUtils.getNamespaceDescriptorHierarchy;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Pavel Talanov
|
* @author Pavel Talanov
|
||||||
@@ -69,15 +63,6 @@ public final class BindingUtils {
|
|||||||
return getDescriptorForExpression(context, declaration, ClassDescriptor.class);
|
return getDescriptorForExpression(context, declaration, ClassDescriptor.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static NamespaceDescriptor getNamespaceDescriptor(@NotNull BindingContext context,
|
|
||||||
@NotNull JetFile declaration) {
|
|
||||||
NamespaceDescriptor namespaceDescriptor =
|
|
||||||
context.get(BindingContext.FQNAME_TO_NAMESPACE_DESCRIPTOR, JetPsiUtil.getFQName(declaration));
|
|
||||||
assert namespaceDescriptor != null : message(declaration, "File should have a namespace descriptor");
|
|
||||||
return namespaceDescriptor;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static FunctionDescriptor getFunctionDescriptor(@NotNull BindingContext context,
|
public static FunctionDescriptor getFunctionDescriptor(@NotNull BindingContext context,
|
||||||
@NotNull JetDeclarationWithBody declaration) {
|
@NotNull JetDeclarationWithBody declaration) {
|
||||||
@@ -90,14 +75,6 @@ public final class BindingUtils {
|
|||||||
return getDescriptorForExpression(context, declaration, PropertyDescriptor.class);
|
return getDescriptorForExpression(context, declaration, PropertyDescriptor.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static JetClass getClassForDescriptor(@NotNull BindingContext context,
|
|
||||||
@NotNull ClassDescriptor descriptor) {
|
|
||||||
PsiElement result = BindingContextUtils.classDescriptorToDeclaration(context, descriptor);
|
|
||||||
assert result instanceof JetClass : message(context, descriptor, "JetClass not found for " + descriptor);
|
|
||||||
return (JetClass) result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JetFunction getFunctionForDescriptor(@NotNull BindingContext context,
|
public static JetFunction getFunctionForDescriptor(@NotNull BindingContext context,
|
||||||
@NotNull SimpleFunctionDescriptor descriptor) {
|
@NotNull SimpleFunctionDescriptor descriptor) {
|
||||||
@@ -107,34 +84,6 @@ public final class BindingUtils {
|
|||||||
return (JetFunction) result;
|
return (JetFunction) result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static List<JetDeclaration> getDeclarationsForNamespace(@NotNull BindingContext bindingContext,
|
|
||||||
@NotNull NamespaceDescriptor namespace) {
|
|
||||||
List<JetDeclaration> declarations = new ArrayList<JetDeclaration>();
|
|
||||||
for (DeclarationDescriptor descriptor : getContainedDescriptorsWhichAreNotPredefined(namespace, bindingContext)) {
|
|
||||||
if (descriptor instanceof NamespaceDescriptor) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
JetDeclaration declaration = getDeclarationForDescriptor(bindingContext, descriptor);
|
|
||||||
if (declaration != null) {
|
|
||||||
declarations.add(declaration);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return declarations;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private static JetDeclaration getDeclarationForDescriptor(@NotNull BindingContext context,
|
|
||||||
@NotNull DeclarationDescriptor descriptor) {
|
|
||||||
PsiElement result = BindingContextUtils.descriptorToDeclaration(context, descriptor);
|
|
||||||
if (result == null) {
|
|
||||||
//TODO: never get there
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
assert result instanceof JetDeclaration : message(context, descriptor, "Descriptor should correspond to an element");
|
|
||||||
return (JetDeclaration) result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private static JetParameter getParameterForDescriptor(@NotNull BindingContext context,
|
private static JetParameter getParameterForDescriptor(@NotNull BindingContext context,
|
||||||
@NotNull ValueParameterDescriptor descriptor) {
|
@NotNull ValueParameterDescriptor descriptor) {
|
||||||
@@ -176,16 +125,6 @@ public final class BindingUtils {
|
|||||||
return context.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, parameter);
|
return context.get(BindingContext.PRIMARY_CONSTRUCTOR_PARAMETER, parameter);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static JetProperty getPropertyForDescriptor(@NotNull BindingContext context,
|
|
||||||
@NotNull PropertyDescriptor property) {
|
|
||||||
PsiElement result = BindingContextUtils.descriptorToDeclaration(context, property);
|
|
||||||
if (!(result instanceof JetProperty)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
return (JetProperty) result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static DeclarationDescriptor getDescriptorForReferenceExpression(@NotNull BindingContext context,
|
public static DeclarationDescriptor getDescriptorForReferenceExpression(@NotNull BindingContext context,
|
||||||
@NotNull JetReferenceExpression reference) {
|
@NotNull JetReferenceExpression reference) {
|
||||||
@@ -327,20 +266,6 @@ public final class BindingUtils {
|
|||||||
return propertyDescriptor;
|
return propertyDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static Set<NamespaceDescriptor> getAllNonNativeNamespaceDescriptors(@NotNull BindingContext context,
|
|
||||||
@NotNull Collection<JetFile> files) {
|
|
||||||
Set<NamespaceDescriptor> descriptorSet = new OrderedSet<NamespaceDescriptor>();
|
|
||||||
for (JetFile file : files) {
|
|
||||||
//TODO: can't be
|
|
||||||
NamespaceDescriptor namespaceDescriptor = getNamespaceDescriptor(context, file);
|
|
||||||
if (!AnnotationsUtils.isPredefinedObject(namespaceDescriptor)) {
|
|
||||||
descriptorSet.addAll(getNamespaceDescriptorHierarchy(namespaceDescriptor));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return descriptorSet;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JetType getTypeForExpression(@NotNull BindingContext context,
|
public static JetType getTypeForExpression(@NotNull BindingContext context,
|
||||||
@NotNull JetExpression expression) {
|
@NotNull JetExpression expression) {
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
|
|
||||||
package org.jetbrains.k2js.translate.utils;
|
package org.jetbrains.k2js.translate.utils;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.google.dart.compiler.backend.js.ast.*;
|
import com.google.dart.compiler.backend.js.ast.*;
|
||||||
import com.intellij.util.SmartList;
|
import com.intellij.util.SmartList;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
@@ -28,7 +27,6 @@ import org.jetbrains.k2js.translate.context.TranslationContext;
|
|||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -52,18 +50,12 @@ public final class JsAstUtils {
|
|||||||
private JsAstUtils() {
|
private JsAstUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static JsPropertyInitializer newNamedMethod(@NotNull JsName name, @NotNull JsFunction function) {
|
|
||||||
JsNameRef methodName = name.makeRef();
|
|
||||||
return new JsPropertyInitializer(methodName, function);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JsStatement convertToStatement(@NotNull JsNode jsNode) {
|
public static JsStatement convertToStatement(@NotNull JsNode jsNode) {
|
||||||
assert (jsNode instanceof JsExpression) || (jsNode instanceof JsStatement)
|
assert (jsNode instanceof JsExpression) || (jsNode instanceof JsStatement)
|
||||||
: "Unexpected node of type: " + jsNode.getClass().toString();
|
: "Unexpected node of type: " + jsNode.getClass().toString();
|
||||||
if (jsNode instanceof JsExpression) {
|
if (jsNode instanceof JsExpression) {
|
||||||
return new JsExprStmt((JsExpression) jsNode);
|
return ((JsExpression) jsNode).makeStmt();
|
||||||
}
|
}
|
||||||
return (JsStatement) jsNode;
|
return (JsStatement) jsNode;
|
||||||
}
|
}
|
||||||
@@ -73,8 +65,7 @@ public final class JsAstUtils {
|
|||||||
if (jsNode instanceof JsBlock) {
|
if (jsNode instanceof JsBlock) {
|
||||||
return (JsBlock) jsNode;
|
return (JsBlock) jsNode;
|
||||||
}
|
}
|
||||||
JsStatement jsStatement = convertToStatement(jsNode);
|
return new JsBlock(convertToStatement(jsNode));
|
||||||
return new JsBlock(jsStatement);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -83,19 +74,6 @@ public final class JsAstUtils {
|
|||||||
return (JsExpression) jsNode;
|
return (JsExpression) jsNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsNameRef thisQualifiedReference(@NotNull JsName name) {
|
|
||||||
JsNameRef result = name.makeRef();
|
|
||||||
result.setQualifier(JsLiteral.THIS);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static JsBlock newBlock(List<JsStatement> statements) {
|
|
||||||
JsBlock result = new JsBlock();
|
|
||||||
setStatements(result, statements);
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JsPrefixOperation negated(@NotNull JsExpression expression) {
|
public static JsPrefixOperation negated(@NotNull JsExpression expression) {
|
||||||
return new JsPrefixOperation(JsUnaryOperator.NOT, expression);
|
return new JsPrefixOperation(JsUnaryOperator.NOT, expression);
|
||||||
@@ -130,12 +108,6 @@ public final class JsAstUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static JsNameRef qualified(@NotNull JsName selector, @Nullable JsExpression qualifier) {
|
|
||||||
JsNameRef reference = selector.makeRef();
|
|
||||||
setQualifier(reference, qualifier);
|
|
||||||
return reference;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JsBinaryOperation equality(@NotNull JsExpression arg1, @NotNull JsExpression arg2) {
|
public static JsBinaryOperation equality(@NotNull JsExpression arg1, @NotNull JsExpression arg2) {
|
||||||
return new JsBinaryOperation(JsBinaryOperator.REF_EQ, arg1, arg2);
|
return new JsBinaryOperation(JsBinaryOperator.REF_EQ, arg1, arg2);
|
||||||
@@ -186,28 +158,15 @@ public final class JsAstUtils {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static JsObjectLiteral newObjectLiteral(@NotNull List<JsPropertyInitializer> propertyList) {
|
|
||||||
JsObjectLiteral jsObjectLiteral = new JsObjectLiteral();
|
|
||||||
jsObjectLiteral.getPropertyInitializers().addAll(propertyList);
|
|
||||||
return jsObjectLiteral;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JsVars newVar(@NotNull JsName name, @Nullable JsExpression expr) {
|
public static JsVars newVar(@NotNull JsName name, @Nullable JsExpression expr) {
|
||||||
return new JsVars(new JsVars.JsVar(name, expr));
|
return new JsVars(new JsVars.JsVar(name, expr));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void addVarDeclaration(@NotNull JsBlock block, @NotNull JsVars vars) {
|
public static void setArguments(@NotNull JsInvocation invocation, @NotNull List<JsExpression> newArgs) {
|
||||||
LinkedList<JsStatement> statementLinkedList = Lists.newLinkedList(block.getStatements());
|
List<JsExpression> arguments = invocation.getArguments();
|
||||||
statementLinkedList.offer(vars);
|
assert arguments.isEmpty() : "Arguments already set.";
|
||||||
setStatements(block, statementLinkedList);
|
arguments.addAll(newArgs);
|
||||||
}
|
|
||||||
|
|
||||||
private static void setStatements(@NotNull JsBlock block, @NotNull List<JsStatement> statements) {
|
|
||||||
List<JsStatement> statementList = block.getStatements();
|
|
||||||
statementList.clear();
|
|
||||||
statementList.addAll(statements);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setArguments(@NotNull HasArguments invocation, @NotNull List<JsExpression> newArgs) {
|
public static void setArguments(@NotNull HasArguments invocation, @NotNull List<JsExpression> newArgs) {
|
||||||
@@ -226,20 +185,6 @@ public final class JsAstUtils {
|
|||||||
parameters.addAll(newParams);
|
parameters.addAll(newParams);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setParameters(@NotNull JsFunction function, JsParameter... arguments) {
|
|
||||||
setParameters(function, Arrays.asList(arguments));
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static JsInvocation newInvocation(@NotNull JsExpression target, List<JsExpression> params) {
|
|
||||||
JsInvocation invoke = new JsInvocation();
|
|
||||||
invoke.setQualifier(target);
|
|
||||||
for (JsExpression expr : params) {
|
|
||||||
invoke.getArguments().add(expr);
|
|
||||||
}
|
|
||||||
return invoke;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JsExpression newSequence(@NotNull List<JsExpression> expressions) {
|
public static JsExpression newSequence(@NotNull List<JsExpression> expressions) {
|
||||||
assert !expressions.isEmpty();
|
assert !expressions.isEmpty();
|
||||||
@@ -255,9 +200,7 @@ public final class JsAstUtils {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JsFunction createFunctionWithEmptyBody(@NotNull JsScope parent) {
|
public static JsFunction createFunctionWithEmptyBody(@NotNull JsScope parent) {
|
||||||
JsFunction correspondingFunction = new JsFunction(parent);
|
return new JsFunction(parent, new JsBlock());
|
||||||
correspondingFunction.setBody(new JsBlock());
|
|
||||||
return correspondingFunction;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
@@ -330,14 +273,6 @@ public final class JsAstUtils {
|
|||||||
return dataDescriptor;
|
return dataDescriptor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static JsInvocation encloseFunction(@NotNull JsFunction function) {
|
|
||||||
JsInvocation blockFunctionInvocation = new JsInvocation();
|
|
||||||
blockFunctionInvocation.setQualifier(EMPTY_REF);
|
|
||||||
blockFunctionInvocation.getArguments().add(function);
|
|
||||||
return blockFunctionInvocation;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JsFunction createPackage(@NotNull List<JsStatement> to, @NotNull JsScope scope) {
|
public static JsFunction createPackage(@NotNull List<JsStatement> to, @NotNull JsScope scope) {
|
||||||
JsFunction packageBlockFunction = createFunctionWithEmptyBody(scope);
|
JsFunction packageBlockFunction = createFunctionWithEmptyBody(scope);
|
||||||
|
|||||||
@@ -16,22 +16,14 @@
|
|||||||
|
|
||||||
package org.jetbrains.k2js.translate.utils;
|
package org.jetbrains.k2js.translate.utils;
|
||||||
|
|
||||||
import com.google.common.collect.Lists;
|
|
||||||
import com.intellij.psi.PsiElement;
|
|
||||||
import com.intellij.psi.PsiFile;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.*;
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
|
||||||
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
|
|
||||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
|
||||||
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ClassReceiver;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ClassReceiver;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ExtensionReceiver;
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
||||||
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
|
import org.jetbrains.jet.lang.types.expressions.OperatorConventions;
|
||||||
import org.jetbrains.jet.lang.types.lang.JetStandardLibrary;
|
|
||||||
import org.jetbrains.k2js.config.LibrarySourcesConfig;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
@@ -131,31 +123,6 @@ public final class JsDescriptorUtils {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static NamespaceDescriptor getContainingNamespace(@NotNull DeclarationDescriptor descriptor) {
|
|
||||||
return DescriptorUtils.getParentOfType(descriptor, NamespaceDescriptor.class);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean isStandardDeclaration(@NotNull DeclarationDescriptor descriptor) {
|
|
||||||
NamespaceDescriptor namespace = getContainingNamespace(descriptor);
|
|
||||||
if (namespace == null) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return namespace.equals(JetStandardLibrary.getInstance().getLibraryScope().getContainingDeclaration());
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static List<NamespaceDescriptor> getNestedNamespaces(@NotNull NamespaceDescriptor namespaceDescriptor,
|
|
||||||
@NotNull BindingContext context) {
|
|
||||||
List<NamespaceDescriptor> result = Lists.newArrayList();
|
|
||||||
for (DeclarationDescriptor descriptor : getContainedDescriptorsWhichAreNotPredefined(namespaceDescriptor, context)) {
|
|
||||||
if (descriptor instanceof NamespaceDescriptor) {
|
|
||||||
result.add((NamespaceDescriptor) descriptor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static FunctionDescriptor getOverriddenDescriptor(@NotNull FunctionDescriptor functionDescriptor) {
|
public static FunctionDescriptor getOverriddenDescriptor(@NotNull FunctionDescriptor functionDescriptor) {
|
||||||
Set<? extends FunctionDescriptor> overriddenDescriptors = functionDescriptor.getOverriddenDescriptors();
|
Set<? extends FunctionDescriptor> overriddenDescriptors = functionDescriptor.getOverriddenDescriptors();
|
||||||
@@ -168,63 +135,6 @@ public final class JsDescriptorUtils {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static List<DeclarationDescriptor> getContainedDescriptorsWhichAreNotPredefined(@NotNull NamespaceDescriptor namespace,
|
|
||||||
@NotNull BindingContext context) {
|
|
||||||
List<DeclarationDescriptor> result = Lists.newArrayList();
|
|
||||||
for (DeclarationDescriptor descriptor : namespace.getMemberScope().getAllDescriptors()) {
|
|
||||||
if (!AnnotationsUtils.isPredefinedObject(descriptor)) {
|
|
||||||
// namespace may be defined in multiple files
|
|
||||||
if (!(descriptor instanceof NamespaceDescriptor)) {
|
|
||||||
PsiElement psiElement = BindingContextUtils.descriptorToDeclaration(context, descriptor);
|
|
||||||
if (psiElement != null) {
|
|
||||||
PsiFile file = psiElement.getContainingFile();
|
|
||||||
if (file.getUserData(LibrarySourcesConfig.EXTERNAL_MODULE_NAME) != null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
result.add(descriptor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
//TODO: at the moment this check is very ineffective
|
|
||||||
public static boolean isNamespaceEmpty(@NotNull NamespaceDescriptor namespace, @NotNull BindingContext context) {
|
|
||||||
List<DeclarationDescriptor> containedDescriptors = getContainedDescriptorsWhichAreNotPredefined(namespace, context);
|
|
||||||
for (DeclarationDescriptor descriptor : containedDescriptors) {
|
|
||||||
if (descriptor instanceof NamespaceDescriptor) {
|
|
||||||
if (!isNamespaceEmpty((NamespaceDescriptor) descriptor, context)) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public static List<NamespaceDescriptor> getNamespaceDescriptorHierarchy(@NotNull NamespaceDescriptor namespaceDescriptor) {
|
|
||||||
List<NamespaceDescriptor> result = Lists.newArrayList(namespaceDescriptor);
|
|
||||||
NamespaceDescriptor current = namespaceDescriptor;
|
|
||||||
while (!(current.getContainingDeclaration() instanceof ModuleDescriptor)) {
|
|
||||||
result.add(current);
|
|
||||||
if (current.getContainingDeclaration() instanceof NamespaceDescriptor) {
|
|
||||||
current = (NamespaceDescriptor) current.getContainingDeclaration();
|
|
||||||
//noinspection ConstantConditions
|
|
||||||
assert current != null;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean isDefaultAccessor(@Nullable PropertyAccessorDescriptor accessorDescriptor) {
|
private static boolean isDefaultAccessor(@Nullable PropertyAccessorDescriptor accessorDescriptor) {
|
||||||
return accessorDescriptor == null || accessorDescriptor.isDefault();
|
return accessorDescriptor == null || accessorDescriptor.isDefault();
|
||||||
}
|
}
|
||||||
@@ -244,7 +154,7 @@ public final class JsDescriptorUtils {
|
|||||||
return ((ExtensionReceiver) receiverArgument).getDeclarationDescriptor();
|
return ((ExtensionReceiver) receiverArgument).getDeclarationDescriptor();
|
||||||
}
|
}
|
||||||
if (receiverArgument instanceof ClassReceiver) {
|
if (receiverArgument instanceof ClassReceiver) {
|
||||||
return ((ClassReceiver)receiverArgument).getDeclarationDescriptor();
|
return ((ClassReceiver) receiverArgument).getDeclarationDescriptor();
|
||||||
}
|
}
|
||||||
throw new IllegalStateException("Unexpected receiver of type " + receiverArgument.getClass());
|
throw new IllegalStateException("Unexpected receiver of type " + receiverArgument.getClass());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,13 +17,13 @@
|
|||||||
package org.jetbrains.k2js.translate.utils;
|
package org.jetbrains.k2js.translate.utils;
|
||||||
|
|
||||||
import com.google.dart.compiler.backend.js.ast.*;
|
import com.google.dart.compiler.backend.js.ast.*;
|
||||||
import com.google.dart.compiler.util.AstUtil;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.lang.descriptors.*;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.FunctionDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.PropertyDescriptor;
|
||||||
|
import org.jetbrains.jet.lang.descriptors.PropertyGetterDescriptor;
|
||||||
import org.jetbrains.jet.lang.psi.*;
|
import org.jetbrains.jet.lang.psi.*;
|
||||||
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
|
||||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.ReceiverDescriptor;
|
|
||||||
import org.jetbrains.k2js.translate.context.TemporaryVariable;
|
import org.jetbrains.k2js.translate.context.TemporaryVariable;
|
||||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||||
import org.jetbrains.k2js.translate.general.Translation;
|
import org.jetbrains.k2js.translate.general.Translation;
|
||||||
@@ -33,16 +33,11 @@ import java.util.List;
|
|||||||
|
|
||||||
import static org.jetbrains.k2js.translate.utils.BindingUtils.getFunctionDescriptorForOperationExpression;
|
import static org.jetbrains.k2js.translate.utils.BindingUtils.getFunctionDescriptorForOperationExpression;
|
||||||
import static org.jetbrains.k2js.translate.utils.JsAstUtils.*;
|
import static org.jetbrains.k2js.translate.utils.JsAstUtils.*;
|
||||||
import static org.jetbrains.k2js.translate.utils.JsDescriptorUtils.getDeclarationDescriptorForReceiver;
|
|
||||||
import static org.jetbrains.k2js.translate.utils.JsDescriptorUtils.getExpectedReceiverDescriptor;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Pavel Talanov
|
* @author Pavel Talanov
|
||||||
*/
|
*/
|
||||||
public final class TranslationUtils {
|
public final class TranslationUtils {
|
||||||
|
|
||||||
private static final JsNameRef UNDEFINED_LITERAL = AstUtil.newQualifiedNameRef("undefined");
|
|
||||||
|
|
||||||
private TranslationUtils() {
|
private TranslationUtils() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -129,10 +124,18 @@ public final class TranslationUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JsNameRef getQualifiedReference(@NotNull TranslationContext context, @NotNull DeclarationDescriptor descriptor) {
|
public static JsNameRef getQualifiedReference(@NotNull TranslationContext context,
|
||||||
return new JsNameRef(context.getNameForDescriptor(descriptor), context.getQualifierForDescriptor(descriptor));
|
@NotNull DeclarationDescriptor descriptor) {
|
||||||
|
JsName name = context.getNameForDescriptor(descriptor);
|
||||||
|
JsNameRef reference = name.makeRef();
|
||||||
|
JsNameRef qualifier = context.getQualifierForDescriptor(descriptor);
|
||||||
|
if (qualifier != null) {
|
||||||
|
setQualifier(reference, qualifier);
|
||||||
|
}
|
||||||
|
return reference;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static List<JsExpression> translateExpressionList(@NotNull TranslationContext context,
|
public static List<JsExpression> translateExpressionList(@NotNull TranslationContext context,
|
||||||
@NotNull List<JetExpression> expressions) {
|
@NotNull List<JetExpression> expressions) {
|
||||||
@@ -173,22 +176,4 @@ public final class TranslationUtils {
|
|||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public static JsExpression resolveThisObjectForResolvedCall(@NotNull ResolvedCall<?> call,
|
|
||||||
@NotNull TranslationContext context) {
|
|
||||||
ReceiverDescriptor thisObject = call.getThisObject();
|
|
||||||
if (!thisObject.exists()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
DeclarationDescriptor expectedThisDescriptor = getDeclarationDescriptorForReceiver(thisObject);
|
|
||||||
return getThisObject(context, expectedThisDescriptor);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void defineModule(@NotNull TranslationContext context, @NotNull List<JsStatement> statements,
|
|
||||||
String moduleId) {
|
|
||||||
statements.add(new JsInvocation(context.namer().kotlin("defineModule"),
|
|
||||||
context.program().getStringLiteral(moduleId),
|
|
||||||
context.scope().declareName("_").makeRef()).makeStmt());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user