use of com.intellij.lang.LighterASTNode in project intellij-community by JetBrains.
the class JavaFunctionalExpressionIndex method calcExprType.
@NotNull
private static String calcExprType(LighterASTNode funExpr, FileLocalResolver resolver) {
LighterASTNode scope = skipExpressionsUp(resolver.getLightTree(), funExpr, TokenSet.create(LOCAL_VARIABLE, FIELD, TYPE_CAST_EXPRESSION, RETURN_STATEMENT, ASSIGNMENT_EXPRESSION));
if (scope != null) {
if (scope.getTokenType() == ASSIGNMENT_EXPRESSION) {
LighterASTNode lValue = findExpressionChild(scope, resolver.getLightTree());
scope = lValue == null ? null : resolver.resolveLocally(lValue).getTarget();
} else if (scope.getTokenType() == RETURN_STATEMENT) {
scope = LightTreeUtil.getParentOfType(resolver.getLightTree(), scope, TokenSet.create(METHOD), TokenSet.orSet(ElementType.MEMBER_BIT_SET, TokenSet.create(LAMBDA_EXPRESSION)));
}
}
return StringUtil.notNullize(scope == null ? null : resolver.getShortClassTypeName(scope));
}
use of com.intellij.lang.LighterASTNode in project intellij-community by JetBrains.
the class PropertyStubElementType method createStub.
@Override
public PropertyStub createStub(LighterAST tree, LighterASTNode node, StubElement parentStub) {
LighterASTNode keyNode = LightTreeUtil.firstChildOfType(tree, node, PropertiesTokenTypes.KEY_CHARACTERS);
String key = intern(tree.getCharTable(), keyNode);
return new PropertyStubImpl(parentStub, key);
}
use of com.intellij.lang.LighterASTNode in project intellij-community by JetBrains.
the class TypeInfo method create.
@NotNull
public static TypeInfo create(@NotNull LighterAST tree, @NotNull LighterASTNode element, StubElement parentStub) {
String text;
byte arrayCount = 0;
boolean isEllipsis = false;
if (element.getTokenType() == JavaElementType.ENUM_CONSTANT) {
text = ((PsiClassStub) parentStub).getName();
} else {
LighterASTNode typeElement = null;
for (final LighterASTNode child : tree.getChildren(element)) {
IElementType type = child.getTokenType();
if (type == JavaElementType.TYPE) {
typeElement = child;
} else if (type == JavaTokenType.LBRACKET) {
// C-style array
arrayCount++;
}
}
if (typeElement == null && element.getTokenType() == JavaElementType.FIELD) {
LighterASTNode parent = tree.getParent(element);
assert parent != null : element;
List<LighterASTNode> fields = LightTreeUtil.getChildrenOfType(tree, parent, JavaElementType.FIELD);
int idx = fields.indexOf(element);
for (int i = idx - 1; i >= 0 && typeElement == null; i--) {
// int i, j
typeElement = LightTreeUtil.firstChildOfType(tree, fields.get(i), JavaElementType.TYPE);
}
}
assert typeElement != null : element + " in " + parentStub;
isEllipsis = LightTreeUtil.firstChildOfType(tree, typeElement, JavaTokenType.ELLIPSIS) != null;
while (true) {
LighterASTNode nested = LightTreeUtil.firstChildOfType(tree, typeElement, JavaElementType.TYPE);
if (nested == null)
break;
typeElement = nested;
// Java-style array
arrayCount++;
}
text = LightTreeUtil.toFilteredString(tree, typeElement, null);
}
return new TypeInfo(text, arrayCount, isEllipsis, PsiAnnotationStub.EMPTY_ARRAY);
}
use of com.intellij.lang.LighterASTNode in project intellij-community by JetBrains.
the class JavaClassElementType method createStub.
@Override
public PsiClassStub createStub(final LighterAST tree, final LighterASTNode node, final StubElement parentStub) {
boolean isDeprecatedByComment = false;
boolean isInterface = false;
boolean isEnum = false;
boolean isEnumConst = false;
boolean isAnonymous = false;
boolean isAnnotation = false;
boolean isInQualifiedNew = false;
boolean hasDeprecatedAnnotation = false;
String qualifiedName = null;
String name = null;
String baseRef = null;
if (node.getTokenType() == JavaElementType.ANONYMOUS_CLASS) {
isAnonymous = true;
} else if (node.getTokenType() == JavaElementType.ENUM_CONSTANT_INITIALIZER) {
isAnonymous = isEnumConst = true;
baseRef = ((PsiClassStub) parentStub.getParentStub()).getName();
}
for (final LighterASTNode child : tree.getChildren(node)) {
final IElementType type = child.getTokenType();
if (type == JavaDocElementType.DOC_COMMENT) {
isDeprecatedByComment = RecordUtil.isDeprecatedByDocComment(tree, child);
} else if (type == JavaElementType.MODIFIER_LIST) {
hasDeprecatedAnnotation = RecordUtil.isDeprecatedByAnnotation(tree, child);
} else if (type == JavaTokenType.AT) {
isAnnotation = true;
} else if (type == JavaTokenType.INTERFACE_KEYWORD) {
isInterface = true;
} else if (type == JavaTokenType.ENUM_KEYWORD) {
isEnum = true;
} else if (!isAnonymous && type == JavaTokenType.IDENTIFIER) {
name = RecordUtil.intern(tree.getCharTable(), child);
} else if (isAnonymous && !isEnumConst && type == JavaElementType.JAVA_CODE_REFERENCE) {
baseRef = LightTreeUtil.toFilteredString(tree, child, null);
}
}
if (name != null) {
if (parentStub instanceof PsiJavaFileStub) {
final String pkg = ((PsiJavaFileStub) parentStub).getPackageName();
if (!pkg.isEmpty())
qualifiedName = pkg + '.' + name;
else
qualifiedName = name;
} else if (parentStub instanceof PsiClassStub) {
final String parentFqn = ((PsiClassStub) parentStub).getQualifiedName();
qualifiedName = parentFqn != null ? parentFqn + '.' + name : null;
}
}
if (isAnonymous) {
final LighterASTNode parent = tree.getParent(node);
if (parent != null && parent.getTokenType() == JavaElementType.NEW_EXPRESSION) {
isInQualifiedNew = (LightTreeUtil.firstChildOfType(tree, parent, JavaTokenType.DOT) != null);
}
}
final byte flags = PsiClassStubImpl.packFlags(isDeprecatedByComment, isInterface, isEnum, isEnumConst, isAnonymous, isAnnotation, isInQualifiedNew, hasDeprecatedAnnotation);
final JavaClassElementType type = typeForClass(isAnonymous, isEnumConst);
return new PsiClassStubImpl(type, parentStub, qualifiedName, name, baseRef, flags);
}
use of com.intellij.lang.LighterASTNode in project intellij-community by JetBrains.
the class JavaFieldStubElementType method createStub.
@Override
public PsiFieldStub createStub(final LighterAST tree, final LighterASTNode node, final StubElement parentStub) {
final TypeInfo typeInfo = TypeInfo.create(tree, node, parentStub);
boolean isDeprecatedByComment = false;
boolean hasDeprecatedAnnotation = false;
boolean hasDocComment = false;
String name = null;
String initializer = null;
boolean expectingInit = false;
for (final LighterASTNode child : tree.getChildren(node)) {
final IElementType type = child.getTokenType();
if (type == JavaDocElementType.DOC_COMMENT) {
hasDocComment = true;
isDeprecatedByComment = RecordUtil.isDeprecatedByDocComment(tree, child);
} else if (type == JavaElementType.MODIFIER_LIST) {
hasDeprecatedAnnotation = RecordUtil.isDeprecatedByAnnotation(tree, child);
} else if (type == JavaTokenType.IDENTIFIER) {
name = RecordUtil.intern(tree.getCharTable(), child);
} else if (type == JavaTokenType.EQ) {
expectingInit = true;
} else if (expectingInit && !ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET.contains(type) && type != JavaTokenType.SEMICOLON) {
initializer = encodeInitializer(tree, child);
break;
}
}
final boolean isEnumConst = node.getTokenType() == JavaElementType.ENUM_CONSTANT;
final byte flags = PsiFieldStubImpl.packFlags(isEnumConst, isDeprecatedByComment, hasDeprecatedAnnotation, hasDocComment);
return new PsiFieldStubImpl(parentStub, name, typeInfo, initializer, flags);
}
Aggregations