Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
硅谷海盗
kotlin
提交
fc01eb2d
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,发现更多精彩内容 >>
提交
fc01eb2d
编写于
10月 30, 2011
作者:
A
Andrey Breslav
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fixing dependencies & nested modules
上级
473779be
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
92 addition
and
81 deletion
+92
-81
compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacade.java
...c/org/jetbrains/jet/lang/resolve/java/AnalyzerFacade.java
+75
-3
compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnalyzingUtils.java
...nd/src/org/jetbrains/jet/lang/resolve/AnalyzingUtils.java
+5
-71
compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java
...d/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java
+7
-4
compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java
...org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java
+1
-1
compiler/tests/org/jetbrains/jet/checkers/CheckerTestUtilTest.java
...tests/org/jetbrains/jet/checkers/CheckerTestUtilTest.java
+2
-1
compiler/tests/org/jetbrains/jet/checkers/QuickJetPsiCheckerTest.java
...ts/org/jetbrains/jet/checkers/QuickJetPsiCheckerTest.java
+2
-1
未找到文件。
compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/AnalyzerFacade.java
浏览文件 @
fc01eb2d
package
org.jetbrains.jet.lang.resolve.java
;
import
com.google.common.collect.Sets
;
import
com.intellij.openapi.application.ApplicationManager
;
import
com.intellij.openapi.compiler.ex.CompilerPathsEx
;
import
com.intellij.openapi.progress.ProcessCanceledException
;
import
com.intellij.openapi.project.Project
;
import
com.intellij.openapi.roots.ProjectRootManager
;
import
com.intellij.openapi.util.Key
;
import
com.intellij.openapi.vfs.VirtualFile
;
import
com.intellij.psi.PsiFile
;
import
com.intellij.psi.PsiManager
;
import
com.intellij.psi.util.CachedValue
;
import
com.intellij.psi.util.CachedValueProvider
;
import
com.intellij.psi.util.CachedValuesManager
;
import
com.intellij.psi.util.PsiModificationTracker
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory
;
import
org.jetbrains.jet.lang.diagnostics.Errors
;
import
org.jetbrains.jet.lang.psi.JetDeclaration
;
import
org.jetbrains.jet.lang.psi.JetFile
;
import
org.jetbrains.jet.lang.psi.JetNamespace
;
import
org.jetbrains.jet.lang.resolve.AnalyzingUtils
;
import
org.jetbrains.jet.lang.resolve.BindingContext
;
import
org.jetbrains.jet.lang.resolve.BindingTraceContext
;
import
java.util.Set
;
/**
* @author abreslav
*/
public
class
AnalyzerFacade
{
private
static
final
AnalyzingUtils
ANALYZING_UTILS
=
AnalyzingUtils
.
getInstance
(
JavaDefaultImports
.
JAVA_DEFAULT_IMPORTS
);
private
final
static
Key
<
CachedValue
<
BindingContext
>>
BINDING_CONTEXT
=
Key
.
create
(
"BINDING_CONTEXT"
);
private
static
final
Object
lock
=
new
Object
();
public
static
BindingContext
analyzeNamespace
(
@NotNull
JetNamespace
namespace
,
@NotNull
JetControlFlowDataTraceFactory
flowDataTraceFactory
)
{
return
A
nalyzingUtils
.
getInstance
(
JavaDefaultImports
.
JAVA_DEFAULT_IMPORTS
)
.
analyzeNamespace
(
namespace
,
flowDataTraceFactory
);
return
A
NALYZING_UTILS
.
analyzeNamespace
(
namespace
,
flowDataTraceFactory
);
}
public
static
BindingContext
analyzeFileWithCache
(
@NotNull
JetFile
file
)
{
return
AnalyzingUtils
.
getInstance
(
JavaDefaultImports
.
JAVA_DEFAULT_IMPORTS
).
analyzeFileWithCache
(
file
);
public
static
BindingContext
analyzeFileWithCache
(
@NotNull
final
JetFile
file
)
{
return
analyzeFileWithCache
(
ANALYZING_UTILS
,
file
);
}
public
static
BindingContext
analyzeFileWithCache
(
@NotNull
final
AnalyzingUtils
analyzingUtils
,
@NotNull
final
JetFile
file
)
{
// TODO : Synchronization?
CachedValue
<
BindingContext
>
bindingContextCachedValue
=
file
.
getUserData
(
BINDING_CONTEXT
);
if
(
bindingContextCachedValue
==
null
)
{
bindingContextCachedValue
=
CachedValuesManager
.
getManager
(
file
.
getProject
()).
createCachedValue
(
new
CachedValueProvider
<
BindingContext
>()
{
@Override
public
Result
<
BindingContext
>
compute
()
{
synchronized
(
lock
)
{
final
Project
project
=
file
.
getProject
();
final
Set
<
JetDeclaration
>
namespaces
=
Sets
.
newLinkedHashSet
();
ProjectRootManager
rootManager
=
ProjectRootManager
.
getInstance
(
project
);
if
(
rootManager
!=
null
&&
!
ApplicationManager
.
getApplication
().
isUnitTestMode
())
{
VirtualFile
[]
contentRoots
=
rootManager
.
getContentRoots
();
CompilerPathsEx
.
visitFiles
(
contentRoots
,
new
CompilerPathsEx
.
FileVisitor
()
{
@Override
protected
void
acceptFile
(
VirtualFile
file
,
String
fileRoot
,
String
filePath
)
{
if
(!(
file
.
getName
().
endsWith
(
".kt"
)
||
file
.
getName
().
endsWith
(
".kts"
)))
return
;
PsiFile
psiFile
=
PsiManager
.
getInstance
(
project
).
findFile
(
file
);
if
(
psiFile
instanceof
JetFile
)
{
namespaces
.
add
(((
JetFile
)
psiFile
).
getRootNamespace
());
}
}
});
}
else
{
namespaces
.
add
(
file
.
getRootNamespace
());
}
try
{
BindingContext
bindingContext
=
analyzingUtils
.
analyzeNamespaces
(
project
,
namespaces
,
JetControlFlowDataTraceFactory
.
EMPTY
);
return
new
Result
<
BindingContext
>(
bindingContext
,
PsiModificationTracker
.
MODIFICATION_COUNT
);
}
catch
(
ProcessCanceledException
e
)
{
throw
e
;
}
catch
(
Throwable
e
)
{
e
.
printStackTrace
();
BindingTraceContext
bindingTraceContext
=
new
BindingTraceContext
();
bindingTraceContext
.
report
(
Errors
.
EXCEPTION_WHILE_ANALYZING
.
on
(
file
,
e
));
return
new
Result
<
BindingContext
>(
bindingTraceContext
.
getBindingContext
(),
PsiModificationTracker
.
MODIFICATION_COUNT
);
}
}
}
},
false
);
file
.
putUserData
(
BINDING_CONTEXT
,
bindingContextCachedValue
);
}
return
bindingContextCachedValue
.
getValue
();
}
}
compiler/frontend/src/org/jetbrains/jet/lang/resolve/AnalyzingUtils.java
浏览文件 @
fc01eb2d
package
org.jetbrains.jet.lang.resolve
;
import
com.google.common.collect.Lists
;
import
com.intellij.openapi.application.ApplicationManager
;
import
com.intellij.openapi.compiler.ex.CompilerPathsEx
;
import
com.intellij.openapi.progress.ProcessCanceledException
;
import
com.intellij.openapi.project.Project
;
import
com.intellij.openapi.roots.ProjectRootManager
;
import
com.intellij.openapi.util.Key
;
import
com.intellij.openapi.vfs.VirtualFile
;
import
com.intellij.psi.*
;
import
com.intellij.psi.util.CachedValue
;
import
com.intellij.psi.util.CachedValueProvider
;
import
com.intellij.psi.util.CachedValuesManager
;
import
com.intellij.psi.util.PsiModificationTracker
;
import
com.intellij.psi.PsiElement
;
import
com.intellij.psi.PsiElementVisitor
;
import
com.intellij.psi.PsiErrorElement
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.jet.lang.JetSemanticServices
;
import
org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory
;
...
...
@@ -20,27 +11,20 @@ import org.jetbrains.jet.lang.descriptors.*;
import
org.jetbrains.jet.lang.diagnostics.Diagnostic
;
import
org.jetbrains.jet.lang.diagnostics.DiagnosticHolder
;
import
org.jetbrains.jet.lang.diagnostics.DiagnosticUtils
;
import
org.jetbrains.jet.lang.diagnostics.Errors
;
import
org.jetbrains.jet.lang.psi.JetDeclaration
;
import
org.jetbrains.jet.lang.psi.JetFile
;
import
org.jetbrains.jet.lang.psi.JetNamespace
;
import
org.jetbrains.jet.lang.resolve.scopes.JetScope
;
import
org.jetbrains.jet.lang.resolve.scopes.WritableScope
;
import
org.jetbrains.jet.lang.resolve.scopes.WritableScopeImpl
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.List
;
//import org.jetbrains.jet.lang.resolve.java.JavaPackageScope;
//import org.jetbrains.jet.lang.resolve.java.JavaSemanticServices;
/**
* @author abreslav
*/
public
class
AnalyzingUtils
{
private
final
static
Key
<
CachedValue
<
BindingContext
>>
BINDING_CONTEXT
=
Key
.
create
(
"BINDING_CONTEXT"
);
private
static
final
Object
lock
=
new
Object
();
public
static
AnalyzingUtils
getInstance
(
@NotNull
ImportingStrategy
importingStrategy
)
{
return
new
AnalyzingUtils
(
importingStrategy
);
}
...
...
@@ -78,7 +62,7 @@ public class AnalyzingUtils {
return
analyzeNamespaces
(
project
,
declarations
,
flowDataTraceFactory
);
}
public
BindingContext
analyzeNamespaces
(
@NotNull
Project
project
,
@NotNull
List
<?
extends
JetDeclaration
>
declarations
,
@NotNull
JetControlFlowDataTraceFactory
flowDataTraceFactory
)
{
public
BindingContext
analyzeNamespaces
(
@NotNull
Project
project
,
@NotNull
Collection
<?
extends
JetDeclaration
>
declarations
,
@NotNull
JetControlFlowDataTraceFactory
flowDataTraceFactory
)
{
BindingTraceContext
bindingTraceContext
=
new
BindingTraceContext
();
JetSemanticServices
semanticServices
=
JetSemanticServices
.
createSemanticServices
(
project
);
...
...
@@ -121,54 +105,4 @@ public class AnalyzingUtils {
return
bindingTraceContext
.
getBindingContext
();
}
public
BindingContext
analyzeFileWithCache
(
@NotNull
final
JetFile
file
)
{
// TODO : Synchronization?
CachedValue
<
BindingContext
>
bindingContextCachedValue
=
file
.
getUserData
(
BINDING_CONTEXT
);
if
(
bindingContextCachedValue
==
null
)
{
bindingContextCachedValue
=
CachedValuesManager
.
getManager
(
file
.
getProject
()).
createCachedValue
(
new
CachedValueProvider
<
BindingContext
>()
{
@Override
public
Result
<
BindingContext
>
compute
()
{
synchronized
(
lock
)
{
final
Project
project
=
file
.
getProject
();
final
List
<
JetDeclaration
>
namespaces
=
Lists
.
newArrayList
();
ProjectRootManager
rootManager
=
ProjectRootManager
.
getInstance
(
project
);
if
(
rootManager
!=
null
&&
!
ApplicationManager
.
getApplication
().
isUnitTestMode
())
{
VirtualFile
[]
contentRoots
=
rootManager
.
getContentRoots
();
CompilerPathsEx
.
visitFiles
(
contentRoots
,
new
CompilerPathsEx
.
FileVisitor
()
{
@Override
protected
void
acceptFile
(
VirtualFile
file
,
String
fileRoot
,
String
filePath
)
{
if
(!(
file
.
getName
().
endsWith
(
".kt"
)
||
file
.
getName
().
endsWith
(
".kts"
)))
return
;
PsiFile
psiFile
=
PsiManager
.
getInstance
(
project
).
findFile
(
file
);
if
(
psiFile
instanceof
JetFile
)
{
namespaces
.
add
(((
JetFile
)
psiFile
).
getRootNamespace
());
}
}
});
}
else
{
namespaces
.
add
(
file
.
getRootNamespace
());
}
try
{
// JetNamespace rootNamespace = file.getRootNamespace();
BindingContext
bindingContext
=
analyzeNamespaces
(
project
,
namespaces
,
JetControlFlowDataTraceFactory
.
EMPTY
);
return
new
Result
<
BindingContext
>(
bindingContext
,
PsiModificationTracker
.
MODIFICATION_COUNT
);
}
catch
(
ProcessCanceledException
e
)
{
throw
e
;
}
catch
(
Throwable
e
)
{
e
.
printStackTrace
();
BindingTraceContext
bindingTraceContext
=
new
BindingTraceContext
();
// bindingTraceContext.getErrorHandler().genericError(file.getNode(), e.getClass().getSimpleName() + ": " + e.getMessage());
bindingTraceContext
.
report
(
Errors
.
EXCEPTION_WHILE_ANALYZING
.
on
(
file
,
e
));
return
new
Result
<
BindingContext
>(
bindingTraceContext
.
getBindingContext
(),
PsiModificationTracker
.
MODIFICATION_COUNT
);
}
}
}
},
false
);
file
.
putUserData
(
BINDING_CONTEXT
,
bindingContextCachedValue
);
}
return
bindingContextCachedValue
.
getValue
();
}
}
compiler/frontend/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java
浏览文件 @
fc01eb2d
...
...
@@ -4,12 +4,15 @@ import org.jetbrains.annotations.NotNull;
import
org.jetbrains.jet.lang.JetSemanticServices
;
import
org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory
;
import
org.jetbrains.jet.lang.descriptors.*
;
import
org.jetbrains.jet.lang.psi.*
;
import
org.jetbrains.jet.lang.psi.JetClassOrObject
;
import
org.jetbrains.jet.lang.psi.JetDeclaration
;
import
org.jetbrains.jet.lang.psi.JetNamespace
;
import
org.jetbrains.jet.lang.psi.JetObjectDeclaration
;
import
org.jetbrains.jet.lang.resolve.scopes.JetScope
;
import
org.jetbrains.jet.lang.resolve.scopes.WritableScope
;
import
java.util.Collection
;
import
java.util.Collections
;
import
java.util.List
;
/**
* @author abreslav
...
...
@@ -23,7 +26,7 @@ public class TopDownAnalyzer {
@NotNull
BindingTrace
trace
,
@NotNull
JetScope
outerScope
,
NamespaceLike
owner
,
@NotNull
List
<?
extends
JetDeclaration
>
declarations
,
@NotNull
Collection
<?
extends
JetDeclaration
>
declarations
,
@NotNull
JetControlFlowDataTraceFactory
flowDataTraceFactory
)
{
process
(
semanticServices
,
trace
,
outerScope
,
owner
,
declarations
,
flowDataTraceFactory
,
false
);
}
...
...
@@ -33,7 +36,7 @@ public class TopDownAnalyzer {
@NotNull
BindingTrace
trace
,
@NotNull
JetScope
outerScope
,
NamespaceLike
owner
,
@NotNull
List
<?
extends
JetDeclaration
>
declarations
,
@NotNull
Collection
<?
extends
JetDeclaration
>
declarations
,
@NotNull
JetControlFlowDataTraceFactory
flowDataTraceFactory
,
boolean
declaredLocally
)
{
TopDownAnalysisContext
context
=
new
TopDownAnalysisContext
(
semanticServices
,
trace
);
...
...
compiler/frontend/src/org/jetbrains/jet/lang/resolve/TypeHierarchyResolver.java
浏览文件 @
fc01eb2d
...
...
@@ -36,7 +36,7 @@ public class TypeHierarchyResolver {
this
.
context
=
context
;
}
public
void
process
(
@NotNull
JetScope
outerScope
,
NamespaceLike
owner
,
@NotNull
List
<?
extends
JetDeclaration
>
declarations
)
{
public
void
process
(
@NotNull
JetScope
outerScope
,
NamespaceLike
owner
,
@NotNull
Collection
<?
extends
JetDeclaration
>
declarations
)
{
collectNamespacesAndClassifiers
(
outerScope
,
owner
,
declarations
);
// namespaceScopes, classes
processTypeImports
();
...
...
compiler/tests/org/jetbrains/jet/checkers/CheckerTestUtilTest.java
浏览文件 @
fc01eb2d
...
...
@@ -8,6 +8,7 @@ import org.jetbrains.jet.lang.psi.JetFile;
import
org.jetbrains.jet.lang.resolve.AnalyzingUtils
;
import
org.jetbrains.jet.lang.resolve.BindingContext
;
import
org.jetbrains.jet.lang.resolve.ImportingStrategy
;
import
org.jetbrains.jet.lang.resolve.java.AnalyzerFacade
;
import
java.util.Collections
;
import
java.util.List
;
...
...
@@ -80,7 +81,7 @@ public class CheckerTestUtilTest extends JetLiteFixture {
}
public
void
test
(
PsiFile
psiFile
)
{
BindingContext
bindingContext
=
Analyz
ingUtils
.
getInstance
(
ImportingStrategy
.
NONE
).
analyzeFileWithCache
(
(
JetFile
)
psiFile
);
BindingContext
bindingContext
=
Analyz
erFacade
.
analyzeFileWithCache
(
AnalyzingUtils
.
getInstance
(
ImportingStrategy
.
NONE
),
(
JetFile
)
psiFile
);
String
expectedText
=
CheckerTestUtil
.
addDiagnosticMarkersToText
(
psiFile
,
bindingContext
).
toString
();
List
<
CheckerTestUtil
.
DiagnosedRange
>
diagnosedRanges
=
Lists
.
newArrayList
();
...
...
compiler/tests/org/jetbrains/jet/checkers/QuickJetPsiCheckerTest.java
浏览文件 @
fc01eb2d
...
...
@@ -12,6 +12,7 @@ import org.jetbrains.jet.lang.psi.JetFile;
import
org.jetbrains.jet.lang.resolve.AnalyzingUtils
;
import
org.jetbrains.jet.lang.resolve.BindingContext
;
import
org.jetbrains.jet.lang.resolve.ImportingStrategy
;
import
org.jetbrains.jet.lang.resolve.java.AnalyzerFacade
;
import
java.util.List
;
...
...
@@ -39,7 +40,7 @@ public class QuickJetPsiCheckerTest extends JetLiteFixture {
createAndCheckPsiFile
(
name
,
clearText
);
JetFile
jetFile
=
(
JetFile
)
myFile
;
BindingContext
bindingContext
=
Analyz
ingUtils
.
getInstance
(
ImportingStrategy
.
NONE
).
analyzeFileWithCache
(
jetFile
);
BindingContext
bindingContext
=
Analyz
erFacade
.
analyzeFileWithCache
(
AnalyzingUtils
.
getInstance
(
ImportingStrategy
.
NONE
),
jetFile
);
CheckerTestUtil
.
diagnosticsDiff
(
diagnosedRanges
,
bindingContext
.
getDiagnostics
(),
new
CheckerTestUtil
.
DiagnosticDiffCallbacks
()
{
@Override
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录