JetNamespace eliminated
This commit is contained in:
@@ -19,7 +19,7 @@ public class JetIconProvider extends IconProvider {
|
||||
|
||||
@Override
|
||||
public Icon getIcon(@NotNull PsiElement psiElement, int flags) {
|
||||
if (psiElement instanceof JetNamespace) {
|
||||
if (psiElement instanceof JetNamespaceHeader) {
|
||||
return (flags & Iconable.ICON_FLAG_OPEN) != 0 ? PlatformIcons.PACKAGE_OPEN_ICON : PlatformIcons.PACKAGE_ICON;
|
||||
}
|
||||
if (psiElement instanceof JetNamedFunction) {
|
||||
|
||||
@@ -13,7 +13,6 @@ import com.intellij.openapi.ui.popup.JBPopupFactory;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.openapi.util.Iconable;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.psi.util.PsiUtilBase;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import com.intellij.util.Function;
|
||||
@@ -42,9 +41,9 @@ public class JetLineMarkerProvider implements LineMarkerProvider {
|
||||
|
||||
@Override
|
||||
public LineMarkerInfo getLineMarkerInfo(PsiElement element) {
|
||||
JetFile file = PsiTreeUtil.getParentOfType(element, JetFile.class);
|
||||
|
||||
JetFile file = (JetFile) element.getContainingFile();
|
||||
if (file == null) return null;
|
||||
|
||||
final BindingContext bindingContext = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(file);
|
||||
|
||||
if (element instanceof JetClass) {
|
||||
@@ -132,11 +131,11 @@ public class JetLineMarkerProvider implements LineMarkerProvider {
|
||||
);
|
||||
}
|
||||
|
||||
if (element instanceof JetNamespace) {
|
||||
JetNamespace namespace = (JetNamespace) element;
|
||||
if (namespace.getNameIdentifier() != null) {
|
||||
return createLineMarkerInfo(namespace,
|
||||
DescriptorRenderer.HTML.render(bindingContext.get(BindingContext.NAMESPACE, element)));
|
||||
if (element instanceof JetNamespaceHeader) {
|
||||
JetNamespaceHeader header = (JetNamespaceHeader) element;
|
||||
if (header.getNameIdentifier() != null) {
|
||||
return createLineMarkerInfo(header,
|
||||
DescriptorRenderer.HTML.render(bindingContext.get(BindingContext.NAMESPACE, file)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@ import org.jetbrains.jet.codegen.*;
|
||||
import org.jetbrains.jet.lang.cfg.pseudocode.JetControlFlowDataTraceFactory;
|
||||
import org.jetbrains.jet.lang.diagnostics.Diagnostic;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade;
|
||||
import org.jetbrains.jet.plugin.JetFileType;
|
||||
@@ -68,16 +67,16 @@ public class JetCompiler implements TranslatingCompiler {
|
||||
VirtualFile[] allFiles = compileContext.getCompileScope().getFiles(null, true);
|
||||
|
||||
GenerationState generationState = new GenerationState(compileContext.getProject(), ClassBuilderFactory.BINARIES);
|
||||
List<JetNamespace> namespaces = Lists.newArrayList();
|
||||
List<JetFile> files = Lists.newArrayList();
|
||||
for (VirtualFile virtualFile : allFiles) {
|
||||
PsiFile psiFile = PsiManager.getInstance(compileContext.getProject()).findFile(virtualFile);
|
||||
if (psiFile instanceof JetFile) {
|
||||
namespaces.add(((JetFile) psiFile).getRootNamespace());
|
||||
files.add(((JetFile) psiFile));
|
||||
}
|
||||
}
|
||||
|
||||
BindingContext bindingContext =
|
||||
AnalyzerFacade.analyzeNamespacesWithJavaIntegration(compileContext.getProject(), namespaces, Predicates.<PsiFile>alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY);
|
||||
AnalyzerFacade.analyzeFilesWithJavaIntegration(compileContext.getProject(), files, Predicates.<PsiFile>alwaysTrue(), JetControlFlowDataTraceFactory.EMPTY);
|
||||
|
||||
boolean errors = false;
|
||||
for (Diagnostic diagnostic : bindingContext.getDiagnostics()) {
|
||||
@@ -96,10 +95,10 @@ public class JetCompiler implements TranslatingCompiler {
|
||||
}
|
||||
|
||||
if (!errors) {
|
||||
generationState.compileCorrectNamespaces(bindingContext, namespaces, new CompilationErrorHandler() {
|
||||
generationState.compileCorrectFiles(bindingContext, files, new CompilationErrorHandler() {
|
||||
@Override
|
||||
public void reportException(Throwable exception, String fileUrl) {
|
||||
if(exception instanceof CompilationException) {
|
||||
if (exception instanceof CompilationException) {
|
||||
report((CompilationException) exception, compileContext);
|
||||
}
|
||||
else {
|
||||
@@ -109,7 +108,7 @@ public class JetCompiler implements TranslatingCompiler {
|
||||
});
|
||||
///////////
|
||||
// GenerationState generationState2 = new GenerationState(compileContext.getProject(), ClassBuilderFactory.TEXT);
|
||||
// generationState2.compileCorrectNamespaces(bindingContext, namespaces);
|
||||
// generationState2.compileCorrectFiles(bindingContext, namespaces);
|
||||
// StringBuilder answer = new StringBuilder();
|
||||
//
|
||||
// final ClassFileFactory factory2 = generationState2.getFactory();
|
||||
@@ -123,8 +122,8 @@ public class JetCompiler implements TranslatingCompiler {
|
||||
|
||||
|
||||
final ClassFileFactory factory = generationState.getFactory();
|
||||
List<String> files = factory.files();
|
||||
for (String file : files) {
|
||||
List<String> filesNames = factory.files();
|
||||
for (String file : filesNames) {
|
||||
File target = new File(outputDir.getPath(), file);
|
||||
try {
|
||||
FileUtil.writeToFile(target, factory.asBytes(file));
|
||||
|
||||
@@ -11,7 +11,6 @@ import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade;
|
||||
@@ -31,13 +30,12 @@ public final class WholeProjectAnalyzerFacade {
|
||||
/**
|
||||
* Will collect all root-namespaces in all kotlin files in the project.
|
||||
*/
|
||||
public static final Function<JetFile, Collection<JetDeclaration>> WHOLE_PROJECT_DECLARATION_PROVIDER =
|
||||
new Function<JetFile, Collection<JetDeclaration>>() {
|
||||
public static final Function<JetFile, Collection<JetFile>> WHOLE_PROJECT_DECLARATION_PROVIDER = new Function<JetFile, Collection<JetFile>>() {
|
||||
|
||||
@Override
|
||||
public Collection<JetDeclaration> fun(final JetFile rootFile) {
|
||||
public Collection<JetFile> fun(final JetFile rootFile) {
|
||||
final Project project = rootFile.getProject();
|
||||
final Set<JetDeclaration> namespaces = Sets.newLinkedHashSet();
|
||||
final Set<JetFile> files = Sets.newLinkedHashSet();
|
||||
final ProjectRootManager rootManager = ProjectRootManager.getInstance(project);
|
||||
|
||||
if (rootManager != null /* && !ApplicationManager.getApplication().isUnitTestMode() */) {
|
||||
@@ -51,15 +49,15 @@ public final class WholeProjectAnalyzerFacade {
|
||||
PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
|
||||
if (psiFile instanceof JetFile) {
|
||||
if (rootFile.getOriginalFile() != psiFile) {
|
||||
namespaces.add(((JetFile) psiFile).getRootNamespace());
|
||||
files.add((JetFile) psiFile);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
namespaces.add(rootFile.getRootNamespace());
|
||||
return namespaces;
|
||||
files.add(rootFile);
|
||||
return files;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -110,12 +110,12 @@ public class JetPositionManager implements PositionManager {
|
||||
names.addAll(typeMapper.allJvmNames(jetClass));
|
||||
}
|
||||
else {
|
||||
JetNamespace namespace = PsiTreeUtil.getParentOfType(sourcePosition.getElementAt(), JetNamespace.class);
|
||||
JetFile namespace = PsiTreeUtil.getParentOfType(sourcePosition.getElementAt(), JetFile.class);
|
||||
if (namespace != null) {
|
||||
names.add(NamespaceCodegen.getJVMClassName(JetPsiUtil.getFQName(namespace)));
|
||||
}
|
||||
else {
|
||||
names.add(NamespaceCodegen.getJVMClassName(JetPsiUtil.getFQName(file.getRootNamespace())));
|
||||
names.add(NamespaceCodegen.getJVMClassName(JetPsiUtil.getFQName(file)));
|
||||
}
|
||||
}
|
||||
return names;
|
||||
|
||||
@@ -182,7 +182,7 @@ public class BytecodeToolwindow extends JPanel {
|
||||
try {
|
||||
BindingContext binding = WholeProjectAnalyzerFacade.analyzeProjectWithCacheOnAFile(file);
|
||||
AnalyzingUtils.throwExceptionOnErrors(binding);
|
||||
state.compileCorrectNamespaces(binding, Collections.singletonList(file.getRootNamespace()));
|
||||
state.compileCorrectFiles(binding, Collections.singletonList(file));
|
||||
} catch (Exception e) {
|
||||
StringWriter out = new StringWriter(1024);
|
||||
e.printStackTrace(new PrintWriter(out));
|
||||
|
||||
@@ -70,14 +70,13 @@ public class JavaElementFinder extends PsiElementFinder {
|
||||
List<PsiClass> answer = new SmartList<PsiClass>();
|
||||
final List<JetFile> filesInScope = collectProjectJetFiles(project, scope);
|
||||
for (JetFile file : filesInScope) {
|
||||
JetNamespace rootNamespace = file.getRootNamespace();
|
||||
final String packageName = JetPsiUtil.getFQName(rootNamespace);
|
||||
final String packageName = JetPsiUtil.getFQName(file);
|
||||
if (packageName != null && qualifiedName.startsWith(packageName)) {
|
||||
if (qualifiedName.equals(fqn(packageName, "namespace"))) {
|
||||
answer.add(new JetLightClass(psiManager, file, qualifiedName));
|
||||
}
|
||||
else {
|
||||
for (JetDeclaration declaration : rootNamespace.getDeclarations()) {
|
||||
for (JetDeclaration declaration : file.getDeclarations()) {
|
||||
scanClasses(answer, declaration, qualifiedName, packageName, file);
|
||||
}
|
||||
}
|
||||
@@ -122,10 +121,9 @@ public class JavaElementFinder extends PsiElementFinder {
|
||||
|
||||
String packageFQN = psiPackage.getQualifiedName();
|
||||
for (JetFile psiFile : collectProjectJetFiles(project, GlobalSearchScope.allScope(project))) {
|
||||
final JetNamespace rootNamespace = psiFile.getRootNamespace();
|
||||
if (packageFQN.equals(JetPsiUtil.getFQName(rootNamespace))) {
|
||||
if (packageFQN.equals(JetPsiUtil.getFQName(psiFile))) {
|
||||
answer.add("namespace");
|
||||
for (JetDeclaration declaration : rootNamespace.getDeclarations()) {
|
||||
for (JetDeclaration declaration : psiFile.getDeclarations()) {
|
||||
if (declaration instanceof JetClassOrObject) {
|
||||
answer.add(getLocalName(declaration));
|
||||
}
|
||||
@@ -146,7 +144,7 @@ public class JavaElementFinder extends PsiElementFinder {
|
||||
final List<JetFile> psiFiles = collectProjectJetFiles(project, GlobalSearchScope.allScope(project));
|
||||
|
||||
for (JetFile psiFile : psiFiles) {
|
||||
if (qualifiedName.equals(JetPsiUtil.getFQName(psiFile.getRootNamespace()))) {
|
||||
if (qualifiedName.equals(JetPsiUtil.getFQName(psiFile))) {
|
||||
return new PsiPackageImpl(psiFile.getManager(), qualifiedName);
|
||||
}
|
||||
}
|
||||
@@ -161,10 +159,9 @@ public class JavaElementFinder extends PsiElementFinder {
|
||||
final List<JetFile> filesInScope = collectProjectJetFiles(project, scope);
|
||||
String packageFQN = psiPackage.getQualifiedName();
|
||||
for (JetFile file : filesInScope) {
|
||||
final JetNamespace rootNamespace = file.getRootNamespace();
|
||||
if (packageFQN.equals(JetPsiUtil.getFQName(rootNamespace))) {
|
||||
if (packageFQN.equals(JetPsiUtil.getFQName(file))) {
|
||||
answer.add(new JetLightClass(psiManager, file, fqn(packageFQN, "namespace")));
|
||||
for (JetDeclaration declaration : rootNamespace.getDeclarations()) {
|
||||
for (JetDeclaration declaration : file.getDeclarations()) {
|
||||
if (declaration instanceof JetClassOrObject) {
|
||||
answer.add(new JetLightClass(psiManager, file, fqn(packageFQN, getLocalName(declaration))));
|
||||
}
|
||||
|
||||
@@ -26,7 +26,6 @@ import org.jetbrains.jet.codegen.ClassBuilder;
|
||||
import org.jetbrains.jet.codegen.ClassBuilderFactory;
|
||||
import org.jetbrains.jet.codegen.GenerationState;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.lang.resolve.BindingContext;
|
||||
import org.jetbrains.jet.lang.resolve.java.AnalyzerFacade;
|
||||
@@ -111,7 +110,7 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa
|
||||
}
|
||||
|
||||
private PsiJavaFileStub calcStub() {
|
||||
final PsiJavaFileStubImpl answer = new PsiJavaFileStubImpl(JetPsiUtil.getFQName(file.getRootNamespace()), true);
|
||||
final PsiJavaFileStubImpl answer = new PsiJavaFileStubImpl(JetPsiUtil.getFQName(file), true);
|
||||
final Project project = getProject();
|
||||
|
||||
final Stack<StubElement> stubStack = new Stack<StubElement>();
|
||||
@@ -135,7 +134,7 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa
|
||||
|
||||
final GenerationState state = new GenerationState(project, builderFactory) {
|
||||
@Override
|
||||
protected void generateNamespace(JetNamespace namespace) {
|
||||
protected void generateNamespace(JetFile namespace) {
|
||||
PsiManager manager = PsiManager.getInstance(project);
|
||||
stubStack.push(answer);
|
||||
|
||||
@@ -164,9 +163,9 @@ public class JetLightClass extends AbstractLightClass implements JetJavaMirrorMa
|
||||
};
|
||||
|
||||
|
||||
List<PsiFile> files = Collections.<PsiFile>singletonList(file);
|
||||
List<JetFile> files = Collections.singletonList(file);
|
||||
final BindingContext context = AnalyzerFacade.shallowAnalyzeFiles(files);
|
||||
state.compileCorrectNamespaces(context, AnalyzerFacade.collectRootNamespaces(files));
|
||||
state.compileCorrectFiles(context, files);
|
||||
state.getFactory().files();
|
||||
|
||||
return answer;
|
||||
|
||||
@@ -5,7 +5,7 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.jet.lang.psi.JetDeclaration;
|
||||
import org.jetbrains.jet.lang.psi.JetImportDirective;
|
||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiFactory;
|
||||
import org.jetbrains.jet.lang.types.ErrorUtils;
|
||||
import org.jetbrains.jet.lang.types.JetType;
|
||||
@@ -25,7 +25,7 @@ public class ImportClassHelper {
|
||||
perform(JetPluginUtil.computeTypeFullName(type), elementToReplace, newElement);
|
||||
}
|
||||
|
||||
public static void perform(@NotNull String typeFullName, @NotNull JetNamespace namespace) {
|
||||
public static void perform(@NotNull String typeFullName, @NotNull JetFile namespace) {
|
||||
perform(typeFullName, namespace, null, null);
|
||||
}
|
||||
|
||||
@@ -35,14 +35,14 @@ public class ImportClassHelper {
|
||||
* @param element Some element in the tree.
|
||||
* @return A namespace element in the tree.
|
||||
*/
|
||||
public static JetNamespace findOuterNamespace(@NotNull PsiElement element) {
|
||||
public static JetFile findOuterNamespace(@NotNull PsiElement element) {
|
||||
PsiElement parent = element;
|
||||
while (!(parent instanceof JetNamespace)) {
|
||||
while (!(parent instanceof JetFile)) {
|
||||
parent = parent.getParent();
|
||||
assert parent != null;
|
||||
}
|
||||
|
||||
return (JetNamespace) parent;
|
||||
return (JetFile) parent;
|
||||
}
|
||||
|
||||
public static void perform(@NotNull String typeFullName, @NotNull PsiElement elementToReplace, @NotNull PsiElement newElement) {
|
||||
@@ -55,7 +55,7 @@ public class ImportClassHelper {
|
||||
* @param importString full name of the import. Can contain .* if necessary.
|
||||
* @param namespace Namespace where directive should be added.
|
||||
*/
|
||||
public static void addImportDirective(@NotNull String importString, @NotNull JetNamespace namespace) {
|
||||
public static void addImportDirective(@NotNull String importString, @NotNull JetFile namespace) {
|
||||
List<JetImportDirective> importDirectives = namespace.getImportDirectives();
|
||||
|
||||
JetImportDirective newDirective = JetPsiFactory.createImportDirective(namespace.getProject(), importString);
|
||||
@@ -83,7 +83,7 @@ public class ImportClassHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public static void perform(@NotNull String typeFullName, @NotNull JetNamespace namespace, @Nullable PsiElement elementToReplace, @Nullable PsiElement newElement) {
|
||||
public static void perform(@NotNull String typeFullName, @NotNull JetFile namespace, @Nullable PsiElement elementToReplace, @Nullable PsiElement newElement) {
|
||||
addImportDirective(typeFullName, namespace);
|
||||
|
||||
if (elementToReplace != null && newElement != null && elementToReplace != newElement) {
|
||||
|
||||
@@ -10,7 +10,6 @@ import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import org.jetbrains.jet.lang.psi.JetClass;
|
||||
import org.jetbrains.jet.lang.psi.JetFile;
|
||||
import org.jetbrains.jet.lang.psi.JetNamespace;
|
||||
import org.jetbrains.jet.lang.psi.JetPsiUtil;
|
||||
import org.jetbrains.jet.plugin.JetMainDetector;
|
||||
|
||||
@@ -38,10 +37,10 @@ public class JetRunConfigurationProducer extends RuntimeConfigurationProducer im
|
||||
}
|
||||
PsiFile psiFile = location.getPsiElement().getContainingFile();
|
||||
if (psiFile instanceof JetFile) {
|
||||
JetNamespace namespace = ((JetFile) psiFile).getRootNamespace();
|
||||
if (JetMainDetector.hasMain(namespace.getDeclarations())) {
|
||||
mySourceElement = namespace;
|
||||
String fqName = JetPsiUtil.getFQName(namespace);
|
||||
JetFile jetFile = (JetFile) psiFile;
|
||||
if (JetMainDetector.hasMain(jetFile.getDeclarations())) {
|
||||
mySourceElement = jetFile;
|
||||
String fqName = JetPsiUtil.getFQName(jetFile);
|
||||
String className = fqName.length() == 0 ? "namespace" : fqName + ".namespace";
|
||||
return createConfigurationByQName(location.getModule(), configurationContext, className);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,6 @@ package org.jetbrains.jet.plugin.structureView;
|
||||
import com.intellij.ide.structureView.StructureViewTreeElement;
|
||||
import com.intellij.ide.util.treeView.smartTree.TreeElement;
|
||||
import com.intellij.navigation.ItemPresentation;
|
||||
import com.intellij.openapi.editor.colors.TextAttributesKey;
|
||||
import com.intellij.openapi.util.Iconable;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.psi.NavigatablePsiElement;
|
||||
@@ -75,11 +74,10 @@ public class JetStructureViewElement implements StructureViewTreeElement {
|
||||
@Override
|
||||
public TreeElement[] getChildren() {
|
||||
if (myElement instanceof JetFile) {
|
||||
JetNamespace rootNamespace = ((JetFile) myElement).getRootNamespace();
|
||||
return new TreeElement[] { new JetStructureViewElement((rootNamespace)) };
|
||||
return new TreeElement[] { new JetStructureViewElement(myElement) };
|
||||
}
|
||||
else if (myElement instanceof JetNamespace) {
|
||||
return wrapDeclarations(((JetNamespace) myElement).getDeclarations());
|
||||
else if (myElement instanceof JetFile) {
|
||||
return wrapDeclarations(((JetFile) myElement).getDeclarations());
|
||||
}
|
||||
else if (myElement instanceof JetClass) {
|
||||
JetClass jetClass = (JetClass) myElement;
|
||||
|
||||
Reference in New Issue
Block a user