1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-16 13:35:22 +02:00

minor code cleanup

This commit is contained in:
Mike Kucera 2008-02-06 23:03:57 +00:00
parent e6ce9e4053
commit e885c18bc4
3 changed files with 22 additions and 53 deletions

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation and others. * Copyright (c) 2004, 2008 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 Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -16,62 +16,41 @@ import java.util.List;
import org.eclipse.cdt.core.parser.IToken; import org.eclipse.cdt.core.parser.IToken;
/** /**
*
* @author Doug Schaefer * @author Doug Schaefer
*/ */
public class ASTCompletionNode implements IASTCompletionNode { public class ASTCompletionNode implements IASTCompletionNode {
private IToken completionToken; private final IToken completionToken;
private final List<IASTName> names = new ArrayList<IASTName>();
private List names = new ArrayList(); private final IASTTranslationUnit translationUnit;
private IASTTranslationUnit translationUnit;
/**
* Only constructor.
*
* @param completionToken the completion token
* @param translationUnit the translation unit for this completion
*/
public ASTCompletionNode(IToken completionToken, IASTTranslationUnit translationUnit) { public ASTCompletionNode(IToken completionToken, IASTTranslationUnit translationUnit) {
this.completionToken = completionToken; this.completionToken = completionToken;
this.translationUnit = translationUnit; this.translationUnit = translationUnit;
} }
/**
* Add a name to node.
*
* @param name
*/
public void addName(IASTName name) { public void addName(IASTName name) {
names.add(name); names.add(name);
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTCompletionNode#getPrefix()
*/
public String getPrefix() { public String getPrefix() {
return completionToken.getType() != IToken.tEOC ? completionToken.getImage() : ""; //$NON-NLS-1$ return completionToken.getType() == IToken.tEOC ? "" : completionToken.getImage(); //$NON-NLS-1$
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTCompletionNode#getLength()
*/
public int getLength() { public int getLength() {
return completionToken.getLength(); return completionToken.getLength();
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTCompletionNode#getNames()
*/
public IASTName[] getNames() { public IASTName[] getNames() {
return (IASTName[]) names.toArray(new IASTName[names.size()]); return names.toArray(new IASTName[names.size()]);
} }
/* (non-Javadoc)
* @see org.eclipse.cdt.core.dom.ast.IASTCompletionNode#getTranslationUnit()
*/
public IASTTranslationUnit getTranslationUnit() { public IASTTranslationUnit getTranslationUnit() {
return translationUnit; return translationUnit;
} }

View file

@ -151,16 +151,14 @@ public abstract class AbstractCLikeLanguage extends AbstractLanguage implements
* @return an instance of ISourceCodeParser * @return an instance of ISourceCodeParser
*/ */
protected ISourceCodeParser createParser(IScanner scanner, IParserLogService log, IIndex index, boolean forCompletion, int options) { protected ISourceCodeParser createParser(IScanner scanner, IParserLogService log, IIndex index, boolean forCompletion, int options) {
ParserMode mode= null; ParserMode mode;
if (forCompletion) { if(forCompletion)
mode= ParserMode.COMPLETION_PARSE; mode= ParserMode.COMPLETION_PARSE;
} else if((options & OPTION_SKIP_FUNCTION_BODIES) != 0)
else if ((options & OPTION_SKIP_FUNCTION_BODIES) != 0) {
mode= ParserMode.STRUCTURAL_PARSE; mode= ParserMode.STRUCTURAL_PARSE;
} else
else {
mode= ParserMode.COMPLETE_PARSE; mode= ParserMode.COMPLETE_PARSE;
}
return createParser(scanner, mode, log, index); return createParser(scanner, mode, log, index);
} }

View file

@ -127,10 +127,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
if (logService instanceof AbstractParserLogService) { if (logService instanceof AbstractParserLogService) {
return (AbstractParserLogService) logService; return (AbstractParserLogService) logService;
} }
else {
return new ParserLogServiceWrapper(logService); return new ParserLogServiceWrapper(logService);
} }
}
protected final void throwBacktrack(int offset, int length) throws BacktrackException { protected final void throwBacktrack(int offset, int length) throws BacktrackException {
++backtrackCount; ++backtrackCount;
@ -150,11 +148,8 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
// Use to create the completion node // Use to create the completion node
protected ASTCompletionNode createCompletionNode(IToken token) { protected ASTCompletionNode createCompletionNode(IToken token) {
// the preprocessor may deliver tokens for literals or header-names. // the preprocessor may deliver tokens for literals or header-names.
if (completionNode == null && token != null) if(completionNode == null && token != null && token.getType() == IToken.tCOMPLETION) {
switch(token.getType()) {
case IToken.tCOMPLETION:
completionNode = new ASTCompletionNode(token, getTranslationUnit()); completionNode = new ASTCompletionNode(token, getTranslationUnit());
break;
} }
return completionNode; return completionNode;
} }
@ -264,8 +259,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
protected static int parseCount = 0; protected static int parseCount = 0;
protected void handleOffsetLimitException( protected void handleOffsetLimitException(OffsetLimitReachedException exception) throws EndOfFileException {
OffsetLimitReachedException exception) throws EndOfFileException {
if (mode != ParserMode.COMPLETION_PARSE) if (mode != ParserMode.COMPLETION_PARSE)
throw new EndOfFileException(); throw new EndOfFileException();
createCompletionNode(exception.getFinalToken()); createCompletionNode(exception.getFinalToken());
@ -283,9 +277,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
* If there are no more tokens. * If there are no more tokens.
*/ */
protected IToken mark() throws EndOfFileException { protected IToken mark() throws EndOfFileException {
if (currToken == null) return currToken == null ? currToken = fetchToken() : currToken;
currToken = fetchToken();
return currToken;
} }
/** /**