use of org.eclipse.jdt.core.dom.ArrayAccess in project xtext-xtend by eclipse.
the class JavaASTFlattener method visit.
@Override
public boolean visit(final Assignment node) {
final Expression leftSide = node.getLeftHandSide();
Type type = null;
if ((leftSide instanceof ArrayAccess)) {
Expression _array = ((ArrayAccess) leftSide).getArray();
if ((_array instanceof SimpleName)) {
Expression _array_1 = ((ArrayAccess) leftSide).getArray();
type = this._aSTFlattenerUtils.findDeclaredType(((SimpleName) _array_1));
}
this.handleAssignment(node, ((ArrayAccess) leftSide), type);
} else {
if ((leftSide instanceof SimpleName)) {
type = this._aSTFlattenerUtils.findDeclaredType(((SimpleName) leftSide));
}
this.handleAssignment(node, leftSide, type);
}
return false;
}
use of org.eclipse.jdt.core.dom.ArrayAccess in project xtext-xtend by eclipse.
the class JavaASTFlattener method computeArrayName.
public String computeArrayName(final ArrayAccess node) {
String _switchResult = null;
Expression _array = node.getArray();
final Expression array = _array;
boolean _matched = false;
if (array instanceof SimpleName) {
_matched = true;
_switchResult = ((SimpleName) array).getIdentifier();
}
if (!_matched) {
if (array instanceof MethodInvocation) {
_matched = true;
_switchResult = ((MethodInvocation) array).getName().getIdentifier();
}
}
if (!_matched) {
if (array instanceof ArrayAccess) {
_matched = true;
String _computeArrayName = this.computeArrayName(((ArrayAccess) array));
_switchResult = ("_" + _computeArrayName);
}
}
if (!_matched) {
_switchResult = "tmpNode";
}
return _switchResult;
}
use of org.eclipse.jdt.core.dom.ArrayAccess in project evosuite by EvoSuite.
the class TestExtractingVisitor method retrieveTypeClass.
/**
* <p>
* retrieveTypeClass
* </p>
*
* @param argument
* a {@link java.lang.Object} object.
* @return a {@link java.lang.Class} object.
*/
protected Class<?> retrieveTypeClass(Object argument) {
assert argument != null;
if (argument instanceof SimpleType) {
SimpleType simpleType = (SimpleType) argument;
return retrieveTypeClass(simpleType);
}
if (argument instanceof ITypeBinding) {
ITypeBinding binding = (ITypeBinding) argument;
return retrieveTypeClass(binding);
}
if (argument instanceof IVariableBinding) {
IVariableBinding variableBinding = (IVariableBinding) argument;
return retrieveTypeClass(variableBinding.getType());
}
if (argument instanceof SimpleName) {
SimpleName simpleName = (SimpleName) argument;
return retrieveTypeClass(simpleName.resolveBinding());
}
if (argument instanceof StringLiteral) {
return String.class;
}
if (argument instanceof NumberLiteral) {
return retrieveTypeClass((NumberLiteral) argument);
}
if (argument instanceof PrimitiveType) {
PrimitiveType primitiveType = (PrimitiveType) argument;
String typeCode = primitiveType.getPrimitiveTypeCode().toString();
Class<?> result = PRIMITIVE_TYPECODE_MAPPING.get(typeCode);
assert result != null : "Could not resolve typecode " + typeCode + ".";
return result;
}
if (argument instanceof ArrayType) {
ArrayType arrayType = (ArrayType) argument;
return retrieveTypeClass(arrayType);
}
if (argument instanceof ParameterizedType) {
ParameterizedType parameterizedType = (ParameterizedType) argument;
return retrieveTypeClass(parameterizedType.getType());
}
if (argument instanceof VariableDeclarationFragment) {
VariableDeclarationFragment varDeclFrgmnt = (VariableDeclarationFragment) argument;
return retrieveTypeClass(varDeclFrgmnt.resolveBinding());
}
if (argument instanceof InfixExpression) {
InfixExpression infixExpr = (InfixExpression) argument;
ITypeBinding refTypeBinding = infixExpr.resolveTypeBinding();
if (refTypeBinding != null) {
return retrieveTypeClass(refTypeBinding);
} else {
throw new RuntimeException("Could not determine type class of infix expression '" + infixExpr + "'.");
}
}
if (argument instanceof MethodInvocation) {
MethodInvocation methodInvocation = (MethodInvocation) argument;
ITypeBinding typeBinding = methodInvocation.resolveTypeBinding();
if (typeBinding != null) {
return retrieveTypeClass(typeBinding);
}
Expression typeExpression = methodInvocation.getExpression();
if (typeExpression instanceof MethodInvocation) {
MethodInvocation parentMethodInvocation = (MethodInvocation) typeExpression;
IMethodBinding parentMethodBinding = parentMethodInvocation.resolveMethodBinding();
return retrieveTypeClass(parentMethodBinding.getDeclaringClass());
} else {
return retrieveTypeClass(typeExpression);
}
}
if (argument instanceof ArrayAccess) {
ArrayAccess arrayAccess = (ArrayAccess) argument;
return retrieveTypeClass(arrayAccess.getArray());
}
if (argument instanceof Class<?>) {
return (Class<?>) argument;
}
if (argument instanceof ClassInstanceCreation) {
return retrieveTypeClass(((ClassInstanceCreation) argument).resolveTypeBinding());
}
if (argument instanceof BooleanLiteral) {
return Boolean.TYPE;
}
throw new UnsupportedOperationException("Retrieval of type " + argument.getClass() + " not implemented yet!");
}
use of org.eclipse.jdt.core.dom.ArrayAccess in project eclipse.jdt.ls by eclipse.
the class ASTResolving method guessTypeForReference.
public static Type guessTypeForReference(AST ast, ASTNode node) {
ASTNode parent = node.getParent();
while (parent != null) {
switch(parent.getNodeType()) {
case ASTNode.VARIABLE_DECLARATION_FRAGMENT:
if (((VariableDeclarationFragment) parent).getInitializer() == node) {
return ASTNodeFactory.newType(ast, (VariableDeclaration) parent);
}
return null;
case ASTNode.SINGLE_VARIABLE_DECLARATION:
if (((VariableDeclarationFragment) parent).getInitializer() == node) {
return ASTNodeFactory.newType(ast, (VariableDeclaration) parent);
}
return null;
case ASTNode.ARRAY_ACCESS:
if (!((ArrayAccess) parent).getIndex().equals(node)) {
Type type = guessTypeForReference(ast, parent);
if (type != null) {
return ASTNodeFactory.newArrayType(type);
}
}
return null;
case ASTNode.FIELD_ACCESS:
if (node.equals(((FieldAccess) parent).getName())) {
node = parent;
parent = parent.getParent();
} else {
return null;
}
break;
case ASTNode.SUPER_FIELD_ACCESS:
case ASTNode.PARENTHESIZED_EXPRESSION:
node = parent;
parent = parent.getParent();
break;
case ASTNode.QUALIFIED_NAME:
if (node.equals(((QualifiedName) parent).getName())) {
node = parent;
parent = parent.getParent();
} else {
return null;
}
break;
default:
return null;
}
}
return null;
}
Aggregations