Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: develar/kotlin
...
head fork: develar/kotlin
  • 13 commits
  • 35 files changed
  • 0 commit comments
  • 3 contributors
Showing with 622 additions and 161 deletions.
  1. +8 −0 compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java
  2. +41 −2 compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClass.java
  3. +12 −0 compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDelegationSpecifier.java
  4. +2 −10 compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDelegatorToSuperCall.java
  5. +10 −0 compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFile.java
  6. +7 −1 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetClassStub.java
  7. +15 −3 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetClassElementType.java
  8. +2 −7 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFileElementType.java
  9. +30 −4 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetClassStubImpl.java
  10. +4 −8 compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JetLightClass.java
  11. +5 −0 idea/src/META-INF/plugin.xml
  12. +0 −8 idea/src/org/jetbrains/jet/plugin/findUsages/KotlinFindClassUsagesHandler.java
  13. +0 −17 idea/src/org/jetbrains/jet/plugin/findUsages/KotlinFindFunctionUsagesHandler.java
  14. +60 −0 idea/src/org/jetbrains/jet/plugin/highlighter/JetLineMarkerProvider.java
  15. +0 −19 idea/src/org/jetbrains/jet/plugin/refactoring/rename/RenameJetClassProcessor.java
  16. +0 −12 idea/src/org/jetbrains/jet/plugin/refactoring/rename/RenameKotlinFunctionProcessor.java
  17. +46 −0 idea/src/org/jetbrains/jet/plugin/search/KotlinDefinitionsSearcher.java
  18. +67 −0 idea/src/org/jetbrains/jet/plugin/search/KotlinDirectInheritorsSearcher.java
  19. +58 −0 idea/src/org/jetbrains/jet/plugin/search/KotlinReferencesSearcher.java
  20. +1 −0  idea/src/org/jetbrains/jet/plugin/stubindex/JetIndexKeys.java
  21. +47 −0 idea/src/org/jetbrains/jet/plugin/stubindex/JetSuperClassIndex.java
  22. +4 −0 idea/src/org/jetbrains/jet/plugin/stubindex/StubIndexServiceImpl.java
  23. +50 −0 idea/tests/org/jetbrains/jet/plugin/stubs/JetStubsTest.java
  24. +2 −3 js/js.tests/test/org/jetbrains/k2js/test/semantics/StandardClassesTest.java
  25. +67 −0 js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTest.java
  26. +1 −2  js/js.tests/test/org/jetbrains/k2js/test/semantics/WebDemoExamples2Test.java
  27. +10 −0 js/js.translator/src/org/jetbrains/k2js/translate/context/Namer.java
  28. +1 −1  js/js.translator/src/org/jetbrains/k2js/translate/initializer/NamespaceInitializerTranslator.java
  29. +2 −23 js/js.translator/src/org/jetbrains/k2js/translate/utils/JsAstUtils.java
  30. +27 −39 js/js.translator/testFiles/kotlin_lib.js
  31. +5 −1 js/js.translator/testFiles/kotlin_lib_ecma5.js
  32. +10 −0 js/js.translator/testFiles/stdlib/cases/browserDocumentAccess.kt
  33. +13 −0 js/js.translator/testFiles/test.html
  34. +13 −0 libraries/stdlib/src/js/Annotations.kt
  35. +2 −1  libraries/stdlib/src/kotlin/browser/Properties.kt
