/*******************************************************************************
* Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
+ * 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
*******************************************************************************/
/**
* Creates a JavaFormatter with the target line delimiter.
- *
+ *
* @param lineDelimiter
* the line delimiter to use
* @param initialIndentLevel
/**
* Formats the template buffer.
- *
+ *
* @param buffer
* @param context
* @throws BadLocationException
return partitionType != null
&& (partitionType.equals(IPHPPartitions.PHP_MULTILINE_COMMENT)
|| partitionType.equals(IPHPPartitions.PHP_SINGLELINE_COMMENT) || partitionType.equals(IPHPPartitions.PHP_STRING_DQ)
- || partitionType.equals(IPHPPartitions.PHP_STRING_SQ) || partitionType.equals(IPHPPartitions.PHP_PHPDOC_COMMENT));
+ || partitionType.equals(IPHPPartitions.PHP_STRING_SQ) || partitionType.equals(IPHPPartitions.PHP_STRING_HEREDOC) || partitionType.equals(IPHPPartitions.PHP_PHPDOC_COMMENT));
} catch (BadLocationException e) {
return false;
}
// private void plainFormat(TemplateBuffer templateBuffer, JavaContext context) throws BadLocationException {
- //
+ //
// IDocument doc= new Document(templateBuffer.getString());
- //
+ //
// TemplateVariable[] variables= templateBuffer.getVariables();
- //
+ //
// List offsets= variablesToPositions(variables);
- //
+ //
// Map options;
// if (context.getCompilationUnit() != null)
// options= context.getCompilationUnit().getJavaProject().getOptions(true);
// else
// options= JavaCore.getOptions();
- //
+ //
// TextEdit edit= CodeFormatterUtil.format2(CodeFormatter.K_UNKNOWN, doc.get(), fInitialIndentLevel, fLineDelimiter, options);
// if (edit == null)
// throw new BadLocationException(); // fall back to indenting
- //
+ //
// MultiTextEdit root;
// if (edit instanceof MultiTextEdit)
// root= (MultiTextEdit) edit;
// // ignore this position
// }
// }
- //
+ //
// root.apply(doc, TextEdit.UPDATE_REGIONS);
- //
+ //
// positionsToVariables(offsets, variables);
- //
+ //
// templateBuffer.setContent(doc.get(), variables);
// }
/**
* Changes the delimiter to the configured line delimiter.
- *
+ *
* @param document
* the temporary document being edited
* @param root
/*******************************************************************************
* Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
+ * 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
*******************************************************************************/
/**
* Action that encloses the editor's current selection with Java block comment terminators (<code>/*</code> and
* <code>*/</code>).
- *
+ *
* @since 3.0
- */
+ */
public class AddBlockCommentAction extends BlockCommentAction {
/**
* Creates a new instance.
- *
+ *
* @param bundle
* the resource bundle
* @param prefix
/**
* Handle the first partition of the selected text.
- *
+ *
* @param partition
* @param edits
* @param factory
/**
* Handles the end of the given partition and the start of the next partition, which is returned.
- *
+ *
* @param partition
* @param edits
* @param factory
if (wasJavadoc) {
// if previous was javadoc, and the current one is not, then add block comment start
- if (partType == IDocument.DEFAULT_CONTENT_TYPE ||
+ if (partType == IDocument.DEFAULT_CONTENT_TYPE ||
partType == PHPDocumentPartitioner.PHP_SCRIPT_CODE ||
isSpecialPartition(partType)) {
edits.add(factory.createEdit(partition.getOffset(), 0, getCommentStart()));
/**
* Handles the end of the last partition.
- *
+ *
* @param partition
* @param edits
* @param factory
/**
* Returns whether <code>partType</code> is special, i.e. a Java <code>String</code>,<code>Character</code>, or
* <code>Line End Comment</code> partition.
- *
+ *
* @param partType
* the partition type to check
* @return <code>true</code> if <code>partType</code> is special, <code>false</code> otherwise
*/
private boolean isSpecialPartition(String partType) {
// return partType == IJavaPartitions.JAVA_CHARACTER
- return partType == IPHPPartitions.PHP_STRING_DQ || partType == IPHPPartitions.PHP_STRING_SQ
+ return partType == IPHPPartitions.PHP_STRING_DQ || partType == IPHPPartitions.PHP_STRING_SQ || partType == IPHPPartitions.PHP_STRING_HEREDOC
|| partType == IPHPPartitions.PHP_SINGLELINE_COMMENT;
}
/*******************************************************************************
* Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
+ * 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
*******************************************************************************/
}
}
}
- }
+ }
} catch (BadLocationException e) {
}
return null;
if (textViewer != null) {
return JavaWordFinder.findWord(textViewer.getDocument(), offset);
}
- return null;
+ return null;
}
-
- }
-
+
+ }
+
private final TemplateVariableProcessor fProcessor;
public TemplateEditorSourceViewerConfiguration(IColorManager colorManager, IPreferenceStore store, ITextEditor editor, TemplateVariableProcessor processor) {
super(colorManager, store, editor, IPHPPartitions.PHP_PARTITIONING);
fProcessor= processor;
}
-
+
/*
* @see SourceViewerConfiguration#getContentAssistant(ISourceViewer)
*/
IPreferenceStore store= PHPeclipsePlugin.getDefault().getPreferenceStore();
JavaTextTools textTools= PHPeclipsePlugin.getDefault().getJavaTextTools();
- IColorManager manager= textTools.getColorManager();
-
+ IColorManager manager= textTools.getColorManager();
+
ContentAssistant assistant= new ContentAssistant();
assistant.setContentAssistProcessor(fProcessor, IDocument.DEFAULT_CONTENT_TYPE);
// Register the same processor for strings and single line comments to get code completion at the start of those partitions.
assistant.setContentAssistProcessor(fProcessor, IPHPPartitions.PHP_STRING_DQ);
assistant.setContentAssistProcessor(fProcessor, IPHPPartitions.PHP_STRING_SQ);
+ assistant.setContentAssistProcessor(fProcessor, IPHPPartitions.PHP_STRING_HEREDOC);
assistant.setContentAssistProcessor(fProcessor, IPHPPartitions.PHP_SINGLELINE_COMMENT);
assistant.setContentAssistProcessor(fProcessor, IPHPPartitions.PHP_MULTILINE_COMMENT);
assistant.setContentAssistProcessor(fProcessor, IPHPPartitions.PHP_PHPDOC_COMMENT);
assistant.setContextInformationPopupOrientation(ContentAssistant.CONTEXT_INFO_ABOVE);
assistant.setInformationControlCreator(getInformationControlCreator(sourceViewer));
- Color background= getColor(store, PreferenceConstants.CODEASSIST_PROPOSALS_BACKGROUND, manager);
+ Color background= getColor(store, PreferenceConstants.CODEASSIST_PROPOSALS_BACKGROUND, manager);
assistant.setContextInformationPopupBackground(background);
assistant.setContextSelectorBackground(background);
assistant.setProposalSelectorBackground(background);
assistant.setContextInformationPopupForeground(foreground);
assistant.setContextSelectorForeground(foreground);
assistant.setProposalSelectorForeground(foreground);
-
+
return assistant;
- }
+ }
private Color getColor(IPreferenceStore store, String key, IColorManager manager) {
RGB rgb= PreferenceConverter.getColor(store, key);
return manager.getColor(rgb);
}
-
+
/*
* @see SourceViewerConfiguration#getTextHover(ISourceViewer, String, int)
* @since 2.1
public interface IPHPPartitions
{
public final static String PHP_PARTITIONING = "___php_partitioning"; //$NON-NLS-1$
-
+
public final static String PHP_PHPDOC_COMMENT = "__php_phpdoc_comment"; //$NON-NLS-1$
public final static String PHP_SINGLELINE_COMMENT = "__php_singleline_comment"; //$NON-NLS-1$
public final static String PHP_MULTILINE_COMMENT = "__php_multiline_comment"; //$NON-NLS-1$
public final static String PHP_STRING_DQ = "__php_string"; //$NON-NLS-1$
public final static String PHP_STRING_SQ = "__php_string_sq"; //$NON-NLS-1$
+ public final static String PHP_STRING_HEREDOC = "__php_string_heredoc"; //$NON-NLS-1$
public final static String JAVASCRIPT = "__javascript"; //$NON-NLS-1$
public final static String JS_MULTILINE_COMMENT = "__js_multiline_comment"; //$NON-NLS-1$
public final static String CSS = "__css"; //$NON-NLS-1$
public final static String CSS_MULTILINE_COMMENT = "__css_multiline_comment"; //$NON-NLS-1$
public final static String HTML = "__html"; //$NON-NLS-1$
public final static String HTML_MULTILINE_COMMENT = "__html_multiline_comment"; //$NON-NLS-1$
-
+
public final static String SMARTY = "__smarty"; //$NON-NLS-1$
public final static String SMARTY_MULTILINE_COMMENT = "__smarty_multiline_comment"; //$NON-NLS-1$
-
- public final static int PHP_FILE = 1;
- public final static int HTML_FILE = 2;
- public final static int XML_FILE = 3;
- public final static int SMARTY_FILE = 4;
+
+ public final static int PHP_FILE = 1;
+ public final static int HTML_FILE = 2;
+ public final static int XML_FILE = 3;
+ public final static int SMARTY_FILE = 4;
}
/*******************************************************************************
* Copyright (c) 2000, 2004 IBM Corporation and others.
- * All rights reserved. This program and the accompanying materials
+ * 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
*******************************************************************************/
/**
* Modifies <code>DocumentCommand</code>s inserting semicolons and opening braces to place them
* smartly, i.e. moving them to the end of a line if that is what the user expects.
- *
+ *
* <p>In practice, semicolons and braces (and the caret) are moved to the end of the line if they are typed
* anywhere except for semicolons in a <code>for</code> statements definition. If the line contains a semicolon
* or brace after the current caret position, the cursor is moved after it.</p>
- *
+ *
* @see org.eclipse.jface.text.DocumentCommand
* @since 3.0
*/
/**
* Creates a new SmartSemicolonAutoEditStrategy.
- *
+ *
* @param partitioning the document partitioning
*/
public SmartSemicolonAutoEditStrategy(String partitioning) {
return;
if (fCharacter == BRACECHAR && !store.getBoolean(PreferenceConstants.EDITOR_SMART_OPENING_BRACE))
return;
-
+
IWorkbenchPage page= PHPeclipsePlugin.getActivePage();
if (page == null)
return;
if (position < pos)
return;
- // never double already existing content
+ // never double already existing content
if (alreadyPresent(document, fCharacter, position))
return;
-
+
// don't do special processing if what we do is actually the normal behaviour
String insertion= adjustSpacing(document, position, fCharacter);
if (command.offset == position && insertion.equals(command.text))
return;
try {
-
+
final SmartBackspaceManager manager= (SmartBackspaceManager) editor.getAdapter(SmartBackspaceManager.class);
if (manager != null && PHPeclipsePlugin.getDefault().getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_SMART_BACKSPACE)) {
TextEdit e1= new ReplaceEdit(command.offset, command.text.length(), document.get(command.offset, command.length));
s1);
manager.register(s2);
}
-
+
// 3: modify command
command.offset= position;
command.length= 0;
PHPeclipsePlugin.log(e);
}
-
+
}
/**
* Returns <code>true</code> if the document command is applied on a multi
* line selection, <code>false</code> otherwise.
- *
+ *
* @param document the document
* @param command the command
* @return <code>true</code> if <code>command</code> is a multiline command
/**
* Adds a space before a brace if it is inserted after a parenthesis, equal sign, or one
- * of the keywords <code>try, else, do</code>.
- *
+ * of the keywords <code>try, else, do</code>.
+ *
* @param document the document we are working on
* @param position the insert position of <code>character</code>
* @param character the character to be inserted
/**
* Checks whether a character to be inserted is already present at the insert location (perhaps
* separated by some whitespace from <code>position</code>.
- *
+ *
* @param document the document we are working on
* @param position the insert position of <code>ch</code>
* @param character the character to be inserted
/**
* Computes the next insert position of the given character in the current line.
- *
+ *
* @param document the document we are working on
* @param line the line where the change is being made
* @param offset the position of the caret in the line when <code>character</code> was typed
if (insertPos > 0 && text.charAt(insertPos - 1) == character)
insertPos= insertPos - 1;
}
-
+
} else {
Assert.isTrue(false);
return -1;
/**
* Computes an insert position for an opening brace if <code>offset</code> maps to a position in
* <code>document</code> that looks like being the RHS of an assignment or like an array definition.
- *
+ *
* @param document the document being modified
* @param line the current line under investigation
* @param offset the offset of the caret position, relative to the line start.
if (pos == 0)
return -1;
-
+
int p= firstNonWhitespaceBackward(document, pos - 1, partitioning, -1);
-
+
if (p == -1)
return -1;
-
+
try {
-
+
char ch= document.getChar(p);
if (ch != '=' && ch != ']')
return -1;
-
+
if (p == 0)
return offset;
-
+
p= firstNonWhitespaceBackward(document, p - 1, partitioning, -1);
if (p == -1)
return -1;
-
+
ch= document.getChar(p);
if (Scanner.isPHPIdentifierPart(ch) || ch == ']' || ch == '[')
return offset;
-
+
} catch (BadLocationException e) {
}
return -1;
/**
* Computes an insert position for an opening brace if <code>offset</code> maps to a position in
- * <code>document</code> involving a keyword taking a block after it. These are: <code>try</code>,
+ * <code>document</code> involving a keyword taking a block after it. These are: <code>try</code>,
* <code>do</code>, <code>synchronized</code>, <code>static</code>, <code>finally</code>, or <code>else</code>.
- *
+ *
* @param document the document being modified
* @param line the current line under investigation
* @param offset the offset of the caret position, relative to the line start.
/**
* Computes an insert position for an opening brace if <code>offset</code> maps to a position in
* <code>document</code> with a expression in parenthesis that will take a block after the closing parenthesis.
- *
+ *
* @param document the document being modified
* @param line the current line under investigation
* @param offset the offset of the caret position, relative to the line start.
int scanTo= scanForward(document, pos, partitioning, length, '}');
if (scanTo == -1)
scanTo= length;
-
+
int closingParen= findClosingParenToLeft(document, pos, partitioning) - 1;
while (true) {
/**
* Finds a closing parenthesis to the left of <code>position</code> in document, where that parenthesis is only
* separated by whitespace from <code>position</code>. If no such parenthesis can be found, <code>position</code> is returned.
- *
+ *
* @param document the document being modified
* @param position the first character position in <code>document</code> to be considered
* @param partitioning the document partitioning
/**
* Finds the first whitespace character position to the right of (and including) <code>position</code>.
- *
+ *
* @param document the document being modified
* @param position the first character position in <code>document</code> to be considered
* @return the position of a whitespace character greater or equal than <code>position</code> separated only by whitespace, or -1 if none found
/**
* Finds the highest position in <code>document</code> such that the position is <= <code>position</code>
* and > <code>bound</code> and <code>Character.isWhitespace(document.getChar(pos))</code> evaluates to <code>false</code>
- * and the position is in the default partition.
- *
+ * and the position is in the default partition.
+ *
* @param document the document being modified
* @param position the first character position in <code>document</code> to be considered
* @param partitioning the document partitioning
/**
* Finds the smallest position in <code>document</code> such that the position is >= <code>position</code>
* and < <code>bound</code> and <code>Character.isWhitespace(document.getChar(pos))</code> evaluates to <code>false</code>
- * and the position is in the default partition.
- *
+ * and the position is in the default partition.
+ *
* @param document the document being modified
* @param position the first character position in <code>document</code> to be considered
* @param partitioning the document partitioning
/**
* Finds the highest position in <code>document</code> such that the position is <= <code>position</code>
* and > <code>bound</code> and <code>document.getChar(position) == ch</code> evaluates to <code>true</code> for at least one
- * ch in <code>chars</code> and the position is in the default partition.
- *
+ * ch in <code>chars</code> and the position is in the default partition.
+ *
* @param document the document being modified
* @param position the first character position in <code>document</code> to be considered
* @param partitioning the document partitioning
private static int scanBackward(IDocument document, int position, String partitioning, int bound, char[] chars) {
Assert.isTrue(bound >= -1);
Assert.isTrue(position < document.getLength() );
-
+
Arrays.sort(chars);
-
+
try {
while (position > bound) {
// /**
// * Finds the highest position in <code>document</code> such that the position is <= <code>position</code>
// * and > <code>bound</code> and <code>document.getChar(position) == ch</code> evaluates to <code>true</code>
-// * and the position is in the default partition.
-// *
+// * and the position is in the default partition.
+// *
// * @param document the document being modified
// * @param position the first character position in <code>document</code> to be considered
// * @param bound the first position in <code>document</code> to not consider any more, with <code>scanTo</code> > <code>position</code>
/**
* Finds the lowest position in <code>document</code> such that the position is >= <code>position</code>
* and < <code>bound</code> and <code>document.getChar(position) == ch</code> evaluates to <code>true</code> for at least one
- * ch in <code>chars</code> and the position is in the default partition.
- *
+ * ch in <code>chars</code> and the position is in the default partition.
+ *
* @param document the document being modified
* @param position the first character position in <code>document</code> to be considered
* @param partitioning the document partitioning
private static int scanForward(IDocument document, int position, String partitioning, int bound, char[] chars) {
Assert.isTrue(position >= 0);
Assert.isTrue(bound <= document.getLength());
-
+
Arrays.sort(chars);
-
+
try {
while (position < bound) {
/**
* Finds the lowest position in <code>document</code> such that the position is >= <code>position</code>
* and < <code>bound</code> and <code>document.getChar(position) == ch</code> evaluates to <code>true</code>
- * and the position is in the default partition.
- *
+ * and the position is in the default partition.
+ *
* @param document the document being modified
* @param position the first character position in <code>document</code> to be considered
* @param partitioning the document partitioning
/**
* Checks whether the content of <code>document</code> in the range (<code>offset</code>, <code>length</code>)
* contains the <code>new</code> keyword.
- *
+ *
* @param document the document being modified
* @param offset the first character position in <code>document</code> to be considered
* @param length the length of the character range to be considered
try {
String text= document.get(offset, length);
int pos= text.indexOf("new"); //$NON-NLS-1$
-
+
while (pos != -1 && !isDefaultPartition(document, pos + offset, partitioning))
pos= text.indexOf("new", pos + 2); //$NON-NLS-1$
if (pos + 3 < length && Scanner.isPHPIdentifierPart(text.charAt(pos + 3)))
return false;
-
+
return true;
} catch (BadLocationException e) {
* Checks whether the content of <code>document</code> at <code>position</code> looks like an
* anonymous class definition. <code>position</code> must be to the left of the opening
* parenthesis of the definition's parameter list.
- *
+ *
* @param document the document being modified
* @param position the first character position in <code>document</code> to be considered
* @param partitioning the document partitioning
/**
* Checks whether <code>position</code> resides in a default (Java) partition of <code>document</code>.
- *
+ *
* @param document the document being modified
* @param position the position to be checked
* @param partitioning the document partitioning
private static boolean isDefaultPartition(IDocument document, int position, String partitioning) {
Assert.isTrue(position >= 0);
Assert.isTrue(position <= document.getLength());
-
+
try {
// don't use getPartition2 since we're interested in the scanned character's partition
ITypedRegion region= TextUtilities.getPartition(document, partitioning, position, false);
return region.getType().equals(IDocument.DEFAULT_CONTENT_TYPE);
-
+
} catch (BadLocationException e) {
}
-
+
return false;
}
/**
* Finds the position of the parenthesis matching the closing parenthesis at <code>position</code>.
- *
+ *
* @param document the document being modified
* @param position the position in <code>document</code> of a closing parenthesis
* @param partitioning the document partitioning
try {
Assert.isTrue(document.getChar(position) == CLOSING_PAREN);
-
+
int depth= 1;
while (true) {
position= scanBackward(document, position - 1, partitioning, -1, new char[] {CLOSING_PAREN, OPENING_PAREN});
if (position == -1)
return -1;
-
+
if (document.getChar(position) == CLOSING_PAREN)
depth++;
else
depth--;
-
+
if (depth == 0)
return position;
}
}
/**
- * Checks whether, to the left of <code>position</code> and separated only by whitespace,
+ * Checks whether, to the left of <code>position</code> and separated only by whitespace,
* <code>document</code> contains a keyword taking a parameter list and a block after it.
- * These are: <code>if</code>, <code>while</code>, <code>catch</code>, <code>for</code>, <code>synchronized</code>, <code>switch</code>.
- *
+ * These are: <code>if</code>, <code>while</code>, <code>catch</code>, <code>for</code>, <code>synchronized</code>, <code>switch</code>.
+ *
* @param document the document being modified
* @param position the first character position in <code>document</code> to be considered
* @param partitioning the document partitioning
}
/**
- * Checks whether code>document</code> contains the <code>String</code> <code>like</code> such
+ * Checks whether code>document</code> contains the <code>String</code> <code>like</code> such
* that its last character is at <code>position</code>. If <code>like</code> starts with a
* identifier part (as determined by {@link Scanner#isPHPIdentifierPart(char)}), it is also made
* sure that <code>like</code> is preceded by some non-identifier character or stands at the
* document start.
- *
+ *
* @param document the document being modified
* @param position the first character position in <code>document</code> to be considered
* @param like the <code>String</code> to look for.
* Checks whether the content of <code>document</code> at <code>position</code> looks like a
* method declaration header (i.e. only the return type and method name). <code>position</code>
* must be just left of the opening parenthesis of the parameter list.
- *
+ *
* @param document the document being modified
* @param position the first character position in <code>document</code> to be considered
* @param partitioning the document partitioning
* @return <code>true</code> if the content of <code>document</code> looks like a method definition, <code>false</code> otherwise
*/
private static boolean looksLikeMethodDecl(IDocument document, int position, String partitioning) {
-
+
// method name
position= eatIdentToLeft(document, position, partitioning);
if (position < 1)
return false;
-
+
position= eatBrackets(document, position - 1, partitioning);
if (position < 1)
return false;
-
+
position= eatIdentToLeft(document, position - 1, partitioning);
return position != -1;
/**
* From <code>position</code> to the left, eats any whitespace and then a pair of brackets
* as used to declare an array return type like <pre>String [ ]</pre>.
- * The return value is either the position of the opening bracket or <code>position</code> if no
- * pair of brackets can be parsed.
- *
+ * The return value is either the position of the opening bracket or <code>position</code> if no
+ * pair of brackets can be parsed.
+ *
* @param document the document being modified
* @param position the first character position in <code>document</code> to be considered
* @param partitioning the document partitioning
}
/**
- * From <code>position</code> to the left, eats any whitespace and the first identifier, returning
+ * From <code>position</code> to the left, eats any whitespace and the first identifier, returning
* the position of the first identifier character (in normal read order).
* <p>When called on a document with content <code>" some string "</code> and positionition 13, the
* return value will be 6 (the first letter in <code>string</code>).
* </p>
- *
+ *
* @param document the document being modified
* @param position the first character position in <code>document</code> to be considered
* @param partitioning the document partitioning
if (position < 0)
return -1;
Assert.isTrue(position < document.getLength());
-
+
int p= firstNonWhitespaceBackward(document, position, partitioning, -1);
if (p == -1)
return -1;
/**
* Returns a position in the first java partition after the last non-empty and non-comment partition.
* There is no non-whitespace from the returned position to the end of the partition it is contained in.
- *
+ *
* @param document the document being modified
* @param line the line under investigation
* @param offset the caret offset into <code>line</code>
/**
* Returns a valid insert location (except for whitespace) in <code>partition</code> or -1 if
- * there is no valid insert location.
+ * there is no valid insert location.
* An valid insert location is right after any java string or character partition, or at the end
- * of a java default partition, but never behind <code>maxOffset</code>. Comment partitions or
+ * of a java default partition, but never behind <code>maxOffset</code>. Comment partitions or
* empty java partitions do never yield valid insert positions.
- *
+ *
* @param doc the document being modified
* @param partition the current partition
* @param maxOffset the maximum offset to consider
return endOffset;
if (IPHPPartitions.PHP_STRING_SQ.equals(partition.getType()))
return endOffset;
+ if (IPHPPartitions.PHP_STRING_HEREDOC.equals(partition.getType()))
+ return endOffset;
if (IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType())) {
try {
if (doc.get(partition.getOffset(), endOffset - partition.getOffset()).trim().length() == 0)
return INVALID;
}
}
- // default: we don't know anything about the partition - assume valid
+ // default: we don't know anything about the partition - assume valid
return endOffset;
}
* Determines whether the current line contains a for statement.
* Algorithm: any "for" word in the line is a positive, "for" contained in a string literal will
* produce a false positive.
- *
+ *
* @param line the line where the change is being made
* @param offset the position of the caret
* @return <code>true</code> if <code>line</code> contains <code>for</code>, <code>false</code> otherwise
}
/**
- * Returns the position in <code>text</code> after which there comes only whitespace, up to
+ * Returns the position in <code>text</code> after which there comes only whitespace, up to
* <code>offset</code>.
- *
+ *
* @param text the text being searched
* @param offset the maximum offset to search for
* @return the smallest value <code>v</code> such that <code>text.substring(v, offset).trim() == 0</code>
PHP_MULTILINE_COMMENT,
PHP_SINGLELINE_COMMENT,
PHP_STRING_DQ,
- PHP_STRING_SQ };
+ PHP_STRING_SQ,
+ PHP_STRING_HEREDOC};
- private static XMLPartitionScanner HTML_PARTITION_SCANNER = null;
+// private static XMLPartitionScanner HTML_PARTITION_SCANNER = null;
- private static FastJavaPartitionScanner PHP_PARTITION_SCANNER = null;
+// private static FastJavaPartitionScanner PHP_PARTITION_SCANNER = null;
private static HTMLPartitionScanner SMARTY_PARTITION_SCANNER = null;
- private static XMLPartitionScanner XML_PARTITION_SCANNER = null;
+// private static XMLPartitionScanner XML_PARTITION_SCANNER = null;
// private final static String[] TYPES= new String[] { PHPPartitionScanner.PHP, PHPPartitionScanner.JAVA_DOC,
// PHPPartitionScanner.JAVA_MULTILINE_COMMENT };
/** The PHP single quoted string scanner */
// private SingleTokenPHPScanner fStringSQScanner;
-
+
/** The PHPDoc scanner */
private PHPDocCodeScanner fPHPDocScanner;
/**
* The core preference store.
- *
+ *
* @since 2.1
*/
private Preferences fCorePreferenceStore;
// private RuleBasedScanner jspBracketScanner;
/**
* Creates a new Java text tools collection.
- *
+ *
* @param store
* the preference store to initialize the text tools. The text tool instance installs a listener on the passed preference
* store to adapt itself to changes in the preference store. In general <code>PreferenceConstants.
/**
* Creates a new Java text tools collection.
- *
+ *
* @param store
* the preference store to initialize the text tools. The text tool instance installs a listener on the passed preference
* store to adapt itself to changes in the preference store. In general <code>PreferenceConstants.
IPreferenceConstants.PHP_SINGLELINE_COMMENT);
// fStringDQScanner = new SingleTokenPHPScanner((JavaColorManager) colorManager, store, IPreferenceConstants.PHP_STRING);
// fStringSQScanner = new SingleTokenPHPScanner((JavaColorManager) colorManager, store, IPreferenceConstants.PHP_STRING);
-
+
fPHPDocScanner = new PHPDocCodeScanner((JavaColorManager) colorManager, store);
// fHTMLScanner = new HTMLCodeScanner((JavaColorManager)fColorManager, store);
fSmartyScanner = new SmartyCodeScanner((JavaColorManager) colorManager, store);
}
/**
- *
+ *
*/
public XMLTextTools getXMLTextTools() {
return xmlTextTools;
/**
* Returns the color manager which is used to manage any Java-specific colors needed for such things like syntax highlighting.
- *
+ *
* @return the color manager to be used for Java text viewers
*/
public JavaColorManager getColorManager() {
/**
* Returns a scanner which is configured to scan Java source code.
- *
+ *
* @return a Java source code scanner
*/
public RuleBasedScanner getCodeScanner() {
/**
* Returns a scanner which is configured to scan Java multiline comments.
- *
+ *
* @return a Java multiline comment scanner
- *
+ *
* @since 2.0
*/
public RuleBasedScanner getMultilineCommentScanner() {
/**
* Returns a scanner which is configured to scan HTML code.
- *
+ *
* @return a HTML scanner
- *
+ *
* @since 2.0
*/
// public RuleBasedScanner getHTMLScanner() {
// }
/**
* Returns a scanner which is configured to scan Smarty code.
- *
+ *
* @return a Smarty scanner
- *
+ *
* @since 2.0
*/
public RuleBasedScanner getSmartyScanner() {
/**
* Returns a scanner which is configured to scan Smarty code.
- *
+ *
* @return a Smarty scanner
- *
+ *
* @since 2.0
*/
public RuleBasedScanner getSmartyDocScanner() {
/**
* Returns a scanner which is configured to scan Java singleline comments.
- *
+ *
* @return a Java singleline comment scanner
- *
+ *
* @since 2.0
*/
public RuleBasedScanner getSinglelineCommentScanner() {
/**
* Returns a scanner which is configured to scan Java strings.
- *
+ *
* @return a Java string scanner
- *
+ *
* @since 2.0
*/
// public RuleBasedScanner getStringScanner() {
/**
* Returns a scanner which is configured to scan JavaDoc compliant comments. Notes that the start sequence "/**" and the
* corresponding end sequence are part of the JavaDoc comment.
- *
+ *
* @return a JavaDoc scanner
*/
public RuleBasedScanner getJavaDocScanner() {
/**
* Returns a scanner which is configured to scan Java-specific partitions, which are multi-line comments, JavaDoc comments, and
* regular Java source code.
- *
+ *
* @return a Java partition scanner
*/
// public IPartitionTokenScanner getPartitionScanner() {
/**
* Factory method for creating a PHP-specific document partitioner using this object's partitions scanner. This method is a
* convenience method.
- *
+ *
* @return a newly created Java document partitioner
*/
public IDocumentPartitioner createDocumentPartitioner() {
/**
* Factory method for creating a PHP-specific document partitioner using this object's partitions scanner. This method is a
* convenience method.
- *
+ *
* @return a newly created Java document partitioner
*/
public IDocumentPartitioner createDocumentPartitioner(String extension) {
/**
* Sets up the Java document partitioner for the given document for the given partitioning.
- *
+ *
* @param document
* the document to be set up
* @param partitioning
* the document partitioning
* @param element
* TODO
- *
+ *
* @since 3.0
*/
// public void setupJavaDocumentPartitioner(IDocument document, String partitioning, Object element) {
/**
* 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 <code>null</code>.
- *
+ *
* @return the partition managing position categories or <code>null</code> if there is none
*/
public String[] getPartitionManagingPositionCategories() {
/**
* Determines whether the preference change encoded by the given event changes the behavior of one its contained components.
- *
+ *
* @param event
* the event to be investigated
* @return <code>true</code> if event causes a behavioral change
// }
/**
* Adapts the behavior of the contained components to the change encoded in the given event.
- *
+ *
* @param event
* the event to which to adapt
* @since 2.0
}
/**
- *
+ *
*/
// public IPartitionTokenScanner getJSPScriptScanner() {
// return jspScriptScanner;
/**
* Returns a scanner which is configured to scan plain text in JSP.
- *
+ *
* @return a JSP text scanner
*/
// public RuleBasedScanner getJSPTextScanner() {
// }
/**
* Returns a scanner which is configured to scan plain text in JSP.
- *
+ *
* @return a JSP text scanner
*/
// public RuleBasedScanner getJSPBracketScanner() {
/**
* Sets up the Java document partitioner for the given document for the default partitioning.
- *
+ *
* @param document
* the document to be set up
* @since 3.0
/**
* Sets up the Java document partitioner for the given document for the given partitioning.
- *
+ *
* @param document
* the document to be set up
* @param partitioning
/**
* Returns this text tool's preference store.
- *
+ *
* @return the preference store
* @since 3.0
*/
/**
* Returns this text tool's core preference store.
- *
+ *
* @return the core preference store
* @since 3.0
*/
IPHPPartitions.HTML, IPHPPartitions.HTML_MULTILINE_COMMENT, IPHPPartitions.PHP_PARTITIONING,
IPHPPartitions.PHP_SINGLELINE_COMMENT, IPHPPartitions.PHP_MULTILINE_COMMENT, IPHPPartitions.PHP_PHPDOC_COMMENT,
- IPHPPartitions.PHP_STRING_DQ, IPHPPartitions.PHP_STRING_SQ, IPHPPartitions.CSS, IPHPPartitions.CSS_MULTILINE_COMMENT,
+ IPHPPartitions.PHP_STRING_DQ, IPHPPartitions.PHP_STRING_SQ, IPHPPartitions.PHP_STRING_HEREDOC, IPHPPartitions.CSS, IPHPPartitions.CSS_MULTILINE_COMMENT,
IPHPPartitions.JAVASCRIPT, IPHPPartitions.JS_MULTILINE_COMMENT, IPHPPartitions.SMARTY,
IPHPPartitions.SMARTY_MULTILINE_COMMENT,
public String[] getConfiguredPHPContentTypes() {
return new String[] { IDocument.DEFAULT_CONTENT_TYPE, IPHPPartitions.PHP_PARTITIONING, IPHPPartitions.PHP_SINGLELINE_COMMENT,
IPHPPartitions.PHP_MULTILINE_COMMENT, IPHPPartitions.PHP_PHPDOC_COMMENT, IPHPPartitions.PHP_STRING_DQ,
- IPHPPartitions.PHP_STRING_SQ, IPHPPartitions.CSS, IPHPPartitions.CSS_MULTILINE_COMMENT, IPHPPartitions.JAVASCRIPT,
+ IPHPPartitions.PHP_STRING_SQ, IPHPPartitions.PHP_STRING_HEREDOC, IPHPPartitions.CSS, IPHPPartitions.CSS_MULTILINE_COMMENT, IPHPPartitions.JAVASCRIPT,
IPHPPartitions.JS_MULTILINE_COMMENT, IPHPPartitions.SMARTY, IPHPPartitions.SMARTY_MULTILINE_COMMENT, };
}
assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_PARTITIONING);
assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_STRING_DQ);
assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_STRING_SQ);
+ assistant.setContentAssistProcessor(processor, IPHPPartitions.PHP_STRING_HEREDOC);
assistant.setContentAssistProcessor(new PHPDocCompletionProcessor(getEditor()), IPHPPartitions.PHP_PHPDOC_COMMENT);
// assistant.enableAutoActivation(true);
phpDR = new DefaultDamagerRepairer(getStringSQScanner());
phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_SQ);
phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_SQ);
+ phpDR = new DefaultDamagerRepairer(getStringDQScanner());
+ phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_STRING_HEREDOC);
+ phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_STRING_HEREDOC);
phpDR = new DefaultDamagerRepairer(getSinglelineCommentScanner());
phpReconciler.setDamager(phpDR, IPHPPartitions.PHP_SINGLELINE_COMMENT);
phpReconciler.setRepairer(phpDR, IPHPPartitions.PHP_SINGLELINE_COMMENT);
List segmentation = new ArrayList();
for (int i = 0; i < linePartitioning.length; i++) {
- if (IPHPPartitions.PHP_STRING_DQ.equals(linePartitioning[i].getType()))
+ if (IPHPPartitions.PHP_STRING_DQ.equals(linePartitioning[i].getType())) {
segmentation.add(linePartitioning[i]);
+ } else if (IPHPPartitions.PHP_STRING_HEREDOC.equals(linePartitioning[i].getType())) {
+ segmentation.add(linePartitioning[i]);
+ }
}
if (segmentation.size() == 0)
* 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
+ *
+ * Contributors: IBM Corporation - Initial implementation
* www.phpeclipse.de
******************************************************************************/
/**
prependAutoEditStrategy(smartSemi, IDocument.DEFAULT_CONTENT_TYPE);
prependAutoEditStrategy(smartSemi, IPHPPartitions.PHP_STRING_DQ);
prependAutoEditStrategy(smartSemi, IPHPPartitions.PHP_STRING_SQ);
+ prependAutoEditStrategy(smartSemi, IPHPPartitions.PHP_STRING_HEREDOC);
}
/*
/**
* Remembers data related to the current selection to be able to restore it later.
- *
+ *
* @since 3.0
*/
private class RememberedSelection {
/**
* Remembers additional data for a given offset to be able restore it later.
- *
+ *
* @since 3.0
*/
private class RememberedOffset {
/**
* Store visual properties of the given offset.
- *
+ *
* @param offset
* Offset in the document
*/
/**
* Return offset recomputed from stored visual properties.
- *
+ *
* @return Offset in the document
*/
public int getOffset() {
/**
* Return offset recomputed from stored visual properties.
- *
+ *
* @param newElement
* Enclosing element
* @return Offset in the document
/**
* Returns the offset used to reveal the given element based on the given selection offset.
- *
+ *
* @param element
* the element
* @param offset
/**
* Return Java element recomputed from stored visual properties.
- *
+ *
* @return Java element
*/
public IJavaElement getElement() {
/**
* Does the given Java element contain the given offset?
- *
+ *
* @param element
* Java element
* @param offset
/**
* Returns the offset of the given Java element.
- *
+ *
* @param element
* Java element
* @return Offset of the given Java element
/**
* Returns the length of the given Java element.
- *
+ *
* @param element
* Java element
* @return Length of the given Java element
/**
* Returns the updated java element for the old java element.
- *
+ *
* @param element
* Old Java element
* @return Updated Java element
/**
* The remembered selection.
- *
+ *
* @since 3.0
*/
private RememberedSelection fRememberedSelection = new RememberedSelection();
/**
* Reconciling listeners.
- *
+ *
* @since 3.0
*/
private ListenerList fReconcilingListeners = new ListenerList();
action.setActionDefinitionId(PHPEditorActionDefinitionIds.FORMAT);
setAction("Format", action); //$NON-NLS-1$
markAsStateDependentAction("Format", true); //$NON-NLS-1$
- markAsSelectionDependentAction("Format", true); //$NON-NLS-1$
+ markAsSelectionDependentAction("Format", true); //$NON-NLS-1$
// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.FORMAT_ACTION);
// action = new AddBlockCommentAction(PHPEditorMessages.getResourceBundle(),
// markAsStateDependentAction("Indent", true); //$NON-NLS-1$
// markAsSelectionDependentAction("Indent", true); //$NON-NLS-1$
//// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.INDENT_ACTION);
- //
+ //
// action= new IndentAction(PHPEditorMessages.getResourceBundle(),
// "Indent.", this, true); //$NON-NLS-1$
// setAction("IndentOnTab", action); //$NON-NLS-1$
// markAsStateDependentAction("IndentOnTab", true); //$NON-NLS-1$
// markAsSelectionDependentAction("IndentOnTab", true); //$NON-NLS-1$
- //
+ //
action = new AddBlockCommentAction(PHPEditorMessages.getResourceBundle(), "AddBlockComment.", this); //$NON-NLS-1$
action.setActionDefinitionId(PHPEditorActionDefinitionIds.ADD_BLOCK_COMMENT);
setAction("AddBlockComment", action); //$NON-NLS-1$
markAsStateDependentAction("AddBlockComment", true); //$NON-NLS-1$
- markAsSelectionDependentAction("AddBlockComment", true); //$NON-NLS-1$
+ markAsSelectionDependentAction("AddBlockComment", true); //$NON-NLS-1$
// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.ADD_BLOCK_COMMENT_ACTION);
action = new RemoveBlockCommentAction(PHPEditorMessages.getResourceBundle(), "RemoveBlockComment.", this); //$NON-NLS-1$
action.setActionDefinitionId(PHPEditorActionDefinitionIds.REMOVE_BLOCK_COMMENT);
setAction("RemoveBlockComment", action); //$NON-NLS-1$
markAsStateDependentAction("RemoveBlockComment", true); //$NON-NLS-1$
- markAsSelectionDependentAction("RemoveBlockComment", true); //$NON-NLS-1$
+ markAsSelectionDependentAction("RemoveBlockComment", true); //$NON-NLS-1$
// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.REMOVE_BLOCK_COMMENT_ACTION);
// action= new IndentAction(PHPEditorMessages.getResourceBundle(), "Indent.", this, false); //$NON-NLS-1$
// markAsStateDependentAction("Indent", true); //$NON-NLS-1$
// markAsSelectionDependentAction("Indent", true); //$NON-NLS-1$
//// WorkbenchHelp.setHelp(action, IJavaHelpContextIds.INDENT_ACTION);
- //
+ //
action = new IndentAction(PHPEditorMessages.getResourceBundle(), "Indent.", this, true); //$NON-NLS-1$
setAction("IndentOnTab", action); //$NON-NLS-1$
markAsStateDependentAction("IndentOnTab", true); //$NON-NLS-1$
* Returns the most narrow element including the given offset. If <code>reconcile</code> is <code>true</code> the editor's
* input element is reconciled in advance. If it is <code>false</code> this method only returns a result if the editor's input
* element does not need to be reconciled.
- *
+ *
* @param offset
* the offset included by the retrieved element
* @param reconcile
/**
* Handles a property change event describing a change of the php core's preferences and updates the preference related editor
* properties.
- *
+ *
* @param event
* the property change event
*/
if (getPreferenceStore().getBoolean(PreferenceConstants.EDITOR_P_RTRIM_ON_SAVE)) {
RTrimAction trimAction = new RTrimAction();
trimAction.setActiveEditor(null, getSite().getPage().getActiveEditor());
- trimAction.run(null);
+ trimAction.run(null);
}
setStatusLineErrorMessage(null);
/**
* The compilation unit editor implementation of this <code>AbstractTextEditor</code> method asks the user for the workspace
* path of a file resource and saves the document there. See http://dev.eclipse.org/bugs/show_bug.cgi?id=6295
- *
+ *
* @param progressMonitor
* the progress monitor
*/
// IJavaElement inputElement= getInputJavaElement();
// if (model == null || inputElement == null)
// return;
- //
+ //
// fOverrideIndicatorManager= new OverrideIndicatorManager(model,
// inputElement, null);
// addReconcileListener(fOverrideIndicatorManager);
// }
// }
- //
+ //
// /*
// * @see
// net.sourceforge.phpdt.internal.ui.javaeditor.JavaEditor#uninstallOverrideIndicator()
/**
* Configures the toggle comment action
- *
+ *
* @since 3.0
*/
private void configureToggleCommentAction() {
/**
* Asks the user if it is ok to store in non-workbench encoding.
- *
+ *
* @return <true>if the user wants to continue
*/
private boolean askIfNonWorkbenchEncodingIsOk() {
// }
/**
* Tells whether this is the active editor in the active page.
- *
+ *
* @return <code>true</code> if this is the active editor in the active page
* @see IWorkbenchPage#getActiveEditor();
*/
/**
* Adds the given listener. Has no effect if an identical listener was not already registered.
- *
+ *
* @param listener
* The reconcile listener to be added
* @since 3.0
/**
* Removes the given listener. Has no effect if an identical listener was not already registered.
- *
+ *
* @param listener
* the reconcile listener to be removed
* @since 3.0
* <p>
* TODO remove once the underlying problem is solved.
* </p>
- *
+ *
* @return the lock reconcilers may use to synchronize on
*/
public Object getReconcilerLock() {
/*
* (non-Javadoc)
- *
+ *
* @see org.eclipse.ui.texteditor.AbstractTextEditor#editorSaved()
*/
protected void editorSaved() {