Changeset 185

Show
Ignore:
Timestamp:
12/14/06 21:25:52 (2 years ago)
Author:
Alan Knowles
Message:

replace all dantfw direct access in CodeView? with wrapper code in Language

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/src/leds/CodeView.d

    r176 r185  
    5858import leds.LanguageMakefile;  
    5959import leds.LanguageJava;  
    60  
     60/* 
    6161import parser.Attributes;  
    6262import parser.Element;  
     
    6767import parser.CodeFormatter;  
    6868import parser.FormatD;  
    69      
     69*/ 
     70 
    7071import leds.SystemConsole; 
    7172import leds.FindAndReplace; 
     
    157158    WrapGtk wrapGtk; 
    158159     
    159     FormatD formatD; 
    160  
     160     
    161161    bit userAllowClose = false; 
    162162     
     
    247247     * @return  
    248248     */ 
    249     Attributes.Language getLanguage() 
    250     { 
    251         Attributes.Language l = Attributes.getLanguageFromFileName(getFileName()); 
    252         if ( l == Attributes.Language.NONE ) 
     249    Language.LangType getLanguage() 
     250    { 
     251        Language.LangType l = Language.getLanguageFromFileName(getFileName()); 
     252        if ( l == Language.LangType.NONE ) 
    253253        { 
    254254            l = getProjectLanguage(); 
     
    257257    } 
    258258     
    259     Attributes.Language getProjectLanguage() 
    260     { 
    261         Attributes.Language language = Attributes.Language.NONE; 
     259    Language.LangType getProjectLanguage() 
     260    { 
     261        Language.LangType language = Language.LangType.NONE; 
    262262        Project p = project; 
    263263        if ( p is null ) 
     
    274274    String getLanguageExt() 
    275275    { 
    276         Attributes.Language l = getLanguage(); 
     276        Language.LangType l = getLanguage(); 
    277277        //printf("CodeView.getLanguageExt l = %\n", l); 
    278278        //printf("CodeView.getLanguageExt parser.Attributes.getLanguageExtension(l) = %.*s\n", parseD.Attributes.getLanguageExtension(l)); 
    279         return Attributes.getLanguageExtension(l); 
     279        return Language.getLanguageExtension(l); 
    280280    } 
    281281     
     
    796796            modifiedTime = getFileMTime(fileName); 
    797797            codeEdit.setSavePoint(); 
    798             if ( project !is null && getLanguage() == Attributes.Language.D ) 
     798            if ( project !is null && getLanguage() == Language.LangType.D ) 
    799799            { 
    800800                project.setNeedsRecompile(true); 
     
    883883            return; 
    884884        } 
    885         auto thisModule = (cast(LanguageD)lang).getCachedModule(this); 
    886          
    887         if ( !thisModule ) 
    888         { 
    889             return; 
    890         } 
    891         String missing = getMissingReturn(thisModule); 
    892         System.writefln("Missing return on: ", missing); 
    893          
    894          
    895     } 
    896      
    897     String getMissingReturn(Element element) 
    898     { 
    899         String miss = new String(); 
    900          
    901         if ( cast(Function)element && element.getReturnType()!="void" ) 
    902         { 
    903             Function f = cast(Function)element; 
    904             String code = f.getBody(); 
    905             if ( code !is null && code.find("return") < 0 ) 
    906             { 
    907                 markError(element.getLineInCode(), new String("Missing return"), 0x00FFFF); 
    908                 miss ~= f.getName(); 
    909                 miss ~= " "; 
    910             } 
    911         } 
    912         if ( element.getElements() !is null ) 
    913         { 
    914             foreach ( Element child ; element.getElements() ) 
    915             { 
    916                 miss ~= getMissingReturn(child); 
    917             } 
    918         } 
    919          
    920         return miss; 
    921     } 
     885        String missing = lang.getMissingReturn(this); 
     886        if (missing) { 
     887            System.writefln("Missing return on: ", missing); 
     888        } 
     889          
     890         
     891         
     892    } 
     893     
     894      
    922895     
    923896      
     
    10921065    } 
    10931066 
    1094     /** 
    1095      * Gets the containeier and function for the line of the current buffer 
    1096      * @param container the container to be populated 
    1097      * @param funct the function to be populated 
    1098      * @param lineNumber the lineNumber 
    1099      * @return true if found the container and function 
    1100      */ 
    1101     bit findContainer(out Block container, out Function funct, in int lineNumber) 
    1102     { 
    1103         return findContainer( 
    1104                         codeEdit.getText(),  
    1105                         lineNumber,  
    1106                         Element.Attribute.NONE,  
    1107                         getLanguage(),  
    1108                         container,  
    1109                         funct); 
    1110     } 
    1111      
    1112     bit findContainer(  String text,  
    1113                         int lineNumber,  
    1114                         Element.Attribute attributes,  
    1115                         Attributes.Language language, 
    1116                         out Block container,  
    1117                         out Function funct) 
    1118     { 
    1119         debug(autoComments) System.writefln("CodeView.findContainer 1"); 
    1120         bit found = false; 
    1121         Module mod = new Module(new String(), text, attributes, language); 
    1122         container = cast(Block)mod.getContainerForLine(lineNumber); 
    1123         debug(autoComments) System.writefln("CodeView.findContainer 3"); 
    1124         if ( container !is null ) 
    1125         { 
    1126             debug(autoComments) System.writefln("CodeView.findContainer 4"); 
    1127             funct = container.getFunction(lineNumber); 
    1128             if ( funct !is null ) 
    1129             { 
    1130                 debug(autoComments) System.writefln("CodeView.findContainer 5"); 
    1131                 found = true; 
    1132             } 
    1133             else 
    1134             { 
    1135                 debug(autoComments) System.writefln("CodeView.findContainer 6"); 
    1136                 //codeEdit.insertText(insertPos, "What function?"); 
    1137             } 
    1138         } 
    1139         else 
    1140         { 
    1141             debug(autoComments) System.writefln("CodeView.findContainer 7"); 
    1142             //codeEdit.insertText(insertPos, "What container?"); 
    1143         } 
    1144         debug(autoComments) System.writefln("CodeView.findContainer exit found = ", found); 
    1145         return found; 
    1146     } 
     1067     
    11471068     
    11481069    /** 
     
    11701091            return commStr; 
    11711092        } 
     1093         
     1094         
    11721095        if ( codeEdit.getCurrLineText().strip().length == 0  
    11731096            && getCommStr().length > 0 
     
    12091132                    ++functionLine; 
    12101133                     
    1211                     Block container; 
    1212                     Function funct; 
    1213                     //Module mod = new Module("",codeEdit.getText(),Attribute.NONE,getLanguage()); 
    1214                     //Struct container = cast(Struct)mod.getContainerForLine(functionLine); 
    1215                     //if ( container !is null ) 
    1216                     debug(autoComments) System.writefln("CodeView.doAutoDocComments NOT emptyDocComments 1"); 
    1217  
    1218                     if ( findContainer(container, funct, functionLine) ) 
    1219                     { 
    1220                         debug(autoComments) System.writefln("CodeView.doAutoDocComments NOT emptyDocComments 2"); 
    1221                         insertPos = codeEdit.getLineEndPosition(currLine); 
    1222                         int count = 0; 
    1223                         foreach ( String par ; funct.getParametersList() ) 
    1224                         { 
    1225                             debug(autoComments) System.writefln("CodeView.doAutoDocComments NOT emptyDocComments 3"); 
    1226                             if ( Leds.leds.getPropValue("ddocComments", false) ) 
    1227                             { 
    1228                                 if ( count == 0 ) 
    1229                                 { 
    1230                                     codeEdit.insertText(insertPos,"\n"~commStr~" Params:"); 
    1231                                     doAutoIndent(++currLine); 
    1232                                     insertPos = codeEdit.getLineEndPosition(currLine); 
    1233                                 } 
    1234                                 codeEdit.insertText(insertPos,"\n"~commStr~"    \t" ~ par.toString() ~ " = \t"); 
    1235                                 doAutoIndent(++currLine); 
    1236                                 insertPos = codeEdit.getLineEndPosition(currLine); 
    1237                             } 
    1238                             else 
    1239                             { 
    1240                                 codeEdit.insertText(insertPos,"\n"~commStr~" @param " ~ par.toString() ~ " "); 
    1241                                 doAutoIndent(++currLine); 
    1242                                 insertPos = codeEdit.getLineEndPosition(currLine); 
    1243                             } 
    1244                             ++count; 
    1245                         } 
    1246                         String retType = funct.getReturnType(); 
    1247                         if ( retType !is null && retType.length>0 && retType!="void" ) 
    1248                         { 
    1249                             debug(autoComments) System.writefln("CodeView.doAutoDocComments NOT emptyDocComments 4"); 
    1250                             if ( Leds.leds.getPropValue("ddocComments", false) ) 
    1251                             { 
    1252                                 codeEdit.insertText(insertPos, "\n"~commStr~" Returns: "); 
    1253                                 doAutoIndent(++currLine); 
    1254                                 insertPos = codeEdit.getLineEndPosition(currLine); 
    1255                             } 
    1256                             else 
    1257                             { 
    1258                                 codeEdit.insertText(insertPos, "\n"~commStr~" @return "); 
    1259                                 doAutoIndent(++currLine); 
    1260                                 insertPos = codeEdit.getLineEndPosition(currLine); 
    1261                             } 
    1262                         } 
     1134                    if (this.getLanguageHandler()) { 
     1135                        this.getLanguageHandler().addAutoDocComments(this,functionLine, commStr ); 
     1136                         
     1137                         
    12631138                    } 
     1139                     
     1140                     
    12641141                } 
    12651142            } 
     
    18421719            codeEdit.setAnchor(codeEdit.getLength()); 
    18431720        } 
    1844         String replace = getFormatter().format(codeEdit.getSelected()); 
     1721         
     1722        if (!getLanguageHandler()) { 
     1723            return; 
     1724        } 
     1725        String replace = getLanguageHandler().format(codeEdit.getSelected()); 
    18451726        if ( replace.length > 0 ) 
    18461727        { 
    18471728            codeEdit.replaceSel(replace); 
    18481729        } 
     1730         
     1731         
    18491732    } 
    18501733     
     
    18841767    void extractInterface(MenuItem item) 
    18851768    { 
    1886         Module sourceModule = new Module(new String(),getText(), Element.Attribute.NONE, Attributes.Language.D); 
    1887         String iText = new String(); 
    1888         iText ~= sourceModule.getInterfaceForm(); 
    1889          
    1890         foreach ( Class clss ; sourceModule.getClasses() ) 
    1891         { 
    1892              
    1893             iText ~= "public interface "; 
    1894             iText ~= clss.getName()~ "IF\n{\n"; 
    1895             foreach(int count, Function element ; clss.getFunctions() ) 
    1896             { 
    1897                 if ( element.getName() != "this" ) 
    1898                 { 
    1899                     iText ~= element.getInterfaceForm().dup.prepend("\n"); 
    1900                 } 
    1901             } 
    1902      
    1903             iText ~= "\n}\n"; 
    1904              
    1905         } 
    1906          
     1769         
     1770        if (!getLanguageHandler()) { 
     1771            return; 
     1772        } 
     1773        String iText = getLanguageHandler().extractInterface(this); 
     1774        if (!iText.length) { 
     1775            return; 
     1776        } 
    19071777        workspace.openBuffer(iText); 
    1908     } 
    1909      
    1910     /** 
    1911      * Gets this codeView instance formatD object 
    1912      * @return the formatD for this codeView 
    1913      */ 
    1914     CodeFormatter getFormatter() 
    1915     { 
    1916         if ( formatD is null ) 
    1917         { 
    1918             formatD = new FormatD(); 
    1919         } 
    1920         return formatD; 
    1921     } 
     1778          
     1779    } 
     1780     
     1781     
    19221782     
    19231783    void removeUnderscore(MenuItem item) 
     
    20121872    { 
    20131873        String packageToken = new String("module"); 
    2014         Attributes.Language language = getProjectLanguage(); 
     1874        Language.LangType language = getProjectLanguage(); 
    20151875        switch ( language ) 
    20161876        { 
    2017             case Attributes.Language.JAVA: 
     1877            case Language.LangType.JAVA: 
    20181878                packageToken.set("package"); 
    20191879                break; 
     
    20561916            modulePath.length = modulePath.length - 1; 
    20571917        } 
    2058         if ( language == Attributes.Language.JAVA ) 
    2059         { 
    2060             // need to add the class name 
    2061             Module mod = new Module(new String(), codeEdit.getText(), Element.Attribute.PUBLIC, language); 
    2062             foreach ( Class element ; mod.getClasses() ) 
    2063             { 
    2064                 if ( element.getAttributes() & Element.Attribute.PUBLIC ) 
    2065                 { 
    2066                     modulePath ~= element.getName().prepend("."); 
    2067                     break; 
    2068                 } 
    2069             } 
     1918        if ( ( language == Language.LangType.JAVA ) && getLanguageHandler()) { 
     1919             
     1920            modulePath ~= getLanguageHandler().getModulePath(this); 
     1921              
    20701922        } 
    20711923        return modulePath; 
     
    22012053        if (stringPrint.length() > 0 ) 
    22022054        { 
    2203             Block container; 
    2204             Function funct; 
     2055            String containerFunc = new String(); 
     2056            if (getLanguageHandler()) { 
     2057                containerFunc = getLanguageHandler().getContainerFunc(this,codeEdit.getCurrLine()); 
     2058            } 
     2059             
     2060             
     2061             
     2062              
    22052063            codeEdit.setCurrentPos(pos-1); 
    22062064            int offsetPos = 0; 
    22072065            String replace = new String(); 
    2208             if ( findContainer(container, funct, codeEdit.getCurrLine())
    2209             { 
    2210                 replace.set("writefln(\"" ~ container.getName().toString() ~"."~ funct.getName.toString()); 
     2066            if ( containerFunc.length
     2067            { 
     2068                replace.set("writefln(\"" ~ containerFunc.toString() ); 
    22112069            } 
    22122070            else 
     
    24052263            return; 
    24062264        } 
     2265        if (codeEdit.isAutoCompletionActive()) { 
     2266            return; 
     2267        } 
    24072268        if (!this.getLanguageHandler()) { 
    24082269            return; 
     
    26562517        codeEdit.setCurrentPos(lineStart); 
    26572518        codeEdit.setAnchor(end+2); 
    2658         String replace = getFormatter().formatComment(codeEdit.getSelected(), maxLine, false); 
     2519        if (!getLanguageHandler())  
     2520        { 
     2521            return formatted; 
     2522        } 
     2523        String replace = getLanguageHandler().formatComment(codeEdit.getSelected(), maxLine, false); 
    26592524        if ( replace !is null && replace.length > 0 ) 
    26602525        {