From: khartlage Date: Wed, 31 Dec 2003 16:12:30 +0000 (+0000) Subject: Eclipse 3.x compatible; X-Git-Url: http://git.phpeclipse.com Eclipse 3.x compatible; early version which is based on same mechanisms as JDT; i.e. like JavaModel; Parser and JavaBuilder; --- diff --git a/net.sourceforge.phpeclipse/.classpath b/net.sourceforge.phpeclipse/.classpath index 5ffe139..19ca38e 100644 --- a/net.sourceforge.phpeclipse/.classpath +++ b/net.sourceforge.phpeclipse/.classpath @@ -1,48 +1,30 @@ - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/net.sourceforge.phpeclipse/plugin.xml b/net.sourceforge.phpeclipse/plugin.xml index 5443171..cced16b 100644 --- a/net.sourceforge.phpeclipse/plugin.xml +++ b/net.sourceforge.phpeclipse/plugin.xml @@ -12,13 +12,22 @@ - + + + + + + + + + + + + - - @@ -33,21 +42,19 @@ class="net.sourceforge.phpdt.internal.core.JavaProject"> - - - + + diff --git a/net.sourceforge.phpeclipse/src/com/xaraya/wizard/NewXarayaResourceWizard.java b/net.sourceforge.phpeclipse/src/com/xaraya/wizard/NewXarayaResourceWizard.java index d57b268..d008e08 100644 --- a/net.sourceforge.phpeclipse/src/com/xaraya/wizard/NewXarayaResourceWizard.java +++ b/net.sourceforge.phpeclipse/src/com/xaraya/wizard/NewXarayaResourceWizard.java @@ -6,56 +6,57 @@ import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.ide.IDE; import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard; public class NewXarayaResourceWizard extends BasicNewResourceWizard { - - private XarayaModuleContainerPage mainPage; //get where to place resource and module name - private XarayaModuleFilePage page1; //get first load of details author/email/which files - - private XarayaVersionModel xvm = new XarayaVersionModel(); //holder for details - -public NewXarayaResourceWizard() { - super(); - //initialize static classes that are required.. - new XarayaModuleText(); - new XarayaModuleMessages(); -} - -public void addPages() { - super.addPages(); - mainPage = new XarayaModuleContainerPage(XarayaModuleMessages.getString("Xaraya.label.container"), getSelection()); - addPage(mainPage); - page1 = new XarayaModuleFilePage(XarayaModuleMessages.getString("Xaraya.label.container")); - addPage(page1); -} -public void init(IWorkbench workbench, IStructuredSelection currentSelection) { - super.init(workbench, currentSelection); - setWindowTitle(XarayaModuleMessages.getString("Xaraya.label.container")); - setNeedsProgressMonitor(true); -} - -public boolean performFinish() { - page1.saveDataToModel(); - IFolder folder = mainPage.createNewModuleFolder(); //create the folder for the module - if (folder == null) - return false; - - Object[] files = mainPage.createNewModuleFiles(); //create the files - - selectAndReveal(folder); - - // Open editor on new xaraya init file. - IWorkbenchWindow dw = getWorkbench().getActiveWorkbenchWindow(); - try { - IWorkbenchPage page = dw.getActivePage(); - if (page != null) - page.openEditor((IFile)files[0]); - } catch (Exception e) { - } - - return true; -} + private XarayaModuleContainerPage mainPage; //get where to place resource and module name + private XarayaModuleFilePage page1; //get first load of details author/email/which files + + private XarayaVersionModel xvm = new XarayaVersionModel(); //holder for details + + public NewXarayaResourceWizard() { + super(); + //initialize static classes that are required.. + new XarayaModuleText(); + new XarayaModuleMessages(); + } + + public void addPages() { + super.addPages(); + mainPage = new XarayaModuleContainerPage(XarayaModuleMessages.getString("Xaraya.label.container"), getSelection()); + addPage(mainPage); + page1 = new XarayaModuleFilePage(XarayaModuleMessages.getString("Xaraya.label.container")); + addPage(page1); + } + + public void init(IWorkbench workbench, IStructuredSelection currentSelection) { + super.init(workbench, currentSelection); + setWindowTitle(XarayaModuleMessages.getString("Xaraya.label.container")); + setNeedsProgressMonitor(true); + } + + public boolean performFinish() { + page1.saveDataToModel(); + IFolder folder = mainPage.createNewModuleFolder(); //create the folder for the module + if (folder == null) + return false; + + Object[] files = mainPage.createNewModuleFiles(); //create the files + + selectAndReveal(folder); + + // Open editor on new xaraya init file. + IWorkbenchWindow dw = getWorkbench().getActiveWorkbenchWindow(); + try { + IWorkbenchPage page = dw.getActivePage(); + if (page != null) + IDE.openEditor(page, (IFile) files[0], true); + } catch (Exception e) { + } + + return true; + } } diff --git a/net.sourceforge.phpeclipse/src/com/xaraya/wizard/XarayaModuleContainerPage.java b/net.sourceforge.phpeclipse/src/com/xaraya/wizard/XarayaModuleContainerPage.java index 34b50ff..b3b14f8 100644 --- a/net.sourceforge.phpeclipse/src/com/xaraya/wizard/XarayaModuleContainerPage.java +++ b/net.sourceforge.phpeclipse/src/com/xaraya/wizard/XarayaModuleContainerPage.java @@ -38,7 +38,8 @@ import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.ui.internal.IHelpContextIds; import org.eclipse.ui.internal.WorkbenchMessages; import org.eclipse.ui.internal.WorkbenchPlugin; -import org.eclipse.ui.internal.misc.ResourceAndContainerGroup; +import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; +import org.eclipse.ui.internal.ide.misc.ResourceAndContainerGroup; public class XarayaModuleContainerPage extends WizardPage implements Listener { private static final int SIZING_CONTAINER_GROUP_HEIGHT = 250; @@ -107,7 +108,7 @@ protected void createFolder(IFolder folderHandle, IProgressMonitor monitor) thro } protected IFolder createFolderHandle(IPath folderPath) { - return WorkbenchPlugin.getPluginWorkspace().getRoot().getFolder(folderPath); + return IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getFolder(folderPath); } public IFolder createNewModuleFolder() { @@ -187,7 +188,7 @@ protected void createFile(IFile fileHandle, InputStream contents, IProgressMonit } protected IFile createFileHandle(IPath filePath) { - return WorkbenchPlugin.getPluginWorkspace().getRoot().getFile(filePath); + return IDEWorkbenchPlugin.getPluginWorkspace().getRoot().getFile(filePath); } public Object[] createNewModuleFiles(){ @@ -340,7 +341,7 @@ public void setVisible(boolean visible) { protected boolean validatePage() { boolean valid = true; String moduleName = new String(); - IWorkspace workspace = WorkbenchPlugin.getPluginWorkspace(); + IWorkspace workspace = IDEWorkbenchPlugin.getPluginWorkspace(); IStatus nameStatus = null; String folderName = resourceGroup.getResource(); moduleName = folderName; diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/ITerminalSymbols.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/ITerminalSymbols.java index adab9e7..9dfca8a 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/ITerminalSymbols.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/core/compiler/ITerminalSymbols.java @@ -142,15 +142,15 @@ public interface ITerminalSymbols { public final static int TokenNameforeach = 1028; public final static int TokenNameendforeach = 1029; public final static int TokenNameextends = 1030; - // public final static int TokenNameempty = 1031; - // public final static int TokenNamearray = 1032; + public final static int TokenNameempty = 1031; + public final static int TokenNamearray = 1032; public final static int TokenNameecho = 1033; public final static int TokenNamevar = 1034; public final static int TokenNameas = 1035; public final static int TokenNameprint = 1036; - // public final static int TokenNameunset = 1037; - // public final static int TokenNameexit = 1038; - // public final static int TokenNamedie = 1039; + public final static int TokenNameunset = 1037; + public final static int TokenNameexit = 1038; + public final static int TokenNamedie = 1039; // public final static int TokenNameand = 1040; // public final static int TokenNameor = 1041; // public final static int TokenNamexor = 1042; @@ -172,4 +172,12 @@ public interface ITerminalSymbols { public final static int TokenNameinstanceof = 1059; public final static int TokenNamesuper = 1060; public final static int TokenNamethrow = 1061; + + public final static int TokenNameconst = 1063; + public final static int TokenNamedeclare = 1064; + public final static int TokenNameenddeclare = 1065; + public final static int TokenNameeval = 1065; + public final static int TokenNameuse = 1066; + public final static int TokenNameisset = 1066; + public final static int TokenNamefinal = 1067; } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/lookup/Scope.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/lookup/Scope.java index 7678e2a..9d210ac 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/lookup/Scope.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/lookup/Scope.java @@ -892,7 +892,7 @@ public abstract class Scope ReferenceBinding type = environment().getType(JAVA_LANG_THROWABLE); if (type != null) return type; - problemReporter().isClassPathCorrect(JAVA_LANG_THROWABLE, referenceCompilationUnit()); +// problemReporter().isClassPathCorrect(JAVA_LANG_THROWABLE, referenceCompilationUnit()); return null; // will not get here since the above error aborts the compilation } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java index 1ff0619..c48d451 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/compiler/parser/Scanner.java @@ -22,19 +22,16 @@ import net.sourceforge.phpdt.internal.compiler.ast.StringLiteral; public class Scanner implements IScanner, ITerminalSymbols { - /* APIs ares - - getNextToken() which return the current type of the token - (this value is not memorized by the scanner) - - getCurrentTokenSource() which provides with the token "REAL" source - (aka all unicode have been transformed into a correct char) - - sourceStart gives the position into the stream - - currentPosition-1 gives the sourceEnd position into the stream - */ - - // 1.4 feature + /* + * APIs ares - getNextToken() which return the current type of the token (this value is not memorized by the scanner) - + * getCurrentTokenSource() which provides with the token "REAL" source (aka all unicode have been transformed into a correct + * char) - sourceStart gives the position into the stream - currentPosition-1 gives the sourceEnd position into the stream + */ + + // 1.4 feature private boolean assertMode; public boolean useAssertAsAnIndentifier = false; - //flag indicating if processed source contains occurrences of keyword assert + //flag indicating if processed source contains occurrences of keyword assert public boolean containsAssertKeyword = false; public boolean recordLineSeparator; @@ -70,7 +67,7 @@ public class Scanner implements IScanner, ITerminalSymbols { //diet parsing support - jump over some method body when requested public boolean diet = false; - //support for the poor-line-debuggers .... + //support for the poor-line-debuggers .... //remember the position of the cr/lf public int[] lineEnds = new int[250]; public int linePtr = -1; @@ -123,7 +120,7 @@ public class Scanner implements IScanner, ITerminalSymbols { static final int TableSize = 30, InternalTableSize = 6; //30*6 = 180 entries public static final int OptimizedLength = 6; - public /*static*/ + public /* static */ final char[][][][] charArray_length = new char[OptimizedLength][TableSize][InternalTableSize][]; // support for detecting non-externalized string literals int currentLineNr = -1; @@ -138,7 +135,7 @@ public class Scanner implements IScanner, ITerminalSymbols { public boolean checkNonExternalizedStringLiterals = true; public boolean wasNonExternalizedStringLiteral = false; - /*static*/ { + /* static */ { for (int i = 0; i < 6; i++) { for (int j = 0; j < TableSize; j++) { for (int k = 0; k < InternalTableSize; k++) { @@ -153,16 +150,16 @@ public class Scanner implements IScanner, ITerminalSymbols { public static final int SquareBracket = 1; public static final int CurlyBracket = 2; public static final int BracketKinds = 3; - - // task tag support - public char[][] foundTaskTags = null; - public char[][] foundTaskMessages; - public char[][] foundTaskPriorities = null; - public int[][] foundTaskPositions; - public int foundTaskCount = 0; - public char[][] taskTags = null; - public char[][] taskPriorities = null; - + + // task tag support + public char[][] foundTaskTags = null; + public char[][] foundTaskMessages; + public char[][] foundTaskPriorities = null; + public int[][] foundTaskPositions; + public int foundTaskCount = 0; + public char[][] taskTags = null; + public char[][] taskPriorities = null; + public static final boolean DEBUG = false; public Scanner() { @@ -173,23 +170,21 @@ public class Scanner implements IScanner, ITerminalSymbols { } /** - * Determines if the specified character is - * permissible as the first character in a PHP identifier + * Determines if the specified character is permissible as the first character in a PHP identifier */ public static boolean isPHPIdentifierStart(char ch) { return Character.isLetter(ch) || (ch == '_') || (0x7F <= ch && ch <= 0xFF); } /** - * Determines if the specified character may be part of a PHP identifier as - * other than the first character + * Determines if the specified character may be part of a PHP identifier as other than the first character */ public static boolean isPHPIdentifierPart(char ch) { return Character.isLetterOrDigit(ch) || (ch == '_') || (0x7F <= ch && ch <= 0xFF); } public final boolean atEnd() { - // This code is not relevant if source is + // This code is not relevant if source is // Only a part of the real stream input return source.length == currentPosition; @@ -302,10 +297,9 @@ public class Scanner implements IScanner, ITerminalSymbols { /* * Search the source position corresponding to the end of a given line number - * - * Line numbers are 1-based, and relative to the scanner initialPosition. - * Character positions are 0-based. - * + * + * Line numbers are 1-based, and relative to the scanner initialPosition. Character positions are 0-based. + * * In case the given line number is inconsistent, answers -1. */ public final int getLineEnd(int lineNumber) { @@ -324,12 +318,11 @@ public class Scanner implements IScanner, ITerminalSymbols { } /** * Search the source position corresponding to the beginning of a given line number - * - * Line numbers are 1-based, and relative to the scanner initialPosition. - * Character positions are 0-based. - * - * e.g. getLineStart(1) --> 0 i.e. first line starts at character 0. - * + * + * Line numbers are 1-based, and relative to the scanner initialPosition. Character positions are 0-based. + * + * e.g. getLineStart(1) --> 0 i.e. first line starts at character 0. + * * In case the given line number is inconsistent, answers -1. */ public final int getLineStart(int lineNumber) { @@ -355,7 +348,7 @@ public class Scanner implements IScanner, ITerminalSymbols { //Both previous lines are true if the currentCharacter is == to the testedChar //On false, no side effect has occured. - //ALL getNextChar.... ARE OPTIMIZED COPIES + //ALL getNextChar.... ARE OPTIMIZED COPIES int temp = currentPosition; try { @@ -432,7 +425,7 @@ public class Scanner implements IScanner, ITerminalSymbols { //Both previous lines are true if the currentCharacter is == to the testedChar1/2 //On false, no side effect has occured. - //ALL getNextChar.... ARE OPTIMIZED COPIES + //ALL getNextChar.... ARE OPTIMIZED COPIES int temp = currentPosition; try { @@ -514,7 +507,7 @@ public class Scanner implements IScanner, ITerminalSymbols { //Both previous lines are true if the currentCharacter is a digit //On false, no side effect has occured. - //ALL getNextChar.... ARE OPTIMIZED COPIES + //ALL getNextChar.... ARE OPTIMIZED COPIES int temp = currentPosition; try { @@ -586,7 +579,7 @@ public class Scanner implements IScanner, ITerminalSymbols { //Both previous lines are true if the currentCharacter is a digit base on radix //On false, no side effect has occured. - //ALL getNextChar.... ARE OPTIMIZED COPIES + //ALL getNextChar.... ARE OPTIMIZED COPIES int temp = currentPosition; try { @@ -658,7 +651,7 @@ public class Scanner implements IScanner, ITerminalSymbols { //Both previous lines are true if the currentCharacter is a JavaIdentifierPart //On false, no side effect has occured. - //ALL getNextChar.... ARE OPTIMIZED COPIES + //ALL getNextChar.... ARE OPTIMIZED COPIES int temp = currentPosition; try { @@ -748,7 +741,7 @@ public class Scanner implements IScanner, ITerminalSymbols { if (test >= 0) { test = getNextChar('P', 'p'); if (test >= 0) { - // 0) && (lineEnds[linePtr] >= separatorPos)) return; - // System.out.println("LF-" + separatorPos); + // System.out.println("LF-" + separatorPos); try { lineEnds[++linePtr] = separatorPos; } catch (IndexOutOfBoundsException e) { @@ -2358,7 +2352,7 @@ public class Scanner implements IScanner, ITerminalSymbols { } // look-ahead for merged cr+lf if (source[currentPosition] == '\n') { - //System.out.println("look-ahead LF-" + currentPosition); + //System.out.println("look-ahead LF-" + currentPosition); lineEnds[linePtr] = currentPosition; currentPosition++; wasAcr = false; @@ -2370,13 +2364,13 @@ public class Scanner implements IScanner, ITerminalSymbols { if (currentCharacter == '\n') { //must merge eventual cr followed by lf if (wasAcr && (lineEnds[linePtr] == (currentPosition - 7))) { - //System.out.println("merge LF-" + (currentPosition - 1)); + //System.out.println("merge LF-" + (currentPosition - 1)); lineEnds[linePtr] = currentPosition - 6; } else { int separatorPos = currentPosition - 6; if ((linePtr > 0) && (lineEnds[linePtr] >= separatorPos)) return; - // System.out.println("LF-" + separatorPos); + // System.out.println("LF-" + separatorPos); try { lineEnds[++linePtr] = separatorPos; } catch (IndexOutOfBoundsException e) { @@ -2524,7 +2518,7 @@ public class Scanner implements IScanner, ITerminalSymbols { } else { // has read \OctalDigit NonDigit--> ignore last character currentPosition--; } - } else { // has read \OctalDigit NonOctalDigit--> ignore last character + } else { // has read \OctalDigit NonOctalDigit--> ignore last character currentPosition--; } } else { // has read \OctalDigit --> ignore last character @@ -2595,7 +2589,7 @@ public class Scanner implements IScanner, ITerminalSymbols { firstLetter = data[index]; switch (firstLetter) { - case 'a' : // as and array + case 'a' : // as and array abstract switch (length) { case 2 : //as if ((data[++index] == 's')) { @@ -2609,11 +2603,22 @@ public class Scanner implements IScanner, ITerminalSymbols { } else { return TokenNameIdentifier; } - // case 5 : - // if ((data[++index] == 'r') && (data[++index] == 'r') && (data[++index] == 'a') && (data[++index] == 'y')) - // return TokenNamearray; - // else - // return TokenNameIdentifier; + case 5 : // array + if ((data[++index] == 'r') && (data[++index] == 'r') && (data[++index] == 'a') && (data[++index] == 'y')) + return TokenNamearray; + else + return TokenNameIdentifier; + case 8 : + if ((data[++index] == 'b') + && (data[++index] == 's') + && (data[++index] == 't') + && (data[++index] == 'r') + && (data[++index] == 'a') + && (data[++index] == 'c') + && (data[++index] == 't')) + return TokenNameabstract; + else + return TokenNameIdentifier; default : return TokenNameIdentifier; } @@ -2628,7 +2633,7 @@ public class Scanner implements IScanner, ITerminalSymbols { return TokenNameIdentifier; } - case 'c' : //case class continue + case 'c' : //case catch class const continue switch (length) { case 4 : if ((data[++index] == 'a') && (data[++index] == 's') && (data[++index] == 'e')) @@ -2636,8 +2641,12 @@ public class Scanner implements IScanner, ITerminalSymbols { else return TokenNameIdentifier; case 5 : - if ((data[++index] == 'l') && (data[++index] == 'a') && (data[++index] == 's') && (data[++index] == 's')) + if ((data[++index] == 'a') && (data[++index] == 't') && (data[++index] == 'c') && (data[++index] == 'h')) + return TokenNamecatch; + if ((data[index] == 'l') && (data[++index] == 'a') && (data[++index] == 's') && (data[++index] == 's')) return TokenNameclass; + if ((data[index] == 'o') && (data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 't')) + return TokenNameconst; else return TokenNameIdentifier; case 8 : @@ -2655,13 +2664,18 @@ public class Scanner implements IScanner, ITerminalSymbols { return TokenNameIdentifier; } - case 'd' : //define default do + case 'd' : //define declare default do die switch (length) { case 2 : if ((data[++index] == 'o')) return TokenNamedo; else return TokenNameIdentifier; + case 3 : + if ((data[++index] == 'i') && (data[++index] == 'e')) + return TokenNamedie; + else + return TokenNameIdentifier; case 6 : if ((data[++index] == 'e') && (data[++index] == 'f') @@ -2673,6 +2687,14 @@ public class Scanner implements IScanner, ITerminalSymbols { return TokenNameIdentifier; case 7 : if ((data[++index] == 'e') + && (data[++index] == 'c') + && (data[++index] == 'l') + && (data[++index] == 'a') + && (data[++index] == 'r') + && (data[++index] == 'e')) + return TokenNamedeclare; + index = 0; + if ((data[++index] == 'e') && (data[++index] == 'f') && (data[++index] == 'a') && (data[++index] == 'u') @@ -2684,18 +2706,24 @@ public class Scanner implements IScanner, ITerminalSymbols { default : return TokenNameIdentifier; } - case 'e' : //echo else elseif extends + case 'e' : //echo else exit elseif extends eval switch (length) { case 4 : if ((data[++index] == 'c') && (data[++index] == 'h') && (data[++index] == 'o')) return TokenNameecho; else if ((data[index] == 'l') && (data[++index] == 's') && (data[++index] == 'e')) return TokenNameelse; + else if ((data[index] == 'x') && (data[++index] == 'i') && (data[++index] == 't')) + return TokenNameexit; + else if ((data[index] == 'v') && (data[++index] == 'a') && (data[++index] == 'l')) + return TokenNameeval; else return TokenNameIdentifier; - case 5 : // endif + case 5 : // endif empty if ((data[++index] == 'n') && (data[++index] == 'd') && (data[++index] == 'i') && (data[++index] == 'f')) return TokenNameendif; + if ((data[index] == 'm') && (data[++index] == 'p') && (data[++index] == 't') && (data[++index] == 'y')) + return TokenNameempty; else return TokenNameIdentifier; case 6 : // endfor @@ -2747,9 +2775,20 @@ public class Scanner implements IScanner, ITerminalSymbols { return TokenNameendswitch; else return TokenNameIdentifier; - case 10 : // endforeach + case 10 : // enddeclare if ((data[++index] == 'n') && (data[++index] == 'd') + && (data[++index] == 'd') + && (data[++index] == 'e') + && (data[++index] == 'c') + && (data[++index] == 'l') + && (data[++index] == 'a') + && (data[++index] == 'r') + && (data[++index] == 'e')) + return TokenNameendforeach; + index = 0; + if ((data[++index] == 'n') // endforeach + && (data[++index] == 'd') && (data[++index] == 'f') && (data[++index] == 'o') && (data[++index] == 'r') @@ -2765,7 +2804,7 @@ public class Scanner implements IScanner, ITerminalSymbols { return TokenNameIdentifier; } - case 'f' : //for false function + case 'f' : //for false final function switch (length) { case 3 : if ((data[++index] == 'o') && (data[++index] == 'r')) @@ -2775,9 +2814,11 @@ public class Scanner implements IScanner, ITerminalSymbols { case 5 : if ((data[++index] == 'a') && (data[++index] == 'l') && (data[++index] == 's') && (data[++index] == 'e')) return TokenNamefalse; + if ((data[index] == 'i') && (data[++index] == 'n') && (data[++index] == 'a') && (data[++index] == 'l')) + return TokenNamefinal; else return TokenNameIdentifier; - case 7 : // function + case 7 : // foreach if ((data[++index] == 'o') && (data[++index] == 'r') && (data[++index] == 'e') @@ -2813,7 +2854,7 @@ public class Scanner implements IScanner, ITerminalSymbols { } return TokenNameIdentifier; - case 'i' : //if int + case 'i' : //if int isset include include_once instanceof interface implements switch (length) { case 2 : if (data[++index] == 'f') @@ -2825,6 +2866,11 @@ public class Scanner implements IScanner, ITerminalSymbols { // return TokenNameint; // else // return TokenNameIdentifier; + case 5 : + if ((data[++index] == 's') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 't')) + return TokenNameisset; + else + return TokenNameIdentifier; case 7 : if ((data[++index] == 'n') && (data[++index] == 'c') @@ -2835,6 +2881,41 @@ public class Scanner implements IScanner, ITerminalSymbols { return TokenNameinclude; else return TokenNameIdentifier; + case 9 : // interface + if ((data[++index] == 'n') + && (data[++index] == 't') + && (data[++index] == 'e') + && (data[++index] == 'r') + && (data[++index] == 'f') + && (data[++index] == 'a') + && (data[++index] == 'c') + && (data[++index] == 'e')) + return TokenNameinterface; + else + return TokenNameIdentifier; + case 10 : // instanceof + if ((data[++index] == 'n') + && (data[++index] == 's') + && (data[++index] == 't') + && (data[++index] == 'a') + && (data[++index] == 'n') + && (data[++index] == 'c') + && (data[++index] == 'e') + && (data[++index] == 'o') + && (data[++index] == 'f')) + return TokenNameinstanceof; + if ((data[index] == 'm') + && (data[++index] == 'p') + && (data[++index] == 'l') + && (data[++index] == 'e') + && (data[++index] == 'm') + && (data[++index] == 'e') + && (data[++index] == 'n') + && (data[++index] == 't') + && (data[++index] == 's')) + return TokenNameimplements; + else + return TokenNameIdentifier; case 12 : if ((data[++index] == 'n') && (data[++index] == 'c') @@ -2901,11 +2982,44 @@ public class Scanner implements IScanner, ITerminalSymbols { // } return TokenNameIdentifier; - case 'p' : // print - if (length == 5) { - if ((data[++index] == 'r') && (data[++index] == 'i') && (data[++index] == 'n') && (data[++index] == 't')) { - return TokenNameprint; - } + case 'p' : // print public private protected + switch (length) { + case 5 : + if ((data[++index] == 'r') && (data[++index] == 'i') && (data[++index] == 'n') && (data[++index] == 't')) { + return TokenNameprint; + } else + return TokenNameIdentifier; + case 6 : + if ((data[++index] == 'u') + && (data[++index] == 'b') + && (data[++index] == 'l') + && (data[++index] == 'i') + && (data[++index] == 'c')) { + return TokenNamepublic; + } else + return TokenNameIdentifier; + case 7 : + if ((data[++index] == 'r') + && (data[++index] == 'i') + && (data[++index] == 'v') + && (data[++index] == 'a') + && (data[++index] == 't') + && (data[++index] == 'e')) { + return TokenNameprivate; + } else + return TokenNameIdentifier; + case 9 : + if ((data[++index] == 'r') + && (data[++index] == 'o') + && (data[++index] == 't') + && (data[++index] == 'e') + && (data[++index] == 'c') + && (data[++index] == 't') + && (data[++index] == 'e') + && (data[++index] == 'd')) { + return TokenNameprotected; + } else + return TokenNameIdentifier; } return TokenNameIdentifier; case 'r' : //return require require_once @@ -2943,7 +3057,7 @@ public class Scanner implements IScanner, ITerminalSymbols { } else return TokenNameIdentifier; - case 's' : //static switch + case 's' : //static switch switch (length) { case 6 : if (data[++index] == 't') @@ -2964,22 +3078,43 @@ public class Scanner implements IScanner, ITerminalSymbols { return TokenNameIdentifier; } - case 't' : // true + case 't' : // try true throw switch (length) { - + case 3 : + if ((data[++index] == 'r') && (data[++index] == 'y')) + return TokenNametry; + else + return TokenNameIdentifier; case 4 : if ((data[++index] == 'r') && (data[++index] == 'u') && (data[++index] == 'e')) return TokenNametrue; else return TokenNameIdentifier; - // if ((data[++index] == 'h') && (data[++index] == 'i') && (data[++index] == 's')) - // return TokenNamethis; + case 5 : + if ((data[++index] == 'h') && (data[++index] == 'r') && (data[++index] == 'o') && (data[++index] == 'w')) + return TokenNamethrow; + else + return TokenNameIdentifier; default : return TokenNameIdentifier; } - - case 'v' : //var + case 'u' : //use unset + switch (length) { + case 3 : + if ((data[++index] == 's') && (data[++index] == 'e')) + return TokenNameuse; + else + return TokenNameIdentifier; + case 5 : + if ((data[++index] == 'n') && (data[++index] == 's') && (data[++index] == 'e') && (data[++index] == 't')) + return TokenNameunset; + else + return TokenNameIdentifier; + default : + return TokenNameIdentifier; + } + case 'v' : //var switch (length) { case 3 : if ((data[++index] == 'a') && (data[++index] == 'r')) @@ -2991,14 +3126,15 @@ public class Scanner implements IScanner, ITerminalSymbols { return TokenNameIdentifier; } - case 'w' : //while + case 'w' : //while switch (length) { case 5 : if ((data[++index] == 'h') && (data[++index] == 'i') && (data[++index] == 'l') && (data[++index] == 'e')) return TokenNamewhile; else return TokenNameIdentifier; - //case 6:if ( (data[++index] =='i') && (data[++index]=='d') && (data[++index]=='e') && (data[++index]=='f')&& (data[++index]=='p')) + //case 6:if ( (data[++index] =='i') && (data[++index]=='d') && (data[++index]=='e') && (data[++index]=='f')&& + // (data[++index]=='p')) //return TokenNamewidefp ; //else //return TokenNameIdentifier; @@ -3176,7 +3312,7 @@ public class Scanner implements IScanner, ITerminalSymbols { } /** * Search the line number corresponding to a specific position - * + * */ public final int getLineNumber(int position) { @@ -3528,177 +3664,195 @@ public class Scanner implements IScanner, ITerminalSymbols { } currentLine = null; } - - - public final void scanEscapeCharacter() throws InvalidInputException { - // the string with "\\u" is a legal string of two chars \ and u - //thus we use a direct access to the source (for regular cases). - - if (unicodeAsBackSlash) { - // consume next character - unicodeAsBackSlash = false; -// if (((currentCharacter = source[currentPosition++]) == '\\') && (source[currentPosition] == 'u')) { -// getNextUnicodeChar(); -// } else { - if (withoutUnicodePtr != 0) { - withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; -// } - } - } else - currentCharacter = source[currentPosition++]; - switch (currentCharacter) { - case 'b' : - currentCharacter = '\b'; - break; - case 't' : - currentCharacter = '\t'; - break; - case 'n' : - currentCharacter = '\n'; - break; - case 'f' : - currentCharacter = '\f'; - break; - case 'r' : - currentCharacter = '\r'; - break; - case '\"' : - currentCharacter = '\"'; - break; - case '\'' : - currentCharacter = '\''; - break; - case '\\' : - currentCharacter = '\\'; - break; - default : - // -----------octal escape-------------- - // OctalDigit - // OctalDigit OctalDigit - // ZeroToThree OctalDigit OctalDigit - - int number = Character.getNumericValue(currentCharacter); - if (number >= 0 && number <= 7) { - boolean zeroToThreeNot = number > 3; - if (Character.isDigit(currentCharacter = source[currentPosition++])) { - int digit = Character.getNumericValue(currentCharacter); - if (digit >= 0 && digit <= 7) { - number = (number * 8) + digit; - if (Character.isDigit(currentCharacter = source[currentPosition++])) { - if (zeroToThreeNot) {// has read \NotZeroToThree OctalDigit Digit --> ignore last character - currentPosition--; - } else { - digit = Character.getNumericValue(currentCharacter); - if (digit >= 0 && digit <= 7){ // has read \ZeroToThree OctalDigit OctalDigit - number = (number * 8) + digit; - } else {// has read \ZeroToThree OctalDigit NonOctalDigit --> ignore last character - currentPosition--; - } - } - } else { // has read \OctalDigit NonDigit--> ignore last character - currentPosition--; - } - } else { // has read \OctalDigit NonOctalDigit--> ignore last character - currentPosition--; - } - } else { // has read \OctalDigit --> ignore last character - currentPosition--; - } - if (number > 255) - throw new InvalidInputException(INVALID_ESCAPE); - currentCharacter = (char) number; - } else - throw new InvalidInputException(INVALID_ESCAPE); - } - } - -// chech presence of task: tags -public void checkTaskTag(int commentStart, int commentEnd) { - - // only look for newer task: tags - if (this.foundTaskCount > 0 && this.foundTaskPositions[this.foundTaskCount-1][0] >= commentStart) { - return; - } - int foundTaskIndex = this.foundTaskCount; - nextChar: for (int i = commentStart; i < commentEnd && i < this.eofPosition; i++) { - - char[] tag = null; - char[] priority = null; - - // check for tag occurrence - nextTag: for (int itag = 0; itag < this.taskTags.length; itag++){ - tag = this.taskTags[itag]; - priority = - this.taskPriorities != null && itag < this.taskPriorities.length ? - this.taskPriorities[itag] : - null; - int tagLength = tag.length; - for (int t = 0; t < tagLength; t++){ - if (this.source[i+t] != tag[t]) continue nextTag; - } - - if (this.foundTaskTags == null){ - this.foundTaskTags = new char[5][]; - this.foundTaskMessages = new char[5][]; - this.foundTaskPriorities = new char[5][]; - this.foundTaskPositions = new int[5][]; - } else if (this.foundTaskCount == this.foundTaskTags.length) { - System.arraycopy(this.foundTaskTags, 0, this.foundTaskTags = new char[this.foundTaskCount*2][], 0, this.foundTaskCount); - System.arraycopy(this.foundTaskMessages, 0, this.foundTaskMessages = new char[this.foundTaskCount*2][], 0, this.foundTaskCount); - System.arraycopy(this.foundTaskPriorities, 0, this.foundTaskPriorities = new char[this.foundTaskCount*2][], 0, this.foundTaskCount); - System.arraycopy(this.foundTaskPositions, 0, this.foundTaskPositions = new int[this.foundTaskCount*2][], 0, this.foundTaskCount); - } - this.foundTaskTags[this.foundTaskCount] = tag; - this.foundTaskPriorities[this.foundTaskCount] = priority; - this.foundTaskPositions[this.foundTaskCount] = new int[]{ i, i+tagLength-1 }; - this.foundTaskMessages[this.foundTaskCount] = CharOperation.NO_CHAR; - this.foundTaskCount++; - - i += tagLength-1; // will be incremented when looping - } - } - - for (int i = foundTaskIndex; i < this.foundTaskCount; i++) { - // retrieve message start and end positions - int msgStart = this.foundTaskPositions[i][0] + this.foundTaskTags[i].length; - int max_value = i + 1 < this.foundTaskCount ? this.foundTaskPositions[i + 1][0] - 1 : commentEnd-1; // at most beginning of next task - if (max_value < msgStart) max_value = msgStart; // would only occur if tag is before EOF. - int end = -1; - char c; - - for (int j = msgStart; j < max_value; j++){ - if ((c = this.source[j]) == '\n' || c == '\r'){ - end = j-1; - break; - } - } - - if (end == -1){ - for (int j = max_value; j > msgStart; j--){ - if ((c = this.source[j]) == '*') { - end = j-1; - break; - } - } - if (end == -1) end = max_value; - } - - if (msgStart == end) continue; // empty - - // trim the message - while (CharOperation.isWhitespace(source[end]) && msgStart <= end) end--; - while (CharOperation.isWhitespace(source[msgStart]) && msgStart <= end) msgStart++; - - // update the end position of the task - this.foundTaskPositions[i][1] = end; - - // get the message source - final int messageLength = end-msgStart+1; - char[] message = new char[messageLength]; - - System.arraycopy(source, msgStart, message, 0, messageLength); - this.foundTaskMessages[i] = message; - } -} + + public final void scanEscapeCharacter() throws InvalidInputException { + // the string with "\\u" is a legal string of two chars \ and u + //thus we use a direct access to the source (for regular cases). + + if (unicodeAsBackSlash) { + // consume next character + unicodeAsBackSlash = false; + // if (((currentCharacter = source[currentPosition++]) == '\\') && (source[currentPosition] == 'u')) { + // getNextUnicodeChar(); + // } else { + if (withoutUnicodePtr != 0) { + withoutUnicodeBuffer[++withoutUnicodePtr] = currentCharacter; + // } + } + } else + currentCharacter = source[currentPosition++]; + switch (currentCharacter) { + case 'b' : + currentCharacter = '\b'; + break; + case 't' : + currentCharacter = '\t'; + break; + case 'n' : + currentCharacter = '\n'; + break; + case 'f' : + currentCharacter = '\f'; + break; + case 'r' : + currentCharacter = '\r'; + break; + case '\"' : + currentCharacter = '\"'; + break; + case '\'' : + currentCharacter = '\''; + break; + case '\\' : + currentCharacter = '\\'; + break; + default : + // -----------octal escape-------------- + // OctalDigit + // OctalDigit OctalDigit + // ZeroToThree OctalDigit OctalDigit + + int number = Character.getNumericValue(currentCharacter); + if (number >= 0 && number <= 7) { + boolean zeroToThreeNot = number > 3; + if (Character.isDigit(currentCharacter = source[currentPosition++])) { + int digit = Character.getNumericValue(currentCharacter); + if (digit >= 0 && digit <= 7) { + number = (number * 8) + digit; + if (Character.isDigit(currentCharacter = source[currentPosition++])) { + if (zeroToThreeNot) { // has read \NotZeroToThree OctalDigit Digit --> ignore last character + currentPosition--; + } else { + digit = Character.getNumericValue(currentCharacter); + if (digit >= 0 && digit <= 7) { // has read \ZeroToThree OctalDigit OctalDigit + number = (number * 8) + digit; + } else { // has read \ZeroToThree OctalDigit NonOctalDigit --> ignore last character + currentPosition--; + } + } + } else { // has read \OctalDigit NonDigit--> ignore last character + currentPosition--; + } + } else { // has read \OctalDigit NonOctalDigit--> ignore last character + currentPosition--; + } + } else { // has read \OctalDigit --> ignore last character + currentPosition--; + } + if (number > 255) + throw new InvalidInputException(INVALID_ESCAPE); + currentCharacter = (char) number; + } else + throw new InvalidInputException(INVALID_ESCAPE); + } + } + + // chech presence of task: tags + public void checkTaskTag(int commentStart, int commentEnd) { + + // only look for newer task: tags + if (this.foundTaskCount > 0 && this.foundTaskPositions[this.foundTaskCount - 1][0] >= commentStart) { + return; + } + int foundTaskIndex = this.foundTaskCount; + nextChar : for (int i = commentStart; i < commentEnd && i < this.eofPosition; i++) { + + char[] tag = null; + char[] priority = null; + + // check for tag occurrence + nextTag : for (int itag = 0; itag < this.taskTags.length; itag++) { + tag = this.taskTags[itag]; + priority = this.taskPriorities != null && itag < this.taskPriorities.length ? this.taskPriorities[itag] : null; + int tagLength = tag.length; + for (int t = 0; t < tagLength; t++) { + if (this.source[i + t] != tag[t]) + continue nextTag; + } + + if (this.foundTaskTags == null) { + this.foundTaskTags = new char[5][]; + this.foundTaskMessages = new char[5][]; + this.foundTaskPriorities = new char[5][]; + this.foundTaskPositions = new int[5][]; + } else if (this.foundTaskCount == this.foundTaskTags.length) { + System.arraycopy(this.foundTaskTags, 0, this.foundTaskTags = new char[this.foundTaskCount * 2][], 0, this.foundTaskCount); + System.arraycopy( + this.foundTaskMessages, + 0, + this.foundTaskMessages = new char[this.foundTaskCount * 2][], + 0, + this.foundTaskCount); + System.arraycopy( + this.foundTaskPriorities, + 0, + this.foundTaskPriorities = new char[this.foundTaskCount * 2][], + 0, + this.foundTaskCount); + System.arraycopy( + this.foundTaskPositions, + 0, + this.foundTaskPositions = new int[this.foundTaskCount * 2][], + 0, + this.foundTaskCount); + } + this.foundTaskTags[this.foundTaskCount] = tag; + this.foundTaskPriorities[this.foundTaskCount] = priority; + this.foundTaskPositions[this.foundTaskCount] = new int[] { i, i + tagLength - 1 }; + this.foundTaskMessages[this.foundTaskCount] = CharOperation.NO_CHAR; + this.foundTaskCount++; + + i += tagLength - 1; // will be incremented when looping + } + } + + for (int i = foundTaskIndex; i < this.foundTaskCount; i++) { + // retrieve message start and end positions + int msgStart = this.foundTaskPositions[i][0] + this.foundTaskTags[i].length; + int max_value = i + 1 < this.foundTaskCount ? this.foundTaskPositions[i + 1][0] - 1 : commentEnd - 1; + // at most beginning of next task + if (max_value < msgStart) + max_value = msgStart; // would only occur if tag is before EOF. + int end = -1; + char c; + + for (int j = msgStart; j < max_value; j++) { + if ((c = this.source[j]) == '\n' || c == '\r') { + end = j - 1; + break; + } + } + + if (end == -1) { + for (int j = max_value; j > msgStart; j--) { + if ((c = this.source[j]) == '*') { + end = j - 1; + break; + } + } + if (end == -1) + end = max_value; + } + + if (msgStart == end) + continue; // empty + + // trim the message + while (CharOperation.isWhitespace(source[end]) && msgStart <= end) + end--; + while (CharOperation.isWhitespace(source[msgStart]) && msgStart <= end) + msgStart++; + + // update the end position of the task + this.foundTaskPositions[i][1] = end; + + // get the message source + final int messageLength = end - msgStart + 1; + char[] message = new char[messageLength]; + + System.arraycopy(source, msgStart, message, 0, messageLength); + this.foundTaskMessages[i] = message; + } + } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/JavaModelManager.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/JavaModelManager.java index 0ab7de9..1838edf 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/JavaModelManager.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/JavaModelManager.java @@ -42,7 +42,7 @@ import net.sourceforge.phpdt.core.JavaModelException; import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil; import net.sourceforge.phpeclipse.PHPCore; import net.sourceforge.phpeclipse.PHPeclipsePlugin; -import net.sourceforge.phpeclipse.builder.PHPBuilder; +import net.sourceforge.phpdt.internal.core.builder.PHPBuilder; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFolder; @@ -540,7 +540,7 @@ public class JavaModelManager implements ISaveParticipant { this.project = project; } } - public static boolean VERBOSE = false; + public static boolean VERBOSE = true; public static boolean CP_RESOLVE_VERBOSE = false; public static boolean ZIP_ACCESS_VERBOSE = false; @@ -1304,9 +1304,8 @@ public class JavaModelManager implements ISaveParticipant { throw new IOException(Util.bind("build.wrongFileFormat")); //$NON-NLS-1$ if (in.readBoolean()) return PHPBuilder.readState(project, in); -// TODO khartlage temp-del -// if (JavaBuilder.DEBUG) -// System.out.println("Saved state thinks last build failed for " + project.getName()); //$NON-NLS-1$ + if (PHPBuilder.DEBUG) + System.out.println("Saved state thinks last build failed for " + project.getName()); //$NON-NLS-1$ } finally { in.close(); } @@ -1446,8 +1445,8 @@ public class JavaModelManager implements ISaveParticipant { * Saves the built state for the project. */ private void saveBuiltState(PerProjectInfo info) throws CoreException { -// if (JavaBuilder.DEBUG) -// System.out.println(Util.bind("build.saveStateProgress", info.project.getName())); //$NON-NLS-1$ + if (PHPBuilder.DEBUG) + System.out.println(Util.bind("build.saveStateProgress", info.project.getName())); //$NON-NLS-1$ File file = getSerializationFile(info.project); if (file == null) return; long t = System.currentTimeMillis(); @@ -1476,10 +1475,10 @@ public class JavaModelManager implements ISaveParticipant { new Status(IStatus.ERROR, PHPCore.PLUGIN_ID, Platform.PLUGIN_ERROR, Util.bind("build.cannotSaveState", info.project.getName()), e)); //$NON-NLS-1$ } -// if (JavaBuilder.DEBUG) { -// t = System.currentTimeMillis() - t; -// System.out.println(Util.bind("build.saveStateComplete", String.valueOf(t))); //$NON-NLS-1$ -// } + if (PHPBuilder.DEBUG) { + t = System.currentTimeMillis() - t; + System.out.println(Util.bind("build.saveStateComplete", String.valueOf(t))); //$NON-NLS-1$ + } } /** diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/JavaProject.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/JavaProject.java index 2a0a680..a634464 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/JavaProject.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/JavaProject.java @@ -151,14 +151,14 @@ public class JavaProject if (externalPath == null) return null; -// if (JavaModelManager.VERBOSE) { -// System.out.println("JAVA MODEL - Canonicalizing " + externalPath.toString()); //$NON-NLS-1$ -// } + if (JavaModelManager.VERBOSE) { + System.out.println("JAVA MODEL - Canonicalizing " + externalPath.toString()); //$NON-NLS-1$ + } if (IS_CASE_SENSITIVE) { -// if (JavaModelManager.VERBOSE) { -// System.out.println("JAVA MODEL - Canonical path is original path (file system is case sensitive)"); //$NON-NLS-1$ -// } + if (JavaModelManager.VERBOSE) { + System.out.println("JAVA MODEL - Canonical path is original path (file system is case sensitive)"); //$NON-NLS-1$ + } return externalPath; } @@ -166,9 +166,9 @@ public class JavaProject IWorkspace workspace = ResourcesPlugin.getWorkspace(); if (workspace == null) return externalPath; // protection during shutdown (30487) if (workspace.getRoot().findMember(externalPath) != null) { -// if (JavaModelManager.VERBOSE) { -// System.out.println("JAVA MODEL - Canonical path is original path (member of workspace)"); //$NON-NLS-1$ -// } + if (JavaModelManager.VERBOSE) { + System.out.println("JAVA MODEL - Canonical path is original path (member of workspace)"); //$NON-NLS-1$ + } return externalPath; } @@ -178,9 +178,9 @@ public class JavaProject new Path(new File(externalPath.toOSString()).getCanonicalPath()); } catch (IOException e) { // default to original path -// if (JavaModelManager.VERBOSE) { -// System.out.println("JAVA MODEL - Canonical path is original path (IOException)"); //$NON-NLS-1$ -// } + if (JavaModelManager.VERBOSE) { + System.out.println("JAVA MODEL - Canonical path is original path (IOException)"); //$NON-NLS-1$ + } return externalPath; } @@ -188,9 +188,9 @@ public class JavaProject int canonicalLength = canonicalPath.segmentCount(); if (canonicalLength == 0) { // the java.io.File canonicalization failed -// if (JavaModelManager.VERBOSE) { -// System.out.println("JAVA MODEL - Canonical path is original path (canonical path is empty)"); //$NON-NLS-1$ -// } + if (JavaModelManager.VERBOSE) { + System.out.println("JAVA MODEL - Canonical path is original path (canonical path is empty)"); //$NON-NLS-1$ + } return externalPath; } else if (externalPath.isAbsolute()) { result = canonicalPath; @@ -201,9 +201,9 @@ public class JavaProject if (canonicalLength >= externalLength) { result = canonicalPath.removeFirstSegments(canonicalLength - externalLength); } else { -// if (JavaModelManager.VERBOSE) { -// System.out.println("JAVA MODEL - Canonical path is original path (canonical path is " + canonicalPath.toString() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ -// } + if (JavaModelManager.VERBOSE) { + System.out.println("JAVA MODEL - Canonical path is original path (canonical path is " + canonicalPath.toString() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ + } return externalPath; } } @@ -212,9 +212,9 @@ public class JavaProject if (externalPath.getDevice() == null) { result = result.setDevice(null); } -// if (JavaModelManager.VERBOSE) { -// System.out.println("JAVA MODEL - Canonical path is " + result.toString()); //$NON-NLS-1$ -// } + if (JavaModelManager.VERBOSE) { + System.out.println("JAVA MODEL - Canonical path is " + result.toString()); //$NON-NLS-1$ + } return result; } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/builder/BatchImageBuilder.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/builder/BatchImageBuilder.java index 579de3c..8743da1 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/builder/BatchImageBuilder.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/builder/BatchImageBuilder.java @@ -36,9 +36,9 @@ public void build() { System.out.println("FULL build"); //$NON-NLS-1$ try { -// notifier.subTask(Util.bind("build.cleaningOutput")); //$NON-NLS-1$ -// JavaModelManager.getJavaModelManager().deltaProcessor.addForRefresh(javaBuilder.javaProject); -// PHPBuilder.removeProblemsAndTasksFor(javaBuilder.currentProject); + notifier.subTask(Util.bind("build.cleaningOutput")); //$NON-NLS-1$ + JavaModelManager.getJavaModelManager().deltaProcessor.addForRefresh(javaBuilder.javaProject); + PHPBuilder.removeProblemsAndTasksFor(javaBuilder.currentProject); // cleanOutputFolders(); notifier.updateProgressDelta(0.1f); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/builder/BuildNotifier.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/builder/BuildNotifier.java index 032cf26..00dd068 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/builder/BuildNotifier.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/builder/BuildNotifier.java @@ -12,7 +12,7 @@ package net.sourceforge.phpdt.internal.core.builder; import net.sourceforge.phpdt.core.compiler.IProblem; import net.sourceforge.phpdt.internal.compiler.problem.AbortCompilation; -import net.sourceforge.phpdt.internal.compiler.util.Util; +import net.sourceforge.phpdt.internal.core.Util; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IProject; diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/builder/State.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/builder/State.java index 057d387..06bf6ca 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/builder/State.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/core/builder/State.java @@ -29,585 +29,533 @@ import org.eclipse.core.runtime.IPath; import org.eclipse.core.runtime.Path; public class State { -// NOTE: this state cannot contain types that are not defined in this project - -String javaProjectName; -ClasspathMultiDirectory[] sourceLocations; -//ClasspathLocation[] binaryLocations; -// keyed by the project relative path of the type (ie. "src1/p1/p2/A.java"), value is a ReferenceCollection or an AdditionalTypeCollection -SimpleLookupTable references; -// keyed by qualified type name "p1/p2/A", value is the project relative path which defines this type "src1/p1/p2/A.java" -SimpleLookupTable typeLocators; - -int buildNumber; -long lastStructuralBuildTime; -SimpleLookupTable structuralBuildTimes; - -private String[] knownPackageNames; // of the form "p1/p2" - -static final byte VERSION = 0x0007; - -static final byte SOURCE_FOLDER = 1; -static final byte BINARY_FOLDER = 2; -static final byte EXTERNAL_JAR = 3; -static final byte INTERNAL_JAR = 4; - -State() { -} - -protected State(PHPBuilder javaBuilder) { - this.knownPackageNames = null; - this.javaProjectName = javaBuilder.currentProject.getName(); - this.sourceLocations = javaBuilder.nameEnvironment.sourceLocations; -// this.binaryLocations = javaBuilder.nameEnvironment.binaryLocations; - this.references = new SimpleLookupTable(7); - this.typeLocators = new SimpleLookupTable(7); - - this.buildNumber = 0; // indicates a full build - this.lastStructuralBuildTime = System.currentTimeMillis(); - this.structuralBuildTimes = new SimpleLookupTable(3); -} - -void copyFrom(State lastState) { - try { - this.knownPackageNames = null; - this.buildNumber = lastState.buildNumber + 1; - this.lastStructuralBuildTime = lastState.lastStructuralBuildTime; - this.references = (SimpleLookupTable) lastState.references.clone(); - this.typeLocators = (SimpleLookupTable) lastState.typeLocators.clone(); - } catch (CloneNotSupportedException e) { - this.references = new SimpleLookupTable(lastState.references.elementSize); - Object[] keyTable = lastState.references.keyTable; - Object[] valueTable = lastState.references.valueTable; - for (int i = 0, l = keyTable.length; i < l; i++) - if (keyTable[i] != null) - this.references.put(keyTable[i], valueTable[i]); - - this.typeLocators = new SimpleLookupTable(lastState.typeLocators.elementSize); - keyTable = lastState.typeLocators.keyTable; - valueTable = lastState.typeLocators.valueTable; - for (int i = 0, l = keyTable.length; i < l; i++) - if (keyTable[i] != null) - this.typeLocators.put(keyTable[i], valueTable[i]); - } -} - -char[][] getDefinedTypeNamesFor(String typeLocator) { - Object c = references.get(typeLocator); - if (c instanceof AdditionalTypeCollection) - return ((AdditionalTypeCollection) c).definedTypeNames; - return null; // means only one type is defined with the same name as the file... saves space -} - -boolean isDuplicateLocator(String qualifiedTypeName, String typeLocator) { - String existing = (String) typeLocators.get(qualifiedTypeName); - return existing != null && !existing.equals(typeLocator); -} - -boolean isKnownPackage(String qualifiedPackageName) { - if (knownPackageNames == null) { - ArrayList names = new ArrayList(typeLocators.elementSize); - Object[] keyTable = typeLocators.keyTable; - for (int i = 0, l = keyTable.length; i < l; i++) { - if (keyTable[i] != null) { - String packageName = (String) keyTable[i]; // is a type name of the form p1/p2/A - int last = packageName.lastIndexOf('/'); - packageName = last == -1 ? null : packageName.substring(0, last); - while (packageName != null && !names.contains(packageName)) { - names.add(packageName); - last = packageName.lastIndexOf('/'); - packageName = last == -1 ? null : packageName.substring(0, last); - } - } - } - knownPackageNames = new String[names.size()]; - names.toArray(knownPackageNames); - } - for (int i = 0, l = knownPackageNames.length; i < l; i++) - if (knownPackageNames[i].equals(qualifiedPackageName)) - return true; - return false; -} - -void record(String typeLocator, char[][][] qualifiedRefs, char[][] simpleRefs, char[] mainTypeName, ArrayList typeNames) { - if (typeNames.size() == 1 && CharOperation.equals(mainTypeName, (char[]) typeNames.get(0))) { - references.put(typeLocator, new ReferenceCollection(qualifiedRefs, simpleRefs)); - } else { - char[][] definedTypeNames = new char[typeNames.size()][]; // can be empty when no types are defined - typeNames.toArray(definedTypeNames); - references.put(typeLocator, new AdditionalTypeCollection(definedTypeNames, qualifiedRefs, simpleRefs)); - } -} - -void recordLocatorForType(String qualifiedTypeName, String typeLocator) { - this.knownPackageNames = null; - typeLocators.put(qualifiedTypeName, typeLocator); -} - -void recordStructuralDependency(IProject prereqProject, State prereqState) { - if (prereqState != null) - structuralBuildTimes.put(prereqProject.getName(), new Long(prereqState.lastStructuralBuildTime)); -} - -void removeLocator(String typeLocatorToRemove) { - this.knownPackageNames = null; - references.removeKey(typeLocatorToRemove); - typeLocators.removeValue(typeLocatorToRemove); -} - -void removePackage(IResourceDelta sourceDelta) { - IResource resource = sourceDelta.getResource(); - switch(resource.getType()) { - case IResource.FOLDER : - IResourceDelta[] children = sourceDelta.getAffectedChildren(); - for (int i = 0, l = children.length; i < l; i++) - removePackage(children[i]); - return; - case IResource.FILE : - IPath typeLocatorPath = resource.getProjectRelativePath(); - if (Util.isJavaFileName(typeLocatorPath.lastSegment())) - removeLocator(typeLocatorPath.toString()); - } -} - -void removeQualifiedTypeName(String qualifiedTypeNameToRemove) { - this.knownPackageNames = null; - typeLocators.removeKey(qualifiedTypeNameToRemove); -} - -static State read(IProject project, DataInputStream in) throws IOException { - if (PHPBuilder.DEBUG) - System.out.println("About to read state..."); //$NON-NLS-1$ - if (VERSION != in.readByte()) { - if (PHPBuilder.DEBUG) - System.out.println("Found non-compatible state version... answered null"); //$NON-NLS-1$ - return null; - } - - State newState = new State(); - newState.javaProjectName = in.readUTF(); - if (!project.getName().equals(newState.javaProjectName)) { - if (PHPBuilder.DEBUG) - System.out.println("Project's name does not match... answered null"); //$NON-NLS-1$ - return null; - } - newState.buildNumber = in.readInt(); - newState.lastStructuralBuildTime = in.readLong(); - - int length = in.readInt(); - newState.sourceLocations = new ClasspathMultiDirectory[0]; -// newState.sourceLocations = new ClasspathMultiDirectory[length]; -// for (int i = 0; i < length; i++) { -// IContainer sourceFolder = project, outputFolder = project; -// String folderName; -// if ((folderName = in.readUTF()).length() > 0) sourceFolder = project.getFolder(folderName); -// if ((folderName = in.readUTF()).length() > 0) outputFolder = project.getFolder(folderName); -// ClasspathMultiDirectory md = -// (ClasspathMultiDirectory) ClasspathLocation.forSourceFolder(sourceFolder, outputFolder, readNames(in)); -// if (in.readBoolean()) -// md.hasIndependentOutputFolder = true; -// newState.sourceLocations[i] = md; -// } - - length = in.readInt(); -// newState.binaryLocations = new ClasspathLocation[length]; -// IWorkspaceRoot root = project.getWorkspace().getRoot(); -// for (int i = 0; i < length; i++) { -// switch (in.readByte()) { -// case SOURCE_FOLDER : -// newState.binaryLocations[i] = newState.sourceLocations[in.readInt()]; -// break; -// case BINARY_FOLDER : -// IPath path = new Path(in.readUTF()); -// IContainer outputFolder = path.segmentCount() == 1 -// ? (IContainer) root.getProject(path.toString()) -// : (IContainer) root.getFolder(path); -// newState.binaryLocations[i] = ClasspathLocation.forBinaryFolder(outputFolder, in.readBoolean()); -// break; -// case EXTERNAL_JAR : -// newState.binaryLocations[i] = ClasspathLocation.forLibrary(in.readUTF()); -// break; -// case INTERNAL_JAR : -// newState.binaryLocations[i] = ClasspathLocation.forLibrary(root.getFile(new Path(in.readUTF()))); -// } -// } - - newState.structuralBuildTimes = new SimpleLookupTable(length = in.readInt()); - for (int i = 0; i < length; i++) - newState.structuralBuildTimes.put(in.readUTF(), new Long(in.readLong())); - - String[] internedTypeLocators = new String[length = in.readInt()]; - for (int i = 0; i < length; i++) - internedTypeLocators[i] = in.readUTF(); - - newState.typeLocators = new SimpleLookupTable(length = in.readInt()); - for (int i = 0; i < length; i++) - newState.typeLocators.put(in.readUTF(), internedTypeLocators[in.readInt()]); - - char[][] internedSimpleNames = ReferenceCollection.internSimpleNames(readNames(in), false); - char[][][] internedQualifiedNames = new char[length = in.readInt()][][]; - for (int i = 0; i < length; i++) { - int qLength = in.readInt(); - char[][] qName = new char[qLength][]; - for (int j = 0; j < qLength; j++) - qName[j] = internedSimpleNames[in.readInt()]; - internedQualifiedNames[i] = qName; - } - internedQualifiedNames = ReferenceCollection.internQualifiedNames(internedQualifiedNames); - - newState.references = new SimpleLookupTable(length = in.readInt()); - for (int i = 0; i < length; i++) { - String typeLocator = internedTypeLocators[in.readInt()]; - ReferenceCollection collection = null; - switch (in.readByte()) { - case 1 : - char[][] additionalTypeNames = readNames(in); - char[][][] qualifiedNames = new char[in.readInt()][][]; - for (int j = 0, m = qualifiedNames.length; j < m; j++) - qualifiedNames[j] = internedQualifiedNames[in.readInt()]; - char[][] simpleNames = new char[in.readInt()][]; - for (int j = 0, m = simpleNames.length; j < m; j++) - simpleNames[j] = internedSimpleNames[in.readInt()]; - collection = new AdditionalTypeCollection(additionalTypeNames, qualifiedNames, simpleNames); - break; - case 2 : - char[][][] qNames = new char[in.readInt()][][]; - for (int j = 0, m = qNames.length; j < m; j++) - qNames[j] = internedQualifiedNames[in.readInt()]; - char[][] sNames = new char[in.readInt()][]; - for (int j = 0, m = sNames.length; j < m; j++) - sNames[j] = internedSimpleNames[in.readInt()]; - collection = new ReferenceCollection(qNames, sNames); - } - newState.references.put(typeLocator, collection); - } - if (PHPBuilder.DEBUG) - System.out.println("Successfully read state for " + newState.javaProjectName); //$NON-NLS-1$ - return newState; -} - -private static char[][] readNames(DataInputStream in) throws IOException { - int length = in.readInt(); - char[][] names = new char[length][]; - for (int i = 0; i < length; i++) { - int nLength = in.readInt(); - char[] name = new char[nLength]; - for (int j = 0; j < nLength; j++) - name[j] = in.readChar(); - names[i] = name; - } - return names; -} - -void tagAsNoopBuild() { - this.buildNumber = -1; // tag the project since it has no source folders and can be skipped -} - -boolean wasNoopBuild() { - return buildNumber == -1; -} - -void tagAsStructurallyChanged() { - this.lastStructuralBuildTime = System.currentTimeMillis(); -} - -boolean wasStructurallyChanged(IProject prereqProject, State prereqState) { - if (prereqState != null) { - Object o = structuralBuildTimes.get(prereqProject.getName()); - long previous = o == null ? 0 : ((Long) o).longValue(); - if (previous == prereqState.lastStructuralBuildTime) return false; - } - return true; -} - -void write(DataOutputStream out) throws IOException { - int length; - Object[] keyTable; - Object[] valueTable; - -/* - * byte VERSION - * String project name - * int build number - * int last structural build number -*/ - out.writeByte(VERSION); - out.writeUTF(javaProjectName); - out.writeInt(buildNumber); - out.writeLong(lastStructuralBuildTime); - -/* - * ClasspathMultiDirectory[] - * int id - * String path(s) -*/ - out.writeInt(length = sourceLocations.length); - for (int i = 0; i < length; i++) { - ClasspathMultiDirectory md = sourceLocations[i]; - out.writeUTF(md.sourceFolder.getProjectRelativePath().toString()); - out.writeUTF(md.binaryFolder.getProjectRelativePath().toString()); - writeNames(md.exclusionPatterns, out); - out.writeBoolean(md.hasIndependentOutputFolder); - } - -/* - * ClasspathLocation[] - * int id - * String path(s) -*/ -// out.writeInt(length = binaryLocations.length); -// next : for (int i = 0; i < length; i++) { -// ClasspathLocation c = binaryLocations[i]; -// if (c instanceof ClasspathMultiDirectory) { -// out.writeByte(SOURCE_FOLDER); -// for (int j = 0, m = sourceLocations.length; j < m; j++) { -// if (sourceLocations[j] == c) { -// out.writeInt(j); -// continue next; -// } -// } -// } else if (c instanceof ClasspathDirectory) { -// out.writeByte(BINARY_FOLDER); -// ClasspathDirectory cd = (ClasspathDirectory) c; -// out.writeUTF(cd.binaryFolder.getFullPath().toString()); -// out.writeBoolean(cd.isOutputFolder); -// } else { -// ClasspathJar jar = (ClasspathJar) c; -// if (jar.resource == null) { -// out.writeByte(EXTERNAL_JAR); -// out.writeUTF(jar.zipFilename); -// } else { -// out.writeByte(INTERNAL_JAR); -// out.writeUTF(jar.resource.getFullPath().toString()); -// } -// } -// } - -/* - * Structural build numbers table - * String prereq project name - * int last structural build number -*/ - out.writeInt(length = structuralBuildTimes.elementSize); - if (length > 0) { - keyTable = structuralBuildTimes.keyTable; - valueTable = structuralBuildTimes.valueTable; - for (int i = 0, l = keyTable.length; i < l; i++) { - if (keyTable[i] != null) { - length--; - out.writeUTF((String) keyTable[i]); - out.writeLong(((Long) valueTable[i]).longValue()); - } - } - if (PHPBuilder.DEBUG && length != 0) - System.out.println("structuralBuildNumbers table is inconsistent"); //$NON-NLS-1$ - } - -/* - * String[] Interned type locators - */ - out.writeInt(length = references.elementSize); - ArrayList internedTypeLocators = new ArrayList(length); - if (length > 0) { - keyTable = references.keyTable; - for (int i = 0, l = keyTable.length; i < l; i++) { - if (keyTable[i] != null) { - length--; - String key = (String) keyTable[i]; - out.writeUTF(key); - internedTypeLocators.add(key); - } - } - if (PHPBuilder.DEBUG && length != 0) - System.out.println("references table is inconsistent"); //$NON-NLS-1$ - } - -/* - * Type locators table - * String type name - * int interned locator id - */ - out.writeInt(length = typeLocators.elementSize); - if (length > 0) { - keyTable = typeLocators.keyTable; - valueTable = typeLocators.valueTable; - for (int i = 0, l = keyTable.length; i < l; i++) { - if (keyTable[i] != null) { - length--; - out.writeUTF((String) keyTable[i]); - out.writeInt(internedTypeLocators.indexOf((String) valueTable[i])); - } - } - if (PHPBuilder.DEBUG && length != 0) - System.out.println("typeLocators table is inconsistent"); //$NON-NLS-1$ - } - -/* - * char[][][] Interned qualified names - * char[][] Interned simple names - */ - ArrayList internedQualifiedNames = new ArrayList(31); - ArrayList internedSimpleNames = new ArrayList(31); - valueTable = references.valueTable; - for (int i = 0, l = valueTable.length; i < l; i++) { - if (valueTable[i] != null) { - ReferenceCollection collection = (ReferenceCollection) valueTable[i]; - char[][][] qNames = collection.qualifiedNameReferences; - for (int j = 0, m = qNames.length; j < m; j++) { - char[][] qName = qNames[j]; - if (!internedQualifiedNames.contains(qName)) { // remember the names have been interned - internedQualifiedNames.add(qName); - for (int k = 0, n = qName.length; k < n; k++) { - char[] sName = qName[k]; - if (!internedSimpleNames.contains(sName)) // remember the names have been interned - internedSimpleNames.add(sName); - } - } - } - char[][] sNames = collection.simpleNameReferences; - for (int j = 0, m = sNames.length; j < m; j++) { - char[] sName = sNames[j]; - if (!internedSimpleNames.contains(sName)) // remember the names have been interned - internedSimpleNames.add(sName); - } - } - } - char[][] internedArray = new char[internedSimpleNames.size()][]; - internedSimpleNames.toArray(internedArray); - writeNames(internedArray, out); - // now write the interned qualified names as arrays of interned simple names - out.writeInt(length = internedQualifiedNames.size()); - for (int i = 0; i < length; i++) { - char[][] qName = (char[][]) internedQualifiedNames.get(i); - int qLength = qName.length; - out.writeInt(qLength); - for (int j = 0; j < qLength; j++) - out.writeInt(internedSimpleNames.indexOf(qName[j])); - } - -/* - * References table - * int interned locator id - * ReferenceCollection -*/ - out.writeInt(length = references.elementSize); - if (length > 0) { - keyTable = references.keyTable; - for (int i = 0, l = keyTable.length; i < l; i++) { - if (keyTable[i] != null) { - length--; - out.writeInt(internedTypeLocators.indexOf((String) keyTable[i])); - ReferenceCollection collection = (ReferenceCollection) valueTable[i]; - if (collection instanceof AdditionalTypeCollection) { - out.writeByte(1); - AdditionalTypeCollection atc = (AdditionalTypeCollection) collection; - writeNames(atc.definedTypeNames, out); - } else { - out.writeByte(2); - } - char[][][] qNames = collection.qualifiedNameReferences; - int qLength = qNames.length; - out.writeInt(qLength); - for (int j = 0; j < qLength; j++) - out.writeInt(internedQualifiedNames.indexOf(qNames[j])); - char[][] sNames = collection.simpleNameReferences; - int sLength = sNames.length; - out.writeInt(sLength); - for (int j = 0; j < sLength; j++) - out.writeInt(internedSimpleNames.indexOf(sNames[j])); - } - } - if (PHPBuilder.DEBUG && length != 0) - System.out.println("references table is inconsistent"); //$NON-NLS-1$ - } -} - -private void writeNames(char[][] names, DataOutputStream out) throws IOException { - int length = names == null ? 0 : names.length; - out.writeInt(length); - for (int i = 0; i < length; i++) { - char[] name = names[i]; - int nLength = name.length; - out.writeInt(nLength); - for (int j = 0; j < nLength; j++) - out.writeChar(name[j]); - } -} - -/** - * Returns a string representation of the receiver. - */ -public String toString() { - return "State for " + javaProjectName //$NON-NLS-1$ - + " (#" + buildNumber //$NON-NLS-1$ - + " @ " + new Date(lastStructuralBuildTime) //$NON-NLS-1$ - + ")"; //$NON-NLS-1$ -} - -/* Debug helper -void dump() { - System.out.println("State for " + javaProjectName + " (" + buildNumber + " @ " + new Date(lastStructuralBuildTime) + ")"); - System.out.println("\tClass path source locations:"); - for (int i = 0, l = sourceLocations.length; i < l; i++) - System.out.println("\t\t" + sourceLocations[i]); - System.out.println("\tClass path binary locations:"); - for (int i = 0, l = binaryLocations.length; i < l; i++) - System.out.println("\t\t" + binaryLocations[i]); - - System.out.print("\tStructural build numbers table:"); - if (structuralBuildTimes.elementSize == 0) { - System.out.print(" "); - } else { - Object[] keyTable = structuralBuildTimes.keyTable; - Object[] valueTable = structuralBuildTimes.valueTable; - for (int i = 0, l = keyTable.length; i < l; i++) - if (keyTable[i] != null) - System.out.print("\n\t\t" + keyTable[i].toString() + " -> " + valueTable[i].toString()); - } - - System.out.print("\tType locators table:"); - if (typeLocators.elementSize == 0) { - System.out.print(" "); - } else { - Object[] keyTable = typeLocators.keyTable; - Object[] valueTable = typeLocators.valueTable; - for (int i = 0, l = keyTable.length; i < l; i++) - if (keyTable[i] != null) - System.out.print("\n\t\t" + keyTable[i].toString() + " -> " + valueTable[i].toString()); - } - - System.out.print("\n\tReferences table:"); - if (references.elementSize == 0) { - System.out.print(" "); - } else { - Object[] keyTable = references.keyTable; - Object[] valueTable = references.valueTable; - for (int i = 0, l = keyTable.length; i < l; i++) { - if (keyTable[i] != null) { - System.out.print("\n\t\t" + keyTable[i].toString()); - ReferenceCollection c = (ReferenceCollection) valueTable[i]; - char[][][] qRefs = c.qualifiedNameReferences; - System.out.print("\n\t\t\tqualified:"); - if (qRefs.length == 0) - System.out.print(" "); - else for (int j = 0, m = qRefs.length; j < m; j++) - System.out.print(" '" + CharOperation.toString(qRefs[j]) + "'"); - char[][] sRefs = c.simpleNameReferences; - System.out.print("\n\t\t\tsimple:"); - if (sRefs.length == 0) - System.out.print(" "); - else for (int j = 0, m = sRefs.length; j < m; j++) - System.out.print(" " + new String(sRefs[j])); - if (c instanceof AdditionalTypeCollection) { - char[][] names = ((AdditionalTypeCollection) c).definedTypeNames; - System.out.print("\n\t\t\tadditional type names:"); - for (int j = 0, m = names.length; j < m; j++) - System.out.print(" " + new String(names[j])); - } - } - } - } - System.out.print("\n\n"); -} -*/ + // NOTE: this state cannot contain types that are not defined in this project + + String javaProjectName; + ClasspathMultiDirectory[] sourceLocations; + //ClasspathLocation[] binaryLocations; + // keyed by the project relative path of the type (ie. "src1/p1/p2/A.java"), value is a ReferenceCollection or an + // AdditionalTypeCollection + SimpleLookupTable references; + // keyed by qualified type name "p1/p2/A", value is the project relative path which defines this type "src1/p1/p2/A.java" + SimpleLookupTable typeLocators; + + int buildNumber; + long lastStructuralBuildTime; + SimpleLookupTable structuralBuildTimes; + + private String[] knownPackageNames; // of the form "p1/p2" + + static final byte VERSION = 0x0007; + + static final byte SOURCE_FOLDER = 1; +// static final byte BINARY_FOLDER = 2; +// static final byte EXTERNAL_JAR = 3; +// static final byte INTERNAL_JAR = 4; + + State() { + } + + protected State(PHPBuilder javaBuilder) { + this.knownPackageNames = null; + this.javaProjectName = javaBuilder.currentProject.getName(); + this.sourceLocations = javaBuilder.nameEnvironment.sourceLocations; + // this.binaryLocations = javaBuilder.nameEnvironment.binaryLocations; + this.references = new SimpleLookupTable(7); + this.typeLocators = new SimpleLookupTable(7); + + this.buildNumber = 0; // indicates a full build + this.lastStructuralBuildTime = System.currentTimeMillis(); + this.structuralBuildTimes = new SimpleLookupTable(3); + } + + void copyFrom(State lastState) { + try { + this.knownPackageNames = null; + this.buildNumber = lastState.buildNumber + 1; + this.lastStructuralBuildTime = lastState.lastStructuralBuildTime; + this.references = (SimpleLookupTable) lastState.references.clone(); + this.typeLocators = (SimpleLookupTable) lastState.typeLocators.clone(); + } catch (CloneNotSupportedException e) { + this.references = new SimpleLookupTable(lastState.references.elementSize); + Object[] keyTable = lastState.references.keyTable; + Object[] valueTable = lastState.references.valueTable; + for (int i = 0, l = keyTable.length; i < l; i++) + if (keyTable[i] != null) + this.references.put(keyTable[i], valueTable[i]); + + this.typeLocators = new SimpleLookupTable(lastState.typeLocators.elementSize); + keyTable = lastState.typeLocators.keyTable; + valueTable = lastState.typeLocators.valueTable; + for (int i = 0, l = keyTable.length; i < l; i++) + if (keyTable[i] != null) + this.typeLocators.put(keyTable[i], valueTable[i]); + } + } + + char[][] getDefinedTypeNamesFor(String typeLocator) { + Object c = references.get(typeLocator); + if (c instanceof AdditionalTypeCollection) + return ((AdditionalTypeCollection) c).definedTypeNames; + return null; // means only one type is defined with the same name as the file... saves space + } + + boolean isDuplicateLocator(String qualifiedTypeName, String typeLocator) { + String existing = (String) typeLocators.get(qualifiedTypeName); + return existing != null && !existing.equals(typeLocator); + } + + boolean isKnownPackage(String qualifiedPackageName) { + if (knownPackageNames == null) { + ArrayList names = new ArrayList(typeLocators.elementSize); + Object[] keyTable = typeLocators.keyTable; + for (int i = 0, l = keyTable.length; i < l; i++) { + if (keyTable[i] != null) { + String packageName = (String) keyTable[i]; // is a type name of the form p1/p2/A + int last = packageName.lastIndexOf('/'); + packageName = last == -1 ? null : packageName.substring(0, last); + while (packageName != null && !names.contains(packageName)) { + names.add(packageName); + last = packageName.lastIndexOf('/'); + packageName = last == -1 ? null : packageName.substring(0, last); + } + } + } + knownPackageNames = new String[names.size()]; + names.toArray(knownPackageNames); + } + for (int i = 0, l = knownPackageNames.length; i < l; i++) + if (knownPackageNames[i].equals(qualifiedPackageName)) + return true; + return false; + } + + void record(String typeLocator, char[][][] qualifiedRefs, char[][] simpleRefs, char[] mainTypeName, ArrayList typeNames) { + if (typeNames.size() == 1 && CharOperation.equals(mainTypeName, (char[]) typeNames.get(0))) { + references.put(typeLocator, new ReferenceCollection(qualifiedRefs, simpleRefs)); + } else { + char[][] definedTypeNames = new char[typeNames.size()][]; // can be empty when no types are defined + typeNames.toArray(definedTypeNames); + references.put(typeLocator, new AdditionalTypeCollection(definedTypeNames, qualifiedRefs, simpleRefs)); + } + } + + void recordLocatorForType(String qualifiedTypeName, String typeLocator) { + this.knownPackageNames = null; + typeLocators.put(qualifiedTypeName, typeLocator); + } + + void recordStructuralDependency(IProject prereqProject, State prereqState) { + if (prereqState != null) + structuralBuildTimes.put(prereqProject.getName(), new Long(prereqState.lastStructuralBuildTime)); + } + + void removeLocator(String typeLocatorToRemove) { + this.knownPackageNames = null; + references.removeKey(typeLocatorToRemove); + typeLocators.removeValue(typeLocatorToRemove); + } + + void removePackage(IResourceDelta sourceDelta) { + IResource resource = sourceDelta.getResource(); + switch (resource.getType()) { + case IResource.FOLDER : + IResourceDelta[] children = sourceDelta.getAffectedChildren(); + for (int i = 0, l = children.length; i < l; i++) + removePackage(children[i]); + return; + case IResource.FILE : + IPath typeLocatorPath = resource.getProjectRelativePath(); + if (Util.isJavaFileName(typeLocatorPath.lastSegment())) + removeLocator(typeLocatorPath.toString()); + } + } + + void removeQualifiedTypeName(String qualifiedTypeNameToRemove) { + this.knownPackageNames = null; + typeLocators.removeKey(qualifiedTypeNameToRemove); + } + + static State read(IProject project, DataInputStream in) throws IOException { + if (PHPBuilder.DEBUG) + System.out.println("About to read state..."); //$NON-NLS-1$ + if (VERSION != in.readByte()) { + if (PHPBuilder.DEBUG) + System.out.println("Found non-compatible state version... answered null"); //$NON-NLS-1$ + return null; + } + + State newState = new State(); + newState.javaProjectName = in.readUTF(); + if (!project.getName().equals(newState.javaProjectName)) { + if (PHPBuilder.DEBUG) + System.out.println("Project's name does not match... answered null"); //$NON-NLS-1$ + return null; + } + newState.buildNumber = in.readInt(); + newState.lastStructuralBuildTime = in.readLong(); + + int length = in.readInt(); + newState.sourceLocations = new ClasspathMultiDirectory[0]; + // newState.sourceLocations = new ClasspathMultiDirectory[length]; + // for (int i = 0; i < length; i++) { + // IContainer sourceFolder = project, outputFolder = project; + // String folderName; + // if ((folderName = in.readUTF()).length() > 0) sourceFolder = project.getFolder(folderName); + // if ((folderName = in.readUTF()).length() > 0) outputFolder = project.getFolder(folderName); + // ClasspathMultiDirectory md = + // (ClasspathMultiDirectory) ClasspathLocation.forSourceFolder(sourceFolder, outputFolder, readNames(in)); + // if (in.readBoolean()) + // md.hasIndependentOutputFolder = true; + // newState.sourceLocations[i] = md; + // } + + length = in.readInt(); + // newState.binaryLocations = new ClasspathLocation[length]; + // IWorkspaceRoot root = project.getWorkspace().getRoot(); + // for (int i = 0; i < length; i++) { + // switch (in.readByte()) { + // case SOURCE_FOLDER : + // newState.binaryLocations[i] = newState.sourceLocations[in.readInt()]; + // break; + // case BINARY_FOLDER : + // IPath path = new Path(in.readUTF()); + // IContainer outputFolder = path.segmentCount() == 1 + // ? (IContainer) root.getProject(path.toString()) + // : (IContainer) root.getFolder(path); + // newState.binaryLocations[i] = ClasspathLocation.forBinaryFolder(outputFolder, in.readBoolean()); + // break; + // case EXTERNAL_JAR : + // newState.binaryLocations[i] = ClasspathLocation.forLibrary(in.readUTF()); + // break; + // case INTERNAL_JAR : + // newState.binaryLocations[i] = ClasspathLocation.forLibrary(root.getFile(new Path(in.readUTF()))); + // } + // } + + newState.structuralBuildTimes = new SimpleLookupTable(length = in.readInt()); + for (int i = 0; i < length; i++) + newState.structuralBuildTimes.put(in.readUTF(), new Long(in.readLong())); + + String[] internedTypeLocators = new String[length = in.readInt()]; + for (int i = 0; i < length; i++) + internedTypeLocators[i] = in.readUTF(); + + newState.typeLocators = new SimpleLookupTable(length = in.readInt()); + for (int i = 0; i < length; i++) + newState.typeLocators.put(in.readUTF(), internedTypeLocators[in.readInt()]); + + char[][] internedSimpleNames = ReferenceCollection.internSimpleNames(readNames(in), false); + char[][][] internedQualifiedNames = new char[length = in.readInt()][][]; + for (int i = 0; i < length; i++) { + int qLength = in.readInt(); + char[][] qName = new char[qLength][]; + for (int j = 0; j < qLength; j++) + qName[j] = internedSimpleNames[in.readInt()]; + internedQualifiedNames[i] = qName; + } + internedQualifiedNames = ReferenceCollection.internQualifiedNames(internedQualifiedNames); + + newState.references = new SimpleLookupTable(length = in.readInt()); + for (int i = 0; i < length; i++) { + String typeLocator = internedTypeLocators[in.readInt()]; + ReferenceCollection collection = null; + switch (in.readByte()) { + case 1 : + char[][] additionalTypeNames = readNames(in); + char[][][] qualifiedNames = new char[in.readInt()][][]; + for (int j = 0, m = qualifiedNames.length; j < m; j++) + qualifiedNames[j] = internedQualifiedNames[in.readInt()]; + char[][] simpleNames = new char[in.readInt()][]; + for (int j = 0, m = simpleNames.length; j < m; j++) + simpleNames[j] = internedSimpleNames[in.readInt()]; + collection = new AdditionalTypeCollection(additionalTypeNames, qualifiedNames, simpleNames); + break; + case 2 : + char[][][] qNames = new char[in.readInt()][][]; + for (int j = 0, m = qNames.length; j < m; j++) + qNames[j] = internedQualifiedNames[in.readInt()]; + char[][] sNames = new char[in.readInt()][]; + for (int j = 0, m = sNames.length; j < m; j++) + sNames[j] = internedSimpleNames[in.readInt()]; + collection = new ReferenceCollection(qNames, sNames); + } + newState.references.put(typeLocator, collection); + } + if (PHPBuilder.DEBUG) + System.out.println("Successfully read state for " + newState.javaProjectName); //$NON-NLS-1$ + return newState; + } + + private static char[][] readNames(DataInputStream in) throws IOException { + int length = in.readInt(); + char[][] names = new char[length][]; + for (int i = 0; i < length; i++) { + int nLength = in.readInt(); + char[] name = new char[nLength]; + for (int j = 0; j < nLength; j++) + name[j] = in.readChar(); + names[i] = name; + } + return names; + } + + void tagAsNoopBuild() { + this.buildNumber = -1; // tag the project since it has no source folders and can be skipped + } + + boolean wasNoopBuild() { + return buildNumber == -1; + } + + void tagAsStructurallyChanged() { + this.lastStructuralBuildTime = System.currentTimeMillis(); + } + + boolean wasStructurallyChanged(IProject prereqProject, State prereqState) { + if (prereqState != null) { + Object o = structuralBuildTimes.get(prereqProject.getName()); + long previous = o == null ? 0 : ((Long) o).longValue(); + if (previous == prereqState.lastStructuralBuildTime) + return false; + } + return true; + } + + void write(DataOutputStream out) throws IOException { + int length; + Object[] keyTable; + Object[] valueTable; + + /* + * byte VERSION String project name int build number int last structural build number + */ + out.writeByte(VERSION); + out.writeUTF(javaProjectName); + out.writeInt(buildNumber); + out.writeLong(lastStructuralBuildTime); + + /* + * ClasspathMultiDirectory[] int id String path(s) + */ + out.writeInt(length = sourceLocations.length); + for (int i = 0; i < length; i++) { + ClasspathMultiDirectory md = sourceLocations[i]; + out.writeUTF(md.sourceFolder.getProjectRelativePath().toString()); + out.writeUTF(md.binaryFolder.getProjectRelativePath().toString()); + writeNames(md.exclusionPatterns, out); + out.writeBoolean(md.hasIndependentOutputFolder); + } + + /* + * ClasspathLocation[] int id String path(s) + */ + // out.writeInt(length = binaryLocations.length); + // next : for (int i = 0; i < length; i++) { + // ClasspathLocation c = binaryLocations[i]; + // if (c instanceof ClasspathMultiDirectory) { + // out.writeByte(SOURCE_FOLDER); + // for (int j = 0, m = sourceLocations.length; j < m; j++) { + // if (sourceLocations[j] == c) { + // out.writeInt(j); + // continue next; + // } + // } + // } else if (c instanceof ClasspathDirectory) { + // out.writeByte(BINARY_FOLDER); + // ClasspathDirectory cd = (ClasspathDirectory) c; + // out.writeUTF(cd.binaryFolder.getFullPath().toString()); + // out.writeBoolean(cd.isOutputFolder); + // } else { + // ClasspathJar jar = (ClasspathJar) c; + // if (jar.resource == null) { + // out.writeByte(EXTERNAL_JAR); + // out.writeUTF(jar.zipFilename); + // } else { + // out.writeByte(INTERNAL_JAR); + // out.writeUTF(jar.resource.getFullPath().toString()); + // } + // } + // } + + /* + * Structural build numbers table String prereq project name int last structural build number + */ + out.writeInt(length = structuralBuildTimes.elementSize); + if (length > 0) { + keyTable = structuralBuildTimes.keyTable; + valueTable = structuralBuildTimes.valueTable; + for (int i = 0, l = keyTable.length; i < l; i++) { + if (keyTable[i] != null) { + length--; + out.writeUTF((String) keyTable[i]); + out.writeLong(((Long) valueTable[i]).longValue()); + } + } + if (PHPBuilder.DEBUG && length != 0) + System.out.println("structuralBuildNumbers table is inconsistent"); //$NON-NLS-1$ + } + + /* + * String[] Interned type locators + */ + out.writeInt(length = references.elementSize); + ArrayList internedTypeLocators = new ArrayList(length); + if (length > 0) { + keyTable = references.keyTable; + for (int i = 0, l = keyTable.length; i < l; i++) { + if (keyTable[i] != null) { + length--; + String key = (String) keyTable[i]; + out.writeUTF(key); + internedTypeLocators.add(key); + } + } + if (PHPBuilder.DEBUG && length != 0) + System.out.println("references table is inconsistent"); //$NON-NLS-1$ + } + + /* + * Type locators table String type name int interned locator id + */ + out.writeInt(length = typeLocators.elementSize); + if (length > 0) { + keyTable = typeLocators.keyTable; + valueTable = typeLocators.valueTable; + for (int i = 0, l = keyTable.length; i < l; i++) { + if (keyTable[i] != null) { + length--; + out.writeUTF((String) keyTable[i]); + out.writeInt(internedTypeLocators.indexOf((String) valueTable[i])); + } + } + if (PHPBuilder.DEBUG && length != 0) + System.out.println("typeLocators table is inconsistent"); //$NON-NLS-1$ + } + + /* + * char[][][] Interned qualified names char[][] Interned simple names + */ + ArrayList internedQualifiedNames = new ArrayList(31); + ArrayList internedSimpleNames = new ArrayList(31); + valueTable = references.valueTable; + for (int i = 0, l = valueTable.length; i < l; i++) { + if (valueTable[i] != null) { + ReferenceCollection collection = (ReferenceCollection) valueTable[i]; + char[][][] qNames = collection.qualifiedNameReferences; + for (int j = 0, m = qNames.length; j < m; j++) { + char[][] qName = qNames[j]; + if (!internedQualifiedNames.contains(qName)) { // remember the names have been interned + internedQualifiedNames.add(qName); + for (int k = 0, n = qName.length; k < n; k++) { + char[] sName = qName[k]; + if (!internedSimpleNames.contains(sName)) // remember the names have been interned + internedSimpleNames.add(sName); + } + } + } + char[][] sNames = collection.simpleNameReferences; + for (int j = 0, m = sNames.length; j < m; j++) { + char[] sName = sNames[j]; + if (!internedSimpleNames.contains(sName)) // remember the names have been interned + internedSimpleNames.add(sName); + } + } + } + char[][] internedArray = new char[internedSimpleNames.size()][]; + internedSimpleNames.toArray(internedArray); + writeNames(internedArray, out); + // now write the interned qualified names as arrays of interned simple names + out.writeInt(length = internedQualifiedNames.size()); + for (int i = 0; i < length; i++) { + char[][] qName = (char[][]) internedQualifiedNames.get(i); + int qLength = qName.length; + out.writeInt(qLength); + for (int j = 0; j < qLength; j++) + out.writeInt(internedSimpleNames.indexOf(qName[j])); + } + + /* + * References table int interned locator id ReferenceCollection + */ + out.writeInt(length = references.elementSize); + if (length > 0) { + keyTable = references.keyTable; + for (int i = 0, l = keyTable.length; i < l; i++) { + if (keyTable[i] != null) { + length--; + out.writeInt(internedTypeLocators.indexOf((String) keyTable[i])); + ReferenceCollection collection = (ReferenceCollection) valueTable[i]; + if (collection instanceof AdditionalTypeCollection) { + out.writeByte(1); + AdditionalTypeCollection atc = (AdditionalTypeCollection) collection; + writeNames(atc.definedTypeNames, out); + } else { + out.writeByte(2); + } + char[][][] qNames = collection.qualifiedNameReferences; + int qLength = qNames.length; + out.writeInt(qLength); + for (int j = 0; j < qLength; j++) + out.writeInt(internedQualifiedNames.indexOf(qNames[j])); + char[][] sNames = collection.simpleNameReferences; + int sLength = sNames.length; + out.writeInt(sLength); + for (int j = 0; j < sLength; j++) + out.writeInt(internedSimpleNames.indexOf(sNames[j])); + } + } + if (PHPBuilder.DEBUG && length != 0) + System.out.println("references table is inconsistent"); //$NON-NLS-1$ + } + } + + private void writeNames(char[][] names, DataOutputStream out) throws IOException { + int length = names == null ? 0 : names.length; + out.writeInt(length); + for (int i = 0; i < length; i++) { + char[] name = names[i]; + int nLength = name.length; + out.writeInt(nLength); + for (int j = 0; j < nLength; j++) + out.writeChar(name[j]); + } + } + + /** + * Returns a string representation of the receiver. + */ + public String toString() { + return "State for " + javaProjectName //$NON-NLS-1$ + +" (#" + buildNumber //$NON-NLS-1$ + +" @ " + new Date(lastStructuralBuildTime) //$NON-NLS-1$ + +")"; //$NON-NLS-1$ + } + + /* + * Debug helper void dump() { System.out.println("State for " + javaProjectName + " (" + buildNumber + " @ " + new + * Date(lastStructuralBuildTime) + ")"); System.out.println("\tClass path source locations:"); for (int i = 0, l = + * sourceLocations.length; i < l; i++) System.out.println("\t\t" + sourceLocations[i]); System.out.println("\tClass path binary + * locations:"); for (int i = 0, l = binaryLocations.length; i < l; i++) System.out.println("\t\t" + binaryLocations[i]); + * + * System.out.print("\tStructural build numbers table:"); if (structuralBuildTimes.elementSize == 0) { System.out.print(" + * "); } else { Object[] keyTable = structuralBuildTimes.keyTable; Object[] valueTable = structuralBuildTimes.valueTable; for + * (int i = 0, l = keyTable.length; i < l; i++) if (keyTable[i] != null) System.out.print("\n\t\t" + keyTable[i].toString() + " -> " + + * valueTable[i].toString()); } + * + * System.out.print("\tType locators table:"); if (typeLocators.elementSize == 0) { System.out.print(" "); } else { + * Object[] keyTable = typeLocators.keyTable; Object[] valueTable = typeLocators.valueTable; for (int i = 0, l = keyTable.length; + * i < l; i++) if (keyTable[i] != null) System.out.print("\n\t\t" + keyTable[i].toString() + " -> " + valueTable[i].toString()); } + * + * System.out.print("\n\tReferences table:"); if (references.elementSize == 0) { System.out.print(" "); } else { Object[] + * keyTable = references.keyTable; Object[] valueTable = references.valueTable; for (int i = 0, l = keyTable.length; i + * < l; i++) { if (keyTable[i] != null) { System.out.print("\n\t\t" + keyTable[i].toString()); ReferenceCollection c = + * (ReferenceCollection) valueTable[i]; char[][][] qRefs = c.qualifiedNameReferences; System.out.print("\n\t\t\tqualified:"); if + * (qRefs.length == 0) System.out.print(" "); else for (int j = 0, m = qRefs.length; j < m; j++) System.out.print(" '" + + * CharOperation.toString(qRefs[j]) + "'"); char[][] sRefs = c.simpleNameReferences; System.out.print("\n\t\t\tsimple:"); if + * (sRefs.length == 0) System.out.print(" "); else for (int j = 0, m = sRefs.length; j < m; j++) System.out.print(" " + + * new String(sRefs[j])); if (c instanceof AdditionalTypeCollection) { char[][] names = ((AdditionalTypeCollection) + * c).definedTypeNames; System.out.print("\n\t\t\tadditional type names:"); for (int j = 0, m = names.length; j < m; j++) + * System.out.print(" " + new String(names[j])); } } } } System.out.print("\n\n"); } + */ } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/HTMLPrinter.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/HTMLPrinter.java new file mode 100644 index 0000000..9ef9836 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/HTMLPrinter.java @@ -0,0 +1,152 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package net.sourceforge.phpdt.internal.ui.text; + + +import java.io.IOException; +import java.io.Reader; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.RGB; +import org.eclipse.swt.widgets.Display; + +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; + + +/** + * Provides a set of convenience methods for creating HTML pages. + */ +public class HTMLPrinter { + + private HTMLPrinter() { + } + + private static String replace(String text, char c, String s) { + + int previous= 0; + int current= text.indexOf(c, previous); + + if (current == -1) + return text; + + StringBuffer buffer= new StringBuffer(); + while (current > -1) { + buffer.append(text.substring(previous, current)); + buffer.append(s); + previous= current + 1; + current= text.indexOf(c, previous); + } + buffer.append(text.substring(previous)); + + return buffer.toString(); + } + + public static String convertToHTMLContent(String content) { + content= replace(content, '<', "<"); //$NON-NLS-1$ + return replace(content, '>', ">"); //$NON-NLS-1$ + } + + public static String read(Reader rd) { + + StringBuffer buffer= new StringBuffer(); + char[] readBuffer= new char[2048]; + + try { + int n= rd.read(readBuffer); + while (n > 0) { + buffer.append(readBuffer, 0, n); + n= rd.read(readBuffer); + } + return buffer.toString(); + } catch (IOException x) { + } + + return null; + } + + public static void insertPageProlog(StringBuffer buffer, int position, RGB bgRGB) { + if (bgRGB == null) + insertPageProlog(buffer, position); + else { + StringBuffer pageProlog= new StringBuffer(60); + pageProlog.append(""); //$NON-NLS-1$ + buffer.insert(position, pageProlog.toString()); + } + } + + private static void appendColor(StringBuffer buffer, RGB rgb) { + buffer.append('#'); + buffer.append(Integer.toHexString(rgb.red)); + buffer.append(Integer.toHexString(rgb.green)); + buffer.append(Integer.toHexString(rgb.blue)); + } + + public static void insertPageProlog(StringBuffer buffer, int position) { + RGB bgColor= null; + IWorkbenchWindow window= PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if (window != null) { + Display display= window.getShell().getDisplay(); + if (display != null && !display.isDisposed()) + bgColor= display.getSystemColor(SWT.COLOR_INFO_BACKGROUND).getRGB(); + } + if (bgColor == null) + bgColor= new RGB(255,255, 225); // RGB value of info bg color on WindowsXP + + insertPageProlog(buffer, position, bgColor); //$NON-NLS-1$ + } + + public static void addPageProlog(StringBuffer buffer) { + insertPageProlog(buffer, buffer.length()); + } + + public static void addPageEpilog(StringBuffer buffer) { + buffer.append(""); //$NON-NLS-1$ + } + + public static void startBulletList(StringBuffer buffer) { + buffer.append("
    "); //$NON-NLS-1$ + } + + public static void endBulletList(StringBuffer buffer) { + buffer.append("
"); //$NON-NLS-1$ + } + + public static void addBullet(StringBuffer buffer, String bullet) { + if (bullet != null) { + buffer.append("
  • "); //$NON-NLS-1$ + buffer.append(bullet); + buffer.append("
  • "); //$NON-NLS-1$ + } + } + + public static void addSmallHeader(StringBuffer buffer, String header) { + if (header != null) { + buffer.append("
    "); //$NON-NLS-1$ + buffer.append(header); + buffer.append("
    "); //$NON-NLS-1$ + } + } + + public static void addParagraph(StringBuffer buffer, String paragraph) { + if (paragraph != null) { + buffer.append("

    "); //$NON-NLS-1$ + buffer.append(paragraph); + } + } + + public static void addParagraph(StringBuffer buffer, Reader paragraphReader) { + if (paragraphReader != null) + addParagraph(buffer, read(paragraphReader)); + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/JavaAnnotationHover.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/JavaAnnotationHover.java index 9f6f980..c57a86d 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/JavaAnnotationHover.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/JavaAnnotationHover.java @@ -26,7 +26,6 @@ import org.eclipse.jface.text.source.Annotation; import org.eclipse.jface.text.source.IAnnotationHover; import org.eclipse.jface.text.source.IAnnotationModel; import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.ui.externaltools.internal.ant.editor.derived.HTMLPrinter; // TODO: delete this class ? we use PHPAnnotationHover instead ! /** diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/hover/JavaProblemHover.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/hover/JavaProblemHover.java index 1ca1d0b..9b019ef 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/hover/JavaProblemHover.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/hover/JavaProblemHover.java @@ -13,6 +13,7 @@ package net.sourceforge.phpdt.internal.ui.text.java.hover; import java.util.Iterator; +import net.sourceforge.phpdt.internal.ui.text.HTMLPrinter; import net.sourceforge.phpdt.ui.PreferenceConstants; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import net.sourceforge.phpeclipse.phpeditor.IJavaAnnotation; @@ -25,7 +26,6 @@ import org.eclipse.jface.text.Position; import org.eclipse.jface.text.source.Annotation; import org.eclipse.jface.text.source.IAnnotationModel; import org.eclipse.ui.IEditorPart; -import org.eclipse.ui.externaltools.internal.ant.editor.derived.HTMLPrinter; import org.eclipse.ui.texteditor.IDocumentProvider; diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/hover/JavaSourceHover.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/hover/JavaSourceHover.java index 786076f..4754b2b 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/hover/JavaSourceHover.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/hover/JavaSourceHover.java @@ -17,13 +17,13 @@ import net.sourceforge.phpdt.core.IJavaElement; import net.sourceforge.phpdt.core.IMember; import net.sourceforge.phpdt.core.ISourceReference; import net.sourceforge.phpdt.core.JavaModelException; +import net.sourceforge.phpdt.internal.ui.text.HTMLPrinter; import net.sourceforge.phpdt.internal.ui.text.PHPCodeReader; import net.sourceforge.phpdt.internal.ui.viewsupport.JavaElementLabels; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import org.eclipse.jface.text.Document; import org.eclipse.jface.text.IDocument; -import org.eclipse.ui.externaltools.internal.ant.editor.derived.HTMLPrinter; /** * Provides source as hover info for Java elements. diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/link/ILinkedPositionListener.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/link/ILinkedPositionListener.java new file mode 100644 index 0000000..1f79b44 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/link/ILinkedPositionListener.java @@ -0,0 +1,37 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ + +package net.sourceforge.phpdt.internal.ui.text.link; + +import org.eclipse.jface.text.Position; + +/** + * A listener for highlight change notification and exititing linked mode. + */ +public interface ILinkedPositionListener { + + /** + * Notifies that the linked mode has been left. On success, all changes are kept, otherwise all changes made to the linked + * positions are restored to the state before entering linked mode. + */ + void exit(int flags); + + /** + * Notifies the changed linked position. The listener is asked to reposition the caret at the given offset. + * + * @param position + * the linked position which initiated the change. + * @param caretOffset + * the caret offset relative to the position. + */ + void setCurrentPosition(Position position, int caretOffset); + +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/link/LinkedPositionManager.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/link/LinkedPositionManager.java index 0745ef7..11403b2 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/link/LinkedPositionManager.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/link/LinkedPositionManager.java @@ -1,13 +1,13 @@ -/********************************************************************** -Copyright (c) 2000, 2002 IBM Corp. and others. -All rights reserved. This program and the accompanying materials -are made available under the terms of the Common Public License v1.0 -which accompanies this distribution, and is available at -http://www.eclipse.org/legal/cpl-v10.html - -Contributors: - IBM Corporation - Initial implementation -**********************************************************************/ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ package net.sourceforge.phpdt.internal.ui.text.link; @@ -18,6 +18,7 @@ import java.util.Map; import net.sourceforge.phpeclipse.PHPeclipsePlugin; +import org.eclipse.jface.text.Assert; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.BadPositionCategoryException; import org.eclipse.jface.text.DocumentCommand; @@ -29,7 +30,7 @@ import org.eclipse.jface.text.IDocumentListener; import org.eclipse.jface.text.IPositionUpdater; import org.eclipse.jface.text.Position; import org.eclipse.jface.text.TypedPosition; -import org.eclipse.jface.util.Assert; +import org.eclipse.jface.text.contentassist.ICompletionProposal; /** @@ -99,35 +100,55 @@ public class LinkedPositionManager implements IDocumentListener, IPositionUpdate } } - private static final String LINKED_POSITION= "LinkedPositionManager.linked.position"; //$NON-NLS-1$ + private static final String LINKED_POSITION_PREFIX= "LinkedPositionManager.linked.position"; //$NON-NLS-1$ private static final Comparator fgPositionComparator= new PositionComparator(); private static final Map fgActiveManagers= new HashMap(); + private static int fgCounter= 0; private IDocument fDocument; - - private LinkedPositionListener fListener; + private ILinkedPositionListener fListener; + private String fPositionCategoryName; + private boolean fMustLeave; + /** + * Flag that records the state of this manager. As there are many different entities that may + * call leave or exit, these cannot always be sure whether the linked position infrastructure is + * still active. This is especially true for multithreaded situations. + */ + private boolean fIsActive= false; + /** * Creates a LinkedPositionManager for a IDocument. * * @param document the document to use with linked positions. + * @param canCoexist true if this manager can coexist with an already existing one */ - public LinkedPositionManager(IDocument document) { + public LinkedPositionManager(IDocument document, boolean canCoexist) { Assert.isNotNull(document); - - fDocument= document; - install(); + fDocument= document; + fPositionCategoryName= LINKED_POSITION_PREFIX + (fgCounter++); + install(canCoexist); } - + + /** + * Creates a LinkedPositionManager for a IDocument. + * + * @param document the document to use with linked positions. + */ + public LinkedPositionManager(IDocument document) { + this(document, false); + } + /** * Sets a listener to notify changes of current linked position. */ - public void setLinkedPositionListener(LinkedPositionListener listener) { + public void setLinkedPositionListener(ILinkedPositionListener listener) { fListener= listener; } /** - * Adds a linked position to the manager. + * Adds a linked position to the manager with the type being the content of + * the document at the specified range. * There are the following constraints for linked positions: * *

      @@ -141,6 +162,26 @@ public class LinkedPositionManager implements IDocumentListener, IPositionUpdate * @param length the length of the position. */ public void addPosition(int offset, int length) throws BadLocationException { + String type= fDocument.get(offset, length); + addPosition(offset, length, type); + } + + /** + * Adds a linked position of the specified position type to the manager. + * There are the following constraints for linked positions: + * + *
        + *
      • Any two positions have spacing of at least one character. + * This implies that two positions must not overlap.
      • + * + *
      • The string at any position must not contain line delimiters.
      • + *
      + * + * @param offset the offset of the position. + * @param length the length of the position. + * @param type the position type name - any positions with the same type are linked. + */ + public void addPosition(int offset, int length, String type) throws BadLocationException { Position[] positions= getPositions(fDocument); if (positions != null) { @@ -149,69 +190,158 @@ public class LinkedPositionManager implements IDocumentListener, IPositionUpdate throw new BadLocationException(LinkedPositionMessages.getString(("LinkedPositionManager.error.position.collision"))); //$NON-NLS-1$ } - String type= fDocument.get(offset, length); + String content= fDocument.get(offset, length); - if (containsLineDelimiters(type)) + if (containsLineDelimiters(content)) throw new BadLocationException(LinkedPositionMessages.getString(("LinkedPositionManager.error.contains.line.delimiters"))); //$NON-NLS-1$ try { - fDocument.addPosition(LINKED_POSITION, new TypedPosition(offset, length, type)); + fDocument.addPosition(fPositionCategoryName, new TypedPosition(offset, length, type)); } catch (BadPositionCategoryException e) { - PHPeclipsePlugin.log(e); + PHPeclipsePlugin.log(e); Assert.isTrue(false); } } + + /** + * Adds a linked position to the manager. The current document content at the specified range is + * taken as the position type. + *

      + * There are the following constraints for linked positions: + * + *

        + *
      • Any two positions have spacing of at least one character. + * This implies that two positions must not overlap.
      • + * + *
      • The string at any position must not contain line delimiters.
      • + *
      + * + * It is usually best to set the first item in additionalChoices to be equal with + * the text inserted at the current position. + *

      + * + * @param offset the offset of the position. + * @param length the length of the position. + * @param additionalChoices a number of additional choices to be displayed when selecting + * a position of this type. + */ + public void addPosition(int offset, int length, ICompletionProposal[] additionalChoices) throws BadLocationException { + String type= fDocument.get(offset, length); + addPosition(offset, length, type, additionalChoices); + } + /** + * Adds a linked position of the specified position type to the manager. + * There are the following constraints for linked positions: + * + *
        + *
      • Any two positions have spacing of at least one character. + * This implies that two positions must not overlap.
      • + * + *
      • The string at any position must not contain line delimiters.
      • + *
      + * + * It is usually best to set the first item in additionalChoices to be equal with + * the text inserted at the current position. + * + * @param offset the offset of the position. + * @param length the length of the position. + * @param type the position type name - any positions with the same type are linked. + * @param additionalChoices a number of additional choices to be displayed when selecting + * a position of this type. + */ + public void addPosition(int offset, int length, String type, ICompletionProposal[] additionalChoices) throws BadLocationException { + Position[] positions= getPositions(fDocument); + + if (positions != null) { + for (int i = 0; i < positions.length; i++) + if (collides(positions[i], offset, length)) + throw new BadLocationException(LinkedPositionMessages.getString(("LinkedPositionManager.error.position.collision"))); //$NON-NLS-1$ + } + + String content= fDocument.get(offset, length); + if (containsLineDelimiters(content)) + throw new BadLocationException(LinkedPositionMessages.getString(("LinkedPositionManager.error.contains.line.delimiters"))); //$NON-NLS-1$ + + try { + fDocument.addPosition(fPositionCategoryName, new ProposalPosition(offset, length, type, additionalChoices)); + } catch (BadPositionCategoryException e) { + PHPeclipsePlugin.log(e); + Assert.isTrue(false); + } + } + /** * Tests if a manager is already active for a document. */ public static boolean hasActiveManager(IDocument document) { return fgActiveManagers.get(document) != null; } - - private void install() { - LinkedPositionManager manager= (LinkedPositionManager) fgActiveManagers.get(fDocument); - if (manager != null) - manager.leave(true); - - fgActiveManagers.put(fDocument, this); + + private void install(boolean canCoexist) { + + if (fIsActive) + ;//JavaPlugin.log(new Status(IStatus.WARNING, JavaPlugin.getPluginId(), IStatus.OK, "LinkedPositionManager is already active: "+fPositionCategoryName, new IllegalStateException())); //$NON-NLS-1$ + else { + fIsActive= true; + //JavaPlugin.log(new Status(IStatus.INFO, JavaPlugin.getPluginId(), IStatus.OK, "LinkedPositionManager activated: "+fPositionCategoryName, new Exception())); //$NON-NLS-1$ + } - fDocument.addPositionCategory(LINKED_POSITION); + if (!canCoexist) { + LinkedPositionManager manager= (LinkedPositionManager) fgActiveManagers.get(fDocument); + if (manager != null) + manager.leave(true); + } + + fgActiveManagers.put(fDocument, this); + fDocument.addPositionCategory(fPositionCategoryName); fDocument.addPositionUpdater(this); fDocument.addDocumentListener(this); + + fMustLeave= false; } /** * Leaves the linked mode. If unsuccessful, the linked positions * are restored to the values at the time they were added. */ - public void uninstall(boolean success) { - fDocument.removeDocumentListener(this); - - try { - Position[] positions= getPositions(fDocument); - if ((!success) && (positions != null)) { - // restore - for (int i= 0; i != positions.length; i++) { - TypedPosition position= (TypedPosition) positions[i]; - fDocument.replace(position.getOffset(), position.getLength(), position.getType()); - } - } + public void uninstall(boolean success) { + + if (!fIsActive) + // we migth also just return + ;//JavaPlugin(new Status(IStatus.WARNING, JavaPlugin.getPluginId(), IStatus.OK, "LinkedPositionManager activated: "+fPositionCategoryName, new IllegalStateException())); //$NON-NLS-1$ + else { + fDocument.removeDocumentListener(this); - fDocument.removePositionCategory(LINKED_POSITION); - - } catch (BadLocationException e) { - PHPeclipsePlugin.log(e); - Assert.isTrue(false); - - } catch (BadPositionCategoryException e) { - PHPeclipsePlugin.log(e); - Assert.isTrue(false); - - } finally { - fDocument.removePositionUpdater(this); - fgActiveManagers.remove(fDocument); + try { + Position[] positions= getPositions(fDocument); + if ((!success) && (positions != null)) { + // restore + for (int i= 0; i != positions.length; i++) { + TypedPosition position= (TypedPosition) positions[i]; + fDocument.replace(position.getOffset(), position.getLength(), position.getType()); + } + } + + fDocument.removePositionCategory(fPositionCategoryName); + + fIsActive= false; + // JavaPlugin.log(new Status(IStatus.INFO, JavaPlugin.getPluginId(), IStatus.OK, "LinkedPositionManager deactivated: "+fPositionCategoryName, new Exception())); //$NON-NLS-1$ + + } catch (BadLocationException e) { + PHPeclipsePlugin.log(e); + Assert.isTrue(false); + + } catch (BadPositionCategoryException e) { + PHPeclipsePlugin.log(e); + Assert.isTrue(false); + + } finally { + fDocument.removePositionUpdater(this); + fgActiveManagers.remove(fDocument); + } } + } /** @@ -240,6 +370,22 @@ public class LinkedPositionManager implements IDocumentListener, IPositionUpdate public Position getFirstPosition() { return getNextPosition(-1); } + + public Position getLastPosition() { + Position[] positions= getPositions(fDocument); + for (int i= positions.length - 1; i >= 0; i--) { + String type= ((TypedPosition) positions[i]).getType(); + int j; + for (j = 0; j != i; j++) + if (((TypedPosition) positions[j]).getType().equals(type)) + break; + + if (j == i) + return positions[i]; + } + + return null; + } /** * Returns the next linked position with an offset greater than offset. @@ -287,22 +433,28 @@ public class LinkedPositionManager implements IDocumentListener, IPositionUpdate Position lastPosition= null; Position position= getFirstPosition(); - while ((position != null) && (position.getOffset() < offset) && !((TypedPosition) position).getType().equals(currentType)) { - lastPosition= position; + while (position != null && position.getOffset() < offset) { + if (!((TypedPosition) position).getType().equals(currentType)) + lastPosition= position; position= findNextPosition(positions, position.getOffset()); } return lastPosition; } - private static Position[] getPositions(IDocument document) { + private Position[] getPositions(IDocument document) { + + if (!fIsActive) + // we migth also just return an empty array + ;//JavaPlugin(new Status(IStatus.WARNING, JavaPlugin.getPluginId(), IStatus.OK, "LinkedPositionManager is not active: "+fPositionCategoryName, new IllegalStateException())); //$NON-NLS-1$ + try { - Position[] positions= document.getPositions(LINKED_POSITION); + Position[] positions= document.getPositions(fPositionCategoryName); Arrays.sort(positions, fgPositionComparator); return positions; } catch (BadPositionCategoryException e) { - PHPeclipsePlugin.log(e); + PHPeclipsePlugin.log(e); Assert.isTrue(false); } @@ -331,10 +483,23 @@ public class LinkedPositionManager implements IDocumentListener, IPositionUpdate } private void leave(boolean success) { - uninstall(success); - + try { + uninstall(success); + + if (fListener != null) + fListener.exit((success ? LinkedPositionUI.COMMIT : 0) | LinkedPositionUI.UPDATE_CARET); + } finally { + fMustLeave= false; + } + } + + private void abort() { + uninstall(true); // don't revert anything + if (fListener != null) - fListener.exit(success); + fListener.exit(LinkedPositionUI.COMMIT); // don't let the UI restore anything + + // don't set fMustLeave, as we will get re-registered by a document event } /* @@ -342,6 +507,11 @@ public class LinkedPositionManager implements IDocumentListener, IPositionUpdate */ public void documentAboutToBeChanged(DocumentEvent event) { + if (fMustLeave) { + event.getDocument().removeDocumentListener(this); + return; + } + IDocument document= event.getDocument(); Position[] positions= getPositions(document); @@ -351,7 +521,7 @@ public class LinkedPositionManager implements IDocumentListener, IPositionUpdate if (position == null) { // check for destruction of constraints (spacing of at least 1) if ((event.getText() == null || event.getText().length() == 0) && - (findCurrentPosition(positions, event.getOffset()) != null) && + (findCurrentPosition(positions, event.getOffset()) != null) && // will never become true, see condition above (findCurrentPosition(positions, event.getOffset() + event.getLength()) != null)) { leave(true); @@ -409,37 +579,54 @@ public class LinkedPositionManager implements IDocumentListener, IPositionUpdate * @see IPositionUpdater#update(DocumentEvent) */ public void update(DocumentEvent event) { - int deltaLength= (event.getText() == null ? 0 : event.getText().length()) - event.getLength(); + + int eventOffset= event.getOffset(); + int eventOldLength= event.getLength(); + int eventNewLength= event.getText() == null ? 0 : event.getText().length(); + int deltaLength= eventNewLength - eventOldLength; Position[] positions= getPositions(event.getDocument()); - TypedPosition currentPosition= (TypedPosition) findCurrentPosition(positions, event.getOffset()); - - // document change outside positions - if (currentPosition == null) { + + + for (int i= 0; i != positions.length; i++) { - for (int i= 0; i != positions.length; i++) { - TypedPosition position= (TypedPosition) positions[i]; - int offset= position.getOffset(); - - if (offset >= event.getOffset()) - position.setOffset(offset + deltaLength); - } + Position position= positions[i]; - // document change within a position - } else { - int length= currentPosition.getLength(); - - for (int i= 0; i != positions.length; i++) { - TypedPosition position= (TypedPosition) positions[i]; - int offset= position.getOffset(); - - if (position.equals(currentPosition)) { - position.setLength(length + deltaLength); - } else if (offset > currentPosition.getOffset()) { - position.setOffset(offset + deltaLength); - } - } + if (position.isDeleted()) + continue; + + int offset= position.getOffset(); + int length= position.getLength(); + int end= offset + length; + + if (offset > eventOffset + eventOldLength) // position comes way after change - shift + position.setOffset(offset + deltaLength); + else if (end < eventOffset) // position comes way before change - leave alone + ; + else if (offset <= eventOffset && end >= eventOffset + eventOldLength) { + // event completely internal to the position - adjust length + position.setLength(length + deltaLength); + } else if (offset < eventOffset) { + // event extends over end of position - adjust length + int newEnd= eventOffset + eventNewLength; + position.setLength(newEnd - offset); + } else if (end > eventOffset + eventOldLength) { + // event extends from before position into it - adjust offset and length + // offset becomes end of event, length ajusted acordingly + // we want to recycle the overlapping part + int newOffset = eventOffset + eventNewLength; + position.setOffset(newOffset); + position.setLength(length + deltaLength); + } else { + // event consumes the position - delete it + position.delete(); +// JavaPlugin.log(new Status(IStatus.INFO, JavaPlugin.getPluginId(), IStatus.OK, "linked position deleted -> must leave: "+fPositionCategoryName, null)); //$NON-NLS-1$ + fMustLeave= true; + } } + + if (fMustLeave) + abort(); } private static Position findCurrentPosition(Position[] positions, int offset) { @@ -477,10 +664,31 @@ public class LinkedPositionManager implements IDocumentListener, IPositionUpdate return includes(position, offset, length); } + /** + * Returns the position that includes the given range. + * @param offset + * @param length + * @return position that includes the given range + */ + public Position getEmbracingPosition(int offset, int length) { + Position[] positions= getPositions(fDocument); + + Position position= findCurrentPosition(positions, offset); + if (position != null && includes(position, offset, length)) + return position; + + return null; + } + /* * @see org.eclipse.jface.text.IAutoIndentStrategy#customizeDocumentCommand(org.eclipse.jface.text.IDocument, org.eclipse.jface.text.DocumentCommand) */ public void customizeDocumentCommand(IDocument document, DocumentCommand command) { + + if (fMustLeave) { + leave(true); + return; + } // don't interfere with preceding auto edit strategies if (command.getCommandCount() != 1) { @@ -514,11 +722,11 @@ public class LinkedPositionManager implements IDocumentListener, IPositionUpdate try { if (position.getType().equals(currentPosition.getType()) && !position.equals(currentPosition)) - command.addCommand(position.getOffset() + deltaOffset, command.length, command.text, this); + command.addCommand(position.getOffset() + deltaOffset, command.length, command.text, true, this); } catch (BadLocationException e) { - PHPeclipsePlugin.log(e); + PHPeclipsePlugin.log(e); } } } -} \ No newline at end of file +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/link/LinkedPositionUI.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/link/LinkedPositionUI.java index d02d674..7f455fe 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/link/LinkedPositionUI.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/link/LinkedPositionUI.java @@ -1,7 +1,13 @@ -/* - * (c) Copyright IBM Corp. 2000, 2001. - * All Rights Reserved. - */ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ package net.sourceforge.phpdt.internal.ui.text.link; import java.lang.reflect.InvocationTargetException; @@ -14,12 +20,14 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferenceConverter; +import org.eclipse.jface.text.Assert; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.BadPositionCategoryException; import org.eclipse.jface.text.DefaultPositionUpdater; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.IPositionUpdater; import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.IRewriteTarget; import org.eclipse.jface.text.ITextInputListener; import org.eclipse.jface.text.ITextListener; import org.eclipse.jface.text.ITextViewer; @@ -29,7 +37,8 @@ import org.eclipse.jface.text.ITextViewerExtension3; import org.eclipse.jface.text.Position; import org.eclipse.jface.text.Region; import org.eclipse.jface.text.TextEvent; -import org.eclipse.jface.util.Assert; +import org.eclipse.jface.text.TextUtilities; +import org.eclipse.jface.text.contentassist.ICompletionProposal; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; import org.eclipse.swt.SWT; @@ -50,10 +59,12 @@ import org.eclipse.swt.graphics.RGB; import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Shell; + + /** * A user interface for LinkedPositionManager, using ITextViewer. */ -public class LinkedPositionUI implements LinkedPositionListener, +public class LinkedPositionUI implements ILinkedPositionListener, ITextInputListener, ITextListener, ModifyListener, VerifyListener, VerifyKeyListener, PaintListener, IPropertyChangeListener, ShellListener { /** @@ -82,15 +93,19 @@ public class LinkedPositionUI implements LinkedPositionListener, private static final int DOCUMENT_CHANGED= 4; // document has changed public static final int UPDATE_CARET= 8; // update caret - private static final String CARET_POSITION= "LinkedPositionUI.caret.position"; //$NON-NLS-1$ - private static final IPositionUpdater fgUpdater= new DefaultPositionUpdater(CARET_POSITION); private static final IPreferenceStore fgStore= PHPeclipsePlugin.getDefault().getPreferenceStore(); + private static final String CARET_POSITION_PREFIX= "LinkedPositionUI.caret.position"; //$NON-NLS-1$ + private static int fgCounter= 0; + private final ITextViewer fViewer; - private final LinkedPositionManager fManager; + private final LinkedPositionManager fManager; + private final IPositionUpdater fUpdater; + private final String fPositionCategoryName; private Color fFrameColor; private int fFinalCaretOffset= -1; // no final caret offset + private Position fFinalCaretPosition; private Position fFramePosition; private int fInitialOffset= -1; @@ -102,6 +117,15 @@ public class LinkedPositionUI implements LinkedPositionListener, private boolean fNeedRedraw; private String fContentType; + private Position fPreviousPosition; +// private ContentAssistant2 fAssistant; + + /** + * Flag that records the state of this ui object. As there are many different entities that may + * call leave or exit, these cannot always be sure whether the linked position infrastructure is + * still active. This is especially true for multithreaded situations. + */ + private boolean fIsActive= false; /** * Creates a user interface for LinkedPositionManager. @@ -116,6 +140,9 @@ public class LinkedPositionUI implements LinkedPositionListener, fViewer= viewer; fManager= manager; + fPositionCategoryName= CARET_POSITION_PREFIX + (fgCounter++); + fUpdater= new DefaultPositionUpdater(fPositionCategoryName); + fManager.setLinkedPositionListener(this); initializeHighlightColor(viewer); @@ -176,6 +203,8 @@ public class LinkedPositionUI implements LinkedPositionListener, /** * Sets the final position of the caret when the linked mode is exited * successfully by leaving the last linked position using TAB. + * The set position will be a TAB stop as well as the positions configured in the + * LinkedPositionManager. */ public void setFinalCaretOffset(int offset) { fFinalCaretOffset= offset; @@ -201,6 +230,9 @@ public class LinkedPositionUI implements LinkedPositionListener, * @see LinkedPositionManager.LinkedPositionListener#setCurrentPositions(Position, int) */ public void setCurrentPosition(Position position, int caretOffset) { + if (!fIsActive) + ;//JavaPlugin.log(new Status(IStatus.WARNING, JavaPlugin.getPluginId(), IStatus.OK, "LinkedPositionUI is not active: "+fPositionCategoryName, new IllegalStateException())); //$NON-NLS-1$ + if (!fFramePosition.equals(position)) { fNeedRedraw= true; fFramePosition= position; @@ -216,20 +248,29 @@ public class LinkedPositionUI implements LinkedPositionListener, * @see #exit(boolean) */ public void enter() { + if (fIsActive) + ;//JavaPlugin.log(new Status(IStatus.WARNING, JavaPlugin.getPluginId(), IStatus.OK, "LinkedPositionUI is already active: "+fPositionCategoryName, new IllegalStateException())); //$NON-NLS-1$ + else { + fIsActive= true; + // JavaPlugin.log(new Status(IStatus.INFO, JavaPlugin.getPluginId(), IStatus.OK, "LinkedPositionUI activated: "+fPositionCategoryName, new Exception())); //$NON-NLS-1$ + } + // track final caret IDocument document= fViewer.getDocument(); - document.addPositionCategory(CARET_POSITION); - document.addPositionUpdater(fgUpdater); + document.addPositionCategory(fPositionCategoryName); + document.addPositionUpdater(fUpdater); try { - if (fFinalCaretOffset != -1) - document.addPosition(CARET_POSITION, new Position(fFinalCaretOffset)); + if (fFinalCaretOffset != -1) { + fFinalCaretPosition= new Position(fFinalCaretOffset); + document.addPosition(fPositionCategoryName, fFinalCaretPosition); + } } catch (BadLocationException e) { handleException(fViewer.getTextWidget().getShell(), e); } catch (BadPositionCategoryException e) { - PHPeclipsePlugin.log(e); + PHPeclipsePlugin.log(e); Assert.isTrue(false); } @@ -247,7 +288,7 @@ public class LinkedPositionUI implements LinkedPositionListener, Shell shell= text.getShell(); shell.addShellListener(this); - + fFramePosition= (fInitialOffset == -1) ? fManager.getFirstPosition() : fManager.getPosition(fInitialOffset); if (fFramePosition == null) { leave(UNINSTALL | COMMIT | UPDATE_CARET); @@ -256,25 +297,37 @@ public class LinkedPositionUI implements LinkedPositionListener, fgStore.addPropertyChangeListener(this); +// try { +// fContentType= TextUtilities.getContentType(document, IJavaPartitions.JAVA_PARTITIONING, fFramePosition.offset); +// if (fViewer instanceof ITextViewerExtension2) { +// ((ITextViewerExtension2) fViewer).prependAutoEditStrategy(fManager, fContentType); +// } else { +// Assert.isTrue(false); +// } +// +// } catch (BadLocationException e) { +// handleException(fViewer.getTextWidget().getShell(), e); +// } try { - fContentType= document.getContentType(fFramePosition.offset); - if (fViewer instanceof ITextViewerExtension2) { - ((ITextViewerExtension2) fViewer).prependAutoEditStrategy(fManager, fContentType); - } else { - Assert.isTrue(false); - } + fContentType= document.getContentType(fFramePosition.offset); + if (fViewer instanceof ITextViewerExtension2) { + ((ITextViewerExtension2) fViewer).prependAutoEditStrategy(fManager, fContentType); + } else { + Assert.isTrue(false); + } } catch (BadLocationException e) { - handleException(fViewer.getTextWidget().getShell(), e); + handleException(fViewer.getTextWidget().getShell(), e); } + selectRegion(); +// triggerContentAssist(); } /* - * @see LinkedPositionManager.LinkedPositionListener#exit(boolean) + * @see org.eclipse.jdt.internal.ui.text.link.ILinkedPositionListener#exit(boolean) */ - public void exit(boolean success) { - // no UNINSTALL since manager has already uninstalled itself - leave((success ? COMMIT : 0) | UPDATE_CARET); + public void exit(int flags) { + leave(flags); } /** @@ -282,6 +335,9 @@ public class LinkedPositionUI implements LinkedPositionListener, * enter() must be called prior to a call to this method. */ public IRegion getSelectedRegion() { + if (!fIsActive) + ;//JavaPlugin.log(new Status(IStatus.WARNING, JavaPlugin.getPluginId(), IStatus.OK, "LinkedPositionUI is not active: "+fPositionCategoryName, new IllegalStateException())); //$NON-NLS-1$ + if (fFramePosition == null) return new Region(fFinalCaretOffset, 0); else @@ -289,6 +345,13 @@ public class LinkedPositionUI implements LinkedPositionListener, } private void leave(int flags) { + if (!fIsActive) + ;//JavaPlugin.log(new Status(IStatus.WARNING, JavaPlugin.getPluginId(), IStatus.OK, "LinkedPositionUI is not active: "+fPositionCategoryName, new IllegalStateException())); //$NON-NLS-1$ + else { + fIsActive= false; + //JavaPlugin.log(new Status(IStatus.INFO, JavaPlugin.getPluginId(), IStatus.OK, "LinkedPositionUI deactivated: "+fPositionCategoryName, new Exception())); //$NON-NLS-1$ + } + fInitialOffset= -1; @@ -302,16 +365,38 @@ public class LinkedPositionUI implements LinkedPositionListener, fFrameColor= null; } - StyledText text= fViewer.getTextWidget(); + StyledText text= fViewer.getTextWidget(); + // bail out if the styled text is null, meaning the viewer has been disposed (-> document is null as well) + // see pr https://bugs.eclipse.org/bugs/show_bug.cgi?id=46821 + if (text == null) + return; + text.removePaintListener(this); text.removeModifyListener(this); text.removeVerifyListener(this); Shell shell= text.getShell(); shell.removeShellListener(this); + +// if (fAssistant != null) { +// Display display= text.getDisplay(); +// if (display != null && !display.isDisposed()) { +// display.asyncExec(new Runnable() { +// public void run() { +// if (fAssistant != null) { +// fAssistant.uninstall(); +// fAssistant= null; +// } +// } +// }); +// } +// } ITextViewerExtension extension= (ITextViewerExtension) fViewer; extension.removeVerifyKeyListener(this); + + IRewriteTarget target= extension.getRewriteTarget(); + target.endCompoundChange(); if (fViewer instanceof ITextViewerExtension2 && fContentType != null) ((ITextViewerExtension2) fViewer).removeAutoEditStrategy(fManager, fContentType); @@ -327,7 +412,7 @@ public class LinkedPositionUI implements LinkedPositionListener, ((flags & DOCUMENT_CHANGED) == 0) && ((flags & UPDATE_CARET) != 0)) { - Position[] positions= document.getPositions(CARET_POSITION); + Position[] positions= document.getPositions(fPositionCategoryName); if ((positions != null) && (positions.length != 0)) { if (fViewer instanceof ITextViewerExtension3) { @@ -345,8 +430,8 @@ public class LinkedPositionUI implements LinkedPositionListener, } } - document.removePositionUpdater(fgUpdater); - document.removePositionCategory(CARET_POSITION); + document.removePositionUpdater(fUpdater); + document.removePositionCategory(fPositionCategoryName); if (fExitListener != null) fExitListener.exit( @@ -354,7 +439,7 @@ public class LinkedPositionUI implements LinkedPositionListener, ((flags & DOCUMENT_CHANGED) != 0)); } catch (BadPositionCategoryException e) { - PHPeclipsePlugin.log(e); + PHPeclipsePlugin.log(e); Assert.isTrue(false); } @@ -363,36 +448,83 @@ public class LinkedPositionUI implements LinkedPositionListener, } private void next() { + if (!fIsActive) + ;//JavaPlugin.log(new Status(IStatus.WARNING, JavaPlugin.getPluginId(), IStatus.OK, "LinkedPositionUI is not active: "+fPositionCategoryName, new IllegalStateException())); //$NON-NLS-1$ + redrawRegion(); - fFramePosition= fManager.getNextPosition(fFramePosition.getOffset()); + if (fFramePosition == fFinalCaretPosition) + fFramePosition= fManager.getFirstPosition(); + else + fFramePosition= fManager.getNextPosition(fFramePosition.getOffset()); + if (fFramePosition == null) { + if (fFinalCaretPosition != null) + fFramePosition= fFinalCaretPosition; + else + fFramePosition= fManager.getFirstPosition(); + } if (fFramePosition == null) { leave(UNINSTALL | COMMIT | UPDATE_CARET); } else { selectRegion(); +// triggerContentAssist(); redrawRegion(); } } private void previous() { + if (!fIsActive) + ;//JavaPlugin.log(new Status(IStatus.WARNING, JavaPlugin.getPluginId(), IStatus.OK, "LinkedPositionUI is not active: "+fPositionCategoryName, new IllegalStateException())); //$NON-NLS-1$ + redrawRegion(); - Position position= fManager.getPreviousPosition(fFramePosition.getOffset()); - if (position == null) { - fViewer.getTextWidget().getDisplay().beep(); + fFramePosition= fManager.getPreviousPosition(fFramePosition.getOffset()); + if (fFramePosition == null) { + if (fFinalCaretPosition != null) + fFramePosition= fFinalCaretPosition; + else + fFramePosition= fManager.getLastPosition(); + } + if (fFramePosition == null) { + leave(UNINSTALL | COMMIT | UPDATE_CARET); } else { - fFramePosition= position; selectRegion(); +// triggerContentAssist(); redrawRegion(); } } + /** Trigger content assist on choice positions */ +// private void triggerContentAssist() { +// if (fFramePosition instanceof ProposalPosition) { +// +// ProposalPosition pp= (ProposalPosition) fFramePosition; +// initializeContentAssistant(); +// if (fAssistant == null) +// return; +// fAssistant.setCompletions(pp.getChoices()); +// fAssistant.showPossibleCompletions(); +// } else { +// if (fAssistant != null) +// fAssistant.setCompletions(new ICompletionProposal[0]); +// } +// } + + /** Lazy initialize content assistant for this linked ui */ +// private void initializeContentAssistant() { +// if (fAssistant != null) +// return; +// fAssistant= new ContentAssistant2(); +// fAssistant.setDocumentPartitioning(IJavaPartitions.JAVA_PARTITIONING); +// fAssistant.install(fViewer); +// } + /* * @see VerifyKeyListener#verifyKey(VerifyEvent) */ public void verifyKey(VerifyEvent event) { - if (!event.doit) + if (!event.doit || !fIsActive) return; Point selection= fViewer.getSelectedRange(); @@ -426,7 +558,23 @@ public class LinkedPositionUI implements LinkedPositionListener, break; // ENTER + case 0x0A: // Ctrl+Enter case 0x0D: + { +// if (fAssistant != null && fAssistant.wasProposalChosen()) { +// next(); +// event.doit= false; +// break; +// } + + // if enter was treated as a document change, would it exceed variable range? + if (!LinkedPositionManager.includes(fFramePosition, offset, length) + || (fFramePosition == fFinalCaretPosition)) { + leave(UNINSTALL | COMMIT); + return; + } + } + leave(UNINSTALL | COMMIT | UPDATE_CARET); event.doit= false; break; @@ -436,17 +584,47 @@ public class LinkedPositionUI implements LinkedPositionListener, leave(UNINSTALL | COMMIT); event.doit= false; break; + + case ';': + leave(UNINSTALL | COMMIT); + event.doit= true; + break; + + default: + if (event.character != 0) { + if (!controlUndoBehavior(offset, length) || fFramePosition == fFinalCaretPosition) { + leave(UNINSTALL | COMMIT); + break; + } + } } } - + + private boolean controlUndoBehavior(int offset, int length) { + + Position position= fManager.getEmbracingPosition(offset, length); + if (position != null) { + + ITextViewerExtension extension= (ITextViewerExtension) fViewer; + IRewriteTarget target= extension.getRewriteTarget(); + + if (fPreviousPosition != null && !fPreviousPosition.equals(position)) + target.endCompoundChange(); + target.beginCompoundChange(); + } + + fPreviousPosition= position; + return fPreviousPosition != null; + } + /* * @see VerifyListener#verifyText(VerifyEvent) */ public void verifyText(VerifyEvent event) { if (!event.doit) return; - - + + int offset= 0; int length= 0; @@ -606,7 +784,7 @@ public class LinkedPositionUI implements LinkedPositionListener, ExceptionHandler.handle((InvocationTargetException)e, shell, title, null); else { MessageDialog.openError(shell, title, e.getMessage()); - PHPeclipsePlugin.log(e); + PHPeclipsePlugin.log(e); } } @@ -659,7 +837,42 @@ public class LinkedPositionUI implements LinkedPositionListener, * @see org.eclipse.swt.events.ShellListener#shellDeactivated(org.eclipse.swt.events.ShellEvent) */ public void shellDeactivated(ShellEvent event) { - leave(UNINSTALL | COMMIT | DOCUMENT_CHANGED); + // don't deactivate on focus lost, since the proposal popups may take focus + // plus: it doesn't hurt if you can check with another window without losing linked mode + // since there is no intrusive popup sticking out. + + // need to check first what happens on reentering based on an open action + // Seems to be no problem + + // TODO check whether we can leave it or uncomment it after debugging + // PS: why DOCUMENT_CHANGED? We want to trigger a redraw! (Shell deactivated does not mean + // it is not visible any longer. +// leave(UNINSTALL | COMMIT | DOCUMENT_CHANGED); + + // Better: + // Check with content assistant and only leave if its not the proposal shell that took the + // focus away. + + StyledText text; + Display display; + +// if (fAssistant == null || fViewer == null || (text= fViewer.getTextWidget()) == null +// || (display= text.getDisplay()) == null || display.isDisposed()) { + if ( fViewer == null || (text= fViewer.getTextWidget()) == null + || (display= text.getDisplay()) == null || display.isDisposed()) { + leave(UNINSTALL | COMMIT); + } else { + // Post in UI thread since the assistant popup will only get the focus after we lose it. + display.asyncExec(new Runnable() { + public void run() { + // TODO add isDisposed / isUninstalled / hasLeft check? for now: check for content type, + // since it gets nullified in leave() + if (fIsActive) {// && (fAssistant == null || !fAssistant.hasFocus())) { + leave(UNINSTALL | COMMIT); + } + } + }); + } } /* @@ -675,4 +888,4 @@ public class LinkedPositionUI implements LinkedPositionListener, leave(UNINSTALL | COMMIT | DOCUMENT_CHANGED); } -} \ No newline at end of file +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/link/ProposalPosition.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/link/ProposalPosition.java new file mode 100644 index 0000000..46ddd75 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/link/ProposalPosition.java @@ -0,0 +1,68 @@ +/******************************************************************************* + * Copyright (c) 2000, 2003 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package net.sourceforge.phpdt.internal.ui.text.link; + +import java.util.Arrays; + +//import org.eclipse.jdt.internal.ui.text.java.JavaCompletionProposal; +import org.eclipse.jface.text.TypedPosition; +import org.eclipse.jface.text.contentassist.ICompletionProposal; + +/** + * + */ +public class ProposalPosition extends TypedPosition { + + /** The choices available for this position, fChoices[0] is the original type. */ + private final ICompletionProposal[] fChoices; + + /* + * @see java.lang.Object#equals(java.lang.Object) + */ + public boolean equals(Object o) { + if (o instanceof ProposalPosition) { + if (super.equals(o)) { + return Arrays.equals(fChoices, ((ProposalPosition)o).fChoices); + } + } + return false; + } + + /** + * @param offset + * @param length + * @param type + */ + public ProposalPosition(int offset, int length, String type, ICompletionProposal[] choices) { + super(offset, length, type); + fChoices= new ICompletionProposal[choices.length]; + System.arraycopy(choices, 0, fChoices, 0, choices.length); + } + + /** + * + * @return an array of choices, including the initial one. Clients must not modify it. + */ + public ICompletionProposal[] getChoices() { + updateChoicePositions(); + return fChoices; + } + + /** + * + */ + private void updateChoicePositions() { + for (int i= 0; i < fChoices.length; i++) { +// if (fChoices[i] instanceof JavaCompletionProposal) +// ((JavaCompletionProposal)fChoices[i]).setReplacementOffset(offset); + } + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/wizards/NewElementWizard.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/wizards/NewElementWizard.java index 65bc255..5110243 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/wizards/NewElementWizard.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/wizards/NewElementWizard.java @@ -30,105 +30,109 @@ import org.eclipse.ui.INewWizard; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PartInitException; +import org.eclipse.ui.ide.IDE; import org.eclipse.ui.wizards.newresource.BasicNewResourceWizard; - public abstract class NewElementWizard extends Wizard implements INewWizard { - private IWorkbench fWorkbench; - private IStructuredSelection fSelection; - - public NewElementWizard() { - setNeedsProgressMonitor(true); - } - - protected void openResource(final IFile resource) { - final IWorkbenchPage activePage= PHPeclipsePlugin.getActivePage(); - if (activePage != null) { - final Display display= getShell().getDisplay(); - if (display != null) { - display.asyncExec(new Runnable() { - public void run() { - try { - activePage.openEditor(resource); - } catch (PartInitException e) { - PHPeclipsePlugin.log(e); - } - } - }); - } - } - } - - /** - * Subclasses should override to perform the actions of the wizard. - * This method is run in the wizard container's context as a workspace runnable. - */ - protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException { - } - - protected void handleFinishException(Shell shell, InvocationTargetException e) { - String title= NewWizardMessages.getString("NewElementWizard.op_error.title"); //$NON-NLS-1$ - String message= NewWizardMessages.getString("NewElementWizard.op_error.message"); //$NON-NLS-1$ - ExceptionHandler.handle(e, shell, title, message); - } - - /* - * @see Wizard#performFinish - */ - public boolean performFinish() { - IWorkspaceRunnable op= new IWorkspaceRunnable() { - public void run(IProgressMonitor monitor) throws CoreException, OperationCanceledException { - try { - finishPage(monitor); - } catch (InterruptedException e) { - throw new OperationCanceledException(e.getMessage()); - } - } - }; - try { - getContainer().run(false, true, new WorkbenchRunnableAdapter(op)); - } catch (InvocationTargetException e) { - handleFinishException(getShell(), e); - return false; - } catch (InterruptedException e) { - return false; - } - return true; - } - -// protected void warnAboutTypeCommentDeprecation() { -// String key= IUIConstants.DIALOGSTORE_TYPECOMMENT_DEPRECATED; -// if (OptionalMessageDialog.isDialogEnabled(key)) { -// Templates templates= Templates.getInstance(); -// boolean isOldWorkspace= templates.getTemplates("filecomment").length > 0 && templates.getTemplates("typecomment").length > 0; //$NON-NLS-1$ //$NON-NLS-2$ -// if (!isOldWorkspace) { -// OptionalMessageDialog.setDialogEnabled(key, false); -// } -// String title= NewWizardMessages.getString("NewElementWizard.typecomment.deprecated.title"); //$NON-NLS-1$ -// String message= NewWizardMessages.getString("NewElementWizard.typecomment.deprecated.message"); //$NON-NLS-1$ -// OptionalMessageDialog.open(key, getShell(), title, OptionalMessageDialog.getDefaultImage(), message, OptionalMessageDialog.INFORMATION, new String[] { IDialogConstants.OK_LABEL }, 0); -// } -// } - - /* (non-Javadoc) - * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection) - */ - public void init(IWorkbench workbench, IStructuredSelection currentSelection) { - fWorkbench= workbench; - fSelection= currentSelection; - } - - public IStructuredSelection getSelection() { - return fSelection; - } - - public IWorkbench getWorkbench() { - return fWorkbench; - } - - protected void selectAndReveal(IResource newResource) { - BasicNewResourceWizard.selectAndReveal(newResource, fWorkbench.getActiveWorkbenchWindow()); - } + private IWorkbench fWorkbench; + private IStructuredSelection fSelection; + + public NewElementWizard() { + setNeedsProgressMonitor(true); + } + + protected void openResource(final IFile resource) { + final IWorkbenchPage activePage = PHPeclipsePlugin.getActivePage(); + if (activePage != null) { + final Display display = getShell().getDisplay(); + if (display != null) { + display.asyncExec(new Runnable() { + public void run() { + try { + IDE.openEditor(activePage, resource, true); + } catch (PartInitException e) { + PHPeclipsePlugin.log(e); + } + } + }); + } + } + } + + /** + * Subclasses should override to perform the actions of the wizard. This method is run in the wizard container's context as a + * workspace runnable. + */ + protected void finishPage(IProgressMonitor monitor) throws InterruptedException, CoreException { + } + + protected void handleFinishException(Shell shell, InvocationTargetException e) { + String title = NewWizardMessages.getString("NewElementWizard.op_error.title"); //$NON-NLS-1$ + String message = NewWizardMessages.getString("NewElementWizard.op_error.message"); //$NON-NLS-1$ + ExceptionHandler.handle(e, shell, title, message); + } + + /* + * @see Wizard#performFinish + */ + public boolean performFinish() { + IWorkspaceRunnable op = new IWorkspaceRunnable() { + public void run(IProgressMonitor monitor) throws CoreException, OperationCanceledException { + try { + finishPage(monitor); + } catch (InterruptedException e) { + throw new OperationCanceledException(e.getMessage()); + } + } + }; + try { + getContainer().run(false, true, new WorkbenchRunnableAdapter(op)); + } catch (InvocationTargetException e) { + handleFinishException(getShell(), e); + return false; + } catch (InterruptedException e) { + return false; + } + return true; + } + + // protected void warnAboutTypeCommentDeprecation() { + // String key= IUIConstants.DIALOGSTORE_TYPECOMMENT_DEPRECATED; + // if (OptionalMessageDialog.isDialogEnabled(key)) { + // Templates templates= Templates.getInstance(); + // boolean isOldWorkspace= templates.getTemplates("filecomment").length > 0 && templates.getTemplates("typecomment").length > 0; + // //$NON-NLS-1$ //$NON-NLS-2$ + // if (!isOldWorkspace) { + // OptionalMessageDialog.setDialogEnabled(key, false); + // } + // String title= NewWizardMessages.getString("NewElementWizard.typecomment.deprecated.title"); //$NON-NLS-1$ + // String message= NewWizardMessages.getString("NewElementWizard.typecomment.deprecated.message"); //$NON-NLS-1$ + // OptionalMessageDialog.open(key, getShell(), title, OptionalMessageDialog.getDefaultImage(), message, + // OptionalMessageDialog.INFORMATION, new String[] { IDialogConstants.OK_LABEL }, 0); + // } + // } + + /* + * (non-Javadoc) + * + * @see org.eclipse.ui.IWorkbenchWizard#init(org.eclipse.ui.IWorkbench, org.eclipse.jface.viewers.IStructuredSelection) + */ + public void init(IWorkbench workbench, IStructuredSelection currentSelection) { + fWorkbench = workbench; + fSelection = currentSelection; + } + + public IStructuredSelection getSelection() { + return fSelection; + } + + public IWorkbench getWorkbench() { + return fWorkbench; + } + + protected void selectAndReveal(IResource newResource) { + BasicNewResourceWizard.selectAndReveal(newResource, fWorkbench.getActiveWorkbenchWindow()); + } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPPerspectiveFactory.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPPerspectiveFactory.java index 8c9a4f0..0f29b99 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPPerspectiveFactory.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPPerspectiveFactory.java @@ -5,7 +5,7 @@ import org.eclipse.swt.SWT; import org.eclipse.ui.IFolderLayout; import org.eclipse.ui.IPageLayout; import org.eclipse.ui.IPerspectiveFactory; -import org.eclipse.update.internal.ui.UpdatePerspective; +//import org.eclipse.update.internal.ui.UpdatePerspective; public class PHPPerspectiveFactory implements IPerspectiveFactory { @@ -31,9 +31,9 @@ public class PHPPerspectiveFactory implements IPerspectiveFactory { consoleArea.addView(IPageLayout.ID_TASK_LIST); consoleArea.addView(IDebugUIConstants.ID_CONSOLE_VIEW); - if (SWT.getPlatform().equals("win32")) { - consoleArea.addView(UpdatePerspective.ID_BROWSER); - } +// if (SWT.getPlatform().equals("win32")) { +// consoleArea.addView(UpdatePerspective.ID_BROWSER); +// } consoleArea.addView(IPageLayout.ID_BOOKMARKS); layout.addView( @@ -47,9 +47,9 @@ public class PHPPerspectiveFactory implements IPerspectiveFactory { layout.addActionSet(PHPeclipsePlugin.PHP_CODING_ACTION_SET_ID); layout.addShowViewShortcut(IDebugUIConstants.ID_CONSOLE_VIEW); - if (SWT.getPlatform().equals("win32")) { - layout.addShowViewShortcut(UpdatePerspective.ID_BROWSER); - } +// if (SWT.getPlatform().equals("win32")) { +// layout.addShowViewShortcut(UpdatePerspective.ID_BROWSER); +// } // layout.addShowViewShortcut(PHPeclipsePlugin.PHP_RESOURCES_VIEW_ID); diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java index fe4136e..735cda1 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPeclipsePlugin.java @@ -75,6 +75,7 @@ import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; import org.eclipse.ui.plugin.AbstractUIPlugin; import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.ITextEditor; @@ -609,7 +610,7 @@ public class PHPeclipsePlugin extends AbstractUIPlugin implements IPreferenceCon IEditorPart editor; ITextEditor textEditor; if (file != null && file.exists()) { - editor = page.openEditor(file); + editor = IDE.openEditor(page, file, true); textEditor = (ITextEditor) editor.getAdapter(ITextEditor.class); } else { // Otherwise open the stream directly diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java index f12aa38..72fb11f 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/actions/PHPEclipseShowAction.java @@ -37,10 +37,8 @@ import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.PartInitException; import org.eclipse.ui.help.WorkbenchHelp; -import org.eclipse.update.internal.ui.UpdatePerspective; -import org.eclipse.update.internal.ui.views.IEmbeddedWebBrowser; -//import org.eclipse.jdt.internal.ui.actions.OpenBrowserUtil; -// import org.eclipse.help.ui.browser.LaunchURL; +//import org.eclipse.update.internal.ui.UpdatePerspective; +//import org.eclipse.update.internal.ui.views.IEmbeddedWebBrowser; public class PHPEclipseShowAction implements IObjectActionDelegate { private IWorkbenchPart workbenchPart; @@ -85,9 +83,12 @@ public class PHPEclipseShowAction implements IObjectActionDelegate { case IResource.FILE : // single file: IFile file = (IFile) resource; - String localhostURL; - if ((localhostURL=getLocalhostURL(store, (IFile) resource)) == null) { - MessageDialog.openInformation(shell, "Couldn't create localhost URL", "Please configure your localhost and documentRoot"); + String localhostURL; + if ((localhostURL = getLocalhostURL(store, (IFile) resource)) == null) { + MessageDialog.openInformation( + shell, + "Couldn't create localhost URL", + "Please configure your localhost and documentRoot"); return; } try { @@ -130,7 +131,7 @@ public class PHPEclipseShowAction implements IObjectActionDelegate { store = PHPeclipsePlugin.getDefault().getPreferenceStore(); } - // IPath path = file.getFullPath(); + // IPath path = file.getFullPath(); String localhostURL = file.getLocation().toString(); String lowerCaseFileName = localhostURL.toLowerCase(); @@ -144,30 +145,30 @@ public class PHPEclipseShowAction implements IObjectActionDelegate { return null; } - return store.getString(PHPeclipsePlugin.LOCALHOST_PREF) + localhostURL; + return store.getString(PHPeclipsePlugin.LOCALHOST_PREF) + localhostURL; } public static void open(final URL url, final Shell shell, final String dialogTitle) { - if (SWT.getPlatform().equals("win32")) { - IWorkbenchPage page = PHPeclipsePlugin.getActivePage(); - try { - IViewPart part = page.findView(UpdatePerspective.ID_BROWSER); - if (part == null) { - part = page.showView(UpdatePerspective.ID_BROWSER); - } else - page.bringToTop(part); - ((IEmbeddedWebBrowser) part).openTo(url.toExternalForm()); - } catch (PartInitException e) { - PHPeclipsePlugin.log(e); - } + // if (SWT.getPlatform().equals("win32")) { + // IWorkbenchPage page = PHPeclipsePlugin.getActivePage(); + // try { + // IViewPart part = page.findView(UpdatePerspective.ID_BROWSER); + // if (part == null) { + // part = page.showView(UpdatePerspective.ID_BROWSER); + // } else + // page.bringToTop(part); + // ((IEmbeddedWebBrowser) part).openTo(url.toExternalForm()); + // } catch (PartInitException e) { + // PHPeclipsePlugin.log(e); + // } + // } else { + IHelp help = WorkbenchHelp.getHelpSupport(); + if (help != null) { + WorkbenchHelp.getHelpSupport().displayHelpResource(url.toExternalForm()); } else { - IHelp help = WorkbenchHelp.getHelpSupport(); - if (help != null) { - WorkbenchHelp.getHelpSupport().displayHelpResource(url.toExternalForm()); - } else { - // showMessage(shell, dialogTitle, ActionMessages.getString("OpenBrowserUtil.help_not_available"), false); //$NON-NLS-1$ - } + // showMessage(shell, dialogTitle, ActionMessages.getString("OpenBrowserUtil.help_not_available"), false); //$NON-NLS-1$ } } + // } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/ClasspathDirectory.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/ClasspathDirectory.java deleted file mode 100644 index 8448fb7..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/ClasspathDirectory.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package net.sourceforge.phpeclipse.builder; - -import net.sourceforge.phpdt.internal.compiler.env.NameEnvironmentAnswer; -import net.sourceforge.phpdt.internal.core.Util; -import net.sourceforge.phpdt.internal.core.util.SimpleLookupTable; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IPath; - -class ClasspathDirectory extends ClasspathLocation { - -IContainer binaryFolder; // includes .class files for a single directory -boolean isOutputFolder; -String binaryLocation; -SimpleLookupTable directoryCache; -String[] missingPackageHolder = new String[1]; - -ClasspathDirectory(IContainer binaryFolder, boolean isOutputFolder) { - this.binaryFolder = binaryFolder; - this.isOutputFolder = isOutputFolder; - IPath location = binaryFolder.getLocation(); - this.binaryLocation = location != null ? location.addTrailingSeparator().toString() : ""; //$NON-NLS-1$ - - this.directoryCache = new SimpleLookupTable(5); -} - -public void cleanup() { - this.directoryCache = null; -} - -String[] directoryList(String qualifiedPackageName) { - String[] dirList = (String[]) directoryCache.get(qualifiedPackageName); - if (dirList == missingPackageHolder) return null; // package exists in another classpath directory or jar - if (dirList != null) return dirList; - - try { - IResource container = binaryFolder.findMember(qualifiedPackageName); // this is a case-sensitive check - if (container instanceof IContainer) { - IResource[] members = ((IContainer) container).members(); - dirList = new String[members.length]; - int index = 0; -// for (int i = 0, l = members.length; i < l; i++) { -// IResource m = members[i]; -// if (m.getType() == IResource.FILE && Util.isClassFileName(m.getName())) -// // add exclusion pattern check here if we want to hide .class files -// dirList[index++] = m.getName(); -// } - if (index < dirList.length) - System.arraycopy(dirList, 0, dirList = new String[index], 0, index); - directoryCache.put(qualifiedPackageName, dirList); - return dirList; - } - } catch(CoreException ignored) { - } - directoryCache.put(qualifiedPackageName, missingPackageHolder); - return null; -} - -boolean doesFileExist(String fileName, String qualifiedPackageName, String qualifiedFullName) { - String[] dirList = directoryList(qualifiedPackageName); - if (dirList == null) return false; // most common case - - for (int i = dirList.length; --i >= 0;) - if (fileName.equals(dirList[i])) - return true; - return false; -} - -public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ClasspathDirectory)) return false; - - return binaryFolder.equals(((ClasspathDirectory) o).binaryFolder); -} - -//public NameEnvironmentAnswer findClass(String binaryFileName, String qualifiedPackageName, String qualifiedBinaryFileName) { -// if (!doesFileExist(binaryFileName, qualifiedPackageName, qualifiedBinaryFileName)) return null; // most common case - -// try { -// ClassFileReader reader = ClassFileReader.read(binaryLocation + qualifiedBinaryFileName); -// if (reader != null) return new NameEnvironmentAnswer(reader); -// } catch (Exception e) {} // treat as if class file is missing -// return null; -//} - -public IPath getProjectRelativePath() { - return binaryFolder.getProjectRelativePath(); -} - -public boolean isOutputFolder() { - return isOutputFolder; -} - -public boolean isPackage(String qualifiedPackageName) { - return directoryList(qualifiedPackageName) != null; -} - -public void reset() { - this.directoryCache = new SimpleLookupTable(5); -} - -public String toString() { - return "Binary classpath directory " + binaryFolder.getFullPath().toString(); //$NON-NLS-1$ -} -} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/ClasspathLocation.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/ClasspathLocation.java deleted file mode 100644 index e96c467..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/ClasspathLocation.java +++ /dev/null @@ -1,50 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package net.sourceforge.phpeclipse.builder; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.runtime.IPath; - -public abstract class ClasspathLocation { - -static ClasspathLocation forSourceFolder(IContainer sourceFolder, IContainer outputFolder, char[][] exclusionPatterns) { - return new ClasspathMultiDirectory(sourceFolder, outputFolder, exclusionPatterns); -} - -public static ClasspathLocation forBinaryFolder(IContainer binaryFolder, boolean isOutputFolder) { - return new ClasspathDirectory(binaryFolder, isOutputFolder); -} - -//static ClasspathLocation forLibrary(String libraryPathname) { -// return new ClasspathJar(libraryPathname); -//} - -//static ClasspathLocation forLibrary(IFile library) { -// return new ClasspathJar(library); -//} - -//public abstract NameEnvironmentAnswer findClass(String binaryFileName, String qualifiedPackageName, String qualifiedBinaryFileName); - -public abstract IPath getProjectRelativePath(); - -public boolean isOutputFolder() { - return false; -} - -public abstract boolean isPackage(String qualifiedPackageName); - -// free anything which is not required when the state is saved -public void cleanup() { -} -// reset any internal caches before another compile loop starts -public void reset() { -} -} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/ClasspathMultiDirectory.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/ClasspathMultiDirectory.java deleted file mode 100644 index ad76fe2..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/ClasspathMultiDirectory.java +++ /dev/null @@ -1,48 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package net.sourceforge.phpeclipse.builder; - -import net.sourceforge.phpdt.core.compiler.CharOperation; - -import org.eclipse.core.resources.IContainer; - -class ClasspathMultiDirectory extends ClasspathDirectory { - -IContainer sourceFolder; -char[][] exclusionPatterns; // used by builders when walking source folders -boolean hasIndependentOutputFolder; // if output folder is not equal to any of the source folders - -ClasspathMultiDirectory(IContainer sourceFolder, IContainer binaryFolder, char[][] exclusionPatterns) { - super(binaryFolder, true); - - this.sourceFolder = sourceFolder; - this.exclusionPatterns = exclusionPatterns; - this.hasIndependentOutputFolder = false; - - // handle the case when a state rebuilds a source folder - if (this.exclusionPatterns != null && this.exclusionPatterns.length == 0) - this.exclusionPatterns = null; -} - -public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof ClasspathMultiDirectory)) return false; - - ClasspathMultiDirectory md = (ClasspathMultiDirectory) o; - return sourceFolder.equals(md.sourceFolder) && binaryFolder.equals(md.binaryFolder) - && CharOperation.equals(exclusionPatterns, md.exclusionPatterns); -} - -public String toString() { - return "Source classpath directory " + sourceFolder.getFullPath().toString() + //$NON-NLS-1$ - " with binary directory " + binaryFolder.getFullPath().toString(); //$NON-NLS-1$ -} -} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/PHPBuilder.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/PHPBuilder.java deleted file mode 100644 index a4a7be9..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/PHPBuilder.java +++ /dev/null @@ -1,242 +0,0 @@ -package net.sourceforge.phpeclipse.builder; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.Map; - -import net.sourceforge.phpdt.core.IJavaModelMarker; -import net.sourceforge.phpdt.internal.core.JavaProject; -import net.sourceforge.phpdt.internal.core.util.SimpleLookupTable; -import net.sourceforge.phpdt.internal.ui.util.PHPFileUtil; -import net.sourceforge.phpeclipse.PHPeclipsePlugin; -import net.sourceforge.phpeclipse.phpeditor.PHPParserAction; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.IResourceVisitor; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.resources.IncrementalProjectBuilder; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IConfigurationElement; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.OperationCanceledException; - -/** - * Builder for .php files. - * - * - * @see org.eclipse.core.resources.IncrementalProjectBuilder - * @see org.eclipse.core.resources.IResourceDelta - */ -public class PHPBuilder extends IncrementalProjectBuilder { - IProject currentProject; - JavaProject javaProject; - IWorkspaceRoot workspaceRoot; - // NameEnvironment nameEnvironment; - SimpleLookupTable binaryLocationsPerProject; - // maps a project to its binary resources (output folders, class folders, zip/jar files) - State lastState; - -// BuildNotifier notifier; - - private final static int TOTAL_WORK = 100; - - public static IMarker[] getProblemsFor(IResource resource) { - try { - if (resource != null && resource.exists()) - return resource.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE); - } catch (CoreException e) { - } // assume there are no problems - return new IMarker[0]; - } - - public static IMarker[] getTasksFor(IResource resource) { - try { - if (resource != null && resource.exists()) - return resource.findMarkers(IJavaModelMarker.TASK_MARKER, false, IResource.DEPTH_INFINITE); - } catch (CoreException e) { - } // assume there are no tasks - return new IMarker[0]; - } - - // public static void finishedBuilding(IResourceChangeEvent event) { - // BuildNotifier.resetProblemCounters(); - // } - - public static void removeProblemsFor(IResource resource) { - try { - if (resource != null && resource.exists()) - resource.deleteMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE); - } catch (CoreException e) { - } // assume there were no problems - } - - public static void removeTasksFor(IResource resource) { - try { - if (resource != null && resource.exists()) - resource.deleteMarkers(IJavaModelMarker.TASK_MARKER, false, IResource.DEPTH_INFINITE); - } catch (CoreException e) { - } // assume there were no problems - } - - public static void removeProblemsAndTasksFor(IResource resource) { - try { - if (resource != null && resource.exists()) { - resource.deleteMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, false, IResource.DEPTH_INFINITE); - resource.deleteMarkers(IJavaModelMarker.TASK_MARKER, false, IResource.DEPTH_INFINITE); - } - } catch (CoreException e) { - } // assume there were no problems - } - public static State readState(IProject project, DataInputStream in) throws IOException { - return State.read(project, in); - } - - public static void writeState(Object state, DataOutputStream out) throws IOException { - ((State) state).write(out); - } - - /** - * Constructor - */ - public PHPBuilder() { - } - - /** - * - */ - protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException { - monitor.beginTask("Parsing files", TOTAL_WORK); - this.currentProject = getProject(); - if (currentProject == null || !currentProject.isAccessible()) - return new IProject[0]; - - if (kind == IncrementalProjectBuilder.FULL_BUILD) { - IResourceDelta delta = getDelta(getProject()); - - processFull(getProject(), monitor); - - } else { // INCREMENTAL_BUILD or AUTO_BUILD - - IResourceDelta delta = getDelta(getProject()); - if (delta != null) { - delta.accept(new ParserVisitor(getProject(), monitor)); - } - - } - monitor.done(); - return null; - } - - /** - * Performs a FULL_BUILD by visiting all nodes in the resource - * tree under the specified project. - * - * @param iProject - */ - public void processFull(final IProject iProject, final IProgressMonitor monitor) { - final IdentifierIndexManager indexManager = PHPeclipsePlugin.getDefault().getIndexManager(iProject); - // Create resource visitor logic - IResourceVisitor myVisitor = new IResourceVisitor() { - public boolean visit(IResource resource) throws CoreException { - if (resource.getType() == IResource.FILE) { - if (monitor.isCanceled()) { - throw new OperationCanceledException(); - } - if ((resource.getFileExtension() != null) && PHPFileUtil.isPHPFile((IFile) resource)) { - monitor.worked(1); - monitor.subTask("Parsing: " + resource.getFullPath()); - // check for parsing errors - PHPParserAction.parseFile((IFile) resource); - // update indexfile for the project: - JavaProject nature = (JavaProject) iProject.getNature(PHPeclipsePlugin.PHP_NATURE_ID); - indexManager.addFile((IFile) resource); - } - } - - return true; - } - }; - - // Process the project using the visitor just created - try { - - // if (iProject.hasNature(PHPeclipsePlugin.PHP_NATURE_ID)) { - // thePHPProject = new PHPProject(); - // thePHPProject.setProject(iProject); - // } - indexManager.initialize(); - iProject.accept(myVisitor); - indexManager.writeFile(); - } catch (CoreException e) { - e.printStackTrace(); - } - - } - - /** - * Sets initialization data for this builder. - *

      - * This method is part of the IExecutableExtension - * interface. - *

      - *

      - * Subclasses are free to extend this method to pick up - * initialization parameters from the plug-in plug-in manifest - * (plugin.xml) file, - * but should be sure to invoke this method on their superclass. - *

      - * For example, the following method looks for a boolean-valued - * parameter named "trace": - *

      -   *     public void setInitializationData(IConfigurationElement cfig, 
      -   *             String propertyName, Object data) 
      -   * 		        throws CoreException {
      -   *         super.setInitializationData(cfig, propertyName, data);
      -   *         if (data instanceof Hashtable) { 
      -   *             Hashtable args = (Hashtable) data; 
      -   *             String traceValue = (String) args.get("trace"); 
      -   *             TRACING = (traceValue!=null && traceValue.equals("true"));
      -   *         }
      -   *     }
      -   * 
      - *

      - */ - public void setInitializationData(IConfigurationElement config, String propertyName, Object data) throws CoreException { - super.setInitializationData(config, propertyName, data); - - } - - /** - * Informs this builder that it is being started by the build management - * infrastructure. By the time this method is run, the builder's project - * is available and setInitializationData has been called. - * The default implementation should be called by all overriding methods. - * - * @see #setInitializationData - */ - protected void startupOnInitialize() { - // traceMsg("Parse Builder Initialize - startupOnInitialize()"); - } - - /** - * Write trace statements. - * System.out.println with prefix tagging used for simplicity. - */ - // private void traceMsg(String msg) { - // if (PHPeclipsePlugin.DEBUG | traceEnabled) - // System.out.println( - // buildMode - // + "<" - // + getProject() - // + "> " - // + "\t\t\t" - // + buildMark - // + msg); - // } - -} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/State.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/State.java deleted file mode 100644 index 754ecbe..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/builder/State.java +++ /dev/null @@ -1,612 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2000, 2003 IBM Corporation and others. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Common Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/cpl-v10.html - * - * Contributors: - * IBM Corporation - initial API and implementation - *******************************************************************************/ -package net.sourceforge.phpeclipse.builder; - -import java.io.DataInputStream; -import java.io.DataOutputStream; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Date; - -import net.sourceforge.phpdt.internal.core.Util; -import net.sourceforge.phpdt.internal.core.util.SimpleLookupTable; - -import org.eclipse.core.resources.IContainer; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.IWorkspaceRoot; -import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.Path; - -public class State { -// NOTE: this state cannot contain types that are not defined in this project - -String javaProjectName; -ClasspathMultiDirectory[] sourceLocations; -ClasspathLocation[] binaryLocations; -// keyed by the project relative path of the type (ie. "src1/p1/p2/A.java"), value is a ReferenceCollection or an AdditionalTypeCollection -SimpleLookupTable references; -// keyed by qualified type name "p1/p2/A", value is the project relative path which defines this type "src1/p1/p2/A.java" -SimpleLookupTable typeLocators; - -int buildNumber; -long lastStructuralBuildTime; -SimpleLookupTable structuralBuildTimes; - -private String[] knownPackageNames; // of the form "p1/p2" - -static final byte VERSION = 0x0007; - -static final byte SOURCE_FOLDER = 1; -static final byte BINARY_FOLDER = 2; -static final byte EXTERNAL_JAR = 3; -static final byte INTERNAL_JAR = 4; - -State() { -} - -protected State(PHPBuilder javaBuilder) { - this.knownPackageNames = null; - this.javaProjectName = javaBuilder.currentProject.getName(); - -// this.sourceLocations = javaBuilder.nameEnvironment.sourceLocations; -// this.binaryLocations = javaBuilder.nameEnvironment.binaryLocations; - this.references = new SimpleLookupTable(7); - this.typeLocators = new SimpleLookupTable(7); - - this.buildNumber = 0; // indicates a full build - this.lastStructuralBuildTime = System.currentTimeMillis(); - this.structuralBuildTimes = new SimpleLookupTable(3); -} - -void copyFrom(State lastState) { - try { - this.knownPackageNames = null; - this.buildNumber = lastState.buildNumber + 1; - this.lastStructuralBuildTime = lastState.lastStructuralBuildTime; - this.references = (SimpleLookupTable) lastState.references.clone(); - this.typeLocators = (SimpleLookupTable) lastState.typeLocators.clone(); - } catch (CloneNotSupportedException e) { - this.references = new SimpleLookupTable(lastState.references.elementSize); - Object[] keyTable = lastState.references.keyTable; - Object[] valueTable = lastState.references.valueTable; - for (int i = 0, l = keyTable.length; i < l; i++) - if (keyTable[i] != null) - this.references.put(keyTable[i], valueTable[i]); - - this.typeLocators = new SimpleLookupTable(lastState.typeLocators.elementSize); - keyTable = lastState.typeLocators.keyTable; - valueTable = lastState.typeLocators.valueTable; - for (int i = 0, l = keyTable.length; i < l; i++) - if (keyTable[i] != null) - this.typeLocators.put(keyTable[i], valueTable[i]); - } -} - -char[][] getDefinedTypeNamesFor(String typeLocator) { - Object c = references.get(typeLocator); -// if (c instanceof AdditionalTypeCollection) -// return ((AdditionalTypeCollection) c).definedTypeNames; - return null; // means only one type is defined with the same name as the file... saves space -} - -boolean isDuplicateLocator(String qualifiedTypeName, String typeLocator) { - String existing = (String) typeLocators.get(qualifiedTypeName); - return existing != null && !existing.equals(typeLocator); -} - -boolean isKnownPackage(String qualifiedPackageName) { - if (knownPackageNames == null) { - ArrayList names = new ArrayList(typeLocators.elementSize); - Object[] keyTable = typeLocators.keyTable; - for (int i = 0, l = keyTable.length; i < l; i++) { - if (keyTable[i] != null) { - String packageName = (String) keyTable[i]; // is a type name of the form p1/p2/A - int last = packageName.lastIndexOf('/'); - packageName = last == -1 ? null : packageName.substring(0, last); - while (packageName != null && !names.contains(packageName)) { - names.add(packageName); - last = packageName.lastIndexOf('/'); - packageName = last == -1 ? null : packageName.substring(0, last); - } - } - } - knownPackageNames = new String[names.size()]; - names.toArray(knownPackageNames); - } - for (int i = 0, l = knownPackageNames.length; i < l; i++) - if (knownPackageNames[i].equals(qualifiedPackageName)) - return true; - return false; -} - -void record(String typeLocator, char[][][] qualifiedRefs, char[][] simpleRefs, char[] mainTypeName, ArrayList typeNames) { -// if (typeNames.size() == 1 && CharOperation.equals(mainTypeName, (char[]) typeNames.get(0))) { -// references.put(typeLocator, new ReferenceCollection(qualifiedRefs, simpleRefs)); -// } else { -// char[][] definedTypeNames = new char[typeNames.size()][]; // can be empty when no types are defined -// typeNames.toArray(definedTypeNames); -// references.put(typeLocator, new AdditionalTypeCollection(definedTypeNames, qualifiedRefs, simpleRefs)); -// } -} - -void recordLocatorForType(String qualifiedTypeName, String typeLocator) { - this.knownPackageNames = null; - typeLocators.put(qualifiedTypeName, typeLocator); -} - -void recordStructuralDependency(IProject prereqProject, State prereqState) { - if (prereqState != null) - structuralBuildTimes.put(prereqProject.getName(), new Long(prereqState.lastStructuralBuildTime)); -} - -void removeLocator(String typeLocatorToRemove) { - this.knownPackageNames = null; - references.removeKey(typeLocatorToRemove); - typeLocators.removeValue(typeLocatorToRemove); -} - -void removePackage(IResourceDelta sourceDelta) { - IResource resource = sourceDelta.getResource(); - switch(resource.getType()) { - case IResource.FOLDER : - IResourceDelta[] children = sourceDelta.getAffectedChildren(); - for (int i = 0, l = children.length; i < l; i++) - removePackage(children[i]); - return; - case IResource.FILE : - IPath typeLocatorPath = resource.getProjectRelativePath(); - if (Util.isJavaFileName(typeLocatorPath.lastSegment())) - removeLocator(typeLocatorPath.toString()); - } -} - -void removeQualifiedTypeName(String qualifiedTypeNameToRemove) { - this.knownPackageNames = null; - typeLocators.removeKey(qualifiedTypeNameToRemove); -} - -static State read(IProject project, DataInputStream in) throws IOException { -// if (JavaBuilder.DEBUG) -// System.out.println("About to read state..."); //$NON-NLS-1$ - if (VERSION != in.readByte()) { -// if (JavaBuilder.DEBUG) -// System.out.println("Found non-compatible state version... answered null"); //$NON-NLS-1$ - return null; - } - - State newState = new State(); - newState.javaProjectName = in.readUTF(); - if (!project.getName().equals(newState.javaProjectName)) { -// if (JavaBuilder.DEBUG) -// System.out.println("Project's name does not match... answered null"); //$NON-NLS-1$ - return null; - } - newState.buildNumber = in.readInt(); - newState.lastStructuralBuildTime = in.readLong(); - - int length = in.readInt(); - newState.sourceLocations = new ClasspathMultiDirectory[length]; - for (int i = 0; i < length; i++) { - IContainer sourceFolder = project, outputFolder = project; - String folderName; - if ((folderName = in.readUTF()).length() > 0) sourceFolder = project.getFolder(folderName); - if ((folderName = in.readUTF()).length() > 0) outputFolder = project.getFolder(folderName); - ClasspathMultiDirectory md = - (ClasspathMultiDirectory) ClasspathLocation.forSourceFolder(sourceFolder, outputFolder, readNames(in)); - if (in.readBoolean()) - md.hasIndependentOutputFolder = true; - newState.sourceLocations[i] = md; - } - - length = in.readInt(); - newState.binaryLocations = new ClasspathLocation[length]; - IWorkspaceRoot root = project.getWorkspace().getRoot(); - for (int i = 0; i < length; i++) { - switch (in.readByte()) { - case SOURCE_FOLDER : - newState.binaryLocations[i] = newState.sourceLocations[in.readInt()]; - break; - case BINARY_FOLDER : - IPath path = new Path(in.readUTF()); - IContainer outputFolder = path.segmentCount() == 1 - ? (IContainer) root.getProject(path.toString()) - : (IContainer) root.getFolder(path); - newState.binaryLocations[i] = ClasspathLocation.forBinaryFolder(outputFolder, in.readBoolean()); - break; -// case EXTERNAL_JAR : -// newState.binaryLocations[i] = ClasspathLocation.forLibrary(in.readUTF()); -// break; -// case INTERNAL_JAR : -// newState.binaryLocations[i] = ClasspathLocation.forLibrary(root.getFile(new Path(in.readUTF()))); - } - } - - newState.structuralBuildTimes = new SimpleLookupTable(length = in.readInt()); - for (int i = 0; i < length; i++) - newState.structuralBuildTimes.put(in.readUTF(), new Long(in.readLong())); - - String[] internedTypeLocators = new String[length = in.readInt()]; - for (int i = 0; i < length; i++) - internedTypeLocators[i] = in.readUTF(); - - newState.typeLocators = new SimpleLookupTable(length = in.readInt()); - for (int i = 0; i < length; i++) - newState.typeLocators.put(in.readUTF(), internedTypeLocators[in.readInt()]); - -// char[][] internedSimpleNames = ReferenceCollection.internSimpleNames(readNames(in), false); -// char[][][] internedQualifiedNames = new char[length = in.readInt()][][]; -// for (int i = 0; i < length; i++) { -// int qLength = in.readInt(); -// char[][] qName = new char[qLength][]; -// for (int j = 0; j < qLength; j++) -// qName[j] = internedSimpleNames[in.readInt()]; -// internedQualifiedNames[i] = qName; -// } -// internedQualifiedNames = ReferenceCollection.internQualifiedNames(internedQualifiedNames); - -// newState.references = new SimpleLookupTable(length = in.readInt()); -// for (int i = 0; i < length; i++) { -// String typeLocator = internedTypeLocators[in.readInt()]; -// ReferenceCollection collection = null; -// switch (in.readByte()) { -// case 1 : -// char[][] additionalTypeNames = readNames(in); -// char[][][] qualifiedNames = new char[in.readInt()][][]; -// for (int j = 0, m = qualifiedNames.length; j < m; j++) -// qualifiedNames[j] = internedQualifiedNames[in.readInt()]; -// char[][] simpleNames = new char[in.readInt()][]; -// for (int j = 0, m = simpleNames.length; j < m; j++) -// simpleNames[j] = internedSimpleNames[in.readInt()]; -// collection = new AdditionalTypeCollection(additionalTypeNames, qualifiedNames, simpleNames); -// break; -// case 2 : -// char[][][] qNames = new char[in.readInt()][][]; -// for (int j = 0, m = qNames.length; j < m; j++) -// qNames[j] = internedQualifiedNames[in.readInt()]; -// char[][] sNames = new char[in.readInt()][]; -// for (int j = 0, m = sNames.length; j < m; j++) -// sNames[j] = internedSimpleNames[in.readInt()]; -// collection = new ReferenceCollection(qNames, sNames); -// } -// newState.references.put(typeLocator, collection); -// } -// if (JavaBuilder.DEBUG) -// System.out.println("Successfully read state for " + newState.javaProjectName); //$NON-NLS-1$ - return newState; -} - -private static char[][] readNames(DataInputStream in) throws IOException { - int length = in.readInt(); - char[][] names = new char[length][]; - for (int i = 0; i < length; i++) { - int nLength = in.readInt(); - char[] name = new char[nLength]; - for (int j = 0; j < nLength; j++) - name[j] = in.readChar(); - names[i] = name; - } - return names; -} - -void tagAsNoopBuild() { - this.buildNumber = -1; // tag the project since it has no source folders and can be skipped -} - -boolean wasNoopBuild() { - return buildNumber == -1; -} - -void tagAsStructurallyChanged() { - this.lastStructuralBuildTime = System.currentTimeMillis(); -} - -boolean wasStructurallyChanged(IProject prereqProject, State prereqState) { - if (prereqState != null) { - Object o = structuralBuildTimes.get(prereqProject.getName()); - long previous = o == null ? 0 : ((Long) o).longValue(); - if (previous == prereqState.lastStructuralBuildTime) return false; - } - return true; -} - -void write(DataOutputStream out) throws IOException { - int length; - Object[] keyTable; - Object[] valueTable; - -/* - * byte VERSION - * String project name - * int build number - * int last structural build number -*/ - out.writeByte(VERSION); - out.writeUTF(javaProjectName); - out.writeInt(buildNumber); - out.writeLong(lastStructuralBuildTime); - -/* - * ClasspathMultiDirectory[] - * int id - * String path(s) -*/ - out.writeInt(length = sourceLocations.length); - for (int i = 0; i < length; i++) { - ClasspathMultiDirectory md = sourceLocations[i]; - out.writeUTF(md.sourceFolder.getProjectRelativePath().toString()); - out.writeUTF(md.binaryFolder.getProjectRelativePath().toString()); - writeNames(md.exclusionPatterns, out); - out.writeBoolean(md.hasIndependentOutputFolder); - } - -/* - * ClasspathLocation[] - * int id - * String path(s) -*/ - out.writeInt(length = binaryLocations.length); - next : for (int i = 0; i < length; i++) { - ClasspathLocation c = binaryLocations[i]; - if (c instanceof ClasspathMultiDirectory) { - out.writeByte(SOURCE_FOLDER); - for (int j = 0, m = sourceLocations.length; j < m; j++) { - if (sourceLocations[j] == c) { - out.writeInt(j); - continue next; - } - } - } else if (c instanceof ClasspathDirectory) { - out.writeByte(BINARY_FOLDER); - ClasspathDirectory cd = (ClasspathDirectory) c; - out.writeUTF(cd.binaryFolder.getFullPath().toString()); - out.writeBoolean(cd.isOutputFolder); - } else { -// ClasspathJar jar = (ClasspathJar) c; -// if (jar.resource == null) { -// out.writeByte(EXTERNAL_JAR); -// out.writeUTF(jar.zipFilename); -// } else { -// out.writeByte(INTERNAL_JAR); -// out.writeUTF(jar.resource.getFullPath().toString()); -// } - } - } - -/* - * Structural build numbers table - * String prereq project name - * int last structural build number -*/ - out.writeInt(length = structuralBuildTimes.elementSize); - if (length > 0) { - keyTable = structuralBuildTimes.keyTable; - valueTable = structuralBuildTimes.valueTable; - for (int i = 0, l = keyTable.length; i < l; i++) { - if (keyTable[i] != null) { - length--; - out.writeUTF((String) keyTable[i]); - out.writeLong(((Long) valueTable[i]).longValue()); - } - } -// if (JavaBuilder.DEBUG && length != 0) -// System.out.println("structuralBuildNumbers table is inconsistent"); //$NON-NLS-1$ - } - -/* - * String[] Interned type locators - */ - out.writeInt(length = references.elementSize); - ArrayList internedTypeLocators = new ArrayList(length); - if (length > 0) { - keyTable = references.keyTable; - for (int i = 0, l = keyTable.length; i < l; i++) { - if (keyTable[i] != null) { - length--; - String key = (String) keyTable[i]; - out.writeUTF(key); - internedTypeLocators.add(key); - } - } -// if (JavaBuilder.DEBUG && length != 0) -// System.out.println("references table is inconsistent"); //$NON-NLS-1$ - } - -/* - * Type locators table - * String type name - * int interned locator id - */ - out.writeInt(length = typeLocators.elementSize); - if (length > 0) { - keyTable = typeLocators.keyTable; - valueTable = typeLocators.valueTable; - for (int i = 0, l = keyTable.length; i < l; i++) { - if (keyTable[i] != null) { - length--; - out.writeUTF((String) keyTable[i]); - out.writeInt(internedTypeLocators.indexOf((String) valueTable[i])); - } - } -// if (JavaBuilder.DEBUG && length != 0) -// System.out.println("typeLocators table is inconsistent"); //$NON-NLS-1$ - } - -/* - * char[][][] Interned qualified names - * char[][] Interned simple names - */ - ArrayList internedQualifiedNames = new ArrayList(31); - ArrayList internedSimpleNames = new ArrayList(31); - valueTable = references.valueTable; - for (int i = 0, l = valueTable.length; i < l; i++) { -// if (valueTable[i] != null) { -// ReferenceCollection collection = (ReferenceCollection) valueTable[i]; -// char[][][] qNames = collection.qualifiedNameReferences; -// for (int j = 0, m = qNames.length; j < m; j++) { -// char[][] qName = qNames[j]; -// if (!internedQualifiedNames.contains(qName)) { // remember the names have been interned -// internedQualifiedNames.add(qName); -// for (int k = 0, n = qName.length; k < n; k++) { -// char[] sName = qName[k]; -// if (!internedSimpleNames.contains(sName)) // remember the names have been interned -// internedSimpleNames.add(sName); -// } -// } -// } -// char[][] sNames = collection.simpleNameReferences; -// for (int j = 0, m = sNames.length; j < m; j++) { -// char[] sName = sNames[j]; -// if (!internedSimpleNames.contains(sName)) // remember the names have been interned -// internedSimpleNames.add(sName); -// } -// } - } - char[][] internedArray = new char[internedSimpleNames.size()][]; - internedSimpleNames.toArray(internedArray); - writeNames(internedArray, out); - // now write the interned qualified names as arrays of interned simple names - out.writeInt(length = internedQualifiedNames.size()); - for (int i = 0; i < length; i++) { - char[][] qName = (char[][]) internedQualifiedNames.get(i); - int qLength = qName.length; - out.writeInt(qLength); - for (int j = 0; j < qLength; j++) - out.writeInt(internedSimpleNames.indexOf(qName[j])); - } - -/* - * References table - * int interned locator id - * ReferenceCollection -*/ - out.writeInt(length = references.elementSize); - if (length > 0) { - keyTable = references.keyTable; - for (int i = 0, l = keyTable.length; i < l; i++) { -// if (keyTable[i] != null) { -// length--; -// out.writeInt(internedTypeLocators.indexOf((String) keyTable[i])); -// ReferenceCollection collection = (ReferenceCollection) valueTable[i]; -// if (collection instanceof AdditionalTypeCollection) { -// out.writeByte(1); -// AdditionalTypeCollection atc = (AdditionalTypeCollection) collection; -// writeNames(atc.definedTypeNames, out); -// } else { -// out.writeByte(2); -// } -// char[][][] qNames = collection.qualifiedNameReferences; -// int qLength = qNames.length; -// out.writeInt(qLength); -// for (int j = 0; j < qLength; j++) -// out.writeInt(internedQualifiedNames.indexOf(qNames[j])); -// char[][] sNames = collection.simpleNameReferences; -// int sLength = sNames.length; -// out.writeInt(sLength); -// for (int j = 0; j < sLength; j++) -// out.writeInt(internedSimpleNames.indexOf(sNames[j])); -// } - } -// if (JavaBuilder.DEBUG && length != 0) -// System.out.println("references table is inconsistent"); //$NON-NLS-1$ - } -} - -private void writeNames(char[][] names, DataOutputStream out) throws IOException { - int length = names == null ? 0 : names.length; - out.writeInt(length); - for (int i = 0; i < length; i++) { - char[] name = names[i]; - int nLength = name.length; - out.writeInt(nLength); - for (int j = 0; j < nLength; j++) - out.writeChar(name[j]); - } -} - -/** - * Returns a string representation of the receiver. - */ -public String toString() { - return "State for " + javaProjectName //$NON-NLS-1$ - + " (#" + buildNumber //$NON-NLS-1$ - + " @ " + new Date(lastStructuralBuildTime) //$NON-NLS-1$ - + ")"; //$NON-NLS-1$ -} - -/* Debug helper -void dump() { - System.out.println("State for " + javaProjectName + " (" + buildNumber + " @ " + new Date(lastStructuralBuildTime) + ")"); - System.out.println("\tClass path source locations:"); - for (int i = 0, l = sourceLocations.length; i < l; i++) - System.out.println("\t\t" + sourceLocations[i]); - System.out.println("\tClass path binary locations:"); - for (int i = 0, l = binaryLocations.length; i < l; i++) - System.out.println("\t\t" + binaryLocations[i]); - - System.out.print("\tStructural build numbers table:"); - if (structuralBuildTimes.elementSize == 0) { - System.out.print(" "); - } else { - Object[] keyTable = structuralBuildTimes.keyTable; - Object[] valueTable = structuralBuildTimes.valueTable; - for (int i = 0, l = keyTable.length; i < l; i++) - if (keyTable[i] != null) - System.out.print("\n\t\t" + keyTable[i].toString() + " -> " + valueTable[i].toString()); - } - - System.out.print("\tType locators table:"); - if (typeLocators.elementSize == 0) { - System.out.print(" "); - } else { - Object[] keyTable = typeLocators.keyTable; - Object[] valueTable = typeLocators.valueTable; - for (int i = 0, l = keyTable.length; i < l; i++) - if (keyTable[i] != null) - System.out.print("\n\t\t" + keyTable[i].toString() + " -> " + valueTable[i].toString()); - } - - System.out.print("\n\tReferences table:"); - if (references.elementSize == 0) { - System.out.print(" "); - } else { - Object[] keyTable = references.keyTable; - Object[] valueTable = references.valueTable; - for (int i = 0, l = keyTable.length; i < l; i++) { - if (keyTable[i] != null) { - System.out.print("\n\t\t" + keyTable[i].toString()); - ReferenceCollection c = (ReferenceCollection) valueTable[i]; - char[][][] qRefs = c.qualifiedNameReferences; - System.out.print("\n\t\t\tqualified:"); - if (qRefs.length == 0) - System.out.print(" "); - else for (int j = 0, m = qRefs.length; j < m; j++) - System.out.print(" '" + CharOperation.toString(qRefs[j]) + "'"); - char[][] sRefs = c.simpleNameReferences; - System.out.print("\n\t\t\tsimple:"); - if (sRefs.length == 0) - System.out.print(" "); - else for (int j = 0, m = sRefs.length; j < m; j++) - System.out.print(" " + new String(sRefs[j])); - if (c instanceof AdditionalTypeCollection) { - char[][] names = ((AdditionalTypeCollection) c).definedTypeNames; - System.out.print("\n\t\t\tadditional type names:"); - for (int j = 0, m = names.length; j < m; j++) - System.out.print(" " + new String(names[j])); - } - } - } - } - System.out.print("\n\n"); -} -*/ -} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/EditorUtility.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/EditorUtility.java index b593805..b874f4f 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/EditorUtility.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/EditorUtility.java @@ -33,6 +33,7 @@ import org.eclipse.ui.IFileEditorInput; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; import org.eclipse.ui.part.FileEditorInput; import org.eclipse.ui.texteditor.ITextEditor; @@ -121,15 +122,15 @@ public class EditorUtility { } private static IEditorPart openInEditor(IFile file, boolean activate) throws PartInitException { - if (file != null) { - IWorkbenchPage p= PHPeclipsePlugin.getActivePage(); - if (p != null) { - IEditorPart editorPart= p.openEditor(file, null, activate); - initializeHighlightRange(editorPart); - return editorPart; - } - } - return null; + if (file != null) { + IWorkbenchPage p= PHPeclipsePlugin.getActivePage(); + if (p != null) { + IEditorPart editorPart= IDE.openEditor(p, file, activate); + initializeHighlightRange(editorPart); + return editorPart; + } + } + return null; } private static IEditorPart openInEditor(IEditorInput input, String editorID, boolean activate) throws PartInitException { diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/IJavaAnnotation.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/IJavaAnnotation.java index 266d368..1a07289 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/IJavaAnnotation.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/IJavaAnnotation.java @@ -89,4 +89,4 @@ public interface IJavaAnnotation { * @return true if it is a problem annotation */ boolean isProblem(); -} +} \ No newline at end of file diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaOutlinePage.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaOutlinePage.java index 98681fa..b6d1eb1 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaOutlinePage.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaOutlinePage.java @@ -30,6 +30,8 @@ import net.sourceforge.phpdt.core.IType; import net.sourceforge.phpdt.core.JavaModelException; import net.sourceforge.phpdt.internal.ui.PHPUiImages; import net.sourceforge.phpdt.internal.ui.actions.CompositeActionGroup; +import net.sourceforge.phpdt.internal.ui.dnd.JdtViewerDragAdapter; +import net.sourceforge.phpdt.internal.ui.dnd.TransferDragSourceListener; import net.sourceforge.phpdt.internal.ui.packageview.SelectionTransferDragAdapter; import net.sourceforge.phpdt.internal.ui.viewsupport.AppearanceAwareLabelProvider; import net.sourceforge.phpdt.internal.ui.viewsupport.DecoratingJavaLabelProvider; @@ -46,8 +48,6 @@ import net.sourceforge.phpeclipse.PHPeclipsePlugin; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IAdaptable; -import net.sourceforge.phpdt.internal.ui.dnd.JdtViewerDragAdapter; -import net.sourceforge.phpdt.internal.ui.dnd.TransferDragSourceListener; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.action.IMenuListener; @@ -87,8 +87,8 @@ import org.eclipse.swt.widgets.Widget; import org.eclipse.ui.IActionBars; import org.eclipse.ui.actions.ActionContext; import org.eclipse.ui.actions.ActionGroup; -import org.eclipse.ui.internal.model.WorkbenchAdapter; import org.eclipse.ui.model.IWorkbenchAdapter; +import org.eclipse.ui.model.WorkbenchAdapter; import org.eclipse.ui.part.IPageSite; import org.eclipse.ui.part.IShowInSource; import org.eclipse.ui.part.IShowInTarget; diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPDocumentProvider.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPDocumentProvider.java index fb4f623..5751336 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPDocumentProvider.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPDocumentProvider.java @@ -71,6 +71,8 @@ import org.eclipse.ui.IFileEditorInput; import org.eclipse.ui.editors.text.FileDocumentProvider; import org.eclipse.ui.part.FileEditorInput; import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel; +import org.eclipse.ui.texteditor.DefaultAnnotation; +import org.eclipse.ui.texteditor.IAnnotationExtension; import org.eclipse.ui.texteditor.MarkerAnnotation; import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel; @@ -142,7 +144,7 @@ public class PHPDocumentProvider extends FileDocumentProvider { /* * @see AnnotationModel#addAnnotation(Annotation, Position, boolean) */ - protected void addAnnotation(Annotation annotation, Position position, boolean fireModelChanged) { + protected void addAnnotation(Annotation annotation, Position position, boolean fireModelChanged) throws BadLocationException { super.addAnnotation(annotation, position, fireModelChanged); Object cached = fReverseMap.get(position); @@ -185,65 +187,128 @@ public class PHPDocumentProvider extends FileDocumentProvider { return new Position(start, length); } - /* * @see IProblemRequestor#endReporting() */ public void endReporting() { if (!isActive()) return; - + if (fProgressMonitor != null && fProgressMonitor.isCanceled()) return; - - boolean isCanceled = false; - boolean temporaryProblemsChanged = false; - fPreviouslyOverlaid = fCurrentlyOverlaid; - fCurrentlyOverlaid = new ArrayList(); - + + + boolean isCanceled= false; + boolean temporaryProblemsChanged= false; + synchronized (fAnnotations) { + + fPreviouslyOverlaid= fCurrentlyOverlaid; + fCurrentlyOverlaid= new ArrayList(); if (fGeneratedAnnotations.size() > 0) { - temporaryProblemsChanged = true; + temporaryProblemsChanged= true; removeAnnotations(fGeneratedAnnotations, false, true); fGeneratedAnnotations.clear(); } - + if (fCollectedProblems != null && fCollectedProblems.size() > 0) { - - Iterator e = fCollectedProblems.iterator(); + + ICompilationUnit cu= getWorkingCopy(fInput); + Iterator e= fCollectedProblems.iterator(); while (e.hasNext()) { - - IProblem problem = (IProblem) e.next(); - + + IProblem problem= (IProblem) e.next(); + if (fProgressMonitor != null && fProgressMonitor.isCanceled()) { - isCanceled = true; + isCanceled= true; break; } - - Position position = createPositionFromProblem(problem); + + Position position= createPositionFromProblem(problem); if (position != null) { - - ProblemAnnotation annotation = new ProblemAnnotation(problem); - overlayMarkers(position, annotation); - fGeneratedAnnotations.add(annotation); - addAnnotation(annotation, position, false); - - temporaryProblemsChanged = true; + try { + ProblemAnnotation annotation= new ProblemAnnotation(problem, cu); + addAnnotation(annotation, position, false); + overlayMarkers(position, annotation); + fGeneratedAnnotations.add(annotation); + + temporaryProblemsChanged= true; + } catch (BadLocationException x) { + // ignore invalid position + } } } - + fCollectedProblems.clear(); } - + removeMarkerOverlays(isCanceled); fPreviouslyOverlaid.clear(); - fPreviouslyOverlaid = null; + fPreviouslyOverlaid= null; } - + if (temporaryProblemsChanged) - fireModelChanged(new CompilationUnitAnnotationModelEvent(this, getResource(), false)); + fireModelChanged(); } + /* + * @see IProblemRequestor#endReporting() + */ +// public void endReporting() { +// if (!isActive()) +// return; +// +// if (fProgressMonitor != null && fProgressMonitor.isCanceled()) +// return; +// +// boolean isCanceled = false; +// boolean temporaryProblemsChanged = false; +// fPreviouslyOverlaid = fCurrentlyOverlaid; +// fCurrentlyOverlaid = new ArrayList(); +// +// synchronized (fAnnotations) { +// +// if (fGeneratedAnnotations.size() > 0) { +// temporaryProblemsChanged = true; +// removeAnnotations(fGeneratedAnnotations, false, true); +// fGeneratedAnnotations.clear(); +// } +// +// if (fCollectedProblems != null && fCollectedProblems.size() > 0) { +// +// Iterator e = fCollectedProblems.iterator(); +// while (e.hasNext()) { +// +// IProblem problem = (IProblem) e.next(); +// +// if (fProgressMonitor != null && fProgressMonitor.isCanceled()) { +// isCanceled = true; +// break; +// } +// +// Position position = createPositionFromProblem(problem); +// if (position != null) { +// +// ProblemAnnotation annotation = new ProblemAnnotation(problem); +// overlayMarkers(position, annotation); +// fGeneratedAnnotations.add(annotation); +// addAnnotation(annotation, position, false); +// +// temporaryProblemsChanged = true; +// } +// } +// +// fCollectedProblems.clear(); +// } +// +// removeMarkerOverlays(isCanceled); +// fPreviouslyOverlaid.clear(); +// fPreviouslyOverlaid = null; +// } +// +// if (temporaryProblemsChanged) +// fireModelChanged(new CompilationUnitAnnotationModelEvent(this, getResource(), false)); +// } private Object getAnnotations(Position position) { return fReverseMap.get(position); @@ -470,30 +535,55 @@ public class PHPDocumentProvider extends FileDocumentProvider { /** * Annotation representating an IProblem. */ - static protected class ProblemAnnotation extends Annotation implements IJavaAnnotation { + static protected class ProblemAnnotation extends Annotation implements IJavaAnnotation, IAnnotationExtension{ + private static final String TASK_ANNOTATION_TYPE= "org.eclipse.ui.workbench.texteditor.task"; //$NON-NLS-1$ + private static final String ERROR_ANNOTATION_TYPE= "org.eclipse.ui.workbench.texteditor.error"; //$NON-NLS-1$ + private static final String WARNING_ANNOTATION_TYPE= "org.eclipse.ui.workbench.texteditor.warning"; //$NON-NLS-1$ + private static final String INFO_ANNOTATION_TYPE= "org.eclipse.ui.workbench.texteditor.info"; //$NON-NLS-1$ + // private static Image fgQuickFixImage; // private static Image fgQuickFixErrorImage; // private static boolean fgQuickFixImagesInitialized = false; + private ICompilationUnit fCompilationUnit; private List fOverlaids; private IProblem fProblem; private Image fImage; // private boolean fQuickFixImagesInitialized = false; - private AnnotationType fType; - - public ProblemAnnotation(IProblem problem) { - - fProblem = problem; - setLayer(MarkerAnnotation.PROBLEM_LAYER + 1); - - if (IProblem.Task == fProblem.getID()) - fType = AnnotationType.TASK; - else if (fProblem.isWarning()) - fType = AnnotationType.WARNING; - else - fType = AnnotationType.ERROR; +// private AnnotationType fType; + private String fType; + + public ProblemAnnotation(IProblem problem, ICompilationUnit cu) { + fProblem= problem; + fCompilationUnit= cu; + + if (IProblem.Task == fProblem.getID()) { + fType= TASK_ANNOTATION_TYPE; + setLayer(DefaultAnnotation.TASK_LAYER + 1); + } else if (fProblem.isWarning()) { + fType= WARNING_ANNOTATION_TYPE; + setLayer(DefaultAnnotation.WARNING_LAYER + 1); + } else if (fProblem.isError()) { + fType= ERROR_ANNOTATION_TYPE; + setLayer(DefaultAnnotation.ERROR_LAYER + 1); + } else { + fType= INFO_ANNOTATION_TYPE; + setLayer(DefaultAnnotation.INFO_LAYER + 1); + } } +// public ProblemAnnotation(IProblem problem) { +// +// fProblem = problem; +// setLayer(MarkerAnnotation.PROBLEM_LAYER + 1); +// +// if (IProblem.Task == fProblem.getID()) +// fType = AnnotationType.TASK; +// else if (fProblem.isWarning()) +// fType = AnnotationType.WARNING; +// else +// fType = AnnotationType.ERROR; +// } private void initializeImages() { // http://bugs.eclipse.org/bugs/show_bug.cgi?id=18936 @@ -562,11 +652,17 @@ public class PHPDocumentProvider extends FileDocumentProvider { return isProblem() ? fProblem.getID() : -1; } +// /* +// * @see IJavaAnnotation#isProblem() +// */ +// public boolean isProblem() { +// return fType == AnnotationType.WARNING || fType == AnnotationType.ERROR; +// } /* * @see IJavaAnnotation#isProblem() */ public boolean isProblem() { - return fType == AnnotationType.WARNING || fType == AnnotationType.ERROR; + return WARNING_ANNOTATION_TYPE.equals(fType) || ERROR_ANNOTATION_TYPE.equals(fType); } /* @@ -612,8 +708,48 @@ public class PHPDocumentProvider extends FileDocumentProvider { return null; } + public AnnotationType getAnnotationType() { - return fType; + if (ERROR_ANNOTATION_TYPE.equals(fType)) { + return AnnotationType.ERROR; + } + if (WARNING_ANNOTATION_TYPE.equals(fType)) { + return AnnotationType.WARNING; + } + if (TASK_ANNOTATION_TYPE.equals(fType)) { + return AnnotationType.TASK; + } +// if (INFO_ANNOTATION_TYPE.equals(fType)) { +// return AnnotationType.INFO; +// } + return AnnotationType.UNKNOWN; + } + + /* + * @see IAnnotationExtension#getMarkerType() + */ + public String getMarkerType() { + if (isProblem() || INFO_ANNOTATION_TYPE.equals(fType)) + return IMarker.PROBLEM; + else + return IMarker.TASK; + } + /* + * @see IAnnotationExtension#getSeverity() + */ + public int getSeverity() { + if (ERROR_ANNOTATION_TYPE.equals(fType)) + return IMarker.SEVERITY_ERROR; + if (WARNING_ANNOTATION_TYPE.equals(fType)) + return IMarker.SEVERITY_WARNING; + return IMarker.SEVERITY_INFO; + } + + /* + * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getCompilationUnit() + */ + public ICompilationUnit getCompilationUnit() { + return fCompilationUnit; } }; /** @@ -1120,60 +1256,116 @@ public class PHPDocumentProvider extends FileDocumentProvider { } /* - * @see AbstractDocumentProvider#resetDocument(Object) + * @see org.eclipse.ui.texteditor.AbstractDocumentProvider#doResetDocument(java.lang.Object, org.eclipse.core.runtime.IProgressMonitor) */ - public void resetDocument(Object element) throws CoreException { + protected void doResetDocument(Object element, IProgressMonitor monitor) throws CoreException { if (element == null) return; - - ElementInfo elementInfo = getElementInfo(element); + + ElementInfo elementInfo= getElementInfo(element); if (elementInfo instanceof CompilationUnitInfo) { - CompilationUnitInfo info = (CompilationUnitInfo) elementInfo; - + CompilationUnitInfo info= (CompilationUnitInfo) elementInfo; + IDocument document; - IStatus status = null; - + IStatus status= null; + try { - - ICompilationUnit original = (ICompilationUnit) info.fCopy.getOriginalElement(); - IResource resource = original.getResource(); + + ICompilationUnit original= (ICompilationUnit) info.fCopy.getOriginalElement(); + IResource resource= original.getResource(); if (resource instanceof IFile) { - - IFile file = (IFile) resource; - + + IFile file= (IFile) resource; + try { - refreshFile(file); + refreshFile(file, monitor); } catch (CoreException x) { - handleCoreException(x, PHPEditorMessages.getString("PHPDocumentProvider.error.resetDocument")); //$NON-NLS-1$ + handleCoreException(x, PHPEditorMessages.getString("CompilationUnitDocumentProvider.error.resetDocument")); //$NON-NLS-1$ } - - IFileEditorInput input = new FileEditorInput(file); - document = super.createDocument(input); - + + IFileEditorInput input= new FileEditorInput(file); + document= super.createDocument(input); + } else { - document = new Document(); + document= createEmptyDocument(); } - + } catch (CoreException x) { - document = new Document(); - status = x.getStatus(); + document= createEmptyDocument(); + status= x.getStatus(); } - + fireElementContentAboutToBeReplaced(element); - + removeUnchangedElementListeners(element, info); info.fDocument.set(document.get()); - info.fCanBeSaved = false; - info.fStatus = status; + info.fCanBeSaved= false; + info.fStatus= status; addUnchangedElementListeners(element, info); - + fireElementContentReplaced(element); fireElementDirtyStateChanged(element, false); - + } else { - super.resetDocument(element); + super.doResetDocument(element, monitor); } } + + /* + * @see AbstractDocumentProvider#resetDocument(Object) + */ +// public void resetDocument(Object element) throws CoreException { +// if (element == null) +// return; +// +// ElementInfo elementInfo = getElementInfo(element); +// if (elementInfo instanceof CompilationUnitInfo) { +// CompilationUnitInfo info = (CompilationUnitInfo) elementInfo; +// +// IDocument document; +// IStatus status = null; +// +// try { +// +// ICompilationUnit original = (ICompilationUnit) info.fCopy.getOriginalElement(); +// IResource resource = original.getResource(); +// if (resource instanceof IFile) { +// +// IFile file = (IFile) resource; +// +// try { +// refreshFile(file); +// } catch (CoreException x) { +// handleCoreException(x, PHPEditorMessages.getString("PHPDocumentProvider.error.resetDocument")); //$NON-NLS-1$ +// } +// +// IFileEditorInput input = new FileEditorInput(file); +// document = super.createDocument(input); +// +// } else { +// document = new Document(); +// } +// +// } catch (CoreException x) { +// document = new Document(); +// status = x.getStatus(); +// } +// +// fireElementContentAboutToBeReplaced(element); +// +// removeUnchangedElementListeners(element, info); +// info.fDocument.set(document.get()); +// info.fCanBeSaved = false; +// info.fStatus = status; +// addUnchangedElementListeners(element, info); +// +// fireElementContentReplaced(element); +// fireElementDirtyStateChanged(element, false); +// +// } else { +// super.resetDocument(element); +// } +// } /** * Saves the content of the given document to the given element. * This is only performed when this provider initiated the save. diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPParserAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPParserAction.java index 8134b38..1fdfc76 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPParserAction.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPParserAction.java @@ -19,11 +19,10 @@ import java.util.ArrayList; import java.util.List; import net.sourceforge.phpdt.internal.compiler.util.Util; +import net.sourceforge.phpdt.internal.core.builder.PHPBuilder; import net.sourceforge.phpeclipse.PHPeclipsePlugin; -import net.sourceforge.phpeclipse.builder.PHPBuilder; import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IMarker; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.ui.IEditorInput; diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSyntaxParserThread.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSyntaxParserThread.java deleted file mode 100644 index b04c4f3..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSyntaxParserThread.java +++ /dev/null @@ -1,421 +0,0 @@ -package net.sourceforge.phpeclipse.phpeditor; - -import java.io.IOException; -import java.io.InputStream; - -import net.sourceforge.phpeclipse.PHPeclipsePlugin; -import net.sourceforge.phpeclipse.builder.PHPBuilder; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.jface.preference.IPreferenceStore; -import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.ui.IEditorInput; -import org.eclipse.ui.IFileEditorInput; -import org.eclipse.ui.editors.text.TextEditor; - -import test.PHPParserManager; -import test.PHPParserSuperclass; - - -public class PHPSyntaxParserThread extends Thread { - private static String[] EXTENSIONS = { ".php", ".php3", ".php4", ".inc", ".phtml" }; - - private String text = ""; - private String previousText = ""; - - private boolean stopValidation = false; - private boolean validationTerminated = false; - private boolean isActive = false; - - private TextEditor fTextEditor; - private ISourceViewer fSourceViewer; - - private int previousHashCode = 0; - // Defaults - private int validationInterval = 2000; //millis - private int waitForTermination = 400; // millis - private int maxErrorsShown = 10; - - public PHPSyntaxParserThread( - TextEditor textEditor, - ISourceViewer viewer) { - super(); - fTextEditor = textEditor; - fSourceViewer = viewer; - } - - public void setText(String text) { - if (!isActive) - this.text = text; - } - - public void setText(String text, boolean forceUpdate) { - if (!isActive) { - this.text = text; - } - - if (forceUpdate) { - this.previousText = ""; - this.previousHashCode = 0; - } - } - - public String getText() { - return text; - } - - public void setInterval(int millis) { - this.validationInterval = millis; - } - - public int getInterval() { - return validationInterval; - } - - public void setErrorsShown(int number) { - this.maxErrorsShown = number; - } - - public int getErrorsShown() { - return maxErrorsShown; - } - - public void dispose() { - this.stopValidation = true; - - if (validationTerminated == false) { - - try { - Thread.sleep(waitForTermination); - } catch (Exception e) { - } - } - } - - public void run() { - while (stopValidation == false) { - try { - - this.isActive = true; - boolean ret = this.validateSyntax(); - - this.previousText = this.text; - this.isActive = false; - - Thread.sleep(validationInterval); - - } catch (Exception e) { - e.printStackTrace(); - } - } - - this.validationTerminated = true; - } - - public boolean validateSyntax() { - - boolean phpFlag = false; - try { - IFile fileToParse = getPHPFile(fTextEditor.getEditorInput()); - if (fileToParse == null) { - // should never happen - System.err.println("Error : no file in the editor"); - // should throw an exception - return false; - } - String name = fileToParse.getName(); - for (int i = 0; i 0) { -// content.append(new String(buffer)); -// } -// in.close(); -// -// //jjjjjjj -// // DEBUG start -// System.out.println("-----------------------------------------"); -// System.out.println(" OUTPUT"); -// System.out.println("-----------------------------------------"); -// System.out.println(content); -// System.out.println("-----------------------------------------"); -// // DEBUG END -// -// String line = null; -// List lines = new ArrayList(); -// int index; -// -// // Compare checksums -// int hashCode = content.toString().hashCode(); -// -// if (previousHashCode == hashCode) { -// -// return true; -// } -// -// previousHashCode = hashCode; -// -// StringTokenizer st = new StringTokenizer(content.toString(), "\n"); -// -// int lineCount = 0; -// -// while (st.hasMoreTokens()) { -// line = st.nextToken(); -// if (line.indexOf("\r") != -1) { -// line = line.substring(0, line.indexOf("\r")); -// } -// -// lines.add(line); -// if (++lineCount >= maxErrorsShown) { -// break; -// } -// -// } -// -// //Delete markers -// resource.deleteMarkers(IMarker.PROBLEM, true, 1); -// -// // Markers have to be added in reverse order -// // Otherwise lower line number will appear at the end of the list -// for (int i = lines.size() - 1; i >= 0; i--) { -// line = (String) lines.get(i); -// -// // If error message is not from temporary file, skip -// if (line.indexOf(tmpFileName) == -1) { -// continue; -// } -// -// // Delete filename from error message -// StringBuffer lineSb = new StringBuffer(line); -// replace(lineSb, tmpFileName + " ", "", true); -// line = lineSb.toString(); -// -// if ((index = line.indexOf(PERL_ERROR_INDICATOR)) != -1) { -// -// // truncatedLIne is the stripped error-line up to the next " " after the line number if present -// // To avoid cluttering with other "." and "," which might occur in the error message -// String truncatedLine = line; -// if (truncatedLine -// .indexOf(" ", index + PERL_ERROR_INDICATOR.length() + 1) -// != -1) { -// truncatedLine = -// truncatedLine.substring( -// 0, -// truncatedLine.indexOf( -// " ", -// index + PERL_ERROR_INDICATOR.length() + 1)); -// } -// -// int endIndex; -// if ((endIndex = truncatedLine.indexOf(".", index)) == -1) { -// endIndex = truncatedLine.indexOf(",", index); -// } -// -// if (endIndex == -1) { -// continue; -// } -// -// String lineNr = -// truncatedLine.substring( -// index + PERL_ERROR_INDICATOR.length(), -// endIndex); -// -// // If there is an addition to the error message -// if (i + 1 < lines.size()) { -// if (((String) lines.get(i + 1)).startsWith(" ")) { -// line += " " + (String) lines.get(i + 1); -// } -// } -// -// IMarker marker = resource.createMarker(IMarker.PROBLEM); -// -// // Check if it's a warning -// boolean isWarning = false; -// -// for (int x = 0; x < WARNING_STRINGS.length; x++) { -// if (truncatedLine.indexOf(WARNING_STRINGS[x]) != -1) { -// isWarning = true; -// } -// } -// -// if (isWarning) { -// marker.setAttribute( -// IMarker.SEVERITY, -// IMarker.SEVERITY_WARNING); -// } else { -// marker.setAttribute( -// IMarker.SEVERITY, -// IMarker.SEVERITY_ERROR); -// } -// -// marker.setAttribute(IMarker.MESSAGE, line); -// -// marker.setAttribute( -// IMarker.LINE_NUMBER, -// Integer.parseInt(lineNr)); -// -// Position pos = -// new Position( -// fSourceViewer.getDocument().getLineOffset( -// Integer.parseInt(lineNr) - 1)); -// fSourceViewer.getAnnotationModel().addAnnotation( -// new MarkerAnnotation(marker), -// pos); -// -// } -// } -// -// } catch (Exception e) { -// e.printStackTrace(); -// if (proc != null) { -// killProcess(proc); -// } -// return false; -// } finally { -// try { -// // Delete tmp file -// new File(tmpFileName).delete(); -// } catch (Exception ex) { -// ex.printStackTrace(); -// } -// } - - return true; - - } - - /** - * Finds the file that's currently opened in the PHP Text Editor - */ - protected IFile getPHPFile(IEditorInput editorInput) { - if (editorInput instanceof IFileEditorInput) - return ((IFileEditorInput) editorInput).getFile(); - - return null; - } - - protected void parse(IFile fileToParse, InputStream iStream) { - - StringBuffer buf = new StringBuffer(); - int c0; - try { - while ((c0 = iStream.read()) != (-1)) { - buf.append((char) c0); - } - } catch (IOException e) { - return; - } - String input = buf.toString(); - - PHPParserSuperclass parser = PHPParserManager.getParser(fileToParse); - try { - parser.parse(input); - } catch (CoreException e) { - } - } - - private void killProcess(Process proc) { - while (true) { - try { - proc.destroy(); - proc.exitValue(); - } catch (Exception ex) { - - continue; - } - break; - } - } - - // Replaces all instances of the String o with the String n in the - // StringBuffer orig if all is true, or only the first instance if all is false. - private static void replace( - StringBuffer orig, - String o, - String n, - boolean all) { - if (orig == null || o == null || o.length() == 0 || n == null) - throw new IllegalArgumentException("Null or zero-length String"); - - int i = 0; - - while (i + o.length() <= orig.length()) { - if (orig.substring(i, i + o.length()).equals(o)) { - orig.replace(i, i + o.length(), n); - if (!all) - break; - else - i += n.length(); - } else - i++; - } - } -} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java index 833c8f8..419fd01 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPUnitEditor.java @@ -1751,18 +1751,37 @@ public class PHPUnitEditor extends PHPEditor { /* * @see AbstractTextEditor#performSaveOperation(WorkspaceModifyOperation, IProgressMonitor) */ - protected void performSaveOperation(WorkspaceModifyOperation operation, IProgressMonitor progressMonitor) { - IDocumentProvider p = getDocumentProvider(); +// protected void performSaveOperation(WorkspaceModifyOperation operation, IProgressMonitor progressMonitor) { +// IDocumentProvider p = getDocumentProvider(); +// if (p instanceof PHPDocumentProvider) { +// PHPDocumentProvider cp = (PHPDocumentProvider) p; +// cp.setSavePolicy(fSavePolicy); +// } +// +// try { +// super.performSaveOperation(operation, progressMonitor); +// } finally { +// if (p instanceof PHPDocumentProvider) { +// PHPDocumentProvider cp = (PHPDocumentProvider) p; +// cp.setSavePolicy(null); +// } +// } +// } + + /* + * @see org.eclipse.ui.texteditor.AbstractTextEditor#performSave(boolean, org.eclipse.core.runtime.IProgressMonitor) + */ + protected void performSave(boolean overwrite, IProgressMonitor progressMonitor) { + IDocumentProvider p= getDocumentProvider(); if (p instanceof PHPDocumentProvider) { - PHPDocumentProvider cp = (PHPDocumentProvider) p; + PHPDocumentProvider cp= (PHPDocumentProvider) p; cp.setSavePolicy(fSavePolicy); } - try { - super.performSaveOperation(operation, progressMonitor); + super.performSave(overwrite, progressMonitor); } finally { if (p instanceof PHPDocumentProvider) { - PHPDocumentProvider cp = (PHPDocumentProvider) p; + PHPDocumentProvider cp= (PHPDocumentProvider) p; cp.setSavePolicy(null); } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/ShowExternalPreviewAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/ShowExternalPreviewAction.java index 7ab6f16..a3669ed 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/ShowExternalPreviewAction.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/ShowExternalPreviewAction.java @@ -24,8 +24,8 @@ import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PartInitException; import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.texteditor.TextEditorAction; -import org.eclipse.update.internal.ui.UpdatePerspective; -import org.eclipse.update.internal.ui.views.IEmbeddedWebBrowser; +//import org.eclipse.update.internal.ui.UpdatePerspective; +//import org.eclipse.update.internal.ui.views.IEmbeddedWebBrowser; /** * ClassDeclaration that defines the action for parsing the current PHP file @@ -58,23 +58,23 @@ public class ShowExternalPreviewAction extends TextEditorAction { return; } - if (SWT.getPlatform().equals("win32")) { - String localhostURL; - if ((localhostURL = PHPEclipseShowAction.getLocalhostURL(null, fileToParse)) == null) { - return; - } - IWorkbenchPage page = PHPeclipsePlugin.getActivePage(); - try { - IViewPart part = page.findView(UpdatePerspective.ID_BROWSER); - if (part == null) { - part = page.showView(UpdatePerspective.ID_BROWSER); - } else - page.bringToTop(part); - ((IEmbeddedWebBrowser) part).openTo(localhostURL); - } catch (PartInitException e) { - PHPeclipsePlugin.log(e); - } - } +// if (SWT.getPlatform().equals("win32")) { +// String localhostURL; +// if ((localhostURL = PHPEclipseShowAction.getLocalhostURL(null, fileToParse)) == null) { +// return; +// } +// IWorkbenchPage page = PHPeclipsePlugin.getActivePage(); +// try { +// IViewPart part = page.findView(UpdatePerspective.ID_BROWSER); +// if (part == null) { +// part = page.showView(UpdatePerspective.ID_BROWSER); +// } else +// page.bringToTop(part); +// ((IEmbeddedWebBrowser) part).openTo(localhostURL); +// } catch (PartInitException e) { +// PHPeclipsePlugin.log(e); +// } +// } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/wizards/PHPFileWizard.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/wizards/PHPFileWizard.java index 572bf4c..d172145 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/wizards/PHPFileWizard.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/wizards/PHPFileWizard.java @@ -37,6 +37,7 @@ import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.ide.IDE; /** * This wizard creates one file with the extension @@ -134,7 +135,7 @@ public class PHPFileWizard extends Wizard implements INewWizard { public void run() { IWorkbenchPage page = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(); try { - page.openEditor(file); + IDE.openEditor(page,file,true); } catch (PartInitException e) { } } diff --git a/net.sourceforge.phpeclipse/src/test/PHPParserSuperclass.java b/net.sourceforge.phpeclipse/src/test/PHPParserSuperclass.java index f612a6c..88b2e8a 100644 --- a/net.sourceforge.phpeclipse/src/test/PHPParserSuperclass.java +++ b/net.sourceforge.phpeclipse/src/test/PHPParserSuperclass.java @@ -5,10 +5,10 @@ import java.util.Hashtable; import net.sourceforge.phpdt.core.IJavaModelMarker; import net.sourceforge.phpdt.internal.compiler.parser.PHPOutlineInfo; +import net.sourceforge.phpdt.internal.core.builder.PHPBuilder; import net.sourceforge.phpdt.internal.ui.util.StringUtil; import net.sourceforge.phpeclipse.PHPeclipsePlugin; import net.sourceforge.phpeclipse.actions.PHPStartApacheAction; -import net.sourceforge.phpeclipse.builder.PHPBuilder; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker;