ElementType separator = qualifiedIdentifier.getElementType().getSeparatorToken();
if (element.getElementType() == separator){
BasePsiElement parentPsiElement = element.getPrevElement();
if (parentPsiElement != null && parentPsiElement instanceof IdentifierPsiElement) {
IdentifierPsiElement identifierPsiElement = (IdentifierPsiElement) parentPsiElement;
parentObject = identifierPsiElement.resolveUnderlyingObject();
if (parentObject != null) {
for (QualifiedIdentifierVariant parseVariant : qualifiedIdentifier.getParseVariants()){
boolean match = parseVariant.matchesPsiElement(qualifiedIdentifier);
if (match) {
int index = qualifiedIdentifier.getIndexOf(identifierPsiElement);
LeafElementType leafElementType = parseVariant.getLeaf(index + 1);
if (leafElementType != null) {
nextPossibleLeafs.put(getLeafUniqueKey(leafElementType), leafElementType);
}
}
}
}
}
}
}
if (nextPossibleLeafs.size() == 0) {
LeafElementType elementType = (LeafElementType) element.getElementType();
PathNode pathNode = new ASTPathNode(element.getNode());
for (LeafElementType leafElementType : elementType.getNextPossibleLeafs(pathNode, filterSettings)) {
String leafUniqueKey = getLeafUniqueKey(leafElementType);
if (leafUniqueKey != null) {
nextPossibleLeafs.put(leafUniqueKey, leafElementType);
}
}
}
for (LeafElementType nextPossibleLeaf : nextPossibleLeafs.values()) {
consumer.check();
//boolean addParenthesis =
// nextPossibleLeaf.getLookupCache().getNextRequiredTokens().contains(
// element.getLanguage().getSharedTokenTypes().getLeftParenthesis());
//consumer.setAddParenthesis(addParenthesis);
if (nextPossibleLeaf instanceof TokenElementType) {
TokenElementType tokenElementType = (TokenElementType) nextPossibleLeaf;
//consumer.setAddParenthesis(addParenthesis && tokenType.isFunction());
if (filterSettings.acceptReservedWord(tokenElementType.getTokenTypeCategory())) {
consumer.consume(tokenElementType);
}
}
else if (nextPossibleLeaf instanceof IdentifierElementType) {
IdentifierElementType identifierElementType = (IdentifierElementType) nextPossibleLeaf;
if (identifierElementType.isReference()) {
DBObjectType objectType = identifierElementType.getObjectType();
if (identifierElementType.isObject()) {
PsiLookupAdapter lookupAdapter = new ObjectDefinitionLookupAdapter(null, objectType, null);
Set<BasePsiElement> objectDefinitions = lookupAdapter.collectInParentScopeOf(element);
if (objectDefinitions != null) {
for (BasePsiElement psiElement : objectDefinitions) {
if (psiElement instanceof IdentifierPsiElement) {
IdentifierPsiElement identifierPsiElement = (IdentifierPsiElement) psiElement;
PsiElement referencedPsiElement = identifierPsiElement.resolve();
if (referencedPsiElement instanceof DBObject) {
DBObject object = (DBObject) referencedPsiElement;
LookupItemFactory lookupItemFactory = object.getLookupItemFactory(identifierElementType.getLanguage());
lookupItemFactory.createLookupItem(object, consumer);
}
}
}
}
if (connectionHandler != null && !connectionHandler.isVirtual()) {
if (parentObject == null) {
BasePsiElement scope = element.getEnclosingScopePsiElement();
collectObjectMatchingScope(consumer, identifierElementType, filterSettings, scope, context);
} else {
for (DBObject object : parentObject.getChildObjects(identifierElementType.getObjectType())) {
consumer.check();
consumer.consume(object);
}
}
}
} else if (identifierElementType.isAlias()) {
PsiLookupAdapter lookupAdapter = new AliasDefinitionLookupAdapter(null, objectType, null);
Set<BasePsiElement> aliasDefinitions = lookupAdapter.collectInParentScopeOf(element);
if (aliasDefinitions != null) {
for (PsiElement psiElement : aliasDefinitions) {
IdentifierPsiElement identifierPsiElement = (IdentifierPsiElement) psiElement;
AliasLookupItemFactory lookupItemFactory = new AliasLookupItemFactory(identifierPsiElement.getChars(), true);
lookupItemFactory.createLookupItem(identifierPsiElement, consumer);
}
}
} else if (identifierElementType.isVariable()) {
PsiLookupAdapter lookupAdapter = new VariableDefinitionLookupAdapter(null, objectType, null);
Set<BasePsiElement> aliasDefinitions = lookupAdapter.collectInParentScopeOf(element);
if (aliasDefinitions != null) {
for (BasePsiElement psiElement : aliasDefinitions) {
IdentifierPsiElement identifierPsiElement = (IdentifierPsiElement) psiElement;
VariableLookupItemFactory lookupItemFactory = new VariableLookupItemFactory(identifierPsiElement.getChars(), true);
lookupItemFactory.createLookupItem(identifierPsiElement, consumer);
}
}
}
} else if (identifierElementType.isDefinition()) {