Merge branch master into pr/269
This commit is contained in:
@@ -46,6 +46,8 @@
|
||||
<target name="lexer">
|
||||
<echo message="${flex.base}"/>
|
||||
<flex flexfile="${home}/src/org/jetbrains/jet/lexer/Jet.flex"
|
||||
destdir="${home}//src/org/jetbrains/jet/lexer/"/>
|
||||
destdir="${home}/src/org/jetbrains/jet/lexer/"/>
|
||||
<flex flexfile="${home}/src/org/jetbrains/jet/kdoc/lexer/KDoc.flex"
|
||||
destdir="${home}/src/org/jetbrains/jet/kdoc/lexer/"/>
|
||||
</target>
|
||||
</project>
|
||||
|
||||
@@ -65,18 +65,12 @@ public open class Throwable(message : String? = null, cause: Throwable? = null)
|
||||
public fun printStackTrace() : Unit
|
||||
}
|
||||
|
||||
/*
|
||||
* Should have an abstract property 'name', overridden in PropertyMetadataImpl
|
||||
*/
|
||||
public trait PropertyMetadata {
|
||||
public fun getName(): String
|
||||
public val name: String
|
||||
}
|
||||
|
||||
/*
|
||||
* In front-end we need to resolve call PropertyMetadataImpl() in getter of delegated property
|
||||
* to be able generate it in back-end using ExpressionCodegen.invokeFunction
|
||||
*/
|
||||
public class PropertyMetadataImpl(private val innerName: String): PropertyMetadata {
|
||||
public override fun getName(): String = innerName
|
||||
}
|
||||
|
||||
public class PropertyMetadataImpl(public override val name: String): PropertyMetadata
|
||||
|
||||
@@ -0,0 +1,95 @@
|
||||
package org.jetbrains.jet.kdoc.lexer;
|
||||
|
||||
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;
|
||||
|
||||
%%
|
||||
|
||||
%unicode
|
||||
%class _KDocLexer
|
||||
%implements FlexLexer
|
||||
|
||||
%{
|
||||
public _KDocLexer() {
|
||||
this((java.io.Reader)null);
|
||||
}
|
||||
|
||||
private boolean isLastToken() {
|
||||
return zzMarkedPos == zzBuffer.length();
|
||||
}
|
||||
|
||||
private Boolean yytextContainLineBreaks() {
|
||||
return CharArrayUtil.containLineBreaks(zzBuffer, zzStartRead, zzMarkedPos);
|
||||
}
|
||||
|
||||
private boolean nextIsNotWhitespace() {
|
||||
return zzMarkedPos <= zzBuffer.length() && !Character.isWhitespace(zzBuffer.charAt(zzMarkedPos + 1));
|
||||
}
|
||||
|
||||
private boolean prevIsNotWhitespace() {
|
||||
return zzMarkedPos != 0 && !Character.isWhitespace(zzBuffer.charAt(zzMarkedPos - 1));
|
||||
}
|
||||
%}
|
||||
|
||||
%function advance
|
||||
%type IElementType
|
||||
%eof{
|
||||
return;
|
||||
%eof}
|
||||
|
||||
%state LINE_BEGINNING
|
||||
%state CONTENTS_BEGINNING
|
||||
%state CONTENTS
|
||||
%state CODE
|
||||
%state CODE2
|
||||
|
||||
WHITE_SPACE_CHAR =[\ \t\f\n\r]
|
||||
NOT_WHITE_SPACE_CHAR=[^\ \t\f\n\r]
|
||||
|
||||
DIGIT=[0-9]
|
||||
ALPHA=[:jletter:]
|
||||
TAG_NAME={ALPHA}({ALPHA}|{DIGIT})*
|
||||
|
||||
MARKDOWN_EMPHASIS=[\*_]
|
||||
|
||||
%%
|
||||
|
||||
|
||||
<YYINITIAL> "/**" { yybegin(CONTENTS);
|
||||
return KDocTokens.START; }
|
||||
"*"+ "/" { if (isLastToken()) return KDocTokens.END;
|
||||
else return KDocTokens.TEXT; }
|
||||
|
||||
<LINE_BEGINNING> "*"+ { yybegin(CONTENTS_BEGINNING);
|
||||
return KDocTokens.LEADING_ASTERISK; }
|
||||
|
||||
<CONTENTS_BEGINNING> "@"{TAG_NAME} { yybegin(CONTENTS);
|
||||
return KDocTokens.TAG_NAME; }
|
||||
|
||||
<LINE_BEGINNING, CONTENTS_BEGINNING, CONTENTS> {
|
||||
{WHITE_SPACE_CHAR}+ {
|
||||
if (yytextContainLineBreaks()) {
|
||||
yybegin(LINE_BEGINNING);
|
||||
return TokenType.WHITE_SPACE;
|
||||
} else {
|
||||
yybegin(yystate() == CONTENTS_BEGINNING? CONTENTS_BEGINNING:CONTENTS);
|
||||
return KDocTokens.TEXT; // internal white space
|
||||
}
|
||||
}
|
||||
|
||||
"\\"[\[\]] { yybegin(CONTENTS);
|
||||
return KDocTokens.MARKDOWN_ESCAPED_CHAR; }
|
||||
|
||||
"[[" { yybegin(CONTENTS);
|
||||
return KDocTokens.WIKI_LINK_OPEN; }
|
||||
"]]" { yybegin(CONTENTS);
|
||||
return KDocTokens.WIKI_LINK_CLOSE; }
|
||||
|
||||
. { yybegin(CONTENTS);
|
||||
return KDocTokens.TEXT; }
|
||||
}
|
||||
|
||||
. { return TokenType.BAD_CHARACTER; }
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.kdoc.lexer;
|
||||
|
||||
import com.intellij.lexer.FlexAdapter;
|
||||
import com.intellij.lexer.MergingLexerAdapter;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
|
||||
import java.io.Reader;
|
||||
|
||||
public class KDocLexer extends MergingLexerAdapter {
|
||||
public KDocLexer() {
|
||||
super(
|
||||
new FlexAdapter(
|
||||
new _KDocLexer((Reader) null)
|
||||
),
|
||||
TokenSet.create(KDocTokens.TEXT)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.kdoc.lexer;
|
||||
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lexer.JetToken;
|
||||
|
||||
public class KDocToken extends JetToken {
|
||||
public KDocToken(@NotNull @NonNls String debugName) {
|
||||
super(debugName);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.kdoc.lexer;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.PsiBuilder;
|
||||
import com.intellij.lang.PsiBuilderFactory;
|
||||
import com.intellij.lang.PsiParser;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.tree.ILazyParseableElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.kdoc.parser.KDocParser;
|
||||
import org.jetbrains.jet.kdoc.psi.impl.KDocImpl;
|
||||
import org.jetbrains.jet.plugin.JetLanguage;
|
||||
|
||||
public interface KDocTokens {
|
||||
ILazyParseableElementType KDOC = new ILazyParseableElementType("KDoc", JetLanguage.INSTANCE) {
|
||||
@Override
|
||||
public ASTNode parseContents(ASTNode chameleon) {
|
||||
PsiElement parentElement = chameleon.getTreeParent().getPsi();
|
||||
Project project = parentElement.getProject();
|
||||
PsiBuilder builder = PsiBuilderFactory.getInstance().createBuilder(project, chameleon, new KDocLexer(), getLanguage(),
|
||||
chameleon.getText());
|
||||
PsiParser parser = new KDocParser();
|
||||
|
||||
return parser.parse(this, builder).getFirstChildNode();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public ASTNode createNode(CharSequence text) {
|
||||
return new KDocImpl(text);
|
||||
}
|
||||
};
|
||||
|
||||
KDocToken START = new KDocToken("KDOC_START");
|
||||
KDocToken END = new KDocToken("KDOC_END");
|
||||
KDocToken LEADING_ASTERISK = new KDocToken("KDOC_LEADING_ASTERISK");
|
||||
|
||||
KDocToken TEXT = new KDocToken("KDOC_TEXT");
|
||||
KDocToken TAG_NAME = new KDocToken("KDOC_TAG_NAME");
|
||||
KDocToken WIKI_LINK_OPEN = new KDocToken("KDOC_WIKI_LINK_OPEN");
|
||||
KDocToken WIKI_LINK_CLOSE = new KDocToken("KDOC_WIKI_LINK_CLOSE");
|
||||
|
||||
KDocToken MARKDOWN_ESCAPED_CHAR = new KDocToken("KDOC_MARKDOWN_ESCAPED_CHAR");
|
||||
|
||||
TokenSet CONTENT_TOKENS = TokenSet.create(START, END, LEADING_ASTERISK, TEXT, WIKI_LINK_OPEN, WIKI_LINK_CLOSE, MARKDOWN_ESCAPED_CHAR);
|
||||
}
|
||||
@@ -0,0 +1,623 @@
|
||||
/* The following code was generated by JFlex 1.4.3 on 25.05.13 16:39 */
|
||||
|
||||
package org.jetbrains.jet.kdoc.lexer;
|
||||
|
||||
import com.intellij.lexer.FlexLexer;
|
||||
import com.intellij.psi.TokenType;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.util.text.CharArrayUtil;
|
||||
|
||||
|
||||
/**
|
||||
* This class is a scanner generated by
|
||||
* <a href="http://www.jflex.de/">JFlex</a> 1.4.3
|
||||
* on 25.05.13 16:39 from the specification file
|
||||
* <tt>/Users/factitious/Documents/kotlin/compiler/frontend/src/org/jetbrains/jet/kdoc/lexer/KDoc.flex</tt>
|
||||
*/
|
||||
class _KDocLexer implements FlexLexer {
|
||||
/** initial size of the lookahead buffer */
|
||||
private static final int ZZ_BUFFERSIZE = 16384;
|
||||
|
||||
/** lexical states */
|
||||
public static final int CODE = 8;
|
||||
public static final int CONTENTS_BEGINNING = 4;
|
||||
public static final int CODE2 = 10;
|
||||
public static final int LINE_BEGINNING = 2;
|
||||
public static final int CONTENTS = 6;
|
||||
public static final int YYINITIAL = 0;
|
||||
|
||||
/**
|
||||
* ZZ_LEXSTATE[l] is the state in the DFA for the lexical state l
|
||||
* ZZ_LEXSTATE[l+1] is the state in the DFA for the lexical state l
|
||||
* at the beginning of a line
|
||||
* l is of the form l = 2*k, k a non negative integer
|
||||
*/
|
||||
private static final int ZZ_LEXSTATE[] = {
|
||||
0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 4, 4
|
||||
};
|
||||
|
||||
/**
|
||||
* Translates characters to character classes
|
||||
*/
|
||||
private static final String ZZ_CMAP_PACKED =
|
||||
"\11\0\1\1\1\12\1\0\2\1\22\0\1\1\3\0\1\3\5\0"+
|
||||
"\1\4\4\0\1\5\12\2\6\0\1\6\32\3\1\11\1\7\1\10"+
|
||||
"\1\0\1\3\1\0\32\3\47\0\4\3\4\0\1\3\12\0\1\3"+
|
||||
"\4\0\1\3\5\0\27\3\1\0\37\3\1\0\u013f\3\31\0\162\3"+
|
||||
"\4\0\14\3\16\0\5\3\11\0\1\3\213\0\1\3\13\0\1\3"+
|
||||
"\1\0\3\3\1\0\1\3\1\0\24\3\1\0\54\3\1\0\46\3"+
|
||||
"\1\0\5\3\4\0\202\3\10\0\105\3\1\0\46\3\2\0\2\3"+
|
||||
"\6\0\20\3\41\0\46\3\2\0\1\3\7\0\47\3\110\0\33\3"+
|
||||
"\5\0\3\3\56\0\32\3\5\0\13\3\43\0\2\3\1\0\143\3"+
|
||||
"\1\0\1\3\17\0\2\3\7\0\2\3\12\0\3\3\2\0\1\3"+
|
||||
"\20\0\1\3\1\0\36\3\35\0\3\3\60\0\46\3\13\0\1\3"+
|
||||
"\u0152\0\66\3\3\0\1\3\22\0\1\3\7\0\12\3\43\0\10\3"+
|
||||
"\2\0\2\3\2\0\26\3\1\0\7\3\1\0\1\3\3\0\4\3"+
|
||||
"\3\0\1\3\36\0\2\3\1\0\3\3\16\0\4\3\21\0\6\3"+
|
||||
"\4\0\2\3\2\0\26\3\1\0\7\3\1\0\2\3\1\0\2\3"+
|
||||
"\1\0\2\3\37\0\4\3\1\0\1\3\23\0\3\3\20\0\11\3"+
|
||||
"\1\0\3\3\1\0\26\3\1\0\7\3\1\0\2\3\1\0\5\3"+
|
||||
"\3\0\1\3\22\0\1\3\17\0\2\3\17\0\1\3\23\0\10\3"+
|
||||
"\2\0\2\3\2\0\26\3\1\0\7\3\1\0\2\3\1\0\5\3"+
|
||||
"\3\0\1\3\36\0\2\3\1\0\3\3\17\0\1\3\21\0\1\3"+
|
||||
"\1\0\6\3\3\0\3\3\1\0\4\3\3\0\2\3\1\0\1\3"+
|
||||
"\1\0\2\3\3\0\2\3\3\0\3\3\3\0\10\3\1\0\3\3"+
|
||||
"\77\0\1\3\13\0\10\3\1\0\3\3\1\0\27\3\1\0\12\3"+
|
||||
"\1\0\5\3\46\0\2\3\43\0\10\3\1\0\3\3\1\0\27\3"+
|
||||
"\1\0\12\3\1\0\5\3\3\0\1\3\40\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
|
||||
*/
|
||||
private static final char [] ZZ_CMAP = zzUnpackCMap(ZZ_CMAP_PACKED);
|
||||
|
||||
/**
|
||||
* Translates DFA states to action switch labels.
|
||||
*/
|
||||
private static final int [] ZZ_ACTION = zzUnpackAction();
|
||||
|
||||
private static final String ZZ_ACTION_PACKED_0 =
|
||||
"\5\0\3\1\1\2\1\3\1\4\5\2\1\0\1\5"+
|
||||
"\1\0\1\6\1\7\1\10\1\11\1\12";
|
||||
|
||||
private static int [] zzUnpackAction() {
|
||||
int [] result = new int[24];
|
||||
int offset = 0;
|
||||
offset = zzUnpackAction(ZZ_ACTION_PACKED_0, offset, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int zzUnpackAction(String packed, int offset, int [] result) {
|
||||
int i = 0; /* index in packed string */
|
||||
int j = offset; /* index in unpacked array */
|
||||
int l = packed.length();
|
||||
while (i < l) {
|
||||
int count = packed.charAt(i++);
|
||||
int value = packed.charAt(i++);
|
||||
do result[j++] = value; while (--count > 0);
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Translates a state to a row index in the transition table
|
||||
*/
|
||||
private static final int [] ZZ_ROWMAP = zzUnpackRowMap();
|
||||
|
||||
private static final String ZZ_ROWMAP_PACKED_0 =
|
||||
"\0\0\0\13\0\26\0\41\0\54\0\67\0\102\0\115"+
|
||||
"\0\67\0\130\0\143\0\156\0\171\0\204\0\102\0\217"+
|
||||
"\0\102\0\67\0\232\0\67\0\67\0\67\0\245\0\67";
|
||||
|
||||
private static int [] zzUnpackRowMap() {
|
||||
int [] result = new int[24];
|
||||
int offset = 0;
|
||||
offset = zzUnpackRowMap(ZZ_ROWMAP_PACKED_0, offset, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int zzUnpackRowMap(String packed, int offset, int [] result) {
|
||||
int i = 0; /* index in packed string */
|
||||
int j = offset; /* index in unpacked array */
|
||||
int l = packed.length();
|
||||
while (i < l) {
|
||||
int high = packed.charAt(i++) << 16;
|
||||
result[j++] = high | packed.charAt(i++);
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
/**
|
||||
* The transition table of the DFA
|
||||
*/
|
||||
private static final int [] ZZ_TRANS = zzUnpackTrans();
|
||||
|
||||
private static final String ZZ_TRANS_PACKED_0 =
|
||||
"\4\6\1\7\1\10\4\6\1\0\1\11\1\12\2\11"+
|
||||
"\1\13\2\11\1\14\1\15\1\16\1\12\1\11\1\12"+
|
||||
"\2\11\1\17\1\11\1\20\1\14\1\15\1\16\1\12"+
|
||||
"\1\11\1\12\2\11\1\17\2\11\1\14\1\15\1\16"+
|
||||
"\1\12\4\6\1\7\5\6\20\0\1\21\1\22\11\0"+
|
||||
"\1\23\7\0\1\12\10\0\1\12\4\0\1\13\1\22"+
|
||||
"\15\0\2\24\11\0\1\25\13\0\1\26\4\0\1\27"+
|
||||
"\13\0\1\30\10\0\2\27\7\0";
|
||||
|
||||
private static int [] zzUnpackTrans() {
|
||||
int [] result = new int[176];
|
||||
int offset = 0;
|
||||
offset = zzUnpackTrans(ZZ_TRANS_PACKED_0, offset, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int zzUnpackTrans(String packed, int offset, int [] result) {
|
||||
int i = 0; /* index in packed string */
|
||||
int j = offset; /* index in unpacked array */
|
||||
int l = packed.length();
|
||||
while (i < l) {
|
||||
int count = packed.charAt(i++);
|
||||
int value = packed.charAt(i++);
|
||||
value--;
|
||||
do result[j++] = value; while (--count > 0);
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
|
||||
/* error codes */
|
||||
private static final int ZZ_UNKNOWN_ERROR = 0;
|
||||
private static final int ZZ_NO_MATCH = 1;
|
||||
private static final int ZZ_PUSHBACK_2BIG = 2;
|
||||
private static final char[] EMPTY_BUFFER = new char[0];
|
||||
private static final int YYEOF = -1;
|
||||
private static java.io.Reader zzReader = null; // Fake
|
||||
|
||||
/* error messages for the codes above */
|
||||
private static final String ZZ_ERROR_MSG[] = {
|
||||
"Unkown internal scanner error",
|
||||
"Error: could not match input",
|
||||
"Error: pushback value was too large"
|
||||
};
|
||||
|
||||
/**
|
||||
* ZZ_ATTRIBUTE[aState] contains the attributes of state <code>aState</code>
|
||||
*/
|
||||
private static final int [] ZZ_ATTRIBUTE = zzUnpackAttribute();
|
||||
|
||||
private static final String ZZ_ATTRIBUTE_PACKED_0 =
|
||||
"\5\0\1\11\2\1\1\11\7\1\1\0\1\11\1\0"+
|
||||
"\3\11\1\1\1\11";
|
||||
|
||||
private static int [] zzUnpackAttribute() {
|
||||
int [] result = new int[24];
|
||||
int offset = 0;
|
||||
offset = zzUnpackAttribute(ZZ_ATTRIBUTE_PACKED_0, offset, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
private static int zzUnpackAttribute(String packed, int offset, int [] result) {
|
||||
int i = 0; /* index in packed string */
|
||||
int j = offset; /* index in unpacked array */
|
||||
int l = packed.length();
|
||||
while (i < l) {
|
||||
int count = packed.charAt(i++);
|
||||
int value = packed.charAt(i++);
|
||||
do result[j++] = value; while (--count > 0);
|
||||
}
|
||||
return j;
|
||||
}
|
||||
|
||||
/** the current state of the DFA */
|
||||
private int zzState;
|
||||
|
||||
/** the current lexical state */
|
||||
private int zzLexicalState = YYINITIAL;
|
||||
|
||||
/** this buffer contains the current text to be matched and is
|
||||
the source of the yytext() string */
|
||||
private CharSequence zzBuffer = "";
|
||||
|
||||
/** this buffer may contains the current text array to be matched when it is cheap to acquire it */
|
||||
private char[] zzBufferArray;
|
||||
|
||||
/** the textposition at the last accepting state */
|
||||
private int zzMarkedPos;
|
||||
|
||||
/** the textposition at the last state to be included in yytext */
|
||||
private int zzPushbackPos;
|
||||
|
||||
/** the current text position in the buffer */
|
||||
private int zzCurrentPos;
|
||||
|
||||
/** startRead marks the beginning of the yytext() string in the buffer */
|
||||
private int zzStartRead;
|
||||
|
||||
/** endRead marks the last character in the buffer, that has been read
|
||||
from input */
|
||||
private int zzEndRead;
|
||||
|
||||
/**
|
||||
* zzAtBOL == true <=> the scanner is currently at the beginning of a line
|
||||
*/
|
||||
private boolean zzAtBOL = true;
|
||||
|
||||
/** zzAtEOF == true <=> the scanner is at the EOF */
|
||||
private boolean zzAtEOF;
|
||||
|
||||
/** denotes if the user-EOF-code has already been executed */
|
||||
private boolean zzEOFDone;
|
||||
|
||||
/* user code: */
|
||||
public _KDocLexer() {
|
||||
this((java.io.Reader)null);
|
||||
}
|
||||
|
||||
private boolean isLastToken() {
|
||||
return zzMarkedPos == zzBuffer.length();
|
||||
}
|
||||
|
||||
private Boolean yytextContainLineBreaks() {
|
||||
return CharArrayUtil.containLineBreaks(zzBuffer, zzStartRead, zzMarkedPos);
|
||||
}
|
||||
|
||||
private boolean nextIsNotWhitespace() {
|
||||
return zzMarkedPos <= zzBuffer.length() && !Character.isWhitespace(zzBuffer.charAt(zzMarkedPos + 1));
|
||||
}
|
||||
|
||||
private boolean prevIsNotWhitespace() {
|
||||
return zzMarkedPos != 0 && !Character.isWhitespace(zzBuffer.charAt(zzMarkedPos - 1));
|
||||
}
|
||||
|
||||
|
||||
_KDocLexer(java.io.Reader in) {
|
||||
this.zzReader = in;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new scanner.
|
||||
* There is also java.io.Reader version of this constructor.
|
||||
*
|
||||
* @param in the java.io.Inputstream to read input from.
|
||||
*/
|
||||
_KDocLexer(java.io.InputStream in) {
|
||||
this(new java.io.InputStreamReader(in));
|
||||
}
|
||||
|
||||
/**
|
||||
* Unpacks the compressed character translation table.
|
||||
*
|
||||
* @param packed the packed character translation table
|
||||
* @return the unpacked character translation table
|
||||
*/
|
||||
private static char [] zzUnpackCMap(String packed) {
|
||||
char [] map = new char[0x10000];
|
||||
int i = 0; /* index in packed string */
|
||||
int j = 0; /* index in unpacked array */
|
||||
while (i < 1206) {
|
||||
int count = packed.charAt(i++);
|
||||
char value = packed.charAt(i++);
|
||||
do map[j++] = value; while (--count > 0);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
public final int getTokenStart(){
|
||||
return zzStartRead;
|
||||
}
|
||||
|
||||
public final int getTokenEnd(){
|
||||
return getTokenStart() + yylength();
|
||||
}
|
||||
|
||||
public void reset(CharSequence buffer, int start, int end,int initialState){
|
||||
zzBuffer = buffer;
|
||||
zzBufferArray = com.intellij.util.text.CharArrayUtil.fromSequenceWithoutCopying(buffer);
|
||||
zzCurrentPos = zzMarkedPos = zzStartRead = start;
|
||||
zzPushbackPos = 0;
|
||||
zzAtEOF = false;
|
||||
zzAtBOL = true;
|
||||
zzEndRead = end;
|
||||
yybegin(initialState);
|
||||
}
|
||||
|
||||
/**
|
||||
* Refills the input buffer.
|
||||
*
|
||||
* @return <code>false</code>, iff there was new input.
|
||||
*
|
||||
* @exception java.io.IOException if any I/O-Error occurs
|
||||
*/
|
||||
private boolean zzRefill() throws java.io.IOException {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the current lexical state.
|
||||
*/
|
||||
public final int yystate() {
|
||||
return zzLexicalState;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Enters a new lexical state
|
||||
*
|
||||
* @param newState the new lexical state
|
||||
*/
|
||||
public final void yybegin(int newState) {
|
||||
zzLexicalState = newState;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the text matched by the current regular expression.
|
||||
*/
|
||||
public final CharSequence yytext() {
|
||||
return zzBuffer.subSequence(zzStartRead, zzMarkedPos);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the character at position <tt>pos</tt> from the
|
||||
* matched text.
|
||||
*
|
||||
* It is equivalent to yytext().charAt(pos), but faster
|
||||
*
|
||||
* @param pos the position of the character to fetch.
|
||||
* A value from 0 to yylength()-1.
|
||||
*
|
||||
* @return the character at position pos
|
||||
*/
|
||||
public final char yycharat(int pos) {
|
||||
return zzBufferArray != null ? zzBufferArray[zzStartRead+pos]:zzBuffer.charAt(zzStartRead+pos);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the length of the matched text region.
|
||||
*/
|
||||
public final int yylength() {
|
||||
return zzMarkedPos-zzStartRead;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Reports an error that occured while scanning.
|
||||
*
|
||||
* In a wellformed scanner (no or only correct usage of
|
||||
* yypushback(int) and a match-all fallback rule) this method
|
||||
* will only be called with things that "Can't Possibly Happen".
|
||||
* If this method is called, something is seriously wrong
|
||||
* (e.g. a JFlex bug producing a faulty scanner etc.).
|
||||
*
|
||||
* Usual syntax/scanner level error handling should be done
|
||||
* in error fallback rules.
|
||||
*
|
||||
* @param errorCode the code of the errormessage to display
|
||||
*/
|
||||
private void zzScanError(int errorCode) {
|
||||
String message;
|
||||
try {
|
||||
message = ZZ_ERROR_MSG[errorCode];
|
||||
}
|
||||
catch (ArrayIndexOutOfBoundsException e) {
|
||||
message = ZZ_ERROR_MSG[ZZ_UNKNOWN_ERROR];
|
||||
}
|
||||
|
||||
throw new Error(message);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Pushes the specified amount of characters back into the input stream.
|
||||
*
|
||||
* They will be read again by then next call of the scanning method
|
||||
*
|
||||
* @param number the number of characters to be read again.
|
||||
* This number must not be greater than yylength()!
|
||||
*/
|
||||
public void yypushback(int number) {
|
||||
if ( number > yylength() )
|
||||
zzScanError(ZZ_PUSHBACK_2BIG);
|
||||
|
||||
zzMarkedPos -= number;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Contains user EOF-code, which will be executed exactly once,
|
||||
* when the end of file is reached
|
||||
*/
|
||||
private void zzDoEOF() {
|
||||
if (!zzEOFDone) {
|
||||
zzEOFDone = true;
|
||||
return;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Resumes scanning until the next regular expression is matched,
|
||||
* the end of input is encountered or an I/O-Error occurs.
|
||||
*
|
||||
* @return the next token
|
||||
* @exception java.io.IOException if any I/O-Error occurs
|
||||
*/
|
||||
public IElementType advance() throws java.io.IOException {
|
||||
int zzInput;
|
||||
int zzAction;
|
||||
|
||||
// cached fields:
|
||||
int zzCurrentPosL;
|
||||
int zzMarkedPosL;
|
||||
int zzEndReadL = zzEndRead;
|
||||
CharSequence zzBufferL = zzBuffer;
|
||||
char[] zzBufferArrayL = zzBufferArray;
|
||||
char [] zzCMapL = ZZ_CMAP;
|
||||
|
||||
int [] zzTransL = ZZ_TRANS;
|
||||
int [] zzRowMapL = ZZ_ROWMAP;
|
||||
int [] zzAttrL = ZZ_ATTRIBUTE;
|
||||
|
||||
while (true) {
|
||||
zzMarkedPosL = zzMarkedPos;
|
||||
|
||||
zzAction = -1;
|
||||
|
||||
zzCurrentPosL = zzCurrentPos = zzStartRead = zzMarkedPosL;
|
||||
|
||||
zzState = ZZ_LEXSTATE[zzLexicalState];
|
||||
|
||||
|
||||
zzForAction: {
|
||||
while (true) {
|
||||
|
||||
if (zzCurrentPosL < zzEndReadL)
|
||||
zzInput = (zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++] : zzBufferL.charAt(zzCurrentPosL++));
|
||||
else if (zzAtEOF) {
|
||||
zzInput = YYEOF;
|
||||
break zzForAction;
|
||||
}
|
||||
else {
|
||||
// store back cached positions
|
||||
zzCurrentPos = zzCurrentPosL;
|
||||
zzMarkedPos = zzMarkedPosL;
|
||||
boolean eof = zzRefill();
|
||||
// get translated positions and possibly new buffer
|
||||
zzCurrentPosL = zzCurrentPos;
|
||||
zzMarkedPosL = zzMarkedPos;
|
||||
zzBufferL = zzBuffer;
|
||||
zzEndReadL = zzEndRead;
|
||||
if (eof) {
|
||||
zzInput = YYEOF;
|
||||
break zzForAction;
|
||||
}
|
||||
else {
|
||||
zzInput = (zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++] : zzBufferL.charAt(zzCurrentPosL++));
|
||||
}
|
||||
}
|
||||
int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];
|
||||
if (zzNext == -1) break zzForAction;
|
||||
zzState = zzNext;
|
||||
|
||||
int zzAttributes = zzAttrL[zzState];
|
||||
if ( (zzAttributes & 1) == 1 ) {
|
||||
zzAction = zzState;
|
||||
zzMarkedPosL = zzCurrentPosL;
|
||||
if ( (zzAttributes & 8) == 8 ) break zzForAction;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
// store back cached position
|
||||
zzMarkedPos = zzMarkedPosL;
|
||||
|
||||
switch (zzAction < 0 ? zzAction : ZZ_ACTION[zzAction]) {
|
||||
case 3:
|
||||
{ if (yytextContainLineBreaks()) {
|
||||
yybegin(LINE_BEGINNING);
|
||||
return TokenType.WHITE_SPACE;
|
||||
} else {
|
||||
yybegin(yystate() == CONTENTS_BEGINNING? CONTENTS_BEGINNING:CONTENTS);
|
||||
return KDocTokens.TEXT; // internal white space
|
||||
}
|
||||
}
|
||||
case 11: break;
|
||||
case 5:
|
||||
{ if (isLastToken()) return KDocTokens.END;
|
||||
else return KDocTokens.TEXT;
|
||||
}
|
||||
case 12: break;
|
||||
case 9:
|
||||
{ yybegin(CONTENTS);
|
||||
return KDocTokens.TAG_NAME;
|
||||
}
|
||||
case 13: break;
|
||||
case 7:
|
||||
{ yybegin(CONTENTS);
|
||||
return KDocTokens.WIKI_LINK_CLOSE;
|
||||
}
|
||||
case 14: break;
|
||||
case 8:
|
||||
{ yybegin(CONTENTS);
|
||||
return KDocTokens.WIKI_LINK_OPEN;
|
||||
}
|
||||
case 15: break;
|
||||
case 10:
|
||||
{ yybegin(CONTENTS);
|
||||
return KDocTokens.START;
|
||||
}
|
||||
case 16: break;
|
||||
case 1:
|
||||
{ return TokenType.BAD_CHARACTER;
|
||||
}
|
||||
case 17: break;
|
||||
case 6:
|
||||
{ yybegin(CONTENTS);
|
||||
return KDocTokens.MARKDOWN_ESCAPED_CHAR;
|
||||
}
|
||||
case 18: break;
|
||||
case 2:
|
||||
{ yybegin(CONTENTS);
|
||||
return KDocTokens.TEXT;
|
||||
}
|
||||
case 19: break;
|
||||
case 4:
|
||||
{ yybegin(CONTENTS_BEGINNING);
|
||||
return KDocTokens.LEADING_ASTERISK;
|
||||
}
|
||||
case 20: break;
|
||||
default:
|
||||
if (zzInput == YYEOF && zzStartRead == zzCurrentPos) {
|
||||
zzAtEOF = true;
|
||||
zzDoEOF();
|
||||
return null;
|
||||
}
|
||||
else {
|
||||
zzScanError(ZZ_NO_MATCH);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.kdoc.parser;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.PsiBuilder;
|
||||
import com.intellij.lang.PsiParser;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class KDocParser implements PsiParser {
|
||||
@Override
|
||||
@NotNull
|
||||
public ASTNode parse(IElementType root, PsiBuilder builder) {
|
||||
PsiBuilder.Marker rootMarker = builder.mark();
|
||||
|
||||
// todo: parse KDoc tags, markdown, etc...
|
||||
while (!builder.eof()) {
|
||||
builder.advanceLexer();
|
||||
}
|
||||
|
||||
rootMarker.done(root);
|
||||
return builder.getTreeBuilt();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.kdoc.psi.api;
|
||||
|
||||
import com.intellij.psi.PsiComment;
|
||||
|
||||
// Don't implement JetElement (or it will be treated as statement)
|
||||
public interface KDoc extends PsiComment {
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.kdoc.psi.api;
|
||||
|
||||
import com.intellij.psi.PsiElement;
|
||||
|
||||
public interface KDocElement extends PsiElement {
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.kdoc.psi.impl;
|
||||
|
||||
import com.intellij.extapi.psi.ASTWrapperPsiElement;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.lang.Language;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.plugin.JetLanguage;
|
||||
|
||||
public abstract class KDocElementImpl extends ASTWrapperPsiElement {
|
||||
@NotNull
|
||||
@Override
|
||||
public Language getLanguage() {
|
||||
return JetLanguage.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getNode().getElementType().toString();
|
||||
}
|
||||
|
||||
public KDocElementImpl(@NotNull ASTNode node) {
|
||||
super(node);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.kdoc.psi.impl;
|
||||
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.psi.impl.source.tree.LazyParseablePsiElement;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.kdoc.lexer.KDocTokens;
|
||||
import org.jetbrains.jet.kdoc.psi.api.KDoc;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.plugin.JetLanguage;
|
||||
|
||||
public class KDocImpl extends LazyParseablePsiElement implements KDoc {
|
||||
public KDocImpl(CharSequence buffer) {
|
||||
super(KDocTokens.KDOC, buffer);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Language getLanguage() {
|
||||
return JetLanguage.INSTANCE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getNode().getElementType().toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public IElementType getTokenType() {
|
||||
return JetTokens.DOC_COMMENT;
|
||||
}
|
||||
}
|
||||
@@ -277,9 +277,6 @@ public class JetFlowInformationProvider {
|
||||
}
|
||||
|
||||
boolean isInitializedNotHere = ctxt.enterInitState.isInitialized;
|
||||
if (expression.getParent() instanceof JetProperty && ((JetProperty)expression).getInitializer() != null) {
|
||||
isInitializedNotHere = false;
|
||||
}
|
||||
boolean hasBackingField = true;
|
||||
if (variableDescriptor instanceof PropertyDescriptor) {
|
||||
hasBackingField = trace.get(BindingContext.BACKING_FIELD_REQUIRED, (PropertyDescriptor) variableDescriptor);
|
||||
|
||||
@@ -45,6 +45,8 @@ public class PseudocodeVariablesData {
|
||||
private final Map<Pseudocode, Set<VariableDescriptor>> declaredVariablesForDeclaration = Maps.newHashMap();
|
||||
private final Map<Pseudocode, Set<VariableDescriptor>> usedVariablesForDeclaration = Maps.newHashMap();
|
||||
|
||||
private Map<Instruction, Edges<Map<VariableDescriptor, VariableInitState>>> variableInitializers;
|
||||
|
||||
public PseudocodeVariablesData(@NotNull Pseudocode pseudocode, @NotNull BindingContext bindingContext) {
|
||||
this.pseudocode = pseudocode;
|
||||
this.bindingContext = bindingContext;
|
||||
@@ -121,7 +123,11 @@ public class PseudocodeVariablesData {
|
||||
|
||||
@NotNull
|
||||
public Map<Instruction, Edges<Map<VariableDescriptor, VariableInitState>>> getVariableInitializers() {
|
||||
return getVariableInitializers(pseudocode);
|
||||
if (variableInitializers == null) {
|
||||
variableInitializers = getVariableInitializers(pseudocode);
|
||||
}
|
||||
|
||||
return variableInitializers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -164,7 +170,7 @@ public class PseudocodeVariablesData {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Map<VariableDescriptor, VariableInitState> prepareInitializersMapForStartInstruction(
|
||||
private static Map<VariableDescriptor, VariableInitState> prepareInitializersMapForStartInstruction(
|
||||
@NotNull Collection<VariableDescriptor> usedVariables,
|
||||
@NotNull Collection<VariableDescriptor> declaredVariables) {
|
||||
|
||||
@@ -184,7 +190,7 @@ public class PseudocodeVariablesData {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private Map<VariableDescriptor, VariableInitState> mergeIncomingEdgesDataForInitializers(
|
||||
private static Map<VariableDescriptor, VariableInitState> mergeIncomingEdgesDataForInitializers(
|
||||
@NotNull Collection<Map<VariableDescriptor, VariableInitState>> incomingEdgesData) {
|
||||
|
||||
Set<VariableDescriptor> variablesInScope = Sets.newHashSet();
|
||||
@@ -194,14 +200,20 @@ public class PseudocodeVariablesData {
|
||||
|
||||
Map<VariableDescriptor, VariableInitState> enterInstructionData = Maps.newHashMap();
|
||||
for (VariableDescriptor variable : variablesInScope) {
|
||||
Set<VariableInitState> edgesDataForVariable = Sets.newHashSet();
|
||||
boolean isInitialized = true;
|
||||
boolean isDeclared = true;
|
||||
for (Map<VariableDescriptor, VariableInitState> edgeData : incomingEdgesData) {
|
||||
VariableInitState initState = edgeData.get(variable);
|
||||
if (initState != null) {
|
||||
edgesDataForVariable.add(initState);
|
||||
if (!initState.isInitialized) {
|
||||
isInitialized = false;
|
||||
}
|
||||
if (!initState.isDeclared) {
|
||||
isDeclared = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
enterInstructionData.put(variable, VariableInitState.create(edgesDataForVariable));
|
||||
enterInstructionData.put(variable, VariableInitState.create(isInitialized, isDeclared));
|
||||
}
|
||||
return enterInstructionData;
|
||||
}
|
||||
@@ -323,20 +335,6 @@ public class PseudocodeVariablesData {
|
||||
private static VariableInitState create(boolean isDeclaredHere, @Nullable VariableInitState mergedEdgesData) {
|
||||
return create(true, isDeclaredHere || (mergedEdgesData != null && mergedEdgesData.isDeclared));
|
||||
}
|
||||
|
||||
private static VariableInitState create(@NotNull Set<VariableInitState> edgesData) {
|
||||
boolean isInitialized = true;
|
||||
boolean isDeclared = true;
|
||||
for (VariableInitState edgeData : edgesData) {
|
||||
if (!edgeData.isInitialized) {
|
||||
isInitialized = false;
|
||||
}
|
||||
if (!edgeData.isDeclared) {
|
||||
isDeclared = false;
|
||||
}
|
||||
}
|
||||
return create(isInitialized, isDeclared);
|
||||
}
|
||||
}
|
||||
|
||||
public static enum VariableUseState {
|
||||
|
||||
+2
-1
@@ -19,6 +19,7 @@ package org.jetbrains.jet.lang.descriptors;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.annotations.Annotated;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
|
||||
import java.util.Set;
|
||||
@@ -57,7 +58,7 @@ public interface ValueParameterDescriptor extends VariableDescriptor, Annotated
|
||||
ValueParameterDescriptor getOriginal();
|
||||
|
||||
@NotNull
|
||||
ValueParameterDescriptor copy(DeclarationDescriptor newOwner);
|
||||
ValueParameterDescriptor copy(DeclarationDescriptor newOwner, Name newName);
|
||||
|
||||
/**
|
||||
* Parameter p1 overrides p2 iff
|
||||
|
||||
+1
-1
@@ -73,7 +73,7 @@ public class ClassDescriptorImpl extends DeclarationDescriptorNonRootImpl implem
|
||||
@Nullable ConstructorDescriptor primaryConstructor,
|
||||
boolean isInner
|
||||
) {
|
||||
this.typeConstructor = new TypeConstructorImpl(this, getAnnotations(), sealed, getName().getName(), typeParameters, supertypes);
|
||||
this.typeConstructor = new TypeConstructorImpl(this, getAnnotations(), sealed, getName().asString(), typeParameters, supertypes);
|
||||
this.memberDeclarations = memberDeclarations;
|
||||
this.constructors = constructors;
|
||||
this.primaryConstructor = primaryConstructor;
|
||||
|
||||
+1
-2
@@ -71,8 +71,7 @@ public class FunctionDescriptorUtil {
|
||||
public static List<ValueParameterDescriptor> getSubstitutedValueParameters(FunctionDescriptor substitutedDescriptor, @NotNull FunctionDescriptor functionDescriptor, @NotNull TypeSubstitutor substitutor) {
|
||||
List<ValueParameterDescriptor> result = new ArrayList<ValueParameterDescriptor>();
|
||||
List<ValueParameterDescriptor> unsubstitutedValueParameters = functionDescriptor.getValueParameters();
|
||||
for (int i = 0, unsubstitutedValueParametersSize = unsubstitutedValueParameters.size(); i < unsubstitutedValueParametersSize; i++) {
|
||||
ValueParameterDescriptor unsubstitutedValueParameter = unsubstitutedValueParameters.get(i);
|
||||
for (ValueParameterDescriptor unsubstitutedValueParameter : unsubstitutedValueParameters) {
|
||||
// TODO : Lazy?
|
||||
JetType substitutedType = substitutor.substitute(unsubstitutedValueParameter.getType(), Variance.IN_VARIANCE);
|
||||
JetType varargElementType = unsubstitutedValueParameter.getVarargElementType();
|
||||
|
||||
+2
-15
@@ -26,7 +26,6 @@ import org.jetbrains.jet.lang.resolve.BindingTrace;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.*;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -224,7 +223,7 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull final MutableClassDescriptorLite classObjectDescriptor) {
|
||||
public ClassObjectStatus setClassObjectDescriptor(@NotNull MutableClassDescriptorLite classObjectDescriptor) {
|
||||
ClassObjectStatus r = superBuilder.setClassObjectDescriptor(classObjectDescriptor);
|
||||
if (r != ClassObjectStatus.OK) {
|
||||
return r;
|
||||
@@ -232,19 +231,7 @@ public class MutableClassDescriptor extends MutableClassDescriptorLite {
|
||||
|
||||
// Members of the class object are accessible from the class
|
||||
// The scope must be lazy, because classObjectDescriptor may not by fully built yet
|
||||
scopeForMemberResolution.importScope(new AbstractScopeAdapter() {
|
||||
@NotNull
|
||||
@Override
|
||||
protected JetScope getWorkerScope() {
|
||||
return classObjectDescriptor.getDefaultType().getMemberScope();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<ReceiverParameterDescriptor> getImplicitReceiversHierarchy() {
|
||||
return Collections.singletonList(classObjectDescriptor.getThisAsReceiverParameter());
|
||||
}
|
||||
});
|
||||
scopeForMemberResolution.importScope(new ClassObjectMixinScope(classObjectDescriptor));
|
||||
|
||||
return ClassObjectStatus.OK;
|
||||
}
|
||||
|
||||
+1
-1
@@ -109,7 +109,7 @@ public abstract class MutableClassDescriptorLite extends ClassDescriptorBase {
|
||||
this,
|
||||
Collections.<AnnotationDescriptor>emptyList(), // TODO : pass annotations from the class?
|
||||
!getModality().isOverridable(),
|
||||
getName().getName(),
|
||||
getName().asString(),
|
||||
typeParameters,
|
||||
supertypes);
|
||||
}
|
||||
|
||||
+1
-1
@@ -91,7 +91,7 @@ public class TypeParameterDescriptorImpl extends DeclarationDescriptorNonRootImp
|
||||
this,
|
||||
annotations,
|
||||
false,
|
||||
name.getName(),
|
||||
name.asString(),
|
||||
Collections.<TypeParameterDescriptor>emptyList(),
|
||||
upperBounds);
|
||||
}
|
||||
|
||||
+3
-2
@@ -111,6 +111,7 @@ public class ValueParameterDescriptorImpl extends VariableDescriptorImpl impleme
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public JetType getVarargElementType() {
|
||||
return varargElementType;
|
||||
}
|
||||
@@ -139,8 +140,8 @@ public class ValueParameterDescriptorImpl extends VariableDescriptorImpl impleme
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ValueParameterDescriptor copy(@NotNull DeclarationDescriptor newOwner) {
|
||||
return new ValueParameterDescriptorImpl(newOwner, index, Lists.newArrayList(getAnnotations()), getName(), getType(), hasDefaultValue, varargElementType);
|
||||
public ValueParameterDescriptor copy(@NotNull DeclarationDescriptor newOwner, @NotNull Name newName) {
|
||||
return new ValueParameterDescriptorImpl(newOwner, index, Lists.newArrayList(getAnnotations()), newName, getType(), declaresDefaultValue(), varargElementType);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -64,7 +64,7 @@ public class Renderers {
|
||||
@Override
|
||||
public String render(@NotNull Object element) {
|
||||
if (element instanceof Named) {
|
||||
return ((Named) element).getName().getName();
|
||||
return ((Named) element).getName().asString();
|
||||
}
|
||||
return element.toString();
|
||||
}
|
||||
@@ -184,7 +184,7 @@ public class Renderers {
|
||||
result.text(newText()
|
||||
.normal("Cannot infer type parameter ")
|
||||
.strong(firstConflictingParameter.getName())
|
||||
.normal(" in"));
|
||||
.normal(" in "));
|
||||
//String type = strong(firstConflictingParameter.getName());
|
||||
TableRenderer table = newTable();
|
||||
result.table(table);
|
||||
@@ -299,7 +299,7 @@ public class Renderers {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
int index = 0;
|
||||
for (ClassDescriptor descriptor : descriptors) {
|
||||
sb.append(DescriptorUtils.getFQName(descriptor).getFqName());
|
||||
sb.append(DescriptorUtils.getFQName(descriptor).asString());
|
||||
index++;
|
||||
if (index <= descriptors.size() - 2) {
|
||||
sb.append(", ");
|
||||
|
||||
@@ -53,7 +53,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
TRUE_KEYWORD, FALSE_KEYWORD, IS_KEYWORD, THROW_KEYWORD, RETURN_KEYWORD, BREAK_KEYWORD,
|
||||
CONTINUE_KEYWORD, OBJECT_KEYWORD, IF_KEYWORD, TRY_KEYWORD, ELSE_KEYWORD, WHILE_KEYWORD, DO_KEYWORD,
|
||||
WHEN_KEYWORD, RBRACKET, RBRACE, RPAR, PLUSPLUS, MINUSMINUS, EXCLEXCL,
|
||||
// MUL,
|
||||
// MUL,
|
||||
PLUS, MINUS, EXCL, DIV, PERC, LTEQ,
|
||||
// TODO GTEQ, foo<bar, baz>=x
|
||||
EQEQEQ, EXCLEQEQEQ, EQEQ, EXCLEQ, ANDAND, OROR, SAFE_ACCESS, ELVIS,
|
||||
@@ -111,17 +111,17 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
);
|
||||
|
||||
private static final TokenSet STATEMENT_FIRST = TokenSet.orSet(
|
||||
EXPRESSION_FIRST,
|
||||
TokenSet.create(
|
||||
// declaration
|
||||
LBRACKET, // attribute
|
||||
FUN_KEYWORD,
|
||||
VAL_KEYWORD, VAR_KEYWORD,
|
||||
TRAIT_KEYWORD,
|
||||
CLASS_KEYWORD,
|
||||
TYPE_KEYWORD
|
||||
),
|
||||
MODIFIER_KEYWORDS
|
||||
EXPRESSION_FIRST,
|
||||
TokenSet.create(
|
||||
// declaration
|
||||
LBRACKET, // attribute
|
||||
FUN_KEYWORD,
|
||||
VAL_KEYWORD, VAR_KEYWORD,
|
||||
TRAIT_KEYWORD,
|
||||
CLASS_KEYWORD,
|
||||
TYPE_KEYWORD
|
||||
),
|
||||
MODIFIER_KEYWORDS
|
||||
);
|
||||
|
||||
/*package*/ static final TokenSet EXPRESSION_FOLLOW = TokenSet.create(
|
||||
@@ -174,7 +174,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
EQUALITY(EQEQ, EXCLEQ, EQEQEQ, EXCLEQEQEQ),
|
||||
CONJUNCTION(ANDAND),
|
||||
DISJUNCTION(OROR),
|
||||
// ARROW(JetTokens.ARROW),
|
||||
// ARROW(JetTokens.ARROW),
|
||||
ASSIGNMENT(EQ, PLUSEQ, MINUSEQ, MULTEQ, DIVEQ, PERCEQ),
|
||||
;
|
||||
|
||||
@@ -287,7 +287,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
* see the precedence table
|
||||
*/
|
||||
private void parseBinaryExpression(Precedence precedence) {
|
||||
// System.out.println(precedence.name() + " at " + myBuilder.getTokenText());
|
||||
// System.out.println(precedence.name() + " at " + myBuilder.getTokenText());
|
||||
|
||||
PsiBuilder.Marker expression = mark();
|
||||
|
||||
@@ -300,7 +300,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
|
||||
JetNodeType resultType = precedence.parseRightHandSide(operation, this);
|
||||
expression.done(resultType);
|
||||
expression = expression.precede();
|
||||
expression = expression.precede();
|
||||
}
|
||||
|
||||
expression.drop();
|
||||
@@ -310,7 +310,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
* operation? prefixExpression
|
||||
*/
|
||||
private void parsePrefixExpression() {
|
||||
// System.out.println("pre at " + myBuilder.getTokenText());
|
||||
// System.out.println("pre at " + myBuilder.getTokenText());
|
||||
|
||||
if (at(LBRACKET)) {
|
||||
if (!parseLocalDeclaration()) {
|
||||
@@ -485,10 +485,10 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
*/
|
||||
protected boolean parseCallWithClosure() {
|
||||
boolean success = false;
|
||||
// while (!myBuilder.newlineBeforeCurrentToken()
|
||||
// && (at(LBRACE)
|
||||
// while (!myBuilder.newlineBeforeCurrentToken()
|
||||
// && (at(LBRACE)
|
||||
while ((at(LBRACE)
|
||||
|| atSet(LABELS) && lookahead(1) == LBRACE)) {
|
||||
|| atSet(LABELS) && lookahead(1) == LBRACE)) {
|
||||
if (!at(LBRACE)) {
|
||||
assert _atSet(LABELS);
|
||||
parsePrefixExpression();
|
||||
@@ -520,7 +520,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
* ;
|
||||
*/
|
||||
private void parseAtomicExpression() {
|
||||
// System.out.println("atom at " + myBuilder.getTokenText());
|
||||
// System.out.println("atom at " + myBuilder.getTokenText());
|
||||
|
||||
if (at(LPAR)) {
|
||||
parseParenthesizedExpression();
|
||||
@@ -574,7 +574,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
parseDoWhile();
|
||||
}
|
||||
else if (atSet(CLASS_KEYWORD, FUN_KEYWORD, VAL_KEYWORD,
|
||||
VAR_KEYWORD, TYPE_KEYWORD)) {
|
||||
VAR_KEYWORD, TYPE_KEYWORD)) {
|
||||
parseLocalDeclaration();
|
||||
}
|
||||
else if (at(FIELD_IDENTIFIER)) {
|
||||
@@ -784,7 +784,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
|
||||
if (!at(ARROW)) {
|
||||
errorUntil("Expecting '->'", TokenSet.create(ARROW,
|
||||
RBRACE, EOL_OR_SEMICOLON));
|
||||
RBRACE, EOL_OR_SEMICOLON));
|
||||
}
|
||||
|
||||
if (at(ARROW)) {
|
||||
@@ -798,7 +798,7 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
}
|
||||
}
|
||||
else if (!atSet(WHEN_CONDITION_RECOVERY_SET)) {
|
||||
errorAndAdvance("Expecting '->'");
|
||||
errorAndAdvance("Expecting '->'");
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -982,8 +982,8 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
parseFunctionLiteralParametersAndType();
|
||||
|
||||
paramsFound = preferParamsToExpressions ?
|
||||
rollbackOrDrop(rollbackMarker, ARROW, "An -> is expected", RBRACE) :
|
||||
rollbackOrDropAt(rollbackMarker, ARROW);
|
||||
rollbackOrDrop(rollbackMarker, ARROW, "An -> is expected", RBRACE) :
|
||||
rollbackOrDropAt(rollbackMarker, ARROW);
|
||||
}
|
||||
|
||||
if (!paramsFound) {
|
||||
@@ -1047,8 +1047,8 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
}
|
||||
|
||||
private boolean rollbackOrDrop(PsiBuilder.Marker rollbackMarker,
|
||||
JetToken expected, String expectMessage,
|
||||
IElementType validForDrop) {
|
||||
JetToken expected, String expectMessage,
|
||||
IElementType validForDrop) {
|
||||
if (at(expected)) {
|
||||
advance(); // dropAt
|
||||
rollbackMarker.drop();
|
||||
@@ -1074,8 +1074,8 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
while (!eof()) {
|
||||
PsiBuilder.Marker parameter = mark();
|
||||
|
||||
// int parameterNamePos = matchTokenStreamPredicate(new LastBefore(new At(IDENTIFIER), new AtOffset(doubleArrowPos)));
|
||||
// createTruncatedBuilder(parameterNamePos).parseModifierList(MODIFIER_LIST, false);
|
||||
// int parameterNamePos = matchTokenStreamPredicate(new LastBefore(new At(IDENTIFIER), new AtOffset(doubleArrowPos)));
|
||||
// createTruncatedBuilder(parameterNamePos).parseModifierList(MODIFIER_LIST, false);
|
||||
|
||||
expect(IDENTIFIER, "Expecting parameter name", TokenSet.create(ARROW));
|
||||
|
||||
@@ -1135,8 +1135,8 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
}
|
||||
|
||||
return preferParamsToExpressions ?
|
||||
rollbackOrDrop(rollbackMarker, ARROW, "An -> is expected", RBRACE) :
|
||||
rollbackOrDropAt(rollbackMarker, ARROW);
|
||||
rollbackOrDrop(rollbackMarker, ARROW, "An -> is expected", RBRACE) :
|
||||
rollbackOrDropAt(rollbackMarker, ARROW);
|
||||
}
|
||||
|
||||
private void parseFunctionLiteralParametersAndType() {
|
||||
@@ -1252,38 +1252,38 @@ public class JetExpressionParsing extends AbstractJetParsing {
|
||||
* ;
|
||||
*/
|
||||
private IElementType parseLocalDeclarationRest(boolean isEnum) {
|
||||
IElementType keywordToken = tt();
|
||||
IElementType declType = null;
|
||||
if (keywordToken == CLASS_KEYWORD || keywordToken == TRAIT_KEYWORD) {
|
||||
declType = myJetParsing.parseClass(isEnum);
|
||||
}
|
||||
else if (keywordToken == FUN_KEYWORD) {
|
||||
declType = myJetParsing.parseFunction();
|
||||
}
|
||||
else if (keywordToken == VAL_KEYWORD || keywordToken == VAR_KEYWORD) {
|
||||
declType = myJetParsing.parseProperty(true);
|
||||
}
|
||||
else if (keywordToken == TYPE_KEYWORD) {
|
||||
declType = myJetParsing.parseTypeDef();
|
||||
}
|
||||
else if (keywordToken == OBJECT_KEYWORD) {
|
||||
// Object expression may appear at the statement position: should parse it
|
||||
// as expression instead of object declaration
|
||||
// sample:
|
||||
// {
|
||||
// object : Thread() {
|
||||
// }
|
||||
// }
|
||||
IElementType lookahead = lookahead(1);
|
||||
if (lookahead == COLON || lookahead == LBRACE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
myJetParsing.parseObject(true, true);
|
||||
declType = OBJECT_DECLARATION;
|
||||
}
|
||||
return declType;
|
||||
}
|
||||
IElementType keywordToken = tt();
|
||||
IElementType declType = null;
|
||||
if (keywordToken == CLASS_KEYWORD || keywordToken == TRAIT_KEYWORD) {
|
||||
declType = myJetParsing.parseClass(isEnum);
|
||||
}
|
||||
else if (keywordToken == FUN_KEYWORD) {
|
||||
declType = myJetParsing.parseFunction();
|
||||
}
|
||||
else if (keywordToken == VAL_KEYWORD || keywordToken == VAR_KEYWORD) {
|
||||
declType = myJetParsing.parseProperty(true);
|
||||
}
|
||||
else if (keywordToken == TYPE_KEYWORD) {
|
||||
declType = myJetParsing.parseTypeDef();
|
||||
}
|
||||
else if (keywordToken == OBJECT_KEYWORD) {
|
||||
// Object expression may appear at the statement position: should parse it
|
||||
// as expression instead of object declaration
|
||||
// sample:
|
||||
// {
|
||||
// object : Thread() {
|
||||
// }
|
||||
// }
|
||||
IElementType lookahead = lookahead(1);
|
||||
if (lookahead == COLON || lookahead == LBRACE) {
|
||||
return null;
|
||||
}
|
||||
|
||||
myJetParsing.parseObject(true, true);
|
||||
declType = OBJECT_DECLARATION;
|
||||
}
|
||||
return declType;
|
||||
}
|
||||
|
||||
/*
|
||||
* doWhile
|
||||
|
||||
@@ -50,6 +50,7 @@ public class JetParsing extends AbstractJetParsing {
|
||||
private static final TokenSet IMPORT_RECOVERY_SET = TokenSet.create(AS_KEYWORD, DOT, EOL_OR_SEMICOLON);
|
||||
/*package*/ static final TokenSet TYPE_REF_FIRST = TokenSet.create(LBRACKET, IDENTIFIER, FUN_KEYWORD, LPAR, CAPITALIZED_THIS_KEYWORD, HASH);
|
||||
private static final TokenSet RECEIVER_TYPE_TERMINATORS = TokenSet.create(DOT, SAFE_ACCESS);
|
||||
private static final TokenSet VALUE_PARAMETER_FIRST = TokenSet.orSet(TokenSet.create(IDENTIFIER, LBRACKET), MODIFIER_KEYWORDS);
|
||||
|
||||
static JetParsing createForTopLevel(SemanticWhitespaceAwarePsiBuilder builder) {
|
||||
JetParsing jetParsing = new JetParsing(builder);
|
||||
@@ -1722,8 +1723,10 @@ public class JetParsing extends AbstractJetParsing {
|
||||
else {
|
||||
parseValueParameter();
|
||||
}
|
||||
if (!at(COMMA)) break;
|
||||
advance(); // COMMA
|
||||
if (at(COMMA)) {
|
||||
advance(); // COMMA
|
||||
}
|
||||
else if (!atSet(VALUE_PARAMETER_FIRST)) break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,7 +54,17 @@ public class JetBlockExpression extends JetExpressionImpl implements JetStatemen
|
||||
|
||||
@Nullable
|
||||
public TextRange getLastBracketRange() {
|
||||
PsiElement rBrace = findChildByType(JetTokens.RBRACE);
|
||||
PsiElement rBrace = getRBrace();
|
||||
return rBrace != null ? rBrace.getTextRange() : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PsiElement getRBrace() {
|
||||
return findChildByType(JetTokens.RBRACE);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PsiElement getLBrace() {
|
||||
return findChildByType(JetTokens.LBRACE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,7 +199,7 @@ public class JetClass extends JetTypeParameterListOwnerStub<PsiJetClassStub> imp
|
||||
PsiJetClassStub stub = getStub();
|
||||
if (stub != null) {
|
||||
FqName fqName = stub.getFqName();
|
||||
return fqName == null ? null : fqName.getFqName();
|
||||
return fqName == null ? null : fqName.asString();
|
||||
}
|
||||
|
||||
List<String> parts = new ArrayList<String>();
|
||||
|
||||
@@ -17,7 +17,10 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
public class JetClassInitializer extends JetDeclarationImpl implements JetStatementExpression {
|
||||
public JetClassInitializer(@NotNull ASTNode node) {
|
||||
@@ -40,4 +43,10 @@ public class JetClassInitializer extends JetDeclarationImpl implements JetStatem
|
||||
assert body != null;
|
||||
return body;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public PsiElement getOpenBraceNode() {
|
||||
JetExpression body = getBody();
|
||||
return (body instanceof JetBlockExpression) ? ((JetBlockExpression) body).getLBrace() : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,9 +17,11 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
public class JetClassObject extends JetDeclarationImpl implements JetStatementExpression {
|
||||
public JetClassObject(@NotNull ASTNode node) {
|
||||
@@ -41,4 +43,9 @@ public class JetClassObject extends JetDeclarationImpl implements JetStatementEx
|
||||
return (JetObjectDeclaration) findChildByType(JetNodeTypes.OBJECT_DECLARATION);
|
||||
}
|
||||
|
||||
@Nullable @IfNotParsed
|
||||
public PsiElement getClassKeywordNode() {
|
||||
ASTNode keywordNode = getNode().findChildByType(JetTokens.CLASS_KEYWORD);
|
||||
return keywordNode != null ? keywordNode.getPsi() : null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.navigation.ItemPresentation;
|
||||
import com.intellij.navigation.ItemPresentationProviders;
|
||||
import com.intellij.psi.stubs.IStubElementType;
|
||||
import com.intellij.util.ArrayFactory;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -107,5 +109,8 @@ public class JetParameter extends JetNamedDeclarationStub<PsiJetParameterStub> {
|
||||
return getNode().findChildByType(JetTokens.VAR_KEYWORD);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public ItemPresentation getPresentation() {
|
||||
return ItemPresentationProviders.getItemPresentation(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,6 +73,13 @@ public class JetPsiFactory {
|
||||
return star;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static PsiElement createComma(Project project) {
|
||||
PsiElement comma = createType(project, "T<X, Y>").findElementAt(3);
|
||||
assert comma != null;
|
||||
return comma;
|
||||
}
|
||||
|
||||
//the pair contains the first and the last elements of a range
|
||||
public static Pair<PsiElement, PsiElement> createColonAndWhiteSpaces(Project project) {
|
||||
JetProperty property = createProperty(project, "val x : Int");
|
||||
@@ -228,7 +235,7 @@ public class JetPsiFactory {
|
||||
|
||||
Name alias = importPath.getAlias();
|
||||
if (alias != null) {
|
||||
importDirectiveBuilder.append(" as ").append(alias.getName());
|
||||
importDirectiveBuilder.append(" as ").append(alias.asString());
|
||||
}
|
||||
|
||||
JetFile namespace = createFile(project, importDirectiveBuilder.toString());
|
||||
@@ -249,20 +256,14 @@ public class JetPsiFactory {
|
||||
return createExpression(project, "$" + fieldName);
|
||||
}
|
||||
|
||||
public static JetBinaryExpression createAssignment(Project project, @NotNull String lhs, @NotNull String rhs) {
|
||||
return (JetBinaryExpression) createExpression(project, lhs + " = " + rhs);
|
||||
@NotNull
|
||||
public static JetBinaryExpression createBinaryExpression(Project project, @NotNull String lhs, @NotNull String op, @NotNull String rhs) {
|
||||
return (JetBinaryExpression) createExpression(project, lhs + " " + op + " " + rhs);
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public static JetBinaryExpression createAssignment(Project project, @NotNull JetExpression lhs, @NotNull JetExpression rhs) {
|
||||
JetBinaryExpression assignment = createAssignment(project, "_", "_");
|
||||
|
||||
assert assignment.getRight() != null;
|
||||
|
||||
assignment = (JetBinaryExpression)assignment.getLeft().replace(lhs).getParent();
|
||||
assignment = (JetBinaryExpression)assignment.getRight().replace(rhs).getParent();
|
||||
|
||||
return assignment;
|
||||
@NotNull
|
||||
public static JetBinaryExpression createBinaryExpression(Project project, @Nullable JetExpression lhs, @NotNull String op, @Nullable JetExpression rhs) {
|
||||
return createBinaryExpression(project, JetPsiUtil.getText(lhs), op, JetPsiUtil.getText(rhs));
|
||||
}
|
||||
|
||||
public static JetTypeCodeFragment createTypeCodeFragment(Project project, String text, PsiElement context) {
|
||||
@@ -273,6 +274,186 @@ public class JetPsiFactory {
|
||||
return new JetExpressionCodeFragmentImpl(project, "fragment.kt", text, context);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetReturnExpression createReturn(Project project, @NotNull String text) {
|
||||
return (JetReturnExpression) createExpression(project, "return " + text);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetReturnExpression createReturn(Project project, @Nullable JetExpression expression) {
|
||||
return createReturn(project, JetPsiUtil.getText(expression));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetIfExpression createIf(Project project,
|
||||
@Nullable JetExpression condition, @Nullable JetExpression thenExpr, @Nullable JetExpression elseExpr) {
|
||||
return (JetIfExpression) createExpression(project, JetPsiUnparsingUtils.toIf(condition, thenExpr, elseExpr));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static JetValueArgument createArgumentWithName(
|
||||
@NotNull Project project,
|
||||
@NotNull String name,
|
||||
@NotNull JetExpression argumentExpression
|
||||
) {
|
||||
return createCallArguments(project, "(" + name + " = " + argumentExpression.getText() + ")").getArguments().get(0);
|
||||
}
|
||||
|
||||
public static class IfChainBuilder {
|
||||
private final StringBuilder sb = new StringBuilder();
|
||||
private boolean first = true;
|
||||
private boolean frozen = false;
|
||||
|
||||
public IfChainBuilder() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public IfChainBuilder ifBranch(@NotNull String conditionText, @NotNull String expressionText) {
|
||||
if (first) {
|
||||
first = false;
|
||||
} else {
|
||||
sb.append("else ");
|
||||
}
|
||||
|
||||
sb.append("if (").append(conditionText).append(") ").append(expressionText).append("\n");
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public IfChainBuilder ifBranch(@NotNull JetExpression condition, @NotNull JetExpression expression) {
|
||||
return ifBranch(condition.getText(), expression.getText());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public IfChainBuilder elseBranch(@NotNull String expressionText) {
|
||||
sb.append("else ").append(expressionText);
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public IfChainBuilder elseBranch(@Nullable JetExpression expression) {
|
||||
return elseBranch(JetPsiUtil.getText(expression));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetIfExpression toExpression(Project project) {
|
||||
if (!frozen) {
|
||||
frozen = true;
|
||||
}
|
||||
return (JetIfExpression) createExpression(project, sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static class WhenBuilder {
|
||||
private final StringBuilder sb = new StringBuilder("when ");
|
||||
private boolean frozen = false;
|
||||
private boolean inCondition = false;
|
||||
|
||||
public WhenBuilder() {
|
||||
this((String)null);
|
||||
}
|
||||
|
||||
public WhenBuilder(@Nullable String subjectText) {
|
||||
if (subjectText != null) {
|
||||
sb.append("(").append(subjectText).append(") ");
|
||||
}
|
||||
sb.append("{\n");
|
||||
}
|
||||
|
||||
public WhenBuilder(@Nullable JetExpression subject) {
|
||||
this(subject != null ? subject.getText() : null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public WhenBuilder condition(@NotNull String text) {
|
||||
assert !frozen;
|
||||
|
||||
if (!inCondition) {
|
||||
inCondition = true;
|
||||
} else {
|
||||
sb.append(", ");
|
||||
}
|
||||
sb.append(text);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public WhenBuilder condition(@Nullable JetExpression expression) {
|
||||
return condition(JetPsiUtil.getText(expression));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public WhenBuilder pattern(@NotNull String typeReferenceText, boolean negated) {
|
||||
return condition((negated ? "!is" : "is") + " " + typeReferenceText);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public WhenBuilder pattern(@Nullable JetTypeReference typeReference, boolean negated) {
|
||||
return pattern(JetPsiUtil.getText(typeReference), negated);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public WhenBuilder range(@NotNull String argumentText, boolean negated) {
|
||||
return condition((negated ? "!in" : "in") + " " + argumentText);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public WhenBuilder range(@Nullable JetExpression argument, boolean negated) {
|
||||
return range(JetPsiUtil.getText(argument), negated);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public WhenBuilder branchExpression(@NotNull String expressionText) {
|
||||
assert !frozen;
|
||||
assert inCondition;
|
||||
|
||||
inCondition = false;
|
||||
sb.append(" -> ").append(expressionText).append("\n");
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public WhenBuilder branchExpression(@Nullable JetExpression expression) {
|
||||
return branchExpression(JetPsiUtil.getText(expression));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public WhenBuilder entry(@NotNull String entryText) {
|
||||
assert !frozen;
|
||||
assert !inCondition;
|
||||
|
||||
sb.append(entryText).append("\n");
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public WhenBuilder entry(@Nullable JetWhenEntry whenEntry) {
|
||||
return entry(JetPsiUtil.getText(whenEntry));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public WhenBuilder elseEntry(@NotNull String text) {
|
||||
return entry("else -> " + text);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public WhenBuilder elseEntry(@Nullable JetExpression expression) {
|
||||
return elseEntry(JetPsiUtil.getText(expression));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public JetWhenExpression toExpression(Project project) {
|
||||
if (!frozen) {
|
||||
sb.append("}");
|
||||
frozen = true;
|
||||
}
|
||||
return (JetWhenExpression) createExpression(project, sb.toString());
|
||||
}
|
||||
}
|
||||
|
||||
public static JetExpression createFunctionBody(Project project, @NotNull String bodyText) {
|
||||
JetFunction func = createFunction(project, "fun foo() {\n" + bodyText + "\n}");
|
||||
return func.getBodyExpression();
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class JetPsiUnparsingUtils {
|
||||
private JetPsiUnparsingUtils() {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String toIf(@Nullable JetExpression condition, @Nullable JetExpression thenExpression, @Nullable JetExpression elseExpression) {
|
||||
return toIf(
|
||||
JetPsiUtil.getText(condition),
|
||||
JetPsiUtil.getText(thenExpression),
|
||||
elseExpression != null ? elseExpression.getText() : null
|
||||
);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String toIf(@NotNull String condition, @NotNull String thenExpression, @Nullable String elseExpression) {
|
||||
return "if " + parenthesizeTextIfNeeded(condition) + " " + thenExpression + (elseExpression != null ? " else " + elseExpression : "");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String toBinaryExpression(@Nullable JetExpression left, @NotNull String op, @Nullable JetElement right) {
|
||||
return toBinaryExpression(JetPsiUtil.getText(left), op, JetPsiUtil.getText(right));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String toBinaryExpression(@NotNull String left, @NotNull String op, @NotNull String right) {
|
||||
return left + " " + op + " " + right;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String parenthesizeIfNeeded(@Nullable JetExpression expression) {
|
||||
String text = JetPsiUtil.getText(expression);
|
||||
|
||||
return (expression instanceof JetParenthesizedExpression ||
|
||||
expression instanceof JetConstantExpression ||
|
||||
expression instanceof JetSimpleNameExpression)
|
||||
? text : "(" + text + ")";
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static String parenthesizeTextIfNeeded(@NotNull String expressionText) {
|
||||
return (expressionText.startsWith("(") && expressionText.endsWith(")")) ? expressionText : "(" + expressionText + ")";
|
||||
}
|
||||
}
|
||||
@@ -17,18 +17,23 @@
|
||||
package org.jetbrains.jet.lang.psi;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiComment;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiWhiteSpace;
|
||||
import com.intellij.psi.impl.CheckUtil;
|
||||
import com.intellij.psi.impl.source.codeStyle.CodeEditUtil;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.util.codeInsight.CommentUtilCore;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
import org.jetbrains.jet.kdoc.psi.api.KDocElement;
|
||||
import org.jetbrains.jet.lang.parsing.JetExpressionParsing;
|
||||
import org.jetbrains.jet.lang.resolve.ImportPath;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
@@ -154,13 +159,14 @@ public class JetPsiUtil {
|
||||
}
|
||||
}
|
||||
|
||||
public static FqName getFQName(JetFile file) {
|
||||
@NotNull
|
||||
public static FqName getFQName(@NotNull JetFile file) {
|
||||
JetNamespaceHeader header = file.getNamespaceHeader();
|
||||
return header != null ? header.getFqName() : FqName.ROOT;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static FqName getFQName(JetNamedDeclaration namedDeclaration) {
|
||||
public static FqName getFQName(@NotNull JetNamedDeclaration namedDeclaration) {
|
||||
if (namedDeclaration instanceof JetObjectDeclarationName) {
|
||||
JetNamedDeclaration objectDeclaration = PsiTreeUtil.getParentOfType(namedDeclaration, JetObjectDeclaration.class);
|
||||
if (objectDeclaration == null) {
|
||||
@@ -192,11 +198,17 @@ public class JetPsiUtil {
|
||||
else if (parent instanceof JetNamedFunction || parent instanceof JetClass) {
|
||||
firstPart = getFQName((JetNamedDeclaration) parent);
|
||||
}
|
||||
else if (namedDeclaration instanceof JetParameter) {
|
||||
JetClass constructorClass = getClassIfParameterIsProperty((JetParameter) namedDeclaration);
|
||||
if (constructorClass != null) {
|
||||
firstPart = getFQName(constructorClass);
|
||||
}
|
||||
}
|
||||
else if (parent instanceof JetObjectDeclaration) {
|
||||
if (parent.getParent() instanceof JetClassObject) {
|
||||
JetClassOrObject classOrObject = PsiTreeUtil.getParentOfType(parent, JetClassOrObject.class);
|
||||
if (classOrObject != null) {
|
||||
firstPart = getFQName((JetNamedDeclaration) classOrObject);
|
||||
firstPart = getFQName(classOrObject);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -229,7 +241,7 @@ public class JetPsiUtil {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Name getShortName(JetAnnotationEntry annotation) {
|
||||
public static Name getShortName(@NotNull JetAnnotationEntry annotation) {
|
||||
JetTypeReference typeReference = annotation.getTypeReference();
|
||||
assert typeReference != null : "Annotation entry hasn't typeReference " + annotation.getText();
|
||||
JetTypeElement typeElement = typeReference.getTypeElement();
|
||||
@@ -243,7 +255,7 @@ public class JetPsiUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean isDeprecated(JetModifierListOwner owner) {
|
||||
public static boolean isDeprecated(@NotNull JetModifierListOwner owner) {
|
||||
JetModifierList modifierList = owner.getModifierList();
|
||||
if (modifierList != null) {
|
||||
List<JetAnnotationEntry> annotationEntries = modifierList.getAnnotationEntries();
|
||||
@@ -259,7 +271,7 @@ public class JetPsiUtil {
|
||||
|
||||
@Nullable
|
||||
@IfNotParsed
|
||||
public static ImportPath getImportPath(JetImportDirective importDirective) {
|
||||
public static ImportPath getImportPath(@NotNull JetImportDirective importDirective) {
|
||||
if (PsiTreeUtil.hasErrorElements(importDirective)) {
|
||||
return null;
|
||||
}
|
||||
@@ -398,7 +410,7 @@ public class JetPsiUtil {
|
||||
return false;
|
||||
}
|
||||
|
||||
return KotlinBuiltIns.getInstance().getUnit().getName().getName().equals(typeReference.getText());
|
||||
return KotlinBuiltIns.getInstance().getUnit().getName().asString().equals(typeReference.getText());
|
||||
}
|
||||
|
||||
public static boolean isSafeCall(@NotNull Call call) {
|
||||
@@ -406,7 +418,7 @@ public class JetPsiUtil {
|
||||
return callOperationNode != null && callOperationNode.getElementType() == JetTokens.SAFE_ACCESS;
|
||||
}
|
||||
|
||||
public static boolean isFunctionLiteralWithoutDeclaredParameterTypes(JetExpression expression) {
|
||||
public static boolean isFunctionLiteralWithoutDeclaredParameterTypes(@Nullable JetExpression expression) {
|
||||
if (!(expression instanceof JetFunctionLiteralExpression)) return false;
|
||||
JetFunctionLiteralExpression functionLiteral = (JetFunctionLiteralExpression) expression;
|
||||
for (JetParameter parameter : functionLiteral.getValueParameters()) {
|
||||
@@ -458,6 +470,7 @@ public class JetPsiUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiElement getTopmostParentOfTypes(@Nullable PsiElement element, @NotNull Class<? extends PsiElement>... parentTypes) {
|
||||
if (element == null) {
|
||||
return null;
|
||||
@@ -564,6 +577,19 @@ public class JetPsiUtil {
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetClass getClassIfParameterIsProperty(@NotNull JetParameter jetParameter) {
|
||||
if (jetParameter.getValOrVarNode() != null) {
|
||||
PsiElement parent = jetParameter.getParent();
|
||||
if (parent instanceof JetParameterList && parent.getParent() instanceof JetClass) {
|
||||
return (JetClass) parent.getParent();
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static IElementType getOperation(@NotNull JetExpression expression) {
|
||||
if (expression instanceof JetQualifiedExpression) {
|
||||
return ((JetQualifiedExpression) expression).getOperationSign();
|
||||
@@ -621,4 +647,197 @@ public class JetPsiUtil {
|
||||
int parentPrecedence = getPrecedenceOfOperation(parentExpression, parentOperation);
|
||||
return innerPrecedence < parentPrecedence;
|
||||
}
|
||||
|
||||
public static boolean isAssignment(@NotNull PsiElement element) {
|
||||
return element instanceof JetBinaryExpression &&
|
||||
JetTokens.ALL_ASSIGNMENTS.contains(((JetBinaryExpression) element).getOperationToken());
|
||||
}
|
||||
|
||||
public static boolean isBranchedExpression(@Nullable PsiElement element) {
|
||||
return element instanceof JetIfExpression || element instanceof JetWhenExpression;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetElement getOutermostLastBlockElement(@Nullable JetElement element, @NotNull Predicate<JetElement> checkElement) {
|
||||
if (element == null) return null;
|
||||
|
||||
if (!(element instanceof JetBlockExpression)) return checkElement.apply(element) ? element : null;
|
||||
|
||||
JetBlockExpression block = (JetBlockExpression)element;
|
||||
int n = block.getStatements().size();
|
||||
|
||||
if (n == 0) return null;
|
||||
|
||||
JetElement lastElement = block.getStatements().get(n - 1);
|
||||
return checkElement.apply(lastElement) ? lastElement : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiElement getParentByTypeAndPredicate(
|
||||
@Nullable PsiElement element, @NotNull Class<? extends PsiElement> aClass, @NotNull Predicate<PsiElement> predicate, boolean strict) {
|
||||
if (element == null) return null;
|
||||
if (strict) {
|
||||
element = element.getParent();
|
||||
}
|
||||
|
||||
while (element != null) {
|
||||
//noinspection unchecked
|
||||
if (aClass.isInstance(element) && predicate.apply(element)) {
|
||||
//noinspection unchecked
|
||||
return element;
|
||||
}
|
||||
if (element instanceof PsiFile) return null;
|
||||
element = element.getParent();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean checkVariableDeclarationInBlock(@NotNull JetBlockExpression block, @NotNull String varName) {
|
||||
for (JetElement element : block.getStatements()) {
|
||||
if (element instanceof JetVariableDeclaration) {
|
||||
if (((JetVariableDeclaration) element).getNameAsSafeName().asString().equals(varName)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static <C extends Collection<JetVariableDeclaration>> C getBlockVariableDeclarations(@NotNull JetBlockExpression block, @NotNull C collection) {
|
||||
for (JetElement element : block.getStatements()) {
|
||||
if (element instanceof JetVariableDeclaration) {
|
||||
collection.add((JetVariableDeclaration) element);
|
||||
}
|
||||
}
|
||||
|
||||
return collection;
|
||||
}
|
||||
|
||||
public static boolean checkWhenExpressionHasSingleElse(@NotNull JetWhenExpression whenExpression) {
|
||||
int elseCount = 0;
|
||||
for (JetWhenEntry entry : whenExpression.getEntries()) {
|
||||
if (entry.isElse()) {
|
||||
elseCount++;
|
||||
}
|
||||
}
|
||||
return (elseCount == 1);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiElement skipTrailingWhitespacesAndComments(@Nullable PsiElement element) {
|
||||
return PsiTreeUtil.skipSiblingsForward(element, PsiWhiteSpace.class, PsiComment.class);
|
||||
}
|
||||
|
||||
public static final Predicate<JetElement> ANY_JET_ELEMENT = new Predicate<JetElement>() {
|
||||
@Override
|
||||
public boolean apply(@Nullable JetElement input) {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
@NotNull
|
||||
public static String getText(@Nullable PsiElement element) {
|
||||
return element != null ? element.getText() : "";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static String getNullableText(@Nullable PsiElement element) {
|
||||
return element != null ? element.getText() : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* CommentUtilCore.isComment fails if element <strong>inside</strong> comment.
|
||||
*
|
||||
* Also, we can not add KDocTokens to COMMENTS TokenSet, because it is used in JetParserDefinition.getCommentTokens(),
|
||||
* and therefor all COMMENTS tokens will be ignored by PsiBuilder.
|
||||
*
|
||||
* @param element
|
||||
* @return
|
||||
*/
|
||||
public static boolean isInComment(PsiElement element) {
|
||||
return CommentUtilCore.isComment(element) || element instanceof KDocElement;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiElement getOutermostParent(@NotNull PsiElement element, @NotNull PsiElement upperBound, boolean strict) {
|
||||
PsiElement parent = strict ? element.getParent() : element;
|
||||
while (parent != null && parent.getParent() != upperBound) {
|
||||
parent = parent.getParent();
|
||||
}
|
||||
|
||||
return parent;
|
||||
}
|
||||
|
||||
public static <T extends PsiElement> T getLastChildByType(@NotNull PsiElement root, @NotNull Class<? extends T>... elementTypes) {
|
||||
PsiElement[] children = root.getChildren();
|
||||
|
||||
for (int i = children.length - 1; i >= 0; i--) {
|
||||
if (PsiTreeUtil.instanceOf(children[i], elementTypes)) {
|
||||
//noinspection unchecked
|
||||
return (T) children[i];
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static <T extends JetElement> T getOutermostJetElement(
|
||||
@Nullable PsiElement root,
|
||||
boolean first,
|
||||
@NotNull final Class<? extends T>... elementTypes
|
||||
) {
|
||||
if (!(root instanceof JetElement)) return null;
|
||||
|
||||
final List<T> results = Lists.newArrayList();
|
||||
|
||||
((JetElement) root).accept(
|
||||
new JetVisitorVoid() {
|
||||
@Override
|
||||
public void visitJetElement(JetElement element) {
|
||||
if (PsiTreeUtil.instanceOf(element, elementTypes)) {
|
||||
//noinspection unchecked
|
||||
results.add((T) element);
|
||||
}
|
||||
else {
|
||||
element.acceptChildren(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
if (results.isEmpty()) return null;
|
||||
|
||||
return first ? results.get(0) : results.get(results.size() - 1);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static PsiElement findChildByType(@NotNull PsiElement element, @NotNull IElementType type) {
|
||||
ASTNode node = element.getNode().findChildByType(type);
|
||||
return node == null ? null : node.getPsi();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static JetExpression getCalleeExpressionIfAny(@NotNull JetExpression expression) {
|
||||
if (expression instanceof JetCallElement) {
|
||||
JetCallElement callExpression = (JetCallElement) expression;
|
||||
return callExpression.getCalleeExpression();
|
||||
}
|
||||
if (expression instanceof JetQualifiedExpression) {
|
||||
JetExpression selectorExpression = ((JetQualifiedExpression) expression).getSelectorExpression();
|
||||
if (selectorExpression != null) {
|
||||
return getCalleeExpressionIfAny(selectorExpression);
|
||||
}
|
||||
}
|
||||
if (expression instanceof JetUnaryExpression) {
|
||||
return ((JetUnaryExpression) expression).getOperationReference();
|
||||
}
|
||||
if (expression instanceof JetBinaryExpression) {
|
||||
return ((JetBinaryExpression) expression).getOperationReference();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -408,5 +408,4 @@ public class JetVisitor<R, D> extends PsiElementVisitor {
|
||||
public R visitEscapeStringTemplateEntry(JetEscapeStringTemplateEntry entry, D data) {
|
||||
return visitStringTemplateEntry(entry, data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -60,4 +60,14 @@ public class JetWhenExpression extends JetExpressionImpl {
|
||||
ASTNode openBraceNode = getNode().findChildByType(JetTokens.RBRACE);
|
||||
return openBraceNode != null ? openBraceNode.getPsi() : null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JetExpression getElseExpression() {
|
||||
for (JetWhenEntry entry : getEntries()) {
|
||||
if (entry.isElse()) {
|
||||
return entry.getExpression();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -50,7 +50,7 @@ public class JetAnnotationElementType extends JetStubElementType<PsiJetAnnotatio
|
||||
@Override
|
||||
public PsiJetAnnotationStub createStub(@NotNull JetAnnotationEntry psi, StubElement parentStub) {
|
||||
Name shortName = JetPsiUtil.getShortName(psi);
|
||||
String resultName = shortName != null ? shortName.getName() : psi.getText();
|
||||
String resultName = shortName != null ? shortName.asString() : psi.getText();
|
||||
return new PsiJetAnnotationStubImpl(parentStub, JetStubElementTypes.ANNOTATION_ENTRY, resultName);
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -54,7 +54,7 @@ public class JetClassElementType extends JetStubElementType<PsiJetClassStub, Jet
|
||||
public PsiJetClassStub createStub(@NotNull JetClass psi, StubElement parentStub) {
|
||||
FqName fqName = JetPsiUtil.getFQName(psi);
|
||||
boolean isEnumEntry = psi instanceof JetEnumEntry;
|
||||
return new PsiJetClassStubImpl(getStubType(isEnumEntry), parentStub, fqName != null ? fqName.getFqName() : null, psi.getName(),
|
||||
return new PsiJetClassStubImpl(getStubType(isEnumEntry), parentStub, fqName != null ? fqName.asString() : null, psi.getName(),
|
||||
psi.getSuperNames(), psi.isTrait(), psi.isEnum(), isEnumEntry, psi.isAnnotation(), psi.isInner());
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ public class JetClassElementType extends JetStubElementType<PsiJetClassStub, Jet
|
||||
public void serialize(PsiJetClassStub stub, StubOutputStream dataStream) throws IOException {
|
||||
dataStream.writeName(stub.getName());
|
||||
FqName fqName = stub.getFqName();
|
||||
dataStream.writeName(fqName == null ? null : fqName.getFqName());
|
||||
dataStream.writeName(fqName == null ? null : fqName.asString());
|
||||
dataStream.writeBoolean(stub.isTrait());
|
||||
dataStream.writeBoolean(stub.isEnumClass());
|
||||
dataStream.writeBoolean(stub.isEnumEntry());
|
||||
|
||||
+11
-4
@@ -23,10 +23,7 @@ import com.intellij.psi.stubs.StubElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetBlockExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetExpression;
|
||||
import org.jetbrains.jet.lang.psi.JetFunctionLiteral;
|
||||
import org.jetbrains.jet.lang.psi.JetWithExpressionInitializer;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.plugin.JetLanguage;
|
||||
|
||||
public abstract class JetStubElementType<StubT extends StubElement, PsiT extends PsiElement> extends IStubElementType<StubT, PsiT> {
|
||||
@@ -67,6 +64,16 @@ public abstract class JetStubElementType<StubT extends StubElement, PsiT extends
|
||||
}
|
||||
}
|
||||
|
||||
// Don't create stubs if declaration is inside property delegate
|
||||
@SuppressWarnings("unchecked") JetPropertyDelegate delegate =
|
||||
PsiTreeUtil.getParentOfType(psi, JetPropertyDelegate.class, true, JetBlockExpression.class);
|
||||
if (delegate != null) {
|
||||
JetExpression delegateExpression = delegate.getExpression();
|
||||
if (PsiTreeUtil.isAncestor(delegateExpression, psi, true)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return super.shouldCreateStub(node);
|
||||
}
|
||||
}
|
||||
|
||||
+19
-1
@@ -16,14 +16,21 @@
|
||||
|
||||
package org.jetbrains.jet.lang.psi.stubs.impl;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.impl.java.stubs.PsiClassStub;
|
||||
import com.intellij.psi.stubs.PsiClassHolderFileStub;
|
||||
import com.intellij.psi.stubs.PsiFileStubImpl;
|
||||
import com.intellij.psi.stubs.StubElement;
|
||||
import com.intellij.psi.tree.IStubFileElementType;
|
||||
import com.intellij.util.io.StringRef;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.stubs.PsiJetFileStub;
|
||||
import org.jetbrains.jet.lang.psi.stubs.elements.JetStubElementTypes;
|
||||
|
||||
public class PsiJetFileStubImpl extends PsiFileStubImpl<JetFile> implements PsiJetFileStub {
|
||||
import java.util.List;
|
||||
|
||||
public class PsiJetFileStubImpl extends PsiFileStubImpl<JetFile> implements PsiJetFileStub, PsiClassHolderFileStub<JetFile> {
|
||||
|
||||
private final StringRef packageName;
|
||||
private final boolean isScript;
|
||||
@@ -65,4 +72,15 @@ public class PsiJetFileStubImpl extends PsiFileStubImpl<JetFile> implements PsiJ
|
||||
|
||||
return builder.toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiClass[] getClasses() {
|
||||
List<PsiClass> result = Lists.newArrayList();
|
||||
for (StubElement child : getChildrenStubs()) {
|
||||
if (child instanceof PsiClassStub) {
|
||||
result.add((PsiClass) child.getPsi());
|
||||
}
|
||||
}
|
||||
return result.toArray(new PsiClass[result.size()]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,11 +93,11 @@ public class AnnotationResolver {
|
||||
ConstructorDescriptor constructor = (ConstructorDescriptor)descriptor;
|
||||
ClassDescriptor classDescriptor = constructor.getContainingDeclaration();
|
||||
if (classDescriptor.getKind() != ClassKind.ANNOTATION_CLASS) {
|
||||
trace.report(Errors.NOT_AN_ANNOTATION_CLASS.on(entryElement, classDescriptor.getName().getName()));
|
||||
trace.report(Errors.NOT_AN_ANNOTATION_CLASS.on(entryElement, classDescriptor.getName().asString()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
trace.report(Errors.NOT_AN_ANNOTATION_CLASS.on(entryElement, descriptor.getName().getName()));
|
||||
trace.report(Errors.NOT_AN_ANNOTATION_CLASS.on(entryElement, descriptor.getName().asString()));
|
||||
}
|
||||
}
|
||||
JetType annotationType = results.getResultingDescriptor().getReturnType();
|
||||
|
||||
@@ -26,6 +26,7 @@ import org.jetbrains.jet.lang.descriptors.annotations.AnnotationDescriptor;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.autocasts.DataFlowInfo;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemCompleter;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.constants.CompileTimeConstant;
|
||||
import org.jetbrains.jet.lang.resolve.name.FqName;
|
||||
@@ -83,6 +84,7 @@ public interface BindingContext {
|
||||
new BasicWritableSlice<JetReferenceExpression, DeclarationDescriptor>(DO_NOTHING);
|
||||
WritableSlice<JetElement, ResolvedCall<? extends CallableDescriptor>> RESOLVED_CALL =
|
||||
new BasicWritableSlice<JetElement, ResolvedCall<? extends CallableDescriptor>>(DO_NOTHING);
|
||||
WritableSlice<JetElement, ConstraintSystemCompleter> CONSTRAINT_SYSTEM_COMPLETER = new BasicWritableSlice<JetElement, ConstraintSystemCompleter>(DO_NOTHING);
|
||||
WritableSlice<JetElement, Call> CALL = new BasicWritableSlice<JetElement, Call>(DO_NOTHING);
|
||||
|
||||
WritableSlice<JetReferenceExpression, Collection<? extends DeclarationDescriptor>> AMBIGUOUS_REFERENCE_TARGET =
|
||||
|
||||
@@ -26,6 +26,10 @@ import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.FunctionDescriptorUtil;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.MutableClassDescriptor;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintPosition;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystem;
|
||||
import org.jetbrains.jet.lang.resolve.calls.inference.ConstraintSystemCompleter;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.calls.util.CallMaker;
|
||||
import org.jetbrains.jet.lang.resolve.calls.CallResolver;
|
||||
import org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults;
|
||||
@@ -36,6 +40,7 @@ import org.jetbrains.jet.lang.types.*;
|
||||
import org.jetbrains.jet.lang.types.checker.JetTypeChecker;
|
||||
import org.jetbrains.jet.lang.types.expressions.DelegatedPropertyUtils;
|
||||
import org.jetbrains.jet.lang.types.expressions.ExpressionTypingServices;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
import org.jetbrains.jet.util.Box;
|
||||
import org.jetbrains.jet.util.lazy.ReenteringLazyValueComputationException;
|
||||
@@ -46,7 +51,8 @@ import java.util.*;
|
||||
|
||||
import static org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER;
|
||||
import static org.jetbrains.jet.lang.diagnostics.Errors.*;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.DEFERRED_TYPE;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.*;
|
||||
import static org.jetbrains.jet.lang.resolve.calls.results.OverloadResolutionResults.Code;
|
||||
import static org.jetbrains.jet.lang.types.TypeUtils.NO_EXPECTED_TYPE;
|
||||
|
||||
public class BodyResolver {
|
||||
@@ -382,17 +388,18 @@ public class BodyResolver {
|
||||
computeDeferredType(propertyDescriptor.getReturnType());
|
||||
|
||||
JetExpression initializer = property.getInitializer();
|
||||
JetScope propertyScope = getScopeForProperty(property);
|
||||
if (initializer != null) {
|
||||
ConstructorDescriptor primaryConstructor = classDescriptor.getUnsubstitutedPrimaryConstructor();
|
||||
if (primaryConstructor != null) {
|
||||
resolvePropertyInitializer(property, propertyDescriptor, initializer);
|
||||
resolvePropertyInitializer(property, propertyDescriptor, initializer, propertyScope);
|
||||
}
|
||||
}
|
||||
|
||||
JetExpression delegateExpression = property.getDelegateExpression();
|
||||
if (delegateExpression != null) {
|
||||
assert initializer == null : "Initializer should be null for delegated property : " + property.getText();
|
||||
resolvePropertyDelegate(property, propertyDescriptor, delegateExpression, classDescriptor.getScopeForMemberResolution());
|
||||
resolvePropertyDelegate(property, propertyDescriptor, delegateExpression, classDescriptor.getScopeForMemberResolution(), propertyScope);
|
||||
}
|
||||
|
||||
resolvePropertyAccessors(property, propertyDescriptor);
|
||||
@@ -411,15 +418,15 @@ public class BodyResolver {
|
||||
computeDeferredType(propertyDescriptor.getReturnType());
|
||||
|
||||
JetExpression initializer = property.getInitializer();
|
||||
JetScope propertyScope = getScopeForProperty(property);
|
||||
if (initializer != null) {
|
||||
resolvePropertyInitializer(property, propertyDescriptor, initializer);
|
||||
resolvePropertyInitializer(property, propertyDescriptor, initializer, propertyScope);
|
||||
}
|
||||
|
||||
JetExpression delegateExpression = property.getDelegateExpression();
|
||||
if (delegateExpression != null) {
|
||||
assert initializer == null : "Initializer should be null for delegated property : " + property.getText();
|
||||
JetScope scope = context.getDeclaringScopes().apply(property);
|
||||
resolvePropertyDelegate(property, propertyDescriptor, delegateExpression, scope);
|
||||
resolvePropertyDelegate(property, propertyDescriptor, delegateExpression, propertyScope, propertyScope);
|
||||
}
|
||||
|
||||
resolvePropertyAccessors(property, propertyDescriptor);
|
||||
@@ -467,11 +474,12 @@ public class BodyResolver {
|
||||
});
|
||||
}
|
||||
|
||||
private void resolvePropertyDelegate(
|
||||
public void resolvePropertyDelegate(
|
||||
@NotNull JetProperty jetProperty,
|
||||
@NotNull PropertyDescriptor propertyDescriptor,
|
||||
@NotNull JetExpression delegateExpression,
|
||||
@NotNull JetScope parentScopeForAccessor
|
||||
@NotNull JetScope parentScopeForAccessor,
|
||||
@NotNull JetScope propertyScope
|
||||
) {
|
||||
JetPropertyAccessor getter = jetProperty.getGetter();
|
||||
if (getter != null) {
|
||||
@@ -483,11 +491,27 @@ public class BodyResolver {
|
||||
trace.report(ACCESSOR_FOR_DELEGATED_PROPERTY.on(setter));
|
||||
}
|
||||
|
||||
JetScope scope = makeScopeForPropertyInitializerOrDelegate(jetProperty, propertyDescriptor);
|
||||
JetType delegateType = expressionTypingServices.safeGetType(scope, delegateExpression, NO_EXPECTED_TYPE,
|
||||
DataFlowInfo.EMPTY, trace);
|
||||
JetScope propertyDeclarationInnerScope = descriptorResolver.getPropertyDeclarationInnerScopeForInitializer(
|
||||
propertyScope, propertyDescriptor.getTypeParameters(), NO_RECEIVER_PARAMETER, trace);
|
||||
TemporaryBindingTrace traceToResolveDelegatedProperty = TemporaryBindingTrace.create(trace, "Trace to resolve delegated property");
|
||||
JetScope accessorScope = JetScopeUtils.makeScopeForPropertyAccessor(
|
||||
propertyDescriptor, parentScopeForAccessor, descriptorResolver, trace);
|
||||
|
||||
JetExpression calleeExpression = JetPsiUtil.getCalleeExpressionIfAny(delegateExpression);
|
||||
ConstraintSystemCompleter completer =
|
||||
createConstraintSystemCompleter(jetProperty, propertyDescriptor, delegateExpression, accessorScope);
|
||||
if (calleeExpression != null) {
|
||||
traceToResolveDelegatedProperty.record(CONSTRAINT_SYSTEM_COMPLETER, calleeExpression, completer);
|
||||
}
|
||||
JetType delegateType = expressionTypingServices.safeGetType(propertyDeclarationInnerScope, delegateExpression, NO_EXPECTED_TYPE,
|
||||
DataFlowInfo.EMPTY, traceToResolveDelegatedProperty);
|
||||
traceToResolveDelegatedProperty.commit(new TraceEntryFilter() {
|
||||
@Override
|
||||
public boolean accept(@NotNull WritableSlice<?, ?> slice, Object key) {
|
||||
return slice != CONSTRAINT_SYSTEM_COMPLETER;
|
||||
}
|
||||
}, true);
|
||||
|
||||
JetScope accessorScope = JetScopeUtils.makeScopeForPropertyAccessor(propertyDescriptor, parentScopeForAccessor, descriptorResolver, trace);
|
||||
DelegatedPropertyUtils.resolveDelegatedPropertyGetMethod(propertyDescriptor, delegateExpression, delegateType,
|
||||
expressionTypingServices, trace, accessorScope);
|
||||
|
||||
@@ -497,12 +521,83 @@ public class BodyResolver {
|
||||
}
|
||||
}
|
||||
|
||||
private void resolvePropertyInitializer(JetProperty property, PropertyDescriptor propertyDescriptor, JetExpression initializer) {
|
||||
JetScope propertyDeclarationInnerScope = makeScopeForPropertyInitializerOrDelegate(property, propertyDescriptor);
|
||||
resolvePropertyInitializer(property, propertyDescriptor, initializer, propertyDeclarationInnerScope);
|
||||
private ConstraintSystemCompleter createConstraintSystemCompleter(
|
||||
JetProperty property,
|
||||
final PropertyDescriptor propertyDescriptor,
|
||||
final JetExpression delegateExpression,
|
||||
final JetScope accessorScope
|
||||
) {
|
||||
final JetType expectedType = property.getTypeRef() != null ? propertyDescriptor.getType() : NO_EXPECTED_TYPE;
|
||||
return new ConstraintSystemCompleter() {
|
||||
@Override
|
||||
public void completeConstraintSystem(
|
||||
@NotNull ConstraintSystem constraintSystem, @NotNull ResolvedCall<?> resolvedCall
|
||||
) {
|
||||
JetType returnType = resolvedCall.getCandidateDescriptor().getReturnType();
|
||||
if (returnType == null) return;
|
||||
|
||||
TemporaryBindingTrace traceToResolveConventionMethods =
|
||||
TemporaryBindingTrace.create(trace, "Trace to resolve delegated property convention methods");
|
||||
OverloadResolutionResults<FunctionDescriptor>
|
||||
getMethodResults = DelegatedPropertyUtils.getDelegatedPropertyConventionMethod(
|
||||
propertyDescriptor, delegateExpression, returnType, expressionTypingServices,
|
||||
traceToResolveConventionMethods, accessorScope, true);
|
||||
|
||||
if (conventionMethodFound(getMethodResults)) {
|
||||
FunctionDescriptor descriptor = getMethodResults.getResultingDescriptor();
|
||||
JetType returnTypeOfGetMethod = descriptor.getReturnType();
|
||||
if (returnTypeOfGetMethod != null) {
|
||||
constraintSystem.addSupertypeConstraint(expectedType, returnTypeOfGetMethod, ConstraintPosition.FROM_COMPLETER);
|
||||
}
|
||||
addConstraintForThisValue(constraintSystem, descriptor);
|
||||
}
|
||||
if (!propertyDescriptor.isVar()) return;
|
||||
|
||||
OverloadResolutionResults<FunctionDescriptor> setMethodResults =
|
||||
DelegatedPropertyUtils.getDelegatedPropertyConventionMethod(
|
||||
propertyDescriptor, delegateExpression, returnType, expressionTypingServices,
|
||||
traceToResolveConventionMethods, accessorScope, false);
|
||||
|
||||
if (conventionMethodFound(setMethodResults)) {
|
||||
FunctionDescriptor descriptor = setMethodResults.getResultingDescriptor();
|
||||
List<ValueParameterDescriptor> valueParameters = descriptor.getValueParameters();
|
||||
if (valueParameters.size() == 3) {
|
||||
ValueParameterDescriptor valueParameterForThis = valueParameters.get(2);
|
||||
|
||||
constraintSystem.addSubtypeConstraint(expectedType, valueParameterForThis.getType(), ConstraintPosition.FROM_COMPLETER);
|
||||
addConstraintForThisValue(constraintSystem, descriptor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean conventionMethodFound(@NotNull OverloadResolutionResults<FunctionDescriptor> results) {
|
||||
return results.isSuccess() ||
|
||||
(results.isSingleResult() && results.getResultCode() == Code.SINGLE_CANDIDATE_ARGUMENT_MISMATCH);
|
||||
}
|
||||
|
||||
private void addConstraintForThisValue(ConstraintSystem constraintSystem, FunctionDescriptor resultingDescriptor) {
|
||||
ReceiverParameterDescriptor receiverParameter = propertyDescriptor.getReceiverParameter();
|
||||
ReceiverParameterDescriptor thisObject = propertyDescriptor.getExpectedThisObject();
|
||||
JetType typeOfThis =
|
||||
receiverParameter != null ? receiverParameter.getType() :
|
||||
thisObject != null ? thisObject.getType() :
|
||||
KotlinBuiltIns.getInstance().getNullableNothingType();
|
||||
|
||||
List<ValueParameterDescriptor> valueParameters = resultingDescriptor.getValueParameters();
|
||||
if (valueParameters.isEmpty()) return;
|
||||
ValueParameterDescriptor valueParameterForThis = valueParameters.get(0);
|
||||
|
||||
constraintSystem.addSubtypeConstraint(typeOfThis, valueParameterForThis.getType(), ConstraintPosition.FROM_COMPLETER);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public void resolvePropertyInitializer(JetProperty property, PropertyDescriptor propertyDescriptor, JetExpression initializer, JetScope scope) {
|
||||
public void resolvePropertyInitializer(
|
||||
@NotNull JetProperty property,
|
||||
@NotNull PropertyDescriptor propertyDescriptor,
|
||||
@NotNull JetExpression initializer,
|
||||
@NotNull JetScope scope
|
||||
) {
|
||||
JetScope propertyDeclarationInnerScope = descriptorResolver.getPropertyDeclarationInnerScopeForInitializer(
|
||||
scope, propertyDescriptor.getTypeParameters(), NO_RECEIVER_PARAMETER, trace);
|
||||
JetType expectedTypeForInitializer = property.getTypeRef() != null ? propertyDescriptor.getType() : NO_EXPECTED_TYPE;
|
||||
@@ -510,11 +605,10 @@ public class BodyResolver {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private JetScope makeScopeForPropertyInitializerOrDelegate(@NotNull JetProperty property, @NotNull PropertyDescriptor descriptor) {
|
||||
private JetScope getScopeForProperty(@NotNull JetProperty property) {
|
||||
JetScope scope = this.context.getDeclaringScopes().apply(property);
|
||||
assert scope != null : "Scope for property " + property.getText() + " should exists";
|
||||
return descriptorResolver.getPropertyDeclarationInnerScopeForInitializer(
|
||||
scope, descriptor.getTypeParameters(), NO_RECEIVER_PARAMETER, trace);
|
||||
return scope;
|
||||
}
|
||||
|
||||
private void resolveFunctionBodies() {
|
||||
|
||||
@@ -313,7 +313,7 @@ public class DeclarationResolver {
|
||||
for (PsiElement declaration : getDeclarationsByDescriptor(declarationDescriptor)) {
|
||||
assert declaration != null : "Null declaration for descriptor: " + declarationDescriptor + " " +
|
||||
(declarationDescriptor != null ? DescriptorRenderer.TEXT.render(declarationDescriptor) : "");
|
||||
trace.report(REDECLARATION.on(declaration, declarationDescriptor.getName().getName()));
|
||||
trace.report(REDECLARATION.on(declaration, declarationDescriptor.getName().asString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -402,7 +402,7 @@ public class DeclarationResolver {
|
||||
}
|
||||
}
|
||||
for (Pair<PsiElement, Name> redeclaration : redeclarations) {
|
||||
trace.report(REDECLARATION.on(redeclaration.getFirst(), redeclaration.getSecond().getName()));
|
||||
trace.report(REDECLARATION.on(redeclaration.getFirst(), redeclaration.getSecond().asString()));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -280,7 +280,7 @@ public class DeclarationsChecker {
|
||||
boolean inEnum = classDescriptor.getKind() == ClassKind.ENUM_CLASS;
|
||||
boolean inAbstractClass = classDescriptor.getModality() == Modality.ABSTRACT;
|
||||
if (hasAbstractModifier && !inAbstractClass && !inEnum) {
|
||||
trace.report(ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS.on(function, functionDescriptor.getName().getName(), classDescriptor));
|
||||
trace.report(ABSTRACT_FUNCTION_IN_NON_ABSTRACT_CLASS.on(function, functionDescriptor.getName().asString(), classDescriptor));
|
||||
}
|
||||
if (hasAbstractModifier && inTrait) {
|
||||
trace.report(ABSTRACT_MODIFIER_IN_TRAIT.on(function));
|
||||
|
||||
@@ -1470,14 +1470,31 @@ public class DescriptorResolver {
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull PsiElement reportErrorsOn,
|
||||
@NotNull ClassDescriptor target
|
||||
) {
|
||||
return checkHasOuterClassInstance(scope, trace, reportErrorsOn, target, true);
|
||||
}
|
||||
|
||||
public static boolean checkHasOuterClassInstance(
|
||||
@NotNull JetScope scope,
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull PsiElement reportErrorsOn,
|
||||
@NotNull ClassDescriptor target,
|
||||
boolean doSuperClassCheck
|
||||
) {
|
||||
DeclarationDescriptor descriptor = getContainingClass(scope);
|
||||
|
||||
while (descriptor != null) {
|
||||
if (descriptor instanceof ClassDescriptor) {
|
||||
ClassDescriptor classDescriptor = (ClassDescriptor) descriptor;
|
||||
if (isSubclass(classDescriptor, target)) {
|
||||
|
||||
if (classDescriptor == target) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (doSuperClassCheck && isSubclass(classDescriptor, target)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (isStaticNestedClass(classDescriptor)) {
|
||||
trace.report(INACCESSIBLE_OUTER_CLASS_EXPRESSION.on(reportErrorsOn, classDescriptor));
|
||||
return false;
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.google.common.base.Predicate;
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
@@ -362,7 +363,7 @@ public class DescriptorUtils {
|
||||
|
||||
@NotNull
|
||||
public static Name getClassObjectName(@NotNull Name className) {
|
||||
return getClassObjectName(className.getName());
|
||||
return getClassObjectName(className.asString());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -404,7 +405,7 @@ public class DescriptorUtils {
|
||||
String typeSuffix = rendererForTypesIfNecessary == null
|
||||
? ""
|
||||
: ": " + rendererForTypesIfNecessary.renderType(value.getType(KotlinBuiltIns.getInstance()));
|
||||
resultList.add(entry.getKey().getName().getName() + " = " + value.toString() + typeSuffix);
|
||||
resultList.add(entry.getKey().getName().asString() + " = " + value.toString() + typeSuffix);
|
||||
}
|
||||
Collections.sort(resultList);
|
||||
return resultList;
|
||||
@@ -535,14 +536,26 @@ public class DescriptorUtils {
|
||||
public static boolean isEnumValueOfMethod(@NotNull FunctionDescriptor functionDescriptor) {
|
||||
List<ValueParameterDescriptor> methodTypeParameters = functionDescriptor.getValueParameters();
|
||||
JetType nullableString = TypeUtils.makeNullable(KotlinBuiltIns.getInstance().getStringType());
|
||||
return "valueOf".equals(functionDescriptor.getName().getName())
|
||||
return "valueOf".equals(functionDescriptor.getName().asString())
|
||||
&& methodTypeParameters.size() == 1
|
||||
&& JetTypeChecker.INSTANCE.isSubtypeOf(methodTypeParameters.get(0).getType(), nullableString);
|
||||
}
|
||||
|
||||
public static boolean isEnumValuesMethod(@NotNull FunctionDescriptor functionDescriptor) {
|
||||
List<ValueParameterDescriptor> methodTypeParameters = functionDescriptor.getValueParameters();
|
||||
return "values".equals(functionDescriptor.getName().getName())
|
||||
return "values".equals(functionDescriptor.getName().asString())
|
||||
&& methodTypeParameters.isEmpty();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static Set<ClassDescriptor> getAllSuperClasses(@NotNull ClassDescriptor klass) {
|
||||
Set<JetType> allSupertypes = TypeUtils.getAllSupertypes(klass.getDefaultType());
|
||||
Set<ClassDescriptor> allSuperclasses = Sets.newHashSet();
|
||||
for (JetType supertype : allSupertypes) {
|
||||
ClassDescriptor superclass = TypeUtils.getClassDescriptor(supertype);
|
||||
assert superclass != null;
|
||||
allSuperclasses.add(superclass);
|
||||
}
|
||||
return allSuperclasses;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,12 +50,12 @@ public final class ImportPath {
|
||||
}
|
||||
|
||||
public String getPathStr() {
|
||||
return fqName.getFqName() + (isAllUnder ? ".*" : "");
|
||||
return fqName.asString() + (isAllUnder ? ".*" : "");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getPathStr() + (alias != null ? " as " + alias.getName() : "");
|
||||
return getPathStr() + (alias != null ? " as " + alias.asString() : "");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -75,7 +75,7 @@ public class OverloadResolver {
|
||||
}
|
||||
|
||||
Key(NamespaceDescriptor namespaceDescriptor, Name name) {
|
||||
this(DescriptorUtils.getFQName(namespaceDescriptor).getFqName(), name);
|
||||
this(DescriptorUtils.getFQName(namespaceDescriptor).asString(), name);
|
||||
}
|
||||
|
||||
public String getNamespace() {
|
||||
@@ -149,7 +149,7 @@ public class OverloadResolver {
|
||||
}
|
||||
if (jetClass instanceof JetObjectDeclaration) {
|
||||
// must be class object
|
||||
name = classDescriptor.getContainingDeclaration().getName().getName();
|
||||
name = classDescriptor.getContainingDeclaration().getName().asString();
|
||||
return "class object " + name;
|
||||
}
|
||||
// safe
|
||||
@@ -223,7 +223,7 @@ public class OverloadResolver {
|
||||
CallableMemberDescriptor memberDescriptor = redeclaration.getSecond();
|
||||
JetDeclaration jetDeclaration = redeclaration.getFirst();
|
||||
if (memberDescriptor instanceof PropertyDescriptor) {
|
||||
trace.report(Errors.REDECLARATION.on(jetDeclaration, memberDescriptor.getName().getName()));
|
||||
trace.report(Errors.REDECLARATION.on(jetDeclaration, memberDescriptor.getName().asString()));
|
||||
}
|
||||
else {
|
||||
trace.report(Errors.CONFLICTING_OVERLOADS.on(jetDeclaration, memberDescriptor, functionContainer));
|
||||
|
||||
@@ -155,7 +155,7 @@ public class OverrideResolver {
|
||||
public void conflict(@NotNull CallableMemberDescriptor fromSuper, @NotNull CallableMemberDescriptor fromCurrent) {
|
||||
JetDeclaration declaration = (JetDeclaration) BindingContextUtils
|
||||
.descriptorToDeclaration(trace.getBindingContext(), fromCurrent);
|
||||
trace.report(Errors.CONFLICTING_OVERLOADS.on(declaration, fromCurrent, fromCurrent.getContainingDeclaration().getName().getName()));
|
||||
trace.report(Errors.CONFLICTING_OVERLOADS.on(declaration, fromCurrent, fromCurrent.getContainingDeclaration().getName().asString()));
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -586,7 +586,7 @@ public class OverrideResolver {
|
||||
private void checkOverrideForMember(@NotNull final CallableMemberDescriptor declared) {
|
||||
if (declared.getKind() == CallableMemberDescriptor.Kind.SYNTHESIZED) {
|
||||
// TODO: this should be replaced soon by a framework of synthesized member generation tools
|
||||
if (declared.getName().getName().startsWith(DescriptorResolver.COMPONENT_FUNCTION_NAME_PREFIX)) {
|
||||
if (declared.getName().asString().startsWith(DescriptorResolver.COMPONENT_FUNCTION_NAME_PREFIX)) {
|
||||
checkOverrideForComponentFunction(declared);
|
||||
}
|
||||
return;
|
||||
|
||||
+1
-1
@@ -39,7 +39,7 @@ public class TraceBasedRedeclarationHandler implements RedeclarationHandler {
|
||||
private void report(DeclarationDescriptor descriptor) {
|
||||
PsiElement firstElement = BindingContextUtils.descriptorToDeclaration(trace.getBindingContext(), descriptor);
|
||||
if (firstElement != null) {
|
||||
trace.report(REDECLARATION.on(firstElement, descriptor.getName().getName()));
|
||||
trace.report(REDECLARATION.on(firstElement, descriptor.getName().asString()));
|
||||
}
|
||||
else {
|
||||
throw new IllegalStateException("No declaration found for " + descriptor);
|
||||
|
||||
@@ -28,10 +28,7 @@ import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.descriptors.impl.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.name.Name;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.JetScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WritableScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.WriteThroughScope;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.*;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.SubstitutionUtils;
|
||||
import org.jetbrains.jet.lang.types.TypeConstructor;
|
||||
@@ -147,40 +144,6 @@ public class TypeHierarchyResolver {
|
||||
checkTypesInClassHeaders(); // Check bounds in the types used in generic bounds and supertype lists
|
||||
}
|
||||
|
||||
/**
|
||||
* Use nearest class object scope or namespace scope
|
||||
*
|
||||
* @param declarationElement
|
||||
* @param owner
|
||||
* @return
|
||||
*/
|
||||
@SuppressWarnings("SuspiciousMethodCalls")
|
||||
@NotNull
|
||||
private JetScope getStaticScope(PsiElement declarationElement, @NotNull NamespaceLikeBuilder owner) {
|
||||
DeclarationDescriptor ownerDescriptor = owner.getOwnerForChildren();
|
||||
if (ownerDescriptor instanceof NamespaceDescriptorImpl) {
|
||||
return context.getNamespaceScopes().get(declarationElement.getContainingFile());
|
||||
}
|
||||
|
||||
if (ownerDescriptor instanceof MutableClassDescriptor) {
|
||||
MutableClassDescriptor classDescriptor = (MutableClassDescriptor) ownerDescriptor;
|
||||
if (classDescriptor.getKind() == ClassKind.CLASS_OBJECT) {
|
||||
return classDescriptor.getScopeForMemberResolution();
|
||||
}
|
||||
|
||||
DeclarationDescriptor declaration = classDescriptor.getContainingDeclaration();
|
||||
if (declaration instanceof NamespaceDescriptorImpl) {
|
||||
return getStaticScope(declarationElement, ((NamespaceDescriptorImpl) declaration).getBuilder());
|
||||
}
|
||||
|
||||
if (declaration instanceof MutableClassDescriptorLite) {
|
||||
return getStaticScope(declarationElement, ((MutableClassDescriptorLite) declaration).getBuilder());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Collection<JetDeclarationContainer> collectNamespacesAndClassifiers(
|
||||
@NotNull JetScope outerScope,
|
||||
@@ -517,7 +480,7 @@ public class TypeHierarchyResolver {
|
||||
MutableClassDescriptorLite classObjectDescriptor = ownerClassDescriptor.getClassObjectDescriptor();
|
||||
|
||||
assert classObjectDescriptor != null : enumEntry.getParent().getText();
|
||||
createClassDescriptorForEnumEntry(enumEntry, classObjectDescriptor.getBuilder());
|
||||
createClassDescriptorForEnumEntry(enumEntry, classObjectDescriptor);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -530,9 +493,11 @@ public class TypeHierarchyResolver {
|
||||
JetObjectDeclaration objectDeclaration = classObject.getObjectDeclaration();
|
||||
if (objectDeclaration != null) {
|
||||
Name classObjectName = getClassObjectName(owner.getOwnerForChildren().getName());
|
||||
MutableClassDescriptor classObjectDescriptor =
|
||||
createClassDescriptorForObject(objectDeclaration, owner, getStaticScope(classObject, owner),
|
||||
classObjectName, ClassKind.CLASS_OBJECT);
|
||||
|
||||
MutableClassDescriptor classObjectDescriptor = createClassDescriptorForObject(
|
||||
objectDeclaration, owner, outerScope,
|
||||
classObjectName, ClassKind.CLASS_OBJECT);
|
||||
|
||||
NamespaceLikeBuilder.ClassObjectStatus status = owner.setClassObjectDescriptor(classObjectDescriptor);
|
||||
switch (status) {
|
||||
case DUPLICATE:
|
||||
@@ -606,6 +571,7 @@ public class TypeHierarchyResolver {
|
||||
) {
|
||||
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(
|
||||
owner.getOwnerForChildren(), scope, kind, false, name);
|
||||
|
||||
context.getObjects().put(declaration, mutableClassDescriptor);
|
||||
|
||||
JetScope classScope = mutableClassDescriptor.getScopeForMemberResolution();
|
||||
@@ -619,10 +585,13 @@ public class TypeHierarchyResolver {
|
||||
|
||||
private MutableClassDescriptor createClassDescriptorForEnumEntry(
|
||||
@NotNull JetEnumEntry declaration,
|
||||
@NotNull NamespaceLikeBuilder owner
|
||||
@NotNull MutableClassDescriptorLite classObjectDescriptor
|
||||
) {
|
||||
NamespaceLikeBuilder owner = classObjectDescriptor.getBuilder();
|
||||
MutableClassDescriptor mutableClassObjectDescriptor = (MutableClassDescriptor) classObjectDescriptor;
|
||||
|
||||
MutableClassDescriptor mutableClassDescriptor = new MutableClassDescriptor(
|
||||
owner.getOwnerForChildren(), getStaticScope(declaration, owner), ClassKind.ENUM_ENTRY,
|
||||
owner.getOwnerForChildren(), mutableClassObjectDescriptor.getScopeForMemberResolution(), ClassKind.ENUM_ENTRY,
|
||||
false, JetPsiUtil.safeName(declaration.getName()));
|
||||
context.getClasses().put(declaration, mutableClassDescriptor);
|
||||
|
||||
|
||||
@@ -123,7 +123,8 @@ public class TypeResolver {
|
||||
|
||||
DeclarationDescriptor containing = typeParameterDescriptor.getContainingDeclaration();
|
||||
if (containing instanceof ClassDescriptor) {
|
||||
DescriptorResolver.checkHasOuterClassInstance(scope, trace, referenceExpression, (ClassDescriptor) containing);
|
||||
// Type parameter can't be inherited from member of parent class, so we can skip subclass check
|
||||
DescriptorResolver.checkHasOuterClassInstance(scope, trace, referenceExpression, (ClassDescriptor) containing, false);
|
||||
}
|
||||
}
|
||||
else if (classifierDescriptor instanceof ClassDescriptor) {
|
||||
@@ -342,7 +343,7 @@ public class TypeResolver {
|
||||
assert size != 0 : "No projections possible for a nilary type constructor" + constructor;
|
||||
ClassifierDescriptor declarationDescriptor = constructor.getDeclarationDescriptor();
|
||||
assert declarationDescriptor != null : "No declaration descriptor for type constructor " + constructor;
|
||||
String name = declarationDescriptor.getName().getName();
|
||||
String name = declarationDescriptor.getName().asString();
|
||||
|
||||
return TypeUtils.getTypeNameAndStarProjectionsString(name, size);
|
||||
}
|
||||
|
||||
@@ -51,7 +51,6 @@ import org.jetbrains.jet.lexer.JetTokens;
|
||||
import javax.inject.Inject;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.List;
|
||||
|
||||
import static org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor.NO_RECEIVER_PARAMETER;
|
||||
@@ -100,7 +99,7 @@ public class CallResolver {
|
||||
Name referencedName = nameExpression.getReferencedNameAsName();
|
||||
List<CallableDescriptorCollector<? extends VariableDescriptor>> callableDescriptorCollectors = Lists.newArrayList();
|
||||
if (nameExpression.getReferencedNameElementType() == JetTokens.FIELD_IDENTIFIER) {
|
||||
referencedName = Name.identifier(referencedName.getName().substring(1));
|
||||
referencedName = Name.identifier(referencedName.asString().substring(1));
|
||||
callableDescriptorCollectors.add(CallableDescriptorCollectors.PROPERTIES);
|
||||
}
|
||||
else {
|
||||
@@ -404,7 +403,7 @@ public class CallResolver {
|
||||
for (ResolutionTask<D, F> task : prioritizedTasks) {
|
||||
TemporaryBindingTrace taskTrace = TemporaryBindingTrace.create(context.trace, "trace to resolve a task for", task.reference);
|
||||
OverloadResolutionResultsImpl<F> results = performResolutionGuardedForExtraFunctionLiteralArguments(
|
||||
task.replaceBindingTrace(taskTrace), callTransformer, context.trace);
|
||||
task.replaceBindingTrace(taskTrace), callTransformer);
|
||||
if (results.isSuccess() || results.isAmbiguity()) {
|
||||
taskTrace.commit();
|
||||
|
||||
@@ -457,9 +456,9 @@ public class CallResolver {
|
||||
@NotNull
|
||||
private <D extends CallableDescriptor, F extends D> OverloadResolutionResultsImpl<F> performResolutionGuardedForExtraFunctionLiteralArguments(
|
||||
@NotNull ResolutionTask<D, F> task,
|
||||
@NotNull CallTransformer<D, F> callTransformer,
|
||||
@NotNull BindingTrace traceForResolutionCache) {
|
||||
OverloadResolutionResultsImpl<F> results = performResolution(task, callTransformer, traceForResolutionCache);
|
||||
@NotNull CallTransformer<D, F> callTransformer
|
||||
) {
|
||||
OverloadResolutionResultsImpl<F> results = performResolution(task, callTransformer);
|
||||
|
||||
// If resolution fails, we should check for some of the following situations:
|
||||
// class A {
|
||||
@@ -478,21 +477,23 @@ public class CallResolver {
|
||||
// }
|
||||
ImmutableSet<OverloadResolutionResults.Code> someFailed = ImmutableSet.of(OverloadResolutionResults.Code.MANY_FAILED_CANDIDATES,
|
||||
OverloadResolutionResults.Code.SINGLE_CANDIDATE_ARGUMENT_MISMATCH);
|
||||
if (someFailed.contains(results.getResultCode()) && !task.call.getFunctionLiteralArguments().isEmpty()) {
|
||||
if (someFailed.contains(results.getResultCode()) && !task.call.getFunctionLiteralArguments().isEmpty()
|
||||
&& task.resolveMode == ResolveMode.TOP_LEVEL_CALL) { //For nested calls there are no such cases
|
||||
// We have some candidates that failed for some reason
|
||||
// And we have a suspect: the function literal argument
|
||||
// Now, we try to remove this argument and see if it helps
|
||||
ResolutionTask<D, F> newTask = new ResolutionTask<D, F>(task.getCandidates(), task.reference, task.tracing,
|
||||
TemporaryBindingTrace.create(task.trace, "trace for resolution guarded for extra function literal arguments"),
|
||||
task.scope, new DelegatingCall(task.call) {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JetExpression> getFunctionLiteralArguments() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}, task.expectedType, task.dataFlowInfo, task.resolveMode, task.checkArguments,
|
||||
task.expressionPosition, task.resolutionResultsCache);
|
||||
OverloadResolutionResultsImpl<F> resultsWithFunctionLiteralsStripped = performResolution(newTask, callTransformer, traceForResolutionCache);
|
||||
DelegatingCall callWithoutFLArgs = new DelegatingCall(task.call) {
|
||||
@NotNull
|
||||
@Override
|
||||
public List<JetExpression> getFunctionLiteralArguments() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
};
|
||||
TemporaryBindingTrace temporaryTrace =
|
||||
TemporaryBindingTrace.create(task.trace, "trace for resolution guarded for extra function literal arguments");
|
||||
ResolutionTask<D, F> newTask = task.replaceBindingTrace(temporaryTrace).replaceCall(callWithoutFLArgs);
|
||||
|
||||
OverloadResolutionResultsImpl<F> resultsWithFunctionLiteralsStripped = performResolution(newTask, callTransformer);
|
||||
if (resultsWithFunctionLiteralsStripped.isSuccess() || resultsWithFunctionLiteralsStripped.isAmbiguity()) {
|
||||
task.tracing.danglingFunctionLiteralArgumentSuspected(task.trace, task.call.getFunctionLiteralArguments());
|
||||
}
|
||||
@@ -504,8 +505,8 @@ public class CallResolver {
|
||||
@NotNull
|
||||
private <D extends CallableDescriptor, F extends D> OverloadResolutionResultsImpl<F> performResolution(
|
||||
@NotNull ResolutionTask<D, F> task,
|
||||
@NotNull CallTransformer<D, F> callTransformer,
|
||||
@NotNull BindingTrace traceForResolutionCache) {
|
||||
@NotNull CallTransformer<D, F> callTransformer
|
||||
) {
|
||||
|
||||
for (ResolutionCandidate<D> resolutionCandidate : task.getCandidates()) {
|
||||
TemporaryBindingTrace candidateTrace = TemporaryBindingTrace.create(
|
||||
|
||||
@@ -235,6 +235,21 @@ public class CandidateResolver {
|
||||
|
||||
constraintSystem.addSupertypeConstraint(context.expectedType, descriptor.getReturnType(), ConstraintPosition.EXPECTED_TYPE_POSITION);
|
||||
|
||||
ConstraintSystemCompleter constraintSystemCompleter = context.trace.get(
|
||||
BindingContext.CONSTRAINT_SYSTEM_COMPLETER, context.call.getCalleeExpression());
|
||||
if (constraintSystemCompleter != null) {
|
||||
ConstraintSystemImpl backup = (ConstraintSystemImpl) constraintSystem.copy();
|
||||
|
||||
//todo improve error reporting with errors in constraints from completer
|
||||
constraintSystemCompleter.completeConstraintSystem(constraintSystem, resolvedCall);
|
||||
if (constraintSystem.hasTypeConstructorMismatchAt(ConstraintPosition.FROM_COMPLETER) ||
|
||||
(constraintSystem.hasContradiction() && !backup.hasContradiction())) {
|
||||
|
||||
constraintSystem = backup;
|
||||
resolvedCall.setConstraintSystem(backup);
|
||||
}
|
||||
}
|
||||
|
||||
if (constraintSystem.hasContradiction()) {
|
||||
return reportInferenceError(context);
|
||||
}
|
||||
|
||||
+139
-34
@@ -18,17 +18,20 @@ package org.jetbrains.jet.lang.resolve.calls.autocasts;
|
||||
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.JetNodeTypes;
|
||||
import org.jetbrains.jet.lang.descriptors.*;
|
||||
import org.jetbrains.jet.lang.psi.*;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.JetModuleUtil;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
import org.jetbrains.jet.lang.resolve.scopes.receivers.*;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
import org.jetbrains.jet.lang.types.TypeUtils;
|
||||
import org.jetbrains.jet.lang.types.lang.KotlinBuiltIns;
|
||||
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.REFERENCE_TARGET;
|
||||
import static org.jetbrains.jet.lang.resolve.BindingContext.RESOLVED_CALL;
|
||||
|
||||
public class DataFlowValueFactory {
|
||||
public static final DataFlowValueFactory INSTANCE = new DataFlowValueFactory();
|
||||
@@ -42,8 +45,8 @@ public class DataFlowValueFactory {
|
||||
if (constantExpression.getNode().getElementType() == JetNodeTypes.NULL) return DataFlowValue.NULL;
|
||||
}
|
||||
if (TypeUtils.equalTypes(type, KotlinBuiltIns.getInstance().getNullableNothingType())) return DataFlowValue.NULL; // 'null' is the only inhabitant of 'Nothing?'
|
||||
Pair<Object, Boolean> result = getIdForStableIdentifier(expression, bindingContext, false);
|
||||
return new DataFlowValue(result.first == null ? expression : result.first, type, result.second, getImmanentNullability(type));
|
||||
IdentifierInfo result = getIdForStableIdentifier(expression, bindingContext);
|
||||
return new DataFlowValue(result.id == null ? expression : result.id, type, result.isStable, getImmanentNullability(type));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -104,55 +107,157 @@ public class DataFlowValueFactory {
|
||||
return type.isNullable() || TypeUtils.hasNullableSuperType(type) ? Nullability.UNKNOWN : Nullability.NOT_NULL;
|
||||
}
|
||||
|
||||
private static class IdentifierInfo {
|
||||
public final Object id;
|
||||
public final boolean isStable;
|
||||
public final boolean isNamespace;
|
||||
|
||||
private IdentifierInfo(Object id, boolean isStable, boolean isNamespace) {
|
||||
this.id = id;
|
||||
this.isStable = isStable;
|
||||
this.isNamespace = isNamespace;
|
||||
}
|
||||
}
|
||||
|
||||
private static final IdentifierInfo NO_IDENTIFIER_INFO = new IdentifierInfo(null, false, false);
|
||||
|
||||
@NotNull
|
||||
private static Pair<Object, Boolean> getIdForStableIdentifier(@NotNull JetExpression expression, @NotNull BindingContext bindingContext, boolean allowNamespaces) {
|
||||
private static IdentifierInfo createInfo(Object id, boolean isStable) {
|
||||
return new IdentifierInfo(id, isStable, false);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static IdentifierInfo createNamespaceInfo(Object id) {
|
||||
return new IdentifierInfo(id, true, true);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static IdentifierInfo combineInfo(@Nullable IdentifierInfo receiverInfo, @NotNull IdentifierInfo selectorInfo) {
|
||||
if (selectorInfo.id == null) {
|
||||
return NO_IDENTIFIER_INFO;
|
||||
}
|
||||
if (receiverInfo == null || receiverInfo == NO_IDENTIFIER_INFO || receiverInfo.isNamespace) {
|
||||
return selectorInfo;
|
||||
}
|
||||
return createInfo(Pair.create(receiverInfo.id, selectorInfo.id), receiverInfo.isStable && selectorInfo.isStable);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static IdentifierInfo getIdForStableIdentifier(
|
||||
@Nullable JetExpression expression,
|
||||
@NotNull BindingContext bindingContext
|
||||
) {
|
||||
if (expression instanceof JetParenthesizedExpression) {
|
||||
JetParenthesizedExpression parenthesizedExpression = (JetParenthesizedExpression) expression;
|
||||
JetExpression innerExpression = parenthesizedExpression.getExpression();
|
||||
if (innerExpression == null) {
|
||||
return Pair.create(null, false);
|
||||
}
|
||||
return getIdForStableIdentifier(innerExpression, bindingContext, allowNamespaces);
|
||||
|
||||
return getIdForStableIdentifier(innerExpression, bindingContext);
|
||||
}
|
||||
else if (expression instanceof JetQualifiedExpression) {
|
||||
JetQualifiedExpression qualifiedExpression = (JetQualifiedExpression) expression;
|
||||
JetExpression receiverExpression = qualifiedExpression.getReceiverExpression();
|
||||
JetExpression selectorExpression = qualifiedExpression.getSelectorExpression();
|
||||
if (selectorExpression == null) {
|
||||
return Pair.create(null, false);
|
||||
}
|
||||
Pair<Object, Boolean> receiverId = getIdForStableIdentifier(qualifiedExpression.getReceiverExpression(), bindingContext, true);
|
||||
Pair<Object, Boolean> selectorId = getIdForStableIdentifier(selectorExpression, bindingContext, allowNamespaces);
|
||||
return receiverId.second ? selectorId : Pair.create(receiverId.first, false);
|
||||
IdentifierInfo receiverId = getIdForStableIdentifier(receiverExpression, bindingContext);
|
||||
IdentifierInfo selectorId = getIdForStableIdentifier(selectorExpression, bindingContext);
|
||||
|
||||
return combineInfo(receiverId, selectorId);
|
||||
}
|
||||
if (expression instanceof JetSimpleNameExpression) {
|
||||
JetSimpleNameExpression simpleNameExpression = (JetSimpleNameExpression) expression;
|
||||
DeclarationDescriptor declarationDescriptor = bindingContext.get(REFERENCE_TARGET, simpleNameExpression);
|
||||
if (declarationDescriptor instanceof VariableDescriptor) {
|
||||
return Pair.create((Object) declarationDescriptor, isStableVariable((VariableDescriptor) declarationDescriptor));
|
||||
}
|
||||
if (declarationDescriptor instanceof NamespaceDescriptor) {
|
||||
return Pair.create((Object) declarationDescriptor, allowNamespaces);
|
||||
}
|
||||
if (declarationDescriptor instanceof ClassDescriptor) {
|
||||
ClassDescriptor classDescriptor = (ClassDescriptor) declarationDescriptor;
|
||||
return Pair.create((Object) classDescriptor, classDescriptor.isClassObjectAValue());
|
||||
}
|
||||
return getIdForSimpleNameExpression((JetSimpleNameExpression) expression, bindingContext);
|
||||
}
|
||||
else if (expression instanceof JetThisExpression) {
|
||||
JetThisExpression thisExpression = (JetThisExpression) expression;
|
||||
DeclarationDescriptor declarationDescriptor = bindingContext.get(REFERENCE_TARGET, thisExpression.getInstanceReference());
|
||||
if (declarationDescriptor instanceof CallableDescriptor) {
|
||||
return Pair.create((Object) ((CallableDescriptor) declarationDescriptor).getReceiverParameter().getValue(), true);
|
||||
}
|
||||
if (declarationDescriptor instanceof ClassDescriptor) {
|
||||
return Pair.create((Object) ((ClassDescriptor) declarationDescriptor).getThisAsReceiverParameter().getValue(), true);
|
||||
}
|
||||
return Pair.create(null, true);
|
||||
|
||||
return getIdForThisReceiver(declarationDescriptor);
|
||||
}
|
||||
else if (expression instanceof JetRootNamespaceExpression) {
|
||||
return Pair.create((Object) JetModuleUtil.getRootNamespaceType(expression), allowNamespaces);
|
||||
return createNamespaceInfo(JetModuleUtil.getRootNamespaceType(expression));
|
||||
}
|
||||
return Pair.create(null, false);
|
||||
return NO_IDENTIFIER_INFO;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static IdentifierInfo getIdForSimpleNameExpression(
|
||||
@NotNull JetSimpleNameExpression simpleNameExpression,
|
||||
@NotNull BindingContext bindingContext
|
||||
) {
|
||||
DeclarationDescriptor declarationDescriptor = bindingContext.get(REFERENCE_TARGET, simpleNameExpression);
|
||||
if (declarationDescriptor instanceof VariableDescriptor) {
|
||||
ResolvedCall<?> resolvedCall = bindingContext.get(RESOLVED_CALL, simpleNameExpression);
|
||||
// todo uncomment assert
|
||||
// for now it fails for resolving 'invoke' convention, return it after 'invoke' algorithm changes
|
||||
// assert resolvedCall != null : "Cannot create right identifier info if the resolved call is not known yet for " + declarationDescriptor;
|
||||
|
||||
IdentifierInfo receiverInfo = resolvedCall != null ? getIdForImplicitReceiver(resolvedCall.getThisObject(), simpleNameExpression) : null;
|
||||
|
||||
VariableDescriptor variableDescriptor = (VariableDescriptor) declarationDescriptor;
|
||||
return combineInfo(receiverInfo, createInfo(variableDescriptor, isStableVariable(variableDescriptor)));
|
||||
}
|
||||
if (declarationDescriptor instanceof NamespaceDescriptor) {
|
||||
return createNamespaceInfo(declarationDescriptor);
|
||||
}
|
||||
if (declarationDescriptor instanceof ClassDescriptor) {
|
||||
ClassDescriptor classDescriptor = (ClassDescriptor) declarationDescriptor;
|
||||
return createInfo(classDescriptor, classDescriptor.isClassObjectAValue());
|
||||
}
|
||||
return NO_IDENTIFIER_INFO;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static IdentifierInfo getIdForImplicitReceiver(@NotNull ReceiverValue receiverValue, @Nullable final JetExpression expression) {
|
||||
return receiverValue.accept(new ReceiverValueVisitor<IdentifierInfo, Void>() {
|
||||
|
||||
@Override
|
||||
public IdentifierInfo visitNoReceiver(ReceiverValue noReceiver, Void data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierInfo visitTransientReceiver(TransientReceiver receiver, Void data) {
|
||||
assert false: "Transient receiver is implicit for an explicit expression: " + expression + ". Receiver: " + receiver;
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierInfo visitExtensionReceiver(ExtensionReceiver receiver, Void data) {
|
||||
return getIdForThisReceiver(receiver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierInfo visitExpressionReceiver(ExpressionReceiver receiver, Void data) {
|
||||
// there is an explicit "this" expression and it was analyzed earlier
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierInfo visitClassReceiver(ClassReceiver receiver, Void data) {
|
||||
return getIdForThisReceiver(receiver);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IdentifierInfo visitScriptReceiver(ScriptReceiver receiver, Void data) {
|
||||
return getIdForThisReceiver(receiver);
|
||||
}
|
||||
}, null);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static IdentifierInfo getIdForThisReceiver(@NotNull ThisReceiver thisReceiver) {
|
||||
return getIdForThisReceiver(thisReceiver.getDeclarationDescriptor());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static IdentifierInfo getIdForThisReceiver(@Nullable DeclarationDescriptor descriptorOfThisReceiver) {
|
||||
if (descriptorOfThisReceiver instanceof CallableDescriptor) {
|
||||
ReceiverParameterDescriptor receiverParameter = ((CallableDescriptor) descriptorOfThisReceiver).getReceiverParameter();
|
||||
assert receiverParameter != null : "'This' refers to the callable member without a receiver parameter: " + descriptorOfThisReceiver;
|
||||
return createInfo(receiverParameter.getValue(), true);
|
||||
}
|
||||
if (descriptorOfThisReceiver instanceof ClassDescriptor) {
|
||||
return createInfo(((ClassDescriptor) descriptorOfThisReceiver).getThisAsReceiverParameter().getValue(), true);
|
||||
}
|
||||
return NO_IDENTIFIER_INFO;
|
||||
}
|
||||
|
||||
public static boolean isStableVariable(@NotNull VariableDescriptor variableDescriptor) {
|
||||
|
||||
+1
@@ -24,6 +24,7 @@ public class ConstraintPosition {
|
||||
public static final ConstraintPosition RECEIVER_POSITION = new ConstraintPosition("RECEIVER_POSITION");
|
||||
public static final ConstraintPosition EXPECTED_TYPE_POSITION = new ConstraintPosition("EXPECTED_TYPE_POSITION");
|
||||
public static final ConstraintPosition BOUND_CONSTRAINT_POSITION = new ConstraintPosition("BOUND_CONSTRAINT_POSITION");
|
||||
public static final ConstraintPosition FROM_COMPLETER = new ConstraintPosition("FROM_COMPLETER");
|
||||
|
||||
private static final Map<Integer, ConstraintPosition> valueParameterPositions = Maps.newHashMap();
|
||||
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.resolve.calls.inference;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.resolve.calls.model.ResolvedCall;
|
||||
|
||||
public interface ConstraintSystemCompleter {
|
||||
void completeConstraintSystem(
|
||||
@NotNull ConstraintSystem constraintSystem,
|
||||
@NotNull ResolvedCall<?> resolvedCall
|
||||
);
|
||||
}
|
||||
@@ -100,6 +100,12 @@ public class ResolutionTask<D extends CallableDescriptor, F extends D> extends C
|
||||
return this;
|
||||
}
|
||||
|
||||
public ResolutionTask<D, F> replaceCall(@NotNull Call newCall) {
|
||||
return new ResolutionTask<D, F>(
|
||||
candidates, reference, tracing, trace, scope, newCall, expectedType, dataFlowInfo, resolveMode, checkArguments,
|
||||
expressionPosition, resolutionResultsCache);
|
||||
}
|
||||
|
||||
public interface DescriptorCheckStrategy {
|
||||
<D extends CallableDescriptor> boolean performAdvancedChecks(D descriptor, BindingTrace trace, TracingStrategy tracing);
|
||||
}
|
||||
|
||||
+1
-1
@@ -181,11 +181,11 @@ public class TaskPrioritizer {
|
||||
TaskPrioritizer.<D>splitLexicallyLocalDescriptors(functions, scope.getContainingDeclaration(), locals, nonlocals);
|
||||
|
||||
result.addLocalExtensions(locals);
|
||||
result.addNonLocalExtensions(nonlocals);
|
||||
|
||||
for (ReceiverValue implicitReceiver : implicitReceivers) {
|
||||
doComputeTasks(scope, implicitReceiver, name, result, context, callableDescriptorCollector);
|
||||
}
|
||||
result.addNonLocalExtensions(nonlocals);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -178,7 +178,7 @@ public class TracingStrategyImpl implements TracingStrategy {
|
||||
JetExpression left = binaryExpression.getLeft();
|
||||
JetExpression right = binaryExpression.getRight();
|
||||
if (left != null && right != null) {
|
||||
trace.report(UNSAFE_INFIX_CALL.on(reference, left.getText(), operationString.getName(), right.getText()));
|
||||
trace.report(UNSAFE_INFIX_CALL.on(reference, left.getText(), operationString.asString(), right.getText()));
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -189,11 +189,15 @@ public class ResolveSessionUtils {
|
||||
PropertyDescriptor descriptor = (PropertyDescriptor) resolveSession.resolveToDescriptor(jetProperty);
|
||||
|
||||
JetExpression propertyInitializer = jetProperty.getInitializer();
|
||||
|
||||
if (propertyInitializer != null) {
|
||||
bodyResolver.resolvePropertyInitializer(jetProperty, descriptor, propertyInitializer, propertyResolutionScope);
|
||||
}
|
||||
|
||||
JetExpression propertyDelegate = jetProperty.getDelegateExpression();
|
||||
if (propertyDelegate != null) {
|
||||
bodyResolver.resolvePropertyDelegate(jetProperty, descriptor, propertyDelegate, propertyResolutionScope, propertyResolutionScope);
|
||||
}
|
||||
|
||||
bodyResolver.resolvePropertyAccessors(jetProperty, descriptor);
|
||||
}
|
||||
|
||||
|
||||
@@ -149,7 +149,11 @@ public class ScopeProvider {
|
||||
return classDescriptor.getScopeForPropertyInitializerResolution();
|
||||
}
|
||||
if (jetDeclaration instanceof JetEnumEntry) {
|
||||
return ((LazyClassDescriptor) classDescriptor.getClassObjectDescriptor()).getScopeForMemberDeclarationResolution();
|
||||
LazyClassDescriptor descriptor = (LazyClassDescriptor) classDescriptor.getClassObjectDescriptor();
|
||||
assert descriptor != null : "There should be class object descriptor for enum class " + parentDeclaration.getText() +
|
||||
" on entry " + jetDeclaration.getText();
|
||||
|
||||
return descriptor.getScopeForMemberDeclarationResolution();
|
||||
}
|
||||
return classDescriptor.getScopeForMemberDeclarationResolution();
|
||||
}
|
||||
@@ -161,8 +165,7 @@ public class ScopeProvider {
|
||||
LazyClassDescriptor classObjectDescriptor =
|
||||
(LazyClassDescriptor) resolveSession.getClassObjectDescriptor(classObject).getContainingDeclaration();
|
||||
|
||||
// During class object header resolve there should be no resolution for parent class generic params
|
||||
return new InnerClassesScopeWrapper(classObjectDescriptor.getScopeForMemberDeclarationResolution());
|
||||
return classObjectDescriptor.getScopeForMemberDeclarationResolution();
|
||||
}
|
||||
|
||||
throw new IllegalStateException("Don't call this method for local declarations: " + jetDeclaration + " " + jetDeclaration.getText());
|
||||
|
||||
+18
-18
@@ -89,7 +89,6 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
||||
private final NotNullLazyValue<JetScope> scopeForMemberDeclarationResolution;
|
||||
private final NotNullLazyValue<JetScope> scopeForPropertyInitializerResolution;
|
||||
|
||||
|
||||
public LazyClassDescriptor(
|
||||
@NotNull ResolveSession resolveSession,
|
||||
@NotNull DeclarationDescriptor containingDeclaration,
|
||||
@@ -108,6 +107,7 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
||||
classLikeInfo.getClassKind() != ClassKind.ENUM_CLASS ? classLikeInfo : noEnumEntries(classLikeInfo);
|
||||
this.declarationProvider = resolveSession.getDeclarationProviderFactory().getClassMemberDeclarationProvider(classLikeInfoForMembers);
|
||||
this.containingDeclaration = containingDeclaration;
|
||||
|
||||
this.unsubstitutedMemberScope = new LazyClassMemberScope(resolveSession, declarationProvider, this);
|
||||
this.unsubstitutedInnerClassesScope = new InnerClassesScopeWrapper(unsubstitutedMemberScope);
|
||||
|
||||
@@ -182,18 +182,17 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
||||
|
||||
@NotNull
|
||||
private JetScope computeScopeForClassHeaderResolution() {
|
||||
WritableScopeImpl scope = new WritableScopeImpl(
|
||||
JetScope.EMPTY, this, RedeclarationHandler.DO_NOTHING, "Class Header Resolution");
|
||||
WritableScopeImpl scope = new WritableScopeImpl(JetScope.EMPTY, this, RedeclarationHandler.DO_NOTHING, "Scope with type parameters for " + name);
|
||||
for (TypeParameterDescriptor typeParameterDescriptor : getTypeConstructor().getParameters()) {
|
||||
scope.addClassifierDescriptor(typeParameterDescriptor);
|
||||
}
|
||||
scope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
|
||||
PsiElement scopeAnchor = declarationProvider.getOwnerInfo().getScopeAnchor();
|
||||
return new ChainedScope(
|
||||
this,
|
||||
"ScopeForClassHeaderResolution: " + getName(),
|
||||
scope, getScopeProvider().getResolutionScopeForDeclaration(scopeAnchor));
|
||||
|
||||
return new ChainedScope(this, "ScopeForClassHeaderResolution: " + getName(),
|
||||
scope,
|
||||
getScopeProvider().getResolutionScopeForDeclaration(scopeAnchor));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -203,15 +202,20 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
||||
|
||||
@NotNull
|
||||
private JetScope computeScopeForMemberDeclarationResolution() {
|
||||
WritableScopeImpl scope = new WritableScopeImpl(
|
||||
JetScope.EMPTY, this, RedeclarationHandler.DO_NOTHING, "Member Declaration Resolution");
|
||||
scope.addLabeledDeclaration(this);
|
||||
scope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
WritableScopeImpl thisScope = new WritableScopeImpl(JetScope.EMPTY, this, RedeclarationHandler.DO_NOTHING, "Scope with 'this' for " + name);
|
||||
thisScope.addLabeledDeclaration(this);
|
||||
thisScope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
|
||||
ClassDescriptor classObject = getClassObjectDescriptor();
|
||||
JetScope classObjectAdapterScope = (classObject != null) ? new ClassObjectMixinScope(classObject) : JetScope.EMPTY;
|
||||
|
||||
return new ChainedScope(
|
||||
this,
|
||||
"ScopeForMemberDeclarationResolution: " + getName(),
|
||||
scope, getScopeForMemberLookup(), getScopeForClassHeaderResolution());
|
||||
thisScope,
|
||||
getScopeForMemberLookup(),
|
||||
getScopeForClassHeaderResolution(),
|
||||
classObjectAdapterScope);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -224,14 +228,10 @@ public class LazyClassDescriptor extends ClassDescriptorBase implements LazyDesc
|
||||
ConstructorDescriptor primaryConstructor = getUnsubstitutedPrimaryConstructor();
|
||||
if (primaryConstructor == null) return getScopeForMemberDeclarationResolution();
|
||||
|
||||
WritableScopeImpl scope = new WritableScopeImpl(
|
||||
JetScope.EMPTY, this, RedeclarationHandler.DO_NOTHING, "Property Initializer Resolution");
|
||||
|
||||
List<ValueParameterDescriptor> parameters = primaryConstructor.getValueParameters();
|
||||
for (ValueParameterDescriptor valueParameterDescriptor : parameters) {
|
||||
WritableScopeImpl scope = new WritableScopeImpl(JetScope.EMPTY, this, RedeclarationHandler.DO_NOTHING, "Scope with constructor parameters in " + name);
|
||||
for (ValueParameterDescriptor valueParameterDescriptor : primaryConstructor.getValueParameters()) {
|
||||
scope.addVariableDescriptor(valueParameterDescriptor);
|
||||
}
|
||||
|
||||
scope.changeLockLevel(WritableScope.LockLevel.READING);
|
||||
|
||||
return new ChainedScope(
|
||||
|
||||
+1
-1
@@ -124,7 +124,7 @@ public class LazyClassMemberScope extends AbstractLazyMemberScope<LazyClassDescr
|
||||
fromCurrent);
|
||||
assert declaration != null : "fromCurrent can not be a fake override";
|
||||
trace.report(Errors.CONFLICTING_OVERLOADS
|
||||
.on(declaration, fromCurrent, fromCurrent.getContainingDeclaration().getName().getName()));
|
||||
.on(declaration, fromCurrent, fromCurrent.getContainingDeclaration().getName().asString()));
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
@@ -59,7 +59,7 @@ public class FqName extends FqNameBase {
|
||||
|
||||
|
||||
private void validateFqName() {
|
||||
if (!isValidAfterUnsafeCheck(fqName.getFqName())) {
|
||||
if (!isValidAfterUnsafeCheck(fqName.asString())) {
|
||||
throw new IllegalArgumentException("incorrect fq name: " + fqName);
|
||||
}
|
||||
}
|
||||
@@ -71,8 +71,8 @@ public class FqName extends FqNameBase {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public String getFqName() {
|
||||
return fqName.getFqName();
|
||||
public String asString() {
|
||||
return fqName.asString();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -27,7 +27,7 @@ public abstract class FqNameBase {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
protected abstract String getFqName();
|
||||
protected abstract String asString();
|
||||
|
||||
@NotNull
|
||||
private FqNameUnsafe toFqNameUnsafe() {
|
||||
@@ -51,6 +51,6 @@ public abstract class FqNameBase {
|
||||
}
|
||||
|
||||
public final boolean equalsTo(@NotNull String that) {
|
||||
return getFqName().equals(that);
|
||||
return asString().equals(that);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +85,7 @@ public class FqNameUnsafe extends FqNameBase {
|
||||
|
||||
|
||||
@NotNull
|
||||
public String getFqName() {
|
||||
public String asString() {
|
||||
return fqName;
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public class FqNameUnsafe extends FqNameBase {
|
||||
if (safe != null) {
|
||||
return true;
|
||||
}
|
||||
return FqName.isValidAfterUnsafeCheck(getFqName());
|
||||
return FqName.isValidAfterUnsafeCheck(asString());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -128,10 +128,10 @@ public class FqNameUnsafe extends FqNameBase {
|
||||
public FqNameUnsafe child(@NotNull Name name) {
|
||||
String childFqName;
|
||||
if (isRoot()) {
|
||||
childFqName = name.getName();
|
||||
childFqName = name.asString();
|
||||
}
|
||||
else {
|
||||
childFqName = fqName + "." + name.getName();
|
||||
childFqName = fqName + "." + name.asString();
|
||||
}
|
||||
return new FqNameUnsafe(childFqName, this, name);
|
||||
}
|
||||
@@ -210,7 +210,7 @@ public class FqNameUnsafe extends FqNameBase {
|
||||
}
|
||||
|
||||
Name firstSegment = Name.guess(fqName.substring(0, pos));
|
||||
FqNameUnsafe last = new FqNameUnsafe(firstSegment.getName(), FqName.ROOT.toUnsafe(), firstSegment);
|
||||
FqNameUnsafe last = new FqNameUnsafe(firstSegment.asString(), FqName.ROOT.toUnsafe(), firstSegment);
|
||||
callback.segment(firstSegment, last);
|
||||
|
||||
while (true) {
|
||||
@@ -254,13 +254,13 @@ public class FqNameUnsafe extends FqNameBase {
|
||||
|
||||
@NotNull
|
||||
public static FqNameUnsafe topLevel(@NotNull Name shortName) {
|
||||
return new FqNameUnsafe(shortName.getName(), FqName.ROOT.toUnsafe(), shortName);
|
||||
return new FqNameUnsafe(shortName.asString(), FqName.ROOT.toUnsafe(), shortName);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return isRoot() ? ROOT_NAME.getName() : fqName;
|
||||
return isRoot() ? ROOT_NAME.asString() : fqName;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -29,7 +29,7 @@ public final class Name implements Comparable<Name> {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getName() {
|
||||
public String asString() {
|
||||
return name;
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ public final class Name implements Comparable<Name> {
|
||||
if (special) {
|
||||
throw new IllegalStateException("not identifier: " + this);
|
||||
}
|
||||
return getName();
|
||||
return asString();
|
||||
}
|
||||
|
||||
public boolean isSpecial() {
|
||||
|
||||
+48
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2010-2013 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.resolve.scopes;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor;
|
||||
import org.jetbrains.jet.lang.descriptors.ReceiverParameterDescriptor;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Members of the class object are accessible from the class.
|
||||
* Scope lazily delegates requests to class object scope.
|
||||
*/
|
||||
public class ClassObjectMixinScope extends AbstractScopeAdapter {
|
||||
private final ClassDescriptor classObjectDescriptor;
|
||||
|
||||
public ClassObjectMixinScope(ClassDescriptor classObjectDescriptor) {
|
||||
this.classObjectDescriptor = classObjectDescriptor;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected JetScope getWorkerScope() {
|
||||
return classObjectDescriptor.getDefaultType().getMemberScope();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<ReceiverParameterDescriptor> getImplicitReceiversHierarchy() {
|
||||
return Collections.singletonList(classObjectDescriptor.getThisAsReceiverParameter());
|
||||
}
|
||||
}
|
||||
@@ -33,6 +33,8 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
private final Multimap<Name, DeclarationDescriptor> declaredDescriptorsAccessibleBySimpleName = HashMultimap.create();
|
||||
private boolean allDescriptorsDone = false;
|
||||
|
||||
private Set<ClassDescriptor> allObjectDescriptors = null;
|
||||
|
||||
@NotNull
|
||||
private final DeclarationDescriptor ownerDeclarationDescriptor;
|
||||
|
||||
@@ -176,7 +178,7 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
checkMayWrite();
|
||||
|
||||
Map<LabelName, List<DeclarationDescriptor>> labelsToDescriptors = getLabelsToDescriptors();
|
||||
LabelName name = new LabelName(descriptor.getName().getName());
|
||||
LabelName name = new LabelName(descriptor.getName().asString());
|
||||
List<DeclarationDescriptor> declarationDescriptors = labelsToDescriptors.get(name);
|
||||
if (declarationDescriptors == null) {
|
||||
declarationDescriptors = new ArrayList<DeclarationDescriptor>();
|
||||
@@ -401,13 +403,26 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
|
||||
@Override
|
||||
public ClassDescriptor getObjectDescriptor(@NotNull Name name) {
|
||||
return getObjectDescriptorsMap().get(name);
|
||||
ClassDescriptor descriptor = getObjectDescriptorsMap().get(name);
|
||||
if (descriptor != null) return descriptor;
|
||||
|
||||
ClassDescriptor fromWorker = getWorkerScope().getObjectDescriptor(name);
|
||||
if (fromWorker != null) return fromWorker;
|
||||
|
||||
return super.getObjectDescriptor(name);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Set<ClassDescriptor> getObjectDescriptors() {
|
||||
return Sets.newHashSet(getObjectDescriptorsMap().values());
|
||||
if (allObjectDescriptors == null) {
|
||||
allObjectDescriptors = Sets.newHashSet(getObjectDescriptorsMap().values());
|
||||
allObjectDescriptors.addAll(getWorkerScope().getObjectDescriptors());
|
||||
for (JetScope imported : getImports()) {
|
||||
allObjectDescriptors.addAll(imported.getObjectDescriptors());
|
||||
}
|
||||
}
|
||||
return allObjectDescriptors;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -481,7 +496,7 @@ public class WritableScopeImpl extends WritableScopeWithImports {
|
||||
public PropertyDescriptor getPropertyByFieldReference(@NotNull Name fieldName) {
|
||||
checkMayRead();
|
||||
|
||||
if (!fieldName.getName().startsWith("$")) {
|
||||
if (!fieldName.asString().startsWith("$")) {
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
|
||||
+7
-19
@@ -16,28 +16,16 @@
|
||||
|
||||
package org.jetbrains.jet.lang.resolve.scopes.receivers;
|
||||
|
||||
public class ReceiverValueVisitor<R, D> {
|
||||
public R visitNoReceiver(ReceiverValue noReceiver, D data) {
|
||||
return null;
|
||||
}
|
||||
public interface ReceiverValueVisitor<R, D> {
|
||||
R visitNoReceiver(ReceiverValue noReceiver, D data);
|
||||
|
||||
public R visitTransientReceiver(TransientReceiver receiver, D data) {
|
||||
return null;
|
||||
}
|
||||
R visitTransientReceiver(TransientReceiver receiver, D data);
|
||||
|
||||
public R visitExtensionReceiver(ExtensionReceiver receiver, D data) {
|
||||
return null;
|
||||
}
|
||||
R visitExtensionReceiver(ExtensionReceiver receiver, D data);
|
||||
|
||||
public R visitExpressionReceiver(ExpressionReceiver receiver, D data) {
|
||||
return null;
|
||||
}
|
||||
R visitExpressionReceiver(ExpressionReceiver receiver, D data);
|
||||
|
||||
public R visitClassReceiver(ClassReceiver receiver, D data) {
|
||||
return null;
|
||||
}
|
||||
R visitClassReceiver(ClassReceiver receiver, D data);
|
||||
|
||||
public R visitScriptReceiver(ScriptReceiver receiver, D data) {
|
||||
return null;
|
||||
}
|
||||
R visitScriptReceiver(ScriptReceiver receiver, D data);
|
||||
}
|
||||
|
||||
@@ -96,7 +96,13 @@ public class DeferredType implements JetType {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
return getActualType().equals(obj);
|
||||
if (this == obj) return true;
|
||||
JetType actualType = getActualType();
|
||||
if (actualType == obj) return true;
|
||||
|
||||
if (!(obj instanceof JetType)) return false;
|
||||
|
||||
return TypeUtils.equalTypes(actualType, (JetType) obj);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -102,11 +102,11 @@ public final class JetTypeImpl extends AnnotatedImpl implements JetType {
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
if (!(o instanceof JetType)) return false;
|
||||
|
||||
JetTypeImpl type = (JetTypeImpl) o;
|
||||
JetType type = (JetType) o;
|
||||
|
||||
return nullable == type.nullable && JetTypeChecker.INSTANCE.equalTypes(this, type);
|
||||
return nullable == type.isNullable() && JetTypeChecker.INSTANCE.equalTypes(this, type);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-2
@@ -792,13 +792,13 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor {
|
||||
if (operationType == JetTokens.PLUSPLUS || operationType == JetTokens.MINUSMINUS) {
|
||||
assert returnType != null : "returnType is null for " + resolutionResults.getResultingDescriptor();
|
||||
if (JetTypeChecker.INSTANCE.isSubtypeOf(returnType, KotlinBuiltIns.getInstance().getUnitType())) {
|
||||
result = ErrorUtils.createErrorType(KotlinBuiltIns.getInstance().getUnit().getName().getName());
|
||||
result = ErrorUtils.createErrorType(KotlinBuiltIns.getInstance().getUnit().getName().asString());
|
||||
context.trace.report(INC_DEC_SHOULD_NOT_RETURN_UNIT.on(operationSign));
|
||||
}
|
||||
else {
|
||||
JetType receiverType = receiver.getType();
|
||||
if (!JetTypeChecker.INSTANCE.isSubtypeOf(returnType, receiverType)) {
|
||||
context.trace.report(RESULT_TYPE_MISMATCH.on(operationSign, name.getName(), receiverType, returnType));
|
||||
context.trace.report(RESULT_TYPE_MISMATCH.on(operationSign, name.asString(), receiverType, returnType));
|
||||
}
|
||||
else {
|
||||
context.trace.record(BindingContext.VARIABLE_REASSIGNMENT, expression);
|
||||
|
||||
+1
-1
@@ -340,7 +340,7 @@ public class ControlStructureTypingVisitor extends ExpressionTypingVisitor {
|
||||
VariableDescriptor olderVariable = context.scope.getLocalVariable(variableDescriptor.getName());
|
||||
if (olderVariable != null && DescriptorUtils.isLocal(context.scope.getContainingDeclaration(), olderVariable)) {
|
||||
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(context.trace.getBindingContext(), variableDescriptor);
|
||||
context.trace.report(Errors.NAME_SHADOWING.on(declaration, variableDescriptor.getName().getName()));
|
||||
context.trace.report(Errors.NAME_SHADOWING.on(declaration, variableDescriptor.getName().asString()));
|
||||
}
|
||||
}
|
||||
return variableDescriptor;
|
||||
|
||||
+49
-33
@@ -88,11 +88,9 @@ public class DelegatedPropertyUtils {
|
||||
scope, true);
|
||||
JetType returnType = getDelegateGetMethodReturnType(trace.getBindingContext(), propertyDescriptor);
|
||||
JetType propertyType = propertyDescriptor.getType();
|
||||
if (propertyType instanceof DeferredType) {
|
||||
assert ((DeferredType) propertyType).isComputed() : "Property type should be computed when resolving delegate convention method";
|
||||
}
|
||||
|
||||
if (returnType != null && !JetTypeChecker.INSTANCE.isSubtypeOf(returnType, propertyType)) {
|
||||
/* Do not check return type of get() method of delegate for properties with DeferredType because property type is taken from it */
|
||||
if (!(propertyType instanceof DeferredType) && returnType != null && !JetTypeChecker.INSTANCE.isSubtypeOf(returnType, propertyType)) {
|
||||
Call call = trace.getBindingContext().get(DELEGATED_PROPERTY_CALL, propertyDescriptor.getGetter());
|
||||
assert call != null : "Call should exists for " + propertyDescriptor.getGetter();
|
||||
trace.report(DELEGATE_SPECIAL_FUNCTION_RETURN_TYPE_MISMATCH
|
||||
@@ -125,8 +123,48 @@ public class DelegatedPropertyUtils {
|
||||
PropertyAccessorDescriptor accessor = isGet ? propertyDescriptor.getGetter() : propertyDescriptor.getSetter();
|
||||
assert accessor != null : "Delegated property should have getter/setter " + propertyDescriptor + " " + delegateExpression.getText();
|
||||
|
||||
if (trace.getBindingContext().get(DELEGATED_PROPERTY_CALL, accessor) != null) return;
|
||||
|
||||
OverloadResolutionResults<FunctionDescriptor> functionResults = getDelegatedPropertyConventionMethod(
|
||||
propertyDescriptor, delegateExpression, delegateType, expressionTypingServices, trace, scope, isGet);
|
||||
Call call = trace.getBindingContext().get(DELEGATED_PROPERTY_CALL, accessor);
|
||||
if (call != null) return;
|
||||
assert call != null : "'getDelegatedPropertyConventionMethod' didn't record a call";
|
||||
|
||||
if (!functionResults.isSuccess()) {
|
||||
String expectedFunction = renderCall(call, trace.getBindingContext());
|
||||
if (functionResults.isIncomplete()) {
|
||||
trace.report(DELEGATE_SPECIAL_FUNCTION_MISSING.on(delegateExpression, expectedFunction, delegateType));
|
||||
}
|
||||
else if (functionResults.isSingleResult() ||
|
||||
functionResults.getResultCode() == OverloadResolutionResults.Code.MANY_FAILED_CANDIDATES) {
|
||||
trace.report(DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE
|
||||
.on(delegateExpression, expectedFunction, functionResults.getResultingCalls()));
|
||||
}
|
||||
else if (functionResults.isAmbiguity()) {
|
||||
trace.report(DELEGATE_SPECIAL_FUNCTION_AMBIGUITY
|
||||
.on(delegateExpression, expectedFunction, functionResults.getResultingCalls()));
|
||||
}
|
||||
else {
|
||||
trace.report(DELEGATE_SPECIAL_FUNCTION_MISSING.on(delegateExpression, expectedFunction, delegateType));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
trace.record(DELEGATED_PROPERTY_RESOLVED_CALL, accessor, functionResults.getResultingCall());
|
||||
}
|
||||
|
||||
/* Resolve get() or set() methods from delegate */
|
||||
public static OverloadResolutionResults<FunctionDescriptor> getDelegatedPropertyConventionMethod(
|
||||
@NotNull PropertyDescriptor propertyDescriptor,
|
||||
@NotNull JetExpression delegateExpression,
|
||||
@NotNull JetType delegateType,
|
||||
@NotNull ExpressionTypingServices expressionTypingServices,
|
||||
@NotNull BindingTrace trace,
|
||||
@NotNull JetScope scope,
|
||||
boolean isGet
|
||||
) {
|
||||
PropertyAccessorDescriptor accessor = isGet ? propertyDescriptor.getGetter() : propertyDescriptor.getSetter();
|
||||
assert accessor != null : "Delegated property should have getter/setter " + propertyDescriptor + " " + delegateExpression.getText();
|
||||
|
||||
ExpressionTypingContext context = ExpressionTypingContext.newContext(
|
||||
expressionTypingServices, trace, scope,
|
||||
@@ -138,7 +176,7 @@ public class DelegatedPropertyUtils {
|
||||
List<JetExpression> arguments = Lists.newArrayList();
|
||||
arguments.add(createExpression(project, hasThis ? "this" : "null"));
|
||||
|
||||
arguments.add(createExpression(project, KotlinBuiltIns.getInstance().getPropertyMetadataImpl().getName().getName() + "(\"" + propertyDescriptor.getName().getName() + "\")"));
|
||||
arguments.add(createExpression(project, KotlinBuiltIns.getInstance().getPropertyMetadataImpl().getName().asString() + "(\"" + propertyDescriptor.getName().asString() + "\")"));
|
||||
|
||||
if (!isGet) {
|
||||
JetReferenceExpression fakeArgument = (JetReferenceExpression) createFakeExpressionOfType(context.expressionTypingServices.getProject(), trace,
|
||||
@@ -146,39 +184,17 @@ public class DelegatedPropertyUtils {
|
||||
propertyDescriptor.getType());
|
||||
arguments.add(fakeArgument);
|
||||
List<ValueParameterDescriptor> valueParameters = accessor.getValueParameters();
|
||||
context.trace.record(REFERENCE_TARGET, fakeArgument, valueParameters.get(0));
|
||||
trace.record(REFERENCE_TARGET, fakeArgument, valueParameters.get(0));
|
||||
}
|
||||
|
||||
Name functionName = Name.identifier(isGet ? "get" : "set");
|
||||
JetReferenceExpression fakeCalleeExpression = createSimpleName(project, functionName.getName());
|
||||
JetReferenceExpression fakeCalleeExpression = createSimpleName(project, functionName.asString());
|
||||
|
||||
ExpressionReceiver receiver = new ExpressionReceiver(delegateExpression, delegateType);
|
||||
call = CallMaker.makeCallWithExpressions(fakeCalleeExpression, receiver, null, fakeCalleeExpression, arguments, Call.CallType.DEFAULT);
|
||||
context.trace.record(BindingContext.DELEGATED_PROPERTY_CALL, accessor, call);
|
||||
Call call = CallMaker.makeCallWithExpressions(fakeCalleeExpression, receiver, null, fakeCalleeExpression, arguments, Call.CallType.DEFAULT);
|
||||
trace.record(BindingContext.DELEGATED_PROPERTY_CALL, accessor, call);
|
||||
|
||||
OverloadResolutionResults<FunctionDescriptor> functionResults = context.resolveCallWithGivenName(call, fakeCalleeExpression, functionName);
|
||||
|
||||
if (!functionResults.isSuccess()) {
|
||||
String expectedFunction = renderCall(call, trace.getBindingContext());
|
||||
if (functionResults.isIncomplete()) {
|
||||
context.trace.report(DELEGATE_SPECIAL_FUNCTION_MISSING.on(delegateExpression, expectedFunction, delegateType));
|
||||
}
|
||||
else if (functionResults.isSingleResult() ||
|
||||
functionResults.getResultCode() == OverloadResolutionResults.Code.MANY_FAILED_CANDIDATES) {
|
||||
context.trace.report(DELEGATE_SPECIAL_FUNCTION_NONE_APPLICABLE
|
||||
.on(delegateExpression, expectedFunction, functionResults.getResultingCalls()));
|
||||
}
|
||||
else if (functionResults.isAmbiguity()) {
|
||||
context.trace.report(DELEGATE_SPECIAL_FUNCTION_AMBIGUITY
|
||||
.on(delegateExpression, expectedFunction, functionResults.getResultingCalls()));
|
||||
}
|
||||
else {
|
||||
context.trace.report(DELEGATE_SPECIAL_FUNCTION_MISSING.on(delegateExpression, expectedFunction, delegateType));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
context.trace.record(DELEGATED_PROPERTY_RESOLVED_CALL, accessor, functionResults.getResultingCall());
|
||||
return context.resolveCallWithGivenName(call, fakeCalleeExpression, functionName);
|
||||
}
|
||||
|
||||
private static String renderCall(@NotNull Call call, @NotNull BindingContext context) {
|
||||
|
||||
+2
-2
@@ -237,7 +237,7 @@ public class ExpressionTypingUtils {
|
||||
@NotNull JetScope scope,
|
||||
@NotNull ModuleDescriptor module
|
||||
) {
|
||||
JetImportDirective importDirective = JetPsiFactory.createImportDirective(project, callableFQN.getFqName());
|
||||
JetImportDirective importDirective = JetPsiFactory.createImportDirective(project, callableFQN.asString());
|
||||
|
||||
Collection<? extends DeclarationDescriptor> declarationDescriptors = new QualifiedExpressionResolver()
|
||||
.analyseImportReference(importDirective, scope, new BindingTraceContext(), module);
|
||||
@@ -436,7 +436,7 @@ public class ExpressionTypingUtils {
|
||||
if (oldDescriptor != null && DescriptorUtils.isLocal(variableDescriptor.getContainingDeclaration(), oldDescriptor)) {
|
||||
PsiElement declaration = BindingContextUtils.descriptorToDeclaration(context.trace.getBindingContext(), variableDescriptor);
|
||||
if (declaration != null) {
|
||||
context.trace.report(Errors.NAME_SHADOWING.on(declaration, variableDescriptor.getName().getName()));
|
||||
context.trace.report(Errors.NAME_SHADOWING.on(declaration, variableDescriptor.getName().asString()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -263,9 +263,9 @@ public class KotlinBuiltIns {
|
||||
}
|
||||
|
||||
private void makePrimitive(PrimitiveType primitiveType) {
|
||||
ClassDescriptor theClass = getBuiltInClassByName(primitiveType.getTypeName().getName());
|
||||
ClassDescriptor theClass = getBuiltInClassByName(primitiveType.getTypeName().asString());
|
||||
JetType type = new JetTypeImpl(theClass);
|
||||
ClassDescriptor arrayClass = getBuiltInClassByName(primitiveType.getArrayTypeName().getName());
|
||||
ClassDescriptor arrayClass = getBuiltInClassByName(primitiveType.getArrayTypeName().asString());
|
||||
JetType arrayType = new JetTypeImpl(arrayClass);
|
||||
|
||||
primitiveTypeToClass.put(primitiveType, theClass);
|
||||
@@ -335,7 +335,7 @@ public class KotlinBuiltIns {
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getPrimitiveClassDescriptor(@NotNull PrimitiveType type) {
|
||||
return getBuiltInClassByName(type.getTypeName().getName());
|
||||
return getBuiltInClassByName(type.getTypeName().asString());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -398,7 +398,7 @@ public class KotlinBuiltIns {
|
||||
|
||||
@NotNull
|
||||
public ClassDescriptor getPrimitiveArrayClassDescriptor(@NotNull PrimitiveType type) {
|
||||
return getBuiltInClassByName(type.getArrayTypeName().getName());
|
||||
return getBuiltInClassByName(type.getArrayTypeName().asString());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
|
||||
@@ -19,14 +19,17 @@ package org.jetbrains.jet.lexer;
|
||||
import com.intellij.psi.TokenType;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.psi.tree.TokenSet;
|
||||
import org.jetbrains.jet.kdoc.lexer.KDocTokens;
|
||||
|
||||
public interface JetTokens {
|
||||
JetToken EOF = new JetToken("EOF");
|
||||
|
||||
JetToken BLOCK_COMMENT = new JetToken("BLOCK_COMMENT");
|
||||
JetToken DOC_COMMENT = new JetToken("DOC_COMMENT");
|
||||
JetToken EOL_COMMENT = new JetToken("EOL_COMMENT");
|
||||
JetToken SHEBANG_COMMENT = new JetToken("SHEBANG_COMMENT");
|
||||
JetToken BLOCK_COMMENT = new JetToken("BLOCK_COMMENT");
|
||||
JetToken EOL_COMMENT = new JetToken("EOL_COMMENT");
|
||||
JetToken SHEBANG_COMMENT = new JetToken("SHEBANG_COMMENT");
|
||||
|
||||
//JetToken DOC_COMMENT = new JetToken("DOC_COMMENT");
|
||||
IElementType DOC_COMMENT = KDocTokens.KDOC;
|
||||
|
||||
IElementType WHITE_SPACE = TokenType.WHITE_SPACE;
|
||||
|
||||
@@ -111,7 +114,7 @@ public interface JetTokens {
|
||||
JetToken SAFE_ACCESS = new JetToken("SAFE_ACCESS");
|
||||
JetToken ELVIS = new JetToken("ELVIS");
|
||||
// JetToken MAP = new JetToken("MAP");
|
||||
// JetToken FILTER = new JetToken("FILTER");
|
||||
// JetToken FILTER = new JetToken("FILTER");
|
||||
JetToken QUEST = new JetToken("QUEST");
|
||||
JetToken COLONCOLON = new JetToken("COLONCOLON");
|
||||
JetToken COLON = new JetToken("COLON");
|
||||
@@ -128,7 +131,7 @@ public interface JetTokens {
|
||||
JetToken HASH = new JetToken("HASH");
|
||||
JetToken AT = new JetToken("AT");
|
||||
JetToken ATAT = new JetToken("ATAT");
|
||||
|
||||
|
||||
JetToken IDE_TEMPLATE_START = new JetToken("IDE_TEMPLATE_START");
|
||||
JetToken IDE_TEMPLATE_END = new JetToken("IDE_TEMPLATE_END");
|
||||
|
||||
@@ -162,37 +165,45 @@ public interface JetTokens {
|
||||
JetKeywordToken FINAL_KEYWORD = JetKeywordToken.softKeyword("final");
|
||||
|
||||
TokenSet KEYWORDS = TokenSet.create(PACKAGE_KEYWORD, AS_KEYWORD, TYPE_KEYWORD, CLASS_KEYWORD, TRAIT_KEYWORD,
|
||||
THIS_KEYWORD, SUPER_KEYWORD, VAL_KEYWORD, VAR_KEYWORD, FUN_KEYWORD, FOR_KEYWORD,
|
||||
NULL_KEYWORD,
|
||||
TRUE_KEYWORD, FALSE_KEYWORD, IS_KEYWORD,
|
||||
IN_KEYWORD, THROW_KEYWORD, RETURN_KEYWORD, BREAK_KEYWORD, CONTINUE_KEYWORD, OBJECT_KEYWORD, IF_KEYWORD,
|
||||
ELSE_KEYWORD, WHILE_KEYWORD, DO_KEYWORD, TRY_KEYWORD, WHEN_KEYWORD,
|
||||
NOT_IN, NOT_IS, CAPITALIZED_THIS_KEYWORD, AS_SAFE
|
||||
THIS_KEYWORD, SUPER_KEYWORD, VAL_KEYWORD, VAR_KEYWORD, FUN_KEYWORD, FOR_KEYWORD,
|
||||
NULL_KEYWORD,
|
||||
TRUE_KEYWORD, FALSE_KEYWORD, IS_KEYWORD,
|
||||
IN_KEYWORD, THROW_KEYWORD, RETURN_KEYWORD, BREAK_KEYWORD, CONTINUE_KEYWORD, OBJECT_KEYWORD, IF_KEYWORD,
|
||||
ELSE_KEYWORD, WHILE_KEYWORD, DO_KEYWORD, TRY_KEYWORD, WHEN_KEYWORD,
|
||||
NOT_IN, NOT_IS, CAPITALIZED_THIS_KEYWORD, AS_SAFE
|
||||
);
|
||||
|
||||
TokenSet SOFT_KEYWORDS = TokenSet.create(IMPORT_KEYWORD, WHERE_KEYWORD, BY_KEYWORD, GET_KEYWORD,
|
||||
SET_KEYWORD, ABSTRACT_KEYWORD, ENUM_KEYWORD, OPEN_KEYWORD, INNER_KEYWORD, ANNOTATION_KEYWORD,
|
||||
OVERRIDE_KEYWORD, PRIVATE_KEYWORD, PUBLIC_KEYWORD, INTERNAL_KEYWORD, PROTECTED_KEYWORD,
|
||||
CATCH_KEYWORD, FINALLY_KEYWORD, OUT_KEYWORD, FINAL_KEYWORD, VARARG_KEYWORD, INLINE_KEYWORD, REIFIED_KEYWORD
|
||||
SET_KEYWORD, ABSTRACT_KEYWORD, ENUM_KEYWORD, OPEN_KEYWORD, INNER_KEYWORD, ANNOTATION_KEYWORD,
|
||||
OVERRIDE_KEYWORD, PRIVATE_KEYWORD, PUBLIC_KEYWORD, INTERNAL_KEYWORD, PROTECTED_KEYWORD,
|
||||
CATCH_KEYWORD, FINALLY_KEYWORD, OUT_KEYWORD, FINAL_KEYWORD, VARARG_KEYWORD, INLINE_KEYWORD, REIFIED_KEYWORD
|
||||
);
|
||||
|
||||
TokenSet MODIFIER_KEYWORDS = TokenSet.create(ABSTRACT_KEYWORD, ENUM_KEYWORD,
|
||||
OPEN_KEYWORD, INNER_KEYWORD, ANNOTATION_KEYWORD, OVERRIDE_KEYWORD, PRIVATE_KEYWORD, PUBLIC_KEYWORD, INTERNAL_KEYWORD,
|
||||
PROTECTED_KEYWORD, OUT_KEYWORD, IN_KEYWORD, FINAL_KEYWORD, VARARG_KEYWORD, INLINE_KEYWORD, REIFIED_KEYWORD
|
||||
OPEN_KEYWORD, INNER_KEYWORD, ANNOTATION_KEYWORD, OVERRIDE_KEYWORD, PRIVATE_KEYWORD, PUBLIC_KEYWORD, INTERNAL_KEYWORD,
|
||||
PROTECTED_KEYWORD, OUT_KEYWORD, IN_KEYWORD, FINAL_KEYWORD, VARARG_KEYWORD, INLINE_KEYWORD, REIFIED_KEYWORD
|
||||
);
|
||||
TokenSet WHITE_SPACE_OR_COMMENT_BIT_SET = TokenSet.create(WHITE_SPACE, BLOCK_COMMENT, EOL_COMMENT, DOC_COMMENT, SHEBANG_COMMENT);
|
||||
TokenSet WHITESPACES = TokenSet.create(TokenType.WHITE_SPACE);
|
||||
|
||||
/**
|
||||
* Don't add KDocTokens to COMMENTS TokenSet, because it is used in JetParserDefinition.getCommentTokens(),
|
||||
* and therefor all COMMENTS tokens will be ignored by PsiBuilder.
|
||||
*
|
||||
* @see org.jetbrains.jet.lang.psi.JetPsiUtil.isInComment()
|
||||
*/
|
||||
TokenSet COMMENTS = TokenSet.create(EOL_COMMENT, BLOCK_COMMENT, DOC_COMMENT, SHEBANG_COMMENT);
|
||||
TokenSet WHITE_SPACE_OR_COMMENT_BIT_SET = TokenSet.orSet(COMMENTS, TokenSet.create(WHITE_SPACE));
|
||||
|
||||
TokenSet STRINGS = TokenSet.create(CHARACTER_LITERAL, REGULAR_STRING_PART);
|
||||
TokenSet OPERATIONS = TokenSet.create(AS_KEYWORD, AS_SAFE, IS_KEYWORD, IN_KEYWORD, DOT, PLUSPLUS, MINUSMINUS, EXCLEXCL, MUL, PLUS,
|
||||
MINUS, EXCL, DIV, PERC, LT, GT, LTEQ, GTEQ, EQEQEQ, EXCLEQEQEQ, EQEQ, EXCLEQ, ANDAND, OROR,
|
||||
SAFE_ACCESS, ELVIS,
|
||||
// MAP, FILTER,
|
||||
COLON,
|
||||
RANGE, EQ, MULTEQ, DIVEQ, PERCEQ, PLUSEQ, MINUSEQ,
|
||||
NOT_IN, NOT_IS,
|
||||
IDENTIFIER, LABEL_IDENTIFIER, ATAT, AT);
|
||||
MINUS, EXCL, DIV, PERC, LT, GT, LTEQ, GTEQ, EQEQEQ, EXCLEQEQEQ, EQEQ, EXCLEQ, ANDAND, OROR,
|
||||
SAFE_ACCESS, ELVIS,
|
||||
// MAP, FILTER,
|
||||
COLON,
|
||||
RANGE, EQ, MULTEQ, DIVEQ, PERCEQ, PLUSEQ, MINUSEQ,
|
||||
NOT_IN, NOT_IS,
|
||||
IDENTIFIER, LABEL_IDENTIFIER, ATAT, AT);
|
||||
|
||||
TokenSet AUGMENTED_ASSIGNMENTS = TokenSet.create(PLUSEQ, MINUSEQ, MULTEQ, PERCEQ, DIVEQ);
|
||||
TokenSet ALL_ASSIGNMENTS = TokenSet.create(EQ, PLUSEQ, MINUSEQ, MULTEQ, PERCEQ, DIVEQ);
|
||||
}
|
||||
|
||||
@@ -1,21 +1,18 @@
|
||||
/* The following code was generated by JFlex 1.4.3 on 3/12/13 8:22 PM */
|
||||
/* The following code was generated by JFlex 1.4.3 on 25.05.13 15:08 */
|
||||
|
||||
package org.jetbrains.jet.lexer;
|
||||
|
||||
import java.util.*;
|
||||
import com.intellij.lexer.*;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.lexer.FlexLexer;
|
||||
import com.intellij.psi.TokenType;
|
||||
import com.intellij.psi.tree.IElementType;
|
||||
import com.intellij.util.containers.Stack;
|
||||
|
||||
import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
|
||||
/**
|
||||
* This class is a scanner generated by
|
||||
* <a href="http://www.jflex.de/">JFlex</a> 1.4.3
|
||||
* on 3/12/13 8:22 PM from the specification file
|
||||
* <tt>C:/1/kotlin/compiler/frontend/src/org/jetbrains/jet/lexer/Jet.flex</tt>
|
||||
* on 25.05.13 15:08 from the specification file
|
||||
* <tt>/Users/factitious/Documents/kotlin/compiler/frontend/src/org/jetbrains/jet/lexer/Jet.flex</tt>
|
||||
*/
|
||||
class _JetLexer implements FlexLexer {
|
||||
/** initial size of the lookahead buffer */
|
||||
@@ -843,7 +840,7 @@ class _JetLexer implements FlexLexer {
|
||||
while (true) {
|
||||
|
||||
if (zzCurrentPosL < zzEndReadL)
|
||||
zzInput = zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++]:zzBufferL.charAt(zzCurrentPosL++);
|
||||
zzInput = (zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++] : zzBufferL.charAt(zzCurrentPosL++));
|
||||
else if (zzAtEOF) {
|
||||
zzInput = YYEOF;
|
||||
break zzForAction;
|
||||
@@ -863,7 +860,7 @@ class _JetLexer implements FlexLexer {
|
||||
break zzForAction;
|
||||
}
|
||||
else {
|
||||
zzInput = zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++]:zzBufferL.charAt(zzCurrentPosL++);
|
||||
zzInput = (zzBufferArrayL != null ? zzBufferArrayL[zzCurrentPosL++] : zzBufferL.charAt(zzCurrentPosL++));
|
||||
}
|
||||
}
|
||||
int zzNext = zzTransL[ zzRowMapL[zzState] + zzCMapL[zzInput] ];
|
||||
@@ -904,193 +901,202 @@ class _JetLexer implements FlexLexer {
|
||||
{ return JetTokens.NULL_KEYWORD ;
|
||||
}
|
||||
case 110: break;
|
||||
case 35:
|
||||
{ if (lBraceCount == 0) {
|
||||
popState();
|
||||
return JetTokens.LONG_TEMPLATE_ENTRY_END;
|
||||
}
|
||||
lBraceCount--;
|
||||
return JetTokens.RBRACE;
|
||||
}
|
||||
case 111: break;
|
||||
case 16:
|
||||
{ return JetTokens.LT ;
|
||||
}
|
||||
case 111: break;
|
||||
case 112: break;
|
||||
case 54:
|
||||
{ return JetTokens.DO_KEYWORD ;
|
||||
}
|
||||
case 112: break;
|
||||
case 113: break;
|
||||
case 20:
|
||||
{ return JetTokens.PLUS ;
|
||||
}
|
||||
case 113: break;
|
||||
case 114: break;
|
||||
case 59:
|
||||
{ return JetTokens.PLUSEQ ;
|
||||
}
|
||||
case 114: break;
|
||||
case 115: break;
|
||||
case 94:
|
||||
{ popState(); return JetTokens.THIS_KEYWORD;
|
||||
}
|
||||
case 115: break;
|
||||
case 116: break;
|
||||
case 28:
|
||||
{ return JetTokens.COMMA ;
|
||||
}
|
||||
case 116: break;
|
||||
case 117: break;
|
||||
case 17:
|
||||
{ return JetTokens.GT ;
|
||||
}
|
||||
case 117: break;
|
||||
case 118: break;
|
||||
case 4:
|
||||
{ return JetTokens.WHITE_SPACE;
|
||||
}
|
||||
case 118: break;
|
||||
case 119: break;
|
||||
case 26:
|
||||
{ return JetTokens.RPAR ;
|
||||
}
|
||||
case 119: break;
|
||||
case 120: break;
|
||||
case 57:
|
||||
{ return JetTokens.DOUBLE_ARROW;
|
||||
}
|
||||
case 120: break;
|
||||
case 121: break;
|
||||
case 88:
|
||||
{ return JetTokens.TRUE_KEYWORD ;
|
||||
}
|
||||
case 121: break;
|
||||
case 122: break;
|
||||
case 82:
|
||||
{ return JetTokens.IDE_TEMPLATE_START ;
|
||||
}
|
||||
case 122: break;
|
||||
case 123: break;
|
||||
case 37:
|
||||
{ return JetTokens.FIELD_IDENTIFIER;
|
||||
}
|
||||
case 123: break;
|
||||
case 124: break;
|
||||
case 61:
|
||||
{ return JetTokens.ANDAND ;
|
||||
}
|
||||
case 124: break;
|
||||
case 125: break;
|
||||
case 66:
|
||||
{ pushState(LONG_TEMPLATE_ENTRY); return JetTokens.LONG_TEMPLATE_ENTRY_START;
|
||||
}
|
||||
case 125: break;
|
||||
case 126: break;
|
||||
case 36:
|
||||
{ return JetTokens.FLOAT_LITERAL;
|
||||
}
|
||||
case 126: break;
|
||||
case 127: break;
|
||||
case 40:
|
||||
{ return JetTokens.EOL_COMMENT;
|
||||
}
|
||||
case 127: break;
|
||||
case 128: break;
|
||||
case 92:
|
||||
{ return JetTokens.WHEN_KEYWORD ;
|
||||
}
|
||||
case 128: break;
|
||||
case 129: break;
|
||||
case 75:
|
||||
{ pushState(RAW_STRING); return JetTokens.OPEN_QUOTE;
|
||||
}
|
||||
case 129: break;
|
||||
case 130: break;
|
||||
case 22:
|
||||
{ return JetTokens.COLON ;
|
||||
}
|
||||
case 130: break;
|
||||
case 131: break;
|
||||
case 55:
|
||||
{ return JetTokens.LTEQ ;
|
||||
}
|
||||
case 131: break;
|
||||
case 132: break;
|
||||
case 47:
|
||||
{ return JetTokens.ARROW ;
|
||||
}
|
||||
case 132: break;
|
||||
case 133: break;
|
||||
case 32:
|
||||
{ popState(); return JetTokens.IDENTIFIER;
|
||||
}
|
||||
case 133: break;
|
||||
case 134: break;
|
||||
case 23:
|
||||
{ return JetTokens.LBRACKET ;
|
||||
}
|
||||
case 134: break;
|
||||
case 135: break;
|
||||
case 70:
|
||||
{ yypushback(2); return JetTokens.INTEGER_LITERAL;
|
||||
}
|
||||
case 135: break;
|
||||
case 136: break;
|
||||
case 11:
|
||||
{ return JetTokens.CHARACTER_LITERAL;
|
||||
}
|
||||
case 136: break;
|
||||
case 137: break;
|
||||
case 80:
|
||||
{ return JetTokens.VAR_KEYWORD ;
|
||||
}
|
||||
case 137: break;
|
||||
case 138: break;
|
||||
case 56:
|
||||
{ return JetTokens.GTEQ ;
|
||||
}
|
||||
case 138: break;
|
||||
case 139: break;
|
||||
case 2:
|
||||
{ return JetTokens.INTEGER_LITERAL;
|
||||
}
|
||||
case 139: break;
|
||||
case 140: break;
|
||||
case 14:
|
||||
{ return JetTokens.RBRACE ;
|
||||
}
|
||||
case 140: break;
|
||||
case 141: break;
|
||||
case 98:
|
||||
{ return JetTokens.CLASS_KEYWORD ;
|
||||
}
|
||||
case 141: break;
|
||||
case 142: break;
|
||||
case 76:
|
||||
{ return JetTokens.TRY_KEYWORD ;
|
||||
}
|
||||
case 142: break;
|
||||
case 143: break;
|
||||
case 8:
|
||||
{ return JetTokens.EXCL ;
|
||||
}
|
||||
case 143: break;
|
||||
case 144: break;
|
||||
case 44:
|
||||
{ return JetTokens.EXCLEQ ;
|
||||
}
|
||||
case 144: break;
|
||||
case 145: break;
|
||||
case 48:
|
||||
{ return JetTokens.MINUSEQ ;
|
||||
}
|
||||
case 145: break;
|
||||
case 146: break;
|
||||
case 104:
|
||||
{ return JetTokens.PACKAGE_KEYWORD ;
|
||||
}
|
||||
case 146: break;
|
||||
case 147: break;
|
||||
case 95:
|
||||
{ return JetTokens.THROW_KEYWORD ;
|
||||
}
|
||||
case 147: break;
|
||||
case 148: break;
|
||||
case 97:
|
||||
{ return JetTokens.SUPER_KEYWORD ;
|
||||
}
|
||||
case 148: break;
|
||||
case 149: break;
|
||||
case 69:
|
||||
{ if (commentDepth > 0) {
|
||||
commentDepth--;
|
||||
}
|
||||
else {
|
||||
int state = yystate();
|
||||
popState();
|
||||
zzStartRead = commentStart;
|
||||
return commentStateToTokenType(state);
|
||||
}
|
||||
}
|
||||
case 150: break;
|
||||
case 100:
|
||||
{ return JetTokens.WHILE_KEYWORD ;
|
||||
}
|
||||
case 149: break;
|
||||
case 151: break;
|
||||
case 46:
|
||||
{ return JetTokens.MINUSMINUS;
|
||||
}
|
||||
case 150: break;
|
||||
case 152: break;
|
||||
case 105:
|
||||
{ return JetTokens.CONTINUE_KEYWORD ;
|
||||
}
|
||||
case 151: break;
|
||||
case 153: break;
|
||||
case 73:
|
||||
{ return JetTokens.NOT_IN;
|
||||
}
|
||||
case 152: break;
|
||||
case 154: break;
|
||||
case 39:
|
||||
{ return JetTokens.ATAT ;
|
||||
}
|
||||
case 153: break;
|
||||
case 71:
|
||||
{ pushState(DOC_COMMENT);
|
||||
commentDepth = 0;
|
||||
commentStart = getTokenStart();
|
||||
}
|
||||
case 154: break;
|
||||
case 155: break;
|
||||
case 6:
|
||||
{ return JetTokens.DIV ;
|
||||
}
|
||||
case 155: break;
|
||||
case 65:
|
||||
{ pushState(SHORT_TEMPLATE_ENTRY);
|
||||
yypushback(yylength() - 1);
|
||||
return JetTokens.SHORT_TEMPLATE_ENTRY_START;
|
||||
}
|
||||
case 156: break;
|
||||
case 83:
|
||||
{ return JetTokens.IDE_TEMPLATE_END ;
|
||||
@@ -1108,14 +1114,10 @@ class _JetLexer implements FlexLexer {
|
||||
{ return JetTokens.QUEST ;
|
||||
}
|
||||
case 160: break;
|
||||
case 43:
|
||||
{ if (zzCurrentPos == 0) {
|
||||
return JetTokens.SHEBANG_COMMENT;
|
||||
}
|
||||
else {
|
||||
yypushback(yylength() - 1);
|
||||
return JetTokens.HASH;
|
||||
}
|
||||
case 71:
|
||||
{ pushState(DOC_COMMENT);
|
||||
commentDepth = 0;
|
||||
commentStart = getTokenStart();
|
||||
}
|
||||
case 161: break;
|
||||
case 62:
|
||||
@@ -1142,83 +1144,77 @@ class _JetLexer implements FlexLexer {
|
||||
{ return TokenType.BAD_CHARACTER;
|
||||
}
|
||||
case 167: break;
|
||||
case 65:
|
||||
{ pushState(SHORT_TEMPLATE_ENTRY);
|
||||
yypushback(yylength() - 1);
|
||||
return JetTokens.SHORT_TEMPLATE_ENTRY_START;
|
||||
}
|
||||
case 168: break;
|
||||
case 72:
|
||||
{ return JetTokens.NOT_IS;
|
||||
}
|
||||
case 168: break;
|
||||
case 169: break;
|
||||
case 15:
|
||||
{ return JetTokens.MUL ;
|
||||
}
|
||||
case 169: break;
|
||||
case 170: break;
|
||||
case 24:
|
||||
{ return JetTokens.RBRACKET ;
|
||||
}
|
||||
case 170: break;
|
||||
case 171: break;
|
||||
case 60:
|
||||
{ return JetTokens.PLUSPLUS ;
|
||||
}
|
||||
case 171: break;
|
||||
case 87:
|
||||
{ return JetTokens.THIS_KEYWORD ;
|
||||
}
|
||||
case 172: break;
|
||||
case 9:
|
||||
{ return JetTokens.DOT ;
|
||||
}
|
||||
case 173: break;
|
||||
case 27:
|
||||
{ return JetTokens.SEMICOLON ;
|
||||
}
|
||||
case 174: break;
|
||||
case 51:
|
||||
{ return JetTokens.IF_KEYWORD ;
|
||||
}
|
||||
case 175: break;
|
||||
case 67:
|
||||
{ return JetTokens.ESCAPE_SEQUENCE;
|
||||
}
|
||||
case 176: break;
|
||||
case 41:
|
||||
{ pushState(BLOCK_COMMENT);
|
||||
commentDepth = 0;
|
||||
commentStart = getTokenStart();
|
||||
}
|
||||
case 173: break;
|
||||
case 87:
|
||||
{ return JetTokens.THIS_KEYWORD ;
|
||||
}
|
||||
case 174: break;
|
||||
case 9:
|
||||
{ return JetTokens.DOT ;
|
||||
}
|
||||
case 175: break;
|
||||
case 27:
|
||||
{ return JetTokens.SEMICOLON ;
|
||||
}
|
||||
case 176: break;
|
||||
case 51:
|
||||
{ return JetTokens.IF_KEYWORD ;
|
||||
}
|
||||
case 177: break;
|
||||
case 67:
|
||||
{ return JetTokens.ESCAPE_SEQUENCE;
|
||||
}
|
||||
case 178: break;
|
||||
case 31:
|
||||
{ popState(); return JetTokens.CLOSING_QUOTE;
|
||||
}
|
||||
case 178: break;
|
||||
case 179: break;
|
||||
case 18:
|
||||
{ return JetTokens.EQ ;
|
||||
}
|
||||
case 179: break;
|
||||
case 180: break;
|
||||
case 5:
|
||||
{ return JetTokens.AT ;
|
||||
}
|
||||
case 180: break;
|
||||
case 181: break;
|
||||
case 77:
|
||||
{ return JetTokens.AS_SAFE;
|
||||
}
|
||||
case 181: break;
|
||||
case 182: break;
|
||||
case 25:
|
||||
{ return JetTokens.LPAR ;
|
||||
}
|
||||
case 182: break;
|
||||
case 183: break;
|
||||
case 10:
|
||||
{ return JetTokens.MINUS ;
|
||||
}
|
||||
case 183: break;
|
||||
case 69:
|
||||
{ if (commentDepth > 0) {
|
||||
commentDepth--;
|
||||
}
|
||||
else {
|
||||
int state = yystate();
|
||||
popState();
|
||||
zzStartRead = commentStart;
|
||||
return commentStateToTokenType(state);
|
||||
}
|
||||
}
|
||||
case 184: break;
|
||||
case 101:
|
||||
{ return JetTokens.FALSE_KEYWORD ;
|
||||
@@ -1288,42 +1284,43 @@ class _JetLexer implements FlexLexer {
|
||||
{ return JetTokens.MULTEQ ;
|
||||
}
|
||||
case 201: break;
|
||||
case 43:
|
||||
{ if (zzCurrentPos == 0) {
|
||||
return JetTokens.SHEBANG_COMMENT;
|
||||
}
|
||||
else {
|
||||
yypushback(yylength() - 1);
|
||||
return JetTokens.HASH;
|
||||
}
|
||||
}
|
||||
case 202: break;
|
||||
case 13:
|
||||
{ return JetTokens.LBRACE ;
|
||||
}
|
||||
case 202: break;
|
||||
case 203: break;
|
||||
case 102:
|
||||
{ return JetTokens.OBJECT_KEYWORD ;
|
||||
}
|
||||
case 203: break;
|
||||
case 204: break;
|
||||
case 99:
|
||||
{ return JetTokens.BREAK_KEYWORD ;
|
||||
}
|
||||
case 204: break;
|
||||
case 205: break;
|
||||
case 85:
|
||||
{ return JetTokens.BLOCK_COMMENT;
|
||||
}
|
||||
case 205: break;
|
||||
case 206: break;
|
||||
case 96:
|
||||
{ return JetTokens.TRAIT_KEYWORD ;
|
||||
}
|
||||
case 206: break;
|
||||
case 207: break;
|
||||
case 64:
|
||||
{ return JetTokens.COLONCOLON;
|
||||
}
|
||||
case 207: break;
|
||||
case 208: break;
|
||||
case 33:
|
||||
{
|
||||
}
|
||||
case 208: break;
|
||||
case 35:
|
||||
{ if (lBraceCount == 0) {
|
||||
popState();
|
||||
return JetTokens.LONG_TEMPLATE_ENTRY_END;
|
||||
}
|
||||
lBraceCount--;
|
||||
return JetTokens.RBRACE;
|
||||
}
|
||||
case 209: break;
|
||||
case 7:
|
||||
{ return JetTokens.HASH ;
|
||||
|
||||
@@ -39,8 +39,8 @@ public final class QualifiedNamesUtil {
|
||||
return true;
|
||||
}
|
||||
|
||||
String subpackageNameStr = subpackageName.getFqName();
|
||||
String packageNameStr = packageName.getFqName();
|
||||
String subpackageNameStr = subpackageName.asString();
|
||||
String packageNameStr = packageName.asString();
|
||||
|
||||
return (subpackageNameStr.startsWith(packageNameStr) && subpackageNameStr.charAt(packageNameStr.length()) == '.');
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public final class QualifiedNamesUtil {
|
||||
}
|
||||
|
||||
public static boolean isOneSegmentFQN(@NotNull FqName fqn) {
|
||||
return isOneSegmentFQN(fqn.getFqName());
|
||||
return isOneSegmentFQN(fqn.asString());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -74,7 +74,7 @@ public final class QualifiedNamesUtil {
|
||||
return FqName.ROOT;
|
||||
}
|
||||
|
||||
String fqNameStr = fqName.getFqName();
|
||||
String fqNameStr = fqName.asString();
|
||||
return new FqName(fqNameStr.substring(fqNameStr.indexOf('.'), fqNameStr.length()));
|
||||
}
|
||||
|
||||
@@ -93,12 +93,12 @@ public final class QualifiedNamesUtil {
|
||||
@NotNull
|
||||
public static String tail(@NotNull FqName headFQN, @NotNull FqName fullFQN) {
|
||||
if (!isSubpackageOf(fullFQN, headFQN) || headFQN.isRoot()) {
|
||||
return fullFQN.getFqName();
|
||||
return fullFQN.asString();
|
||||
}
|
||||
|
||||
return fullFQN.equals(headFQN) ?
|
||||
"" :
|
||||
fullFQN.getFqName().substring(headFQN.getFqName().length() + 1); // (headFQN + '.').length
|
||||
fullFQN.asString().substring(headFQN.asString().length() + 1); // (headFQN + '.').length
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -143,6 +143,16 @@ public final class QualifiedNamesUtil {
|
||||
return isImported(alreadyImported, newImport.fqnPart());
|
||||
}
|
||||
|
||||
public static boolean isImported(@NotNull Iterable<ImportPath> imports, @NotNull ImportPath newImport) {
|
||||
for (ImportPath alreadyImported : imports) {
|
||||
if (isImported(alreadyImported, newImport)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isValidJavaFqName(@Nullable String qualifiedName) {
|
||||
if (qualifiedName == null) return false;
|
||||
|
||||
|
||||
@@ -55,6 +55,7 @@ public class TrackingSlicedMap implements MutableSlicedMap {
|
||||
return delegate.getKeys(wrapSlice(slice));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterator<Map.Entry<SlicedMapKey<?, ?>, ?>> iterator() {
|
||||
Map<SlicedMapKey<?, ?>, Object> map = Maps.newHashMap();
|
||||
|
||||
Reference in New Issue
Block a user