use of com.intellij.psi.PsiArrayType in project kotlin by JetBrains.
the class ConstantEvaluator method isArrayLiteral.
/**
* Returns true if the node is pointing to a an array literal
*/
public static boolean isArrayLiteral(@Nullable PsiElement node) {
if (node instanceof PsiReference) {
PsiElement resolved = ((PsiReference) node).resolve();
if (resolved instanceof PsiField) {
PsiField field = (PsiField) resolved;
if (field.getInitializer() != null) {
return isArrayLiteral(field.getInitializer());
}
} else if (resolved instanceof PsiLocalVariable) {
PsiLocalVariable variable = (PsiLocalVariable) resolved;
PsiStatement statement = PsiTreeUtil.getParentOfType(node, PsiStatement.class, false);
if (statement != null) {
PsiStatement prev = PsiTreeUtil.getPrevSiblingOfType(statement, PsiStatement.class);
String targetName = variable.getName();
if (targetName == null) {
return false;
}
while (prev != null) {
if (prev instanceof PsiDeclarationStatement) {
for (PsiElement element : ((PsiDeclarationStatement) prev).getDeclaredElements()) {
if (variable.equals(element)) {
return isArrayLiteral(variable.getInitializer());
}
}
} else if (prev instanceof PsiExpressionStatement) {
PsiExpression expression = ((PsiExpressionStatement) prev).getExpression();
if (expression instanceof PsiAssignmentExpression) {
PsiAssignmentExpression assign = (PsiAssignmentExpression) expression;
PsiExpression lhs = assign.getLExpression();
if (lhs instanceof PsiReferenceExpression) {
PsiReferenceExpression reference = (PsiReferenceExpression) lhs;
if (targetName.equals(reference.getReferenceName()) && reference.getQualifier() == null) {
return isArrayLiteral(assign.getRExpression());
}
}
}
}
prev = PsiTreeUtil.getPrevSiblingOfType(prev, PsiStatement.class);
}
}
}
} else if (node instanceof PsiNewExpression) {
PsiNewExpression creation = (PsiNewExpression) node;
if (creation.getArrayInitializer() != null) {
return true;
}
PsiType type = creation.getType();
if (type instanceof PsiArrayType) {
return true;
}
} else if (node instanceof PsiParenthesizedExpression) {
PsiParenthesizedExpression parenthesizedExpression = (PsiParenthesizedExpression) node;
PsiExpression expression = parenthesizedExpression.getExpression();
if (expression != null) {
return isArrayLiteral(expression);
}
} else if (node instanceof PsiTypeCastExpression) {
PsiTypeCastExpression castExpression = (PsiTypeCastExpression) node;
PsiExpression operand = castExpression.getOperand();
if (operand != null) {
return isArrayLiteral(operand);
}
}
return false;
}
use of com.intellij.psi.PsiArrayType in project intellij-community by JetBrains.
the class TargetType method create.
@Nullable
public static TargetType create(final PsiArrayType arrayType) {
PsiType currentComponentType = arrayType.getComponentType();
while (currentComponentType instanceof PsiArrayType) {
currentComponentType = ((PsiArrayType) currentComponentType).getComponentType();
}
if (!(currentComponentType instanceof PsiClassType)) {
return null;
}
final String targetQName = arrayType.getCanonicalText();
return new TargetType(targetQName, true, arrayType);
}
use of com.intellij.psi.PsiArrayType in project smali by JesusFreke.
the class SmaliArrayTypeElement method getType.
@NotNull
@Override
public PsiType getType() {
ASTNode token = findChildByType(SmaliTokens.ARRAY_TYPE_PREFIX);
assert token != null;
PsiTypeElement baseType = findChildByClass(PsiTypeElement.class);
assert baseType != null;
PsiArrayType arrayType = new PsiArrayType(baseType.getType());
int dimensions = token.getTextLength() - 1;
while (dimensions > 0) {
arrayType = new PsiArrayType(arrayType);
dimensions--;
}
return arrayType;
}
use of com.intellij.psi.PsiArrayType in project intellij-community by JetBrains.
the class ComponentTypeOfMacro method calculateLookupItems.
@Override
public LookupElement[] calculateLookupItems(@NotNull Expression[] params, ExpressionContext context) {
if (params.length != 1)
return null;
LookupElement[] lookupItems = params[0].calculateLookupItems(context);
if (lookupItems == null)
return null;
List<LookupElement> result = ContainerUtil.newArrayList();
for (LookupElement element : lookupItems) {
PsiTypeLookupItem lookupItem = element.as(PsiTypeLookupItem.CLASS_CONDITION_KEY);
if (lookupItem != null) {
PsiType psiType = lookupItem.getType();
if (psiType instanceof PsiArrayType) {
result.add(PsiTypeLookupItem.createLookupItem(((PsiArrayType) psiType).getComponentType(), null));
}
}
}
return lookupItems;
}
use of com.intellij.psi.PsiArrayType in project intellij-community by JetBrains.
the class ComponentTypeOfMacro method calculateResult.
@Override
public Result calculateResult(@NotNull Expression[] params, final ExpressionContext context) {
if (params.length != 1)
return null;
final Result result = params[0].calculateResult(context);
if (result == null)
return null;
if (result instanceof PsiTypeResult) {
PsiType type = ((PsiTypeResult) result).getType();
if (type instanceof PsiArrayType) {
return new PsiTypeResult(((PsiArrayType) type).getComponentType(), context.getProject());
}
}
PsiExpression expr = MacroUtil.resultToPsiExpression(result, context);
PsiType type = expr == null ? MacroUtil.resultToPsiType(result, context) : expr.getType();
if (type instanceof PsiArrayType) {
return new PsiTypeResult(((PsiArrayType) type).getComponentType(), context.getProject());
}
LookupElement[] elements = params[0].calculateLookupItems(context);
if (elements != null) {
for (LookupElement element : elements) {
PsiTypeLookupItem typeLookupItem = element.as(PsiTypeLookupItem.CLASS_CONDITION_KEY);
if (typeLookupItem != null) {
PsiType psiType = typeLookupItem.getType();
if (psiType instanceof PsiArrayType) {
return new PsiTypeResult(((PsiArrayType) psiType).getComponentType(), context.getProject());
}
}
}
}
return new PsiElementResult(null);
}
Aggregations