package com.reason.lang.core.psi.impl;

import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFileFactory;
import com.reason.ide.files.RmlFile;
import com.reason.ide.files.RmlFileType;
import com.reason.lang.RmlLanguage;
import com.reason.lang.core.psi.PsiType;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;

class RmlElementFactory {
    private RmlElementFactory() {
    }

    static PsiElement createModuleName(Project project, String name) {
        RmlFile dummyFile = createFileFromText(project, "module " + name + " = {};");
        return dummyFile.asModule().getModules().iterator().next().getNameIdentifier();
    }

    public static PsiElement createTypeName(Project project, String name) {
        RmlFile dummyFile = createFileFromText(project, "type " + name + ";");
        return ((PsiType) dummyFile.getFirstChild()).getNameIdentifier();
    }

    @NotNull
    private static RmlFile createFileFromText(@NotNull Project project, @NotNull String text) {
        @NonNls String filename = "dummy." + RmlFileType.INSTANCE.getDefaultExtension();
        return (RmlFile) PsiFileFactory.getInstance(project).createFileFromText(filename, RmlLanguage.INSTANCE, text);
    }
}

@@ -182,22 +182,23 @@
 e.files.
-Rml
 Fil
+eBas
 e;%0Aimpor
@@ -214,28 +214,23 @@
 son.
-ide.files.RmlFileTyp
+lang.RmlLanguag
 e;%0Ai
@@ -247,34 +247,41 @@
 reason.lang.
-RmlLanguag
+core.psi.PsiModul
 e;%0Aimport co
@@ -347,20 +347,21 @@
 tions.No
-nNls
+tNull
 ;%0Aimport
@@ -388,22 +388,23 @@
 ations.N
-otN
 ull
+able
 ;%0A%0Aclass
@@ -461,24 +461,38 @@
 () %7B%0A    %7D%0A%0A
+    @Nullable%0A
     static P
@@ -554,37 +554,39 @@
 ) %7B%0A        
-RmlFi
+PsiModu
 le dummy
 File = creat
@@ -565,34 +565,36 @@
  PsiModule dummy
-Fi
+Modu
 le = createFileF
@@ -638,18 +638,68 @@
  = %7B%7D;%22)
-;%0A
+.asModule();%0A        if (dummyModule != null) %7B%0A    
         
@@ -714,23 +714,14 @@
 ummy
-File.as
 Module
-()
 .get
@@ -777,21 +777,45 @@
     
-%7D%0A%0A    public
+    %7D%0A        return null;%0A    %7D%0A%0A   
  sta
@@ -884,22 +884,23 @@
         
-Rml
 Fil
+eBas
 e dummyF
@@ -1069,22 +1069,23 @@
  static 
-Rml
 Fil
+eBas
 e create
@@ -1151,97 +1151,8 @@
 ) %7B%0A
-        @NonNls String filename = %22dummy.%22 + RmlFileType.INSTANCE.getDefaultExtension();%0A
     
@@ -1167,14 +1167,15 @@
 rn (
-Rml
 Fil
+eBas
 e) P
@@ -1232,16 +1232,18 @@
 ext(
-filename
+%22Dummy.re%22
 , Rm

fix problems