Compare commits

...

4 Commits

Author SHA1 Message Date
Andrey Breslav
9b3ad30290 [experiment] Some minor tweaks 2015-09-21 11:25:59 +03:00
Andrey Breslav
dd44c71db7 [experiment] Treat '^' as comment and action to insert it 2015-09-20 02:34:42 +03:00
Andrey Breslav
d2f96b4df3 [experiment] Treat '^' as whitespace 2015-09-20 02:34:42 +03:00
Andrey Breslav
01ec840905 Minor. Rename Ant project from JetLexer to KotlnLexer 2015-09-20 02:34:41 +03:00
6 changed files with 561 additions and 454 deletions

View File

@@ -1,4 +1,4 @@
<project name="JetLexer" default="lexer">
<project name="KotlinLexer" default="lexer">
<property name="home" value="${basedir}"/>
<property name="flex.base" value="${home}/../../dependencies/jflex"/>
<property name="out.dir" value="${basedir}/tmpout"/>

View File

@@ -1,4 +1,4 @@
/* The following code was generated by JFlex 1.4.3 on 4/24/15 7:12 PM */
/* The following code was generated by JFlex 1.4.3 on 9/19/15 9:15 PM */
package org.jetbrains.kotlin.kdoc.lexer;
@@ -6,16 +6,14 @@ import com.intellij.lexer.FlexLexer;
import com.intellij.psi.TokenType;
import com.intellij.psi.tree.IElementType;
import com.intellij.util.text.CharArrayUtil;
import java.lang.Character;
import org.jetbrains.kotlin.lexer.JetTokens;
import org.jetbrains.kotlin.kdoc.parser.KDocKnownTag;
/**
* This class is a scanner generated by
* <a href="http://www.jflex.de/">JFlex</a> 1.4.3
* on 4/24/15 7:12 PM from the specification file
* <tt>/home/sufix/work/kotlin/compiler/frontend/src/org/jetbrains/kotlin/kdoc/lexer/KDoc.flex</tt>
* on 9/19/15 9:15 PM from the specification file
* <tt>/Users/abreslav/work/kotlin/compiler/frontend/src/org/jetbrains/kotlin/kdoc/lexer/KDoc.flex</tt>
*/
class _KDocLexer implements FlexLexer {
/** initial size of the lookahead buffer */
@@ -47,81 +45,63 @@ class _KDocLexer implements FlexLexer {
"\1\14\1\15\1\10\3\0\1\4\1\7\12\2\6\0\1\11\32\3"+
"\1\5\1\13\1\6\1\0\1\3\1\0\32\3\47\0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3\0\30\3\1\0\11\3\1\0\1\3\2\0\7\3\72\0"+
"\60\3\1\0\2\3\13\0\10\3\72\0\2\3\1\0\1\3\2\0"+
"\2\3\1\0\1\3\2\0\1\3\6\0\4\3\1\0\7\3\1\0"+
"\3\3\1\0\1\3\1\0\1\3\2\0\2\3\1\0\4\3\1\0"+
"\2\3\11\0\1\3\2\0\5\3\1\0\1\3\25\0\2\3\42\0"+
"\1\3\77\0\10\3\1\0\44\3\33\0\5\3\163\0\53\3\24\0"+
"\1\3\20\0\6\3\4\0\4\3\3\0\1\3\3\0\2\3\7\0"+
"\3\3\4\0\15\3\14\0\1\3\21\0\46\3\12\0\53\3\1\0"+
"\1\3\3\0\u0149\3\1\0\4\3\2\0\7\3\1\0\1\3\1\0"+
"\4\3\2\0\51\3\1\0\4\3\2\0\41\3\1\0\4\3\2\0"+
"\7\3\1\0\1\3\1\0\4\3\2\0\17\3\1\0\71\3\1\0"+
"\4\3\2\0\103\3\45\0\20\3\20\0\125\3\14\0\u026c\3\2\0"+
"\21\3\1\0\32\3\5\0\113\3\3\0\3\3\17\0\15\3\1\0"+
"\4\3\16\0\22\3\16\0\22\3\16\0\15\3\1\0\3\3\17\0"+
"\64\3\43\0\1\3\3\0\2\3\103\0\130\3\10\0\51\3\1\0"+
"\1\3\5\0\106\3\12\0\35\3\63\0\36\3\2\0\5\3\13\0"+
"\54\3\25\0\7\3\70\0\27\3\11\0\65\3\122\0\1\3\135\0"+
"\57\3\21\0\7\3\67\0\36\3\15\0\2\3\20\0\46\3\32\0"+
"\44\3\51\0\3\3\12\0\44\3\153\0\4\3\1\0\4\3\16\0"+
"\300\3\100\0\u0116\3\2\0\6\3\2\0\46\3\2\0\6\3\2\0"+
"\10\3\1\0\1\3\1\0\1\3\1\0\1\3\1\0\37\3\2\0"+
"\65\3\1\0\7\3\1\0\1\3\3\0\3\3\1\0\7\3\3\0"+
"\4\3\2\0\6\3\4\0\15\3\5\0\3\3\1\0\7\3\102\0"+
"\2\3\23\0\1\3\34\0\1\3\15\0\1\3\20\0\15\3\3\0"+
"\32\3\110\0\1\3\4\0\1\3\2\0\12\3\1\0\1\3\3\0"+
"\5\3\6\0\1\3\1\0\1\3\1\0\1\3\1\0\4\3\1\0"+
"\13\3\2\0\4\3\5\0\5\3\4\0\1\3\21\0\51\3\u0a77\0"+
"\57\3\1\0\57\3\1\0\205\3\6\0\4\3\21\0\46\3\12\0"+
"\66\3\11\0\1\3\20\0\27\3\11\0\7\3\1\0\7\3\1\0"+
"\7\3\1\0\7\3\1\0\7\3\1\0\7\3\1\0\7\3\1\0"+
"\7\3\120\0\1\3\u01d5\0\3\3\31\0\11\3\7\0\5\3\2\0"+
"\5\3\4\0\126\3\6\0\3\3\1\0\132\3\1\0\4\3\5\0"+
"\51\3\3\0\136\3\21\0\33\3\65\0\20\3\u0200\0\u19b6\3\112\0"+
"\u51cc\3\64\0\u048d\3\103\0\56\3\2\0\u010d\3\3\0\20\3\12\0"+
"\2\3\24\0\57\3\20\0\31\3\10\0\120\3\47\0\11\3\2\0"+
"\147\3\2\0\4\3\1\0\2\3\16\0\12\3\120\0\10\3\1\0"+
"\3\3\1\0\4\3\1\0\27\3\25\0\1\3\7\0\64\3\16\0"+
"\62\3\76\0\6\3\3\0\1\3\16\0\34\3\12\0\27\3\31\0"+
"\35\3\7\0\57\3\34\0\1\3\60\0\51\3\27\0\3\3\1\0"+
"\10\3\24\0\27\3\3\0\1\3\5\0\60\3\1\0\1\3\3\0"+
"\2\3\2\0\5\3\2\0\1\3\1\0\1\3\30\0\3\3\43\0"+
"\6\3\2\0\6\3\2\0\6\3\11\0\7\3\1\0\7\3\221\0"+
"\43\3\35\0\u2ba4\3\14\0\27\3\4\0\61\3\u2104\0\u012e\3\2\0"+
"\76\3\2\0\152\3\46\0\7\3\14\0\5\3\5\0\1\3\1\0"+
"\12\3\1\0\15\3\1\0\5\3\1\0\1\3\1\0\2\3\1\0"+
"\2\3\1\0\154\3\41\0\u016b\3\22\0\100\3\2\0\66\3\50\0"+
"\15\3\66\0\2\3\30\0\3\3\31\0\1\3\6\0\5\3\1\0"+
"\207\3\7\0\1\3\34\0\32\3\4\0\1\3\1\0\32\3\13\0"+
"\131\3\3\0\6\3\2\0\6\3\2\0\6\3\2\0\3\3\3\0"+
"\2\3\3\0\2\3\31\0";
"\1\3\1\0\2\3\43\0\10\3\1\0\3\3\1\0\27\3\1\0"+
"\20\3\46\0\2\3\43\0\22\3\3\0\30\3\1\0\11\3\1\0"+
"\1\3\2\0\7\3\72\0\60\3\1\0\2\3\13\0\10\3\72\0"+
"\2\3\1\0\1\3\2\0\2\3\1\0\1\3\2\0\1\3\6\0"+
"\4\3\1\0\7\3\1\0\3\3\1\0\1\3\1\0\1\3\2\0"+
"\2\3\1\0\4\3\1\0\2\3\11\0\1\3\2\0\5\3\1\0"+
"\1\3\25\0\2\3\42\0\1\3\77\0\10\3\1\0\42\3\35\0"+
"\4\3\164\0\42\3\1\0\5\3\1\0\2\3\45\0\6\3\112\0"+
"\46\3\12\0\51\3\7\0\132\3\5\0\104\3\5\0\122\3\6\0"+
"\7\3\1\0\77\3\1\0\1\3\1\0\4\3\2\0\7\3\1\0"+
"\1\3\1\0\4\3\2\0\47\3\1\0\1\3\1\0\4\3\2\0"+
"\37\3\1\0\1\3\1\0\4\3\2\0\7\3\1\0\1\3\1\0"+
"\4\3\2\0\7\3\1\0\7\3\1\0\27\3\1\0\37\3\1\0"+
"\1\3\1\0\4\3\2\0\7\3\1\0\47\3\1\0\23\3\105\0"+
"\125\3\14\0\u026c\3\2\0\10\3\12\0\32\3\5\0\113\3\3\0"+
"\3\3\17\0\15\3\1\0\4\3\16\0\22\3\16\0\22\3\16\0"+
"\15\3\1\0\3\3\17\0\64\3\43\0\1\3\3\0\2\3\103\0"+
"\130\3\10\0\51\3\127\0\35\3\63\0\36\3\2\0\5\3\u038b\0"+
"\154\3\224\0\234\3\4\0\132\3\6\0\26\3\2\0\6\3\2\0"+
"\46\3\2\0\6\3\2\0\10\3\1\0\1\3\1\0\1\3\1\0"+
"\1\3\1\0\37\3\2\0\65\3\1\0\7\3\1\0\1\3\3\0"+
"\3\3\1\0\7\3\3\0\4\3\2\0\6\3\4\0\15\3\5\0"+
"\3\3\1\0\7\3\102\0\2\3\23\0\1\3\34\0\1\3\15\0"+
"\1\3\40\0\22\3\120\0\1\3\4\0\1\3\2\0\12\3\1\0"+
"\1\3\3\0\5\3\6\0\1\3\1\0\1\3\1\0\1\3\1\0"+
"\4\3\1\0\3\3\1\0\7\3\3\0\3\3\5\0\5\3\26\0"+
"\44\3\u0e81\0\3\3\31\0\11\3\7\0\5\3\2\0\5\3\4\0"+
"\126\3\6\0\3\3\1\0\137\3\5\0\50\3\4\0\136\3\21\0"+
"\30\3\70\0\20\3\u0200\0\u19b6\3\112\0\u51a6\3\132\0\u048d\3\u0773\0"+
"\u2ba4\3\u215c\0\u012e\3\2\0\73\3\225\0\7\3\14\0\5\3\5\0"+
"\1\3\1\0\12\3\1\0\15\3\1\0\5\3\1\0\1\3\1\0"+
"\2\3\1\0\2\3\1\0\154\3\41\0\u016b\3\22\0\100\3\2\0"+
"\66\3\50\0\15\3\66\0\2\3\30\0\3\3\31\0\1\3\6\0"+
"\5\3\1\0\207\3\7\0\1\3\34\0\32\3\4\0\1\3\1\0"+
"\32\3\12\0\132\3\3\0\6\3\2\0\6\3\2\0\6\3\2\0"+
"\3\3\3\0\2\3\3\0\2\3\31\0";
/**
* Translates characters to character classes
@@ -359,7 +339,7 @@ class _KDocLexer implements FlexLexer {
char [] map = new char[0x10000];
int i = 0; /* index in packed string */
int j = 0; /* index in unpacked array */
while (i < 1568) {
while (i < 1212) {
int count = packed.charAt(i++);
char value = packed.charAt(i++);
do map[j++] = value; while (--count > 0);

View File

@@ -174,6 +174,9 @@ LONG_TEMPLATE_ENTRY_START=\$\{
// (Nested) comments
"^" {
return JetTokens.BLOCK_COMMENT;
}
"/**/" {
return JetTokens.BLOCK_COMMENT;
}

View File

@@ -124,6 +124,12 @@
<add-to-group group-id="KotlinToolsGroup" anchor="last"/>
</action>
<action id="AddHatsAction" class="org.jetbrains.kotlin.idea.actions.internal.AddHatsAction"
text="[experiment] Add Hats to Resulting Expressions">
<keyboard-shortcut keymap="$default" first-keystroke="control alt shift Z"/>
<add-to-group group-id="KotlinToolsGroup" anchor="last"/>
</action>
<action id="CheckPartialBodyResolve" class="org.jetbrains.kotlin.idea.actions.internal.CheckPartialBodyResolveAction"
text="Check Partial Body Resolve">
<add-to-group group-id="KotlinToolsGroup" anchor="last"/>

View File

@@ -0,0 +1,118 @@
/*
* Copyright 2010-2015 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.kotlin.idea.actions.internal
import com.intellij.openapi.actionSystem.AnAction
import com.intellij.openapi.actionSystem.AnActionEvent
import com.intellij.openapi.actionSystem.CommonDataKeys
import com.intellij.openapi.application.ApplicationManager
import com.intellij.openapi.application.Result
import com.intellij.openapi.command.WriteCommandAction
import com.intellij.openapi.vfs.VfsUtil
import com.intellij.psi.PsiManager
import com.intellij.psi.impl.source.tree.LeafPsiElement
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
import org.jetbrains.kotlin.idea.caches.resolve.analyzeFully
import org.jetbrains.kotlin.lexer.JetTokens
import org.jetbrains.kotlin.psi.*
import org.jetbrains.kotlin.resolve.BindingContext
import org.jetbrains.kotlin.resolve.bindingContextUtil.isUsedAsExpression
public class AddHatsAction : AnAction() {
override fun actionPerformed(e: AnActionEvent) {
val virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE)
?: return
val virtualFiles = VfsUtil.collectChildrenRecursively(virtualFile)
val project = e.project!!
val jetFiles = virtualFiles.map {
PsiManager.getInstance(project).findFile(it) as? JetFile
}.filterNotNull().toTypedArray()
object : WriteCommandAction<Any?>(project, *jetFiles) {
override fun run(result: Result<Any?>) {
for (jetFile in jetFiles) {
val bindingContext = jetFile.analyzeFully()
jetFile.accept(
object : JetTreeVisitorVoid() {
override fun visitBlockExpression(expression: JetBlockExpression) {
val parent = expression.parent
if (parent !is JetDeclaration) {
addHats(expression.statements)
}
super.visitBlockExpression(expression)
}
override fun visitFunctionLiteralExpression(expression: JetFunctionLiteralExpression) {
addHats(expression.bodyExpression?.statements ?: emptyList())
super.visitFunctionLiteralExpression(expression)
}
private fun addHats(statements: List<JetExpression>) {
if (statements.size() <= 1) return
val lastExpression = statements.last()
if (!lastExpression.isUsedAsExpression(bindingContext)) {
println("Not used as expression: $lastExpression")
return
}
val type = bindingContext.get(BindingContext.EXPRESSION_TYPE_INFO, lastExpression)?.type
if (type == null) {
println("Type is null: $lastExpression")
}
if (type != null && (KotlinBuiltIns.isUnit(type) || KotlinBuiltIns.isNothing(type))) {
println("Type is Unit/Nothing: $lastExpression")
return
}
val expectedType = bindingContext.get(BindingContext.EXPECTED_EXPRESSION_TYPE, lastExpression)
if (expectedType != null && (KotlinBuiltIns.isUnit(expectedType) || KotlinBuiltIns.isNothing(expectedType))) {
println("Expected Type is Unit/Nothing: $lastExpression")
return
}
val node = lastExpression.node
val space = node.treePrev
val oldText = space.text
val newText = if (oldText.endsWith("^")) oldText else oldText.removeSuffix(" ") + "^"
node.treeParent.replaceChild(
space,
LeafPsiElement(JetTokens.BLOCK_COMMENT, newText)
)
}
}
)
}
}
}.execute()
}
override fun update(e: AnActionEvent?) {
e!!.presentation.isVisible = ApplicationManager.getApplication().isInternal
val virtualFile = e.getData(CommonDataKeys.VIRTUAL_FILE)
e.presentation.isEnabled = virtualFile != null
}
}