deleted lots of dead code
This commit is contained in:
@@ -10,12 +10,12 @@ import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.types.JetStandardLibrary;
|
||||
import org.jetbrains.k2js.translate.context.declaration.AnnotationsUtils;
|
||||
import org.jetbrains.k2js.translate.context.generator.Generator;
|
||||
import org.jetbrains.k2js.translate.context.generator.Rule;
|
||||
import org.jetbrains.k2js.translate.intrinsic.Intrinsics;
|
||||
import org.jetbrains.k2js.translate.utils.AnnotationsUtils;
|
||||
|
||||
import static org.jetbrains.k2js.translate.context.declaration.AnnotationsUtils.*;
|
||||
import static org.jetbrains.k2js.translate.utils.AnnotationsUtils.*;
|
||||
import static org.jetbrains.k2js.translate.utils.DescriptorUtils.*;
|
||||
|
||||
public class StaticContext {
|
||||
|
||||
-135
@@ -1,135 +0,0 @@
|
||||
package org.jetbrains.k2js.translate.context.declaration;
|
||||
|
||||
import com.google.dart.compiler.backend.js.ast.JsName;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.k2js.translate.context.NamingScope;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import static org.jetbrains.k2js.translate.utils.DescriptorUtils.getOwnDeclarations;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public abstract class AbstractDeclarationVisitor extends DeclarationDescriptorVisitor<Void, DeclarationContext> {
|
||||
|
||||
@NotNull
|
||||
private final Declarations declarations;
|
||||
|
||||
/*package*/ AbstractDeclarationVisitor(@NotNull Declarations declarations) {
|
||||
this.declarations = declarations;
|
||||
}
|
||||
|
||||
abstract protected NamingScope doDeclareScope(@NotNull DeclarationDescriptor descriptor,
|
||||
@NotNull DeclarationContext context,
|
||||
@NotNull String recommendedName);
|
||||
|
||||
@NotNull
|
||||
abstract protected JsName doDeclareName(@NotNull DeclarationDescriptor descriptor,
|
||||
@NotNull DeclarationContext context,
|
||||
@NotNull String recommendedName);
|
||||
|
||||
abstract protected boolean accept(@NotNull DeclarationDescriptor descriptor);
|
||||
|
||||
abstract public void traverseNamespace(@NotNull NamespaceDescriptor namespace, @NotNull DeclarationContext context);
|
||||
|
||||
@NotNull
|
||||
protected Declarations declarations() {
|
||||
return declarations;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private JsName declareName(@NotNull DeclarationDescriptor descriptor,
|
||||
@NotNull DeclarationContext context) {
|
||||
return declareName(descriptor, context, descriptor.getName());
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private JsName declareName(@NotNull DeclarationDescriptor descriptor,
|
||||
@NotNull DeclarationContext context,
|
||||
@NotNull String name) {
|
||||
if (!accept(descriptor)) {
|
||||
return null;
|
||||
}
|
||||
return doDeclareName(descriptor, context, name);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private NamingScope declareScope(@NotNull DeclarationDescriptor descriptor,
|
||||
@NotNull DeclarationContext context,
|
||||
@NotNull String name) {
|
||||
if (!accept(descriptor)) {
|
||||
return null;
|
||||
}
|
||||
return doDeclareScope(descriptor, context, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitClassDescriptor(@NotNull ClassDescriptor descriptor, @NotNull DeclarationContext context) {
|
||||
if (!accept(descriptor)) {
|
||||
return null;
|
||||
}
|
||||
DeclarationContext classContext = declareClass(descriptor, context);
|
||||
declareClassConstructor(descriptor, context);
|
||||
declareClassMembers(descriptor, classContext);
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private DeclarationContext declareClass(@NotNull ClassDescriptor descriptor,
|
||||
@NotNull DeclarationContext context) {
|
||||
NamingScope classScope = doDeclareScope(descriptor, context, "class " + descriptor.getName());
|
||||
JsName className = doDeclareName(descriptor, context, descriptor.getName());
|
||||
return context.innerDeclaration(classScope, className);
|
||||
}
|
||||
|
||||
private void declareClassMembers(@NotNull ClassDescriptor descriptor, @NotNull DeclarationContext context) {
|
||||
for (DeclarationDescriptor memberDescriptor : getOwnDeclarations(descriptor)) {
|
||||
memberDescriptor.accept(this, context);
|
||||
}
|
||||
}
|
||||
|
||||
private void declareClassConstructor(@NotNull ClassDescriptor descriptor, @NotNull DeclarationContext context) {
|
||||
for (ConstructorDescriptor constructorDescriptor : descriptor.getConstructors()) {
|
||||
constructorDescriptor.accept(this, context);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitConstructorDescriptor(@NotNull ConstructorDescriptor descriptor,
|
||||
@NotNull DeclarationContext context) {
|
||||
assert accept(descriptor) : "Must accept constructor fot he class we accepted";
|
||||
JsName alreadyDeclaredClassName = declarations.getName(descriptor.getContainingDeclaration());
|
||||
//already defined in
|
||||
declarations.putName(descriptor, alreadyDeclaredClassName);
|
||||
declarations.putQualifier(descriptor, context.getQualifier());
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Void visitFunctionDescriptor(@NotNull FunctionDescriptor descriptor, @NotNull DeclarationContext context) {
|
||||
boolean overridesDeclaredDescriptor = declareAsOverridden(descriptor, context);
|
||||
if (overridesDeclaredDescriptor) {
|
||||
return null;
|
||||
}
|
||||
declareName(descriptor, context);
|
||||
declareScope(descriptor, context, "function " + descriptor.getName());
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean declareAsOverridden(@NotNull FunctionDescriptor descriptor, @NotNull DeclarationContext context) {
|
||||
Set<? extends FunctionDescriptor> overriddenDescriptors = descriptor.getOverriddenDescriptors();
|
||||
for (FunctionDescriptor overriddenDescriptor : overriddenDescriptors) {
|
||||
if (declarations.hasDeclaredName(overriddenDescriptor)) {
|
||||
declarations.putName(descriptor, declarations.getName(overriddenDescriptor));
|
||||
declareScope(descriptor, context, "function " + descriptor.getName());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
-46
@@ -1,46 +0,0 @@
|
||||
package org.jetbrains.k2js.translate.context.declaration;
|
||||
|
||||
import com.google.dart.compiler.backend.js.ast.JsName;
|
||||
import com.google.dart.compiler.backend.js.ast.JsNameRef;
|
||||
import com.google.dart.compiler.util.AstUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.k2js.translate.context.NamingScope;
|
||||
|
||||
public final class DeclarationContext {
|
||||
|
||||
@NotNull
|
||||
public static DeclarationContext rootContext(@NotNull NamingScope scope, @Nullable JsNameRef qualifier) {
|
||||
return new DeclarationContext(scope, qualifier);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private final NamingScope scope;
|
||||
|
||||
@Nullable
|
||||
private final JsNameRef qualifier;
|
||||
|
||||
private DeclarationContext(@NotNull NamingScope scope, @Nullable JsNameRef qualifier) {
|
||||
this.scope = scope;
|
||||
this.qualifier = qualifier;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public NamingScope getScope() {
|
||||
return scope;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JsNameRef getQualifier() {
|
||||
return qualifier;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DeclarationContext innerDeclaration(@NotNull NamingScope declarationScope, @NotNull JsName declarationName) {
|
||||
JsNameRef reference = declarationName.makeRef();
|
||||
if (qualifier != null) {
|
||||
AstUtil.setQualifier(reference, qualifier);
|
||||
}
|
||||
return new DeclarationContext(declarationScope, reference);
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
package org.jetbrains.k2js.translate.context.declaration;
|
||||
|
||||
import com.google.dart.compiler.backend.js.ast.JsName;
|
||||
import com.google.dart.compiler.backend.js.ast.JsNameRef;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Pavel Talanov
|
||||
*/
|
||||
public final class Declarations {
|
||||
|
||||
@NotNull
|
||||
/*package*/ static Declarations newInstance() {
|
||||
return new Declarations();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private final Map<DeclarationDescriptor, JsName> descriptorToNameMap = new HashMap<DeclarationDescriptor, JsName>();
|
||||
@NotNull
|
||||
private final Map<DeclarationDescriptor, JsNameRef> descriptorToQualifierMap = new HashMap<DeclarationDescriptor, JsNameRef>();
|
||||
|
||||
private Declarations() {
|
||||
}
|
||||
|
||||
|
||||
@NotNull
|
||||
public JsName getName(@NotNull DeclarationDescriptor descriptor) {
|
||||
JsName name = descriptorToNameMap.get(descriptor.getOriginal());
|
||||
assert name != null : "Unknown declaration: " + DescriptorUtils.getFQName(descriptor);
|
||||
return name;
|
||||
}
|
||||
|
||||
public boolean hasDeclaredName(@NotNull DeclarationDescriptor descriptor) {
|
||||
return descriptorToNameMap.containsKey(descriptor.getOriginal());
|
||||
}
|
||||
|
||||
public boolean hasQualifier(@NotNull DeclarationDescriptor descriptor) {
|
||||
return (descriptorToQualifierMap.get(descriptor.getOriginal()) != null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JsNameRef getQualifier(@NotNull DeclarationDescriptor descriptor) {
|
||||
JsNameRef qualifier = descriptorToQualifierMap.get(descriptor.getOriginal());
|
||||
assert qualifier != null : "Cannot be null. Use hasQualifier to check.";
|
||||
return qualifier;
|
||||
}
|
||||
|
||||
/*package*/ void putName(@NotNull DeclarationDescriptor descriptor, @NotNull JsName name) {
|
||||
assert !descriptorToNameMap.containsKey(descriptor)
|
||||
: "Already contains that key!\n" + descriptor;
|
||||
descriptorToNameMap.put(descriptor, name);
|
||||
}
|
||||
|
||||
/*package*/ void putQualifier(@NotNull DeclarationDescriptor descriptor, @Nullable JsNameRef qualifier) {
|
||||
assert !descriptorToQualifierMap.containsKey(descriptor)
|
||||
: "Already contains that key!";
|
||||
descriptorToQualifierMap.put(descriptor, qualifier);
|
||||
}
|
||||
}
|
||||
-44
@@ -1,44 +0,0 @@
|
||||
//package org.jetbrains.k2js.translate.context.declaration;
|
||||
//
|
||||
//import com.google.dart.compiler.backend.js.ast.JsName;
|
||||
//import org.jetbrains.annotations.NotNull;
|
||||
//import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||
//import org.jetbrains.jet.lang.descriptors.NamespaceDescriptor;
|
||||
//import org.jetbrains.k2js.translate.context.NamingScope;
|
||||
//
|
||||
//import static org.jetbrains.k2js.translate.context.declaration.AnnotationsUtils.doesNotHaveInternalAnnotations;
|
||||
//
|
||||
///**
|
||||
// * @author Pavel Talanov
|
||||
// */
|
||||
//public final class KotlinDeclarationVisitor extends AbstractDeclarationVisitor {
|
||||
//
|
||||
// private final boolean shouldObfuscate;
|
||||
//
|
||||
// /*package*/ KotlinDeclarationVisitor(@NotNull Declarations declarations, boolean obfuscateNames) {
|
||||
// super(declarations);
|
||||
// this.shouldObfuscate = obfuscateNames;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// @NotNull
|
||||
// protected JsName doDeclareName(@NotNull DeclarationDescriptor descriptor, @NotNull DeclarationContext context,
|
||||
// @NotNull String recommendedName) {
|
||||
// JsName jsName = context.getScope().declareVariable(descriptor, recommendedName, shouldObfuscate);
|
||||
// jsName.setObfuscatable(false);
|
||||
// declarations().putName(descriptor, jsName);
|
||||
// declarations().putQualifier(descriptor, context.getQualifier());
|
||||
// return jsName;
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// protected boolean accept(@NotNull DeclarationDescriptor descriptor) {
|
||||
// return (doesNotHaveInternalAnnotations(descriptor));
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void traverseNamespace(@NotNull NamespaceDescriptor descriptor, @NotNull DeclarationContext context) {
|
||||
// DeclarationContext namespaceContext = extractNamespaceDeclaration(descriptor, context);
|
||||
// declareMembers(descriptor, namespaceContext);
|
||||
// }
|
||||
//}
|
||||
@@ -11,7 +11,7 @@ import org.jetbrains.jet.lang.psi.JetSimpleNameExpression;
|
||||
import org.jetbrains.jet.lang.resolve.calls.ResolvedCall;
|
||||
import org.jetbrains.k2js.translate.context.TranslationContext;
|
||||
|
||||
import static org.jetbrains.k2js.translate.context.declaration.AnnotationsUtils.isNativeObject;
|
||||
import static org.jetbrains.k2js.translate.utils.AnnotationsUtils.isNativeObject;
|
||||
import static org.jetbrains.k2js.translate.utils.BindingUtils.getDescriptorForReferenceExpression;
|
||||
import static org.jetbrains.k2js.translate.utils.BindingUtils.getResolvedCall;
|
||||
import static org.jetbrains.k2js.translate.utils.PsiUtils.getSelectorAsSimpleName;
|
||||
|
||||
+2
-1
@@ -1,4 +1,4 @@
|
||||
package org.jetbrains.k2js.translate.context.declaration;
|
||||
package org.jetbrains.k2js.translate.utils;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -25,6 +25,7 @@ public final class AnnotationsUtils {
|
||||
private AnnotationsUtils() {
|
||||
}
|
||||
|
||||
//TODO: make public, use when necessary
|
||||
private static boolean hasAnnotation(@NotNull DeclarationDescriptor descriptor,
|
||||
@NotNull String annotationFQNAme) {
|
||||
return getAnnotationByName(descriptor, annotationFQNAme) != null;
|
||||
Reference in New Issue
Block a user