mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
bug 69833 - Use hashmaps during completion parse and then just sort the
prefix lookup results at the end
This commit is contained in:
parent
44fdb04953
commit
993b0299f4
3 changed files with 30 additions and 49 deletions
|
@ -26,10 +26,8 @@ import java.util.ListIterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.NoSuchElementException;
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
|
||||||
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
import org.eclipse.cdt.core.parser.ast.ASTAccessVisibility;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTMember;
|
import org.eclipse.cdt.core.parser.ast.IASTMember;
|
||||||
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
import org.eclipse.cdt.core.parser.ast.IASTNode;
|
||||||
|
@ -55,12 +53,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
|
||||||
ContainerSymbol copy = (ContainerSymbol)super.clone();
|
ContainerSymbol copy = (ContainerSymbol)super.clone();
|
||||||
|
|
||||||
copy._usingDirectives = (_usingDirectives != Collections.EMPTY_LIST) ? (List) ((ArrayList)_usingDirectives).clone() : _usingDirectives;
|
copy._usingDirectives = (_usingDirectives != Collections.EMPTY_LIST) ? (List) ((ArrayList)_usingDirectives).clone() : _usingDirectives;
|
||||||
|
copy._containedSymbols = ( _containedSymbols != Collections.EMPTY_MAP )? (Map)((HashMap) _containedSymbols).clone() : _containedSymbols;
|
||||||
if( getSymbolTable().getParserMode() == ParserMode.COMPLETION_PARSE )
|
|
||||||
copy._containedSymbols = ( _containedSymbols != Collections.EMPTY_MAP )? (Map)((TreeMap) _containedSymbols).clone() : _containedSymbols;
|
|
||||||
else
|
|
||||||
copy._containedSymbols = ( _containedSymbols != Collections.EMPTY_MAP )? (Map)((HashMap) _containedSymbols).clone() : _containedSymbols;
|
|
||||||
|
|
||||||
copy._contents = (_contents != Collections.EMPTY_LIST) ? (List) ((ArrayList)_contents).clone() : _contents;
|
copy._contents = (_contents != Collections.EMPTY_LIST) ? (List) ((ArrayList)_contents).clone() : _contents;
|
||||||
|
|
||||||
return copy;
|
return copy;
|
||||||
|
@ -435,11 +428,7 @@ public class ContainerSymbol extends BasicSymbol implements IContainerSymbol {
|
||||||
|
|
||||||
protected void putInContainedSymbols( String key, Object obj ){
|
protected void putInContainedSymbols( String key, Object obj ){
|
||||||
if( _containedSymbols == Collections.EMPTY_MAP ){
|
if( _containedSymbols == Collections.EMPTY_MAP ){
|
||||||
if( getSymbolTable().getParserMode() == ParserMode.COMPLETION_PARSE ){
|
_containedSymbols = new HashMap( );
|
||||||
_containedSymbols = new TreeMap( new SymbolTableComparator() );
|
|
||||||
} else {
|
|
||||||
_containedSymbols = new HashMap( );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
_containedSymbols.put( key, obj );
|
_containedSymbols.put( key, obj );
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,6 @@ import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TreeMap;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author aniefer
|
* @author aniefer
|
||||||
|
@ -43,11 +40,7 @@ public class ParameterizedSymbol extends ContainerSymbol implements IParameteriz
|
||||||
ParameterizedSymbol copy = (ParameterizedSymbol)super.clone();
|
ParameterizedSymbol copy = (ParameterizedSymbol)super.clone();
|
||||||
|
|
||||||
copy._parameterList = ( _parameterList != Collections.EMPTY_LIST ) ? (List) ((ArrayList)_parameterList).clone() : _parameterList;
|
copy._parameterList = ( _parameterList != Collections.EMPTY_LIST ) ? (List) ((ArrayList)_parameterList).clone() : _parameterList;
|
||||||
|
copy._parameterMap = ( _parameterMap != Collections.EMPTY_MAP ) ? (Map) ((HashMap) _parameterMap).clone() : _parameterMap;
|
||||||
if( getSymbolTable().getParserMode() == ParserMode.COMPLETION_PARSE )
|
|
||||||
copy._parameterMap = ( _parameterMap != Collections.EMPTY_MAP ) ? (Map) ((TreeMap) _parameterMap).clone() : _parameterMap;
|
|
||||||
else
|
|
||||||
copy._parameterMap = ( _parameterMap != Collections.EMPTY_MAP ) ? (Map) ((HashMap) _parameterMap).clone() : _parameterMap;
|
|
||||||
|
|
||||||
return copy;
|
return copy;
|
||||||
}
|
}
|
||||||
|
@ -131,10 +124,7 @@ public class ParameterizedSymbol extends ContainerSymbol implements IParameteriz
|
||||||
if( name != null && !name.equals(ParserSymbolTable.EMPTY_NAME) )
|
if( name != null && !name.equals(ParserSymbolTable.EMPTY_NAME) )
|
||||||
{
|
{
|
||||||
if( _parameterMap == Collections.EMPTY_MAP ){
|
if( _parameterMap == Collections.EMPTY_MAP ){
|
||||||
if( getSymbolTable().getParserMode() == ParserMode.COMPLETION_PARSE )
|
_parameterMap = new HashMap( );
|
||||||
_parameterMap = new TreeMap( new SymbolTableComparator() );
|
|
||||||
else
|
|
||||||
_parameterMap = new HashMap( );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( !_parameterMap.containsKey( name ) )
|
if( !_parameterMap.containsKey( name ) )
|
||||||
|
|
|
@ -23,7 +23,7 @@ import java.util.List;
|
||||||
import java.util.ListIterator;
|
import java.util.ListIterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.SortedMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.parser.ParserLanguage;
|
import org.eclipse.cdt.core.parser.ParserLanguage;
|
||||||
import org.eclipse.cdt.core.parser.ParserMode;
|
import org.eclipse.cdt.core.parser.ParserMode;
|
||||||
|
@ -326,11 +326,7 @@ public class ParserSymbolTable {
|
||||||
|
|
||||||
Iterator iterator = null;
|
Iterator iterator = null;
|
||||||
if( data.isPrefixLookup() && declarations != Collections.EMPTY_MAP ){
|
if( data.isPrefixLookup() && declarations != Collections.EMPTY_MAP ){
|
||||||
if( declarations instanceof SortedMap ){
|
iterator = declarations.keySet().iterator();
|
||||||
iterator = ((SortedMap)declarations).tailMap( data.name.toLowerCase() ).keySet().iterator();
|
|
||||||
} else {
|
|
||||||
throw new ParserSymbolTableError( ParserSymbolTableError.r_InternalError );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String name = ( iterator != null && iterator.hasNext() ) ? (String) iterator.next() : data.name;
|
String name = ( iterator != null && iterator.hasNext() ) ? (String) iterator.next() : data.name;
|
||||||
|
@ -342,13 +338,15 @@ public class ParserSymbolTable {
|
||||||
obj = collectSymbol( data, obj );
|
obj = collectSymbol( data, obj );
|
||||||
|
|
||||||
if( obj != null ){
|
if( obj != null ){
|
||||||
if( found == null )
|
if( found == null ){
|
||||||
found = new LinkedHashMap();
|
if( data.isPrefixLookup() )
|
||||||
|
found = new TreeMap( new ContainerSymbol.SymbolTableComparator() );
|
||||||
|
else
|
||||||
|
found = new LinkedHashMap();
|
||||||
|
}
|
||||||
found.put( name, obj );
|
found.put( name, obj );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( iterator != null && iterator.hasNext() ){
|
if( iterator != null && iterator.hasNext() ){
|
||||||
|
@ -357,6 +355,8 @@ public class ParserSymbolTable {
|
||||||
name = null;
|
name = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if( found != null && data.isPrefixLookup() )
|
||||||
|
found = new LinkedHashMap( found );
|
||||||
|
|
||||||
if( found != null && !data.isPrefixLookup() ){
|
if( found != null && !data.isPrefixLookup() ){
|
||||||
return found;
|
return found;
|
||||||
|
@ -401,13 +401,17 @@ public class ParserSymbolTable {
|
||||||
if( nameMatches( data, symbol.getName() ) ){
|
if( nameMatches( data, symbol.getName() ) ){
|
||||||
obj = collectSymbol( data, symbol );
|
obj = collectSymbol( data, symbol );
|
||||||
if( obj != null ){
|
if( obj != null ){
|
||||||
if( found == null )
|
if( found == null ){
|
||||||
found = new LinkedHashMap();
|
if( data.isPrefixLookup() )
|
||||||
|
found = new TreeMap( new ContainerSymbol.SymbolTableComparator() );
|
||||||
|
else
|
||||||
|
found = new LinkedHashMap();
|
||||||
|
}
|
||||||
found.put( symbol.getName(), obj );
|
found.put( symbol.getName(), obj );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return found;
|
return ( found instanceof TreeMap ) ? new LinkedHashMap( found ) : found;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -415,11 +419,7 @@ public class ParserSymbolTable {
|
||||||
if( parameters != Collections.EMPTY_MAP ){
|
if( parameters != Collections.EMPTY_MAP ){
|
||||||
iterator = null;
|
iterator = null;
|
||||||
if( data.isPrefixLookup() ){
|
if( data.isPrefixLookup() ){
|
||||||
if( parameters instanceof SortedMap ){
|
iterator = parameters.keySet().iterator();
|
||||||
iterator = ((SortedMap) parameters).tailMap( data.name.toLowerCase() ).keySet().iterator();
|
|
||||||
} else {
|
|
||||||
throw new ParserSymbolTableError( ParserSymbolTableError.r_InternalError );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
name = ( iterator != null && iterator.hasNext() ) ? (String) iterator.next() : data.name;
|
name = ( iterator != null && iterator.hasNext() ) ? (String) iterator.next() : data.name;
|
||||||
|
@ -428,12 +428,14 @@ public class ParserSymbolTable {
|
||||||
obj = parameters.get( name );
|
obj = parameters.get( name );
|
||||||
obj = collectSymbol( data, obj );
|
obj = collectSymbol( data, obj );
|
||||||
if( obj != null ){
|
if( obj != null ){
|
||||||
if( found == null )
|
if( found == null ){
|
||||||
found = new LinkedHashMap();
|
if( data.isPrefixLookup() )
|
||||||
|
found = new TreeMap( new ContainerSymbol.SymbolTableComparator() );
|
||||||
|
else
|
||||||
|
found = new LinkedHashMap();
|
||||||
|
}
|
||||||
found.put( name, obj );
|
found.put( name, obj );
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( iterator != null && iterator.hasNext() ){
|
if( iterator != null && iterator.hasNext() ){
|
||||||
|
@ -443,7 +445,7 @@ public class ParserSymbolTable {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return found;
|
return ( found instanceof TreeMap ) ? new LinkedHashMap( found ) : found;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean nameMatches( LookupData data, String name ){
|
private static boolean nameMatches( LookupData data, String name ){
|
||||||
|
@ -452,7 +454,7 @@ public class ParserSymbolTable {
|
||||||
}
|
}
|
||||||
return name.equals( data.name );
|
return name.equals( data.name );
|
||||||
}
|
}
|
||||||
private static boolean checkType( LookupData data, ISymbol symbol ) { //, TypeInfo.eType type, TypeInfo.eType upperType ){
|
private static boolean checkType( LookupData data, ISymbol symbol ) {
|
||||||
if( data.getFilter() == null ){
|
if( data.getFilter() == null ){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue