Parser for JetBlockCodeFragment
This commit is contained in:
@@ -152,4 +152,5 @@ public interface JetNodeTypes {
|
|||||||
|
|
||||||
IFileElementType TYPE_CODE_FRAGMENT = new JetTypeCodeFragmentType();
|
IFileElementType TYPE_CODE_FRAGMENT = new JetTypeCodeFragmentType();
|
||||||
IFileElementType EXPRESSION_CODE_FRAGMENT = new JetExpressionCodeFragmentType();
|
IFileElementType EXPRESSION_CODE_FRAGMENT = new JetExpressionCodeFragmentType();
|
||||||
|
IFileElementType BLOCK_CODE_FRAGMENT = new JetBlockCodeFragmentType();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,4 +65,11 @@ public class JetParser implements PsiParser {
|
|||||||
jetParsing.parseExpressionCodeFragment();
|
jetParsing.parseExpressionCodeFragment();
|
||||||
return psiBuilder.getTreeBuilt();
|
return psiBuilder.getTreeBuilt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static ASTNode parseBlockCodeFragment(PsiBuilder psiBuilder) {
|
||||||
|
JetParsing jetParsing = JetParsing.createForTopLevel(new SemanticWhitespaceAwarePsiBuilderImpl(psiBuilder));
|
||||||
|
jetParsing.parseBlockCodeFragment();
|
||||||
|
return psiBuilder.getTreeBuilt();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,7 +97,9 @@ public class JetParserDefinition implements ParserDefinition {
|
|||||||
if (elementType instanceof JetStubElementType) {
|
if (elementType instanceof JetStubElementType) {
|
||||||
return ((JetStubElementType) elementType).createPsiFromAst(astNode);
|
return ((JetStubElementType) elementType).createPsiFromAst(astNode);
|
||||||
}
|
}
|
||||||
else if (elementType == JetNodeTypes.TYPE_CODE_FRAGMENT || elementType == JetNodeTypes.EXPRESSION_CODE_FRAGMENT) {
|
else if (elementType == JetNodeTypes.TYPE_CODE_FRAGMENT ||
|
||||||
|
elementType == JetNodeTypes.EXPRESSION_CODE_FRAGMENT ||
|
||||||
|
elementType == JetNodeTypes.BLOCK_CODE_FRAGMENT) {
|
||||||
return new ASTWrapperPsiElement(astNode);
|
return new ASTWrapperPsiElement(astNode);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
@@ -106,10 +106,7 @@ public class JetParsing extends AbstractJetParsing {
|
|||||||
PsiBuilder.Marker marker = mark();
|
PsiBuilder.Marker marker = mark();
|
||||||
parseTypeRef();
|
parseTypeRef();
|
||||||
|
|
||||||
while (!eof()) {
|
checkForUnexpectedSymbols();
|
||||||
error("unexpected symbol");
|
|
||||||
advance();
|
|
||||||
}
|
|
||||||
|
|
||||||
marker.done(TYPE_CODE_FRAGMENT);
|
marker.done(TYPE_CODE_FRAGMENT);
|
||||||
}
|
}
|
||||||
@@ -118,14 +115,29 @@ public class JetParsing extends AbstractJetParsing {
|
|||||||
PsiBuilder.Marker marker = mark();
|
PsiBuilder.Marker marker = mark();
|
||||||
myExpressionParsing.parseExpression();
|
myExpressionParsing.parseExpression();
|
||||||
|
|
||||||
while (!eof()) {
|
checkForUnexpectedSymbols();
|
||||||
error("unexpected symbol");
|
|
||||||
advance();
|
|
||||||
}
|
|
||||||
|
|
||||||
marker.done(EXPRESSION_CODE_FRAGMENT);
|
marker.done(EXPRESSION_CODE_FRAGMENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void parseBlockCodeFragment() {
|
||||||
|
PsiBuilder.Marker marker = mark();
|
||||||
|
PsiBuilder.Marker blockMarker = mark();
|
||||||
|
|
||||||
|
if (at(PACKAGE_KEYWORD) || at(IMPORT_KEYWORD)) {
|
||||||
|
PsiBuilder.Marker err = mark();
|
||||||
|
parsePreamble();
|
||||||
|
err.error("Package directive and imports are forbidden in code fragments");
|
||||||
|
}
|
||||||
|
|
||||||
|
myExpressionParsing.parseStatements();
|
||||||
|
|
||||||
|
checkForUnexpectedSymbols();
|
||||||
|
|
||||||
|
blockMarker.done(BLOCK);
|
||||||
|
marker.done(BLOCK_CODE_FRAGMENT);
|
||||||
|
}
|
||||||
|
|
||||||
void parseScript() {
|
void parseScript() {
|
||||||
PsiBuilder.Marker fileMarker = mark();
|
PsiBuilder.Marker fileMarker = mark();
|
||||||
|
|
||||||
@@ -137,11 +149,19 @@ public class JetParsing extends AbstractJetParsing {
|
|||||||
|
|
||||||
myExpressionParsing.parseStatements();
|
myExpressionParsing.parseStatements();
|
||||||
|
|
||||||
|
checkForUnexpectedSymbols();
|
||||||
|
|
||||||
blockMarker.done(BLOCK);
|
blockMarker.done(BLOCK);
|
||||||
scriptMarker.done(SCRIPT);
|
scriptMarker.done(SCRIPT);
|
||||||
fileMarker.done(JET_FILE);
|
fileMarker.done(JET_FILE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkForUnexpectedSymbols() {
|
||||||
|
while (!eof()) {
|
||||||
|
errorAndAdvance("unexpected symbol");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
*preamble
|
*preamble
|
||||||
* : packageDirective? import*
|
* : packageDirective? import*
|
||||||
|
|||||||
@@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2014 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.lang.psi
|
||||||
|
|
||||||
|
import com.intellij.openapi.project.Project
|
||||||
|
import com.intellij.psi.PsiElement
|
||||||
|
import org.jetbrains.jet.JetNodeTypes
|
||||||
|
|
||||||
|
public class JetBlockCodeFragment(
|
||||||
|
project: Project,
|
||||||
|
name: String,
|
||||||
|
text: CharSequence,
|
||||||
|
context: PsiElement?
|
||||||
|
) : JetCodeFragment(project, name, text, JetNodeTypes.BLOCK_CODE_FRAGMENT, context) {
|
||||||
|
|
||||||
|
fun getBlock() = findChildByClass(javaClass<JetBlockExpression>()) ?: throw IllegalStateException("Block expression should be parsed for BlockCodeFragment")
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2014 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.lang.psi;
|
||||||
|
|
||||||
|
import com.intellij.lang.ASTNode;
|
||||||
|
import com.intellij.lang.Language;
|
||||||
|
import com.intellij.lang.PsiBuilder;
|
||||||
|
import com.intellij.lang.PsiBuilderFactory;
|
||||||
|
import com.intellij.openapi.project.Project;
|
||||||
|
import com.intellij.psi.PsiElement;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.lang.parsing.JetParser;
|
||||||
|
import org.jetbrains.jet.lang.psi.stubs.elements.JetFileElementType;
|
||||||
|
|
||||||
|
public class JetBlockCodeFragmentType extends JetFileElementType {
|
||||||
|
private static final String NAME = "jet.BLOCK_CODE_FRAGMENT";
|
||||||
|
|
||||||
|
public JetBlockCodeFragmentType() {
|
||||||
|
super(NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public String getExternalId() {
|
||||||
|
return NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ASTNode doParseContents(@NotNull ASTNode chameleon, @NotNull PsiElement psi) {
|
||||||
|
Project project = psi.getProject();
|
||||||
|
Language languageForParser = getLanguageForParser(psi);
|
||||||
|
PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, null, languageForParser, chameleon.getChars());
|
||||||
|
return JetParser.parseBlockCodeFragment(builder).getFirstChildNode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -344,6 +344,11 @@ public class JetPsiFactory {
|
|||||||
return new JetExpressionCodeFragment(project, "fragment.kt", text, context);
|
return new JetExpressionCodeFragment(project, "fragment.kt", text, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public static JetBlockCodeFragment createBlockCodeFragment(Project project, String text, PsiElement context) {
|
||||||
|
return new JetBlockCodeFragment(project, "fragment.kt", text, context);
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static JetReturnExpression createReturn(Project project, @NotNull String text) {
|
public static JetReturnExpression createReturn(Project project, @NotNull String text) {
|
||||||
return (JetReturnExpression) createExpression(project, "return " + text);
|
return (JetReturnExpression) createExpression(project, "return " + text);
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
val a = 1
|
||||||
|
1 + 1
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
JetFile: fragment.kt
|
||||||
|
BLOCK
|
||||||
|
PROPERTY
|
||||||
|
PsiElement(val)('val')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(IDENTIFIER)('a')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(EQ)('=')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
INTEGER_CONSTANT
|
||||||
|
PsiElement(INTEGER_LITERAL)('1')
|
||||||
|
PsiWhiteSpace('\n')
|
||||||
|
BINARY_EXPRESSION
|
||||||
|
INTEGER_CONSTANT
|
||||||
|
PsiElement(INTEGER_LITERAL)('1')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
OPERATION_REFERENCE
|
||||||
|
PsiElement(PLUS)('+')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
INTEGER_CONSTANT
|
||||||
|
PsiElement(INTEGER_LITERAL)('1')
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
import a
|
||||||
|
val a = 1
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
JetFile: fragment.kt
|
||||||
|
BLOCK
|
||||||
|
PsiErrorElement:Package directive and imports are forbidden in code fragments
|
||||||
|
PACKAGE_DIRECTIVE
|
||||||
|
<empty list>
|
||||||
|
IMPORT_LIST
|
||||||
|
IMPORT_DIRECTIVE
|
||||||
|
PsiElement(import)('import')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('a')
|
||||||
|
PsiWhiteSpace('\n')
|
||||||
|
PROPERTY
|
||||||
|
PsiElement(val)('val')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(IDENTIFIER)('a')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(EQ)('=')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
INTEGER_CONSTANT
|
||||||
|
PsiElement(INTEGER_LITERAL)('1')
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fun foo() = 1
|
||||||
|
foo()
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
JetFile: fragment.kt
|
||||||
|
BLOCK
|
||||||
|
FUN
|
||||||
|
PsiElement(fun)('fun')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(IDENTIFIER)('foo')
|
||||||
|
VALUE_PARAMETER_LIST
|
||||||
|
PsiElement(LPAR)('(')
|
||||||
|
PsiElement(RPAR)(')')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(EQ)('=')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
INTEGER_CONSTANT
|
||||||
|
PsiElement(INTEGER_LITERAL)('1')
|
||||||
|
PsiWhiteSpace('\n')
|
||||||
|
CALL_EXPRESSION
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('foo')
|
||||||
|
VALUE_ARGUMENT_LIST
|
||||||
|
PsiElement(LPAR)('(')
|
||||||
|
PsiElement(RPAR)(')')
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val a = 1;val b = 2
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
JetFile: fragment.kt
|
||||||
|
BLOCK
|
||||||
|
PROPERTY
|
||||||
|
PsiElement(val)('val')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(IDENTIFIER)('a')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(EQ)('=')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
INTEGER_CONSTANT
|
||||||
|
PsiElement(INTEGER_LITERAL)('1')
|
||||||
|
PsiElement(SEMICOLON)(';')
|
||||||
|
PROPERTY
|
||||||
|
PsiElement(val)('val')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(IDENTIFIER)('b')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(EQ)('=')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
INTEGER_CONSTANT
|
||||||
|
PsiElement(INTEGER_LITERAL)('2')
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
val a = 1
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
JetFile: fragment.kt
|
||||||
|
BLOCK
|
||||||
|
PROPERTY
|
||||||
|
PsiElement(val)('val')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(IDENTIFIER)('a')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(EQ)('=')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
INTEGER_CONSTANT
|
||||||
|
PsiElement(INTEGER_LITERAL)('1')
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package a
|
||||||
|
|
||||||
|
import foo.*
|
||||||
|
|
||||||
|
val a = 1
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
JetFile: fragment.kt
|
||||||
|
BLOCK
|
||||||
|
PsiErrorElement:Package directive and imports are forbidden in code fragments
|
||||||
|
PACKAGE_DIRECTIVE
|
||||||
|
PsiElement(package)('package')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('a')
|
||||||
|
PsiWhiteSpace('\n\n')
|
||||||
|
IMPORT_LIST
|
||||||
|
IMPORT_DIRECTIVE
|
||||||
|
PsiElement(import)('import')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('foo')
|
||||||
|
PsiElement(DOT)('.')
|
||||||
|
PsiElement(MUL)('*')
|
||||||
|
PsiWhiteSpace('\n\n')
|
||||||
|
PROPERTY
|
||||||
|
PsiElement(val)('val')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(IDENTIFIER)('a')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(EQ)('=')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
INTEGER_CONSTANT
|
||||||
|
PsiElement(INTEGER_LITERAL)('1')
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
package a
|
||||||
|
val a = 1
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
JetFile: fragment.kt
|
||||||
|
BLOCK
|
||||||
|
PsiErrorElement:Package directive and imports are forbidden in code fragments
|
||||||
|
PACKAGE_DIRECTIVE
|
||||||
|
PsiElement(package)('package')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('a')
|
||||||
|
PsiWhiteSpace('\n')
|
||||||
|
PROPERTY
|
||||||
|
PsiElement(val)('val')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(IDENTIFIER)('a')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(EQ)('=')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
INTEGER_CONSTANT
|
||||||
|
PsiElement(INTEGER_LITERAL)('1')
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
1 + 1
|
||||||
|
1 * 1
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
JetFile: fragment.kt
|
||||||
|
BLOCK
|
||||||
|
BINARY_EXPRESSION
|
||||||
|
INTEGER_CONSTANT
|
||||||
|
PsiElement(INTEGER_LITERAL)('1')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
OPERATION_REFERENCE
|
||||||
|
PsiElement(PLUS)('+')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
INTEGER_CONSTANT
|
||||||
|
PsiElement(INTEGER_LITERAL)('1')
|
||||||
|
PsiWhiteSpace('\n')
|
||||||
|
BINARY_EXPRESSION
|
||||||
|
INTEGER_CONSTANT
|
||||||
|
PsiElement(INTEGER_LITERAL)('1')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
OPERATION_REFERENCE
|
||||||
|
PsiElement(MUL)('*')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
INTEGER_CONSTANT
|
||||||
|
PsiElement(INTEGER_LITERAL)('1')
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
val a = 1
|
||||||
|
val b = 2
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
JetFile: fragment.kt
|
||||||
|
BLOCK
|
||||||
|
PROPERTY
|
||||||
|
PsiElement(val)('val')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(IDENTIFIER)('a')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(EQ)('=')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
INTEGER_CONSTANT
|
||||||
|
PsiElement(INTEGER_LITERAL)('1')
|
||||||
|
PsiWhiteSpace('\n')
|
||||||
|
PROPERTY
|
||||||
|
PsiElement(val)('val')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(IDENTIFIER)('b')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(EQ)('=')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
INTEGER_CONSTANT
|
||||||
|
PsiElement(INTEGER_LITERAL)('2')
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
val a = 1
|
||||||
|
}
|
||||||
|
val b = 4
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
JetFile: fragment.kt
|
||||||
|
BLOCK
|
||||||
|
PROPERTY
|
||||||
|
PsiElement(val)('val')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(IDENTIFIER)('a')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiElement(EQ)('=')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
INTEGER_CONSTANT
|
||||||
|
PsiElement(INTEGER_LITERAL)('1')
|
||||||
|
PsiWhiteSpace('\n')
|
||||||
|
PsiErrorElement:unexpected symbol
|
||||||
|
PsiElement(RBRACE)('}')
|
||||||
|
PsiWhiteSpace('\n')
|
||||||
|
PsiErrorElement:unexpected symbol
|
||||||
|
PsiElement(val)('val')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiErrorElement:unexpected symbol
|
||||||
|
PsiElement(IDENTIFIER)('b')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiErrorElement:unexpected symbol
|
||||||
|
PsiElement(EQ)('=')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
PsiErrorElement:unexpected symbol
|
||||||
|
PsiElement(INTEGER_LITERAL)('4')
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
1 +
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
JetFile: fragment.kt
|
||||||
|
BINARY_EXPRESSION
|
||||||
|
INTEGER_CONSTANT
|
||||||
|
PsiElement(INTEGER_LITERAL)('1')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
OPERATION_REFERENCE
|
||||||
|
PsiElement(PLUS)('+')
|
||||||
|
PsiErrorElement:Expecting an element
|
||||||
|
<empty list>
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
1 + 1
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
JetFile: fragment.kt
|
||||||
|
BINARY_EXPRESSION
|
||||||
|
INTEGER_CONSTANT
|
||||||
|
PsiElement(INTEGER_LITERAL)('1')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
OPERATION_REFERENCE
|
||||||
|
PsiElement(PLUS)('+')
|
||||||
|
PsiWhiteSpace(' ')
|
||||||
|
INTEGER_CONSTANT
|
||||||
|
PsiElement(INTEGER_LITERAL)('1')
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
println(1)
|
||||||
|
}
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
JetFile: unexpectedSymbol.kts
|
||||||
|
PACKAGE_DIRECTIVE
|
||||||
|
<empty list>
|
||||||
|
SCRIPT
|
||||||
|
BLOCK
|
||||||
|
CALL_EXPRESSION
|
||||||
|
REFERENCE_EXPRESSION
|
||||||
|
PsiElement(IDENTIFIER)('println')
|
||||||
|
VALUE_ARGUMENT_LIST
|
||||||
|
PsiElement(LPAR)('(')
|
||||||
|
VALUE_ARGUMENT
|
||||||
|
INTEGER_CONSTANT
|
||||||
|
PsiElement(INTEGER_LITERAL)('1')
|
||||||
|
PsiElement(RPAR)(')')
|
||||||
|
PsiWhiteSpace('\n')
|
||||||
|
PsiErrorElement:unexpected symbol
|
||||||
|
PsiElement(RBRACE)('}')
|
||||||
@@ -18,14 +18,18 @@ package org.jetbrains.jet.parsing;
|
|||||||
|
|
||||||
import com.intellij.openapi.util.io.FileUtil;
|
import com.intellij.openapi.util.io.FileUtil;
|
||||||
import com.intellij.psi.PsiErrorElement;
|
import com.intellij.psi.PsiErrorElement;
|
||||||
|
import com.intellij.psi.PsiFile;
|
||||||
|
import com.intellij.psi.tree.IElementType;
|
||||||
import com.intellij.psi.util.PsiTreeUtil;
|
import com.intellij.psi.util.PsiTreeUtil;
|
||||||
import com.intellij.testFramework.ParsingTestCase;
|
import com.intellij.testFramework.ParsingTestCase;
|
||||||
import com.intellij.util.PathUtil;
|
import com.intellij.util.PathUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.jet.JetNodeTypes;
|
||||||
import org.jetbrains.jet.JetTestCaseBuilder;
|
import org.jetbrains.jet.JetTestCaseBuilder;
|
||||||
import org.jetbrains.jet.lang.parsing.JetParserDefinition;
|
import org.jetbrains.jet.lang.parsing.JetParserDefinition;
|
||||||
import org.jetbrains.jet.lang.psi.IfNotParsed;
|
import org.jetbrains.jet.lang.psi.IfNotParsed;
|
||||||
import org.jetbrains.jet.lang.psi.JetElement;
|
import org.jetbrains.jet.lang.psi.JetElement;
|
||||||
|
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||||
import org.jetbrains.jet.lang.psi.JetVisitorVoid;
|
import org.jetbrains.jet.lang.psi.JetVisitorVoid;
|
||||||
|
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
@@ -72,8 +76,20 @@ public abstract class AbstractJetParsingTest extends ParsingTestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected void doParsingTest(@NotNull String filePath) throws Exception {
|
protected void doParsingTest(@NotNull String filePath) throws Exception {
|
||||||
|
doBaseTest(filePath, JetNodeTypes.JET_FILE);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doExpressionCodeFragmentParsingTest(@NotNull String filePath) throws Exception {
|
||||||
|
doBaseTest(filePath, JetNodeTypes.EXPRESSION_CODE_FRAGMENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void doBlockCodeFragmentParsingTest(@NotNull String filePath) throws Exception {
|
||||||
|
doBaseTest(filePath, JetNodeTypes.BLOCK_CODE_FRAGMENT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void doBaseTest(@NotNull String filePath, @NotNull IElementType fileType) throws Exception {
|
||||||
myFileExt = FileUtil.getExtension(PathUtil.getFileName(filePath));
|
myFileExt = FileUtil.getExtension(PathUtil.getFileName(filePath));
|
||||||
myFile = createPsiFile(FileUtil.getNameWithoutExtension(PathUtil.getFileName(filePath)), loadFile(filePath));
|
myFile = createFile(filePath, fileType);
|
||||||
|
|
||||||
myFile.acceptChildren(new JetVisitorVoid() {
|
myFile.acceptChildren(new JetVisitorVoid() {
|
||||||
@Override
|
@Override
|
||||||
@@ -90,4 +106,16 @@ public abstract class AbstractJetParsingTest extends ParsingTestCase {
|
|||||||
|
|
||||||
doCheckResult(myFullDataPath, filePath.replaceAll("\\.kts?", ".txt"), toParseTreeText(myFile, false, false).trim());
|
doCheckResult(myFullDataPath, filePath.replaceAll("\\.kts?", ".txt"), toParseTreeText(myFile, false, false).trim());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private PsiFile createFile(@NotNull String filePath, @NotNull IElementType fileType) throws Exception {
|
||||||
|
if (fileType == JetNodeTypes.EXPRESSION_CODE_FRAGMENT) {
|
||||||
|
return JetPsiFactory.createExpressionCodeFragment(myProject, loadFile(filePath), null);
|
||||||
|
}
|
||||||
|
else if (fileType == JetNodeTypes.BLOCK_CODE_FRAGMENT) {
|
||||||
|
return JetPsiFactory.createBlockCodeFragment(myProject, loadFile(filePath), null);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return createPsiFile(FileUtil.getNameWithoutExtension(PathUtil.getFileName(filePath)), loadFile(filePath));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -139,6 +139,8 @@ fun main(args: Array<String>) {
|
|||||||
|
|
||||||
testClass(javaClass<AbstractJetParsingTest>()) {
|
testClass(javaClass<AbstractJetParsingTest>()) {
|
||||||
model("psi", testMethod = "doParsingTest", pattern = "^(.*)\\.kts?$")
|
model("psi", testMethod = "doParsingTest", pattern = "^(.*)\\.kts?$")
|
||||||
|
model("parseCodeFragment/expression", testMethod = "doExpressionCodeFragmentParsingTest", extension = "kt")
|
||||||
|
model("parseCodeFragment/block", testMethod = "doBlockCodeFragmentParsingTest", extension = "kt")
|
||||||
}
|
}
|
||||||
|
|
||||||
GenerateRangesCodegenTestData.main(array<String>())
|
GenerateRangesCodegenTestData.main(array<String>())
|
||||||
|
|||||||
Reference in New Issue
Block a user