From: Peter S. <sch...@us...> - 2006-01-24 14:38:32
|
Update of /cvsroot/plb4jedit/plb4jedit/Plb/src/java/net/sf/plb4jedit/plb In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv4369/Plb/src/java/net/sf/plb4jedit/plb Modified Files: PlbPlugin.java PlbParser.java PlbSource.java ResourceManager.java Log Message: includes listing and includes nested too deeply check Index: ResourceManager.java =================================================================== RCS file: /cvsroot/plb4jedit/plb4jedit/Plb/src/java/net/sf/plb4jedit/plb/ResourceManager.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- ResourceManager.java 20 Oct 2005 13:50:17 -0000 1.5 +++ ResourceManager.java 24 Jan 2006 14:38:16 -0000 1.6 @@ -22,7 +22,9 @@ */ public class ResourceManager { private PathBroker pathBroker; - private Set includes; + private List includes; + + private Map includeLevelMap; private TreeMap variables; private TreeMap labels; private static IncludeCache cache; @@ -45,27 +47,18 @@ public ResourceManager(String plbPath, PlbSource program) { cache = IncludeCache.getInstance(); - includes = new TreeSet(); + includeLevelMap = new TreeMap(); + includes = new ArrayList(); variables = new TreeMap(); labels = new TreeMap(); pathBroker = new PathBroker(plbPath, program.getPath()); fillOwn(program); - resolveIncludes(); } - private void resolveIncludes() { - Stack todo = new Stack(); - for (Iterator it = includes.iterator(); it.hasNext();) { - todo.push(it.next()); - } - while (!todo.isEmpty()) { - handleOneInclude(todo); - } - } - - private void handleOneInclude(Stack todo) { - String incPath = (String) todo.pop(); + private void scanInclude(String incPath, Integer includeLevel) { Include inc; + includes.add(incPath); + includeLevelMap.put(incPath, includeLevel); try { inc = cache.getByPath(incPath); } catch (FileNotFoundException e) { @@ -88,14 +81,17 @@ + e1.getMessage() + incPath + "/" + next); jEdit.getActiveView().getStatus().setMessage( "Error " + incPath + "/" + next); - return; + continue; } - if (!includes.contains(id)) { - todo.push(id); - includes.add(id); + if (!includeLevelMap.containsKey(id)) { + scanInclude(id, increment(includeLevel)); } } } + + private Integer increment(Integer i) { + return (new Integer(i.intValue()+1)); + } /** * searches for a Variable name and returns a Variable object which gives @@ -124,22 +120,6 @@ } private void fillOwn(PlbSource source) { - for (Iterator it = source.getIncludes().iterator(); it.hasNext();) { - SourceLine line = (SourceLine) it.next(); - File incFile; - try { - incFile = pathBroker.searchInclude(line.getRest()); - } catch (FileNotFoundException e) { - Log.log(Log.ERROR, this, "fillOwn: " + e.getMessage() + "\n" - + line.getRest() + "/" + line.getLine() + "\nin " - + source.getPath() + "/" + pathBroker.getPathElements()); - jEdit.getActiveView().getStatus().setMessage( - "Error: can't find " + line.getRest()); - return; - } - String absPath = incFile.getAbsolutePath(); - includes.add(absPath); - } for (Iterator it = source.getLabels().iterator(); it.hasNext();) { SourceLine line = (SourceLine) it.next(); String label = line.getLabel(); @@ -156,14 +136,44 @@ .getRest())); } + Integer eins = new Integer(1); + for (Iterator it = source.getIncludes().iterator(); it.hasNext();) { + SourceLine line = (SourceLine) it.next(); + File incFile; + try { + incFile = pathBroker.searchInclude(line.getRest()); + } catch (FileNotFoundException e) { + Log.log(Log.ERROR, this, "fillOwn: " + e.getMessage() + "\n" + + line.getRest() + "/" + line.getLine() + "\nin " + + source.getPath() + "/" + pathBroker.getPathElements()); + jEdit.getActiveView().getStatus().setMessage( + "Error: can't find " + line.getRest()); + return; + } + String absPath = incFile.getAbsolutePath(); + scanInclude(absPath, eins); + } } /** * @return a set of inlcudes includes by this file. */ - public Set getIncludes() { + public List getIncludes() { return includes; } + + /** + * return the level of the given include or -1 if include is not in current resource. + * @param incPath absolute path of include name + * @return level of include or -1 if given include is not part of resource + */ + public int getIncludeLevel(String incPath) { + if (includeLevelMap.containsKey(incPath)) { + return ((Integer)includeLevelMap.get(incPath)).intValue(); + } else { + return -1; + } + } /** * @return containing all labels defined in the source file and its includes Index: PlbPlugin.java =================================================================== RCS file: /cvsroot/plb4jedit/plb4jedit/Plb/src/java/net/sf/plb4jedit/plb/PlbPlugin.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -d -r1.5 -r1.6 --- PlbPlugin.java 28 Jun 2005 07:01:12 -0000 1.5 +++ PlbPlugin.java 24 Jan 2006 14:38:16 -0000 1.6 @@ -1,5 +1,10 @@ package net.sf.plb4jedit.plb; +import java.awt.TextArea; +import java.io.File; +import java.util.Iterator; +import java.util.List; +import java.util.Set; import java.util.Vector; import org.gjt.sp.jedit.*; @@ -13,21 +18,23 @@ /** * jEdit plugin to add Plb-specific enhancements to jEdit: * <ul> - * <li>SideKick structure view</li> - * <li>PlbParser, which gives "goto variable/label declaration" functionality</li> - * </ul> + * <li>SideKick structure view</li> + * <li>PlbParser, which gives "goto variable/label declaration" functionality + * </li> + * </ul> + * Plans/TODO for jEdit 4.2. Port to new plugin architecture. Use new version of + * SideKick-Plugin which gives easy to perform code-completion. * - * Plans/TODO for jEdit 4.2. Port to new plugin architecture. Use new version of SideKick-Plugin - * which gives easy to perform code-completion. - * - * @author Peter Schaefer + * @author Peter Schaefer */ public class PlbPlugin extends EBPlugin { - - /** prefix to lookup properties in Plb.props*/ + + public static final int MAX_LEVEL = 4; + /** prefix to lookup properties in Plb.props */ public final static String PROPERTY_PREFIX = "plugin.Plb."; /** singletion PlbParser instance for SideKick-Plugin */ public static final PlbParser PLB_PARSER_INSTANCE = new PlbParser("plb"); + /** jEdit plugin architecture: called on start-up to initialize plugin */ public void start() { SideKickPlugin.registerParser(PLB_PARSER_INSTANCE); @@ -36,31 +43,34 @@ /** jEdit plugin architecture: called on shutdown */ public void stop() { SideKickPlugin.unregisterParser(PLB_PARSER_INSTANCE); - + } /** - * creates Plugin menu entries from properties in Plb.props: - * plb.menu.label=Plb - * plb.menu=Plb - plb.open-variable-declaration plb.goto-label - * - * @param menuItems param - */ + * creates Plugin menu entries from properties in Plb.props: + * plb.menu.label=Plb plb.menu=Plb - plb.open-variable-declaration + * plb.goto-label + * + * @param menuItems + * param + */ public void createMenuItems(Vector menuItems) { menuItems.addElement(GUIUtilities.loadMenu("plb.menu")); } /** - * jEdit plugin architecture: handle messages (e.g. buffer save, etc) + * jEdit plugin architecture: handle messages (e.g. buffer save, etc) */ public void handleMessage(EBMessage msg) { } /** - * get current Word from the textarea of the parameter view. - * recognizes $ and # as belonging to a word - * @param view to handle - * @return the word where the cursor stands in the textarea + * get current Word from the textarea of the parameter view. recognizes $ + * and # as belonging to a word + * + * @param view + * to handle + * @return the word where the cursor stands in the textarea */ private static String getCurrentWord(View view) { JEditTextArea textarea = view.getTextArea(); @@ -84,20 +94,18 @@ if (offset == textarea.getLineLength(line)) offset--; - int wordStart = - TextUtilities.findWordStart(lineText, offset, noWordSep); - int wordEnd = - TextUtilities.findWordEnd(lineText, offset + 1, noWordSep); + int wordStart = TextUtilities + .findWordStart(lineText, offset, noWordSep); + int wordEnd = TextUtilities + .findWordEnd(lineText, offset + 1, noWordSep); return lineText.substring(wordStart, wordEnd); } /** - * opens the variable definition in a new buffer. - * The lookup is performed with the word where the cursor stands. - * If nothing is found or on errors stati are shown in the status bar. - * - * Is linked with the action open-variable-declaration, see actions.xml. - * + * opens the variable definition in a new buffer. The lookup is performed + * with the word where the cursor stands. If nothing is found or on errors + * stati are shown in the status bar. Is linked with the action + * open-variable-declaration, see actions.xml. */ public static void openVariableDeclaration() { Log.log(Log.DEBUG, jEdit.getPlugin("Plb"), "openVariableDeclaration()"); @@ -122,13 +130,13 @@ Log.log(Log.DEBUG, jEdit.getPlugin("Plb"), " nothing found"); return; } - openBuffer(view,var.getSource(),var.getLineno()-1); + openBuffer(view, var.getSource(), var.getLineno() - 1); } /** - * goes to the position where the label under the cursor is defined. - * Opens this position in a new buffer. If nothing is found or an error occrus - * a status is shown in the status bar. + * goes to the position where the label under the cursor is defined. Opens + * this position in a new buffer. If nothing is found or an error occrus a + * status is shown in the status bar. */ public static void gotoLabel() { Log.log(Log.DEBUG, jEdit.getPlugin("Plb"), "gotoLabelDefinition()"); @@ -154,27 +162,67 @@ Log.log(Log.DEBUG, jEdit.getPlugin("Plb"), " nothing found"); return; } - openBuffer(view,label.getSource(),label.getLineno()-1); + openBuffer(view, label.getSource(), label.getLineno() - 1); + } + + public static void printIncludeList() { + Log.log(Log.DEBUG, jEdit.getPlugin("Plb"), "printIncludeList()"); + View view = jEdit.getActiveView(); + ResourceManager resource = getResource(view); + Buffer includeBuffer = jEdit.newFile(view); + + StringBuffer includeList = new StringBuffer(); + for (Iterator iter = resource.getIncludes().iterator(); iter.hasNext();) { + String incPath = (String) iter.next(); + final int level = resource.getIncludeLevel(incPath); + for(int i = 1; i < level; i++) { + includeList.append("\t"); + } + includeList.append(incPath); + for(int i = 0; i <= MAX_LEVEL-level+2; i++) { + includeList.append("\t"); + } + includeList.append(level+"\n"); + } + view.getTextArea().setText(includeList.toString()); + } + + public static int getMaxLevel() { + Log.log(Log.DEBUG, jEdit.getPlugin("Plb"), "printIncludeList()"); + ResourceManager resource = getResource(jEdit.getActiveView()); + int max = 0; + for (Iterator iter = resource.getIncludes().iterator(); iter.hasNext();) { + int level = resource.getIncludeLevel((String)iter.next()); + if (level > max) { + max = level; + } + } + return max; + } + + public static void enableToolTips() { + jEdit.getActiveView().getTextArea().getPainter() + .addExtension(new PlbTextAreaExtension()); } /** * helper to get the ResourceManager of the actual buffer in the given view. - * The resource-manager can be accessed from the PlbSource, which is stored in - * PlbParsedData, a subclass of SideKickParsedData, which can be received from - * the SideKickPlugin.<br/> - * The PlbParsedData can only be received if the buffer was parsed by the the SideKickPlugin - * before, so if buffer was not parsed, parsing is performed first. - * @param view to handle + * The resource-manager can be accessed from the PlbSource, which is stored + * in PlbParsedData, a subclass of SideKickParsedData, which can be received + * from the SideKickPlugin. <br/>The PlbParsedData can only be received if + * the buffer was parsed by the the SideKickPlugin before, so if buffer was + * not parsed, parsing is performed first. + * + * @param view + * to handle * @return resource-manager belonging to the view actual buffer. */ private static ResourceManager getResource(View view) { Buffer buffer = view.getBuffer(); if (!buffer.getMode().getName().equals("plb")) { view.getStatus().setMessage("no plb buffer"); - Log.log( - Log.DEBUG, - jEdit.getPlugin("Plb"), - " not in plb mode: " + buffer.getMode().getName()); + Log.log(Log.DEBUG, jEdit.getPlugin("Plb"), " not in plb mode: " + + buffer.getMode().getName()); return null; } SideKickParsedData sdata = SideKickParsedData.getParsedData(view); @@ -184,23 +232,23 @@ sdata = SideKickParsedData.getParsedData(view); if (sdata == null || !(sdata instanceof PlbParsedData)) { view.getStatus().setMessage("Buffer not parsed. Parse first."); - Log.log( - Log.DEBUG, - jEdit.getPlugin("Plb"), - " no parsed data?!"); + Log + .log(Log.DEBUG, jEdit.getPlugin("Plb"), + " no parsed data?!"); return null; } } PlbParsedData data = (PlbParsedData) sdata; ResourceManager resource; - resource = - data.getSource().getResources( - jEdit.getProperty("rsi.plb.path")); + resource = data.getSource().getResources( + jEdit.getProperty("rsi.plb.path")); return resource; } - - private static void openBuffer(final View view, String path, final int lineNo) { + + private static void openBuffer(final View view, String path, + final int lineNo) + { final Buffer buffer; if (jEdit.getBuffer(path) != null) { buffer = jEdit.getBuffer(path); @@ -214,10 +262,10 @@ public void run() { // new in 4.2 view.goToBuffer(buffer); view.setBuffer(buffer); - view.getTextArea().moveCaretPosition(buffer.getLineStartOffset(lineNo)); + view.getTextArea().moveCaretPosition( + buffer.getLineStartOffset(lineNo)); } }); } - - + } Index: PlbParser.java =================================================================== RCS file: /cvsroot/plb4jedit/plb4jedit/Plb/src/java/net/sf/plb4jedit/plb/PlbParser.java,v retrieving revision 1.2 retrieving revision 1.3 diff -u -d -r1.2 -r1.3 --- PlbParser.java 6 Jan 2004 17:57:46 -0000 1.2 +++ PlbParser.java 24 Jan 2006 14:38:16 -0000 1.3 @@ -35,7 +35,7 @@ // taken from super class public boolean supportsCompletion() { - return false; + return true; } // taken from super class @@ -63,6 +63,7 @@ DefaultErrorSource errorSource) { Log.log(Log.DEBUG, this, "parse"); String[] text; + try { buffer.readLock(); Index: PlbSource.java =================================================================== RCS file: /cvsroot/plb4jedit/plb4jedit/Plb/src/java/net/sf/plb4jedit/plb/PlbSource.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- PlbSource.java 28 Jun 2005 07:01:12 -0000 1.4 +++ PlbSource.java 24 Jan 2006 14:38:16 -0000 1.5 @@ -102,7 +102,7 @@ private void sortLists() { Collections.sort(vars, SourceLine.LABEL_ORDERED); - Collections.sort(includes, SourceLine.REST_ORDERED); + //Collections.sort(includes, SourceLine.REST_ORDERED); Collections.sort(labels, SourceLine.LABEL_ORDERED); } |