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;
|
package org.eclipse.cdt.internal.core.model;
|
||||||
|
|
||||||
import java.io.StringReader;
|
import java.io.Reader;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
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.ParserException;
|
||||||
import org.eclipse.cdt.internal.core.parser.util.ASTUtil;
|
import org.eclipse.cdt.internal.core.parser.util.ASTUtil;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
|
||||||
|
|
||||||
public class CModelBuilder {
|
public class CModelBuilder {
|
||||||
|
@ -81,7 +82,6 @@ public class CModelBuilder {
|
||||||
{
|
{
|
||||||
IProject currentProject = null;
|
IProject currentProject = null;
|
||||||
boolean hasCppNature = true;
|
boolean hasCppNature = true;
|
||||||
String code = ""; //$NON-NLS-1$
|
|
||||||
|
|
||||||
// get the current project
|
// get the current project
|
||||||
if (translationUnit != null && translationUnit.getCProject() != null) {
|
if (translationUnit != null && translationUnit.getCProject() != null) {
|
||||||
|
@ -92,11 +92,11 @@ public class CModelBuilder {
|
||||||
{
|
{
|
||||||
hasCppNature = CoreModel.hasCCNature(currentProject);
|
hasCppNature = CoreModel.hasCCNature(currentProject);
|
||||||
}
|
}
|
||||||
// get the code to parse
|
|
||||||
try{
|
Reader reader = null;
|
||||||
code = translationUnit.getBuffer().getContents();
|
try {
|
||||||
} catch (CModelException e) {
|
reader = ParserUtil.createResourceReader( translationUnit.getResource() );
|
||||||
|
} catch (CoreException e) {
|
||||||
}
|
}
|
||||||
// use quick or structural parse mode
|
// use quick or structural parse mode
|
||||||
ParserMode mode = quickParseMode ? ParserMode.QUICK_PARSE : ParserMode.STRUCTURAL_PARSE;
|
ParserMode mode = quickParseMode ? ParserMode.QUICK_PARSE : ParserMode.STRUCTURAL_PARSE;
|
||||||
|
@ -124,7 +124,7 @@ public class CModelBuilder {
|
||||||
|
|
||||||
parser = ParserFactory.createParser(
|
parser = ParserFactory.createParser(
|
||||||
ParserFactory.createScanner(
|
ParserFactory.createScanner(
|
||||||
new StringReader( code ),
|
reader,
|
||||||
(translationUnit.getUnderlyingResource() != null ?
|
(translationUnit.getUnderlyingResource() != null ?
|
||||||
translationUnit.getUnderlyingResource().getLocation().toOSString() :
|
translationUnit.getUnderlyingResource().getLocation().toOSString() :
|
||||||
""), //$NON-NLS-1$
|
""), //$NON-NLS-1$
|
||||||
|
|
|
@ -231,7 +231,7 @@ public abstract class AbstractToken implements IToken, ITokenDuple {
|
||||||
* @see org.eclipse.cdt.core.parser.ITokenDuple#getStartOffset()
|
* @see org.eclipse.cdt.core.parser.ITokenDuple#getStartOffset()
|
||||||
*/
|
*/
|
||||||
public int getStartOffset() {
|
public int getStartOffset() {
|
||||||
return 0;
|
return getOffset();
|
||||||
}
|
}
|
||||||
/* (non-Javadoc)
|
/* (non-Javadoc)
|
||||||
* @see org.eclipse.cdt.core.parser.ITokenDuple#getSubrange(int, int)
|
* @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 ){
|
if( args != null && args[ args.length - 1 ] != null ){
|
||||||
List newArgs = new ArrayList( 1 );
|
List newArgs = new ArrayList( 1 );
|
||||||
newArgs.add( args[ args.length - 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 )
|
if( args[i] != null )
|
||||||
foundArgs = true;
|
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()
|
public int getSegmentCount()
|
||||||
|
@ -329,7 +329,7 @@ public class TokenDuple implements ITokenDuple {
|
||||||
*/
|
*/
|
||||||
public ITokenDuple getSubrange(int startIndex, int endIndex)
|
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 );
|
Reader r = findWorkingCopy( resultingResource, workingCopies );
|
||||||
if( r != null ) return r;
|
if( r != null ) return r;
|
||||||
}
|
}
|
||||||
BufferedInputStream bufferedStream = new BufferedInputStream( ((IFile) resultingResource).getContents() );
|
return createResourceReader(resultingResource);
|
||||||
InputStreamReader inputReader = new InputStreamReader( bufferedStream );
|
|
||||||
return new BufferedReader( inputReader );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch( CoreException ce )
|
catch( CoreException ce )
|
||||||
|
@ -79,6 +77,15 @@ public class ParserUtil
|
||||||
return InternalParserUtil.createFileReader(finalPath);
|
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
|
* @param finalPath
|
||||||
* @return
|
* @return
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
**********************************************************************/
|
**********************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.text.contentassist;
|
package org.eclipse.cdt.internal.ui.text.contentassist;
|
||||||
|
|
||||||
import java.io.CharArrayReader;
|
|
||||||
import java.io.Reader;
|
import java.io.Reader;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
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.cdt.ui.CUIPlugin;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IPath;
|
import org.eclipse.core.runtime.IPath;
|
||||||
import org.eclipse.jface.preference.IPreferenceStore;
|
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.prefixEquals(prefix.toCharArray(), proposalName.toCharArray(), true /* do not ignore case */)) {
|
||||||
if(CharOperation.equals(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;
|
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){
|
private int computeTypeRelevance(int type){
|
||||||
switch (type){
|
switch (type){
|
||||||
|
@ -151,7 +148,11 @@ public class CompletionEngine implements RelevanceConstants {
|
||||||
IResource currentResource = sourceUnit.getResource();
|
IResource currentResource = sourceUnit.getResource();
|
||||||
IPath realPath = currentResource.getLocation();
|
IPath realPath = currentResource.getLocation();
|
||||||
IProject project = currentResource.getProject();
|
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
|
//Get the scanner info
|
||||||
IScannerInfo scanInfo = new ScannerInfo();
|
IScannerInfo scanInfo = new ScannerInfo();
|
||||||
|
@ -202,9 +203,8 @@ public class CompletionEngine implements RelevanceConstants {
|
||||||
elementRequestor.stopTimer();
|
elementRequestor.stopTimer();
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} else {
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void addNodeToCompletions(IASTNode node, String prefix, int totalNumberOfResults, boolean addStaticMethodsOnly, boolean addStaticFieldsOnly, int parameterIndex){
|
private void addNodeToCompletions(IASTNode node, String prefix, int totalNumberOfResults, boolean addStaticMethodsOnly, boolean addStaticFieldsOnly, int parameterIndex){
|
||||||
|
|
Loading…
Add table
Reference in a new issue