View
8 compiler/backend/src/org/jetbrains/jet/codegen/JetTypeMapper.java
@@ -376,8 +376,16 @@ else if (kind == MapTypeMode.IMPL) {
}
}
+ final TypeConstructor constructor = jetType.getConstructor();
+ if (constructor instanceof IntersectionTypeConstructor) {
+ jetType = CommonSupertypes.commonSupertype(new ArrayList<JetType>(constructor.getSupertypes()));
+ }
DeclarationDescriptor descriptor = jetType.getConstructor().getDeclarationDescriptor();
+ if (descriptor == null) {
+ throw new UnsupportedOperationException("no descriptor for type constructor of " + jetType);
+ }
+
if (ErrorUtils.isError(descriptor)) {
if (classBuilderMode != ClassBuilderMode.SIGNATURES) {
throw new IllegalStateException("error types are not allowed when classBuilderMode = " + classBuilderMode);
View
43 compiler/frontend/src/org/jetbrains/jet/lang/psi/JetClass.java
@@ -39,7 +39,7 @@
* @author max
*/
public class JetClass extends JetTypeParameterListOwner
- implements JetClassOrObject, JetModifierListOwner, StubBasedPsiElement<PsiJetClassStub<?>> {
+ implements JetClassOrObject, JetModifierListOwner, StubBasedPsiElement<PsiJetClassStub> {
private PsiJetClassStub stub;
@@ -158,7 +158,7 @@ public IStubElementType getElementType() {
}
@Override
- public PsiJetClassStub<?> getStub() {
+ public PsiJetClassStub getStub() {
// TODO (stubs)
return null;
}
@@ -198,4 +198,43 @@ private String getQualifiedName() {
Collections.reverse(parts);
return StringUtil.join(parts, ".");
}
+
+ /**
+ * Returns the list of unqualified names that are indexed as the superclass names of this class. For the names that might be imported
+ * via an aliased import, includes both the original and the aliased name (reference resolution during inheritor search will sort this out).
+ *
+ * @return the list of possible superclass names
+ */
+ @NotNull
+ public List<String> getSuperNames() {
+ final List<JetDelegationSpecifier> specifiers = getDelegationSpecifiers();
+ if (specifiers.size() == 0) return Collections.emptyList();
+ List<String> result = new ArrayList<String>();
+ for (JetDelegationSpecifier specifier : specifiers) {
+ final JetUserType superType = specifier.getTypeAsUserType();
+ if (superType != null) {
+ final String referencedName = superType.getReferencedName();
+ if (referencedName != null) {
+ addSuperName(result, referencedName);
+ }
+ }
+ }
+ return result;
+ }
+
+ private void addSuperName(List<String> result, String referencedName) {
+ result.add(referencedName);
+ if (getContainingFile() instanceof JetFile) {
+ final JetImportDirective directive = ((JetFile) getContainingFile()).findImportByAlias(referencedName);
+ if (directive != null) {
+ JetExpression reference = directive.getImportedReference();
+ while (reference instanceof JetDotQualifiedExpression) {
+ reference = ((JetDotQualifiedExpression) reference).getSelectorExpression();
+ }
+ if (reference instanceof JetSimpleNameExpression) {
+ result.add(((JetSimpleNameExpression) reference).getReferencedName());
+ }
+ }
+ }
+ }
}
View
12 compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDelegationSpecifier.java
@@ -43,4 +43,16 @@ public void accept(@NotNull JetVisitorVoid visitor) {
public JetTypeReference getTypeReference() {
return (JetTypeReference) findChildByType(JetNodeTypes.TYPE_REFERENCE);
}
+
+ @Nullable
+ public JetUserType getTypeAsUserType() {
+ final JetTypeReference reference = getTypeReference();
+ if (reference != null) {
+ final JetTypeElement element = reference.getTypeElement();
+ if (element instanceof JetUserType) {
+ return ((JetUserType) element);
+ }
+ }
+ return null;
+ }
}
View
12 compiler/frontend/src/org/jetbrains/jet/lang/psi/JetDelegatorToSuperCall.java
@@ -82,16 +82,8 @@ public JetTypeReference getTypeReference() {
@Override
public JetTypeArgumentList getTypeArgumentList() {
- JetTypeReference typeReference = getTypeReference();
- if (typeReference == null) {
- return null;
- }
- JetTypeElement typeElement = typeReference.getTypeElement();
- if (typeElement instanceof JetUserType) {
- JetUserType userType = (JetUserType) typeElement;
- return userType.getTypeArgumentList();
- }
- return null;
+ final JetUserType userType = getTypeAsUserType();
+ return userType != null ? userType.getTypeArgumentList() : null;
}
}
View
10 compiler/frontend/src/org/jetbrains/jet/lang/psi/JetFile.java
@@ -61,6 +61,16 @@ public String toString() {
return PsiTreeUtil.getChildrenOfTypeAsList(this, JetImportDirective.class);
}
+ @Nullable
+ public JetImportDirective findImportByAlias(@NotNull String name) {
+ for (JetImportDirective directive : getImportDirectives()) {
+ if (name.equals(directive.getAliasName())) {
+ return directive;
+ }
+ }
+ return null;
+ }
+
// scripts has no namespace header
@Nullable
public JetNamespaceHeader getNamespaceHeader() {
View
8 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/PsiJetClassStub.java
@@ -18,13 +18,16 @@
import com.intellij.psi.stubs.StubElement;
import org.jetbrains.annotations.NonNls;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.psi.JetClass;
+import java.util.List;
+
/**
* @author Nikolay Krasko
*/
-public interface PsiJetClassStub<T extends JetClass> extends StubElement<T> {
+public interface PsiJetClassStub extends StubElement<JetClass> {
@NonNls
@Nullable
String getQualifiedName();
@@ -32,6 +35,9 @@
@Nullable
String getName();
+ @NotNull
+ List<String> getSuperNames();
+
boolean isDeprecated();
boolean hasDeprecatedAnnotation();
}
View
18 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetClassElementType.java
@@ -33,6 +33,7 @@
import org.jetbrains.jet.lang.resolve.name.FqName;
import java.io.IOException;
+import java.util.List;
/**
* @author Nikolay Krasko
@@ -62,22 +63,33 @@ public JetClass createPsiFromAst(@NotNull ASTNode node) {
@Override
public PsiJetClassStub createStub(@NotNull JetClass psi, StubElement parentStub) {
FqName fqName = JetPsiUtil.getFQName(psi);
- return new PsiJetClassStubImpl(JetStubElementTypes.CLASS, parentStub, fqName != null ? fqName.getFqName() : null, psi.getName());
+ return new PsiJetClassStubImpl(JetStubElementTypes.CLASS, parentStub, fqName != null ? fqName.getFqName() : null, psi.getName(),
+ psi.getSuperNames());
}
@Override
public void serialize(PsiJetClassStub stub, StubOutputStream dataStream) throws IOException {
dataStream.writeName(stub.getName());
dataStream.writeName(stub.getQualifiedName());
+ final List<String> superNames = stub.getSuperNames();
+ dataStream.writeVarInt(superNames.size());
+ for (String name : superNames) {
+ dataStream.writeName(name);
+ }
}
@Override
public PsiJetClassStub deserialize(StubInputStream dataStream, StubElement parentStub) throws IOException {
final StringRef name = dataStream.readName();
final StringRef qualifiedName = dataStream.readName();
-
+ final int superCount = dataStream.readVarInt();
+ final StringRef[] superNames = StringRef.createArray(superCount);
+ for (int i = 0; i < superCount; i++) {
+ superNames[i] = dataStream.readName();
+ }
+
final JetClassElementType type = JetStubElementTypes.CLASS;
- final PsiJetClassStubImpl classStub = new PsiJetClassStubImpl(type, parentStub, qualifiedName, name);
+ final PsiJetClassStubImpl classStub = new PsiJetClassStubImpl(type, parentStub, qualifiedName, name, superNames);
return classStub;
}
View
9 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/elements/JetFileElementType.java
@@ -16,12 +16,7 @@
package org.jetbrains.jet.lang.psi.stubs.elements;
-import com.intellij.lang.ASTNode;
-import com.intellij.lang.Language;
-import com.intellij.lang.LanguageParserDefinitions;
-import com.intellij.lang.PsiBuilder;
-import com.intellij.lang.PsiBuilderFactory;
-import com.intellij.lang.PsiParser;
+import com.intellij.lang.*;
import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.StubBuilder;
@@ -43,7 +38,7 @@
* @author Nikolay Krasko
*/
public class JetFileElementType extends IStubFileElementType<PsiJetFileStub> {
- public static final int STUB_VERSION = 3;
+ public static final int STUB_VERSION = 4;
public JetFileElementType() {
super("jet.FILE", JetLanguage.INSTANCE);
View
34 compiler/frontend/src/org/jetbrains/jet/lang/psi/stubs/impl/PsiJetClassStubImpl.java
@@ -19,37 +19,53 @@
import com.intellij.psi.stubs.StubBase;
import com.intellij.psi.stubs.StubElement;
import com.intellij.util.io.StringRef;
+import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.jet.lang.psi.JetClass;
import org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub;
import org.jetbrains.jet.lang.psi.stubs.elements.JetClassElementType;
+import java.util.ArrayList;
+import java.util.List;
+
/**
* @author Nikolay Krasko
*/
-public class PsiJetClassStubImpl extends StubBase<JetClass> implements PsiJetClassStub<JetClass> {
+public class PsiJetClassStubImpl extends StubBase<JetClass> implements PsiJetClassStub {
private final StringRef qualifiedName;
private final StringRef name;
+ private final StringRef[] superNames;
public PsiJetClassStubImpl(
JetClassElementType type,
final StubElement parent,
@Nullable final String qualifiedName,
- final String name) {
+ final String name,
+ final List<String> superNames) {
+
+ this(type, parent, StringRef.fromString(qualifiedName), StringRef.fromString(name), wrapStrings(superNames));
+ }
- this(type, parent, StringRef.fromString(qualifiedName), StringRef.fromString(name));
+ private static StringRef[] wrapStrings(List<String> names) {
+ StringRef[] refs = new StringRef[names.size()];
+ for (int i = 0; i < names.size(); i++) {
+ refs[i] = StringRef.fromString(names.get(i));
+ }
+ return refs;
}
public PsiJetClassStubImpl(
JetClassElementType type,
final StubElement parent,
final StringRef qualifiedName,
- final StringRef name) {
+ final StringRef name,
+ final StringRef[] superNames) {
super(parent, type);
this.qualifiedName = qualifiedName;
this.name = name;
+ this.superNames = superNames;
}
@Override
@@ -71,4 +87,14 @@ public boolean hasDeprecatedAnnotation() {
public String getName() {
return StringRef.toString(name);
}
+
+ @NotNull
+ @Override
+ public List<String> getSuperNames() {
+ List<String> result = new ArrayList<String>();
+ for (StringRef ref : superNames) {
+ result.add(ref.toString());
+ }
+ return result;
+ }
}
View
12 compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JetLightClass.java
@@ -194,14 +194,10 @@ public PsiClassHolderFileStub getStub() {
fakeFile.setPhysical(false);
answer.setPsi(fakeFile);
- try {
- super.generateNamespace(namespace);
- }
- finally {
- final StubElement pop = stubStack.pop();
- if (pop != answer) {
- LOG.error("Unbalanced stack operations: " + pop);
- }
+ super.generateNamespace(namespace);
+ final StubElement pop = stubStack.pop();
+ if (pop != answer) {
+ LOG.error("Unbalanced stack operations: " + pop);
}
}
};
View
5 idea/src/META-INF/plugin.xml
@@ -175,6 +175,7 @@
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetShortFunctionNameIndex"/>
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetExtensionFunctionNameIndex"/>
<stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetAllShortFunctionNameIndex"/>
+ <stubIndex implementation="org.jetbrains.jet.plugin.stubindex.JetSuperClassIndex"/>
<contentBasedClassFileProcessor implementation="org.jetbrains.jet.plugin.libraries.JetContentBasedFileSubstitutor" />
<psi.clsCustomNavigationPolicy implementation="org.jetbrains.jet.plugin.libraries.JetClsNavigationPolicy" />
@@ -184,6 +185,10 @@
<psi.treeChangePreprocessor implementation="org.jetbrains.jet.asJava.JetCodeBlockModificationListener"/>
+ <referencesSearch implementation="org.jetbrains.jet.plugin.search.KotlinReferencesSearcher"/>
+ <directClassInheritorsSearch implementation="org.jetbrains.jet.plugin.search.KotlinDirectInheritorsSearcher"/>
+ <definitionsSearch implementation="org.jetbrains.jet.plugin.search.KotlinDefinitionsSearcher"/>
+
<toolWindow id="Kotlin"
factoryClass="org.jetbrains.jet.plugin.internal.KotlinInternalToolWindowFactory"
anchor="right"
View
8 idea/src/org/jetbrains/jet/plugin/findUsages/KotlinFindClassUsagesHandler.java
@@ -19,8 +19,6 @@
import com.intellij.find.findUsages.FindUsagesHandler;
import com.intellij.psi.PsiElement;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.jet.asJava.JetLightClass;
-import org.jetbrains.jet.lang.psi.JetClass;
/**
* @author yole
@@ -29,10 +27,4 @@
public KotlinFindClassUsagesHandler(@NotNull PsiElement psiElement) {
super(psiElement);
}
-
- @NotNull
- @Override
- public PsiElement[] getSecondaryElements() {
- return new PsiElement[] {JetLightClass.wrapDelegate((JetClass) getPsiElement()) };
- }
}
View
17 idea/src/org/jetbrains/jet/plugin/findUsages/KotlinFindFunctionUsagesHandler.java
@@ -18,11 +18,7 @@
import com.intellij.find.findUsages.FindUsagesHandler;
import com.intellij.psi.PsiElement;
-import com.intellij.psi.PsiMethod;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.jet.asJava.JetLightClass;
-import org.jetbrains.jet.lang.psi.JetClassBody;
-import org.jetbrains.jet.lang.psi.JetFunction;
/**
* @author yole
@@ -31,17 +27,4 @@
protected KotlinFindFunctionUsagesHandler(@NotNull PsiElement psiElement) {
super(psiElement);
}
-
- @NotNull
- @Override
- public PsiElement[] getSecondaryElements() {
- JetFunction function = (JetFunction) getPsiElement();
- if (function.getParent() instanceof JetClassBody) {
- final PsiMethod method = JetLightClass.wrapMethod(function);
- if (method != null) {
- return new PsiElement[] { method };
- }
- }
- return PsiElement.EMPTY_ARRAY;
- }
}
View
60 idea/src/org/jetbrains/jet/plugin/highlighter/JetLineMarkerProvider.java
@@ -21,24 +21,31 @@
import com.intellij.codeInsight.daemon.GutterIconNavigationHandler;
import com.intellij.codeInsight.daemon.LineMarkerInfo;
import com.intellij.codeInsight.daemon.LineMarkerProvider;
+import com.intellij.codeInsight.daemon.impl.MarkerType;
import com.intellij.codeInsight.hint.HintUtil;
import com.intellij.codeInsight.navigation.NavigationUtil;
+import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.ui.popup.JBPopup;
import com.intellij.openapi.ui.popup.JBPopupFactory;
import com.intellij.openapi.util.IconLoader;
+import com.intellij.psi.PsiClass;
import com.intellij.psi.PsiElement;
+import com.intellij.psi.search.searches.ClassInheritorsSearch;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.ui.awt.RelativePoint;
import com.intellij.util.Function;
import com.intellij.util.PsiNavigateUtil;
+import org.jetbrains.jet.asJava.JetLightClass;
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
import org.jetbrains.jet.lang.descriptors.Modality;
+import org.jetbrains.jet.lang.psi.JetClass;
import org.jetbrains.jet.lang.psi.JetFile;
import org.jetbrains.jet.lang.psi.JetNamedFunction;
import org.jetbrains.jet.lang.psi.JetProperty;
import org.jetbrains.jet.lang.resolve.BindingContext;
import org.jetbrains.jet.lang.resolve.BindingContextUtils;
+import org.jetbrains.jet.lexer.JetTokens;
import org.jetbrains.jet.plugin.codeInsight.JetFunctionPsiElementCellRenderer;
import org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade;
import org.jetbrains.jet.resolve.DescriptorRenderer;
@@ -55,6 +62,38 @@
public class JetLineMarkerProvider implements LineMarkerProvider {
public static final Icon OVERRIDING_MARK = IconLoader.getIcon("/gutter/overridingMethod.png");
public static final Icon IMPLEMENTING_MARK = IconLoader.getIcon("/gutter/implementingMethod.png");
+ protected static final Icon OVERRIDDEN_MARK = IconLoader.getIcon("/gutter/overridenMethod.png");
+
+ private static final Function<PsiElement, String> SUBCLASSED_CLASS_TOOLTIP_ADAPTER = new Function<PsiElement, String>() {
+ @Override
+ public String fun(PsiElement element) {
+ PsiElement child = getPsiClassFirstChild(element);
+ // Java puts its marker on a child of the PsiClass, so we must find a child of our own class too
+ return child != null ? MarkerType.SUBCLASSED_CLASS.getTooltip().fun(child) : null;
+ }
+ };
+
+ private static PsiElement getPsiClassFirstChild(PsiElement element) {
+ if (!(element instanceof JetClass)) {
+ element = element.getParent();
+ if (!(element instanceof JetClass)) {
+ return null;
+ }
+ }
+ final PsiClass lightClass = JetLightClass.wrapDelegate((JetClass) element).getDelegate();
+ final PsiElement[] children = lightClass.getChildren();
+ return children.length > 0 ? children[0] : null;
+ }
+
+ private static final GutterIconNavigationHandler<PsiElement> SUBCLASSED_CLASS_NAVIGATION_HANDLER = new GutterIconNavigationHandler<PsiElement>() {
+ @Override
+ public void navigate(MouseEvent e, PsiElement elt) {
+ PsiElement child = getPsiClassFirstChild(elt);
+ if (child != null) {
+ MarkerType.SUBCLASSED_CLASS.getNavigationHandler().navigate(e, child);
+ }
+ }
+ };
@Override
public LineMarkerInfo getLineMarkerInfo(final PsiElement element) {
@@ -141,5 +180,26 @@ public void navigate(MouseEvent event, PsiElement elt) {
@Override
public void collectSlowLineMarkers(List<PsiElement> elements, Collection<LineMarkerInfo> result) {
+ if (elements.isEmpty() || DumbService.getInstance(elements.get(0).getProject()).isDumb()) {
+ return;
+ }
+ for (PsiElement element : elements) {
+ if (element instanceof JetClass) {
+ collectInheritingClasses((JetClass)element, result);
+ }
+ }
+ }
+
+ private static void collectInheritingClasses(JetClass element, Collection<LineMarkerInfo> result) {
+ if (!element.hasModifier(JetTokens.OPEN_KEYWORD)) {
+ return;
+ }
+ PsiClass inheritor = ClassInheritorsSearch.search(JetLightClass.wrapDelegate(element), false).findFirst();
+ if (inheritor != null) {
+ final PsiElement nameIdentifier = element.getNameIdentifier();
+ PsiElement anchor = nameIdentifier != null ? nameIdentifier : element;
+ result.add(new LineMarkerInfo<PsiElement>(anchor, anchor.getTextOffset(), OVERRIDDEN_MARK, Pass.UPDATE_OVERRIDEN_MARKERS,
+ SUBCLASSED_CLASS_TOOLTIP_ADAPTER, SUBCLASSED_CLASS_NAVIGATION_HANDLER));
+ }
}
}
View
19 idea/src/org/jetbrains/jet/plugin/refactoring/rename/RenameJetClassProcessor.java
@@ -18,18 +18,11 @@
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiElement;
-import com.intellij.psi.PsiReference;
-import com.intellij.psi.search.searches.ReferencesSearch;
import com.intellij.refactoring.rename.RenamePsiElementProcessor;
import org.jetbrains.annotations.NotNull;
-import org.jetbrains.jet.asJava.JetLightClass;
-import org.jetbrains.jet.lang.psi.JetClass;
import org.jetbrains.jet.lang.psi.JetClassOrObject;
import org.jetbrains.jet.lang.psi.JetFile;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
import java.util.Map;
/**
@@ -42,18 +35,6 @@ public boolean canProcessElement(@NotNull PsiElement element) {
return element instanceof JetClassOrObject;
}
- @NotNull
- @Override
- public Collection<PsiReference> findReferences(PsiElement element) {
- if (element instanceof JetClass) {
- List<PsiReference> references = new ArrayList<PsiReference>();
- references.addAll(ReferencesSearch.search(element).findAll());
- references.addAll(ReferencesSearch.search(JetLightClass.wrapDelegate((JetClass) element)).findAll());
- return references;
- }
- return super.findReferences(element);
- }
-
@Override
public void prepareRenaming(PsiElement element, String newName, Map<PsiElement, String> allRenames) {
JetClassOrObject clazz = (JetClassOrObject) element;
View
12 idea/src/org/jetbrains/jet/plugin/refactoring/rename/RenameKotlinFunctionProcessor.java
@@ -52,16 +52,4 @@ public PsiElement substituteElementToRename(PsiElement element, @Nullable Editor
}
return super.substituteElementToRename(element, editor);
}
-
- @NotNull
- @Override
- public Collection<PsiReference> findReferences(PsiElement element) {
- if (element instanceof JetFunction) {
- List<PsiReference> references = new ArrayList<PsiReference>();
- references.addAll(ReferencesSearch.search(element).findAll());
- references.addAll(ReferencesSearch.search(JetLightClass.wrapMethod((JetFunction) element)).findAll());
- return references;
- }
- return super.findReferences(element);
- }
}
View
46 idea/src/org/jetbrains/jet/plugin/search/KotlinDefinitionsSearcher.java
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2010-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jetbrains.jet.plugin.search;
+
+import com.intellij.openapi.application.QueryExecutorBase;
+import com.intellij.psi.PsiClass;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.search.searches.ClassInheritorsSearch;
+import com.intellij.util.Processor;
+import com.intellij.util.Query;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.jet.asJava.JetLightClass;
+import org.jetbrains.jet.lang.psi.JetClass;
+
+/**
+ * @author yole
+ */
+public class KotlinDefinitionsSearcher extends QueryExecutorBase<PsiElement, PsiElement> {
+ @Override
+ public void processQuery(@NotNull PsiElement queryParameters, @NotNull final Processor<PsiElement> consumer) {
+ if (queryParameters instanceof JetClass) {
+ final JetLightClass psiClass = JetLightClass.wrapDelegate((JetClass) queryParameters);
+ final Query<PsiClass> query = ClassInheritorsSearch.search(psiClass, true);
+ query.forEach(new Processor<PsiClass>() {
+ @Override
+ public boolean process(final PsiClass pyClass) {
+ return consumer.process(pyClass);
+ }
+ });
+ }
+ }
+}
View
67 idea/src/org/jetbrains/jet/plugin/search/KotlinDirectInheritorsSearcher.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2010-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jetbrains.jet.plugin.search;
+
+import com.intellij.openapi.application.QueryExecutorBase;
+import com.intellij.psi.PsiClass;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiReference;
+import com.intellij.psi.search.GlobalSearchScope;
+import com.intellij.psi.search.searches.DirectClassInheritorsSearch;
+import com.intellij.util.Processor;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.jet.asJava.JetLightClass;
+import org.jetbrains.jet.lang.psi.*;
+import org.jetbrains.jet.plugin.stubindex.JetSuperClassIndex;
+
+import java.util.Collection;
+import java.util.List;
+
+/**
+ * @author yole
+ */
+public class KotlinDirectInheritorsSearcher extends QueryExecutorBase<PsiClass, DirectClassInheritorsSearch.SearchParameters> {
+ public KotlinDirectInheritorsSearcher() {
+ super(true);
+ }
+
+ @Override
+ public void processQuery(@NotNull DirectClassInheritorsSearch.SearchParameters queryParameters, @NotNull Processor<PsiClass> consumer) {
+ final PsiClass clazz = queryParameters.getClassToProcess();
+ final String name = clazz.getName();
+ if (name == null || !(queryParameters.getScope() instanceof GlobalSearchScope)) return;
+ GlobalSearchScope scope = (GlobalSearchScope) queryParameters.getScope();
+ final Collection<JetClassOrObject> candidates = JetSuperClassIndex.getInstance().get(name, clazz.getProject(), scope);
+ for (JetClassOrObject candidate : candidates) {
+ if (!(candidate instanceof JetClass)) continue;
+ final List<JetDelegationSpecifier> specifiers = candidate.getDelegationSpecifiers();
+ for (JetDelegationSpecifier specifier : specifiers) {
+ final JetUserType type = specifier.getTypeAsUserType();
+ if (type != null) {
+ final JetSimpleNameExpression referenceExpression = type.getReferenceExpression();
+ if (referenceExpression != null) {
+ final PsiReference reference = referenceExpression.getReference();
+ final PsiElement resolved = reference != null ? reference.resolve() : null;
+ if ((resolved instanceof PsiClass || resolved instanceof JetClass) && resolved.isEquivalentTo(clazz)) {
+ consumer.process(JetLightClass.wrapDelegate((JetClass) candidate));
+ }
+ }
+ }
+ }
+ }
+ }
+}
View
58 idea/src/org/jetbrains/jet/plugin/search/KotlinReferencesSearcher.java
@@ -0,0 +1,58 @@
+/*
+ * Copyright 2010-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jetbrains.jet.plugin.search;
+
+import com.intellij.openapi.application.QueryExecutorBase;
+import com.intellij.psi.PsiElement;
+import com.intellij.psi.PsiMethod;
+import com.intellij.psi.PsiReference;
+import com.intellij.psi.search.searches.ReferencesSearch;
+import com.intellij.util.Processor;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.jet.asJava.JetLightClass;
+import org.jetbrains.jet.lang.psi.JetClass;
+import org.jetbrains.jet.lang.psi.JetClassBody;
+import org.jetbrains.jet.lang.psi.JetFunction;
+
+/**
+ * @author yole
+ */
+public class KotlinReferencesSearcher extends QueryExecutorBase<PsiReference, ReferencesSearch.SearchParameters> {
+ @Override
+ public void processQuery(@NotNull ReferencesSearch.SearchParameters queryParameters, @NotNull Processor<PsiReference> consumer) {
+ PsiElement element = queryParameters.getElementToSearch();
+ if (element instanceof JetClass) {
+ String className = ((JetClass) element).getName();
+ if (className != null) {
+ queryParameters.getOptimizer().searchWord(className, queryParameters.getScope(),
+ true, JetLightClass.wrapDelegate((JetClass) element));
+ }
+ }
+ else if (element instanceof JetFunction) {
+ final JetFunction function = (JetFunction) element;
+ final String name = function.getName();
+ if (function.getParent() instanceof JetClassBody && name != null) {
+ final PsiMethod method = JetLightClass.wrapMethod(function);
+ if (method != null) {
+ queryParameters.getOptimizer().searchWord(name, queryParameters.getScope(),
+ true, JetLightClass.wrapMethod((JetFunction) element));
+ }
+ }
+
+ }
+ }
+}
View
1  idea/src/org/jetbrains/jet/plugin/stubindex/JetIndexKeys.java
@@ -25,6 +25,7 @@
*/
public interface JetIndexKeys {
StubIndexKey<String, JetClassOrObject> SHORT_NAME_KEY = StubIndexKey.createIndexKey("jet.class.shortName");
+ StubIndexKey<String, JetClassOrObject> SUPERCLASS_NAME_KEY = StubIndexKey.createIndexKey("jet.class.superClassName");
StubIndexKey<String, JetClassOrObject> FQN_KEY = StubIndexKey.createIndexKey("jet.fqn");
StubIndexKey<String, JetNamedFunction> TOP_LEVEL_FUNCTION_SHORT_NAME_KEY = StubIndexKey.createIndexKey("jet.top.level.function.short.name");
View
47 idea/src/org/jetbrains/jet/plugin/stubindex/JetSuperClassIndex.java
@@ -0,0 +1,47 @@
+/*
+ * Copyright 2010-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jetbrains.jet.plugin.stubindex;
+
+import com.intellij.openapi.project.Project;
+import com.intellij.psi.search.GlobalSearchScope;
+import com.intellij.psi.stubs.StringStubIndexExtension;
+import com.intellij.psi.stubs.StubIndexKey;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.jet.lang.psi.JetClassOrObject;
+
+import java.util.Collection;
+
+/**
+ * @author yole
+ */
+public class JetSuperClassIndex extends StringStubIndexExtension<JetClassOrObject> {
+ private static final JetSuperClassIndex ourInstance = new JetSuperClassIndex();
+ public static JetSuperClassIndex getInstance() {
+ return ourInstance;
+ }
+
+ @NotNull
+ @Override
+ public StubIndexKey<String, JetClassOrObject> getKey() {
+ return JetIndexKeys.SUPERCLASS_NAME_KEY;
+ }
+
+ @Override
+ public Collection<JetClassOrObject> get(final String s, final Project project, @NotNull final GlobalSearchScope scope) {
+ return super.get(s, project, new JetSourceFilterScope(scope));
+ }
+}
View
4 idea/src/org/jetbrains/jet/plugin/stubindex/StubIndexServiceImpl.java
@@ -37,6 +37,10 @@ public void indexClass(PsiJetClassStub stub, IndexSink sink) {
if (fqn != null) {
sink.occurrence(JetIndexKeys.FQN_KEY, fqn);
}
+
+ for (String superName : stub.getSuperNames()) {
+ sink.occurrence(JetIndexKeys.SUPERCLASS_NAME_KEY, superName);
+ }
}
@Override
View
50 idea/tests/org/jetbrains/jet/plugin/stubs/JetStubsTest.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2010-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jetbrains.jet.plugin.stubs;
+
+import com.intellij.psi.PsiFile;
+import com.intellij.testFramework.LightProjectDescriptor;
+import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.jet.lang.psi.JetClass;
+import org.jetbrains.jet.lang.psi.JetDeclaration;
+import org.jetbrains.jet.lang.psi.JetFile;
+import org.jetbrains.jet.lang.psi.stubs.PsiJetClassStub;
+import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
+import org.jetbrains.jet.plugin.JetLightProjectDescriptor;
+
+import java.util.List;
+
+/**
+ * @author yole
+ */
+public class JetStubsTest extends LightCodeInsightFixtureTestCase {
+ @NotNull
+ @Override
+ protected LightProjectDescriptor getProjectDescriptor() {
+ return JetLightProjectDescriptor.INSTANCE;
+ }
+
+ public void testSuperclassNames() {
+ final PsiFile psiFile = myFixture.configureByText("foo.kt", "import java.util.ArrayList as alist\nclass C(): alist() { }");
+ final List<JetDeclaration> declarations = ((JetFile) psiFile).getDeclarations();
+ final JetClass jetClass = (JetClass) declarations.get(0);
+ final PsiJetClassStub stub = JetStubElementTypes.CLASS.createStub(jetClass, null);
+ final List<String> names = stub.getSuperNames();
+ assertSameElements(names, "ArrayList", "alist");
+ }
+}
View
5 js/js.tests/test/org/jetbrains/k2js/test/semantics/StandardClassesTest.java
@@ -17,7 +17,6 @@
package org.jetbrains.k2js.test.semantics;
import org.jetbrains.k2js.test.SingleFileTranslationTest;
-import org.jetbrains.k2js.test.utils.JsTestUtils;
/**
* @author Pavel Talanov
@@ -61,6 +60,6 @@ public void testArraySize() throws Exception {
public void testArraysIterator() throws Exception {
- fooBoxTest(JsTestUtils.failsOnEcmaV5());
+ fooBoxTest();
}
-}
+}
View
67 js/js.tests/test/org/jetbrains/k2js/test/semantics/StdLibTest.java
@@ -0,0 +1,67 @@
+/*
+ * Copyright 2010-2012 JetBrains s.r.o.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.jetbrains.k2js.test.semantics;
+
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.k2js.config.EcmaVersion;
+import org.jetbrains.k2js.facade.MainCallParameters;
+import org.jetbrains.k2js.test.SingleFileTranslationTest;
+
+import java.io.File;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.EnumSet;
+import java.util.List;
+
+/**
+ * @author Pavel Talanov
+ */
+public final class StdLibTest extends SingleFileTranslationTest {
+
+ public StdLibTest() {
+ super("stdlib/");
+ }
+
+ public void testDummy() {
+ }
+
+ public void TODO_testBrowserDocumentAccess() throws Exception {
+ runFunctionOutputTest("browserDocumentAccess.kt", "test.browser", "foo", "Hello World!");
+ }
+
+ @Override
+ protected void generateJavaScriptFiles(@NotNull String kotlinFilename,
+ @NotNull MainCallParameters mainCallParameters,
+ @NotNull EnumSet<EcmaVersion> ecmaVersions) throws Exception {
+
+ String stdlibdir = pathToTestFiles() + "../../../../libraries/stdlib/src/";
+ String browser = stdlibdir + "kotlin/browser/Properties.kt";
+
+ File file = new File(browser);
+ assertTrue("Could not find file: " + browser, file.exists());
+
+ List<String> files = Arrays.asList(getInputFilePath(kotlinFilename), browser);
+
+ generateJavaScriptFiles(files, kotlinFilename, mainCallParameters, ecmaVersions);
+ }
+
+ @Override
+ protected boolean shouldCreateOut() {
+ return false;
+ }
+
+}
View
3  js/js.tests/test/org/jetbrains/k2js/test/semantics/WebDemoExamples2Test.java
@@ -17,7 +17,6 @@
package org.jetbrains.k2js.test.semantics;
import org.jetbrains.k2js.test.SingleFileTranslationTest;
-import org.jetbrains.k2js.test.utils.JsTestUtils;
/**
* @author Pavel Talanov
@@ -34,7 +33,7 @@ public void testBottles() throws Exception {
}
public void testLife() throws Exception {
- performTestWithMain(JsTestUtils.failsOnEcmaV5(), "life", "", "2");
+ performTestWithMain("life", "", "2");
}
public void testBuilder() throws Exception {
View
10 js/js.translator/src/org/jetbrains/k2js/translate/context/Namer.java
@@ -119,6 +119,9 @@ public static Namer newInstance(@NotNull JsScope rootScope) {
@NotNull
private final JsName isTypeName;
+ @NotNull
+ private final JsPropertyInitializer writablePropertyDescriptorField;
+
private Namer(@NotNull JsScope rootScope) {
kotlinName = rootScope.declareName(KOTLIN_OBJECT_NAME);
kotlinScope = new JsScope(rootScope, "Kotlin standard object");
@@ -128,6 +131,8 @@ private Namer(@NotNull JsScope rootScope) {
objectName = kotlinScope.declareName(OBJECT_OBJECT_NAME);
isTypeName = kotlinScope.declareName("isType");
+
+ writablePropertyDescriptorField = new JsPropertyInitializer(new JsNameRef("writable"), rootScope.getProgram().getTrueLiteral());
}
@NotNull
@@ -181,6 +186,11 @@ public JsExpression isOperationReference() {
}
@NotNull
+ public JsPropertyInitializer writablePropertyDescriptorField() {
+ return writablePropertyDescriptorField;
+ }
+
+ @NotNull
/*package*/ JsScope getKotlinScope() {
return kotlinScope;
}
View
2  ...anslator/src/org/jetbrains/k2js/translate/initializer/NamespaceInitializerTranslator.java
@@ -47,7 +47,7 @@ public JsFunction generateInitializeMethod() {
TranslationContext namespaceInitializerContext
= namespaceContext.innerContextWithGivenScopeAndBlock(result.getScope(), result.getBody());
- List<JsStatement> initializerStatements = (new InitializerVisitor()).traverseNamespace(namespace, namespaceInitializerContext);
+ List<JsStatement> initializerStatements = new InitializerVisitor().traverseNamespace(namespace, namespaceInitializerContext);
result.getBody().getStatements().addAll(initializerStatements);
return result;
}
View
25 js/js.translator/src/org/jetbrains/k2js/translate/utils/JsAstUtils.java
@@ -30,17 +30,12 @@
* @author Pavel Talanov
*/
public final class JsAstUtils {
- private static final JsPropertyInitializer WRITABLE = new JsPropertyInitializer(new JsNameRef("writable"), null);
- private static final JsNameRef DEFINE_PROPERTIES = new JsNameRef("defineProperties");
private static final JsNameRef DEFINE_PROPERTY = new JsNameRef("defineProperty");
- private static final JsNameRef CREATE = new JsNameRef("create");
private static final JsNameRef EMPTY_REF = new JsNameRef("");
static {
JsNameRef globalObjectReference = new JsNameRef("Object");
- DEFINE_PROPERTIES.setQualifier(globalObjectReference);
DEFINE_PROPERTY.setQualifier(globalObjectReference);
- CREATE.setQualifier(globalObjectReference);
}
private JsAstUtils() {
@@ -305,20 +300,12 @@ public static JsObjectLiteral createPropertyDataDescriptor(boolean writable,
List<JsPropertyInitializer> meta = jsPropertyDescriptor.getPropertyInitializers();
meta.add(new JsPropertyInitializer(context.program().getStringLiteral("value"), value));
if (writable) {
- meta.add(getWritable(context));
+ meta.add(context.namer().writablePropertyDescriptorField());
}
return jsPropertyDescriptor;
}
@NotNull
- private static JsPropertyInitializer getWritable(@NotNull TranslationContext context) {
- if (WRITABLE.getValueExpr() == null) {
- WRITABLE.setValueExpr(context.program().getTrueLiteral());
- }
- return WRITABLE;
- }
-
- @NotNull
public static JsInvocation encloseFunction(JsFunction function) {
JsInvocation blockFunctionInvocation = new JsInvocation();
blockFunctionInvocation.setQualifier(EMPTY_REF);
@@ -328,8 +315,7 @@ public static JsInvocation encloseFunction(JsFunction function) {
@NotNull
public static JsFunction createPackage(List<JsStatement> to, JsScope scope) {
- JsFunction packageBlockFunction = new JsFunction(scope);
- packageBlockFunction.setBody(new JsBlock());
+ JsFunction packageBlockFunction = createFunctionWithEmptyBody(scope);
JsInvocation packageBlockFunctionInvocation = encloseFunction(packageBlockFunction);
JsInvocation packageBlock = new JsInvocation();
@@ -338,11 +324,4 @@ public static JsFunction createPackage(List<JsStatement> to, JsScope scope) {
return packageBlockFunction;
}
-
- @NotNull
- public static JsInvocation objectCreate() {
- JsInvocation invocation = new JsInvocation();
- invocation.setQualifier(CREATE);
- return invocation;
- }
}
View
66 js/js.translator/testFiles/kotlin_lib.js
@@ -181,18 +181,15 @@
});
Kotlin.ArrayIterator = Kotlin.$createClass(Kotlin.Iterator, {
- initialize:function (array) {
+ initialize: function (array) {
this.array = array;
this.index = 0;
},
- next:function () {
+ next: function () {
return this.array.get(this.index++);
},
- hasNext:function () {
- return (this.array.size() > this.index);
- },
- get_hasNext:function () {
- return (this.array.size() > this.index);
+ get_hasNext: function () {
+ return this.array.size() > this.index;
}
});
@@ -256,20 +253,18 @@
});
Kotlin.Comparator = Kotlin.$createClass(
- {
- initialize:function () {
- },
- compare:function (el1, el2) {
- throw Kotlin.$new(Kotlin.AbstractFunctionInvocationError)();
- }
+ {
+ initialize: function () {
+ },
+ compare: function (el1, el2) {
+ throw Kotlin.$new(Kotlin.AbstractFunctionInvocationError)();
}
+ }
);
Kotlin.comparator = function (f) {
var result = Kotlin.$new(Kotlin.Comparator)();
- result.compare = function (el1, el2) {
- return f(el1, el2);
- };
+ result.compare = f;
return result;
};
@@ -330,23 +325,20 @@
};
var intrinsicArrayIterator = Kotlin.$createClass(
- Kotlin.Iterator,
- {
- initialize:function (arr) {
- this.arr = arr;
- this.len = arr.length;
- this.i = 0;
- },
- hasNext:function () {
- return (this.i < this.len);
- },
- next:function () {
- return this.arr[this.i++];
- },
- get_hasNext:function () {
- return (this.i < this.len);
- }
+ Kotlin.Iterator,
+ {
+ initialize: function (arr) {
+ this.arr = arr;
+ this.len = arr.length;
+ this.i = 0;
+ },
+ next: function () {
+ return this.arr[this.i++];
+ },
+ get_hasNext: function () {
+ return this.i < this.len;
}
+ }
);
Kotlin.arrayIterator = function (arr) {
@@ -858,12 +850,8 @@
};
}
- Kotlin.HashSet = Kotlin.$createClass(
- {
- initialize:function () {
- HashSet.call(this);
- }
- }
- );
+ Kotlin.HashSet = Kotlin.$createClass({initialize: function () {
+ HashSet.call(this);
+ }});
}());
})();
View
6 js/js.translator/testFiles/kotlin_lib_ecma5.js
@@ -1,3 +1,6 @@
+// Be aware — Google Chrome has serious issue — you can rewrite READ-ONLY property (if it is defined in prototype). Firefox and Safari work correct.
+// Always test property access issues in Firefox, but not in Chrome.
+
var Kotlin = {};
(function () {
@@ -149,7 +152,8 @@ var Kotlin = {};
descriptors[name] = {value: value};
}
else {
- descriptors[name] = {value: value};
+ // we assume all our std lib functions are open
+ descriptors[name] = {value: value, writable: true};
}
}
}
View
10 js/js.translator/testFiles/stdlib/cases/browserDocumentAccess.kt
@@ -0,0 +1,10 @@
+package test.browser
+
+import kotlin.browser.document
+
+fun foo() {
+ val element = document.getElementById("foo")
+ if (element != null) {
+ element.appendChild(document.createTextNode("Some Dynamically Created Contenet!!!"))
+ }
+}
View
13 js/js.translator/testFiles/test.html
@@ -0,0 +1,13 @@
+<!-- Only for developers -->
+<html>
+<head>
+ <script src="kotlin_lib_ecma5.js"></script>
+ <script src="kotlin_lib.js"></script>
+ <script src="webDemoExamples2/out/life_v5.js"></script>
+ <script>
+ //console.assert(Kotlin.defs.foo.box());
+ </script>
+</head>
+<body>
+</body>
+</html>
View
13 libraries/stdlib/src/js/Annotations.kt
@@ -0,0 +1,13 @@
+package js
+
+/**
+ * This annotation marks code as being a native JavaScript expression
+ */
+native
+annotation class native(name : String = "") {}
+
+/**
+ * Represents a function in the standard library
+ */
+native
+annotation class library(name : String = "") {}
View
3  libraries/stdlib/src/kotlin/browser/Properties.kt
@@ -1,13 +1,14 @@
package kotlin.browser
import org.w3c.dom.Document
+import js.native
private var _document: Document? = null
/**
* Provides access to the current active browsers DOM for the currently visible page.
*/
-var document: Document
+native var document: Document
get() = _document!!
set(value) {
_document = value

No commit comments for this range

Something went wrong with that request. Please try again.