Exemplo n.º 1
0
        /**
        * create new file, under the name untitled or a followup
        * untitled2, untitled3 etc etc
        */
        public void newFile(boolean template) {
                // get the openfile handler to add the new file
                OpenFileHandler ofh=(OpenFileHandler)getJPE().getHandler("Opened");        
                if (ofh==null) {
                        // no opened handler started so lets start one and add it the
                        // menu.
                        ofh=(OpenFileHandler)getJPE().addHandler(new OpenFileHandler(getJPE()));
                        ofh.createMenu(getJPE().getMenuBar());
                }


                // find a empty untitled filename
                String prefix="untitled";
                String filename=prefix;
                int i=2;
                // repeat until we found one        
                while (ofh.isLoaded(filename)) {
                        filename=prefix+(i++);        
                }

                // open a file with the found name
                OpenFile file=new OpenFile(filename);
                if(template) {
                        // open a dialog to let the user select the file we need to load        
                        String tempfilename = getFileName(FileDialog.LOAD);
                        OpenFile tempfile = new OpenFile(tempfilename);
                        String txt = tempfile.getText();
                        try {
                                RE re = new RE("<getJPE():date>");
                                txt = re.substitute(txt,""+new Date());
                                file.setText(txt);
                        } catch(REException ree) {
                                ree.printStackTrace();
                        }
                }

                // add the file to the opened file list
                ofh.addFile(file);

                // load this file into the text area
                getJPE().getEditor().useFile(file);
        }
Exemplo n.º 2
0
 public void run() {
   ArrayList tags = new ArrayList();
   Line line = buffer.getFirstLine();
   while (line != null) {
     String s = line.trim();
     if (s != null && s.startsWith("function")) {
       REMatch match = functionRE.getMatch(s);
       if (match != null) {
         String token = s.substring(match.getSubStartIndex(1), match.getSubEndIndex(1));
         tags.add(new LocalTag(token, line));
       }
     }
     line = line.next();
   }
   buffer.setTags(tags);
 }
Exemplo n.º 3
0
        public void parseSource(Reader reader) {
                imports.addElement("java.lang.*");
                try {
                        BufferedReader bir = new BufferedReader(reader);
                        String line;
                        REMatch match;
                        boolean inComment = false;
                        Vector localClassNames = new Vector();
                        int count = 0;
                        
                        while( (line = bir.readLine()) != null) {
                                count++;
                                if(line.startsWith("package ")) {
                                        pckge = line.substring(8,line.length()-1);
                                        imports.addElement(pckge+".*");
                                }
                                if(line.startsWith("import ")) {
                                        imports.addElement(line.substring(7,line.length()-1));
                                        this.importLine = count;
                                }
                                if(line.indexOf("class ") != -1) {  // improve
                                                match = classRe.getMatch(line);
                                                if(match != null) {
                                                        int st = match.getSubStartIndex(1);
                                                        int end = match.getSubEndIndex(1);
                                                        if(st != -1 && end != -1) {
                                                            localClassNames.addElement(line.substring(st,end));
                                                    }
                                        }
                                        break;
                                }
                        }

                        while( (line = bir.readLine()) != null) {
                          // if in comment, see if time to come out of it
                                if(inComment) {
                                        if(line.indexOf("*/") != -1) {
                                                inComment = false;
                                                line = cPlusEndCommentRe.substitute(line,"");                                                
                                        } else {
                                                continue;
                                        }
                                }
                          // remove any literal Strings????
                            // s/"[^"]*"//g
                            line = stringLitRe.substitute(line,"");
                          // remove any commented out bits
                                // s/\/\*[^\/\*]\*\///
                            line = cPlusCommentRe.substitute(line,"");
                          // also handle being in a comment section
                                // then handle multi-line         \* ... *\. turn on a 'incomment' flag.
                                if(line.indexOf("/*") != -1) {
                                        inComment = true;
                                        line = cPlusStartCommentRe.substitute(line,"");
                                }
                          // chunk off any //'s
                                // s/\/\/.*$//
                            line = cCommentRe.substitute(line,"");
// NOT POSSIBLE TO DO CASTING PROPERLY. CAN MAKE MISTAKES.
                          // look for casting:   (Word) - primitives
                            // /\(([a-zA-Z0-9_]*)\)      can pick up variables here :(
                                match = castRe.getMatch(line);
                                if(match != null) {
                                                int st = match.getSubStartIndex(1);
                                                int end = match.getSubEndIndex(1);
                                                if(st != -1 && end != -1) {
                                                        if(!names.contains(line.substring(st,end))) {
                                                            names.addElement(line.substring(st,end));
                                                    }
                                            }
                                }
                          // look for declarations:   Word word;
                            // /([a-zA-Z0-9_]*)\s*[a-zA-Z0-9_]*;/
                                match = declRe.getMatch(line);
                                if(match != null) {
                                                int st = match.getSubStartIndex(1);
                                                int end = match.getSubEndIndex(1);
                                                if(st != -1 && end != -1) {
                                                        if(!names.contains(line.substring(st,end))) {
                                                            names.addElement(line.substring(st,end));
                                                    }
                                            }
                                }
                          // look for declaration/assigns: Word word=..;
                            // /([a-zA-Z0-9_]*)\s*[a-zA-Z0-9_]*\s*=/
                                match = assiRe.getMatch(line);
                                if(match != null) {
                                                int st = match.getSubStartIndex(1);
                                                int end = match.getSubEndIndex(1);
                                                if(st != -1 && end != -1) {
                                                        if(!names.contains(line.substring(st,end))) {
                                                            names.addElement(line.substring(st,end));
                                                    }
                                            }
                                }
                          // look for instanceof: instanceof Word
                              // /instanceof\s*[a-zA-Z0-9_]*/
                                match = instRe.getMatch(line);
                                if(match != null) {
                                                int st = match.getSubStartIndex(1);
                                                int end = match.getSubEndIndex(1);
                                                if(st != -1 && end != -1) {
                                                        if(!names.contains(line.substring(st,end))) {
                                                            names.addElement(line.substring(st,end));
                                                    }
                                            }
                                }
                          // look for arguments: (Argument argument, Arg arg..)
                            // /\(([a-zA-Z0-9_]*)\s*[a-zA-Z0-9_]*,... handle list.
                          // look for throws Exception
                              // /throws\s*([a-zA-Z0-9_]*),... handle list.
                          // look for new Word(
                                // /new\s*([a-zA-Z0-9_]*)
                                match = newRe.getMatch(line);
                                if(match != null) {
                                                int st = match.getSubStartIndex(1);
                                                int end = match.getSubEndIndex(1);
                                                if(st != -1 && end != -1) {
                                                        if(!names.contains(line.substring(st,end))) {
                                                            names.addElement(line.substring(st,end));
                                                    }
                                            }
                                }
                          // look for any class declarations, these must be removed
                            // /class\s*([a-zA-Z0-9_]*)
                                match = classRe.getMatch(line);
                                if(match != null) {
                                                int st = match.getSubStartIndex(1);
                                                int end = match.getSubEndIndex(1);
                                                if(st != -1 && end != -1) {
                                                    localClassNames.addElement(line.substring(st,end));
                                            }
                                }
                        }
                        bir.close();
                        // remove class declarations from the list of classes
                        Enumeration enum = localClassNames.elements();
                        while(enum.hasMoreElements()) {
                                names.removeElement(enum.nextElement());
                        }
                } catch(IOException ioe) {