Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
766b4dc9
K
kotlin
项目概览
硅谷海盗
/
kotlin
与 Fork 源项目一致
从无法访问的项目Fork
通知
2
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kotlin
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
766b4dc9
编写于
4月 04, 2012
作者:
P
Pavel V. Talanov
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Move AnalyzerExhaust from frontend.java to frontend.
上级
973c6f8d
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
315 addition
and
250 deletion
+315
-250
compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java
...ackend/src/org/jetbrains/jet/codegen/GenerationState.java
+21
-10
compiler/backend/src/org/jetbrains/jet/codegen/GenerationUtils.java
...ackend/src/org/jetbrains/jet/codegen/GenerationUtils.java
+5
-4
compiler/cli/src/org/jetbrains/jet/compiler/CompileSession.java
...er/cli/src/org/jetbrains/jet/compiler/CompileSession.java
+22
-13
compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java
...jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java
+53
-49
compiler/frontend/src/org/jetbrains/jet/analyzer/AnalyzeExhaust.java
...ontend/src/org/jetbrains/jet/analyzer/AnalyzeExhaust.java
+3
-2
compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JetLightClass.java
....java.psi/src/org/jetbrains/jet/asJava/JetLightClass.java
+17
-15
compiler/tests/org/jetbrains/jet/JetTestUtils.java
compiler/tests/org/jetbrains/jet/JetTestUtils.java
+61
-57
compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java
...iler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java
+34
-22
compiler/tests/org/jetbrains/jet/resolve/ExpectedResolveData.java
.../tests/org/jetbrains/jet/resolve/ExpectedResolveData.java
+34
-32
compiler/tests/org/jetbrains/jet/types/JetDefaultModalityModifiersTest.java
.../jetbrains/jet/types/JetDefaultModalityModifiersTest.java
+28
-16
idea/src/org/jetbrains/jet/plugin/debugger/JetPositionManager.java
...org/jetbrains/jet/plugin/debugger/JetPositionManager.java
+14
-13
idea/src/org/jetbrains/jet/plugin/internal/codewindow/BytecodeToolwindow.java
...ns/jet/plugin/internal/codewindow/BytecodeToolwindow.java
+17
-14
idea/src/org/jetbrains/jet/plugin/project/WholeProjectAnalyzerFacade.java
...brains/jet/plugin/project/WholeProjectAnalyzerFacade.java
+6
-3
未找到文件。
compiler/backend/src/org/jetbrains/jet/codegen/GenerationState.java
浏览文件 @
766b4dc9
...
...
@@ -25,6 +25,7 @@ import com.intellij.openapi.project.Project;
import
com.intellij.openapi.util.Pair
;
import
com.intellij.openapi.vfs.VirtualFile
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.jet.analyzer.AnalyzeExhaust
;
import
org.jetbrains.jet.di.InjectorForJvmCodegen
;
import
org.jetbrains.jet.lang.descriptors.ClassDescriptor
;
import
org.jetbrains.jet.lang.descriptors.ConstructorDescriptor
;
...
...
@@ -34,7 +35,6 @@ import org.jetbrains.jet.lang.psi.JetFile;
import
org.jetbrains.jet.lang.psi.JetObjectDeclaration
;
import
org.jetbrains.jet.lang.psi.JetObjectLiteralExpression
;
import
org.jetbrains.jet.lang.resolve.BindingContext
;
import
org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust
;
import
org.jetbrains.jet.utils.Progress
;
import
java.util.List
;
...
...
@@ -54,12 +54,18 @@ public class GenerationState {
this
(
project
,
builderFactory
,
Progress
.
DEAF
,
analyzeExhaust
,
files
);
}
public
GenerationState
(
Project
project
,
ClassBuilderFactory
builderFactory
,
Progress
progress
,
@NotNull
AnalyzeExhaust
exhaust
,
@NotNull
List
<
JetFile
>
files
)
{
public
GenerationState
(
Project
project
,
ClassBuilderFactory
builderFactory
,
Progress
progress
,
@NotNull
AnalyzeExhaust
exhaust
,
@NotNull
List
<
JetFile
>
files
)
{
this
.
project
=
project
;
this
.
progress
=
progress
;
this
.
analyzeExhaust
=
exhaust
;
this
.
files
=
files
;
this
.
injector
=
new
InjectorForJvmCodegen
(
analyzeExhaust
.
getStandardLibrary
(),
analyzeExhaust
.
getBindingContext
(),
this
.
files
,
project
,
this
,
builderFactory
);
this
.
injector
=
new
InjectorForJvmCodegen
(
analyzeExhaust
.
getStandardLibrary
(),
analyzeExhaust
.
getBindingContext
(),
this
.
files
,
project
,
this
,
builderFactory
);
}
@NotNull
...
...
@@ -84,11 +90,13 @@ public class GenerationState {
}
public
ClassBuilder
forClassImplementation
(
ClassDescriptor
aClass
)
{
return
getFactory
().
newVisitor
(
getInjector
().
getJetTypeMapper
().
mapType
(
aClass
.
getDefaultType
(),
OwnerKind
.
IMPLEMENTATION
).
getInternalName
()
+
".class"
);
return
getFactory
().
newVisitor
(
getInjector
().
getJetTypeMapper
().
mapType
(
aClass
.
getDefaultType
(),
OwnerKind
.
IMPLEMENTATION
).
getInternalName
()
+
".class"
);
}
public
ClassBuilder
forTraitImplementation
(
ClassDescriptor
aClass
)
{
return
getFactory
().
newVisitor
(
getInjector
().
getJetTypeMapper
().
mapType
(
aClass
.
getDefaultType
(),
OwnerKind
.
TRAIT_IMPL
).
getInternalName
()
+
".class"
);
return
getFactory
().
newVisitor
(
getInjector
().
getJetTypeMapper
().
mapType
(
aClass
.
getDefaultType
(),
OwnerKind
.
TRAIT_IMPL
).
getInternalName
()
+
".class"
);
}
public
Pair
<
String
,
ClassBuilder
>
forAnonymousSubclass
(
JetExpression
expression
)
{
...
...
@@ -134,14 +142,17 @@ public class GenerationState {
closure
.
cv
=
nameAndVisitor
.
getSecond
();
closure
.
name
=
nameAndVisitor
.
getFirst
();
final
CodegenContext
objectContext
=
closure
.
context
.
intoAnonymousClass
(
closure
,
analyzeExhaust
.
getBindingContext
().
get
(
BindingContext
.
CLASS
,
objectDeclaration
),
OwnerKind
.
IMPLEMENTATION
,
injector
.
getJetTypeMapper
());
closure
,
analyzeExhaust
.
getBindingContext
().
get
(
BindingContext
.
CLASS
,
objectDeclaration
),
OwnerKind
.
IMPLEMENTATION
,
injector
.
getJetTypeMapper
());
new
ImplementationBodyCodegen
(
objectDeclaration
,
objectContext
,
nameAndVisitor
.
getSecond
(),
this
).
generate
();
ConstructorDescriptor
constructorDescriptor
=
analyzeExhaust
.
getBindingContext
().
get
(
BindingContext
.
CONSTRUCTOR
,
objectDeclaration
);
CallableMethod
callableMethod
=
injector
.
getJetTypeMapper
().
mapToCallableMethod
(
constructorDescriptor
,
OwnerKind
.
IMPLEMENTATION
,
injector
.
getJetTypeMapper
().
hasThis0
(
constructorDescriptor
.
getContainingDeclaration
()));
return
new
GeneratedAnonymousClassDescriptor
(
nameAndVisitor
.
first
,
callableMethod
.
getSignature
().
getAsmMethod
(),
objectContext
.
outerWasUsed
,
null
);
constructorDescriptor
,
OwnerKind
.
IMPLEMENTATION
,
injector
.
getJetTypeMapper
().
hasThis0
(
constructorDescriptor
.
getContainingDeclaration
()));
return
new
GeneratedAnonymousClassDescriptor
(
nameAndVisitor
.
first
,
callableMethod
.
getSignature
().
getAsmMethod
(),
objectContext
.
outerWasUsed
,
null
);
}
public
String
createText
()
{
...
...
@@ -151,8 +162,8 @@ public class GenerationState {
List
<
String
>
files
=
factory
.
files
();
for
(
String
file
:
files
)
{
// if (!file.startsWith("kotlin/")) {
answer
.
append
(
"@"
).
append
(
file
).
append
(
'\n'
);
answer
.
append
(
factory
.
asText
(
file
));
answer
.
append
(
"@"
).
append
(
file
).
append
(
'\n'
);
answer
.
append
(
factory
.
asText
(
file
));
// }
}
...
...
compiler/backend/src/org/jetbrains/jet/codegen/GenerationUtils.java
浏览文件 @
766b4dc9
...
...
@@ -17,9 +17,9 @@
package
org.jetbrains.jet.codegen
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.jet.analyzer.AnalyzeExhaust
;
import
org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory
;
import
org.jetbrains.jet.lang.psi.JetFile
;
import
org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust
;
import
org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM
;
import
java.util.Collections
;
...
...
@@ -34,10 +34,11 @@ public class GenerationUtils {
}
public
static
GenerationState
compileFileGetGenerationState
(
JetFile
psiFile
)
{
final
AnalyzeExhaust
analyzeExhaust
=
AnalyzerFacadeForJVM
.
analyzeOneFileWithJavaIntegrationAndCheckForErrors
(
psiFile
,
JetControlFlowDataTraceFactory
.
EMPTY
);
GenerationState
state
=
new
GenerationState
(
psiFile
.
getProject
(),
ClassBuilderFactories
.
binaries
(
false
),
analyzeExhaust
,
Collections
.
singletonList
(
psiFile
));
final
AnalyzeExhaust
analyzeExhaust
=
AnalyzerFacadeForJVM
.
analyzeOneFileWithJavaIntegrationAndCheckForErrors
(
psiFile
,
JetControlFlowDataTraceFactory
.
EMPTY
);
GenerationState
state
=
new
GenerationState
(
psiFile
.
getProject
(),
ClassBuilderFactories
.
binaries
(
false
),
analyzeExhaust
,
Collections
.
singletonList
(
psiFile
));
state
.
compileCorrectFiles
(
CompilationErrorHandler
.
THROW_EXCEPTION
);
return
state
;
}
}
compiler/cli/src/org/jetbrains/jet/compiler/CompileSession.java
浏览文件 @
766b4dc9
...
...
@@ -26,6 +26,7 @@ import com.intellij.psi.PsiFile;
import
com.intellij.psi.PsiManager
;
import
com.intellij.psi.PsiRecursiveElementWalkingVisitor
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.jet.analyzer.AnalyzeExhaust
;
import
org.jetbrains.jet.codegen.ClassBuilderFactories
;
import
org.jetbrains.jet.codegen.CompilationErrorHandler
;
import
org.jetbrains.jet.codegen.GenerationState
;
...
...
@@ -41,7 +42,6 @@ import org.jetbrains.jet.lang.diagnostics.DiagnosticUtils;
import
org.jetbrains.jet.lang.diagnostics.Severity
;
import
org.jetbrains.jet.lang.psi.JetFile
;
import
org.jetbrains.jet.lang.resolve.BindingContext
;
import
org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust
;
import
org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM
;
import
org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode
;
import
org.jetbrains.jet.lang.resolve.java.JavaDescriptorResolver
;
...
...
@@ -71,7 +71,11 @@ public class CompileSession {
private
final
CompilerSpecialMode
compilerSpecialMode
;
private
AnalyzeExhaust
bindingContext
;
public
CompileSession
(
JetCoreEnvironment
environment
,
MessageRenderer
messageRenderer
,
PrintStream
errorStream
,
boolean
verbose
,
CompilerSpecialMode
mode
)
{
public
CompileSession
(
JetCoreEnvironment
environment
,
MessageRenderer
messageRenderer
,
PrintStream
errorStream
,
boolean
verbose
,
CompilerSpecialMode
mode
)
{
this
.
environment
=
environment
;
this
.
messageRenderer
=
messageRenderer
;
this
.
errorStream
=
errorStream
;
...
...
@@ -90,8 +94,9 @@ public class CompileSession {
}
public
void
addSources
(
String
path
)
{
if
(
path
==
null
)
if
(
path
==
null
)
{
return
;
}
VirtualFile
vFile
=
environment
.
getLocalFileSystem
().
findFileByPath
(
path
);
if
(
vFile
==
null
)
{
...
...
@@ -107,7 +112,7 @@ public class CompileSession {
}
private
void
addSources
(
File
file
)
{
if
(
file
.
isDirectory
())
{
if
(
file
.
isDirectory
())
{
File
[]
files
=
file
.
listFiles
();
if
(
files
!=
null
)
{
for
(
File
child
:
files
)
{
...
...
@@ -119,7 +124,7 @@ public class CompileSession {
VirtualFile
fileByPath
=
environment
.
getLocalFileSystem
().
findFileByPath
(
file
.
getAbsolutePath
());
if
(
fileByPath
!=
null
)
{
PsiFile
psiFile
=
PsiManager
.
getInstance
(
environment
.
getProject
()).
findFile
(
fileByPath
);
if
(
psiFile
instanceof
JetFile
)
{
if
(
psiFile
instanceof
JetFile
)
{
sourceFiles
.
add
((
JetFile
)
psiFile
);
}
}
...
...
@@ -127,7 +132,7 @@ public class CompileSession {
}
public
void
addSources
(
VirtualFile
vFile
)
{
if
(
vFile
.
isDirectory
())
{
if
(
vFile
.
isDirectory
())
{
for
(
VirtualFile
virtualFile
:
vFile
.
getChildren
())
{
addSources
(
virtualFile
);
}
...
...
@@ -161,22 +166,25 @@ public class CompileSession {
/**
* @see JetTypeMapper#getFQName(DeclarationDescriptor)
* TODO possibly duplicates DescriptorUtils#getFQName(DeclarationDescriptor)
*
TODO possibly duplicates DescriptorUtils#getFQName(DeclarationDescriptor)
*/
private
static
String
fqName
(
ClassOrNamespaceDescriptor
descriptor
)
{
DeclarationDescriptor
containingDeclaration
=
descriptor
.
getContainingDeclaration
();
if
(
containingDeclaration
==
null
||
containingDeclaration
instanceof
ModuleDescriptor
||
containingDeclaration
.
getName
().
equals
(
JavaDescriptorResolver
.
JAVA_ROOT
))
{
if
(
containingDeclaration
==
null
||
containingDeclaration
instanceof
ModuleDescriptor
||
containingDeclaration
.
getName
().
equals
(
JavaDescriptorResolver
.
JAVA_ROOT
))
{
return
descriptor
.
getName
();
}
else
{
return
fqName
((
ClassOrNamespaceDescriptor
)
containingDeclaration
)
+
"."
+
descriptor
.
getName
();
}
else
{
return
fqName
((
ClassOrNamespaceDescriptor
)
containingDeclaration
)
+
"."
+
descriptor
.
getName
();
}
}
private
void
analyzeAndReportSemanticErrors
()
{
Predicate
<
PsiFile
>
filesToAnalyzeCompletely
=
stubs
?
Predicates
.<
PsiFile
>
alwaysFalse
()
:
Predicates
.<
PsiFile
>
alwaysTrue
();
stubs
?
Predicates
.<
PsiFile
>
alwaysFalse
()
:
Predicates
.<
PsiFile
>
alwaysTrue
();
bindingContext
=
AnalyzerFacadeForJVM
.
analyzeFilesWithJavaIntegration
(
environment
.
getProject
(),
sourceFiles
,
filesToAnalyzeCompletely
,
JetControlFlowDataTraceFactory
.
EMPTY
,
compilerSpecialMode
);
environment
.
getProject
(),
sourceFiles
,
filesToAnalyzeCompletely
,
JetControlFlowDataTraceFactory
.
EMPTY
,
compilerSpecialMode
);
for
(
Diagnostic
diagnostic
:
bindingContext
.
getBindingContext
().
getDiagnostics
())
{
reportDiagnostic
(
messageCollector
,
diagnostic
);
...
...
@@ -221,7 +229,8 @@ public class CompileSession {
public
GenerationState
generate
(
boolean
module
)
{
Project
project
=
environment
.
getProject
();
GenerationState
generationState
=
new
GenerationState
(
project
,
ClassBuilderFactories
.
binaries
(
stubs
),
isVerbose
?
new
BackendProgress
()
:
Progress
.
DEAF
,
bindingContext
,
sourceFiles
);
isVerbose
?
new
BackendProgress
()
:
Progress
.
DEAF
,
bindingContext
,
sourceFiles
);
generationState
.
compileCorrectFiles
(
CompilationErrorHandler
.
THROW_EXCEPTION
);
List
<
CompilerPlugin
>
plugins
=
environment
.
getCompilerPlugins
();
...
...
compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacadeForJVM.java
浏览文件 @
766b4dc9
...
...
@@ -29,6 +29,7 @@ import com.intellij.psi.util.CachedValuesManager;
import
com.intellij.psi.util.PsiModificationTracker
;
import
com.intellij.util.Function
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.jet.analyzer.AnalyzeExhaust
;
import
org.jetbrains.jet.di.InjectorForTopDownAnalyzerForJvm
;
import
org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory
;
import
org.jetbrains.jet.lang.descriptors.ModuleDescriptor
;
...
...
@@ -71,36 +72,38 @@ public class AnalyzerFacadeForJVM {
* @param declarationProvider
* @return
*/
public
static
AnalyzeExhaust
analyzeFileWithCache
(
@NotNull
final
JetFile
file
,
@NotNull
final
Function
<
JetFile
,
Collection
<
JetFile
>>
declarationProvider
)
{
public
static
AnalyzeExhaust
analyzeFileWithCache
(
@NotNull
final
JetFile
file
,
@NotNull
final
Function
<
JetFile
,
Collection
<
JetFile
>>
declarationProvider
)
{
// Need lock for getValue(), because parallel threads can start evaluation of compute() simultaneously
synchronized
(
lock
)
{
CachedValue
<
AnalyzeExhaust
>
bindingContextCachedValue
=
file
.
getUserData
(
BINDING_CONTEXT
);
if
(
bindingContextCachedValue
==
null
)
{
bindingContextCachedValue
=
CachedValuesManager
.
getManager
(
file
.
getProject
()).
createCachedValue
(
new
CachedValueProvider
<
AnalyzeExhaust
>()
{
@Override
public
Result
<
AnalyzeExhaust
>
compute
()
{
try
{
AnalyzeExhaust
bindingContext
=
analyzeFilesWithJavaIntegration
(
bindingContextCachedValue
=
CachedValuesManager
.
getManager
(
file
.
getProject
()).
createCachedValue
(
new
CachedValueProvider
<
AnalyzeExhaust
>()
{
@Override
public
Result
<
AnalyzeExhaust
>
compute
()
{
try
{
AnalyzeExhaust
bindingContext
=
analyzeFilesWithJavaIntegration
(
file
.
getProject
(),
declarationProvider
.
fun
(
file
),
Predicates
.<
PsiFile
>
equalTo
(
file
),
JetControlFlowDataTraceFactory
.
EMPTY
,
CompilerSpecialMode
.
REGULAR
);
return
new
Result
<
AnalyzeExhaust
>(
bindingContext
,
PsiModificationTracker
.
MODIFICATION_COUNT
);
return
new
Result
<
AnalyzeExhaust
>(
bindingContext
,
PsiModificationTracker
.
MODIFICATION_COUNT
);
}
catch
(
ProcessCanceledException
e
)
{
throw
e
;
}
catch
(
Throwable
e
)
{
DiagnosticUtils
.
throwIfRunningOnServer
(
e
);
LOG
.
error
(
e
);
BindingTraceContext
bindingTraceContext
=
new
BindingTraceContext
();
bindingTraceContext
.
report
(
Errors
.
EXCEPTION_WHILE_ANALYZING
.
on
(
file
,
e
));
AnalyzeExhaust
analyzeExhaust
=
new
AnalyzeExhaust
(
bindingTraceContext
.
getBindingContext
(),
null
);
return
new
Result
<
AnalyzeExhaust
>(
analyzeExhaust
,
PsiModificationTracker
.
MODIFICATION_COUNT
);
}
}
catch
(
ProcessCanceledException
e
)
{
throw
e
;
}
catch
(
Throwable
e
)
{
DiagnosticUtils
.
throwIfRunningOnServer
(
e
);
LOG
.
error
(
e
);
BindingTraceContext
bindingTraceContext
=
new
BindingTraceContext
();
bindingTraceContext
.
report
(
Errors
.
EXCEPTION_WHILE_ANALYZING
.
on
(
file
,
e
));
AnalyzeExhaust
analyzeExhaust
=
new
AnalyzeExhaust
(
bindingTraceContext
.
getBindingContext
(),
null
);
return
new
Result
<
AnalyzeExhaust
>(
analyzeExhaust
,
PsiModificationTracker
.
MODIFICATION_COUNT
);
}
}
},
false
);
},
false
);
file
.
putUserData
(
BINDING_CONTEXT
,
bindingContextCachedValue
);
}
return
bindingContextCachedValue
.
getValue
();
...
...
@@ -111,35 +114,36 @@ public class AnalyzerFacadeForJVM {
* Analyze project with string cache for the whole project. All given files will be analyzed only for descriptors.
*/
public
static
AnalyzeExhaust
analyzeProjectWithCache
(
@NotNull
final
Project
project
,
@NotNull
final
Collection
<
JetFile
>
files
)
{
@NotNull
final
Collection
<
JetFile
>
files
)
{
// Need lock for getValue(), because parallel threads can start evaluation of compute() simultaneously
synchronized
(
lock
)
{
CachedValue
<
AnalyzeExhaust
>
bindingContextCachedValue
=
project
.
getUserData
(
BINDING_CONTEXT
);
if
(
bindingContextCachedValue
==
null
)
{
bindingContextCachedValue
=
CachedValuesManager
.
getManager
(
project
).
createCachedValue
(
new
CachedValueProvider
<
AnalyzeExhaust
>()
{
@Override
public
Result
<
AnalyzeExhaust
>
compute
()
{
try
{
AnalyzeExhaust
analyzeExhaust
=
analyzeFilesWithJavaIntegration
(
bindingContextCachedValue
=
CachedValuesManager
.
getManager
(
project
).
createCachedValue
(
new
CachedValueProvider
<
AnalyzeExhaust
>()
{
@Override
public
Result
<
AnalyzeExhaust
>
compute
()
{
try
{
AnalyzeExhaust
analyzeExhaust
=
analyzeFilesWithJavaIntegration
(
project
,
files
,
Predicates
.<
PsiFile
>
alwaysFalse
(),
JetControlFlowDataTraceFactory
.
EMPTY
,
CompilerSpecialMode
.
REGULAR
);
return
new
Result
<
AnalyzeExhaust
>(
analyzeExhaust
,
PsiModificationTracker
.
MODIFICATION_COUNT
);
}
catch
(
ProcessCanceledException
e
)
{
throw
e
;
}
catch
(
Throwable
e
)
{
DiagnosticUtils
.
throwIfRunningOnServer
(
e
);
LOG
.
error
(
e
);
BindingTraceContext
bindingTraceContext
=
new
BindingTraceContext
();
AnalyzeExhaust
analyzeExhaust
=
new
AnalyzeExhaust
(
bindingTraceContext
.
getBindingContext
(),
null
);
return
new
Result
<
AnalyzeExhaust
>(
analyzeExhaust
,
PsiModificationTracker
.
MODIFICATION_COUNT
);
return
new
Result
<
AnalyzeExhaust
>(
analyzeExhaust
,
PsiModificationTracker
.
MODIFICATION_COUNT
);
}
catch
(
ProcessCanceledException
e
)
{
throw
e
;
}
catch
(
Throwable
e
)
{
DiagnosticUtils
.
throwIfRunningOnServer
(
e
);
LOG
.
error
(
e
);
BindingTraceContext
bindingTraceContext
=
new
BindingTraceContext
();
AnalyzeExhaust
analyzeExhaust
=
new
AnalyzeExhaust
(
bindingTraceContext
.
getBindingContext
(),
null
);
return
new
Result
<
AnalyzeExhaust
>(
analyzeExhaust
,
PsiModificationTracker
.
MODIFICATION_COUNT
);
}
}
}
},
false
);
},
false
);
project
.
putUserData
(
BINDING_CONTEXT
,
bindingContextCachedValue
);
}
return
bindingContextCachedValue
.
getValue
();
...
...
@@ -147,7 +151,7 @@ public class AnalyzerFacadeForJVM {
}
public
static
AnalyzeExhaust
analyzeOneFileWithJavaIntegrationAndCheckForErrors
(
JetFile
file
,
JetControlFlowDataTraceFactory
flowDataTraceFactory
)
{
JetFile
file
,
JetControlFlowDataTraceFactory
flowDataTraceFactory
)
{
AnalyzingUtils
.
checkForSyntacticErrors
(
file
);
AnalyzeExhaust
analyzeExhaust
=
analyzeOneFileWithJavaIntegration
(
file
,
flowDataTraceFactory
);
...
...
@@ -159,25 +163,25 @@ public class AnalyzerFacadeForJVM {
public
static
AnalyzeExhaust
analyzeOneFileWithJavaIntegration
(
JetFile
file
,
JetControlFlowDataTraceFactory
flowDataTraceFactory
)
{
return
analyzeFilesWithJavaIntegration
(
file
.
getProject
(),
Collections
.
singleton
(
file
),
Predicates
.<
PsiFile
>
alwaysTrue
(),
flowDataTraceFactory
,
CompilerSpecialMode
.
REGULAR
);
Predicates
.<
PsiFile
>
alwaysTrue
(),
flowDataTraceFactory
,
CompilerSpecialMode
.
REGULAR
);
}
public
static
AnalyzeExhaust
analyzeFilesWithJavaIntegration
(
Project
project
,
Collection
<
JetFile
>
files
,
Predicate
<
PsiFile
>
filesToAnalyzeCompletely
,
JetControlFlowDataTraceFactory
flowDataTraceFactory
,
CompilerSpecialMode
compilerSpecialMode
)
{
Project
project
,
Collection
<
JetFile
>
files
,
Predicate
<
PsiFile
>
filesToAnalyzeCompletely
,
JetControlFlowDataTraceFactory
flowDataTraceFactory
,
CompilerSpecialMode
compilerSpecialMode
)
{
BindingTraceContext
bindingTraceContext
=
new
BindingTraceContext
();
final
ModuleDescriptor
owner
=
new
ModuleDescriptor
(
"<module>"
);
TopDownAnalysisParameters
topDownAnalysisParameters
=
new
TopDownAnalysisParameters
(
filesToAnalyzeCompletely
,
false
,
false
);
filesToAnalyzeCompletely
,
false
,
false
);
InjectorForTopDownAnalyzerForJvm
injector
=
new
InjectorForTopDownAnalyzerForJvm
(
project
,
topDownAnalysisParameters
,
new
ObservableBindingTrace
(
bindingTraceContext
),
owner
,
flowDataTraceFactory
,
compilerSpecialMode
);
project
,
topDownAnalysisParameters
,
new
ObservableBindingTrace
(
bindingTraceContext
),
owner
,
flowDataTraceFactory
,
compilerSpecialMode
);
injector
.
getTopDownAnalyzer
().
analyzeFiles
(
files
);
...
...
@@ -190,6 +194,6 @@ public class AnalyzerFacadeForJVM {
Project
project
=
files
.
iterator
().
next
().
getProject
();
return
analyzeFilesWithJavaIntegration
(
project
,
files
,
Predicates
.<
PsiFile
>
alwaysFalse
(),
JetControlFlowDataTraceFactory
.
EMPTY
,
CompilerSpecialMode
.
REGULAR
);
JetControlFlowDataTraceFactory
.
EMPTY
,
CompilerSpecialMode
.
REGULAR
);
}
}
compiler/frontend
.java/src/org/jetbrains/jet/lang/resolve/java
/AnalyzeExhaust.java
→
compiler/frontend
/src/org/jetbrains/jet/analyzer
/AnalyzeExhaust.java
浏览文件 @
766b4dc9
...
...
@@ -14,7 +14,7 @@
* limitations under the License.
*/
package
org.jetbrains.jet.
lang.resolve.java
;
package
org.jetbrains.jet.
analyzer
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
...
...
@@ -35,7 +35,8 @@ public class AnalyzeExhaust {
this
.
standardLibrary
=
standardLibrary
;
}
@NotNull
public
BindingContext
getBindingContext
()
{
@NotNull
public
BindingContext
getBindingContext
()
{
return
bindingContext
;
}
...
...
compiler/jet.as.java.psi/src/org/jetbrains/jet/asJava/JetLightClass.java
浏览文件 @
766b4dc9
...
...
@@ -41,6 +41,7 @@ import com.intellij.psi.util.CachedValuesManager;
import
com.intellij.psi.util.PsiModificationTracker
;
import
com.intellij.util.containers.Stack
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.jet.analyzer.AnalyzeExhaust
;
import
org.jetbrains.jet.codegen.ClassBuilder
;
import
org.jetbrains.jet.codegen.ClassBuilderFactory
;
import
org.jetbrains.jet.codegen.CompilationErrorHandler
;
...
...
@@ -48,7 +49,6 @@ import org.jetbrains.jet.codegen.GenerationState;
import
org.jetbrains.jet.lang.psi.JetFile
;
import
org.jetbrains.jet.lang.psi.JetPsiUtil
;
import
org.jetbrains.jet.lang.resolve.FqName
;
import
org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust
;
import
org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM
;
import
org.jetbrains.jet.lang.resolve.java.JetFilesProvider
;
import
org.jetbrains.jet.lang.resolve.java.JetJavaMirrorMarker
;
...
...
@@ -100,8 +100,8 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa
}
private
static
PsiClass
findClass
(
FqName
fqn
,
StubElement
<?>
stub
)
{
if
(
stub
instanceof
PsiClassStub
&&
Comparing
.
equal
(
fqn
.
getFqName
(),
((
PsiClassStub
)
stub
).
getQualifiedName
()))
{
return
(
PsiClass
)
stub
.
getPsi
();
if
(
stub
instanceof
PsiClassStub
&&
Comparing
.
equal
(
fqn
.
getFqName
(),
((
PsiClassStub
)
stub
).
getQualifiedName
()))
{
return
(
PsiClass
)
stub
.
getPsi
();
}
for
(
StubElement
child
:
stub
.
getChildrenStubs
())
{
...
...
@@ -128,14 +128,14 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa
},
false
);
file
.
putUserData
(
JAVA_API_STUB
,
answer
);
}
return
answer
.
getValue
();
}
private
PsiJavaFileStub
calcStub
()
{
final
PsiJavaFileStubImpl
answer
=
new
PsiJavaFileStubImpl
(
JetPsiUtil
.
getFQName
(
file
).
getFqName
(),
true
);
final
Project
project
=
getProject
();
final
Stack
<
StubElement
>
stubStack
=
new
Stack
<
StubElement
>();
final
ClassBuilderFactory
builderFactory
=
new
ClassBuilderFactory
()
{
...
...
@@ -168,13 +168,14 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa
stubStack
.
push
(
answer
);
answer
.
setPsiFactory
(
new
ClsWrapperStubPsiFactory
());
final
ClsFileImpl
fakeFile
=
new
ClsFileImpl
((
PsiManagerImpl
)
manager
,
new
ClassFileViewProvider
(
manager
,
file
.
getVirtualFile
()))
{
@NotNull
@Override
public
PsiClassHolderFileStub
getStub
()
{
return
answer
;
}
};
final
ClsFileImpl
fakeFile
=
new
ClsFileImpl
((
PsiManagerImpl
)
manager
,
new
ClassFileViewProvider
(
manager
,
file
.
getVirtualFile
()))
{
@NotNull
@Override
public
PsiClassHolderFileStub
getStub
()
{
return
answer
;
}
};
fakeFile
.
setPhysical
(
false
);
answer
.
setPsi
(
fakeFile
);
...
...
@@ -205,7 +206,7 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa
@Override
public
boolean
isEquivalentTo
(
PsiElement
another
)
{
return
another
instanceof
PsiClass
&&
Comparing
.
equal
(((
PsiClass
)
another
).
getQualifiedName
(),
getQualifiedName
());
return
another
instanceof
PsiClass
&&
Comparing
.
equal
(((
PsiClass
)
another
).
getQualifiedName
(),
getQualifiedName
());
}
@Override
...
...
@@ -217,7 +218,8 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa
public
String
toString
()
{
try
{
return
JetLightClass
.
class
.
getSimpleName
()
+
":"
+
getQualifiedName
();
}
catch
(
Throwable
e
)
{
}
catch
(
Throwable
e
)
{
return
JetLightClass
.
class
.
getSimpleName
()
+
":"
+
e
.
toString
();
}
}
...
...
compiler/tests/org/jetbrains/jet/JetTestUtils.java
浏览文件 @
766b4dc9
...
...
@@ -22,6 +22,7 @@ import com.intellij.openapi.util.ShutDownTracker;
import
com.intellij.openapi.util.io.FileUtil
;
import
junit.framework.TestCase
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.jet.analyzer.AnalyzeExhaust
;
import
org.jetbrains.jet.compiler.JetCoreEnvironment
;
import
org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory
;
import
org.jetbrains.jet.lang.diagnostics.Diagnostic
;
...
...
@@ -30,7 +31,6 @@ import org.jetbrains.jet.lang.diagnostics.UnresolvedReferenceDiagnostic;
import
org.jetbrains.jet.lang.psi.JetFile
;
import
org.jetbrains.jet.lang.resolve.BindingContext
;
import
org.jetbrains.jet.lang.resolve.BindingTrace
;
import
org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust
;
import
org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM
;
import
org.jetbrains.jet.util.slicedmap.ReadOnlySlice
;
import
org.jetbrains.jet.util.slicedmap.SlicedMap
;
...
...
@@ -86,7 +86,7 @@ public class JetTestUtils {
@Override
public
<
K
,
V
>
V
get
(
ReadOnlySlice
<
K
,
V
>
slice
,
K
key
)
{
if
(
slice
==
BindingContext
.
PROCESSED
)
return
(
V
)
Boolean
.
FALSE
;
if
(
slice
==
BindingContext
.
PROCESSED
)
return
(
V
)
Boolean
.
FALSE
;
return
SlicedMap
.
DO_NOTHING
.
get
(
slice
,
key
);
}
...
...
@@ -100,61 +100,61 @@ public class JetTestUtils {
@Override
public
void
report
(
@NotNull
Diagnostic
diagnostic
)
{
if
(
diagnostic
instanceof
UnresolvedReferenceDiagnostic
)
{
UnresolvedReferenceDiagnostic
unresolvedReferenceDiagnostic
=
(
UnresolvedReferenceDiagnostic
)
diagnostic
;
UnresolvedReferenceDiagnostic
unresolvedReferenceDiagnostic
=
(
UnresolvedReferenceDiagnostic
)
diagnostic
;
throw
new
IllegalStateException
(
"Unresolved: "
+
unresolvedReferenceDiagnostic
.
getPsiElement
().
getText
());
}
}
};
public
static
BindingTrace
DUMMY_EXCEPTION_ON_ERROR_TRACE
=
new
BindingTrace
()
{
@Override
public
BindingContext
getBindingContext
()
{
return
new
BindingContext
()
{
@Override
public
Collection
<
Diagnostic
>
getDiagnostics
()
{
throw
new
UnsupportedOperationException
();
}
@Override
public
<
K
,
V
>
V
get
(
ReadOnlySlice
<
K
,
V
>
slice
,
K
key
)
{
return
DUMMY_EXCEPTION_ON_ERROR_TRACE
.
get
(
slice
,
key
);
}
@NotNull
@Override
public
<
K
,
V
>
Collection
<
K
>
getKeys
(
WritableSlice
<
K
,
V
>
slice
)
{
return
DUMMY_EXCEPTION_ON_ERROR_TRACE
.
getKeys
(
slice
);
}
};
}
@Override
public
BindingContext
getBindingContext
()
{
return
new
BindingContext
()
{
@Override
public
Collection
<
Diagnostic
>
getDiagnostics
()
{
throw
new
UnsupportedOperationException
();
}
@Override
public
<
K
,
V
>
void
record
(
WritableSlice
<
K
,
V
>
slice
,
K
key
,
V
value
)
{
}
@Override
public
<
K
,
V
>
V
get
(
ReadOnlySlice
<
K
,
V
>
slice
,
K
key
)
{
return
DUMMY_EXCEPTION_ON_ERROR_TRACE
.
get
(
slice
,
key
);
}
@Override
public
<
K
>
void
record
(
WritableSlice
<
K
,
Boolean
>
slice
,
K
key
)
{
}
@NotNull
@Override
public
<
K
,
V
>
Collection
<
K
>
getKeys
(
WritableSlice
<
K
,
V
>
slice
)
{
return
DUMMY_EXCEPTION_ON_ERROR_TRACE
.
getKeys
(
slice
);
}
};
}
@Override
public
<
K
,
V
>
V
get
(
ReadOnlySlice
<
K
,
V
>
slice
,
K
key
)
{
return
null
;
}
@Override
public
<
K
,
V
>
void
record
(
WritableSlice
<
K
,
V
>
slice
,
K
key
,
V
value
)
{
}
@NotNull
@Override
public
<
K
,
V
>
Collection
<
K
>
getKeys
(
WritableSlice
<
K
,
V
>
slice
)
{
assert
slice
.
isCollective
();
return
Collections
.
emptySet
();
}
@Override
public
<
K
>
void
record
(
WritableSlice
<
K
,
Boolean
>
slice
,
K
key
)
{
}
@Override
public
void
report
(
@NotNull
Diagnostic
diagnostic
)
{
if
(
diagnostic
.
getSeverity
()
==
Severity
.
ERROR
)
{
throw
new
IllegalStateException
(
diagnostic
.
getMessage
());
}
}
};
@Override
public
<
K
,
V
>
V
get
(
ReadOnlySlice
<
K
,
V
>
slice
,
K
key
)
{
return
null
;
}
@NotNull
@Override
public
<
K
,
V
>
Collection
<
K
>
getKeys
(
WritableSlice
<
K
,
V
>
slice
)
{
assert
slice
.
isCollective
();
return
Collections
.
emptySet
();
}
@Override
public
void
report
(
@NotNull
Diagnostic
diagnostic
)
{
if
(
diagnostic
.
getSeverity
()
==
Severity
.
ERROR
)
{
throw
new
IllegalStateException
(
diagnostic
.
getMessage
());
}
}
};
public
static
AnalyzeExhaust
analyzeFile
(
@NotNull
JetFile
namespace
,
@NotNull
JetControlFlowDataTraceFactory
flowDataTraceFactory
)
{
return
AnalyzerFacadeForJVM
.
analyzeOneFileWithJavaIntegration
(
namespace
,
flowDataTraceFactory
);
...
...
@@ -202,24 +202,25 @@ public class JetTestUtils {
public
static
void
deleteOnShutdown
(
File
file
)
{
if
(
filesToDelete
.
isEmpty
())
{
ShutDownTracker
.
getInstance
().
registerShutdownTask
(
new
Runnable
()
{
@Override
public
void
run
()
{
@Override
public
void
run
()
{
ShutDownTracker
.
invokeAndWait
(
true
,
true
,
new
Runnable
()
{
@Override
public
void
run
()
{
for
(
File
victim
:
filesToDelete
)
{
FileUtil
.
delete
(
victim
);
}
}
@Override
public
void
run
()
{
for
(
File
victim
:
filesToDelete
)
{
FileUtil
.
delete
(
victim
);
}
}
});
}
});
}
});
}
filesToDelete
.
add
(
file
);
}
public
static
final
Pattern
FILE_PATTERN
=
Pattern
.
compile
(
"//\\s*FILE:\\s*(.*)$"
,
Pattern
.
MULTILINE
);
public
interface
TestFileFactory
<
F
>
{
F
create
(
String
fileName
,
String
text
);
}
...
...
@@ -254,7 +255,10 @@ public class JetTestUtils {
if
(!
nextFileExists
)
break
;
}
assert
processedChars
==
expectedText
.
length
()
:
"Characters skipped from "
+
processedChars
+
" to "
+
(
expectedText
.
length
()
-
1
);
assert
processedChars
==
expectedText
.
length
()
:
"Characters skipped from "
+
processedChars
+
" to "
+
(
expectedText
.
length
()
-
1
);
}
return
testFileFiles
;
}
...
...
compiler/tests/org/jetbrains/jet/codegen/CodegenTestCase.java
浏览文件 @
766b4dc9
...
...
@@ -19,11 +19,10 @@ package org.jetbrains.jet.codegen;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
import
org.jetbrains.jet.JetLiteFixture
;
import
org.jetbrains.jet.analyzer.AnalyzeExhaust
;
import
org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory
;
import
org.jetbrains.jet.lang.psi.JetFile
;
import
org.jetbrains.jet.lang.psi.JetPsiUtil
;
import
org.jetbrains.jet.lang.resolve.AnalyzingUtils
;
import
org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust
;
import
org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM
;
import
org.jetbrains.jet.parsing.JetParsingTest
;
...
...
@@ -38,12 +37,13 @@ import java.util.Collections;
*/
public
abstract
class
CodegenTestCase
extends
JetLiteFixture
{
protected
static
void
assertThrows
(
Method
foo
,
Class
<?
extends
Throwable
>
exceptionClass
,
Object
instance
,
Object
...
args
)
throws
IllegalAccessException
{
protected
static
void
assertThrows
(
Method
foo
,
Class
<?
extends
Throwable
>
exceptionClass
,
Object
instance
,
Object
...
args
)
throws
IllegalAccessException
{
boolean
caught
=
false
;
try
{
foo
.
invoke
(
instance
,
args
);
}
catch
(
InvocationTargetException
ex
)
{
catch
(
InvocationTargetException
ex
)
{
caught
=
exceptionClass
.
isInstance
(
ex
.
getTargetException
());
}
assertTrue
(
caught
);
...
...
@@ -61,16 +61,17 @@ public abstract class CodegenTestCase extends JetLiteFixture {
}
protected
void
loadText
(
final
String
text
)
{
myFile
=
(
JetFile
)
createFile
(
"a.jet"
,
text
);
myFile
=
(
JetFile
)
createFile
(
"a.jet"
,
text
);
}
@Override
protected
String
loadFile
(
final
String
name
)
{
try
{
final
String
content
=
doLoadFile
(
JetParsingTest
.
getTestDataDir
()
+
"/codegen/"
,
name
);
myFile
=
(
JetFile
)
createFile
(
name
,
content
);
myFile
=
(
JetFile
)
createFile
(
name
,
content
);
return
content
;
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
}
}
...
...
@@ -88,10 +89,12 @@ public abstract class CodegenTestCase extends JetLiteFixture {
String
actual
;
try
{
actual
=
blackBox
();
}
catch
(
NoClassDefFoundError
e
)
{
}
catch
(
NoClassDefFoundError
e
)
{
System
.
out
.
println
(
generateToText
());
throw
e
;
}
catch
(
Throwable
e
)
{
}
catch
(
Throwable
e
)
{
System
.
out
.
println
(
generateToText
());
throw
new
RuntimeException
(
e
);
}
...
...
@@ -109,9 +112,10 @@ public abstract class CodegenTestCase extends JetLiteFixture {
String
fqName
=
NamespaceCodegen
.
getJVMClassName
(
JetPsiUtil
.
getFQName
(
myFile
),
true
).
replace
(
"/"
,
"."
);
Class
<?>
namespaceClass
=
loader
.
loadClass
(
fqName
);
Method
method
=
namespaceClass
.
getMethod
(
"box"
);
return
(
String
)
method
.
invoke
(
null
);
}
finally
{
loader
.
dispose
();
return
(
String
)
method
.
invoke
(
null
);
}
finally
{
loader
.
dispose
();
}
}
...
...
@@ -124,7 +128,8 @@ public abstract class CodegenTestCase extends JetLiteFixture {
}
private
GenerationState
generateCommon
(
ClassBuilderFactory
classBuilderFactory
)
{
final
AnalyzeExhaust
analyzeExhaust
=
AnalyzerFacadeForJVM
.
analyzeOneFileWithJavaIntegrationAndCheckForErrors
(
myFile
,
JetControlFlowDataTraceFactory
.
EMPTY
);
final
AnalyzeExhaust
analyzeExhaust
=
AnalyzerFacadeForJVM
.
analyzeOneFileWithJavaIntegrationAndCheckForErrors
(
myFile
,
JetControlFlowDataTraceFactory
.
EMPTY
);
GenerationState
state
=
new
GenerationState
(
getProject
(),
classBuilderFactory
,
analyzeExhaust
,
Collections
.
singletonList
(
myFile
));
state
.
compileCorrectFiles
(
CompilationErrorHandler
.
THROW_EXCEPTION
);
return
state
;
...
...
@@ -144,9 +149,11 @@ public abstract class CodegenTestCase extends JetLiteFixture {
String
fqName
=
NamespaceCodegen
.
getJVMClassName
(
JetPsiUtil
.
getFQName
(
myFile
),
true
).
replace
(
"/"
,
"."
);
try
{
return
createClassLoader
(
state
).
loadClass
(
fqName
);
}
catch
(
ClassNotFoundException
e
)
{
}
catch
(
ClassNotFoundException
e
)
{
e
.
printStackTrace
();
}
catch
(
MalformedURLException
e
)
{
}
catch
(
MalformedURLException
e
)
{
e
.
printStackTrace
();
}
return
null
;
...
...
@@ -155,8 +162,10 @@ public abstract class CodegenTestCase extends JetLiteFixture {
protected
Class
loadClass
(
String
fqName
,
@NotNull
ClassFileFactory
state
)
{
try
{
return
createClassLoader
(
state
).
loadClass
(
fqName
);
}
catch
(
ClassNotFoundException
e
)
{
}
catch
(
MalformedURLException
e
)
{
}
catch
(
ClassNotFoundException
e
)
{
}
catch
(
MalformedURLException
e
)
{
}
fail
(
"No classfile was generated for: "
+
fqName
);
...
...
@@ -169,7 +178,8 @@ public abstract class CodegenTestCase extends JetLiteFixture {
ClassBuilderFactory
classBuilderFactory
=
ClassBuilderFactories
.
binaries
(
false
);
return
generateCommon
(
classBuilderFactory
).
getFactory
();
}
catch
(
RuntimeException
e
)
{
}
catch
(
RuntimeException
e
)
{
System
.
out
.
println
(
generateToText
());
throw
e
;
}
...
...
@@ -190,10 +200,12 @@ public abstract class CodegenTestCase extends JetLiteFixture {
r
=
method
;
}
if
(
r
==
null
)
if
(
r
==
null
)
{
throw
new
AssertionError
();
}
return
r
;
}
catch
(
Error
e
)
{
}
catch
(
Error
e
)
{
System
.
out
.
println
(
generateToText
());
throw
e
;
}
...
...
@@ -221,11 +233,11 @@ public abstract class CodegenTestCase extends JetLiteFixture {
protected
static
void
assertIsCurrentTime
(
long
returnValue
)
{
long
currentTime
=
System
.
currentTimeMillis
();
long
diff
=
Math
.
abs
(
returnValue
-
currentTime
);
assertTrue
(
"Difference with current time: "
+
diff
+
" (this test is a bad one: it may fail even if the generated code is correct)"
,
diff
<=
1L
);
assertTrue
(
"Difference with current time: "
+
diff
+
" (this test is a bad one: it may fail even if the generated code is correct)"
,
diff
<=
1L
);
}
protected
Class
loadImplementationClass
(
@NotNull
ClassFileFactory
codegens
,
final
String
name
)
{
return
loadClass
(
name
,
codegens
);
}
}
compiler/tests/org/jetbrains/jet/resolve/ExpectedResolveData.java
浏览文件 @
766b4dc9
...
...
@@ -23,6 +23,7 @@ import com.intellij.openapi.project.Project;
import
com.intellij.psi.PsiElement
;
import
com.intellij.psi.PsiFile
;
import
com.intellij.psi.util.PsiTreeUtil
;
import
org.jetbrains.jet.analyzer.AnalyzeExhaust
;
import
org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory
;
import
org.jetbrains.jet.lang.descriptors.*
;
import
org.jetbrains.jet.lang.diagnostics.Diagnostic
;
...
...
@@ -31,13 +32,12 @@ import org.jetbrains.jet.lang.diagnostics.UnresolvedReferenceDiagnostic;
import
org.jetbrains.jet.lang.psi.*
;
import
org.jetbrains.jet.lang.resolve.BindingContext
;
import
org.jetbrains.jet.lang.resolve.BindingContextUtils
;
import
org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust
;
import
org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM
;
import
org.jetbrains.jet.lang.resolve.java.CompilerSpecialMode
;
import
org.jetbrains.jet.lang.types.ErrorUtils
;
import
org.jetbrains.jet.lang.types.lang.JetStandardLibrary
;
import
org.jetbrains.jet.lang.types.JetType
;
import
org.jetbrains.jet.lang.types.TypeConstructor
;
import
org.jetbrains.jet.lang.types.lang.JetStandardLibrary
;
import
java.util.List
;
import
java.util.Map
;
...
...
@@ -139,11 +139,13 @@ public abstract class ExpectedResolveData {
JetStandardLibrary
lib
=
JetStandardLibrary
.
getInstance
();
AnalyzeExhaust
analyzeExhaust
=
AnalyzerFacadeForJVM
.
analyzeFilesWithJavaIntegration
(
project
,
files
,
Predicates
.<
PsiFile
>
alwaysTrue
(),
JetControlFlowDataTraceFactory
.
EMPTY
,
CompilerSpecialMode
.
REGULAR
);
Predicates
.<
PsiFile
>
alwaysTrue
(),
JetControlFlowDataTraceFactory
.
EMPTY
,
CompilerSpecialMode
.
REGULAR
);
BindingContext
bindingContext
=
analyzeExhaust
.
getBindingContext
();
for
(
Diagnostic
diagnostic
:
bindingContext
.
getDiagnostics
())
{
if
(
diagnostic
instanceof
UnresolvedReferenceDiagnostic
)
{
UnresolvedReferenceDiagnostic
unresolvedReferenceDiagnostic
=
(
UnresolvedReferenceDiagnostic
)
diagnostic
;
UnresolvedReferenceDiagnostic
unresolvedReferenceDiagnostic
=
(
UnresolvedReferenceDiagnostic
)
diagnostic
;
unresolvedReferences
.
add
(
unresolvedReferenceDiagnostic
.
getPsiElement
());
}
}
...
...
@@ -174,35 +176,35 @@ public abstract class ExpectedResolveData {
JetReferenceExpression
referenceExpression
=
PsiTreeUtil
.
getParentOfType
(
element
,
JetReferenceExpression
.
class
);
if
(
"!"
.
equals
(
name
))
{
assertTrue
(
"Must have been unresolved: "
+
renderReferenceInContext
(
referenceExpression
)
+
" but was resolved to "
+
DescriptorRenderer
.
TEXT
.
render
(
bindingContext
.
get
(
REFERENCE_TARGET
,
referenceExpression
)),
unresolvedReferences
.
contains
(
referenceExpression
));
"Must have been unresolved: "
+
renderReferenceInContext
(
referenceExpression
)
+
" but was resolved to "
+
DescriptorRenderer
.
TEXT
.
render
(
bindingContext
.
get
(
REFERENCE_TARGET
,
referenceExpression
)),
unresolvedReferences
.
contains
(
referenceExpression
));
continue
;
}
if
(
"!!"
.
equals
(
name
))
{
assertTrue
(
"Must have been resolved to multiple descriptors: "
+
renderReferenceInContext
(
referenceExpression
)
+
" but was resolved to "
+
DescriptorRenderer
.
TEXT
.
render
(
bindingContext
.
get
(
REFERENCE_TARGET
,
referenceExpression
)),
bindingContext
.
get
(
AMBIGUOUS_REFERENCE_TARGET
,
referenceExpression
)
!=
null
);
"Must have been resolved to multiple descriptors: "
+
renderReferenceInContext
(
referenceExpression
)
+
" but was resolved to "
+
DescriptorRenderer
.
TEXT
.
render
(
bindingContext
.
get
(
REFERENCE_TARGET
,
referenceExpression
)),
bindingContext
.
get
(
AMBIGUOUS_REFERENCE_TARGET
,
referenceExpression
)
!=
null
);
continue
;
}
else
if
(
"!null"
.
equals
(
name
))
{
assertTrue
(
"Must have been resolved to null: "
+
renderReferenceInContext
(
referenceExpression
)
+
" but was resolved to "
+
DescriptorRenderer
.
TEXT
.
render
(
bindingContext
.
get
(
REFERENCE_TARGET
,
referenceExpression
)),
bindingContext
.
get
(
REFERENCE_TARGET
,
referenceExpression
)
==
null
"Must have been resolved to null: "
+
renderReferenceInContext
(
referenceExpression
)
+
" but was resolved to "
+
DescriptorRenderer
.
TEXT
.
render
(
bindingContext
.
get
(
REFERENCE_TARGET
,
referenceExpression
)),
bindingContext
.
get
(
REFERENCE_TARGET
,
referenceExpression
)
==
null
);
continue
;
}
else
if
(
"!error"
.
equals
(
name
))
{
assertTrue
(
"Must have been resolved to error: "
+
renderReferenceInContext
(
referenceExpression
)
+
" but was resolved to "
+
DescriptorRenderer
.
TEXT
.
render
(
bindingContext
.
get
(
REFERENCE_TARGET
,
referenceExpression
)),
ErrorUtils
.
isError
(
bindingContext
.
get
(
REFERENCE_TARGET
,
referenceExpression
))
"Must have been resolved to error: "
+
renderReferenceInContext
(
referenceExpression
)
+
" but was resolved to "
+
DescriptorRenderer
.
TEXT
.
render
(
bindingContext
.
get
(
REFERENCE_TARGET
,
referenceExpression
)),
ErrorUtils
.
isError
(
bindingContext
.
get
(
REFERENCE_TARGET
,
referenceExpression
))
);
continue
;
}
...
...
@@ -250,30 +252,30 @@ public abstract class ExpectedResolveData {
if
(
expected
instanceof
JetParameter
||
actual
instanceof
JetParameter
)
{
DeclarationDescriptor
expectedDescriptor
;
if
(
name
.
startsWith
(
"$"
))
{
expectedDescriptor
=
bindingContext
.
get
(
BindingContext
.
PRIMARY_CONSTRUCTOR_PARAMETER
,
(
JetParameter
)
expected
);
expectedDescriptor
=
bindingContext
.
get
(
BindingContext
.
PRIMARY_CONSTRUCTOR_PARAMETER
,
(
JetParameter
)
expected
);
}
else
{
expectedDescriptor
=
bindingContext
.
get
(
BindingContext
.
DECLARATION_TO_DESCRIPTOR
,
expected
);
if
(
expectedDescriptor
==
null
)
{
expectedDescriptor
=
bindingContext
.
get
(
BindingContext
.
CONSTRUCTOR
,
(
JetElement
)
expected
);
expectedDescriptor
=
bindingContext
.
get
(
BindingContext
.
CONSTRUCTOR
,
(
JetElement
)
expected
);
}
}
DeclarationDescriptor
actualDescriptor
=
bindingContext
.
get
(
REFERENCE_TARGET
,
reference
);
if
(
actualDescriptor
instanceof
VariableAsFunctionDescriptor
)
{
VariableAsFunctionDescriptor
descriptor
=
(
VariableAsFunctionDescriptor
)
actualDescriptor
;
VariableAsFunctionDescriptor
descriptor
=
(
VariableAsFunctionDescriptor
)
actualDescriptor
;
actualDescriptor
=
descriptor
.
getVariableDescriptor
();
}
assertEquals
(
"Reference `"
+
name
+
"`"
+
renderReferenceInContext
(
reference
)
+
" is resolved into "
+
actualName
+
"."
,
expectedDescriptor
,
actualDescriptor
);
"Reference `"
+
name
+
"`"
+
renderReferenceInContext
(
reference
)
+
" is resolved into "
+
actualName
+
"."
,
expectedDescriptor
,
actualDescriptor
);
}
else
{
assertEquals
(
"Reference `"
+
name
+
"`"
+
renderReferenceInContext
(
reference
)
+
" is resolved into "
+
actualName
+
"."
,
expected
,
actual
);
"Reference `"
+
name
+
"`"
+
renderReferenceInContext
(
reference
)
+
" is resolved into "
+
actualName
+
"."
,
expected
,
actual
);
}
}
...
...
@@ -305,7 +307,8 @@ public abstract class ExpectedResolveData {
expectedTypeConstructor
=
classDescriptor
.
getTypeConstructor
();
}
else
if
(
declaration
instanceof
JetTypeParameter
)
{
TypeParameterDescriptor
typeParameterDescriptor
=
bindingContext
.
get
(
BindingContext
.
TYPE_PARAMETER
,
(
JetTypeParameter
)
declaration
);
TypeParameterDescriptor
typeParameterDescriptor
=
bindingContext
.
get
(
BindingContext
.
TYPE_PARAMETER
,
(
JetTypeParameter
)
declaration
);
expectedTypeConstructor
=
typeParameterDescriptor
.
getTypeConstructor
();
}
else
{
...
...
@@ -325,14 +328,13 @@ public abstract class ExpectedResolveData {
PsiElement
parent
=
statement
.
getParent
();
if
(!(
parent
instanceof
JetExpression
))
break
;
if
(
parent
instanceof
JetBlockExpression
)
break
;
statement
=
(
JetExpression
)
parent
;
statement
=
(
JetExpression
)
parent
;
}
JetDeclaration
declaration
=
PsiTreeUtil
.
getParentOfType
(
referenceExpression
,
JetDeclaration
.
class
);
return
referenceExpression
.
getText
()
+
" at "
+
DiagnosticUtils
.
atLocation
(
referenceExpression
)
+
" in "
+
statement
.
getText
()
+
(
declaration
==
null
?
""
:
" in "
+
declaration
.
getText
());
" in "
+
statement
.
getText
()
+
(
declaration
==
null
?
""
:
" in "
+
declaration
.
getText
());
}
private
static
<
T
>
T
getAncestorOfType
(
Class
<
T
>
type
,
PsiElement
element
)
{
...
...
@@ -340,7 +342,7 @@ public abstract class ExpectedResolveData {
element
=
element
.
getParent
();
}
@SuppressWarnings
({
"unchecked"
,
"UnnecessaryLocalVariable"
})
T
result
=
(
T
)
element
;
T
result
=
(
T
)
element
;
return
result
;
}
}
compiler/tests/org/jetbrains/jet/types/JetDefaultModalityModifiersTest.java
浏览文件 @
766b4dc9
...
...
@@ -18,12 +18,12 @@ package org.jetbrains.jet.types;
import
org.jetbrains.jet.JetLiteFixture
;
import
org.jetbrains.jet.JetTestUtils
;
import
org.jetbrains.jet.analyzer.AnalyzeExhaust
;
import
org.jetbrains.jet.di.InjectorForTests
;
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.DescriptorResolver
;
import
org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust
;
import
org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM
;
import
org.jetbrains.jet.lang.resolve.scopes.JetScope
;
import
org.jetbrains.jet.lang.resolve.scopes.RedeclarationHandler
;
...
...
@@ -45,7 +45,7 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
tc
.
setUp
();
}
public
class
JetDefaultModalityModifiersTestCase
{
public
class
JetDefaultModalityModifiersTestCase
{
private
ModuleDescriptor
root
=
new
ModuleDescriptor
(
"test_root"
);
private
DescriptorResolver
descriptorResolver
;
private
JetScope
scope
;
...
...
@@ -62,11 +62,13 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
List
<
JetDeclaration
>
declarations
=
file
.
getDeclarations
();
JetDeclaration
aClass
=
declarations
.
get
(
0
);
assert
aClass
instanceof
JetClass
;
AnalyzeExhaust
bindingContext
=
AnalyzerFacadeForJVM
.
analyzeFileWithCache
(
file
,
AnalyzerFacadeForJVM
.
SINGLE_DECLARATION_PROVIDER
);
DeclarationDescriptor
classDescriptor
=
bindingContext
.
getBindingContext
().
get
(
BindingContext
.
DECLARATION_TO_DESCRIPTOR
,
aClass
);
AnalyzeExhaust
bindingContext
=
AnalyzerFacadeForJVM
.
analyzeFileWithCache
(
file
,
AnalyzerFacadeForJVM
.
SINGLE_DECLARATION_PROVIDER
);
DeclarationDescriptor
classDescriptor
=
bindingContext
.
getBindingContext
().
get
(
BindingContext
.
DECLARATION_TO_DESCRIPTOR
,
aClass
);
WritableScopeImpl
scope
=
new
WritableScopeImpl
(
libraryScope
,
root
,
RedeclarationHandler
.
DO_NOTHING
);
assert
classDescriptor
instanceof
ClassifierDescriptor
;
scope
.
addClassifierDescriptor
((
ClassifierDescriptor
)
classDescriptor
);
scope
.
addClassifierDescriptor
((
ClassifierDescriptor
)
classDescriptor
);
scope
.
changeLockLevel
(
WritableScope
.
LockLevel
.
READING
);
return
scope
;
}
...
...
@@ -90,8 +92,9 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
MutableClassDescriptor
classDescriptor
=
createClassDescriptor
(
kind
,
aClass
);
List
<
JetDeclaration
>
declarations
=
aClass
.
getDeclarations
();
JetNamedFunction
function
=
(
JetNamedFunction
)
declarations
.
get
(
0
);
SimpleFunctionDescriptor
functionDescriptor
=
descriptorResolver
.
resolveFunctionDescriptor
(
classDescriptor
,
scope
,
function
,
JetTestUtils
.
DUMMY_TRACE
);
JetNamedFunction
function
=
(
JetNamedFunction
)
declarations
.
get
(
0
);
SimpleFunctionDescriptor
functionDescriptor
=
descriptorResolver
.
resolveFunctionDescriptor
(
classDescriptor
,
scope
,
function
,
JetTestUtils
.
DUMMY_TRACE
);
assertEquals
(
expectedFunctionModality
,
functionDescriptor
.
getModality
());
}
...
...
@@ -101,20 +104,25 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
MutableClassDescriptor
classDescriptor
=
createClassDescriptor
(
kind
,
aClass
);
List
<
JetDeclaration
>
declarations
=
aClass
.
getDeclarations
();
JetProperty
property
=
(
JetProperty
)
declarations
.
get
(
0
);
PropertyDescriptor
propertyDescriptor
=
descriptorResolver
.
resolvePropertyDescriptor
(
classDescriptor
,
scope
,
property
,
JetTestUtils
.
DUMMY_TRACE
);
JetProperty
property
=
(
JetProperty
)
declarations
.
get
(
0
);
PropertyDescriptor
propertyDescriptor
=
descriptorResolver
.
resolvePropertyDescriptor
(
classDescriptor
,
scope
,
property
,
JetTestUtils
.
DUMMY_TRACE
);
assertEquals
(
expectedPropertyModality
,
propertyDescriptor
.
getModality
());
}
private
void
testPropertyAccessorModality
(
String
classWithPropertyWithAccessor
,
ClassKind
kind
,
Modality
expectedPropertyAccessorModality
,
boolean
isGetter
)
{
private
void
testPropertyAccessorModality
(
String
classWithPropertyWithAccessor
,
ClassKind
kind
,
Modality
expectedPropertyAccessorModality
,
boolean
isGetter
)
{
JetClass
aClass
=
JetPsiFactory
.
createClass
(
getProject
(),
classWithPropertyWithAccessor
);
MutableClassDescriptor
classDescriptor
=
createClassDescriptor
(
kind
,
aClass
);
List
<
JetDeclaration
>
declarations
=
aClass
.
getDeclarations
();
JetProperty
property
=
(
JetProperty
)
declarations
.
get
(
0
);
PropertyDescriptor
propertyDescriptor
=
descriptorResolver
.
resolvePropertyDescriptor
(
classDescriptor
,
scope
,
property
,
JetTestUtils
.
DUMMY_TRACE
);
JetProperty
property
=
(
JetProperty
)
declarations
.
get
(
0
);
PropertyDescriptor
propertyDescriptor
=
descriptorResolver
.
resolvePropertyDescriptor
(
classDescriptor
,
scope
,
property
,
JetTestUtils
.
DUMMY_TRACE
);
PropertyAccessorDescriptor
propertyAccessor
=
isGetter
?
propertyDescriptor
.
getGetter
()
:
propertyDescriptor
.
getSetter
();
...
...
@@ -382,13 +390,15 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
tc
.
testPropertyAccessorModalityInClass
(
"open class A : C { open override val a: Int = 0; open get }"
,
Modality
.
OPEN
);
tc
.
testPropertyAccessorModalityInClass
(
"open class A : C { open override val a: Int = 0; final get }"
,
Modality
.
FINAL
);
tc
.
testPropertyAccessorModalityInClass
(
"open class A : C { open override val a: Int = 0; override get() = 2 }"
,
Modality
.
OPEN
);
tc
.
testPropertyAccessorModalityInClass
(
"open class A : C { open override val a: Int = 0; final override get() = 2 }"
,
Modality
.
FINAL
);
tc
.
testPropertyAccessorModalityInClass
(
"open class A : C { open override val a: Int = 0; final override get() = 2 }"
,
Modality
.
FINAL
);
tc
.
testPropertyAccessorModalityInClass
(
"open class A : C { final override val a: Int = 0 }"
,
Modality
.
FINAL
);
tc
.
testPropertyAccessorModalityInClass
(
"open class A : C { final override val a: Int = 0; get }"
,
Modality
.
FINAL
);
tc
.
testPropertyAccessorModalityInClass
(
"open class A : C { final override val a: Int = 0; final get }"
,
Modality
.
FINAL
);
tc
.
testPropertyAccessorModalityInClass
(
"open class A : C { final override val a: Int = 0; override get() = 2 }"
,
Modality
.
OPEN
);
tc
.
testPropertyAccessorModalityInClass
(
"open class A : C { final override val a: Int = 0; final override get() = 2 }"
,
Modality
.
FINAL
);
tc
.
testPropertyAccessorModalityInClass
(
"open class A : C { final override val a: Int = 0; final override get() = 2 }"
,
Modality
.
FINAL
);
tc
.
testPropertyAccessorModalityInClass
(
"abstract class A : C { abstract override val a: Int }"
,
Modality
.
ABSTRACT
);
tc
.
testPropertyAccessorModalityInClass
(
"abstract class A : C { abstract override val a: Int get }"
,
Modality
.
ABSTRACT
);
...
...
@@ -401,10 +411,12 @@ public class JetDefaultModalityModifiersTest extends JetLiteFixture {
tc
.
testPropertyAccessorModalityInClass
(
"abstract class A : C { open abstract override val a: Int }"
,
Modality
.
ABSTRACT
);
tc
.
testPropertyAccessorModalityInClass
(
"abstract class A : C { open abstract override val a: Int get }"
,
Modality
.
ABSTRACT
);
tc
.
testPropertyAccessorModalityInClass
(
"abstract class A : C { open abstract override val a: Int open get }"
,
Modality
.
ABSTRACT
);
tc
.
testPropertyAccessorModalityInClass
(
"abstract class A : C { open abstract override val a: Int abstract get }"
,
Modality
.
ABSTRACT
);
tc
.
testPropertyAccessorModalityInClass
(
"abstract class A : C { open abstract override val a: Int abstract get }"
,
Modality
.
ABSTRACT
);
tc
.
testPropertyAccessorModalityInClass
(
"abstract class A : C { open override val a: Int override get() = 10 }"
,
Modality
.
OPEN
);
tc
.
testPropertyAccessorModalityInClass
(
"abstract class A : C { open override val a: Int open override get() = 10 }"
,
Modality
.
OPEN
);
tc
.
testPropertyAccessorModalityInClass
(
"abstract class A : C { open override val a: Int final override get() = 10 }"
,
Modality
.
FINAL
);
tc
.
testPropertyAccessorModalityInClass
(
"abstract class A : C { open override val a: Int final override get() = 10 }"
,
Modality
.
FINAL
);
tc
.
testPropertyAccessorModalityInTrait
(
"trait A : C { override val a: Int }"
,
Modality
.
ABSTRACT
);
tc
.
testPropertyAccessorModalityInTrait
(
"trait A : C { override val a: Int get }"
,
Modality
.
ABSTRACT
);
...
...
idea/src/org/jetbrains/jet/plugin/debugger/JetPositionManager.java
浏览文件 @
766b4dc9
...
...
@@ -34,13 +34,13 @@ import com.sun.jdi.ReferenceType;
import
com.sun.jdi.request.ClassPrepareRequest
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
import
org.jetbrains.jet.analyzer.AnalyzeExhaust
;
import
org.jetbrains.jet.codegen.JetTypeMapper
;
import
org.jetbrains.jet.codegen.NamespaceCodegen
;
import
org.jetbrains.jet.di.InjectorForJetTypeMapper
;
import
org.jetbrains.jet.lang.psi.JetClassOrObject
;
import
org.jetbrains.jet.lang.psi.JetFile
;
import
org.jetbrains.jet.lang.psi.JetPsiUtil
;
import
org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust
;
import
org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade
;
import
java.util.*
;
...
...
@@ -67,7 +67,8 @@ public class JetPositionManager implements PositionManager {
int
lineNumber
;
try
{
lineNumber
=
location
.
lineNumber
()
-
1
;
}
catch
(
InternalError
e
)
{
}
catch
(
InternalError
e
)
{
lineNumber
=
-
1
;
}
...
...
@@ -86,8 +87,8 @@ public class JetPositionManager implements PositionManager {
if
(
files
.
length
==
1
&&
files
[
0
]
instanceof
JetFile
)
{
return
files
[
0
];
}
}
catch
(
AbsentInformationException
e
)
{
}
catch
(
AbsentInformationException
e
)
{
throw
new
NoDataException
();
}
...
...
@@ -126,7 +127,7 @@ public class JetPositionManager implements PositionManager {
ApplicationManager
.
getApplication
().
runReadAction
(
new
Runnable
()
{
@Override
public
void
run
()
{
final
JetFile
file
=
(
JetFile
)
sourcePosition
.
getFile
();
final
JetFile
file
=
(
JetFile
)
sourcePosition
.
getFile
();
JetTypeMapper
typeMapper
=
prepareTypeMapper
(
file
);
JetClassOrObject
jetClass
=
PsiTreeUtil
.
getParentOfType
(
sourcePosition
.
getElementAt
(),
JetClassOrObject
.
class
);
...
...
@@ -155,7 +156,7 @@ public class JetPositionManager implements PositionManager {
}
final
AnalyzeExhaust
analyzeExhaust
=
WholeProjectAnalyzerFacade
.
analyzeProjectWithCacheOnAFile
(
file
);
JetTypeMapper
typeMapper
=
new
InjectorForJetTypeMapper
(
analyzeExhaust
.
getStandardLibrary
(),
analyzeExhaust
.
getBindingContext
(),
Collections
.
singletonList
(
file
)).
getJetTypeMapper
();
analyzeExhaust
.
getStandardLibrary
(),
analyzeExhaust
.
getBindingContext
(),
Collections
.
singletonList
(
file
)).
getJetTypeMapper
();
myTypeMappers
.
put
(
file
,
typeMapper
);
return
typeMapper
;
}
...
...
@@ -167,15 +168,15 @@ public class JetPositionManager implements PositionManager {
throw
new
NoDataException
();
}
try
{
int
line
=
position
.
getLine
()
+
1
;
List
<
Location
>
locations
=
myDebugProcess
.
getVirtualMachineProxy
().
versionHigher
(
"1.4"
)
?
type
.
locationsOfLine
(
DebugProcess
.
JAVA_STRATUM
,
null
,
line
)
:
type
.
locationsOfLine
(
line
);
if
(
locations
==
null
||
locations
.
isEmpty
())
throw
new
NoDataException
();
return
locations
;
int
line
=
position
.
getLine
()
+
1
;
List
<
Location
>
locations
=
myDebugProcess
.
getVirtualMachineProxy
().
versionHigher
(
"1.4"
)
?
type
.
locationsOfLine
(
DebugProcess
.
JAVA_STRATUM
,
null
,
line
)
:
type
.
locationsOfLine
(
line
);
if
(
locations
==
null
||
locations
.
isEmpty
())
throw
new
NoDataException
();
return
locations
;
}
catch
(
AbsentInformationException
e
)
{
throw
new
NoDataException
();
throw
new
NoDataException
();
}
}
...
...
idea/src/org/jetbrains/jet/plugin/internal/codewindow/BytecodeToolwindow.java
浏览文件 @
766b4dc9
...
...
@@ -36,12 +36,12 @@ import com.intellij.openapi.vfs.VirtualFile;
import
com.intellij.psi.PsiFile
;
import
com.intellij.psi.PsiManager
;
import
com.intellij.util.Alarm
;
import
org.jetbrains.jet.analyzer.AnalyzeExhaust
;
import
org.jetbrains.jet.codegen.ClassBuilderFactories
;
import
org.jetbrains.jet.codegen.ClassFileFactory
;
import
org.jetbrains.jet.codegen.CompilationErrorHandler
;
import
org.jetbrains.jet.codegen.GenerationState
;
import
org.jetbrains.jet.lang.psi.JetFile
;
import
org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust
;
import
org.jetbrains.jet.plugin.project.WholeProjectAnalyzerFacade
;
import
javax.swing.*
;
...
...
@@ -69,7 +69,8 @@ public class BytecodeToolwindow extends JPanel implements Disposable {
public
BytecodeToolwindow
(
Project
project
)
{
super
(
new
BorderLayout
());
myProject
=
project
;
myEditor
=
EditorFactory
.
getInstance
().
createEditor
(
EditorFactory
.
getInstance
().
createDocument
(
""
),
project
,
JavaFileType
.
INSTANCE
,
true
);
myEditor
=
EditorFactory
.
getInstance
().
createEditor
(
EditorFactory
.
getInstance
().
createDocument
(
""
),
project
,
JavaFileType
.
INSTANCE
,
true
);
add
(
myEditor
.
getComponent
());
myUpdateAlarm
=
new
Alarm
(
Alarm
.
ThreadToUse
.
SWING_THREAD
,
this
);
myUpdateAlarm
.
addRequest
(
new
Runnable
()
{
...
...
@@ -92,7 +93,7 @@ public class BytecodeToolwindow extends JPanel implements Disposable {
setText
(
DEFAULT_TEXT
);
}
else
{
VirtualFile
vFile
=
((
EditorEx
)
editor
).
getVirtualFile
();
VirtualFile
vFile
=
((
EditorEx
)
editor
).
getVirtualFile
();
if
(
vFile
==
null
)
{
setText
(
DEFAULT_TEXT
);
return
;
...
...
@@ -104,17 +105,21 @@ public class BytecodeToolwindow extends JPanel implements Disposable {
return
;
}
if
(
oldLocation
==
null
||
!
Comparing
.
equal
(
oldLocation
.
editor
,
location
.
editor
)
||
oldLocation
.
modificationStamp
!=
location
.
modificationStamp
)
{
setText
(
generateToText
((
JetFile
)
psiFile
));
if
(
oldLocation
==
null
||
!
Comparing
.
equal
(
oldLocation
.
editor
,
location
.
editor
)
||
oldLocation
.
modificationStamp
!=
location
.
modificationStamp
)
{
setText
(
generateToText
((
JetFile
)
psiFile
));
}
Document
document
=
editor
.
getDocument
();
int
startLine
=
document
.
getLineNumber
(
location
.
startOffset
);
int
endLine
=
document
.
getLineNumber
(
location
.
endOffset
);
if
(
endLine
>
startLine
&&
location
.
endOffset
>
0
&&
document
.
getCharsSequence
().
charAt
(
location
.
endOffset
-
1
)
==
'\n'
)
endLine
--;
if
(
endLine
>
startLine
&&
location
.
endOffset
>
0
&&
document
.
getCharsSequence
().
charAt
(
location
.
endOffset
-
1
)
==
'\n'
)
{
endLine
--;
}
Document
byteCodeDocument
=
myEditor
.
getDocument
();
Pair
<
Integer
,
Integer
>
linesRange
=
mapLines
(
byteCodeDocument
.
getText
(),
startLine
,
endLine
);
int
endSelectionLineIndex
=
Math
.
min
(
linesRange
.
second
+
1
,
byteCodeDocument
.
getLineCount
());
...
...
@@ -152,7 +157,7 @@ public class BytecodeToolwindow extends JPanel implements Disposable {
break
;
}
}
for
(
String
line
:
text
.
split
(
"\n"
))
{
line
=
line
.
trim
();
...
...
@@ -163,7 +168,7 @@ public class BytecodeToolwindow extends JPanel implements Disposable {
byteCodeStartLine
=
byteCodeLine
;
}
if
(
byteCodeStartLine
>
0
&&
ktLineNum
>
endLine
)
{
if
(
byteCodeStartLine
>
0
&&
ktLineNum
>
endLine
)
{
byteCodeEndLine
=
byteCodeLine
-
1
;
break
;
}
...
...
@@ -179,14 +184,12 @@ public class BytecodeToolwindow extends JPanel implements Disposable {
}
if
(
byteCodeStartLine
==
-
1
||
byteCodeEndLine
==
-
1
)
{
return
new
Pair
<
Integer
,
Integer
>(
0
,
0
);
}
else
{
return
new
Pair
<
Integer
,
Integer
>(
byteCodeStartLine
,
byteCodeEndLine
);
}
}
private
void
setText
(
final
String
text
)
{
...
...
@@ -269,7 +272,7 @@ public class BytecodeToolwindow extends JPanel implements Disposable {
if
(
this
==
o
)
return
true
;
if
(!(
o
instanceof
Location
))
return
false
;
Location
location
=
(
Location
)
o
;
Location
location
=
(
Location
)
o
;
if
(
endOffset
!=
location
.
endOffset
)
return
false
;
if
(
modificationStamp
!=
location
.
modificationStamp
)
return
false
;
...
...
@@ -282,10 +285,10 @@ public class BytecodeToolwindow extends JPanel implements Disposable {
@Override
public
int
hashCode
()
{
int
result
=
editor
!=
null
?
editor
.
hashCode
()
:
0
;
result
=
31
*
result
+
(
int
)
(
modificationStamp
^
(
modificationStamp
>>>
32
));
result
=
31
*
result
+
(
int
)(
modificationStamp
^
(
modificationStamp
>>>
32
));
result
=
31
*
result
+
startOffset
;
result
=
31
*
result
+
endOffset
;
return
result
;
}
}
}
}
idea/src/org/jetbrains/jet/plugin/project/WholeProjectAnalyzerFacade.java
浏览文件 @
766b4dc9
...
...
@@ -19,8 +19,8 @@ package org.jetbrains.jet.plugin.project;
import
com.intellij.openapi.project.Project
;
import
com.intellij.psi.search.GlobalSearchScope
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.jet.analyzer.AnalyzeExhaust
;
import
org.jetbrains.jet.lang.psi.JetFile
;
import
org.jetbrains.jet.lang.resolve.java.AnalyzeExhaust
;
import
org.jetbrains.jet.lang.resolve.java.AnalyzerFacadeForJVM
;
import
org.jetbrains.jet.lang.resolve.java.JetFilesProvider
;
...
...
@@ -29,8 +29,11 @@ import org.jetbrains.jet.lang.resolve.java.JetFilesProvider;
*/
public
final
class
WholeProjectAnalyzerFacade
{
/** Forbid creating */
private
WholeProjectAnalyzerFacade
()
{}
/**
* Forbid creating
*/
private
WholeProjectAnalyzerFacade
()
{
}
@NotNull
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录