mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
Code cleanup
This commit is contained in:
parent
54eba1ba20
commit
b7ca58a629
2 changed files with 26 additions and 62 deletions
|
@ -1009,23 +1009,23 @@ public final class CIndenter {
|
|||
/**
|
||||
* Test whether an identifier encountered during scanning is part of
|
||||
* a type declaration, by scanning backward and ignoring any identifiers, commas,
|
||||
* and colons until we hit <code>class</code>, <code>struct</code>, <code>union</code>,
|
||||
* and colons until we hit <code>class</code>, <code>struct</code>, <code>union</code>,
|
||||
* or <code>enum</code>. If any braces, semicolons, or parentheses are encountered,
|
||||
* this is not a type declaration.
|
||||
* this is not a type declaration.
|
||||
* @return the reference offset of the start of the statement
|
||||
*/
|
||||
private int matchTypeDeclaration() {
|
||||
while (true) {
|
||||
nextToken();
|
||||
if (fToken == Symbols.TokenIDENT
|
||||
if (fToken == Symbols.TokenIDENT
|
||||
|| fToken == Symbols.TokenCOMMA
|
||||
|| fToken == Symbols.TokenCOLON
|
||||
|| fToken == Symbols.TokenPUBLIC
|
||||
|| fToken == Symbols.TokenPUBLIC
|
||||
|| fToken == Symbols.TokenPROTECTED
|
||||
|| fToken == Symbols.TokenPRIVATE) {
|
||||
continue;
|
||||
}
|
||||
else if (fToken == Symbols.TokenCLASS
|
||||
else if (fToken == Symbols.TokenCLASS
|
||||
|| fToken == Symbols.TokenSTRUCT
|
||||
|| fToken == Symbols.TokenUNION
|
||||
|| fToken == Symbols.TokenENUM) {
|
||||
|
@ -1045,7 +1045,7 @@ public final class CIndenter {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test whether the colon at the current position marks a case statement
|
||||
* Test whether the colon at the current position marks a case statement
|
||||
*
|
||||
* @return <code>true</code> if this looks like a case statement
|
||||
*/
|
||||
|
@ -1071,6 +1071,7 @@ public final class CIndenter {
|
|||
case Symbols.TokenCASE:
|
||||
return true;
|
||||
}
|
||||
break;
|
||||
case Symbols.TokenDEFAULT:
|
||||
return true;
|
||||
}
|
||||
|
@ -1078,7 +1079,7 @@ public final class CIndenter {
|
|||
}
|
||||
|
||||
/**
|
||||
* Test whether the colon at the current position marks a type inheritance decl.
|
||||
* Test whether the colon at the current position marks a type inheritance decl.
|
||||
*
|
||||
* @return <code>true</code> if this looks like a a type inheritance decl
|
||||
*/
|
||||
|
@ -1205,6 +1206,7 @@ public final class CIndenter {
|
|||
case Symbols.TokenRPAREN:
|
||||
if (isInBlock)
|
||||
mayBeMethodBody= READ_PARENS;
|
||||
// fall thru
|
||||
case Symbols.TokenRBRACKET:
|
||||
case Symbols.TokenGREATERTHAN:
|
||||
pos= fPreviousPos;
|
||||
|
@ -1281,6 +1283,7 @@ public final class CIndenter {
|
|||
if (previous == Symbols.TokenIDENT) {
|
||||
return false;
|
||||
}
|
||||
// fall thru
|
||||
case Symbols.TokenDOUBLECOLON:
|
||||
case Symbols.TokenOTHER:
|
||||
continue;
|
||||
|
@ -1353,8 +1356,8 @@ public final class CIndenter {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns as a reference any previous access specifiers (<code>public</code>,
|
||||
* <code>protected</code> or <code>default</code>) or the offset of the brace that
|
||||
* Returns as a reference any previous access specifiers (<code>public</code>,
|
||||
* <code>protected</code> or <code>default</code>) or the offset of the brace that
|
||||
* scopes the class body.
|
||||
* Sets <code>fIndent</code> to <code>prefAccessSpecifierIndent</code> upon
|
||||
* a match.
|
||||
|
@ -1491,6 +1494,7 @@ public final class CIndenter {
|
|||
case Symbols.TokenIDENT:
|
||||
if (!isGenericStarter(getTokenContent()))
|
||||
break;
|
||||
// fall thru
|
||||
case Symbols.TokenQUESTIONMARK:
|
||||
case Symbols.TokenGREATERTHAN:
|
||||
if (skipScope(Symbols.TokenLESSTHAN, Symbols.TokenGREATERTHAN))
|
||||
|
@ -1660,7 +1664,7 @@ public final class CIndenter {
|
|||
|
||||
/**
|
||||
* Returns <code>true</code> if the next token received after calling
|
||||
* <code>nextToken</code> is either an equal sign, an opening brace,
|
||||
* <code>nextToken</code> is either an equal sign, an opening brace,
|
||||
* a comma or an array designator ('[]').
|
||||
*
|
||||
* @return <code>true</code> if the next elements look like the start of an array definition
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2005, 2007 IBM Corporation and others.
|
||||
* Copyright (c) 2005, 2008 IBM Corporation and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -26,20 +26,16 @@ import org.eclipse.ui.texteditor.ITextEditor;
|
|||
import org.eclipse.cdt.core.dom.ast.IASTTranslationUnit;
|
||||
import org.eclipse.cdt.core.index.IIndex;
|
||||
import org.eclipse.cdt.core.model.CModelException;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.model.IWorkingCopy;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.IWorkingCopyManager;
|
||||
|
||||
import org.eclipse.cdt.internal.core.model.CModelManager;
|
||||
|
||||
|
||||
public class CReconcilingStrategy implements IReconcilingStrategy, IReconcilingStrategyExtension {
|
||||
|
||||
private ITextEditor fEditor;
|
||||
private ITextEditor fEditor;
|
||||
private IWorkingCopyManager fManager;
|
||||
private IProgressMonitor fProgressMonitor;
|
||||
private String txt = null;
|
||||
// used by tests
|
||||
protected boolean fInitialProcessDone;
|
||||
|
||||
|
@ -52,7 +48,14 @@ public class CReconcilingStrategy implements IReconcilingStrategy, IReconcilingS
|
|||
* @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#setDocument(org.eclipse.jface.text.IDocument)
|
||||
*/
|
||||
public void setDocument(IDocument document) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#reconcile(org.eclipse.jface.text.reconciler.DirtyRegion, org.eclipse.jface.text.IRegion)
|
||||
*/
|
||||
public void reconcile(DirtyRegion dirtyRegion, IRegion subRegion) {
|
||||
// only called for incremental reconciler
|
||||
}
|
||||
|
||||
/*
|
||||
* @see IReconcilingStrategyExtension#setProgressMonitor(IProgressMonitor)
|
||||
|
@ -68,50 +71,6 @@ public class CReconcilingStrategy implements IReconcilingStrategy, IReconcilingS
|
|||
reconcile(false);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* @see org.eclipse.jface.text.reconciler.IReconcilingStrategy#reconcile(org.eclipse.jface.text.reconciler.DirtyRegion, org.eclipse.jface.text.IRegion)
|
||||
* Called for incremental reconciler only - currently not used (no shift deltas)
|
||||
*/
|
||||
public void reconcile(DirtyRegion dirtyRegion, IRegion region) {
|
||||
// consistent data needs not further checks !
|
||||
ITranslationUnit tu = fManager.getWorkingCopy(fEditor.getEditorInput());
|
||||
if (tu != null && tu.isWorkingCopy()) {
|
||||
try {
|
||||
if (tu.isConsistent()) return;
|
||||
} catch (CModelException e) {}
|
||||
}
|
||||
|
||||
// bug 113518
|
||||
// local data needs not to be re-parsed
|
||||
boolean needReconcile = true;
|
||||
int dOff = dirtyRegion.getOffset();
|
||||
int dLen = dirtyRegion.getLength();
|
||||
IDocument doc = fEditor.getDocumentProvider().getDocument(fEditor.getEditorInput());
|
||||
|
||||
if ((doc != null) && (!CWordFinder.isGlobal(doc, dOff))) {
|
||||
String s = ""; //$NON-NLS-1$
|
||||
if (dirtyRegion.getType().charAt(2) == 'i') { // insert operation
|
||||
s = dirtyRegion.getText();
|
||||
if (!CWordFinder.hasCBraces(s)) {
|
||||
CModelManager.getDefault().fireShift(tu, dOff, dLen, CWordFinder.countLFs(s));
|
||||
needReconcile = false;
|
||||
}
|
||||
} else { // remove operation
|
||||
// check whether old document copy is relevant
|
||||
if (txt != null && (txt.length() == doc.getLength() + dLen)) {
|
||||
s = txt.substring(dOff, dOff + dLen);
|
||||
if (!CWordFinder.hasCBraces(s)) {
|
||||
CModelManager.getDefault().fireShift(tu, dOff, -dLen, -CWordFinder.countLFs(s));
|
||||
needReconcile = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (needReconcile) reconcile(false);
|
||||
txt = doc.get(); // save doc copy for further use
|
||||
}
|
||||
|
||||
private void reconcile(final boolean initialReconcile) {
|
||||
boolean computeAST= fEditor instanceof ICReconcilingListener;
|
||||
IASTTranslationUnit ast= null;
|
||||
|
@ -172,5 +131,6 @@ public class CReconcilingStrategy implements IReconcilingStrategy, IReconcilingS
|
|||
if (fEditor instanceof ICReconcilingListener) {
|
||||
((ICReconcilingListener)fEditor).aboutToBeReconciled();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue