From: khartlage Date: Tue, 24 Feb 2004 20:42:33 +0000 (+0000) Subject: Eclipse 3M7 X-Git-Url: http://secure.phpeclipse.com Eclipse 3M7 --- diff --git a/net.sourceforge.phpeclipse/.classpath b/net.sourceforge.phpeclipse/.classpath index 19ca38e..065ac06 100644 --- a/net.sourceforge.phpeclipse/.classpath +++ b/net.sourceforge.phpeclipse/.classpath @@ -1,30 +1,7 @@ - - - - - - - - - - - - - - - - - - - - - - - - + diff --git a/net.sourceforge.phpeclipse/plugin.properties b/net.sourceforge.phpeclipse/plugin.properties index ecc9f01..d214c3d 100644 --- a/net.sourceforge.phpeclipse/plugin.properties +++ b/net.sourceforge.phpeclipse/plugin.properties @@ -5,6 +5,9 @@ pluginName=PHPEclipse Tools Core providerName=phpeclipse.de naturePHP.name=PHP Project phpProblemName=PHP Problem +transientPHPProblemName=Transient PHP Problem +phpTaskName=Java Task + phpEditorTextHoversName=PHP Editor Text Hovers perspectivePHP.name=PHP @@ -43,8 +46,8 @@ javadocHover= PHPdoc javadocHoverDescription= Shows the PHPdoc of the selected element. sequentialHover= Best Match sequentialHoverDescription= Shows the hover which fits best for the selected element and the current context. -problemHover= Problems -problemHoverDescription= Shows the problem descriptions for the selected element. +annotationHover= Annotation +annotationHoverDescription= Shows the text of the selected annotation. # # Action sets diff --git a/net.sourceforge.phpeclipse/plugin.xml b/net.sourceforge.phpeclipse/plugin.xml index cced16b..adedc5e 100644 --- a/net.sourceforge.phpeclipse/plugin.xml +++ b/net.sourceforge.phpeclipse/plugin.xml @@ -54,22 +54,39 @@ - - - - + + - + - + - + + + + + + + + + + + + + + + + + + + + @@ -133,12 +150,12 @@ + class="net.sourceforge.phpdt.internal.ui.text.java.hover.AnnotationHover" + id="net.sourceforge.phpdt.ui.AnnotationHover" + label="%annotationHover" + description="%annotationHoverDescription"> - r + @@ -346,6 +363,72 @@ + + + + + + + + + + + + + + + + + + + + + + TokenNameKEYWORD && token != TokenNamelist && token != TokenNamenew) { // char[] ident = scanner.getCurrentIdentifierSource(); // String keyword = new String(ident); + if (token == TokenNameAT) { + getNextToken(); + if (token != TokenNamerequire + && token != TokenNamerequire_once + && token != TokenNameinclude + && token != TokenNameinclude_once + && token != TokenNameIdentifier + && token != TokenNameVariable + && token != TokenNamethis + && token != TokenNameStringInterpolated) { + throwSyntaxError("identifier expected after '@'."); + } + } if (token == TokenNameinclude || token == TokenNameinclude_once) { getNextToken(); if (token == TokenNameLPAREN) { diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/util/JavaModelUtil.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/util/JavaModelUtil.java index 5fc7858..a2e6fcc 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/util/JavaModelUtil.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/corext/util/JavaModelUtil.java @@ -10,17 +10,12 @@ *******************************************************************************/ package net.sourceforge.phpdt.internal.corext.util; -import java.util.Arrays; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Set; +import java.util.StringTokenizer; import net.sourceforge.phpdt.core.Flags; import net.sourceforge.phpdt.core.ICompilationUnit; import net.sourceforge.phpdt.core.IField; import net.sourceforge.phpdt.core.IJavaElement; -import net.sourceforge.phpdt.core.IJavaProject; import net.sourceforge.phpdt.core.IMember; import net.sourceforge.phpdt.core.IMethod; import net.sourceforge.phpdt.core.IPackageFragment; @@ -31,13 +26,9 @@ import net.sourceforge.phpdt.core.Signature; import net.sourceforge.phpdt.core.compiler.CharOperation; import net.sourceforge.phpeclipse.phpeditor.EditorUtility; -import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; -import org.eclipse.core.runtime.IProgressMonitor; -import org.eclipse.core.runtime.Path; -import org.eclipse.core.runtime.SubProgressMonitor; @@ -696,4 +687,43 @@ public class JavaModelUtil { return false; } + + private static final String ARGUMENTS_DELIMITER = "#"; //$NON-NLS-1$ + private static final String EMPTY_ARGUMENT = " "; //$NON-NLS-1$ + + /** + * Copied from org.eclipse.jdt.internal.core.Util; + */ + public static String[] getProblemArgumentsFromMarker(String argumentsString){ + if (argumentsString == null) return null; + int index = argumentsString.indexOf(':'); + if(index == -1) + return null; + + int length = argumentsString.length(); + int numberOfArg; + try{ + numberOfArg = Integer.parseInt(argumentsString.substring(0 , index)); + } catch (NumberFormatException e) { + return null; + } + argumentsString = argumentsString.substring(index + 1, length); + + String[] args = new String[length]; + int count = 0; + + StringTokenizer tokenizer = new StringTokenizer(argumentsString, ARGUMENTS_DELIMITER); + while(tokenizer.hasMoreTokens()) { + String argument = tokenizer.nextToken(); + if(argument.equals(EMPTY_ARGUMENT)) + argument = ""; //$NON-NLS-1$ + args[count++] = argument; + } + + if(count != numberOfArg) + return null; + + System.arraycopy(args, 0, args = new String[count], 0, count); + return args; + } } 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 c57a86d..bdecc4a 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 @@ -16,9 +16,11 @@ import java.util.Iterator; import java.util.List; import java.util.Map; +import net.sourceforge.phpdt.internal.corext.Assert; import net.sourceforge.phpdt.internal.ui.PHPUIMessages; -import net.sourceforge.phpeclipse.phpeditor.IJavaAnnotation; +import net.sourceforge.phpeclipse.PHPeclipsePlugin; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.text.BadLocationException; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.Position; @@ -26,6 +28,8 @@ 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.editors.text.EditorsUI; +import org.eclipse.ui.texteditor.AnnotationPreference; // TODO: delete this class ? we use PHPAnnotationHover instead ! /** @@ -33,6 +37,21 @@ import org.eclipse.jface.text.source.ISourceViewer; * their messages. */ public class JavaAnnotationHover implements IAnnotationHover { + private static class JavaAnnotationHoverType { + } + + public static final JavaAnnotationHoverType OVERVIEW_RULER_HOVER= new JavaAnnotationHoverType(); + public static final JavaAnnotationHoverType TEXT_RULER_HOVER= new JavaAnnotationHoverType(); + public static final JavaAnnotationHoverType VERTICAL_RULER_HOVER= new JavaAnnotationHoverType(); + + private IPreferenceStore fStore= PHPeclipsePlugin.getDefault().getPreferenceStore(); + + private JavaAnnotationHoverType fType; + + public JavaAnnotationHover(JavaAnnotationHoverType type) { + Assert.isTrue(OVERVIEW_RULER_HOVER.equals(type) || TEXT_RULER_HOVER.equals(type) || VERTICAL_RULER_HOVER.equals(type)); + fType= type; + } /** * Returns the distance to the ruler line. @@ -60,7 +79,6 @@ public class JavaAnnotationHover implements IAnnotationHover { protected List select(List exactMatch, List including) { return exactMatch; } - /** * Returns one marker which includes the ruler's line of activity. */ @@ -78,31 +96,97 @@ public class JavaAnnotationHover implements IAnnotationHover { Iterator e= model.getAnnotationIterator(); HashMap messagesAtPosition= new HashMap(); while (e.hasNext()) { - Object o= e.next(); - if (o instanceof IJavaAnnotation) { - IJavaAnnotation a= (IJavaAnnotation)o; - if (!a.hasOverlay()) { - Position position= model.getPosition((Annotation)a); - if (position == null) - continue; + Annotation annotation= (Annotation) e.next(); - if (isDuplicateJavaAnnotation(messagesAtPosition, position, a.getMessage())) + if (annotation.getText() == null) + continue; + + Position position= model.getPosition(annotation); + if (position == null) + continue; + + AnnotationPreference preference= getAnnotationPreference(annotation); + if (preference == null) + continue; + + if (OVERVIEW_RULER_HOVER.equals(fType)) { + String key= preference.getOverviewRulerPreferenceKey(); + if (key == null || !fStore.getBoolean(key)) + continue; + } else if (TEXT_RULER_HOVER.equals(fType)) { + String key= preference.getTextPreferenceKey(); + if (key != null) { + if (!fStore.getBoolean(key)) + continue; + } else { + key= preference.getHighlightPreferenceKey(); + if (key == null || !fStore.getBoolean(key)) continue; - - switch (compareRulerLine(position, document, line)) { - case 1: - exact.add(a); - break; - case 2: - including.add(a); - break; - } } + } else if (VERTICAL_RULER_HOVER.equals(fType)) { + String key= preference.getVerticalRulerPreferenceKey(); + // backward compatibility + if (key != null && !fStore.getBoolean(key)) + continue; + } + + if (isDuplicateJavaAnnotation(messagesAtPosition, position, annotation.getText())) + continue; + + switch (compareRulerLine(position, document, line)) { + case 1: + exact.add(annotation); + break; + case 2: + including.add(annotation); + break; } } return select(exact, including); } +// /** +// * Returns one marker which includes the ruler's line of activity. +// */ +// protected List getJavaAnnotationsForLine(ISourceViewer viewer, int line) { +// +// IDocument document= viewer.getDocument(); +// IAnnotationModel model= viewer.getAnnotationModel(); +// +// if (model == null) +// return null; +// +// List exact= new ArrayList(); +// List including= new ArrayList(); +// +// Iterator e= model.getAnnotationIterator(); +// HashMap messagesAtPosition= new HashMap(); +// while (e.hasNext()) { +// Object o= e.next(); +// if (o instanceof IJavaAnnotation) { +// IJavaAnnotation a= (IJavaAnnotation)o; +// if (!a.hasOverlay()) { +// Position position= model.getPosition((Annotation)a); +// if (position == null) +// continue; +// +// if (isDuplicateJavaAnnotation(messagesAtPosition, position, a.getMessage())) +// continue; +// +// switch (compareRulerLine(position, document, line)) { +// case 1: +// exact.add(a); +// break; +// case 2: +// including.add(a); +// break; +// } +// } +// } +// } +// +// return select(exact, including); +// } private boolean isDuplicateJavaAnnotation(Map messagesAtPosition, Position position, String message) { if (messagesAtPosition.containsKey(position)) { @@ -126,7 +210,7 @@ public class JavaAnnotationHover implements IAnnotationHover { messagesAtPosition.put(position, message); return false; } - + /* * @see IVerticalRulerHover#getHoverInfo(ISourceViewer, int) */ @@ -137,8 +221,8 @@ public class JavaAnnotationHover implements IAnnotationHover { if (javaAnnotations.size() == 1) { // optimization - IJavaAnnotation javaAnnotation= (IJavaAnnotation) javaAnnotations.get(0); - String message= javaAnnotation.getMessage(); + Annotation annotation= (Annotation) javaAnnotations.get(0); + String message= annotation.getText(); if (message != null && message.trim().length() > 0) return formatSingleMessage(message); @@ -148,8 +232,8 @@ public class JavaAnnotationHover implements IAnnotationHover { Iterator e= javaAnnotations.iterator(); while (e.hasNext()) { - IJavaAnnotation javaAnnotation= (IJavaAnnotation) e.next(); - String message= javaAnnotation.getMessage(); + Annotation annotation= (Annotation) e.next(); + String message= annotation.getText(); if (message != null && message.trim().length() > 0) messages.add(message.trim()); } @@ -164,6 +248,43 @@ public class JavaAnnotationHover implements IAnnotationHover { return null; } + /* + * @see IVerticalRulerHover#getHoverInfo(ISourceViewer, int) + */ +// public String getHoverInfo(ISourceViewer sourceViewer, int lineNumber) { +// List javaAnnotations= getJavaAnnotationsForLine(sourceViewer, lineNumber); +// if (javaAnnotations != null) { +// +// if (javaAnnotations.size() == 1) { +// +// // optimization +// IJavaAnnotation javaAnnotation= (IJavaAnnotation) javaAnnotations.get(0); +// String message= javaAnnotation.getMessage(); +// if (message != null && message.trim().length() > 0) +// return formatSingleMessage(message); +// +// } else { +// +// List messages= new ArrayList(); +// +// Iterator e= javaAnnotations.iterator(); +// while (e.hasNext()) { +// IJavaAnnotation javaAnnotation= (IJavaAnnotation) e.next(); +// String message= javaAnnotation.getMessage(); +// if (message != null && message.trim().length() > 0) +// messages.add(message.trim()); +// } +// +// if (messages.size() == 1) +// return formatSingleMessage((String) messages.get(0)); +// +// if (messages.size() > 1) +// return formatMultipleMessages(messages); +// } +// } +// +// return null; +// } /* * Formats a message as HTML text. @@ -193,4 +314,14 @@ public class JavaAnnotationHover implements IAnnotationHover { HTMLPrinter.addPageEpilog(buffer); return buffer.toString(); } + + /** + * Returns the annotation preference for the given annotation. + * + * @param annotation the annotation + * @return the annotation preference or null if none + */ + private AnnotationPreference getAnnotationPreference(Annotation annotation) { + return EditorsUI.getAnnotationPreferenceLookup().getAnnotationPreference(annotation); + } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/PHPAnnotationHover.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/PHPAnnotationHover.java deleted file mode 100644 index aea860f..0000000 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/PHPAnnotationHover.java +++ /dev/null @@ -1,186 +0,0 @@ -package net.sourceforge.phpdt.internal.ui.text; -/********************************************************************** -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 - Klaus Hartlage - www.eclipseproject.de -**********************************************************************/ - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -import org.eclipse.core.resources.IMarker; -import org.eclipse.jface.text.BadLocationException; -import org.eclipse.jface.text.IDocument; -import org.eclipse.jface.text.Position; -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.texteditor.MarkerAnnotation; - -/** - * The PHPAnnotationHover provides the hover support for PHP editors. - */ - -public class PHPAnnotationHover implements IAnnotationHover { - - /* (non-Javadoc) - * Method declared on IAnnotationHover - */ -// public String getHoverInfo(ISourceViewer sourceViewer, int lineNumber) { -// IDocument document= sourceViewer.getDocument(); -// -// try { -// IRegion info= document.getLineInformation(lineNumber); -// return document.get(info.getOffset(), info.getLength()); -// } catch (BadLocationException x) { -// } -// -// return null; -// } -// - static final int MAX_INFO_LENGTH = 80; - - /** - * @see org.eclipse.jface.text.source.IAnnotationHover#getHoverInfo(org.eclipse.jface.text.source.ISourceViewer, int) - */ - - public String getHoverInfo(ISourceViewer viewer, int line) { - String info = null; - List markers = getMarkersForLine(viewer, line); - if (markers != null) { - info = ""; - for (int i = 0; i < markers.size(); i++) { - IMarker marker = (IMarker) markers.get(i); - String message = - marker.getAttribute(IMarker.MESSAGE, (String) null); - if (message != null && message.trim().length() > 0) { - - if (message.length() > MAX_INFO_LENGTH) { - message = splitMessage(message); - } - info += message; - - if(i != markers.size() - 1) { - info += "\n"; - } - } - } - } - return info; - } - - private String splitMessage(String message) { - String result = ""; - - if(message.length() <= MAX_INFO_LENGTH) { - return message; - } - - String tmpStr = new String(message); - - while(tmpStr.length() > MAX_INFO_LENGTH) { - - int spacepos = tmpStr.indexOf(" ", MAX_INFO_LENGTH); - - if(spacepos != -1) { - result += tmpStr.substring(0, spacepos) + "\n"; - tmpStr = tmpStr.substring(spacepos); - } - else { - result += tmpStr.substring(0, MAX_INFO_LENGTH) + "\n"; - tmpStr = tmpStr.substring(MAX_INFO_LENGTH); - } - - - - } - - result += tmpStr; - - return result; - } - - /** - * Returns all markers which includes the ruler's line of activity. - */ - protected List getMarkersForLine(ISourceViewer aViewer, int aLine) { - List markers = new ArrayList(); - IAnnotationModel model = aViewer.getAnnotationModel(); - if (model != null) { - Iterator e = model.getAnnotationIterator(); - while (e.hasNext()) { - Object o = e.next(); - if (o instanceof MarkerAnnotation) { - MarkerAnnotation a = (MarkerAnnotation) o; - if (compareRulerLine(model.getPosition(a), - aViewer.getDocument(), - aLine) - != 0) { - markers.add(a.getMarker()); - } - } - } - } - return markers; - } - - /** - * Returns one marker which includes the ruler's line of activity. - */ - protected IMarker getMarkerForLine(ISourceViewer aViewer, int aLine) { - IMarker marker = null; - IAnnotationModel model = aViewer.getAnnotationModel(); - if (model != null) { - Iterator e = model.getAnnotationIterator(); - while (e.hasNext()) { - Object o = e.next(); - if (o instanceof MarkerAnnotation) { - MarkerAnnotation a = (MarkerAnnotation) o; - if (compareRulerLine(model.getPosition(a), - aViewer.getDocument(), - aLine) - != 0) { - marker = a.getMarker(); - } - } - } - } - return marker; - } - - /** - * Returns distance of given line to specified position (1 = same line, - * 2 = included in given position, 0 = not related). - */ - protected int compareRulerLine( - Position aPosition, - IDocument aDocument, - int aLine) { - int distance = 0; - if (aPosition.getOffset() > -1 && aPosition.getLength() > -1) { - try { - int markerLine = - aDocument.getLineOfOffset(aPosition.getOffset()); - if (aLine == markerLine) { - distance = 1; - } else if ( - markerLine <= aLine - && aLine - <= aDocument.getLineOfOffset( - aPosition.getOffset() - + aPosition.getLength())) { - distance = 2; - } - } catch (BadLocationException e) { - } - } - return distance; - } -} 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/AnnotationHover.java similarity index 61% rename from net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/hover/JavaProblemHover.java rename to net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/hover/AnnotationHover.java index 9b019ef..1c533df 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/AnnotationHover.java @@ -16,21 +16,27 @@ 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; import net.sourceforge.phpeclipse.phpeditor.JavaAnnotationIterator; import net.sourceforge.phpeclipse.phpeditor.PHPUnitEditor; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.ITextViewer; 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.editors.text.EditorsUI; +import org.eclipse.ui.texteditor.AnnotationPreference; +import org.eclipse.ui.texteditor.DefaultMarkerAnnotationAccess; import org.eclipse.ui.texteditor.IDocumentProvider; -public class JavaProblemHover extends AbstractJavaEditorTextHover { +public class AnnotationHover extends AbstractJavaEditorTextHover { + private IPreferenceStore fStore= PHPeclipsePlugin.getDefault().getPreferenceStore(); + private DefaultMarkerAnnotationAccess fAnnotationAccess= new DefaultMarkerAnnotationAccess(); + /* * Formats a message as HTML text. */ @@ -49,21 +55,35 @@ public class JavaProblemHover extends AbstractJavaEditorTextHover { if (getEditor() == null) return null; - + IDocumentProvider provider= PHPeclipsePlugin.getDefault().getCompilationUnitDocumentProvider(); IAnnotationModel model= provider.getAnnotationModel(getEditor().getEditorInput()); if (model != null) { Iterator e= new JavaAnnotationIterator(model, true); + int layer= -1; + String message= null; while (e.hasNext()) { Annotation a= (Annotation) e.next(); + + AnnotationPreference preference= getAnnotationPreference(a); + if (preference == null || !(fStore.getBoolean(preference.getTextPreferenceKey()) || (preference.getHighlightPreferenceKey() != null && fStore.getBoolean(preference.getHighlightPreferenceKey())))) + continue; + Position p= model.getPosition(a); - if (p.overlapsWith(hoverRegion.getOffset(), hoverRegion.getLength())) { - String msg= ((IJavaAnnotation) a).getMessage(); - if (msg != null && msg.trim().length() > 0) - return formatMessage(msg); + + int l= fAnnotationAccess.getLayer(a); + + if (l > layer && p != null && p.overlapsWith(hoverRegion.getOffset(), hoverRegion.getLength())) { + String msg= a.getText(); + if (msg != null && msg.trim().length() > 0) { + message= msg; + layer= l; + } } } + if (layer > -1) + return formatMessage(message); } return null; @@ -79,6 +99,19 @@ public class JavaProblemHover extends AbstractJavaEditorTextHover { super.setEditor(null); } + /** + * Returns the annotation preference for the given annotation. + * + * @param annotation the annotation + * @return the annotation preference or null if none + */ + private AnnotationPreference getAnnotationPreference(Annotation annotation) { + + if (annotation.isMarkedDeleted()) + return null; + return EditorsUI.getAnnotationPreferenceLookup().getAnnotationPreference(annotation); + } + static boolean isJavaProblemHover(String id) { return PreferenceConstants.ID_PROBLEM_HOVER.equals(id); } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/hover/BestMatchHover.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/hover/BestMatchHover.java index 88cd055..cb927fb 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/hover/BestMatchHover.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/hover/BestMatchHover.java @@ -10,10 +10,7 @@ *******************************************************************************/ package net.sourceforge.phpdt.internal.ui.text.java.hover; - import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; import java.util.Iterator; import java.util.List; @@ -21,54 +18,23 @@ import net.sourceforge.phpdt.ui.PreferenceConstants; import net.sourceforge.phpdt.ui.text.java.hover.IJavaEditorTextHover; import net.sourceforge.phpeclipse.PHPeclipsePlugin; +import org.eclipse.jface.text.IInformationControlCreator; import org.eclipse.jface.text.IRegion; import org.eclipse.jface.text.ITextHover; +import org.eclipse.jface.text.ITextHoverExtension; import org.eclipse.jface.text.ITextViewer; +import org.eclipse.jface.text.information.IInformationProviderExtension2; import org.eclipse.ui.IEditorPart; + /** * Caution: this implementation is a layer breaker and contains some "shortcuts" */ -public class BestMatchHover extends AbstractJavaEditorTextHover { - - private static class JavaEditorTextHoverDescriptorComparator implements Comparator { - - /* - * @see Comparator#compare(Object, Object) - */ - public int compare(Object object0, Object object1) { - - JavaEditorTextHoverDescriptor element0= (JavaEditorTextHoverDescriptor)object0; - JavaEditorTextHoverDescriptor element1= (JavaEditorTextHoverDescriptor)object1; - - String id0= element0.getId(); - String id1= element1.getId(); - - if (id0 != null && id0.equals(id1)) - return 0; - - if (id0 != null && JavaProblemHover.isJavaProblemHover(id0)) - return -1; - - if (id1 != null && JavaProblemHover.isJavaProblemHover(id1)) - return +1; - - - // now compare non-problem hovers - if (element0.dependsOn(element1)) - return -1; - - if (element1.dependsOn(element0)) - return +1; - - return 0; - } - } - - protected String fCurrentPerspectiveId; - protected List fTextHoverSpecifications; - protected List fInstantiatedTextHovers; +public class BestMatchHover extends AbstractJavaEditorTextHover implements ITextHoverExtension, IInformationProviderExtension2 { + private List fTextHoverSpecifications; + private List fInstantiatedTextHovers; + private ITextHover fBestHover; public BestMatchHover() { installTextHovers(); @@ -95,7 +61,6 @@ public class BestMatchHover extends AbstractJavaEditorTextHover { if (!PreferenceConstants.ID_BESTMATCH_HOVER.equals(hoverDescs[i].getId())) fTextHoverSpecifications.add(hoverDescs[i]); } - Collections.sort(fTextHoverSpecifications, new JavaEditorTextHoverDescriptorComparator()); } private void checkTextHovers() { @@ -125,18 +90,43 @@ public class BestMatchHover extends AbstractJavaEditorTextHover { public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) { checkTextHovers(); + fBestHover= null; if (fInstantiatedTextHovers == null) return null; for (Iterator iterator= fInstantiatedTextHovers.iterator(); iterator.hasNext(); ) { - ITextHover hover= (ITextHover) iterator.next(); + ITextHover hover= (ITextHover)iterator.next(); String s= hover.getHoverInfo(textViewer, hoverRegion); - if (s != null && s.trim().length() > 0) + if (s != null && s.trim().length() > 0) { + fBestHover= hover; return s; + } } return null; } + + /* + * @see org.eclipse.jface.text.ITextHoverExtension#getInformationControlCreator() + * @since 3.0 + */ + public IInformationControlCreator getInformationControlCreator() { + if (fBestHover instanceof ITextHoverExtension) + return ((ITextHoverExtension)fBestHover).getInformationControlCreator(); + + return null; + } + + /* + * @see org.eclipse.jface.text.information.IInformationProviderExtension2#getInformationPresenterControlCreator() + * @since 3.0 + */ + public IInformationControlCreator getInformationPresenterControlCreator() { + if (fBestHover instanceof IInformationProviderExtension2) + return ((IInformationProviderExtension2)fBestHover).getInformationPresenterControlCreator(); + + return null; + } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/hover/JavaTypeHover.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/hover/JavaTypeHover.java new file mode 100644 index 0000000..288f7c0 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpdt/internal/ui/text/java/hover/JavaTypeHover.java @@ -0,0 +1,58 @@ +/******************************************************************************* + * 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.java.hover; + +import org.eclipse.jface.text.IRegion; +import org.eclipse.jface.text.ITextViewer; + +import org.eclipse.ui.IEditorPart; + +import net.sourceforge.phpdt.ui.text.java.hover.IJavaEditorTextHover; + + +public class JavaTypeHover implements IJavaEditorTextHover { + + private IJavaEditorTextHover fAnnotationHover; + //private IJavaEditorTextHover fJavadocHover; + + public JavaTypeHover() { + fAnnotationHover= new AnnotationHover(); + // fJavadocHover= new JavadocHover(); + } + + /** + * @see IJavaEditorTextHover#setEditor(IEditorPart) + */ + public void setEditor(IEditorPart editor) { + fAnnotationHover.setEditor(editor); + // fJavadocHover.setEditor(editor); + } + + /* + * @see ITextHover#getHoverRegion(ITextViewer, int) + */ + public IRegion getHoverRegion(ITextViewer textViewer, int offset) { + //return fJavadocHover.getHoverRegion(textViewer, offset); + return null; + } + + /* + * @see ITextHover#getHoverInfo(ITextViewer, IRegion) + */ + public String getHoverInfo(ITextViewer textViewer, IRegion hoverRegion) { + String hoverInfo= fAnnotationHover.getHoverInfo(textViewer, hoverRegion); + if (hoverInfo != null) + return hoverInfo; + + //return fJavadocHover.getHoverInfo(textViewer, hoverRegion); + return null; + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPPerspectiveFactory.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPPerspectiveFactory.java index 0f29b99..364df7a 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPPerspectiveFactory.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/PHPPerspectiveFactory.java @@ -1,7 +1,6 @@ package net.sourceforge.phpeclipse; import org.eclipse.debug.ui.IDebugUIConstants; -import org.eclipse.swt.SWT; import org.eclipse.ui.IFolderLayout; import org.eclipse.ui.IPageLayout; import org.eclipse.ui.IPerspectiveFactory; @@ -30,10 +29,7 @@ public class PHPPerspectiveFactory implements IPerspectiveFactory { editorArea); consoleArea.addView(IPageLayout.ID_TASK_LIST); - consoleArea.addView(IDebugUIConstants.ID_CONSOLE_VIEW); -// if (SWT.getPlatform().equals("win32")) { -// consoleArea.addView(UpdatePerspective.ID_BROWSER); -// } + consoleArea.addView(org.eclipse.ui.console.IConsoleConstants.ID_CONSOLE_VIEW); consoleArea.addView(IPageLayout.ID_BOOKMARKS); layout.addView( @@ -46,11 +42,10 @@ public class PHPPerspectiveFactory implements IPerspectiveFactory { layout.addActionSet(IPageLayout.ID_NAVIGATE_ACTION_SET); layout.addActionSet(PHPeclipsePlugin.PHP_CODING_ACTION_SET_ID); - layout.addShowViewShortcut(IDebugUIConstants.ID_CONSOLE_VIEW); + layout.addShowViewShortcut(org.eclipse.ui.console.IConsoleConstants.ID_CONSOLE_VIEW); // if (SWT.getPlatform().equals("win32")) { -// layout.addShowViewShortcut(UpdatePerspective.ID_BROWSER); -// } - +// layout.addShowViewShortcut(UpdatePerspective.ID_BROWSER); +// } // layout.addShowViewShortcut(PHPeclipsePlugin.PHP_RESOURCES_VIEW_ID); // views - standard workbench diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/BreakpointImageProvider.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/BreakpointImageProvider.java new file mode 100644 index 0000000..c425748 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/BreakpointImageProvider.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.phpeclipse.phpeditor; + +import org.eclipse.core.resources.IMarker; + +import org.eclipse.debug.ui.DebugUITools; +import org.eclipse.debug.ui.IDebugModelPresentation; + +import org.eclipse.swt.graphics.Image; + +import org.eclipse.jface.resource.ImageDescriptor; + +import org.eclipse.jface.text.source.Annotation; + +import org.eclipse.ui.texteditor.IAnnotationImageProvider; +import org.eclipse.ui.texteditor.MarkerAnnotation; + +/** + * BreakpointImageProvider + * @since 3.0 + */ +public class BreakpointImageProvider implements IAnnotationImageProvider { + + private IDebugModelPresentation fPresentation; + + /* + * @see org.eclipse.jface.text.source.IAnnotationImageProvider#getManagedImage(org.eclipse.jface.text.source.Annotation) + */ + public Image getManagedImage(Annotation annotation) { + if (annotation instanceof MarkerAnnotation) { + MarkerAnnotation markerAnnotation= (MarkerAnnotation) annotation; + IMarker marker= markerAnnotation.getMarker(); + if (marker != null && marker.exists()) + return getPresentation().getImage(marker); + } + + return null; + } + + /* + * @see org.eclipse.jface.text.source.IAnnotationImageProvider#getImageDescriptorId(org.eclipse.jface.text.source.Annotation) + */ + public String getImageDescriptorId(Annotation annotation) { + return null; + } + + /* + * @see org.eclipse.jface.text.source.IAnnotationImageProvider#getImageDescriptor(java.lang.String) + */ + public ImageDescriptor getImageDescriptor(String imageDescritporId) { + return null; + } + + private IDebugModelPresentation getPresentation() { + if (fPresentation == null) + fPresentation= DebugUITools.newDebugModelPresentation(); + return fPresentation; + } +} 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 1a07289..5634c76 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/IJavaAnnotation.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/IJavaAnnotation.java @@ -15,6 +15,8 @@ import java.util.Iterator; import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Display; +import net.sourceforge.phpdt.core.ICompilationUnit; + /** * Interface of annotations representing markers * and problems. @@ -24,32 +26,25 @@ import org.eclipse.swt.widgets.Display; */ public interface IJavaAnnotation { - AnnotationType getAnnotationType(); - - boolean isTemporary(); - - String getMessage(); - - String[] getArguments(); - - int getId(); + /** + * @see org.eclipse.jface.text.source.Annotation#getType() + */ + String getType(); + /** + * @see org.eclipse.jface.text.source.Annotation#isPersistent() + */ + boolean isPersistent(); - Image getImage(Display display); + /** + * @see org.eclipse.jface.text.source.Annotation#isMarkedDeleted() + */ + boolean isMarkedDeleted(); /** - * Returns whether this annotation is relavant. - *

- * If the annotation is overlaid then it is not - * relevant. After all overlays have been removed - * the annotation might either become relevant again - * or stay irrelevant. - *

- * - * @return true if relevant - * @see #hasOverlay() + * @see org.eclipse.jface.text.source.Annotation#getText() */ - boolean isRelevant(); + String getText(); /** * Returns whether this annotation is overlaid. @@ -59,6 +54,14 @@ public interface IJavaAnnotation { boolean hasOverlay(); /** + * Returns the overlay of this annotation. + * + * @return the annotation's overlay + * @since 3.0 + */ + IJavaAnnotation getOverlay(); + + /** * Returns an iterator for iterating over the * annotation which are overlaid by this annotation. * @@ -89,4 +92,16 @@ public interface IJavaAnnotation { * @return true if it is a problem annotation */ boolean isProblem(); -} \ No newline at end of file + + /** + * Returns the compilation unit corresponding to the document on which the annotation is set + * or null if no corresponding co0mpilationunit exists. + */ + ICompilationUnit getCompilationUnit(); + + String[] getArguments(); + + int getId(); + + Image getImage(Display display); +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaAnnotationImageProvider.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaAnnotationImageProvider.java new file mode 100644 index 0000000..6ec9b9b --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaAnnotationImageProvider.java @@ -0,0 +1,167 @@ +/******************************************************************************* + * 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.phpeditor; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.graphics.Image; +import org.eclipse.swt.widgets.Display; + +import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.resource.ImageRegistry; + +import org.eclipse.jface.text.source.Annotation; + +import org.eclipse.ui.ISharedImages; +import org.eclipse.ui.PlatformUI; +import org.eclipse.ui.texteditor.IAnnotationImageProvider; + +import net.sourceforge.phpdt.ui.PreferenceConstants; + +import net.sourceforge.phpdt.internal.ui.PHPUiImages; +//import net.sourceforge.phpdt.internal.ui.text.correction.JavaCorrectionProcessor; + +/** + * Image provider for annotations based on Java problem markers. + * + * @since 3.0 + */ +public class JavaAnnotationImageProvider implements IAnnotationImageProvider { + + private final static int NO_IMAGE= 0; + private final static int GRAY_IMAGE= 1; + private final static int OVERLAY_IMAGE= 2; + private final static int QUICKFIX_IMAGE= 3; + private final static int QUICKFIX_ERROR_IMAGE= 4; + + + private static Image fgQuickFixImage; + private static Image fgQuickFixErrorImage; + private static ImageRegistry fgImageRegistry; + + private boolean fShowQuickFixIcon; + private int fCachedImageType; + private Image fCachedImage; + + + public JavaAnnotationImageProvider() { + fShowQuickFixIcon= PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_CORRECTION_INDICATION); + } + + /* + * @see org.eclipse.jface.text.source.IAnnotationImageProvider#getManagedImage(org.eclipse.jface.text.source.Annotation) + */ + public Image getManagedImage(Annotation annotation) { + if (annotation instanceof IJavaAnnotation) { + IJavaAnnotation javaAnnotation= (IJavaAnnotation) annotation; + int imageType= getImageType(javaAnnotation); + return getImage(javaAnnotation, imageType, Display.getCurrent()); + } + return null; + } + + /* + * @see org.eclipse.jface.text.source.IAnnotationImageProvider#getImageDescriptorId(org.eclipse.jface.text.source.Annotation) + */ + public String getImageDescriptorId(Annotation annotation) { + // unmanaged images are not supported + return null; + } + + /* + * @see org.eclipse.jface.text.source.IAnnotationImageProvider#getImageDescriptor(java.lang.String) + */ + public ImageDescriptor getImageDescriptor(String symbolicName) { + // unmanaged images are not supported + return null; + } + + + private boolean showQuickFix(IJavaAnnotation annotation) { + // return fShowQuickFixIcon && annotation.isProblem() && JavaCorrectionProcessor.hasCorrections(annotation); + return false; + } + + private Image getQuickFixImage() { + if (fgQuickFixImage == null) + fgQuickFixImage= PHPUiImages.get(PHPUiImages.IMG_OBJS_FIXABLE_PROBLEM); + return fgQuickFixImage; + } + + private Image getQuickFixErrorImage() { + if (fgQuickFixErrorImage == null) + fgQuickFixErrorImage= PHPUiImages.get(PHPUiImages.IMG_OBJS_FIXABLE_ERROR); + return fgQuickFixErrorImage; + } + + private ImageRegistry getImageRegistry(Display display) { + if (fgImageRegistry == null) + fgImageRegistry= new ImageRegistry(display); + return fgImageRegistry; + } + + private int getImageType(IJavaAnnotation annotation) { + int imageType= NO_IMAGE; + if (annotation.hasOverlay()) + imageType= OVERLAY_IMAGE; + else if (!annotation.isMarkedDeleted()) { + if (showQuickFix(annotation)) + imageType= JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(annotation.getType()) ? QUICKFIX_ERROR_IMAGE : QUICKFIX_IMAGE; + } else { + imageType= GRAY_IMAGE; + } + return imageType; + } + + private Image getImage(IJavaAnnotation annotation, int imageType, Display display) { + if (fCachedImageType == imageType) + return fCachedImage; + + Image image= null; + switch (imageType) { + case OVERLAY_IMAGE: + IJavaAnnotation overlay= annotation.getOverlay(); + image= overlay.getImage(display); + break; + case QUICKFIX_IMAGE: + image= getQuickFixImage(); + break; + case QUICKFIX_ERROR_IMAGE: + image= getQuickFixErrorImage(); + break; + case GRAY_IMAGE: { + ISharedImages sharedImages= PlatformUI.getWorkbench().getSharedImages(); + String annotationType= annotation.getType(); + if (JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(annotationType)) { + image= sharedImages.getImage(ISharedImages.IMG_OBJS_ERROR_TSK); + } else if (JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE.equals(annotationType)) { + image= sharedImages.getImage(ISharedImages.IMG_OBJS_WARN_TSK); + } else if (JavaMarkerAnnotation.INFO_ANNOTATION_TYPE.equals(annotationType)) { + image= sharedImages.getImage(ISharedImages.IMG_OBJS_INFO_TSK); + } + if (image != null) { + ImageRegistry registry= getImageRegistry(display); + String key= Integer.toString(image.hashCode()); + Image grayImage= registry.get(key); + if (grayImage == null) { + grayImage= new Image(display, image, SWT.IMAGE_GRAY); + registry.put(key, grayImage); + } + image= grayImage; + } + break; + } + } + + fCachedImageType= imageType; + fCachedImage= image; + return fCachedImage; + } +} diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaAnnotationIterator.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaAnnotationIterator.java index 66b9669..ad4eb24 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaAnnotationIterator.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaAnnotationIterator.java @@ -10,8 +10,10 @@ *******************************************************************************/ package net.sourceforge.phpeclipse.phpeditor; +import java.util.Collections; import java.util.Iterator; +import org.eclipse.jface.text.source.Annotation; import org.eclipse.jface.text.source.IAnnotationModel; @@ -21,29 +23,49 @@ import org.eclipse.jface.text.source.IAnnotationModel; public class JavaAnnotationIterator implements Iterator { private Iterator fIterator; - private IJavaAnnotation fNext; + private Annotation fNext; private boolean fSkipIrrelevants; + private boolean fReturnAllAnnotations; + /** + * Equivalent to JavaAnnotationIterator(model, skipIrrelevants, false). + */ public JavaAnnotationIterator(IAnnotationModel model, boolean skipIrrelevants) { - fIterator= model.getAnnotationIterator(); + this(model, skipIrrelevants, false); + } + + /** + * Returns a new JavaAnnotationIterator. + * @param model the annotation model + * @param skipIrrelevants whether to skip irrelevant annotations + * @param returnAllAnnotations Whether to return non IJavaAnnotations as well + */ + public JavaAnnotationIterator(IAnnotationModel model, boolean skipIrrelevants, boolean returnAllAnnotations) { + fReturnAllAnnotations= returnAllAnnotations; + if (model != null) + fIterator= model.getAnnotationIterator(); + else + fIterator= Collections.EMPTY_LIST.iterator(); fSkipIrrelevants= skipIrrelevants; skip(); } private void skip() { while (fIterator.hasNext()) { - Object next= fIterator.next(); + Annotation next= (Annotation) fIterator.next(); if (next instanceof IJavaAnnotation) { - IJavaAnnotation a= (IJavaAnnotation) next; if (fSkipIrrelevants) { - if (a.isRelevant()) { - fNext= a; + if (!next.isMarkedDeleted()) { + fNext= next; return; } } else { - fNext= a; + fNext= next; return; } + } else if (fReturnAllAnnotations) { + fNext= next; + return; } } fNext= null; diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaMarkerAnnotation.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaMarkerAnnotation.java index 64905c4..65b7e5d 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaMarkerAnnotation.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaMarkerAnnotation.java @@ -14,46 +14,31 @@ package net.sourceforge.phpeclipse.phpeditor; import java.util.Iterator; -import net.sourceforge.phpdt.internal.ui.PHPUiImages; -import net.sourceforge.phpdt.ui.PreferenceConstants; -import net.sourceforge.phpeclipse.PHPeclipsePlugin; - import org.eclipse.core.resources.IMarker; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.debug.core.model.IBreakpoint; -import org.eclipse.debug.ui.DebugUITools; -import org.eclipse.debug.ui.IDebugModelPresentation; -import org.eclipse.jface.resource.ImageRegistry; -import org.eclipse.jface.text.Assert; -import org.eclipse.search.ui.SearchUI; -import org.eclipse.swt.SWT; + import org.eclipse.swt.graphics.Image; import org.eclipse.swt.widgets.Display; + import org.eclipse.ui.texteditor.MarkerAnnotation; -import org.eclipse.ui.texteditor.MarkerUtilities; + +import net.sourceforge.phpdt.core.ICompilationUnit; +import net.sourceforge.phpdt.core.IJavaElement; +import net.sourceforge.phpdt.core.IJavaModelMarker; +import net.sourceforge.phpdt.core.JavaCore; + +import net.sourceforge.phpdt.internal.corext.util.JavaModelUtil; public class JavaMarkerAnnotation extends MarkerAnnotation implements IJavaAnnotation { - - private static final int NO_IMAGE= 0; - private static final int ORIGINAL_MARKER_IMAGE= 1; - private static final int QUICKFIX_IMAGE= 2; - private static final int QUICKFIX_ERROR_IMAGE= 3; - private static final int OVERLAY_IMAGE= 4; - private static final int GRAY_IMAGE= 5; - private static final int BREAKPOINT_IMAGE= 6; - private static Image fgQuickFixImage; - private static Image fgQuickFixErrorImage; - private static ImageRegistry fgGrayMarkersImageRegistry; - - private IDebugModelPresentation fPresentation; + public static final String JAVA_MARKER_TYPE_PREFIX= "org.eclipse.jdt"; //$NON-NLS-1$ + public static final String ERROR_ANNOTATION_TYPE= "org.eclipse.jdt.ui.error"; //$NON-NLS-1$ + public static final String WARNING_ANNOTATION_TYPE= "org.eclipse.jdt.ui.warning"; //$NON-NLS-1$ + public static final String INFO_ANNOTATION_TYPE= "org.eclipse.jdt.ui.info"; //$NON-NLS-1$ + public static final String TASK_ANNOTATION_TYPE= "org.eclipse.ui.workbench.texteditor.task"; //$NON-NLS-1$ + private IJavaAnnotation fOverlay; - private boolean fNotRelevant= false; - private AnnotationType fType; - private int fImageType; - private boolean fQuickFixIconEnabled; public JavaMarkerAnnotation(IMarker marker) { @@ -61,95 +46,10 @@ public class JavaMarkerAnnotation extends MarkerAnnotation implements IJavaAnnot } /* - * @see MarkerAnnotation#getUnknownImageName(IMarker) - */ - protected String getUnknownImageName(IMarker marker) { - return PHPUiImages.IMG_OBJS_GHOST; - } - - /** - * Initializes the annotation's icon representation and its drawing layer - * based upon the properties of the underlying marker. - */ - protected void initialize() { - fQuickFixIconEnabled= PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_CORRECTION_INDICATION); - fImageType= NO_IMAGE; - IMarker marker= getMarker(); - - if (MarkerUtilities.isMarkerType(marker, IBreakpoint.BREAKPOINT_MARKER)) { - - if (fPresentation == null) - fPresentation= DebugUITools.newDebugModelPresentation(); - - setImage(null); // see bug 32469 - setLayer(4); - fImageType= BREAKPOINT_IMAGE; - - fType= AnnotationType.UNKNOWN; - - } else { - - fType= AnnotationType.UNKNOWN; - if (marker.exists()) { - try { - - if (marker.isSubtypeOf(IMarker.PROBLEM)) { - int severity= marker.getAttribute(IMarker.SEVERITY, -1); - switch (severity) { - case IMarker.SEVERITY_ERROR: - fType= AnnotationType.ERROR; - break; - case IMarker.SEVERITY_WARNING: - fType= AnnotationType.WARNING; - break; - } - } else if (marker.isSubtypeOf(IMarker.TASK)) - fType= AnnotationType.TASK; - else if (marker.isSubtypeOf(SearchUI.SEARCH_MARKER)) - fType= AnnotationType.SEARCH; - else if (marker.isSubtypeOf(IMarker.BOOKMARK)) - fType= AnnotationType.BOOKMARK; - - } catch(CoreException e) { - PHPeclipsePlugin.log(e); - } - } - super.initialize(); - } - } - -// private boolean mustShowQuickFixIcon() { -// return fQuickFixIconEnabled && JavaCorrectionProcessor.hasCorrections(getMarker()); -// } -// -// private Image getQuickFixImage() { -// if (fgQuickFixImage == null) -// fgQuickFixImage= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_PROBLEM); -// return fgQuickFixImage; -// } -// -// private Image getQuickFixErrorImage() { -// if (fgQuickFixErrorImage == null) -// fgQuickFixErrorImage= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_ERROR); -// return fgQuickFixErrorImage; -// } - - /* - * @see IJavaAnnotation#getMessage() - */ - public String getMessage() { - IMarker marker= getMarker(); - if (marker == null || !marker.exists()) - return ""; //$NON-NLS-1$ - else - return marker.getAttribute(IMarker.MESSAGE, ""); //$NON-NLS-1$ - } - - /* - * @see IJavaAnnotation#isTemporary() + * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getImage(org.eclipse.swt.widgets.Display) */ - public boolean isTemporary() { - return false; + public Image getImage(Display display) { + return super.getImage(display); } /* @@ -157,8 +57,8 @@ public class JavaMarkerAnnotation extends MarkerAnnotation implements IJavaAnnot */ public String[] getArguments() { IMarker marker= getMarker(); -// if (marker != null && marker.exists() && isProblem()) -// return Util.getProblemArgumentsFromMarker(marker.getAttribute(IJavaModelMarker.ARGUMENTS, "")); //$NON-NLS-1$ + if (marker != null && marker.exists() && isProblem()) + return JavaModelUtil.getProblemArgumentsFromMarker(marker.getAttribute(IJavaModelMarker.ARGUMENTS, "")); //$NON-NLS-1$ return null; } @@ -167,8 +67,22 @@ public class JavaMarkerAnnotation extends MarkerAnnotation implements IJavaAnnot */ public int getId() { IMarker marker= getMarker(); -// if (marker != null && marker.exists() && isProblem()) -// return marker.getAttribute(IJavaModelMarker.ID, -1); + if (marker == null || !marker.exists()) + return -1; + + if (isProblem()) + return marker.getAttribute(IJavaModelMarker.ID, -1); + +// if (TASK_ANNOTATION_TYPE.equals(getAnnotationType())) { +// try { +// if (marker.isSubtypeOf(IJavaModelMarker.TASK_MARKER)) { +// return IProblem.Task; +// } +// } catch (CoreException e) { +// JavaPlugin.log(e); // should no happen, we test for marker.exists +// } +// } + return -1; } @@ -176,14 +90,8 @@ public class JavaMarkerAnnotation extends MarkerAnnotation implements IJavaAnnot * @see IJavaAnnotation#isProblem() */ public boolean isProblem() { - return fType == AnnotationType.WARNING || fType == AnnotationType.ERROR; - } - - /* - * @see IJavaAnnotation#isRelevant() - */ - public boolean isRelevant() { - return !fNotRelevant; + String type= getType(); + return WARNING_ANNOTATION_TYPE.equals(type) || ERROR_ANNOTATION_TYPE.equals(type); } /** @@ -196,10 +104,11 @@ public class JavaMarkerAnnotation extends MarkerAnnotation implements IJavaAnnot fOverlay.removeOverlaid(this); fOverlay= javaAnnotation; - fNotRelevant= (fNotRelevant || fOverlay != null); + if (!isMarkedDeleted()) + markDeleted(fOverlay != null); - if (javaAnnotation != null) - javaAnnotation.addOverlaid(this); + if (fOverlay != null) + fOverlay.addOverlaid(this); } /* @@ -210,84 +119,10 @@ public class JavaMarkerAnnotation extends MarkerAnnotation implements IJavaAnnot } /* - * @see MarkerAnnotation#getImage(Display) + * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getOverlay() */ - public Image getImage(Display display) { - if (fImageType == BREAKPOINT_IMAGE) { - Image result= super.getImage(display); - if (result == null) { - IMarker marker= getMarker(); - if (marker != null && marker.exists()) { - result= fPresentation.getImage(getMarker()); - setImage(result); - } - } - return result; - } - - int newImageType= NO_IMAGE; - - if (hasOverlay()) - newImageType= OVERLAY_IMAGE; - else if (isRelevant()) { -// if (mustShowQuickFixIcon()) { -// if (fType == AnnotationType.ERROR) -// newImageType= QUICKFIX_ERROR_IMAGE; -// else -// newImageType= QUICKFIX_IMAGE; -// } else - newImageType= ORIGINAL_MARKER_IMAGE; - } else - newImageType= GRAY_IMAGE; - - if (fImageType == newImageType && newImageType != OVERLAY_IMAGE) - // Nothing changed - simply return the current image - return super.getImage(display); - - Image newImage= null; - switch (newImageType) { - case ORIGINAL_MARKER_IMAGE: - newImage= null; - break; - case OVERLAY_IMAGE: - newImage= fOverlay.getImage(display); - break; -// case QUICKFIX_IMAGE: -// newImage= getQuickFixImage(); -// break; -// case QUICKFIX_ERROR_IMAGE: -// newImage= getQuickFixErrorImage(); -// break; - case GRAY_IMAGE: - if (fImageType != ORIGINAL_MARKER_IMAGE) - setImage(null); - Image originalImage= super.getImage(display); - if (originalImage != null) { - ImageRegistry imageRegistry= getGrayMarkerImageRegistry(display); - if (imageRegistry != null) { - String key= Integer.toString(originalImage.hashCode()); - Image grayImage= imageRegistry.get(key); - if (grayImage == null) { - grayImage= new Image(display, originalImage, SWT.IMAGE_GRAY); - imageRegistry.put(key, grayImage); - } - newImage= grayImage; - } - } - break; - default: - Assert.isLegal(false); - } - - fImageType= newImageType; - setImage(newImage); - return super.getImage(display); - } - - private ImageRegistry getGrayMarkerImageRegistry(Display display) { - if (fgGrayMarkersImageRegistry == null) - fgGrayMarkersImageRegistry= new ImageRegistry(display); - return fgGrayMarkersImageRegistry; + public IJavaAnnotation getOverlay() { + return fOverlay; } /* @@ -311,11 +146,20 @@ public class JavaMarkerAnnotation extends MarkerAnnotation implements IJavaAnnot // not supported return null; } - - /* - * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getAnnotationType() + + /* (non-Javadoc) + * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getCompilationUnit() */ - public AnnotationType getAnnotationType() { - return fType; + public ICompilationUnit getCompilationUnit() { + IJavaElement element= JavaCore.create(getMarker().getResource()); + if (element instanceof ICompilationUnit) { + ICompilationUnit cu= (ICompilationUnit)element; + ICompilationUnit workingCopy= EditorUtility.getWorkingCopy(cu); + if (workingCopy != null) { + return workingCopy; + } + return cu; + } + return null; } } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaSelectMarkerRulerAction.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaSelectMarkerRulerAction.java index b32d137..6e01d7b 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaSelectMarkerRulerAction.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaSelectMarkerRulerAction.java @@ -13,44 +13,54 @@ package net.sourceforge.phpeclipse.phpeditor; import java.util.Iterator; import java.util.ResourceBundle; +import net.sourceforge.phpdt.core.ICompilationUnit; +import net.sourceforge.phpdt.core.IJavaElement; +import net.sourceforge.phpdt.core.JavaCore; import net.sourceforge.phpdt.internal.ui.IJavaHelpContextIds; +import net.sourceforge.phpdt.ui.PreferenceConstants; +import net.sourceforge.phpeclipse.PHPeclipsePlugin; +import org.eclipse.core.resources.IFile; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.ITextOperationTarget; import org.eclipse.jface.text.Position; import org.eclipse.jface.text.source.Annotation; import org.eclipse.jface.text.source.IVerticalRulerInfo; +import org.eclipse.ui.IEditorInput; +import org.eclipse.ui.IFileEditorInput; import org.eclipse.ui.help.WorkbenchHelp; import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel; import org.eclipse.ui.texteditor.ITextEditor; import org.eclipse.ui.texteditor.ITextEditorExtension; import org.eclipse.ui.texteditor.SelectMarkerRulerAction; + /** * A special select marker ruler action which activates quick fix if clicked on a quick fixable problem. */ public class JavaSelectMarkerRulerAction extends SelectMarkerRulerAction { - private ITextEditor fMyTextEditor; + private ITextEditor fTextEditor; private Position fPosition; public JavaSelectMarkerRulerAction(ResourceBundle bundle, String prefix, ITextEditor editor, IVerticalRulerInfo ruler) { super(bundle, prefix, editor, ruler); - fMyTextEditor= editor; + fTextEditor= editor; WorkbenchHelp.setHelp(this, IJavaHelpContextIds.JAVA_SELECT_MARKER_RULER_ACTION); } public void run() { - superCall: { - if (fPosition == null) - break superCall; - ITextOperationTarget operation= (ITextOperationTarget) fMyTextEditor.getAdapter(ITextOperationTarget.class); -// final int opCode= CompilationUnitEditor.CORRECTIONASSIST_PROPOSALS; - if (operation == null ) { //|| !operation.canDoOperation(opCode)) { - break superCall; - } - fMyTextEditor.selectAndReveal(fPosition.getOffset(), 0); -// operation.doOperation(opCode); +// if (PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_ANNOTATION_ROLL_OVER)) +// return; + + if (fPosition != null) { + ITextOperationTarget operation= (ITextOperationTarget) fTextEditor.getAdapter(ITextOperationTarget.class); +// final int opCode= PHPUnitEditor.CORRECTIONASSIST_PROPOSALS; +// if (operation != null && operation.canDoOperation(opCode)) { +// fTextEditor.selectAndReveal(fPosition.getOffset(), fPosition.getLength()); +// operation.doOperation(opCode); +// return; +// } return; } super.run(); @@ -58,7 +68,7 @@ public class JavaSelectMarkerRulerAction extends SelectMarkerRulerAction { public void update() { // Begin Fix for http://dev.eclipse.org/bugs/show_bug.cgi?id=20114 - if (!(fMyTextEditor instanceof ITextEditorExtension) || ((ITextEditorExtension) fMyTextEditor).isEditorInputReadOnly()) { + if (!(fTextEditor instanceof ITextEditorExtension) || ((ITextEditorExtension) fTextEditor).isEditorInputReadOnly()) { fPosition= null; super.update(); return; @@ -76,17 +86,47 @@ public class JavaSelectMarkerRulerAction extends SelectMarkerRulerAction { IDocument document= getDocument(); if (model == null) return null; + ICompilationUnit cu= getCompilationUnit(); + if (cu == null) { + return null; + } + +// boolean hasAssistLightbulb= PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.APPEARANCE_QUICKASSIST_LIGHTBULB); + Annotation assistAnnotation= null; + Iterator iter= model.getAnnotationIterator(); while (iter.hasNext()) { Annotation annotation= (Annotation) iter.next(); if (annotation instanceof IJavaAnnotation) { IJavaAnnotation javaAnnotation= (IJavaAnnotation)annotation; - if (javaAnnotation.isRelevant()) { + if (!javaAnnotation.isMarkedDeleted()) { Position position= model.getPosition(annotation); // if (includesRulerLine(position, document) && JavaCorrectionProcessor.hasCorrections(javaAnnotation)) // return position; } - } + } +// else if (hasAssistLightbulb && annotation instanceof AssistAnnotation) { +// // there is only one AssistAnnotation at a time +// assistAnnotation= annotation; +// } + } + if (assistAnnotation != null) { + Position position= model.getPosition(assistAnnotation); + // no need to check 'JavaCorrectionProcessor.hasAssists': annotation only created when + // there are assists + if (includesRulerLine(position, document)) + return position; + } + return null; + } + + private ICompilationUnit getCompilationUnit() { + IEditorInput input= fTextEditor.getEditorInput(); + if (input instanceof IFileEditorInput) { + IFile file= ((IFileEditorInput) input).getFile(); + IJavaElement element= JavaCore.create(file); + if (element instanceof ICompilationUnit) + return (ICompilationUnit) element; } return null; } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaSelectMarkerRulerAction2.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaSelectMarkerRulerAction2.java new file mode 100644 index 0000000..29a2fb4 --- /dev/null +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/JavaSelectMarkerRulerAction2.java @@ -0,0 +1,99 @@ +/******************************************************************************* + * 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.phpeditor; + +import java.util.ResourceBundle; + +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.text.ITextOperationTarget; +import org.eclipse.jface.text.Position; +import org.eclipse.jface.text.source.Annotation; +import org.eclipse.jface.text.source.AnnotationEvent; +import org.eclipse.jface.text.source.IAnnotationModel; +import org.eclipse.ui.ISelectionListener; +import org.eclipse.ui.texteditor.ITextEditor; +import org.eclipse.ui.texteditor.ITextEditorActionConstants; +import org.eclipse.ui.texteditor.IUpdate; +import org.eclipse.ui.texteditor.SelectMarkerRulerAction2; + +//import org.eclipse.jdt.internal.ui.IJavaHelpContextIds; +//import org.eclipse.jdt.internal.ui.text.correction.JavaCorrectionProcessor; +//import org.eclipse.jdt.internal.ui.text.correction.QuickAssistLightBulbUpdater.AssistAnnotation; +//import org.eclipse.jdt.internal.ui.text.java.hover.JavaExpandHover; + +/** + * A special select marker ruler action which activates quick fix if clicked on a quick fixable problem. + */ +public class JavaSelectMarkerRulerAction2 extends SelectMarkerRulerAction2 { + + public JavaSelectMarkerRulerAction2(ResourceBundle bundle, String prefix, ITextEditor editor) { + super(bundle, prefix, editor); +// WorkbenchHelp.setHelp(this, IJavaHelpContextIds.JAVA_SELECT_MARKER_RULER_ACTION); + } + + /* + * @see org.eclipse.ui.texteditor.IAnnotationListener#annotationDefaultSelected(org.eclipse.ui.texteditor.AnnotationEvent) + */ + public void annotationDefaultSelected(AnnotationEvent event) { + Annotation a= event.getAnnotation(); + IAnnotationModel model= getAnnotationModel(); + Position position= model.getPosition(a); + + if (isBreakpoint(a)) + triggerAction(ITextEditorActionConstants.RULER_DOUBLE_CLICK); + + if (position == null) + return; + + if (isQuickFixTarget(a)) { + ITextOperationTarget operation= (ITextOperationTarget) getTextEditor().getAdapter(ITextOperationTarget.class); +// final int opCode= PHPUnitEditor.CORRECTIONASSIST_PROPOSALS; +// if (operation != null && operation.canDoOperation(opCode)) { +// getTextEditor().selectAndReveal(position.getOffset(), position.getLength()); +// operation.doOperation(opCode); +// return; +// } + } + + // default: + super.annotationDefaultSelected(event); + } + + /** + * @param ma + * @return + */ + private boolean isBreakpoint(Annotation a) { + return a.getType().equals("org.eclipse.debug.core.breakpoint"); + //|| a.getType().equals(JavaExpandHover.NO_BREAKPOINT_ANNOTATION); //$NON-NLS-1$ + } + + private boolean isQuickFixTarget(Annotation a) { + // return a instanceof IJavaAnnotation && JavaCorrectionProcessor.hasCorrections((IJavaAnnotation) a) || a instanceof AssistAnnotation; + return false; + } + + private void triggerAction(String actionID) { + IAction action= getTextEditor().getAction(actionID); + if (action != null) { + if (action instanceof IUpdate) + ((IUpdate) action).update(); + // hack to propagate line change + if (action instanceof ISelectionListener) { + ((ISelectionListener)action).selectionChanged(null, null); + } + if (action.isEnabled()) + action.run(); + } + } + +} + 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 5751336..a79460d 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPDocumentProvider.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPDocumentProvider.java @@ -54,9 +54,11 @@ import org.eclipse.jface.text.ILineTracker; import org.eclipse.jface.text.Position; import org.eclipse.jface.text.source.Annotation; import org.eclipse.jface.text.source.AnnotationModelEvent; +import org.eclipse.jface.text.source.IAnnotationAccessExtension; import org.eclipse.jface.text.source.IAnnotationModel; import org.eclipse.jface.text.source.IAnnotationModelListener; import org.eclipse.jface.text.source.IAnnotationModelListenerExtension; +import org.eclipse.jface.text.source.IAnnotationPresentation; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.ListenerList; import org.eclipse.jface.util.PropertyChangeEvent; @@ -68,11 +70,12 @@ import org.eclipse.swt.widgets.Canvas; import org.eclipse.swt.widgets.Display; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IFileEditorInput; +import org.eclipse.ui.editors.text.EditorsUI; 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.AnnotationPreference; +import org.eclipse.ui.texteditor.AnnotationPreferenceLookup; import org.eclipse.ui.texteditor.MarkerAnnotation; import org.eclipse.ui.texteditor.ResourceMarkerAnnotationModel; @@ -533,225 +536,211 @@ public class PHPDocumentProvider extends FileDocumentProvider { } /** - * Annotation representating an IProblem. - */ - 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; - 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 - // if (!fQuickFixImagesInitialized) { - // if (indicateQuixFixableProblems() && JavaCorrectionProcessor.hasCorrections(fProblem.getID())) { - // if (!fgQuickFixImagesInitialized) { - // fgQuickFixImage = JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_PROBLEM); - // fgQuickFixErrorImage = JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_ERROR); - // fgQuickFixImagesInitialized = true; - // } - // if (fType == AnnotationType.ERROR) - // fImage = fgQuickFixErrorImage; - // else - // fImage = fgQuickFixImage; - // } - // fQuickFixImagesInitialized = true; - // } - } - - private boolean indicateQuixFixableProblems() { - return PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_CORRECTION_INDICATION); - } - - /* - * @see Annotation#paint - */ - public void paint(GC gc, Canvas canvas, Rectangle r) { - initializeImages(); - if (fImage != null) - drawImage(fImage, gc, canvas, r, SWT.CENTER, SWT.TOP); - } - - /* - * @see IJavaAnnotation#getImage(Display) - */ - public Image getImage(Display display) { - initializeImages(); - return fImage; - } - - /* - * @see IJavaAnnotation#getMessage() - */ - public String getMessage() { - return fProblem.getMessage(); - } - - /* - * @see IJavaAnnotation#isTemporary() - */ - public boolean isTemporary() { - return true; - } - - /* - * @see IJavaAnnotation#getArguments() - */ - public String[] getArguments() { - return isProblem() ? fProblem.getArguments() : null; - } - - /* - * @see IJavaAnnotation#getId() - */ - public int getId() { - 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 WARNING_ANNOTATION_TYPE.equals(fType) || ERROR_ANNOTATION_TYPE.equals(fType); - } - - /* - * @see IJavaAnnotation#isRelevant() - */ - public boolean isRelevant() { - return true; - } - - /* - * @see IJavaAnnotation#hasOverlay() - */ - public boolean hasOverlay() { - return false; - } - - /* - * @see IJavaAnnotation#addOverlaid(IJavaAnnotation) - */ - public void addOverlaid(IJavaAnnotation annotation) { - if (fOverlaids == null) - fOverlaids = new ArrayList(1); - fOverlaids.add(annotation); - } - - /* - * @see IJavaAnnotation#removeOverlaid(IJavaAnnotation) - */ - public void removeOverlaid(IJavaAnnotation annotation) { - if (fOverlaids != null) { - fOverlaids.remove(annotation); - if (fOverlaids.size() == 0) - fOverlaids = null; - } - } - - /* - * @see IJavaAnnotation#getOverlaidIterator() - */ - public Iterator getOverlaidIterator() { - if (fOverlaids != null) - return fOverlaids.iterator(); - return null; - } - - - public AnnotationType getAnnotationType() { - 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; - } - }; + * Annotation representating an IProblem. + */ + static protected class ProblemAnnotation extends Annotation implements IJavaAnnotation, IAnnotationPresentation { + + private static final String SPELLING_ANNOTATION_TYPE= "org.eclipse.ui.workbench.texteditor.spelling"; + + //XXX: To be fully correct these constants should be non-static + /** + * The layer in which task problem annotations are located. + */ + private static final int TASK_LAYER; + /** + * The layer in which info problem annotations are located. + */ + private static final int INFO_LAYER; + /** + * The layer in which warning problem annotations representing are located. + */ + private static final int WARNING_LAYER; + /** + * The layer in which error problem annotations representing are located. + */ + private static final int ERROR_LAYER; + + static { + AnnotationPreferenceLookup lookup= EditorsUI.getAnnotationPreferenceLookup(); + TASK_LAYER= computeLayer("org.eclipse.ui.workbench.texteditor.task", lookup); //$NON-NLS-1$ + INFO_LAYER= computeLayer("net.sourceforge.phpdt.ui.info", lookup); //$NON-NLS-1$ + WARNING_LAYER= computeLayer("net.sourceforge.phpdt.ui.warning", lookup); //$NON-NLS-1$ + ERROR_LAYER= computeLayer("net.sourceforge.phpdt.ui.error", lookup); //$NON-NLS-1$ + } + + private static int computeLayer(String annotationType, AnnotationPreferenceLookup lookup) { + Annotation annotation= new Annotation(annotationType, false, null); + AnnotationPreference preference= lookup.getAnnotationPreference(annotation); + if (preference != null) + return preference.getPresentationLayer() + 1; + else + return IAnnotationAccessExtension.DEFAULT_LAYER + 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 int fLayer= IAnnotationAccessExtension.DEFAULT_LAYER; + + public ProblemAnnotation(IProblem problem, ICompilationUnit cu) { + + fProblem= problem; + fCompilationUnit= cu; + +// if (SpellProblem.Spelling == fProblem.getID()) { +// setType(SPELLING_ANNOTATION_TYPE); +// fLayer= WARNING_LAYER; +// } else + if (IProblem.Task == fProblem.getID()) { + setType(JavaMarkerAnnotation.TASK_ANNOTATION_TYPE); + fLayer= TASK_LAYER; + } else if (fProblem.isWarning()) { + setType(JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE); + fLayer= WARNING_LAYER; + } else if (fProblem.isError()) { + setType(JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE); + fLayer= ERROR_LAYER; + } else { + setType(JavaMarkerAnnotation.INFO_ANNOTATION_TYPE); + fLayer= INFO_LAYER; + } + } + + /* + * @see org.eclipse.jface.text.source.IAnnotationPresentation#getLayer() + */ + public int getLayer() { + return fLayer; + } + + private void initializeImages() { + // http://bugs.eclipse.org/bugs/show_bug.cgi?id=18936 +// if (!fQuickFixImagesInitialized) { +// if (isProblem() && indicateQuixFixableProblems() && JavaCorrectionProcessor.hasCorrections(this)) { // no light bulb for tasks +// if (!fgQuickFixImagesInitialized) { +// fgQuickFixImage= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_PROBLEM); +// fgQuickFixErrorImage= JavaPluginImages.get(JavaPluginImages.IMG_OBJS_FIXABLE_ERROR); +// fgQuickFixImagesInitialized= true; +// } +// if (JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(getType())) +// fImage= fgQuickFixErrorImage; +// else +// fImage= fgQuickFixImage; +// } +// fQuickFixImagesInitialized= true; +// } + } + + private boolean indicateQuixFixableProblems() { + return PreferenceConstants.getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_CORRECTION_INDICATION); + } + + /* + * @see Annotation#paint + */ + public void paint(GC gc, Canvas canvas, Rectangle r) { + initializeImages(); + if (fImage != null) + drawImage(fImage, gc, canvas, r, SWT.CENTER, SWT.TOP); + } + + /* + * @see IJavaAnnotation#getImage(Display) + */ + public Image getImage(Display display) { + initializeImages(); + return fImage; + } + + /* + * @see IJavaAnnotation#getMessage() + */ + public String getText() { + return fProblem.getMessage(); + } + + /* + * @see IJavaAnnotation#getArguments() + */ + public String[] getArguments() { + return isProblem() ? fProblem.getArguments() : null; + } + + /* + * @see IJavaAnnotation#getId() + */ + public int getId() { + return fProblem.getID(); + } + + /* + * @see IJavaAnnotation#isProblem() + */ + public boolean isProblem() { + String type= getType(); + return JavaMarkerAnnotation.WARNING_ANNOTATION_TYPE.equals(type) || + JavaMarkerAnnotation.ERROR_ANNOTATION_TYPE.equals(type) || + SPELLING_ANNOTATION_TYPE.equals(type); + } + + /* + * @see IJavaAnnotation#hasOverlay() + */ + public boolean hasOverlay() { + return false; + } + + /* + * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getOverlay() + */ + public IJavaAnnotation getOverlay() { + return null; + } + + /* + * @see IJavaAnnotation#addOverlaid(IJavaAnnotation) + */ + public void addOverlaid(IJavaAnnotation annotation) { + if (fOverlaids == null) + fOverlaids= new ArrayList(1); + fOverlaids.add(annotation); + } + + /* + * @see IJavaAnnotation#removeOverlaid(IJavaAnnotation) + */ + public void removeOverlaid(IJavaAnnotation annotation) { + if (fOverlaids != null) { + fOverlaids.remove(annotation); + if (fOverlaids.size() == 0) + fOverlaids= null; + } + } + + /* + * @see IJavaAnnotation#getOverlaidIterator() + */ + public Iterator getOverlaidIterator() { + if (fOverlaids != null) + return fOverlaids.iterator(); + return null; + } + + /* + * @see org.eclipse.jdt.internal.ui.javaeditor.IJavaAnnotation#getCompilationUnit() + */ + public ICompilationUnit getCompilationUnit() { + return fCompilationUnit; + } + } + + /** * Internal structure for mapping positions to some value. * The reason for this specific structure is that positions can diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java index a2f3ae0..47c1963 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPEditor.java @@ -12,8 +12,10 @@ Contributors: Klaus Hartlage - www.eclipseproject.de **********************************************************************/ import java.util.ArrayList; +import java.util.HashMap; import java.util.Iterator; import java.util.List; +import java.util.Map; import java.util.ResourceBundle; import java.util.StringTokenizer; @@ -32,7 +34,6 @@ import net.sourceforge.phpdt.ui.JavaUI; import net.sourceforge.phpdt.ui.PreferenceConstants; import net.sourceforge.phpdt.ui.actions.GenerateActionGroup; import net.sourceforge.phpdt.ui.actions.GotoMatchingBracketAction; -import net.sourceforge.phpdt.ui.text.IColorManager; import net.sourceforge.phpdt.ui.text.JavaTextTools; import net.sourceforge.phpeclipse.PHPCore; import net.sourceforge.phpeclipse.PHPeclipsePlugin; @@ -41,8 +42,11 @@ import net.sourceforge.phpeclipse.phpeditor.php.IPHPPartitionScannerConstants; import org.eclipse.core.resources.IMarker; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Preferences; +import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.jobs.Job; import org.eclipse.jface.action.Action; import org.eclipse.jface.action.GroupMarker; import org.eclipse.jface.action.IAction; @@ -72,19 +76,12 @@ import org.eclipse.jface.text.TextSelection; import org.eclipse.jface.text.information.IInformationProvider; import org.eclipse.jface.text.information.InformationPresenter; import org.eclipse.jface.text.source.Annotation; -import org.eclipse.jface.text.source.AnnotationRulerColumn; -import org.eclipse.jface.text.source.CompositeRuler; -import org.eclipse.jface.text.source.IAnnotationAccess; import org.eclipse.jface.text.source.IAnnotationModel; +import org.eclipse.jface.text.source.IAnnotationModelExtension; import org.eclipse.jface.text.source.IOverviewRuler; -import org.eclipse.jface.text.source.ISharedTextColors; import org.eclipse.jface.text.source.ISourceViewer; -import org.eclipse.jface.text.source.ISourceViewerExtension; import org.eclipse.jface.text.source.IVerticalRuler; -import org.eclipse.jface.text.source.IVerticalRulerColumn; -import org.eclipse.jface.text.source.LineNumberRulerColumn; import org.eclipse.jface.text.source.OverviewRuler; -import org.eclipse.jface.text.source.SourceViewer; import org.eclipse.jface.text.source.SourceViewerConfiguration; import org.eclipse.jface.util.IPropertyChangeListener; import org.eclipse.jface.util.PropertyChangeEvent; @@ -130,18 +127,15 @@ import org.eclipse.ui.actions.ActionGroup; import org.eclipse.ui.editors.text.DefaultEncodingSupport; import org.eclipse.ui.editors.text.IEncodingSupport; import org.eclipse.ui.part.IShowInTargetList; -import org.eclipse.ui.texteditor.AddTaskAction; import org.eclipse.ui.texteditor.ContentAssistAction; import org.eclipse.ui.texteditor.DefaultRangeIndicator; -import org.eclipse.ui.texteditor.IAbstractTextEditorHelpContextIds; +import org.eclipse.ui.texteditor.ExtendedTextEditor; import org.eclipse.ui.texteditor.IDocumentProvider; import org.eclipse.ui.texteditor.IEditorStatusLine; import org.eclipse.ui.texteditor.ITextEditorActionConstants; import org.eclipse.ui.texteditor.ITextEditorActionDefinitionIds; import org.eclipse.ui.texteditor.MarkerAnnotation; import org.eclipse.ui.texteditor.ResourceAction; -import org.eclipse.ui.texteditor.SourceViewerDecorationSupport; -import org.eclipse.ui.texteditor.StatusTextEditor; import org.eclipse.ui.texteditor.TextEditorAction; import org.eclipse.ui.texteditor.TextOperationAction; import org.eclipse.ui.views.contentoutline.IContentOutlinePage; @@ -150,7 +144,8 @@ import org.eclipse.ui.views.tasklist.TaskList; /** * PHP specific text editor. */ -public abstract class PHPEditor extends StatusTextEditor implements IViewPartInputProvider { // extends TextEditor { +public abstract class PHPEditor extends ExtendedTextEditor implements IViewPartInputProvider { +//extends StatusTextEditor implements IViewPartInputProvider { // extends TextEditor { /** * "Smart" runnable for updating the outline page's selection. */ @@ -960,38 +955,38 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp } }; - static protected class AnnotationAccess implements IAnnotationAccess { - /* - * @see org.eclipse.jface.text.source.IAnnotationAccess#getType(org.eclipse.jface.text.source.Annotation) - */ - public Object getType(Annotation annotation) { - if (annotation instanceof IJavaAnnotation) { - IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation; - if (javaAnnotation.isRelevant()) - return javaAnnotation.getAnnotationType(); - } - return null; - } - - /* - * @see org.eclipse.jface.text.source.IAnnotationAccess#isMultiLine(org.eclipse.jface.text.source.Annotation) - */ - public boolean isMultiLine(Annotation annotation) { - return true; - } - - /* - * @see org.eclipse.jface.text.source.IAnnotationAccess#isTemporary(org.eclipse.jface.text.source.Annotation) - */ - public boolean isTemporary(Annotation annotation) { - if (annotation instanceof IJavaAnnotation) { - IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation; - if (javaAnnotation.isRelevant()) - return javaAnnotation.isTemporary(); - } - return false; - } - }; +// static protected class AnnotationAccess implements IAnnotationAccess { +// /* +// * @see org.eclipse.jface.text.source.IAnnotationAccess#getType(org.eclipse.jface.text.source.Annotation) +// */ +// public Object getType(Annotation annotation) { +// if (annotation instanceof IJavaAnnotation) { +// IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation; +// // if (javaAnnotation.isRelevant()) +// // return javaAnnotation.getAnnotationType(); +// } +// return null; +// } +// +// /* +// * @see org.eclipse.jface.text.source.IAnnotationAccess#isMultiLine(org.eclipse.jface.text.source.Annotation) +// */ +// public boolean isMultiLine(Annotation annotation) { +// return true; +// } +// +// /* +// * @see org.eclipse.jface.text.source.IAnnotationAccess#isTemporary(org.eclipse.jface.text.source.Annotation) +// */ +// public boolean isTemporary(Annotation annotation) { +// if (annotation instanceof IJavaAnnotation) { +// IJavaAnnotation javaAnnotation = (IJavaAnnotation) annotation; +// if (javaAnnotation.isRelevant()) +// return javaAnnotation.isTemporary(); +// } +// return false; +// } +// }; private class PropertyChangeListener implements org.eclipse.core.runtime.Preferences.IPropertyChangeListener { /* @@ -1001,10 +996,130 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp handlePreferencePropertyChanged(event); } }; + + /** + * Finds and marks occurrence annotations. + * + * @since 3.0 + */ + class OccurrencesFinderJob extends Job implements IDocumentListener { + + private IDocument fDocument; + private boolean fCancelled= false; + private IProgressMonitor fProgressMonitor; + private Position[] fPositions; + + public OccurrencesFinderJob(IDocument document, Position[] positions) { + super("Occurrences Marker"); //$NON-NLS-1$ + fDocument= document; + fPositions= positions; + fDocument.addDocumentListener(this); + } + + private boolean isCancelled() { + return fCancelled || fProgressMonitor.isCanceled(); + } + + /* + * @see Job#run(org.eclipse.core.runtime.IProgressMonitor) + */ + public IStatus run(IProgressMonitor progressMonitor) { + + fProgressMonitor= progressMonitor; + + try { + + if (isCancelled()) + return Status.CANCEL_STATUS; + + ITextViewer textViewer= getViewer(); + if (textViewer == null) + return Status.CANCEL_STATUS; + + IDocument document= textViewer.getDocument(); + if (document == null) + return Status.CANCEL_STATUS; + + IDocumentProvider documentProvider= getDocumentProvider(); + if (documentProvider == null) + return Status.CANCEL_STATUS; + + IAnnotationModel annotationModel= documentProvider.getAnnotationModel(getEditorInput()); + if (annotationModel == null) + return Status.CANCEL_STATUS; + + // Add occurrence annotations + int length= fPositions.length; + Map annotationMap= new HashMap(length); + for (int i= 0; i < length; i++) { + + if (isCancelled()) + return Status.CANCEL_STATUS; + + String message; + Position position= fPositions[i]; + + // Create & add annotation + try { + message= document.get(position.offset, position.length); + } catch (BadLocationException ex) { + // Skip this match + continue; + } + annotationMap.put( + new Annotation("net.sourceforge.phpdt.ui.occurrences", false, message), //$NON-NLS-1$ + position); + } + + if (isCancelled()) + return Status.CANCEL_STATUS; + + synchronized (annotationModel) { + if (annotationModel instanceof IAnnotationModelExtension) { + ((IAnnotationModelExtension)annotationModel).replaceAnnotations(fOccurrenceAnnotations, annotationMap); + } else { + removeOccurrenceAnnotations(); + Iterator iter= annotationMap.entrySet().iterator(); + while (iter.hasNext()) { + Map.Entry mapEntry= (Map.Entry)iter.next(); + annotationModel.addAnnotation((Annotation)mapEntry.getKey(), (Position)mapEntry.getValue()); + } + } + fOccurrenceAnnotations= (Annotation[])annotationMap.keySet().toArray(new Annotation[annotationMap.keySet().size()]); + } + } finally { + fDocument.removeDocumentListener(this); + } + return Status.OK_STATUS; + } + + /* + * @see org.eclipse.jface.text.IDocumentListener#documentAboutToBeChanged(org.eclipse.jface.text.DocumentEvent) + */ + public void documentAboutToBeChanged(DocumentEvent event) { + fCancelled= true; + } + + /* + * @see org.eclipse.jface.text.IDocumentListener#documentChanged(org.eclipse.jface.text.DocumentEvent) + */ + public void documentChanged(DocumentEvent event) { + } + } + + + /** + * Holds the current occurrence annotations. + * @since 3.0 + */ + private Annotation[] fOccurrenceAnnotations= null; + + private Job fOccurrencesFinderJob; + /** Preference key for showing the line number ruler */ - private final static String LINE_NUMBER_RULER = PreferenceConstants.EDITOR_LINE_NUMBER_RULER; +// private final static String LINE_NUMBER_RULER = PreferenceConstants.EDITOR_LINE_NUMBER_RULER; /** Preference key for the foreground color of the line numbers */ - private final static String LINE_NUMBER_COLOR = PreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR; + // private final static String LINE_NUMBER_COLOR = PreferenceConstants.EDITOR_LINE_NUMBER_RULER_COLOR; /** Preference key for the link color */ private final static String LINK_COLOR = PreferenceConstants.EDITOR_LINK_COLOR; /** Preference key for compiler task tags */ @@ -1033,7 +1148,7 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp /** The line number ruler column */ - private LineNumberRulerColumn fLineNumberRulerColumn; +// private LineNumberRulerColumn fLineNumberRulerColumn; /** This editor's encoding support */ private DefaultEncodingSupport fEncodingSupport; /** The mouse listener */ @@ -1047,13 +1162,13 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp /** The information presenter. */ private InformationPresenter fInformationPresenter; /** The annotation access */ - protected IAnnotationAccess fAnnotationAccess = new AnnotationAccess(); +// protected IAnnotationAccess fAnnotationAccess = new AnnotationAccess(); /** The overview ruler */ protected OverviewRuler isOverviewRulerVisible; /** The source viewer decoration support */ - protected SourceViewerDecorationSupport fSourceViewerDecorationSupport; + //protected SourceViewerDecorationSupport fSourceViewerDecorationSupport; /** The overview ruler */ - protected OverviewRuler fOverviewRuler; + //protected OverviewRuler fOverviewRuler; /** The preference property change listener for java core. */ private org.eclipse.core.runtime.Preferences.IPropertyChangeListener fPropertyChangeListener = new PropertyChangeListener(); @@ -1166,7 +1281,7 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp public void createPartControl(Composite parent) { super.createPartControl(parent); - fSourceViewerDecorationSupport.install(getPreferenceStore()); + //fSourceViewerDecorationSupport.install(getPreferenceStore()); Preferences preferences = PHPeclipsePlugin.getDefault().getPluginPreferences(); preferences.addPropertyChangeListener(fPropertyChangeListener); @@ -1220,12 +1335,7 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp protected void createActions() { super.createActions(); - ResourceAction resAction = new AddTaskAction(PHPEditorMessages.getResourceBundle(), "AddTask.", this); //$NON-NLS-1$ - resAction.setHelpContextId(IAbstractTextEditorHelpContextIds.ADD_TASK_ACTION); - resAction.setActionDefinitionId(ITextEditorActionDefinitionIds.ADD_TASK); - setAction(ITextEditorActionConstants.ADD_TASK, resAction); - - resAction = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "ShowJavaDoc.", this, ISourceViewer.INFORMATION, true); //$NON-NLS-1$ + ResourceAction resAction = new TextOperationAction(PHPEditorMessages.getResourceBundle(), "ShowJavaDoc.", this, ISourceViewer.INFORMATION, true); //$NON-NLS-1$ resAction = new InformationDispatchAction(PHPEditorMessages.getResourceBundle(), "ShowJavaDoc.", (TextOperationAction) resAction); //$NON-NLS-1$ resAction.setActionDefinitionId(PHPEditorActionDefinitionIds.SHOW_JAVADOC); setAction("ShowJavaDoc", resAction); //$NON-NLS-1$ @@ -1278,15 +1388,9 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp // rg, // new LocalHistoryActionGroup(this, ITextEditorActionConstants.GROUP_EDIT)}); - // if (fValidationThread == null) { - // fValidationThread = - // new PHPSyntaxParserThread(this, getSourceViewer()); - // //Thread defaults - // - // fValidationThread.start(); - // } - // - // fValidationThread.setText(getSourceViewer().getTextWidget().getText()); + // add annotation actions + action= new JavaSelectMarkerRulerAction2(PHPEditorMessages.getResourceBundle(), "Editor.RulerAnnotationSelection.", this); //$NON-NLS-1$ + setAction("AnnotationAction", action); //$NON-NLS-1$ } /** The PHPEditor implementation of this @@ -1315,10 +1419,10 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp fPropertyChangeListener = null; } - if (fSourceViewerDecorationSupport != null) { - fSourceViewerDecorationSupport.dispose(); - fSourceViewerDecorationSupport = null; - } +// if (fSourceViewerDecorationSupport != null) { +// fSourceViewerDecorationSupport.dispose(); +// fSourceViewerDecorationSupport = null; +// } if (fBracketMatcher != null) { fBracketMatcher.dispose(); @@ -1805,28 +1909,28 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp } return; } - - if (OVERVIEW_RULER.equals(property)) { - if (isOverviewRulerVisible()) - showOverviewRuler(); - else - hideOverviewRuler(); - return; - } - - if (LINE_NUMBER_RULER.equals(property)) { - if (isLineNumberRulerVisible()) - showLineNumberRuler(); - else - hideLineNumberRuler(); - return; - } - - if (fLineNumberRulerColumn != null - && (LINE_NUMBER_COLOR.equals(property) || PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property) || PREFERENCE_COLOR_BACKGROUND.equals(property))) { - - initializeLineNumberRulerColumn(fLineNumberRulerColumn); - } + +// if (OVERVIEW_RULER.equals(property)) { +// if (isOverviewRulerVisible()) +// showOverviewRuler(); +// else +// hideOverviewRuler(); +// return; +// } + +// if (LINE_NUMBER_RULER.equals(property)) { +// if (isLineNumberRulerVisible()) +// showLineNumberRuler(); +// else +// hideLineNumberRuler(); +// return; +// } + +// if (fLineNumberRulerColumn != null +// && (LINE_NUMBER_COLOR.equals(property) || PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT.equals(property) || PREFERENCE_COLOR_BACKGROUND.equals(property))) { +// +// initializeLineNumberRulerColumn(fLineNumberRulerColumn); +// } if (isJavaEditorHoverProperty(property)) updateHoverBehavior(); @@ -1902,13 +2006,13 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp /** * Shows the line number ruler column. */ - private void showLineNumberRuler() { - IVerticalRuler v = getVerticalRuler(); - if (v instanceof CompositeRuler) { - CompositeRuler c = (CompositeRuler) v; - c.addDecorator(1, createLineNumberRulerColumn()); - } - } +// private void showLineNumberRuler() { +// IVerticalRuler v = getVerticalRuler(); +// if (v instanceof CompositeRuler) { +// CompositeRuler c = (CompositeRuler) v; +// c.addDecorator(1, createLineNumberRulerColumn()); +// } +// } private boolean isJavaEditorHoverProperty(String property) { return PreferenceConstants.EDITOR_TEXT_HOVER_MODIFIERS.equals(property); } @@ -1963,23 +2067,23 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp * visible according to the preference store settings. * @return true if the line numbers should be visible */ - private boolean isLineNumberRulerVisible() { - IPreferenceStore store = getPreferenceStore(); - return store.getBoolean(LINE_NUMBER_RULER); - } +// protected boolean isLineNumberRulerVisible() { +// IPreferenceStore store = getPreferenceStore(); +// return store.getBoolean(LINE_NUMBER_RULER); +// } /** * Hides the line number ruler column. */ - private void hideLineNumberRuler() { - IVerticalRuler v = getVerticalRuler(); - if (v instanceof CompositeRuler) { - CompositeRuler c = (CompositeRuler) v; - try { - c.removeDecorator(1); - } catch (Throwable e) { - } - } - } +// private void hideLineNumberRuler() { +// IVerticalRuler v = getVerticalRuler(); +// if (v instanceof CompositeRuler) { +// CompositeRuler c = (CompositeRuler) v; +// try { +// c.removeDecorator(1); +// } catch (Throwable e) { +// } +// } +// } /* * @see AbstractTextEditor#handleCursorPositionChanged() @@ -1994,56 +2098,56 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp * Initializes the given line number ruler column from the preference store. * @param rulerColumn the ruler column to be initialized */ - protected void initializeLineNumberRulerColumn(LineNumberRulerColumn rulerColumn) { - JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools(); - IColorManager manager = textTools.getColorManager(); - - IPreferenceStore store = getPreferenceStore(); - if (store != null) { - - RGB rgb = null; - // foreground color - if (store.contains(LINE_NUMBER_COLOR)) { - if (store.isDefault(LINE_NUMBER_COLOR)) - rgb = PreferenceConverter.getDefaultColor(store, LINE_NUMBER_COLOR); - else - rgb = PreferenceConverter.getColor(store, LINE_NUMBER_COLOR); - } - rulerColumn.setForeground(manager.getColor(rgb)); - - rgb = null; - // background color - if (!store.getBoolean(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) { - if (store.contains(PREFERENCE_COLOR_BACKGROUND)) { - if (store.isDefault(PREFERENCE_COLOR_BACKGROUND)) - rgb = PreferenceConverter.getDefaultColor(store, PREFERENCE_COLOR_BACKGROUND); - else - rgb = PreferenceConverter.getColor(store, PREFERENCE_COLOR_BACKGROUND); - } - } - rulerColumn.setBackground(manager.getColor(rgb)); - } - } +// protected void initializeLineNumberRulerColumn(LineNumberRulerColumn rulerColumn) { +// JavaTextTools textTools = PHPeclipsePlugin.getDefault().getJavaTextTools(); +// IColorManager manager = textTools.getColorManager(); +// +// IPreferenceStore store = getPreferenceStore(); +// if (store != null) { +// +// RGB rgb = null; +// // foreground color +// if (store.contains(LINE_NUMBER_COLOR)) { +// if (store.isDefault(LINE_NUMBER_COLOR)) +// rgb = PreferenceConverter.getDefaultColor(store, LINE_NUMBER_COLOR); +// else +// rgb = PreferenceConverter.getColor(store, LINE_NUMBER_COLOR); +// } +// rulerColumn.setForeground(manager.getColor(rgb)); +// +// rgb = null; +// // background color +// if (!store.getBoolean(PREFERENCE_COLOR_BACKGROUND_SYSTEM_DEFAULT)) { +// if (store.contains(PREFERENCE_COLOR_BACKGROUND)) { +// if (store.isDefault(PREFERENCE_COLOR_BACKGROUND)) +// rgb = PreferenceConverter.getDefaultColor(store, PREFERENCE_COLOR_BACKGROUND); +// else +// rgb = PreferenceConverter.getColor(store, PREFERENCE_COLOR_BACKGROUND); +// } +// } +// rulerColumn.setBackground(manager.getColor(rgb)); +// } +// } /** * Creates a new line number ruler column that is appropriately initialized. */ - protected IVerticalRulerColumn createLineNumberRulerColumn() { - fLineNumberRulerColumn = new LineNumberRulerColumn(); - initializeLineNumberRulerColumn(fLineNumberRulerColumn); - return fLineNumberRulerColumn; - } +// protected IVerticalRulerColumn createLineNumberRulerColumn() { +// fLineNumberRulerColumn = new LineNumberRulerColumn(); +// initializeLineNumberRulerColumn(fLineNumberRulerColumn); +// return fLineNumberRulerColumn; +// } /* * @see AbstractTextEditor#createVerticalRuler() */ - protected IVerticalRuler createVerticalRuler() { - CompositeRuler ruler = new CompositeRuler(); - ruler.addDecorator(0, new AnnotationRulerColumn(VERTICAL_RULER_WIDTH)); - if (isLineNumberRulerVisible()) - ruler.addDecorator(1, createLineNumberRulerColumn()); - return ruler; - } +// protected IVerticalRuler createVerticalRuler() { +// CompositeRuler ruler = new CompositeRuler(); +// ruler.addDecorator(0, new AnnotationRulerColumn(VERTICAL_RULER_WIDTH)); +// if (isLineNumberRulerVisible()) +// ruler.addDecorator(1, createLineNumberRulerColumn()); +// return ruler; +// } private static IRegion getSignedSelection(ITextViewer viewer) { @@ -2154,54 +2258,54 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp } } - protected void configureSourceViewerDecorationSupport() { - - fSourceViewerDecorationSupport.setCharacterPairMatcher(fBracketMatcher); - - fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys( - AnnotationType.UNKNOWN, - UNKNOWN_INDICATION_COLOR, - UNKNOWN_INDICATION, - UNKNOWN_INDICATION_IN_OVERVIEW_RULER, - 0); - fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys( - AnnotationType.BOOKMARK, - BOOKMARK_INDICATION_COLOR, - BOOKMARK_INDICATION, - BOOKMARK_INDICATION_IN_OVERVIEW_RULER, - 1); - fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys( - AnnotationType.TASK, - TASK_INDICATION_COLOR, - TASK_INDICATION, - TASK_INDICATION_IN_OVERVIEW_RULER, - 2); - fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys( - AnnotationType.SEARCH, - SEARCH_RESULT_INDICATION_COLOR, - SEARCH_RESULT_INDICATION, - SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER, - 3); - fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys( - AnnotationType.WARNING, - WARNING_INDICATION_COLOR, - WARNING_INDICATION, - WARNING_INDICATION_IN_OVERVIEW_RULER, - 4); - fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys( - AnnotationType.ERROR, - ERROR_INDICATION_COLOR, - ERROR_INDICATION, - ERROR_INDICATION_IN_OVERVIEW_RULER, - 5); - - fSourceViewerDecorationSupport.setCursorLinePainterPreferenceKeys(CURRENT_LINE, CURRENT_LINE_COLOR); - fSourceViewerDecorationSupport.setMarginPainterPreferenceKeys(PRINT_MARGIN, PRINT_MARGIN_COLOR, PRINT_MARGIN_COLUMN); - fSourceViewerDecorationSupport.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS, MATCHING_BRACKETS_COLOR); - - fSourceViewerDecorationSupport.setSymbolicFontName(getFontPropertyPreferenceKey()); - - } +// protected void configureSourceViewerDecorationSupport() { +// +// fSourceViewerDecorationSupport.setCharacterPairMatcher(fBracketMatcher); +// +// fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys( +// AnnotationType.UNKNOWN, +// UNKNOWN_INDICATION_COLOR, +// UNKNOWN_INDICATION, +// UNKNOWN_INDICATION_IN_OVERVIEW_RULER, +// 0); +// fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys( +// AnnotationType.BOOKMARK, +// BOOKMARK_INDICATION_COLOR, +// BOOKMARK_INDICATION, +// BOOKMARK_INDICATION_IN_OVERVIEW_RULER, +// 1); +// fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys( +// AnnotationType.TASK, +// TASK_INDICATION_COLOR, +// TASK_INDICATION, +// TASK_INDICATION_IN_OVERVIEW_RULER, +// 2); +// fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys( +// AnnotationType.SEARCH, +// SEARCH_RESULT_INDICATION_COLOR, +// SEARCH_RESULT_INDICATION, +// SEARCH_RESULT_INDICATION_IN_OVERVIEW_RULER, +// 3); +// fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys( +// AnnotationType.WARNING, +// WARNING_INDICATION_COLOR, +// WARNING_INDICATION, +// WARNING_INDICATION_IN_OVERVIEW_RULER, +// 4); +// fSourceViewerDecorationSupport.setAnnotationPainterPreferenceKeys( +// AnnotationType.ERROR, +// ERROR_INDICATION_COLOR, +// ERROR_INDICATION, +// ERROR_INDICATION_IN_OVERVIEW_RULER, +// 5); +// +// fSourceViewerDecorationSupport.setCursorLinePainterPreferenceKeys(CURRENT_LINE, CURRENT_LINE_COLOR); +// fSourceViewerDecorationSupport.setMarginPainterPreferenceKeys(PRINT_MARGIN, PRINT_MARGIN_COLOR, PRINT_MARGIN_COLUMN); +// fSourceViewerDecorationSupport.setMatchingCharacterPainterPreferenceKeys(MATCHING_BRACKETS, MATCHING_BRACKETS_COLOR); +// +// fSourceViewerDecorationSupport.setSymbolicFontName(getFontPropertyPreferenceKey()); +// +// } /** * Jumps to the matching bracket. */ @@ -2363,64 +2467,89 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp // // JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR); // return viewer; // } - protected final ISourceViewer createSourceViewer(Composite parent, IVerticalRuler verticalRuler, int styles) { - - ISharedTextColors sharedColors = PHPeclipsePlugin.getDefault().getJavaTextTools().getColorManager(); - - fOverviewRuler = new OverviewRuler(fAnnotationAccess, VERTICAL_RULER_WIDTH, sharedColors); - fOverviewRuler.addHeaderAnnotationType(AnnotationType.WARNING); - fOverviewRuler.addHeaderAnnotationType(AnnotationType.ERROR); - - ISourceViewer viewer = createJavaSourceViewer(parent, verticalRuler, fOverviewRuler, isOverviewRulerVisible(), styles); - - StyledText text = viewer.getTextWidget(); - text.addBidiSegmentListener(new BidiSegmentListener() { - public void lineGetSegments(BidiSegmentEvent event) { - event.segments = getBidiLineSegments(event.lineOffset, event.lineText); - } - }); - - // JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR); - - fSourceViewerDecorationSupport = new SourceViewerDecorationSupport(viewer, fOverviewRuler, fAnnotationAccess, sharedColors); - configureSourceViewerDecorationSupport(); - - return viewer; - } - - protected void showOverviewRuler() { - if (fOverviewRuler != null) { - if (getSourceViewer() instanceof ISourceViewerExtension) { - ((ISourceViewerExtension) getSourceViewer()).showAnnotationsOverview(true); - fSourceViewerDecorationSupport.updateOverviewDecorations(); - } - } + + public final ISourceViewer getViewer() { + return getSourceViewer(); } + + protected final ISourceViewer createSourceViewer(Composite parent, IVerticalRuler verticalRuler, int styles) { + ISourceViewer viewer= createJavaSourceViewer(parent, verticalRuler, getOverviewRuler(), isOverviewRulerVisible(), styles); + + StyledText text= viewer.getTextWidget(); + text.addBidiSegmentListener(new BidiSegmentListener() { + public void lineGetSegments(BidiSegmentEvent event) { + event.segments= getBidiLineSegments(event.lineOffset, event.lineText); + } + }); + +// JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR); - protected void hideOverviewRuler() { - if (getSourceViewer() instanceof ISourceViewerExtension) { - fSourceViewerDecorationSupport.hideAnnotationOverview(); - ((ISourceViewerExtension) getSourceViewer()).showAnnotationsOverview(false); - } + // ensure source viewer decoration support has been created and configured + getSourceViewerDecorationSupport(viewer); + + return viewer; + +// ISharedTextColors sharedColors = PHPeclipsePlugin.getDefault().getJavaTextTools().getColorManager(); +// +// fOverviewRuler = new OverviewRuler(fAnnotationAccess, VERTICAL_RULER_WIDTH, sharedColors); +// fOverviewRuler.addHeaderAnnotationType(AnnotationType.WARNING); +// fOverviewRuler.addHeaderAnnotationType(AnnotationType.ERROR); +// +// ISourceViewer viewer = createJavaSourceViewer(parent, verticalRuler, fOverviewRuler, isOverviewRulerVisible(), styles); +// +// StyledText text = viewer.getTextWidget(); +// text.addBidiSegmentListener(new BidiSegmentListener() { +// public void lineGetSegments(BidiSegmentEvent event) { +// event.segments = getBidiLineSegments(event.lineOffset, event.lineText); +// } +// }); +// +// // JavaUIHelp.setHelp(this, text, IJavaHelpContextIds.JAVA_EDITOR); +// +// fSourceViewerDecorationSupport = new SourceViewerDecorationSupport(viewer, fOverviewRuler, fAnnotationAccess, sharedColors); +// configureSourceViewerDecorationSupport(); +// +// return viewer; } - protected boolean isOverviewRulerVisible() { - IPreferenceStore store = getPreferenceStore(); - return store.getBoolean(OVERVIEW_RULER); - } +// protected void showOverviewRuler() { +// if (fOverviewRuler != null) { +// if (getSourceViewer() instanceof ISourceViewerExtension) { +// ((ISourceViewerExtension) getSourceViewer()).showAnnotationsOverview(true); +// fSourceViewerDecorationSupport.updateOverviewDecorations(); +// } +// } +// } +// +// protected void hideOverviewRuler() { +// if (getSourceViewer() instanceof ISourceViewerExtension) { +// fSourceViewerDecorationSupport.hideAnnotationOverview(); +// ((ISourceViewerExtension) getSourceViewer()).showAnnotationsOverview(false); +// } +// } + +// protected boolean isOverviewRulerVisible() { +// IPreferenceStore store = getPreferenceStore(); +// return store.getBoolean(OVERVIEW_RULER); +// } /* * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int) */ - protected ISourceViewer createJavaSourceViewer( - Composite parent, - IVerticalRuler ruler, - IOverviewRuler overviewRuler, - boolean isOverviewRulerVisible, - int styles) { - return new SourceViewer(parent, ruler, overviewRuler, isOverviewRulerVisible(), styles); - // return super.createSourceViewer(parent, ruler, styles); - } - +// protected ISourceViewer createJavaSourceViewer( +// Composite parent, +// IVerticalRuler ruler, +// IOverviewRuler overviewRuler, +// boolean isOverviewRulerVisible, +// int styles) { +// return new SourceViewer(parent, ruler, overviewRuler, isOverviewRulerVisible(), styles); +// } + + /* + * @see AbstractTextEditor#createSourceViewer(Composite, IVerticalRuler, int) + */ + protected ISourceViewer createJavaSourceViewer(Composite parent, IVerticalRuler verticalRuler, IOverviewRuler overviewRuler, boolean isOverviewRulerVisible, int styles) { + return new JavaSourceViewer(parent, verticalRuler, getOverviewRuler(), isOverviewRulerVisible(), styles); + } /* * @see AbstractTextEditor#affectsTextPresentation(PropertyChangeEvent) */ @@ -2468,7 +2597,7 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp } selectAndReveal(errorPosition.getOffset(), errorPosition.getLength()); - setStatusLineErrorMessage(nextError.getMessage()); +// setStatusLineErrorMessage(nextError.getMessage()); } else { @@ -2524,4 +2653,23 @@ public abstract class PHPEditor extends StatusTextEditor implements IViewPartInp return nextError; } + void removeOccurrenceAnnotations() { + IDocumentProvider documentProvider= getDocumentProvider(); + if (documentProvider == null) + return; + + IAnnotationModel annotationModel= documentProvider.getAnnotationModel(getEditorInput()); + if (annotationModel == null || fOccurrenceAnnotations == null) + return; + + synchronized (annotationModel) { + if (annotationModel instanceof IAnnotationModelExtension) { + ((IAnnotationModelExtension)annotationModel).replaceAnnotations(fOccurrenceAnnotations, null); + } else { + for (int i= 0, length= fOccurrenceAnnotations.length; i < length; i++) + annotationModel.removeAnnotation(fOccurrenceAnnotations[i]); + } + fOccurrenceAnnotations= null; + } +} } diff --git a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java index b7f6156..c870909 100644 --- a/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java +++ b/net.sourceforge.phpeclipse/src/net/sourceforge/phpeclipse/phpeditor/PHPSourceViewerConfiguration.java @@ -1,24 +1,22 @@ /********************************************************************** -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 - Klaus Hartlage - www.eclipseproject.de -**********************************************************************/ + 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 + Klaus Hartlage - www.eclipseproject.de + **********************************************************************/ package net.sourceforge.phpeclipse.phpeditor; - import java.util.Vector; - import net.sourceforge.phpdt.internal.ui.text.ContentAssistPreference; import net.sourceforge.phpdt.internal.ui.text.HTMLTextPresenter; +import net.sourceforge.phpdt.internal.ui.text.JavaAnnotationHover; import net.sourceforge.phpdt.internal.ui.text.JavaElementProvider; import net.sourceforge.phpdt.internal.ui.text.JavaOutlineInformationControl; import net.sourceforge.phpdt.internal.ui.text.JavaReconciler; -import net.sourceforge.phpdt.internal.ui.text.PHPAnnotationHover; import net.sourceforge.phpdt.internal.ui.text.java.JavaFormattingStrategy; import net.sourceforge.phpdt.internal.ui.text.java.JavaReconcilingStrategy; import net.sourceforge.phpdt.internal.ui.text.java.hover.JavaEditorTextHoverDescriptor; @@ -35,7 +33,6 @@ import net.sourceforge.phpeclipse.phpeditor.php.PHPAutoIndentStrategy; import net.sourceforge.phpeclipse.phpeditor.php.PHPCompletionProcessor; import net.sourceforge.phpeclipse.phpeditor.php.PHPDoubleClickSelector; import net.sourceforge.phpeclipse.phpeditor.util.PHPColorProvider; - import org.eclipse.core.resources.IFile; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.jface.preference.IPreferenceStore; @@ -73,537 +70,566 @@ import org.eclipse.swt.SWT; import org.eclipse.swt.widgets.Shell; import org.eclipse.ui.IEditorInput; import org.eclipse.ui.IFileEditorInput; - /** - * Configuration for an SourceViewer which shows PHP code. + * Configuration for an SourceViewer which shows PHP code. */ public class PHPSourceViewerConfiguration extends SourceViewerConfiguration { - - /** - * Preference key used to look up display tab width. - * - * @since 2.0 - */ - public final static String PREFERENCE_TAB_WIDTH = PreferenceConstants.EDITOR_TAB_WIDTH; - /** - * Preference key for inserting spaces rather than tabs. - * - * @since 2.0 - */ - public final static String SPACES_FOR_TABS = PreferenceConstants.EDITOR_SPACES_FOR_TABS; - - // public static final String HTML_DEFAULT = IPHPPartitionScannerConstants.HTML; - //IDocument.DEFAULT_CONTENT_TYPE; - - private JavaTextTools fJavaTextTools; - private PHPEditor fEditor; - - private ContentFormatter fFormatter; - private HTMLFormattingStrategy fFormattingStrategy; - /** - * Single token scanner. - */ - static class SingleTokenScanner extends BufferedRuleBasedScanner { - public SingleTokenScanner(TextAttribute attribute) { - setDefaultReturnToken(new Token(attribute)); - } - }; - - /** - * Default constructor. - */ - public PHPSourceViewerConfiguration(JavaTextTools textTools, PHPEditor editor) { - fJavaTextTools = textTools; - fEditor = editor; - } - - /* - * @see SourceViewerConfiguration#getContentFormatter(ISourceViewer) - */ - public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) { - // if (fFormatter == null) { - // fFormatter = new ContentFormatter(); - // fFormattingStrategy = new HTMLFormattingStrategy(this, sourceViewer); - // fFormatter.setFormattingStrategy(fFormattingStrategy, HTML_DEFAULT); - // fFormatter.enablePartitionAwareFormatting(false); - // fFormatter.setPartitionManagingPositionCategories(getConfiguredContentTypes(null)); - // } - // return fFormatter; - - if (fFormatter == null) { - //ContentFormatter - fFormatter = new ContentFormatter(); - IFormattingStrategy strategy = new JavaFormattingStrategy(sourceViewer); - - fFormatter.setFormattingStrategy(strategy, IDocument.DEFAULT_CONTENT_TYPE); - fFormatter.enablePartitionAwareFormatting(false); - fFormatter.setPartitionManagingPositionCategories(getPartitionManagingPositionCategories()); - } - return fFormatter; - } - - /** - * Returns the names of the document position categories used by the document - * partitioners created by this object to manage their partition information. - * If the partitioners don't use document position categories, the returned - * result is null. - * - * @return the partition managing position categories or null - * if there is none - */ - public String[] getPartitionManagingPositionCategories() { - return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY }; - } - // /** - // * Returns the names of the document position categories used by the document - // * partitioners created by this object to manage their partition information. - // * If the partitioners don't use document position categories, the returned - // * result is null. - // * - // * @return the partition managing position categories or null - // * if there is none - // */ - // private String[] getPartitionManagingPositionCategories() { - // return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY }; - // } - - public PHPEditor getEditor() { - return fEditor; - } - - /** - * Returns the preference store used by this configuration to initialize - * the individual bits and pieces. - * - * @return the preference store used to initialize this configuration - * - * @since 2.0 - */ - protected IPreferenceStore getPreferenceStore() { - return PHPeclipsePlugin.getDefault().getPreferenceStore(); - } - - // /* (non-Javadoc) - // * Method declared on SourceViewerConfiguration - // */ - // public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) { - // return new PHPAnnotationHover(); - // } - /* - * @see SourceViewerConfiguration#getAnnotationHover(ISourceViewer) - */ - public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) { - return new PHPAnnotationHover(); - } - - /* (non-Javadoc) - * Method declared on SourceViewerConfiguration - */ - public IAutoIndentStrategy getAutoIndentStrategy(ISourceViewer sourceViewer, String contentType) { - return (IPHPPartitionScannerConstants.PHP.equals(contentType) ? new PHPAutoIndentStrategy() : new DefaultAutoIndentStrategy()); - } - - /** - * Returns the PHP source code scanner for this configuration. - * - * @return the PHP source code scanner - */ - protected RuleBasedScanner getCodeScanner() { - return fJavaTextTools.getCodeScanner(); - } - - /** - * Returns the HTML source code scanner for this configuration. - * - * @return the HTML source code scanner - */ - protected RuleBasedScanner getHTMLScanner() { - return fJavaTextTools.getHTMLScanner(); - } - - /** - * Returns the Smarty source code scanner for this configuration. - * - * @return the Smarty source code scanner - */ - protected RuleBasedScanner getSmartyScanner() { - return fJavaTextTools.getSmartyScanner(); - } - - /* - * @see SourceViewerConfiguration#getReconciler(ISourceViewer) - */ - public IReconciler getReconciler(ISourceViewer sourceViewer) { - - if (getEditor() != null && getEditor().isEditable()) { - JavaReconciler reconciler = new JavaReconciler(getEditor(), new JavaReconcilingStrategy(getEditor()), false); - reconciler.setProgressMonitor(new NullProgressMonitor()); - reconciler.setDelay(500); - return reconciler; - } - - return null; - } - - /* - * @see SourceViewerConfiguration#getConfiguredTextHoverStateMasks(ISourceViewer, String) - * @since 2.1 - */ - public int[] getConfiguredTextHoverStateMasks(ISourceViewer sourceViewer, String contentType) { - JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin.getDefault().getJavaEditorTextHoverDescriptors(); - int stateMasks[] = new int[hoverDescs.length]; - int stateMasksLength = 0; - for (int i = 0; i < hoverDescs.length; i++) { - if (hoverDescs[i].isEnabled()) { - int j = 0; - int stateMask = hoverDescs[i].getStateMask(); - while (j < stateMasksLength) { - if (stateMasks[j] == stateMask) - break; - j++; - } - if (j == stateMasksLength) - stateMasks[stateMasksLength++] = stateMask; - } - } - if (stateMasksLength == hoverDescs.length) - return stateMasks; - - int[] shortenedStateMasks = new int[stateMasksLength]; - System.arraycopy(stateMasks, 0, shortenedStateMasks, 0, stateMasksLength); - return shortenedStateMasks; - } - - /* - * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String, int) - * @since 2.1 - */ - public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType, int stateMask) { - JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin.getDefault().getJavaEditorTextHoverDescriptors(); - int i = 0; - while (i < hoverDescs.length) { - if (hoverDescs[i].isEnabled() && hoverDescs[i].getStateMask() == stateMask) - return new JavaEditorTextHoverProxy(hoverDescs[i], getEditor()); - i++; - } - - if (fEditor != null) { - IEditorInput editorInput = fEditor.getEditorInput(); - if (editorInput instanceof IFileEditorInput) { - try { - IFile f = ((IFileEditorInput) editorInput).getFile(); - return new PHPTextHover(f.getProject()); - } catch (NullPointerException e) { - // this exception occurs, if getTextHover is called by preference pages ! - } - } - } - return new PHPTextHover(null); - } - - /* - * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String) - */ - public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) { - return getTextHover(sourceViewer, contentType, ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK); - } - - /** - * Returns the SmartyDoc source code scanner for this configuration. - * - * @return the SmartyDoc source code scanner - */ - protected RuleBasedScanner getSmartyDocScanner() { - return fJavaTextTools.getSmartyDocScanner(); - } - - /** - * Returns the PHPDoc source code scanner for this configuration. - * - * @return the PHPDoc source code scanner - */ - protected RuleBasedScanner getPHPDocScanner() { - return fJavaTextTools.getJavaDocScanner(); - } - - /* (non-Javadoc) - * Method declared on SourceViewerConfiguration - */ - public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { - return new String[] { - IPHPPartitionScannerConstants.HTML, - IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT, - IPHPPartitionScannerConstants.PHP, - IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT, - IPHPPartitionScannerConstants.CSS, - IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT, - IPHPPartitionScannerConstants.JAVASCRIPT, - IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT, - IPHPPartitionScannerConstants.SMARTY, - IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT, - IDocument.DEFAULT_CONTENT_TYPE }; - } - - /* (non-Javadoc) - * Method declared on SourceViewerConfiguration - */ - public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) { - - ContentAssistant assistant = new ContentAssistant(); - IContentAssistProcessor processor = new HTMLCompletionProcessor(); - assistant.setContentAssistProcessor(processor, IPHPPartitionScannerConstants.HTML); - assistant.setContentAssistProcessor(processor, IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT); - assistant.setContentAssistProcessor(processor, IDocument.DEFAULT_CONTENT_TYPE); - assistant.setContentAssistProcessor(processor, IPHPPartitionScannerConstants.CSS); - assistant.setContentAssistProcessor(processor, IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT); - assistant.setContentAssistProcessor(processor, IPHPPartitionScannerConstants.JAVASCRIPT); - assistant.setContentAssistProcessor(processor, IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT); - // TODO define special smarty partition content assist - assistant.setContentAssistProcessor(processor, IPHPPartitionScannerConstants.SMARTY); - assistant.setContentAssistProcessor(processor, IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT); - - assistant.setContentAssistProcessor(new PHPCompletionProcessor(), IPHPPartitionScannerConstants.PHP); - - assistant.setContentAssistProcessor(new PHPDocCompletionProcessor(), IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT); - - // assistant.enableAutoActivation(true); - // assistant.setAutoActivationDelay(500); - // assistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_OVERLAY); - // ContentAssistPreference.configure(assistant, getPreferenceStore()); - // assistant.setContextInformationPopupOrientation( - // ContentAssistant.CONTEXT_INFO_ABOVE); - // assistant.setContextInformationPopupBackground( - // PHPEditorEnvironment.getPHPColorProvider().getColor( - // new RGB(150, 150, 0))); - ContentAssistPreference.configure(assistant, getPreferenceStore()); - - assistant.setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_ABOVE); - assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer)); - - return assistant; - } - - /* (non-Javadoc) - * Method declared on SourceViewerConfiguration - */ - // public String getDefaultPrefix(ISourceViewer sourceViewer, String contentType) { - // return (PHPPartitionScanner.PHP.equals(contentType) ? "//" : null); //$NON-NLS-1$ - // // return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" : null); //$NON-NLS-1$ - // } - - /* - * @see SourceViewerConfiguration#getDefaultPrefix(ISourceViewer, String) - * @since 2.0 - */ - public String[] getDefaultPrefixes(ISourceViewer sourceViewer, String contentType) { - return new String[] { "//", "" }; //$NON-NLS-1$ //$NON-NLS-2$ - } - - /* (non-Javadoc) - * Method declared on SourceViewerConfiguration - */ - public ITextDoubleClickStrategy getDoubleClickStrategy(ISourceViewer sourceViewer, String contentType) { - return new PHPDoubleClickSelector(); - } - - /* - * @see SourceViewerConfiguration#getIndentPrefixes(ISourceViewer, String) - */ - public String[] getIndentPrefixes(ISourceViewer sourceViewer, String contentType) { - - Vector vector = new Vector(); - - // prefix[0] is either '\t' or ' ' x tabWidth, depending on useSpaces - - final IPreferenceStore preferences = PHPeclipsePlugin.getDefault().getPreferenceStore(); - int tabWidth = preferences.getInt(PHPCore.FORMATTER_TAB_SIZE); - boolean useSpaces = getPreferenceStore().getBoolean(SPACES_FOR_TABS); - - for (int i = 0; i <= tabWidth; i++) { - StringBuffer prefix = new StringBuffer(); - - if (useSpaces) { - for (int j = 0; j + i < tabWidth; j++) - prefix.append(' '); - - if (i != 0) - prefix.append('\t'); - } else { - for (int j = 0; j < i; j++) - prefix.append(' '); - - if (i != tabWidth) - prefix.append('\t'); - } - - vector.add(prefix.toString()); - } - - vector.add(""); //$NON-NLS-1$ - - return (String[]) vector.toArray(new String[vector.size()]); - } - /* (non-Javadoc) - * Method declared on SourceViewerConfiguration - */ - public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) { - // PHPColorProvider provider = PHPEditorEnvironment.getPHPColorProvider(); - // JavaColorManager provider = PHPEditorEnvironment.getPHPColorProvider(); - PresentationReconciler reconciler = new PresentationReconciler(); - - DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getHTMLScanner()); - reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); - reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); - - dr = new DefaultDamagerRepairer(getHTMLScanner()); - reconciler.setDamager(dr, IPHPPartitionScannerConstants.HTML); - reconciler.setRepairer(dr, IPHPPartitionScannerConstants.HTML); - dr = new DefaultDamagerRepairer(getHTMLScanner()); - reconciler.setDamager(dr, IPHPPartitionScannerConstants.CSS); - reconciler.setRepairer(dr, IPHPPartitionScannerConstants.CSS); - dr = new DefaultDamagerRepairer(getHTMLScanner()); - reconciler.setDamager(dr, IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT); - reconciler.setRepairer(dr, IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT); - dr = new DefaultDamagerRepairer(getHTMLScanner()); - reconciler.setDamager(dr, IPHPPartitionScannerConstants.JAVASCRIPT); - reconciler.setRepairer(dr, IPHPPartitionScannerConstants.JAVASCRIPT); - dr = new DefaultDamagerRepairer(getHTMLScanner()); - reconciler.setDamager(dr, IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT); - reconciler.setRepairer(dr, IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT); - - dr = new DefaultDamagerRepairer(getSmartyScanner()); - reconciler.setDamager(dr, IPHPPartitionScannerConstants.SMARTY); - reconciler.setRepairer(dr, IPHPPartitionScannerConstants.SMARTY); - - dr = new DefaultDamagerRepairer(getSmartyDocScanner()); - reconciler.setDamager(dr, IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT); - reconciler.setRepairer(dr, IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT); - - dr = - new DefaultDamagerRepairer( - new SingleTokenScanner(new TextAttribute(fJavaTextTools.getColorManager().getColor(PHPColorProvider.MULTI_LINE_COMMENT)))); - reconciler.setDamager(dr, IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT); - reconciler.setRepairer(dr, IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT); - - dr = new DefaultDamagerRepairer(getCodeScanner()); - reconciler.setDamager(dr, IPHPPartitionScannerConstants.PHP); - reconciler.setRepairer(dr, IPHPPartitionScannerConstants.PHP); - - dr = new DefaultDamagerRepairer(getPHPDocScanner()); - reconciler.setDamager(dr, IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT); - reconciler.setRepairer(dr, IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT); - - return reconciler; - } - - /* (non-Javadoc) - * Method declared on SourceViewerConfiguration - */ - public int getTabWidth(ISourceViewer sourceViewer) { - return getPreferenceStore().getInt(PREFERENCE_TAB_WIDTH); - } - - /* (non-Javadoc) - * Method declared on SourceViewerConfiguration - */ - // public ITextHover getTextHover(ISourceViewer sourceViewer, String contentType) { - // if (fEditor != null) { - // IEditorInput editorInput = fEditor.getEditorInput(); - // if (editorInput instanceof IFileEditorInput) { - // try { - // IFile f = ((IFileEditorInput) editorInput).getFile(); - // return new PHPTextHover(f.getProject()); - // } catch (NullPointerException e) { - // // this exception occurs, if getTextHover is called by preference pages ! - // } - // } - // } - // return new PHPTextHover(null); - // } - - /* - * @see SourceViewerConfiguration#getInformationControlCreator(ISourceViewer) - * @since 2.0 - */ - public IInformationControlCreator getInformationControlCreator(ISourceViewer sourceViewer) { - return new IInformationControlCreator() { - public IInformationControl createInformationControl(Shell parent) { - return new DefaultInformationControl(parent, SWT.NONE, new HTMLTextPresenter(true)); - // return new HoverBrowserControl(parent); - } - }; - } - - /* - * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer) - * @since 2.0 - */ - // public IInformationPresenter getInformationPresenter(ISourceViewer sourceViewer) { - // InformationPresenter presenter= new InformationPresenter(getInformationPresenterControlCreator(sourceViewer)); - // IInformationProvider provider= new JavaInformationProvider(getEditor()); - // presenter.setInformationProvider(provider, IDocument.DEFAULT_CONTENT_TYPE); - // presenter.setInformationProvider(provider, IJavaPartitions.JAVA_DOC); - // presenter.setSizeConstraints(60, 10, true, true); - // return presenter; - // } - - /** - * Returns the information presenter control creator. The creator is a factory creating the - * presenter controls for the given source viewer. This implementation always returns a creator - * for DefaultInformationControl instances. - * - * @param sourceViewer the source viewer to be configured by this configuration - * @return an information control creator - * @since 2.1 - */ - private IInformationControlCreator getInformationPresenterControlCreator(ISourceViewer sourceViewer) { - return new IInformationControlCreator() { - public IInformationControl createInformationControl(Shell parent) { - int shellStyle = SWT.RESIZE; - int style = SWT.V_SCROLL | SWT.H_SCROLL; - return new DefaultInformationControl(parent, shellStyle, style, new HTMLTextPresenter(false)); - // return new HoverBrowserControl(parent); - } - }; - } - /** - * Returns the outline presenter control creator. The creator is a factory creating outline - * presenter controls for the given source viewer. This implementation always returns a creator - * for JavaOutlineInformationControl instances. - * - * @param sourceViewer the source viewer to be configured by this configuration - * @return an information control creator - * @since 2.1 - */ - private IInformationControlCreator getOutlinePresenterControlCreator(ISourceViewer sourceViewer) { - return new IInformationControlCreator() { - public IInformationControl createInformationControl(Shell parent) { - int shellStyle = SWT.RESIZE; - int treeStyle = SWT.V_SCROLL | SWT.H_SCROLL; - return new JavaOutlineInformationControl(parent, shellStyle, treeStyle); - } - }; - } - /** - * Returns the outline presenter which will determine and shown - * information requested for the current cursor position. - * - * @param sourceViewer the source viewer to be configured by this configuration - * @param doCodeResolve a boolean which specifies whether code resolve should be used to compute the Java element - * @return an information presenter - * @since 2.1 - */ - public IInformationPresenter getOutlinePresenter(ISourceViewer sourceViewer, boolean doCodeResolve) { - InformationPresenter presenter = new InformationPresenter(getOutlinePresenterControlCreator(sourceViewer)); - presenter.setAnchor(InformationPresenter.ANCHOR_GLOBAL); - IInformationProvider provider = new JavaElementProvider(getEditor(), doCodeResolve); - presenter.setInformationProvider(provider, IDocument.DEFAULT_CONTENT_TYPE); - presenter.setInformationProvider(provider, IPHPPartitionScannerConstants.PHP); - presenter.setInformationProvider(provider, IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT); - presenter.setInformationProvider(provider, IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT); - presenter.setInformationProvider(provider, IPHPPartitionScannerConstants.HTML); - presenter.setInformationProvider(provider, IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT); - presenter.setSizeConstraints(40, 20, true, false); - return presenter; - } + /** + * Preference key used to look up display tab width. + * + * @since 2.0 + */ + public final static String PREFERENCE_TAB_WIDTH = PreferenceConstants.EDITOR_TAB_WIDTH; + /** + * Preference key for inserting spaces rather than tabs. + * + * @since 2.0 + */ + public final static String SPACES_FOR_TABS = PreferenceConstants.EDITOR_SPACES_FOR_TABS; + // public static final String HTML_DEFAULT = + // IPHPPartitionScannerConstants.HTML; + //IDocument.DEFAULT_CONTENT_TYPE; + private JavaTextTools fJavaTextTools; + private PHPEditor fEditor; + private ContentFormatter fFormatter; + private HTMLFormattingStrategy fFormattingStrategy; + /** + * Single token scanner. + */ + static class SingleTokenScanner extends BufferedRuleBasedScanner { + public SingleTokenScanner(TextAttribute attribute) { + setDefaultReturnToken(new Token(attribute)); + } + }; + /** + * Default constructor. + */ + public PHPSourceViewerConfiguration(JavaTextTools textTools, + PHPEditor editor) { + fJavaTextTools = textTools; + fEditor = editor; + } + /* + * @see SourceViewerConfiguration#getContentFormatter(ISourceViewer) + */ + public IContentFormatter getContentFormatter(ISourceViewer sourceViewer) { + // if (fFormatter == null) { + // fFormatter = new ContentFormatter(); + // fFormattingStrategy = new HTMLFormattingStrategy(this, + // sourceViewer); + // fFormatter.setFormattingStrategy(fFormattingStrategy, HTML_DEFAULT); + // fFormatter.enablePartitionAwareFormatting(false); + // fFormatter.setPartitionManagingPositionCategories(getConfiguredContentTypes(null)); + // } + // return fFormatter; + if (fFormatter == null) { + //ContentFormatter + fFormatter = new ContentFormatter(); + IFormattingStrategy strategy = new JavaFormattingStrategy( + sourceViewer); + fFormatter.setFormattingStrategy(strategy, + IDocument.DEFAULT_CONTENT_TYPE); + fFormatter.enablePartitionAwareFormatting(false); + fFormatter + .setPartitionManagingPositionCategories(getPartitionManagingPositionCategories()); + } + return fFormatter; + } + /** + * Returns the names of the document position categories used by the + * document partitioners created by this object to manage their partition + * information. If the partitioners don't use document position categories, + * the returned result is null. + * + * @return the partition managing position categories or null + * if there is none + */ + public String[] getPartitionManagingPositionCategories() { + return new String[]{DefaultPartitioner.CONTENT_TYPES_CATEGORY}; + } + // /** + // * Returns the names of the document position categories used by the + // document + // * partitioners created by this object to manage their partition + // information. + // * If the partitioners don't use document position categories, the + // returned + // * result is null. + // * + // * @return the partition managing position categories or + // null + // * if there is none + // */ + // private String[] getPartitionManagingPositionCategories() { + // return new String[] { DefaultPartitioner.CONTENT_TYPES_CATEGORY }; + // } + public PHPEditor getEditor() { + return fEditor; + } + /** + * Returns the preference store used by this configuration to initialize + * the individual bits and pieces. + * + * @return the preference store used to initialize this configuration + * + * @since 2.0 + */ + protected IPreferenceStore getPreferenceStore() { + return PHPeclipsePlugin.getDefault().getPreferenceStore(); + } + // /* (non-Javadoc) + // * Method declared on SourceViewerConfiguration + // */ + // public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) { + // return new PHPAnnotationHover(); + // } + /* + * @see SourceViewerConfiguration#getAnnotationHover(ISourceViewer) + */ + public IAnnotationHover getAnnotationHover(ISourceViewer sourceViewer) { + return new JavaAnnotationHover(JavaAnnotationHover.VERTICAL_RULER_HOVER); + } + /* + * @see SourceViewerConfiguration#getOverviewRulerAnnotationHover(ISourceViewer) + * @since 3.0 + */ + public IAnnotationHover getOverviewRulerAnnotationHover( + ISourceViewer sourceViewer) { + return new JavaAnnotationHover(JavaAnnotationHover.OVERVIEW_RULER_HOVER); + } + /* + * (non-Javadoc) Method declared on SourceViewerConfiguration + */ + public IAutoIndentStrategy getAutoIndentStrategy( + ISourceViewer sourceViewer, String contentType) { + return (IPHPPartitionScannerConstants.PHP.equals(contentType) + ? new PHPAutoIndentStrategy() + : new DefaultAutoIndentStrategy()); + } + /** + * Returns the PHP source code scanner for this configuration. + * + * @return the PHP source code scanner + */ + protected RuleBasedScanner getCodeScanner() { + return fJavaTextTools.getCodeScanner(); + } + /** + * Returns the HTML source code scanner for this configuration. + * + * @return the HTML source code scanner + */ + protected RuleBasedScanner getHTMLScanner() { + return fJavaTextTools.getHTMLScanner(); + } + /** + * Returns the Smarty source code scanner for this configuration. + * + * @return the Smarty source code scanner + */ + protected RuleBasedScanner getSmartyScanner() { + return fJavaTextTools.getSmartyScanner(); + } + /* + * @see SourceViewerConfiguration#getReconciler(ISourceViewer) + */ + public IReconciler getReconciler(ISourceViewer sourceViewer) { + if (getEditor() != null && getEditor().isEditable()) { + JavaReconciler reconciler = new JavaReconciler(getEditor(), + new JavaReconcilingStrategy(getEditor()), false); + reconciler.setProgressMonitor(new NullProgressMonitor()); + reconciler.setDelay(500); + return reconciler; + } + return null; + } + /* + * @see SourceViewerConfiguration#getConfiguredTextHoverStateMasks(ISourceViewer, + * String) + * @since 2.1 + */ + public int[] getConfiguredTextHoverStateMasks(ISourceViewer sourceViewer, + String contentType) { + JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin + .getDefault().getJavaEditorTextHoverDescriptors(); + int stateMasks[] = new int[hoverDescs.length]; + int stateMasksLength = 0; + for (int i = 0; i < hoverDescs.length; i++) { + if (hoverDescs[i].isEnabled()) { + int j = 0; + int stateMask = hoverDescs[i].getStateMask(); + while (j < stateMasksLength) { + if (stateMasks[j] == stateMask) + break; + j++; + } + if (j == stateMasksLength) + stateMasks[stateMasksLength++] = stateMask; + } + } + if (stateMasksLength == hoverDescs.length) + return stateMasks; + int[] shortenedStateMasks = new int[stateMasksLength]; + System.arraycopy(stateMasks, 0, shortenedStateMasks, 0, + stateMasksLength); + return shortenedStateMasks; + } + /* + * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String, int) + * @since 2.1 + */ + public ITextHover getTextHover(ISourceViewer sourceViewer, + String contentType, int stateMask) { + JavaEditorTextHoverDescriptor[] hoverDescs = PHPeclipsePlugin + .getDefault().getJavaEditorTextHoverDescriptors(); + int i = 0; + while (i < hoverDescs.length) { + if (hoverDescs[i].isEnabled() + && hoverDescs[i].getStateMask() == stateMask) + return new JavaEditorTextHoverProxy(hoverDescs[i], getEditor()); + i++; + } + if (fEditor != null) { + IEditorInput editorInput = fEditor.getEditorInput(); + if (editorInput instanceof IFileEditorInput) { + try { + IFile f = ((IFileEditorInput) editorInput).getFile(); + return new PHPTextHover(f.getProject()); + } catch (NullPointerException e) { + // this exception occurs, if getTextHover is called by + // preference pages ! + } + } + } + return new PHPTextHover(null); + } + /* + * @see SourceViewerConfiguration#getTextHover(ISourceViewer, String) + */ + public ITextHover getTextHover(ISourceViewer sourceViewer, + String contentType) { + return getTextHover(sourceViewer, contentType, + ITextViewerExtension2.DEFAULT_HOVER_STATE_MASK); + } + /** + * Returns the SmartyDoc source code scanner for this configuration. + * + * @return the SmartyDoc source code scanner + */ + protected RuleBasedScanner getSmartyDocScanner() { + return fJavaTextTools.getSmartyDocScanner(); + } + /** + * Returns the PHPDoc source code scanner for this configuration. + * + * @return the PHPDoc source code scanner + */ + protected RuleBasedScanner getPHPDocScanner() { + return fJavaTextTools.getJavaDocScanner(); + } + /* + * (non-Javadoc) Method declared on SourceViewerConfiguration + */ + public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { + return new String[]{IPHPPartitionScannerConstants.HTML, + IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT, + IPHPPartitionScannerConstants.PHP, + IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT, + IPHPPartitionScannerConstants.CSS, + IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT, + IPHPPartitionScannerConstants.JAVASCRIPT, + IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT, + IPHPPartitionScannerConstants.SMARTY, + IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT, + IDocument.DEFAULT_CONTENT_TYPE}; + } + /* + * (non-Javadoc) Method declared on SourceViewerConfiguration + */ + public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) { + ContentAssistant assistant = new ContentAssistant(); + IContentAssistProcessor processor = new HTMLCompletionProcessor(); + assistant.setContentAssistProcessor(processor, + IPHPPartitionScannerConstants.HTML); + assistant.setContentAssistProcessor(processor, + IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT); + assistant.setContentAssistProcessor(processor, + IDocument.DEFAULT_CONTENT_TYPE); + assistant.setContentAssistProcessor(processor, + IPHPPartitionScannerConstants.CSS); + assistant.setContentAssistProcessor(processor, + IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT); + assistant.setContentAssistProcessor(processor, + IPHPPartitionScannerConstants.JAVASCRIPT); + assistant.setContentAssistProcessor(processor, + IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT); + // TODO define special smarty partition content assist + assistant.setContentAssistProcessor(processor, + IPHPPartitionScannerConstants.SMARTY); + assistant.setContentAssistProcessor(processor, + IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT); + assistant.setContentAssistProcessor(new PHPCompletionProcessor(), + IPHPPartitionScannerConstants.PHP); + assistant.setContentAssistProcessor(new PHPDocCompletionProcessor(), + IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT); + // assistant.enableAutoActivation(true); + // assistant.setAutoActivationDelay(500); + // assistant.setProposalPopupOrientation(ContentAssistant.PROPOSAL_OVERLAY); + // ContentAssistPreference.configure(assistant, getPreferenceStore()); + // assistant.setContextInformationPopupOrientation( + // ContentAssistant.CONTEXT_INFO_ABOVE); + // assistant.setContextInformationPopupBackground( + // PHPEditorEnvironment.getPHPColorProvider().getColor( + // new RGB(150, 150, 0))); + ContentAssistPreference.configure(assistant, getPreferenceStore()); + assistant + .setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_ABOVE); + assistant + .setInformationControlCreator(getInformationControlCreator(sourceViewer)); + return assistant; + } + /* + * (non-Javadoc) Method declared on SourceViewerConfiguration + */ + // public String getDefaultPrefix(ISourceViewer sourceViewer, String + // contentType) { + // return (PHPPartitionScanner.PHP.equals(contentType) ? "//" : null); + // //$NON-NLS-1$ + // // return (IDocument.DEFAULT_CONTENT_TYPE.equals(contentType) ? "//" : + // null); //$NON-NLS-1$ + // } + /* + * @see SourceViewerConfiguration#getDefaultPrefix(ISourceViewer, String) + * @since 2.0 + */ + public String[] getDefaultPrefixes(ISourceViewer sourceViewer, + String contentType) { + return new String[]{"//", ""}; //$NON-NLS-1$ //$NON-NLS-2$ + } + /* + * (non-Javadoc) Method declared on SourceViewerConfiguration + */ + public ITextDoubleClickStrategy getDoubleClickStrategy( + ISourceViewer sourceViewer, String contentType) { + return new PHPDoubleClickSelector(); + } + /* + * @see SourceViewerConfiguration#getIndentPrefixes(ISourceViewer, String) + */ + public String[] getIndentPrefixes(ISourceViewer sourceViewer, + String contentType) { + Vector vector = new Vector(); + // prefix[0] is either '\t' or ' ' x tabWidth, depending on useSpaces + final IPreferenceStore preferences = PHPeclipsePlugin.getDefault() + .getPreferenceStore(); + int tabWidth = preferences.getInt(PHPCore.FORMATTER_TAB_SIZE); + boolean useSpaces = getPreferenceStore().getBoolean(SPACES_FOR_TABS); + for (int i = 0; i <= tabWidth; i++) { + StringBuffer prefix = new StringBuffer(); + if (useSpaces) { + for (int j = 0; j + i < tabWidth; j++) + prefix.append(' '); + if (i != 0) + prefix.append('\t'); + } else { + for (int j = 0; j < i; j++) + prefix.append(' '); + if (i != tabWidth) + prefix.append('\t'); + } + vector.add(prefix.toString()); + } + vector.add(""); //$NON-NLS-1$ + return (String[]) vector.toArray(new String[vector.size()]); + } + /* + * (non-Javadoc) Method declared on SourceViewerConfiguration + */ + public IPresentationReconciler getPresentationReconciler( + ISourceViewer sourceViewer) { + // PHPColorProvider provider = + // PHPEditorEnvironment.getPHPColorProvider(); + // JavaColorManager provider = + // PHPEditorEnvironment.getPHPColorProvider(); + PresentationReconciler reconciler = new PresentationReconciler(); + DefaultDamagerRepairer dr = new DefaultDamagerRepairer(getHTMLScanner()); + reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE); + reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE); + dr = new DefaultDamagerRepairer(getHTMLScanner()); + reconciler.setDamager(dr, IPHPPartitionScannerConstants.HTML); + reconciler.setRepairer(dr, IPHPPartitionScannerConstants.HTML); + dr = new DefaultDamagerRepairer(getHTMLScanner()); + reconciler.setDamager(dr, IPHPPartitionScannerConstants.CSS); + reconciler.setRepairer(dr, IPHPPartitionScannerConstants.CSS); + dr = new DefaultDamagerRepairer(getHTMLScanner()); + reconciler.setDamager(dr, + IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT); + reconciler.setRepairer(dr, + IPHPPartitionScannerConstants.CSS_MULTILINE_COMMENT); + dr = new DefaultDamagerRepairer(getHTMLScanner()); + reconciler.setDamager(dr, IPHPPartitionScannerConstants.JAVASCRIPT); + reconciler.setRepairer(dr, IPHPPartitionScannerConstants.JAVASCRIPT); + dr = new DefaultDamagerRepairer(getHTMLScanner()); + reconciler.setDamager(dr, + IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT); + reconciler.setRepairer(dr, + IPHPPartitionScannerConstants.JS_MULTILINE_COMMENT); + dr = new DefaultDamagerRepairer(getSmartyScanner()); + reconciler.setDamager(dr, IPHPPartitionScannerConstants.SMARTY); + reconciler.setRepairer(dr, IPHPPartitionScannerConstants.SMARTY); + dr = new DefaultDamagerRepairer(getSmartyDocScanner()); + reconciler.setDamager(dr, + IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT); + reconciler.setRepairer(dr, + IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT); + dr = new DefaultDamagerRepairer(new SingleTokenScanner( + new TextAttribute(fJavaTextTools.getColorManager().getColor( + PHPColorProvider.MULTI_LINE_COMMENT)))); + reconciler.setDamager(dr, + IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT); + reconciler.setRepairer(dr, + IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT); + dr = new DefaultDamagerRepairer(getCodeScanner()); + reconciler.setDamager(dr, IPHPPartitionScannerConstants.PHP); + reconciler.setRepairer(dr, IPHPPartitionScannerConstants.PHP); + dr = new DefaultDamagerRepairer(getPHPDocScanner()); + reconciler.setDamager(dr, + IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT); + reconciler.setRepairer(dr, + IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT); + return reconciler; + } + /* + * (non-Javadoc) Method declared on SourceViewerConfiguration + */ + public int getTabWidth(ISourceViewer sourceViewer) { + return getPreferenceStore().getInt(PREFERENCE_TAB_WIDTH); + } + /* + * (non-Javadoc) Method declared on SourceViewerConfiguration + */ + // public ITextHover getTextHover(ISourceViewer sourceViewer, String + // contentType) { + // if (fEditor != null) { + // IEditorInput editorInput = fEditor.getEditorInput(); + // if (editorInput instanceof IFileEditorInput) { + // try { + // IFile f = ((IFileEditorInput) editorInput).getFile(); + // return new PHPTextHover(f.getProject()); + // } catch (NullPointerException e) { + // // this exception occurs, if getTextHover is called by preference pages + // ! + // } + // } + // } + // return new PHPTextHover(null); + // } + /* + * @see SourceViewerConfiguration#getInformationControlCreator(ISourceViewer) + * @since 2.0 + */ + public IInformationControlCreator getInformationControlCreator( + ISourceViewer sourceViewer) { + return new IInformationControlCreator() { + public IInformationControl createInformationControl(Shell parent) { + return new DefaultInformationControl(parent, SWT.NONE, + new HTMLTextPresenter(true)); + // return new HoverBrowserControl(parent); + } + }; + } + /* + * @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer) + * @since 2.0 + */ + // public IInformationPresenter getInformationPresenter(ISourceViewer + // sourceViewer) { + // InformationPresenter presenter= new + // InformationPresenter(getInformationPresenterControlCreator(sourceViewer)); + // IInformationProvider provider= new JavaInformationProvider(getEditor()); + // presenter.setInformationProvider(provider, + // IDocument.DEFAULT_CONTENT_TYPE); + // presenter.setInformationProvider(provider, IJavaPartitions.JAVA_DOC); + // presenter.setSizeConstraints(60, 10, true, true); + // return presenter; + // } + /** + * Returns the information presenter control creator. The creator is a + * factory creating the presenter controls for the given source viewer. + * This implementation always returns a creator for DefaultInformationControl + * instances. + * + * @param sourceViewer + * the source viewer to be configured by this configuration + * @return an information control creator + * @since 2.1 + */ + private IInformationControlCreator getInformationPresenterControlCreator( + ISourceViewer sourceViewer) { + return new IInformationControlCreator() { + public IInformationControl createInformationControl(Shell parent) { + int shellStyle = SWT.RESIZE; + int style = SWT.V_SCROLL | SWT.H_SCROLL; + return new DefaultInformationControl(parent, shellStyle, style, + new HTMLTextPresenter(false)); + // return new HoverBrowserControl(parent); + } + }; + } + /** + * Returns the outline presenter control creator. The creator is a factory + * creating outline presenter controls for the given source viewer. This + * implementation always returns a creator for JavaOutlineInformationControl + * instances. + * + * @param sourceViewer + * the source viewer to be configured by this configuration + * @return an information control creator + * @since 2.1 + */ + private IInformationControlCreator getOutlinePresenterControlCreator( + ISourceViewer sourceViewer) { + return new IInformationControlCreator() { + public IInformationControl createInformationControl(Shell parent) { + int shellStyle = SWT.RESIZE; + int treeStyle = SWT.V_SCROLL | SWT.H_SCROLL; + return new JavaOutlineInformationControl(parent, shellStyle, + treeStyle); + } + }; + } + /** + * Returns the outline presenter which will determine and shown information + * requested for the current cursor position. + * + * @param sourceViewer + * the source viewer to be configured by this configuration + * @param doCodeResolve + * a boolean which specifies whether code resolve should be used + * to compute the Java element + * @return an information presenter + * @since 2.1 + */ + public IInformationPresenter getOutlinePresenter( + ISourceViewer sourceViewer, boolean doCodeResolve) { + InformationPresenter presenter = new InformationPresenter( + getOutlinePresenterControlCreator(sourceViewer)); + presenter.setAnchor(InformationPresenter.ANCHOR_GLOBAL); + IInformationProvider provider = new JavaElementProvider(getEditor(), + doCodeResolve); + presenter.setInformationProvider(provider, + IDocument.DEFAULT_CONTENT_TYPE); + presenter.setInformationProvider(provider, + IPHPPartitionScannerConstants.PHP); + presenter.setInformationProvider(provider, + IPHPPartitionScannerConstants.PHP_MULTILINE_COMMENT); + presenter.setInformationProvider(provider, + IPHPPartitionScannerConstants.SMARTY_MULTILINE_COMMENT); + presenter.setInformationProvider(provider, + IPHPPartitionScannerConstants.HTML); + presenter.setInformationProvider(provider, + IPHPPartitionScannerConstants.HTML_MULTILINE_COMMENT); + presenter.setSizeConstraints(40, 20, true, false); + return presenter; + } }