mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 17:26:01 +02:00
2005-03-20 Alain Magloire
Fix for 77978. * src/org/eclipse/cdt/internal/ui/actions/AddBlockCommentAction.java * src/org/eclipse/cdt/internal/ui/text/CAutoIndentStrategy.java * src/org/eclipse/cdt/internal/ui/text/CCommentAutoIndenStrategy.java * src/org/eclipse/cdt/internal/ui/text/CPartitionScanner.java * src/org/eclipse/cdt/internal/ui/text/CSourceViewerConfiguration.java * src/org/eclipse/cdt/internal/ui/text/CTextTools.java * src/org/eclipse/cdt/internal/ui/text/FastCPartionScanner.java * src/org/eclipse/cdt/internal/ui/text/ICPartitions.java
This commit is contained in:
parent
3e1e0bb9e2
commit
697521bcd1
9 changed files with 113 additions and 205 deletions
|
@ -1,3 +1,14 @@
|
||||||
|
2005-03-20 Alain Magloire
|
||||||
|
Fix for 77978.
|
||||||
|
* src/org/eclipse/cdt/internal/ui/actions/AddBlockCommentAction.java
|
||||||
|
* src/org/eclipse/cdt/internal/ui/text/CAutoIndentStrategy.java
|
||||||
|
* src/org/eclipse/cdt/internal/ui/text/CCommentAutoIndenStrategy.java
|
||||||
|
* src/org/eclipse/cdt/internal/ui/text/CPartitionScanner.java
|
||||||
|
* src/org/eclipse/cdt/internal/ui/text/CSourceViewerConfiguration.java
|
||||||
|
* src/org/eclipse/cdt/internal/ui/text/CTextTools.java
|
||||||
|
* src/org/eclipse/cdt/internal/ui/text/FastCPartionScanner.java
|
||||||
|
* src/org/eclipse/cdt/internal/ui/text/ICPartitions.java
|
||||||
|
|
||||||
2005-03-18 David Inglis
|
2005-03-18 David Inglis
|
||||||
|
|
||||||
Fixed problem with error tick in CView not updateing properly.
|
Fixed problem with error tick in CView not updateing properly.
|
||||||
|
|
|
@ -109,18 +109,9 @@ public class AddBlockCommentAction extends BlockCommentAction {
|
||||||
int partEndOffset= partition.getOffset() + partition.getLength();
|
int partEndOffset= partition.getOffset() + partition.getLength();
|
||||||
int tokenLength= getCommentStart().length();
|
int tokenLength= getCommentStart().length();
|
||||||
|
|
||||||
/*boolean wasJavadoc= false; // true if the previous partition is javadoc
|
|
||||||
|
|
||||||
if (partType == IJavaPartitions.JAVA_DOC) {
|
|
||||||
|
|
||||||
wasJavadoc= true;
|
|
||||||
|
|
||||||
} else*/
|
|
||||||
if (partType == ICPartitions.C_MULTILINE_COMMENT) {
|
if (partType == ICPartitions.C_MULTILINE_COMMENT) {
|
||||||
|
|
||||||
// already in a comment - remove ending mark
|
// already in a comment - remove ending mark
|
||||||
edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$
|
edits.add(factory.createEdit(partEndOffset - tokenLength, tokenLength, "")); //$NON-NLS-1$
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// advance to next partition
|
// advance to next partition
|
||||||
|
@ -128,25 +119,10 @@ public class AddBlockCommentAction extends BlockCommentAction {
|
||||||
partType= partition.getType();
|
partType= partition.getType();
|
||||||
|
|
||||||
// start of next partition
|
// start of next partition
|
||||||
// if (wasJavadoc) {
|
if (partType == ICPartitions.C_MULTILINE_COMMENT) {
|
||||||
//
|
|
||||||
// // if previous was javadoc, and the current one is not, then add block comment start
|
|
||||||
// if (partType == IDocument.DEFAULT_CONTENT_TYPE
|
|
||||||
// || isSpecialPartition(partType)) {
|
|
||||||
// edits.add(factory.createEdit(partition.getOffset(), 0, getCommentStart()));
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// } else { // !wasJavadoc
|
|
||||||
|
|
||||||
/*if (partType == IJavaPartitions.JAVA_DOC) {
|
|
||||||
// if next is javadoc, end block comment before
|
|
||||||
edits.add(factory.createEdit(partition.getOffset(), 0, getCommentEnd()));
|
|
||||||
} else*/ if (partType == ICPartitions.C_MULTILINE_COMMENT) {
|
|
||||||
// already in a comment - remove startToken
|
// already in a comment - remove startToken
|
||||||
edits.add(factory.createEdit(partition.getOffset(), getCommentStart().length(), "")); //$NON-NLS-1$
|
edits.add(factory.createEdit(partition.getOffset(), getCommentStart().length(), "")); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
// }
|
|
||||||
|
|
||||||
return partition;
|
return partition;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -180,8 +156,8 @@ public class AddBlockCommentAction extends BlockCommentAction {
|
||||||
* @return <code>true</code> if <code>partType</code> is special, <code>false</code> otherwise
|
* @return <code>true</code> if <code>partType</code> is special, <code>false</code> otherwise
|
||||||
*/
|
*/
|
||||||
private boolean isSpecialPartition(String partType) {
|
private boolean isSpecialPartition(String partType) {
|
||||||
return /*partType == IJavaPartitions.JAVA_CHARACTER
|
return partType == ICPartitions.C_CHARACTER
|
||||||
|| */partType == ICPartitions.C_STRING
|
|| partType == ICPartitions.C_STRING
|
||||||
|| partType == ICPartitions.C_SINGLE_LINE_COMMENT;
|
|| partType == ICPartitions.C_SINGLE_LINE_COMMENT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ package org.eclipse.cdt.internal.ui.text;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.eclipse.jface.text.BadLocationException;
|
import org.eclipse.jface.text.BadLocationException;
|
||||||
import org.eclipse.jface.text.DefaultAutoIndentStrategy;
|
import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy;
|
||||||
import org.eclipse.jface.text.DocumentCommand;
|
import org.eclipse.jface.text.DocumentCommand;
|
||||||
import org.eclipse.jface.text.IDocument;
|
import org.eclipse.jface.text.IDocument;
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
/**
|
/**
|
||||||
* Auto indent strategy sensitive to brackets.
|
* Auto indent strategy sensitive to brackets.
|
||||||
*/
|
*/
|
||||||
public class CAutoIndentStrategy extends DefaultAutoIndentStrategy {
|
public class CAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
|
||||||
|
|
||||||
|
|
||||||
public CAutoIndentStrategy() {
|
public CAutoIndentStrategy() {
|
||||||
|
@ -114,9 +114,8 @@ public class CAutoIndentStrategy extends DefaultAutoIndentStrategy {
|
||||||
int end= start + d.getLineLength(line) - 1;
|
int end= start + d.getLineLength(line) - 1;
|
||||||
int whiteend= findEndOfWhiteSpace(d, start, end);
|
int whiteend= findEndOfWhiteSpace(d, start, end);
|
||||||
return d.get(start, whiteend - start);
|
return d.get(start, whiteend - start);
|
||||||
} else {
|
|
||||||
return ""; //$NON-NLS-1$
|
|
||||||
}
|
}
|
||||||
|
return ""; //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getStringEnd(IDocument d, int pos, int end, char ch) throws BadLocationException {
|
private int getStringEnd(IDocument d, int pos, int end, char ch) throws BadLocationException {
|
||||||
|
|
|
@ -6,7 +6,7 @@ package org.eclipse.cdt.internal.ui.text;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import org.eclipse.jface.text.BadLocationException;
|
import org.eclipse.jface.text.BadLocationException;
|
||||||
import org.eclipse.jface.text.DefaultAutoIndentStrategy;
|
import org.eclipse.jface.text.DefaultIndentLineAutoEditStrategy;
|
||||||
import org.eclipse.jface.text.DocumentCommand;
|
import org.eclipse.jface.text.DocumentCommand;
|
||||||
import org.eclipse.jface.text.IDocument;
|
import org.eclipse.jface.text.IDocument;
|
||||||
import org.eclipse.jface.text.IRegion;
|
import org.eclipse.jface.text.IRegion;
|
||||||
|
@ -14,7 +14,7 @@ import org.eclipse.jface.text.IRegion;
|
||||||
/**
|
/**
|
||||||
* Auto indent strategy for java doc comments
|
* Auto indent strategy for java doc comments
|
||||||
*/
|
*/
|
||||||
public class CCommentAutoIndentStrategy extends DefaultAutoIndentStrategy {
|
public class CCommentAutoIndentStrategy extends DefaultIndentLineAutoEditStrategy {
|
||||||
|
|
||||||
public CCommentAutoIndentStrategy() {
|
public CCommentAutoIndentStrategy() {
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,9 @@ import org.eclipse.jface.text.rules.WordRule;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This scanner recognizes comments
|
* This scanner is not actually use in the code it was relace by
|
||||||
|
* FastCPartitionScanner which was faster. We keep this around
|
||||||
|
* as a reference.
|
||||||
*/
|
*/
|
||||||
public class CPartitionScanner extends RuleBasedPartitionScanner implements ICPartitions {
|
public class CPartitionScanner extends RuleBasedPartitionScanner implements ICPartitions {
|
||||||
|
|
||||||
|
@ -85,6 +87,7 @@ public class CPartitionScanner extends RuleBasedPartitionScanner implements ICPa
|
||||||
IToken comment= new Token(C_MULTILINE_COMMENT);
|
IToken comment= new Token(C_MULTILINE_COMMENT);
|
||||||
IToken single_comment= new Token(C_SINGLE_LINE_COMMENT);
|
IToken single_comment= new Token(C_SINGLE_LINE_COMMENT);
|
||||||
IToken string= new Token(C_STRING);
|
IToken string= new Token(C_STRING);
|
||||||
|
IToken character = new Token(C_CHARACTER);
|
||||||
IToken skip= new Token(SKIP);
|
IToken skip= new Token(SKIP);
|
||||||
|
|
||||||
|
|
||||||
|
@ -97,12 +100,13 @@ public class CPartitionScanner extends RuleBasedPartitionScanner implements ICPa
|
||||||
|
|
||||||
|
|
||||||
// Add rule for single line comments.
|
// Add rule for single line comments.
|
||||||
rules.add(new EndOfLineRule("//", single_comment)); //$NON-NLS-1$
|
rules.add(new EndOfLineRule("//", single_comment, '\\', true)); //$NON-NLS-1$
|
||||||
|
|
||||||
|
|
||||||
// Add rule for strings and character constants.
|
// Add rule for string constants.
|
||||||
rules.add(new SingleLineRule("\"", "\"", string, '\\')); //$NON-NLS-1$ //$NON-NLS-2$
|
rules.add(new SingleLineRule("\"", "\"", string, '\\', false, true)); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
rules.add(new SingleLineRule("'", "'", skip, '\\')); //$NON-NLS-1$ //$NON-NLS-2$
|
// Add rule for character constants
|
||||||
|
rules.add(new SingleLineRule("'", "'", character, '\\')); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
|
|
||||||
// Add special case word rule.
|
// Add special case word rule.
|
||||||
EmptyCommentRule wordRule= new EmptyCommentRule(comment);
|
EmptyCommentRule wordRule= new EmptyCommentRule(comment);
|
||||||
|
|
|
@ -19,7 +19,7 @@ import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
import org.eclipse.jface.dialogs.IDialogSettings;
|
import org.eclipse.jface.dialogs.IDialogSettings;
|
||||||
import org.eclipse.jface.preference.IPreferenceStore;
|
import org.eclipse.jface.preference.IPreferenceStore;
|
||||||
import org.eclipse.jface.text.DefaultInformationControl;
|
import org.eclipse.jface.text.DefaultInformationControl;
|
||||||
import org.eclipse.jface.text.IAutoIndentStrategy;
|
import org.eclipse.jface.text.IAutoEditStrategy;
|
||||||
import org.eclipse.jface.text.IDocument;
|
import org.eclipse.jface.text.IDocument;
|
||||||
import org.eclipse.jface.text.IInformationControl;
|
import org.eclipse.jface.text.IInformationControl;
|
||||||
import org.eclipse.jface.text.IInformationControlCreator;
|
import org.eclipse.jface.text.IInformationControlCreator;
|
||||||
|
@ -121,6 +121,7 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
||||||
return fEditor;
|
return fEditor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates outline presenter.
|
* Creates outline presenter.
|
||||||
* @param editor Editor.
|
* @param editor Editor.
|
||||||
|
@ -171,13 +172,17 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
||||||
reconciler.setDamager(dr, ICPartitions.C_SINGLE_LINE_COMMENT);
|
reconciler.setDamager(dr, ICPartitions.C_SINGLE_LINE_COMMENT);
|
||||||
reconciler.setRepairer(dr, ICPartitions.C_SINGLE_LINE_COMMENT);
|
reconciler.setRepairer(dr, ICPartitions.C_SINGLE_LINE_COMMENT);
|
||||||
|
|
||||||
|
dr= new DefaultDamagerRepairer(getMultilineCommentScanner());
|
||||||
|
reconciler.setDamager(dr, ICPartitions.C_MULTILINE_COMMENT);
|
||||||
|
reconciler.setRepairer(dr, ICPartitions.C_MULTILINE_COMMENT);
|
||||||
|
|
||||||
dr= new DefaultDamagerRepairer(getStringScanner());
|
dr= new DefaultDamagerRepairer(getStringScanner());
|
||||||
reconciler.setDamager(dr, ICPartitions.C_STRING);
|
reconciler.setDamager(dr, ICPartitions.C_STRING);
|
||||||
reconciler.setRepairer(dr, ICPartitions.C_STRING);
|
reconciler.setRepairer(dr, ICPartitions.C_STRING);
|
||||||
|
|
||||||
dr= new DefaultDamagerRepairer(getMultilineCommentScanner());
|
dr= new DefaultDamagerRepairer(getStringScanner());
|
||||||
reconciler.setDamager(dr, ICPartitions.C_MULTILINE_COMMENT);
|
reconciler.setDamager(dr, ICPartitions.C_CHARACTER);
|
||||||
reconciler.setRepairer(dr, ICPartitions.C_MULTILINE_COMMENT);
|
reconciler.setRepairer(dr, ICPartitions.C_CHARACTER);
|
||||||
|
|
||||||
return reconciler;
|
return reconciler;
|
||||||
}
|
}
|
||||||
|
@ -232,18 +237,16 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
/**
|
* @see org.eclipse.jface.text.source.SourceViewerConfiguration#getAutoEditStrategies(org.eclipse.jface.text.source.ISourceViewer, java.lang.String)
|
||||||
* @see SourceViewerConfiguration#getAutoIndentStrategy(ISourceViewer, String)
|
|
||||||
*/
|
*/
|
||||||
public IAutoIndentStrategy getAutoIndentStrategy(ISourceViewer sourceViewer, String contentType) {
|
public IAutoEditStrategy[] getAutoEditStrategies(ISourceViewer sourceViewer, String contentType) {
|
||||||
if(ICPartitions.C_MULTILINE_COMMENT.equals(contentType)) {
|
if(ICPartitions.C_MULTILINE_COMMENT.equals(contentType)) {
|
||||||
return new CCommentAutoIndentStrategy();
|
return new IAutoEditStrategy[] {new CCommentAutoIndentStrategy()};
|
||||||
}
|
}
|
||||||
return new CAutoIndentStrategy();
|
return new IAutoEditStrategy[] {new CAutoIndentStrategy()};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see SourceViewerConfiguration#getDoubleClickStrategy(ISourceViewer, String)
|
* @see SourceViewerConfiguration#getDoubleClickStrategy(ISourceViewer, String)
|
||||||
*/
|
*/
|
||||||
|
@ -384,10 +387,12 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
||||||
* @see SourceViewerConfiguration#getConfiguredContentTypes(ISourceViewer)
|
* @see SourceViewerConfiguration#getConfiguredContentTypes(ISourceViewer)
|
||||||
*/
|
*/
|
||||||
public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
|
public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
|
||||||
return new String[] { IDocument.DEFAULT_CONTENT_TYPE,
|
return new String[] {
|
||||||
|
IDocument.DEFAULT_CONTENT_TYPE,
|
||||||
ICPartitions.C_MULTILINE_COMMENT,
|
ICPartitions.C_MULTILINE_COMMENT,
|
||||||
ICPartitions.C_SINGLE_LINE_COMMENT,
|
ICPartitions.C_SINGLE_LINE_COMMENT,
|
||||||
ICPartitions.C_STRING };
|
ICPartitions.C_STRING,
|
||||||
|
ICPartitions.C_CHARACTER};
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -428,6 +433,10 @@ public class CSourceViewerConfiguration extends TextSourceViewerConfiguration {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* @see SourceViewerConfiguration#getInformationPresenter(ISourceViewer)
|
||||||
|
* @since 2.0
|
||||||
|
*/
|
||||||
public IInformationPresenter getInformationPresenter(ISourceViewer sourceViewer) {
|
public IInformationPresenter getInformationPresenter(ISourceViewer sourceViewer) {
|
||||||
return super.getInformationPresenter(sourceViewer);
|
return super.getInformationPresenter(sourceViewer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,7 @@ import org.eclipse.jface.preference.IPreferenceStore;
|
||||||
import org.eclipse.jface.text.IDocument;
|
import org.eclipse.jface.text.IDocument;
|
||||||
import org.eclipse.jface.text.IDocumentExtension3;
|
import org.eclipse.jface.text.IDocumentExtension3;
|
||||||
import org.eclipse.jface.text.IDocumentPartitioner;
|
import org.eclipse.jface.text.IDocumentPartitioner;
|
||||||
import org.eclipse.jface.text.rules.DefaultPartitioner;
|
import org.eclipse.jface.text.rules.FastPartitioner;
|
||||||
import org.eclipse.jface.text.rules.IPartitionTokenScanner;
|
import org.eclipse.jface.text.rules.IPartitionTokenScanner;
|
||||||
import org.eclipse.jface.text.rules.RuleBasedScanner;
|
import org.eclipse.jface.text.rules.RuleBasedScanner;
|
||||||
import org.eclipse.jface.util.IPropertyChangeListener;
|
import org.eclipse.jface.util.IPropertyChangeListener;
|
||||||
|
@ -172,10 +172,11 @@ public class CTextTools {
|
||||||
String[] types= new String[] {
|
String[] types= new String[] {
|
||||||
ICPartitions.C_MULTILINE_COMMENT,
|
ICPartitions.C_MULTILINE_COMMENT,
|
||||||
ICPartitions.C_SINGLE_LINE_COMMENT,
|
ICPartitions.C_SINGLE_LINE_COMMENT,
|
||||||
ICPartitions.C_STRING
|
ICPartitions.C_STRING,
|
||||||
|
ICPartitions.C_CHARACTER
|
||||||
};
|
};
|
||||||
|
|
||||||
return new DefaultPartitioner(getPartitionScanner(), types);
|
return new FastPartitioner(getPartitionScanner(), types);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -29,10 +29,11 @@ public class FastCPartitionScanner implements IPartitionTokenScanner, ICPartitio
|
||||||
// beginning of prefixes and postfixes
|
// beginning of prefixes and postfixes
|
||||||
private static final int NONE= 0;
|
private static final int NONE= 0;
|
||||||
private static final int BACKSLASH= 1; // postfix for STRING and CHARACTER
|
private static final int BACKSLASH= 1; // postfix for STRING and CHARACTER
|
||||||
private static final int SLASH= 2; // prefix for SINGLE_LINE or MULTI_LINE or JAVADOC
|
private static final int SLASH= 2; // prefix for SINGLE_LINE or MULTI_LINE
|
||||||
private static final int SLASH_STAR= 3; // prefix for MULTI_LINE_COMMENT or JAVADOC
|
private static final int SLASH_STAR= 3; // prefix for MULTI_LINE_COMMENT
|
||||||
private static final int STAR= 4; // postfix for MULTI_LINE_COMMENT or JAVADOC
|
private static final int STAR= 4; // postfix for MULTI_LINE_COMMENT
|
||||||
private static final int CARRIAGE_RETURN=5; // postfix for STRING, CHARACTER and SINGLE_LINE_COMMENT
|
private static final int CARRIAGE_RETURN=5; // postfix for STRING, CHARACTER and SINGLE_LINE_COMMENT
|
||||||
|
private static final int ESCAPED_CR=6; // for win32 system where termination string is \r\n save the backslash
|
||||||
|
|
||||||
/** The scanner. */
|
/** The scanner. */
|
||||||
// private final BufferedRuleBasedScanner fScanner= new BufferedRuleBasedScanner(1000);
|
// private final BufferedRuleBasedScanner fScanner= new BufferedRuleBasedScanner(1000);
|
||||||
|
@ -50,16 +51,11 @@ public class FastCPartitionScanner implements IPartitionTokenScanner, ICPartitio
|
||||||
/** The amount of characters already read on first call to nextToken(). */
|
/** The amount of characters already read on first call to nextToken(). */
|
||||||
private int fPrefixLength;
|
private int fPrefixLength;
|
||||||
|
|
||||||
// emulate CPartitionScanner
|
|
||||||
private static final boolean fgEmulate= false;
|
|
||||||
private int fCOffset;
|
|
||||||
private int fCLength;
|
|
||||||
|
|
||||||
private final IToken[] fTokens= new IToken[] {
|
private final IToken[] fTokens= new IToken[] {
|
||||||
new Token(null),
|
new Token(null),
|
||||||
new Token(C_SINGLE_LINE_COMMENT),
|
new Token(C_SINGLE_LINE_COMMENT),
|
||||||
new Token(C_MULTILINE_COMMENT),
|
new Token(C_MULTILINE_COMMENT),
|
||||||
new Token(SKIP),
|
new Token(C_CHARACTER),
|
||||||
new Token(C_STRING)
|
new Token(C_STRING)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -67,17 +63,6 @@ public class FastCPartitionScanner implements IPartitionTokenScanner, ICPartitio
|
||||||
* @see org.eclipse.jface.text.rules.ITokenScanner#nextToken()
|
* @see org.eclipse.jface.text.rules.ITokenScanner#nextToken()
|
||||||
*/
|
*/
|
||||||
public IToken nextToken() {
|
public IToken nextToken() {
|
||||||
|
|
||||||
// emulate CPartitionScanner
|
|
||||||
if (fgEmulate) {
|
|
||||||
if (fCOffset != -1 && fTokenOffset + fTokenLength != fCOffset + fCLength) {
|
|
||||||
fTokenOffset += fTokenLength;
|
|
||||||
return fTokens[CCODE];
|
|
||||||
}
|
|
||||||
fCOffset= -1;
|
|
||||||
fCLength= 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
fTokenOffset += fTokenLength;
|
fTokenOffset += fTokenLength;
|
||||||
fTokenLength= fPrefixLength;
|
fTokenLength= fPrefixLength;
|
||||||
|
|
||||||
|
@ -97,109 +82,27 @@ public class FastCPartitionScanner implements IPartitionTokenScanner, ICPartitio
|
||||||
return Token.EOF;
|
return Token.EOF;
|
||||||
|
|
||||||
case '\r':
|
case '\r':
|
||||||
// emulate CPartitionScanner
|
fLast= (fLast == BACKSLASH) ? ESCAPED_CR : CARRIAGE_RETURN;
|
||||||
if (!fgEmulate && fLast != CARRIAGE_RETURN) {
|
|
||||||
fLast= CARRIAGE_RETURN;
|
|
||||||
fTokenLength++;
|
fTokenLength++;
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (fState) {
|
|
||||||
case SINGLE_LINE_COMMENT:
|
|
||||||
case CHARACTER:
|
|
||||||
case STRING:
|
|
||||||
if (fTokenLength > 0) {
|
|
||||||
IToken token= fTokens[fState];
|
|
||||||
|
|
||||||
// emulate CPartitionScanner
|
|
||||||
if (fgEmulate) {
|
|
||||||
fTokenLength++;
|
|
||||||
fLast= NONE;
|
|
||||||
fPrefixLength= 0;
|
|
||||||
} else {
|
|
||||||
fLast= CARRIAGE_RETURN;
|
|
||||||
fPrefixLength= 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
fState= CCODE;
|
|
||||||
return token;
|
|
||||||
|
|
||||||
}
|
|
||||||
consume();
|
|
||||||
continue;
|
|
||||||
|
|
||||||
default:
|
|
||||||
consume();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
case '\n':
|
case '\n':
|
||||||
switch (fState) {
|
switch (fState) {
|
||||||
case SINGLE_LINE_COMMENT:
|
case SINGLE_LINE_COMMENT:
|
||||||
case CHARACTER:
|
case CHARACTER:
|
||||||
case STRING:
|
//case STRING:
|
||||||
// assert(fTokenLength > 0);
|
// assert(fTokenLength > 0);
|
||||||
|
boolean escapedLine = (fLast == BACKSLASH || fLast == ESCAPED_CR);
|
||||||
|
if (!escapedLine) {
|
||||||
return postFix(fState);
|
return postFix(fState);
|
||||||
|
}
|
||||||
|
// FALLTHROUGH
|
||||||
|
|
||||||
default:
|
default:
|
||||||
consume();
|
consume();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
default:
|
|
||||||
if (!fgEmulate && fLast == CARRIAGE_RETURN) {
|
|
||||||
switch (fState) {
|
|
||||||
case SINGLE_LINE_COMMENT:
|
|
||||||
case CHARACTER:
|
|
||||||
case STRING:
|
|
||||||
|
|
||||||
int last;
|
|
||||||
int newState;
|
|
||||||
switch (ch) {
|
|
||||||
case '/':
|
|
||||||
last= SLASH;
|
|
||||||
newState= CCODE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '*':
|
|
||||||
last= STAR;
|
|
||||||
newState= CCODE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '\'':
|
|
||||||
last= NONE;
|
|
||||||
newState= CHARACTER;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '"':
|
|
||||||
last= NONE;
|
|
||||||
newState= STRING;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '\r':
|
|
||||||
last= CARRIAGE_RETURN;
|
|
||||||
newState= CCODE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case '\\':
|
|
||||||
last= BACKSLASH;
|
|
||||||
newState= CCODE;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
last= NONE;
|
|
||||||
newState= CCODE;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
fLast= NONE; // ignore fLast
|
|
||||||
return preFix(fState, newState, last, 1);
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// states
|
// states
|
||||||
|
@ -237,8 +140,9 @@ public class FastCPartitionScanner implements IPartitionTokenScanner, ICPartitio
|
||||||
|
|
||||||
case '\'':
|
case '\'':
|
||||||
fLast= NONE; // ignore fLast
|
fLast= NONE; // ignore fLast
|
||||||
if (fTokenLength > 0)
|
if (fTokenLength > 0) {
|
||||||
return preFix(CCODE, CHARACTER, NONE, 1);
|
return preFix(CCODE, CHARACTER, NONE, 1);
|
||||||
|
}
|
||||||
preFix(CCODE, CHARACTER, NONE, 1);
|
preFix(CCODE, CHARACTER, NONE, 1);
|
||||||
fTokenOffset += fTokenLength;
|
fTokenOffset += fTokenLength;
|
||||||
fTokenLength= fPrefixLength;
|
fTokenLength= fPrefixLength;
|
||||||
|
@ -246,11 +150,13 @@ public class FastCPartitionScanner implements IPartitionTokenScanner, ICPartitio
|
||||||
|
|
||||||
case '"':
|
case '"':
|
||||||
fLast= NONE; // ignore fLast
|
fLast= NONE; // ignore fLast
|
||||||
if (fTokenLength > 0)
|
if (fTokenLength > 0 ) {
|
||||||
return preFix(CCODE, STRING, NONE, 1);
|
return preFix(CCODE, STRING, NONE, 1);
|
||||||
|
}
|
||||||
preFix(CCODE, STRING, NONE, 1);
|
preFix(CCODE, STRING, NONE, 1);
|
||||||
fTokenOffset += fTokenLength;
|
fTokenOffset += fTokenLength;
|
||||||
fTokenLength= fPrefixLength;
|
fTokenLength= fPrefixLength;
|
||||||
|
consume();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
@ -260,8 +166,16 @@ public class FastCPartitionScanner implements IPartitionTokenScanner, ICPartitio
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SINGLE_LINE_COMMENT:
|
case SINGLE_LINE_COMMENT:
|
||||||
|
switch (ch) {
|
||||||
|
case '\\':
|
||||||
|
fLast= (fLast == BACKSLASH) ? NONE : BACKSLASH;
|
||||||
|
fTokenLength++;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
consume();
|
consume();
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
case MULTI_LINE_COMMENT:
|
case MULTI_LINE_COMMENT:
|
||||||
switch (ch) {
|
switch (ch) {
|
||||||
|
@ -362,18 +276,6 @@ public class FastCPartitionScanner implements IPartitionTokenScanner, ICPartitio
|
||||||
}
|
}
|
||||||
|
|
||||||
private final IToken preFix(int state, int newState, int last, int prefixLength) {
|
private final IToken preFix(int state, int newState, int last, int prefixLength) {
|
||||||
// emulate CPartitionScanner
|
|
||||||
if (fgEmulate && state == CCODE && (fTokenLength - getLastLength(fLast) > 0)) {
|
|
||||||
fTokenLength -= getLastLength(fLast);
|
|
||||||
fCOffset= fTokenOffset;
|
|
||||||
fCLength= fTokenLength;
|
|
||||||
fTokenLength= 1;
|
|
||||||
fState= newState;
|
|
||||||
fPrefixLength= prefixLength;
|
|
||||||
fLast= last;
|
|
||||||
return fTokens[state];
|
|
||||||
|
|
||||||
}
|
|
||||||
fTokenLength -= getLastLength(fLast);
|
fTokenLength -= getLastLength(fLast);
|
||||||
fLast= last;
|
fLast= last;
|
||||||
fPrefixLength= prefixLength;
|
fPrefixLength= prefixLength;
|
||||||
|
@ -396,7 +298,7 @@ public class FastCPartitionScanner implements IPartitionTokenScanner, ICPartitio
|
||||||
else if (contentType.equals(C_STRING))
|
else if (contentType.equals(C_STRING))
|
||||||
return STRING;
|
return STRING;
|
||||||
|
|
||||||
else if (contentType.equals(SKIP))
|
else if (contentType.equals(C_CHARACTER))
|
||||||
return CHARACTER;
|
return CHARACTER;
|
||||||
|
|
||||||
else
|
else
|
||||||
|
@ -421,11 +323,6 @@ public class FastCPartitionScanner implements IPartitionTokenScanner, ICPartitio
|
||||||
fState= getState(contentType);
|
fState= getState(contentType);
|
||||||
}
|
}
|
||||||
|
|
||||||
// emulate CPartitionScanner
|
|
||||||
if (fgEmulate) {
|
|
||||||
fCOffset= -1;
|
|
||||||
fCLength= 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -440,11 +337,6 @@ public class FastCPartitionScanner implements IPartitionTokenScanner, ICPartitio
|
||||||
fLast= NONE;
|
fLast= NONE;
|
||||||
fState= CCODE;
|
fState= CCODE;
|
||||||
|
|
||||||
// emulate CPartitionScanner
|
|
||||||
if (fgEmulate) {
|
|
||||||
fCOffset= -1;
|
|
||||||
fCLength= 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -18,9 +18,25 @@ package org.eclipse.cdt.internal.ui.text;
|
||||||
*/
|
*/
|
||||||
public interface ICPartitions {
|
public interface ICPartitions {
|
||||||
|
|
||||||
public final static String SKIP= "__skip"; //$NON-NLS-1$
|
String SKIP= "__skip"; //$NON-NLS-1$
|
||||||
public final static String C_MULTILINE_COMMENT= "c_multi_line_comment"; //$NON-NLS-1$
|
/**
|
||||||
public final static String C_SINGLE_LINE_COMMENT= "c_single_line_comment"; //$NON-NLS-1$
|
* The identifier multi-line (JLS2: TraditionalComment) comment partition content type.
|
||||||
public final static String C_STRING= "c_string"; //$NON-NLS-1$
|
*/
|
||||||
|
String C_MULTILINE_COMMENT= "c_multi_line_comment"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The identifier of the single-line (JLS2: EndOfLineComment) end comment partition content type.
|
||||||
|
*/
|
||||||
|
String C_SINGLE_LINE_COMMENT= "c_single_line_comment"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The identifier of the C string partition content type.
|
||||||
|
*/
|
||||||
|
String C_STRING= "c_string"; //$NON-NLS-1$
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The identifier of the C character partition content type.
|
||||||
|
*/
|
||||||
|
String C_CHARACTER= "c_character"; //$NON-NLS-1$
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue