mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-01 06:05:24 +02:00
minor code cleanup
This commit is contained in:
parent
e6ce9e4053
commit
e885c18bc4
3 changed files with 22 additions and 53 deletions
|
@ -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
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
|
@ -16,62 +16,41 @@ import java.util.List;
|
|||
import org.eclipse.cdt.core.parser.IToken;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Doug Schaefer
|
||||
*/
|
||||
public class ASTCompletionNode implements IASTCompletionNode {
|
||||
|
||||
private IToken completionToken;
|
||||
|
||||
private List names = new ArrayList();
|
||||
|
||||
private IASTTranslationUnit translationUnit;
|
||||
private final IToken completionToken;
|
||||
private final List<IASTName> names = new ArrayList<IASTName>();
|
||||
private final IASTTranslationUnit translationUnit;
|
||||
|
||||
|
||||
/**
|
||||
* Only constructor.
|
||||
*
|
||||
* @param completionToken the completion token
|
||||
* @param translationUnit the translation unit for this completion
|
||||
*/
|
||||
public ASTCompletionNode(IToken completionToken, IASTTranslationUnit translationUnit) {
|
||||
this.completionToken = completionToken;
|
||||
this.translationUnit = translationUnit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a name to node.
|
||||
*
|
||||
* @param name
|
||||
*/
|
||||
|
||||
public void addName(IASTName name) {
|
||||
names.add(name);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IASTCompletionNode#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() {
|
||||
return completionToken.getLength();
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.dom.ast.IASTCompletionNode#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() {
|
||||
return translationUnit;
|
||||
}
|
||||
|
|
|
@ -151,16 +151,14 @@ public abstract class AbstractCLikeLanguage extends AbstractLanguage implements
|
|||
* @return an instance of ISourceCodeParser
|
||||
*/
|
||||
protected ISourceCodeParser createParser(IScanner scanner, IParserLogService log, IIndex index, boolean forCompletion, int options) {
|
||||
ParserMode mode= null;
|
||||
if (forCompletion) {
|
||||
ParserMode mode;
|
||||
if(forCompletion)
|
||||
mode= ParserMode.COMPLETION_PARSE;
|
||||
}
|
||||
else if ((options & OPTION_SKIP_FUNCTION_BODIES) != 0) {
|
||||
else if((options & OPTION_SKIP_FUNCTION_BODIES) != 0)
|
||||
mode= ParserMode.STRUCTURAL_PARSE;
|
||||
}
|
||||
else {
|
||||
else
|
||||
mode= ParserMode.COMPLETE_PARSE;
|
||||
}
|
||||
|
||||
return createParser(scanner, mode, log, index);
|
||||
}
|
||||
|
||||
|
|
|
@ -127,9 +127,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
if (logService instanceof AbstractParserLogService) {
|
||||
return (AbstractParserLogService) logService;
|
||||
}
|
||||
else {
|
||||
return new ParserLogServiceWrapper(logService);
|
||||
}
|
||||
return new ParserLogServiceWrapper(logService);
|
||||
}
|
||||
|
||||
protected final void throwBacktrack(int offset, int length) throws BacktrackException {
|
||||
|
@ -150,12 +148,9 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
// Use to create the completion node
|
||||
protected ASTCompletionNode createCompletionNode(IToken token) {
|
||||
// the preprocessor may deliver tokens for literals or header-names.
|
||||
if (completionNode == null && token != null)
|
||||
switch(token.getType()) {
|
||||
case IToken.tCOMPLETION:
|
||||
completionNode = new ASTCompletionNode(token, getTranslationUnit());
|
||||
break;
|
||||
}
|
||||
if(completionNode == null && token != null && token.getType() == IToken.tCOMPLETION) {
|
||||
completionNode = new ASTCompletionNode(token, getTranslationUnit());
|
||||
}
|
||||
return completionNode;
|
||||
}
|
||||
|
||||
|
@ -264,8 +259,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
|
||||
protected static int parseCount = 0;
|
||||
|
||||
protected void handleOffsetLimitException(
|
||||
OffsetLimitReachedException exception) throws EndOfFileException {
|
||||
protected void handleOffsetLimitException(OffsetLimitReachedException exception) throws EndOfFileException {
|
||||
if (mode != ParserMode.COMPLETION_PARSE)
|
||||
throw new EndOfFileException();
|
||||
createCompletionNode(exception.getFinalToken());
|
||||
|
@ -283,9 +277,7 @@ public abstract class AbstractGNUSourceCodeParser implements ISourceCodeParser {
|
|||
* If there are no more tokens.
|
||||
*/
|
||||
protected IToken mark() throws EndOfFileException {
|
||||
if (currToken == null)
|
||||
currToken = fetchToken();
|
||||
return currToken;
|
||||
return currToken == null ? currToken = fetchToken() : currToken;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Reference in a new issue