mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Changed CModelBuilder & CompletionEngine to use buffered input streams rather than String/CharArray Readers
This commit is contained in:
parent
b87794dd73
commit
a3179774f5
5 changed files with 34 additions and 27 deletions
|
@ -10,7 +10,7 @@
|
|||
******************************************************************************/
|
||||
package org.eclipse.cdt.internal.core.model;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.io.Reader;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
@ -61,6 +61,7 @@ import org.eclipse.cdt.core.parser.ast.IASTVariable;
|
|||
import org.eclipse.cdt.internal.core.parser.ParserException;
|
||||
import org.eclipse.cdt.internal.core.parser.util.ASTUtil;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
|
||||
|
||||
public class CModelBuilder {
|
||||
|
@ -81,7 +82,6 @@ public class CModelBuilder {
|
|||
{
|
||||
IProject currentProject = null;
|
||||
boolean hasCppNature = true;
|
||||
String code = ""; //$NON-NLS-1$
|
||||
|
||||
// get the current project
|
||||
if (translationUnit != null && translationUnit.getCProject() != null) {
|
||||
|
@ -92,11 +92,11 @@ public class CModelBuilder {
|
|||
{
|
||||
hasCppNature = CoreModel.hasCCNature(currentProject);
|
||||
}
|
||||
// get the code to parse
|
||||
try{
|
||||
code = translationUnit.getBuffer().getContents();
|
||||
} catch (CModelException e) {
|
||||
|
||||
|
||||
Reader reader = null;
|
||||
try {
|
||||
reader = ParserUtil.createResourceReader( translationUnit.getResource() );
|
||||
} catch (CoreException e) {
|
||||
}
|
||||
// use quick or structural parse mode
|
||||
ParserMode mode = quickParseMode ? ParserMode.QUICK_PARSE : ParserMode.STRUCTURAL_PARSE;
|
||||
|
@ -124,7 +124,7 @@ public class CModelBuilder {
|
|||
|
||||
parser = ParserFactory.createParser(
|
||||
ParserFactory.createScanner(
|
||||
new StringReader( code ),
|
||||
reader,
|
||||
(translationUnit.getUnderlyingResource() != null ?
|
||||
translationUnit.getUnderlyingResource().getLocation().toOSString() :
|
||||
""), //$NON-NLS-1$
|
||||
|
|
|
@ -231,7 +231,7 @@ public abstract class AbstractToken implements IToken, ITokenDuple {
|
|||
* @see org.eclipse.cdt.core.parser.ITokenDuple#getStartOffset()
|
||||
*/
|
||||
public int getStartOffset() {
|
||||
return 0;
|
||||
return getOffset();
|
||||
}
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.cdt.core.parser.ITokenDuple#getSubrange(int, int)
|
||||
|
|
|
@ -110,9 +110,9 @@ public class TokenDuple implements ITokenDuple {
|
|||
if( args != null && args[ args.length - 1 ] != null ){
|
||||
List newArgs = new ArrayList( 1 );
|
||||
newArgs.add( args[ args.length - 1 ] );
|
||||
return new TokenDuple( first, last, newArgs );
|
||||
return TokenFactory.createTokenDuple( first, last, newArgs );
|
||||
}
|
||||
return new TokenDuple( first, last );
|
||||
return TokenFactory.createTokenDuple( first, last );
|
||||
|
||||
}
|
||||
|
||||
|
@ -157,9 +157,9 @@ public class TokenDuple implements ITokenDuple {
|
|||
if( args[i] != null )
|
||||
foundArgs = true;
|
||||
}
|
||||
return new TokenDuple( first, last, ( foundArgs ? newArgs : null ) );
|
||||
return TokenFactory.createTokenDuple( first, last, ( foundArgs ? newArgs : null ) );
|
||||
}
|
||||
return new TokenDuple( first, last );
|
||||
return TokenFactory.createTokenDuple( first, last );
|
||||
}
|
||||
|
||||
public int getSegmentCount()
|
||||
|
@ -329,7 +329,7 @@ public class TokenDuple implements ITokenDuple {
|
|||
*/
|
||||
public ITokenDuple getSubrange(int startIndex, int endIndex)
|
||||
{
|
||||
return new TokenDuple( getToken( startIndex ), getToken( endIndex) );
|
||||
return TokenFactory.createTokenDuple( getToken( startIndex ), getToken( endIndex) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -68,9 +68,7 @@ public class ParserUtil
|
|||
Reader r = findWorkingCopy( resultingResource, workingCopies );
|
||||
if( r != null ) return r;
|
||||
}
|
||||
BufferedInputStream bufferedStream = new BufferedInputStream( ((IFile) resultingResource).getContents() );
|
||||
InputStreamReader inputReader = new InputStreamReader( bufferedStream );
|
||||
return new BufferedReader( inputReader );
|
||||
return createResourceReader(resultingResource);
|
||||
}
|
||||
}
|
||||
catch( CoreException ce )
|
||||
|
@ -79,6 +77,15 @@ public class ParserUtil
|
|||
return InternalParserUtil.createFileReader(finalPath);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param resource
|
||||
* @return
|
||||
* @throws CoreException
|
||||
*/
|
||||
public static BufferedReader createResourceReader(IResource resource) throws CoreException {
|
||||
return new BufferedReader( new InputStreamReader( new BufferedInputStream( ((IFile) resource).getContents() ) ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @param finalPath
|
||||
* @return
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
**********************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.text.contentassist;
|
||||
|
||||
import java.io.CharArrayReader;
|
||||
import java.io.Reader;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
@ -66,6 +65,7 @@ import org.eclipse.cdt.internal.ui.util.Util;
|
|||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.jface.preference.IPreferenceStore;
|
||||
|
||||
|
@ -96,13 +96,10 @@ public class CompletionEngine implements RelevanceConstants {
|
|||
if (CharOperation.prefixEquals(prefix.toCharArray(), proposalName.toCharArray(), true /* do not ignore case */)) {
|
||||
if(CharOperation.equals(prefix.toCharArray(), proposalName.toCharArray(), true /* do not ignore case */)) {
|
||||
return CASE_MATCH_RELEVANCE + EXACT_NAME_MATCH_RELEVANCE;
|
||||
} else {
|
||||
return CASE_MATCH_RELEVANCE;
|
||||
}
|
||||
return CASE_MATCH_RELEVANCE;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
private int computeTypeRelevance(int type){
|
||||
switch (type){
|
||||
|
@ -151,7 +148,11 @@ public class CompletionEngine implements RelevanceConstants {
|
|||
IResource currentResource = sourceUnit.getResource();
|
||||
IPath realPath = currentResource.getLocation();
|
||||
IProject project = currentResource.getProject();
|
||||
Reader reader = new CharArrayReader( sourceUnit.getContents() );
|
||||
Reader reader = null;
|
||||
try {
|
||||
reader = ParserUtil.createResourceReader(sourceUnit.getResource());
|
||||
} catch (CoreException e1) {
|
||||
}
|
||||
|
||||
//Get the scanner info
|
||||
IScannerInfo scanInfo = new ScannerInfo();
|
||||
|
@ -202,9 +203,8 @@ public class CompletionEngine implements RelevanceConstants {
|
|||
elementRequestor.stopTimer();
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void addNodeToCompletions(IASTNode node, String prefix, int totalNumberOfResults, boolean addStaticMethodsOnly, boolean addStaticFieldsOnly, int parameterIndex){
|
||||
|
|
Loading…
Add table
Reference in a new issue