Check all files have same package
This commit is contained in:
@@ -52,13 +52,15 @@ public class NamespaceCodegen {
|
|||||||
private final Collection<JetFile> files;
|
private final Collection<JetFile> files;
|
||||||
private int nextMultiFile = 0;
|
private int nextMultiFile = 0;
|
||||||
|
|
||||||
public NamespaceCodegen(@NotNull ClassBuilderOnDemand v, @NotNull final FqName fqName, GenerationState state, Collection<JetFile> files) {
|
public NamespaceCodegen(@NotNull ClassBuilderOnDemand v, @NotNull final FqName fqName, GenerationState state, Collection<JetFile> namespaceFiles) {
|
||||||
|
checkAllFilesHaveSameNamespace(namespaceFiles);
|
||||||
|
|
||||||
this.v = v;
|
this.v = v;
|
||||||
name = fqName;
|
name = fqName;
|
||||||
this.state = state;
|
this.state = state;
|
||||||
this.files = files;
|
this.files = namespaceFiles;
|
||||||
|
|
||||||
final PsiFile sourceFile = files.iterator().next().getContainingFile();
|
final PsiFile sourceFile = namespaceFiles.iterator().next().getContainingFile();
|
||||||
|
|
||||||
v.addOptionalDeclaration(new ClassBuilderOnDemand.ClassBuilderCallback() {
|
v.addOptionalDeclaration(new ClassBuilderOnDemand.ClassBuilderCallback() {
|
||||||
@Override
|
@Override
|
||||||
@@ -195,8 +197,14 @@ public class NamespaceCodegen {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean shouldGenerateNSClass(Collection<JetFile> files) {
|
/**
|
||||||
for (JetFile file : files) {
|
* @param namespaceFiles all files should have same package name
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static boolean shouldGenerateNSClass(Collection<JetFile> namespaceFiles) {
|
||||||
|
checkAllFilesHaveSameNamespace(namespaceFiles);
|
||||||
|
|
||||||
|
for (JetFile file : namespaceFiles) {
|
||||||
for (JetDeclaration declaration : file.getDeclarations()) {
|
for (JetDeclaration declaration : file.getDeclarations()) {
|
||||||
if (declaration instanceof JetProperty || declaration instanceof JetNamedFunction) {
|
if (declaration instanceof JetProperty || declaration instanceof JetNamedFunction) {
|
||||||
return true;
|
return true;
|
||||||
@@ -207,6 +215,21 @@ public class NamespaceCodegen {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void checkAllFilesHaveSameNamespace(Collection<JetFile> namespaceFiles) {
|
||||||
|
FqName commonFqName = null;
|
||||||
|
for (JetFile file : namespaceFiles) {
|
||||||
|
FqName fqName = JetPsiUtil.getFQName(file);
|
||||||
|
if (commonFqName != null) {
|
||||||
|
if (!commonFqName.equals(fqName)) {
|
||||||
|
throw new IllegalArgumentException("All files should have same package name");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
commonFqName = JetPsiUtil.getFQName(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void generateStaticInitializers() {
|
private void generateStaticInitializers() {
|
||||||
final JetFile namespace = files.iterator().next(); // @todo: hack
|
final JetFile namespace = files.iterator().next(); // @todo: hack
|
||||||
|
|
||||||
|
|||||||
@@ -179,7 +179,7 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa
|
|||||||
|
|
||||||
final GenerationState state = new GenerationState(project, builderFactory, context, Collections.singletonList(file)) {
|
final GenerationState state = new GenerationState(project, builderFactory, context, Collections.singletonList(file)) {
|
||||||
@Override
|
@Override
|
||||||
protected void generateNamespace(FqName fqName, Collection<JetFile> namespace, CompilationErrorHandler errorHandler, Progress progress) {
|
protected void generateNamespace(FqName fqName, Collection<JetFile> namespaceFiles, CompilationErrorHandler errorHandler, Progress progress) {
|
||||||
PsiManager manager = PsiManager.getInstance(project);
|
PsiManager manager = PsiManager.getInstance(project);
|
||||||
stubStack.push(answer);
|
stubStack.push(answer);
|
||||||
|
|
||||||
@@ -196,7 +196,7 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa
|
|||||||
fakeFile.setPhysical(false);
|
fakeFile.setPhysical(false);
|
||||||
answer.setPsi(fakeFile);
|
answer.setPsi(fakeFile);
|
||||||
|
|
||||||
super.generateNamespace(fqName, namespace, errorHandler, progress);
|
super.generateNamespace(fqName, namespaceFiles, errorHandler, progress);
|
||||||
final StubElement pop = stubStack.pop();
|
final StubElement pop = stubStack.pop();
|
||||||
if (pop != answer) {
|
if (pop != answer) {
|
||||||
LOG.error("Unbalanced stack operations: " + pop);
|
LOG.error("Unbalanced stack operations: " + pop);
|
||||||
|
|||||||
Reference in New Issue
Block a user