org.eclipse.jdt.core.dom.ArrayAccess Java Examples

The following examples show how to use org.eclipse.jdt.core.dom.ArrayAccess. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NecessaryParenthesesChecker.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
private static boolean locationNeedsParentheses(StructuralPropertyDescriptor locationInParent) {
	if (locationInParent instanceof ChildListPropertyDescriptor && locationInParent != InfixExpression.EXTENDED_OPERANDS_PROPERTY) {
		// e.g. argument lists of MethodInvocation, ClassInstanceCreation, dimensions of ArrayCreation ...
		return false;
	}
	if (locationInParent == VariableDeclarationFragment.INITIALIZER_PROPERTY
			|| locationInParent == SingleVariableDeclaration.INITIALIZER_PROPERTY
			|| locationInParent == ReturnStatement.EXPRESSION_PROPERTY
			|| locationInParent == EnhancedForStatement.EXPRESSION_PROPERTY
			|| locationInParent == ForStatement.EXPRESSION_PROPERTY
			|| locationInParent == WhileStatement.EXPRESSION_PROPERTY
			|| locationInParent == DoStatement.EXPRESSION_PROPERTY
			|| locationInParent == AssertStatement.EXPRESSION_PROPERTY
			|| locationInParent == AssertStatement.MESSAGE_PROPERTY
			|| locationInParent == IfStatement.EXPRESSION_PROPERTY
			|| locationInParent == SwitchStatement.EXPRESSION_PROPERTY
			|| locationInParent == SwitchCase.EXPRESSION_PROPERTY
			|| locationInParent == ArrayAccess.INDEX_PROPERTY
			|| locationInParent == ThrowStatement.EXPRESSION_PROPERTY
			|| locationInParent == SynchronizedStatement.EXPRESSION_PROPERTY
			|| locationInParent == ParenthesizedExpression.EXPRESSION_PROPERTY) {
		return false;
	}
	return true;
}
 
Example #2
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@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;
}
 
Example #3
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public boolean visit(final ArrayAccess node) {
  Expression _index = node.getIndex();
  if ((_index instanceof NumberLiteral)) {
    node.getArray().accept(this);
    this.appendToBuffer(".get(");
    node.getIndex().accept(this);
    this.appendToBuffer(")");
  } else {
    final String arrayname = this.computeArrayName(node);
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("{val _rdIndx_");
    _builder.append(arrayname);
    _builder.append("=");
    this.appendToBuffer(_builder.toString());
    node.getIndex().accept(this);
    this.appendSpaceToBuffer();
    node.getArray().accept(this);
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append(".get(_rdIndx_");
    _builder_1.append(arrayname);
    _builder_1.append(")}");
    this.appendToBuffer(_builder_1.toString());
  }
  return false;
}
 
Example #4
Source File: ASTNodeMatcher.java    From JDeodorant with MIT License 6 votes vote down vote up
protected boolean isTypeHolder(Object o) {
	if(o.getClass().equals(MethodInvocation.class) || o.getClass().equals(SuperMethodInvocation.class)			
			|| o.getClass().equals(NumberLiteral.class) || o.getClass().equals(StringLiteral.class)
			|| o.getClass().equals(CharacterLiteral.class) || o.getClass().equals(BooleanLiteral.class)
			|| o.getClass().equals(TypeLiteral.class) || o.getClass().equals(NullLiteral.class)
			|| o.getClass().equals(ArrayCreation.class)
			|| o.getClass().equals(ClassInstanceCreation.class)
			|| o.getClass().equals(ArrayAccess.class) || o.getClass().equals(FieldAccess.class)
			|| o.getClass().equals(SuperFieldAccess.class) || o.getClass().equals(ParenthesizedExpression.class)
			|| o.getClass().equals(SimpleName.class) || o.getClass().equals(QualifiedName.class)
			|| o.getClass().equals(CastExpression.class) || o.getClass().equals(InfixExpression.class)
			|| o.getClass().equals(PrefixExpression.class) || o.getClass().equals(InstanceofExpression.class)
			|| o.getClass().equals(ThisExpression.class) || o.getClass().equals(ConditionalExpression.class))
		return true;
	return false;
}
 
Example #5
Source File: FlowAnalyzer.java    From eclipse.jdt.ls with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void endVisit(ArrayAccess node) {
	if (skipNode(node)) {
		return;
	}
	processSequential(node, node.getArray(), node.getIndex());
}
 
Example #6
Source File: GenerateForLoopAssistProposal.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates an {@link Assignment} as first expression appearing in a <code>for</code> loop's
 * body. This Assignment declares a local variable and initializes it using the array's current
 * element identified by the loop index.
 * 
 * @param rewrite the current {@link ASTRewrite} instance
 * @param loopVariableName the name of the index variable in String representation
 * @return a completed {@link Assignment} containing the mentioned declaration and
 *         initialization
 */
private Assignment getForBodyAssignment(ASTRewrite rewrite, SimpleName loopVariableName) {
	AST ast= rewrite.getAST();
	ITypeBinding loopOverType= extractElementType(ast);

	Assignment assignResolvedVariable= ast.newAssignment();

	// left hand side
	SimpleName resolvedVariableName= resolveLinkedVariableNameWithProposals(rewrite, loopOverType.getName(), loopVariableName.getIdentifier(), false);
	VariableDeclarationFragment resolvedVariableDeclarationFragment= ast.newVariableDeclarationFragment();
	resolvedVariableDeclarationFragment.setName(resolvedVariableName);
	VariableDeclarationExpression resolvedVariableDeclaration= ast.newVariableDeclarationExpression(resolvedVariableDeclarationFragment);
	resolvedVariableDeclaration.setType(getImportRewrite().addImport(loopOverType, ast, new ContextSensitiveImportRewriteContext(fCurrentNode, getImportRewrite())));
	assignResolvedVariable.setLeftHandSide(resolvedVariableDeclaration);

	// right hand side
	ArrayAccess access= ast.newArrayAccess();
	access.setArray((Expression) rewrite.createCopyTarget(fCurrentExpression));
	SimpleName indexName= ast.newSimpleName(loopVariableName.getIdentifier());
	addLinkedPosition(rewrite.track(indexName), LinkedPositionGroup.NO_STOP, indexName.getIdentifier());
	access.setIndex(indexName);
	assignResolvedVariable.setRightHandSide(access);

	assignResolvedVariable.setOperator(Assignment.Operator.ASSIGN);

	return assignResolvedVariable;
}
 
Example #7
Source File: OperatorPrecedence.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the precedence of the expression. Expression
 * with higher precedence are executed before expressions
 * with lower precedence.
 * i.e. in:
 * <br><code> int a= ++3--;</code></br>
 *
 * the  precedence order is
 * <ul>
 * <li>3</li>
 * <li>++</li>
 * <li>--</li>
 * <li>=</li>
 * </ul>
 * 1. 3 -(++)-> 4<br>
 * 2. 4 -(--)-> 3<br>
 * 3. 3 -(=)-> a<br>
 *
 * @param expression the expression to determine the precedence for
 * @return the precedence the higher to stronger the binding to its operand(s)
 */
public static int getExpressionPrecedence(Expression expression) {
	if (expression instanceof InfixExpression) {
		return getOperatorPrecedence(((InfixExpression)expression).getOperator());
	} else if (expression instanceof Assignment) {
		return ASSIGNMENT;
	} else if (expression instanceof ConditionalExpression) {
		return CONDITIONAL;
	} else if (expression instanceof InstanceofExpression) {
		return RELATIONAL;
	} else if (expression instanceof CastExpression) {
		return TYPEGENERATION;
	} else if (expression instanceof ClassInstanceCreation) {
		return POSTFIX;
	} else if (expression instanceof PrefixExpression) {
		return PREFIX;
	} else if (expression instanceof FieldAccess) {
		return POSTFIX;
	} else if (expression instanceof MethodInvocation) {
		return POSTFIX;
	} else if (expression instanceof ArrayAccess) {
		return POSTFIX;
	} else if (expression instanceof PostfixExpression) {
		return POSTFIX;
	}
	return Integer.MAX_VALUE;
}
 
Example #8
Source File: SourceAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public boolean visit(ArrayAccess node) {
	Expression array= node.getArray();
	if (array instanceof SimpleName && fParameter.isEqualTo(((SimpleName)array).resolveBinding())) {
		fArrayAccess= true;
	}
	return true;
}
 
Example #9
Source File: InferTypeArgumentsConstraintCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public void endVisit(ArrayAccess node) {
	if (node.resolveBoxing()) {
		ImmutableTypeVariable2 boxed= fTCModel.makeImmutableTypeVariable(node.resolveTypeBinding(), node);
		setConstraintVariable(node, boxed);
		return;
	}

	ConstraintVariable2 arrayCv= getConstraintVariable(node.getArray());
	if (arrayCv == null)
		return;

	ArrayElementVariable2 arrayElementCv= fTCModel.getArrayElementVariable(arrayCv);
	setConstraintVariable(node, arrayElementCv);
}
 
Example #10
Source File: Visitor.java    From RefactoringMiner with MIT License 5 votes vote down vote up
private void processArgument(Expression argument) {
	if(argument instanceof SuperMethodInvocation ||
			argument instanceof Name ||
			argument instanceof StringLiteral ||
			argument instanceof BooleanLiteral ||
			(argument instanceof FieldAccess && ((FieldAccess)argument).getExpression() instanceof ThisExpression) ||
			(argument instanceof ArrayAccess && invalidArrayAccess((ArrayAccess)argument)) ||
			(argument instanceof InfixExpression && invalidInfix((InfixExpression)argument)))
		return;
	this.arguments.add(argument.toString());
	if(current.getUserObject() != null) {
		AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject();
		anonymous.getArguments().add(argument.toString());
	}
}
 
Example #11
Source File: Visitor.java    From RefactoringMiner with MIT License 5 votes vote down vote up
public boolean visit(ArrayAccess node) {
	arrayAccesses.add(node.toString());
	if(current.getUserObject() != null) {
		AnonymousClassDeclarationObject anonymous = (AnonymousClassDeclarationObject)current.getUserObject();
		anonymous.getArrayAccesses().add(node.toString());
	}
	return super.visit(node);
}
 
Example #12
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
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;
}
 
Example #13
Source File: StyledStringVisitor.java    From JDeodorant with MIT License 5 votes vote down vote up
public boolean visit(ArrayAccess expr) {
	/*
	 * Expression [ Expression ]
	 */
	activateDiffStyle(expr);
	handleExpression((Expression) expr.getArray());
	appendOpenBracket();
	handleExpression((Expression) expr.getIndex());
	appendClosedBracket();
	deactivateDiffStyle(expr);
	return false;
}
 
Example #14
Source File: CodeBlock.java    From SimFix with GNU General Public License v2.0 5 votes vote down vote up
private ArrayAcc visit(ArrayAccess node) {
	int startLine = _cunit.getLineNumber(node.getStartPosition());
	int endLine = _cunit.getLineNumber(node.getStartPosition() + node.getLength());
	ArrayAcc arrayAcc = new ArrayAcc(startLine, endLine, node);
	
	Expr array = (Expr) process(node.getArray());
	array.setParent(arrayAcc);
	arrayAcc.setArray(array);
	
	Expr indexExpr = (Expr) process(node.getIndex());
	indexExpr.setParent(arrayAcc);
	arrayAcc.setIndex(indexExpr);
	
	Pair<String, String> classAndMethodName = NodeUtils.getTypeDecAndMethodDec(node);
	String nodeStr = node.toString();
	int index = nodeStr.indexOf("[");
	if(index >= 0){
		nodeStr = nodeStr.substring(0, index);
	}
	Type type = ProjectInfo.getVariableType(classAndMethodName.getFirst(), classAndMethodName.getSecond(), nodeStr);
	if(type != null){
		if(type instanceof ArrayType){
			ArrayType arrayType = (ArrayType) type;
			type = arrayType.getElementType();
		} else {
			System.out.println("ArrayAccess type error : not array type ! " + node.toString());
		}
	}
	arrayAcc.setType(type);
	
	return arrayAcc;
}
 
Example #15
Source File: InstanceOfArrayAccess.java    From JDeodorant with MIT License 4 votes vote down vote up
public boolean instanceOf(Expression expression) {
	if(expression instanceof ArrayAccess)
		return true;
	else
		return false;
}
 
Example #16
Source File: BindingSignatureVisitor.java    From JDeodorant with MIT License 4 votes vote down vote up
public boolean visit(ArrayAccess expr) {
	handleExpression(expr.getArray());
	handleExpression(expr.getIndex());
	return false;
}
 
Example #17
Source File: BindingSignatureVisitor.java    From JDeodorant with MIT License 4 votes vote down vote up
private void handleExpression(Expression expression) {
	if (expression instanceof ArrayAccess) {
		visit((ArrayAccess) expression);
	} else if (expression instanceof ArrayCreation) {
		visit((ArrayCreation) expression);
	} else if (expression instanceof ArrayInitializer) {
		visit((ArrayInitializer) expression);
	} else if (expression instanceof Assignment) {
		visit((Assignment) expression);
	} else if (expression instanceof BooleanLiteral) {
		visit((BooleanLiteral) expression);
	} else if (expression instanceof CastExpression) {
		visit((CastExpression) expression);
	} else if (expression instanceof CharacterLiteral) {
		visit((CharacterLiteral) expression);
	} else if (expression instanceof ClassInstanceCreation) {
		visit((ClassInstanceCreation) expression);
	} else if (expression instanceof ConditionalExpression) {
		visit((ConditionalExpression) expression);
	} else if (expression instanceof FieldAccess) {
		visit((FieldAccess) expression);
	} else if (expression instanceof InfixExpression) {
		visit((InfixExpression) expression);
	} else if (expression instanceof InstanceofExpression) {
		visit((InstanceofExpression) expression);
	} else if (expression instanceof MethodInvocation) {
		visit((MethodInvocation) expression);
	} else if (expression instanceof NullLiteral) {
		visit((NullLiteral) expression);
	} else if (expression instanceof NumberLiteral) {
		visit((NumberLiteral) expression);
	} else if (expression instanceof ParenthesizedExpression) {
		visit((ParenthesizedExpression) expression);
	} else if (expression instanceof PostfixExpression) {
		visit((PostfixExpression) expression);
	} else if (expression instanceof PrefixExpression) {
		visit((PrefixExpression) expression);
	} else if ((expression instanceof QualifiedName)) {
		visit((QualifiedName) expression);
	} else if (expression instanceof SimpleName) {
		visit((SimpleName) expression);
	} else if (expression instanceof StringLiteral) {
		visit((StringLiteral) expression);
	} else if (expression instanceof SuperFieldAccess) {
		visit((SuperFieldAccess) expression);
	} else if (expression instanceof SuperMethodInvocation) {
		visit((SuperMethodInvocation) expression);
	} else if (expression instanceof ThisExpression) {
		visit((ThisExpression) expression);
	} else if (expression instanceof TypeLiteral) {
		visit((TypeLiteral) expression);
	} else if (expression instanceof VariableDeclarationExpression) {
		visit((VariableDeclarationExpression) expression);
	}
}
 
Example #18
Source File: ArrayAccessObject.java    From JDeodorant with MIT License 4 votes vote down vote up
public void setArrayAccess(ArrayAccess arrayAccess) {
	this.arrayAccess = ASTInformationGenerator.generateASTInformation(arrayAccess);
}
 
Example #19
Source File: ArrayAccessObject.java    From JDeodorant with MIT License 4 votes vote down vote up
public ArrayAccess getArrayAccess() {
	return (ArrayAccess)this.arrayAccess.recoverASTNode();
}
 
Example #20
Source File: ASTResolving.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
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;
}
 
Example #21
Source File: StyledStringVisitor.java    From JDeodorant with MIT License 4 votes vote down vote up
private void handleExpression(Expression expression) {
	if (expression instanceof ArrayAccess) {
		visit((ArrayAccess) expression);
	} else if (expression instanceof ArrayCreation) {
		visit((ArrayCreation) expression);
	} else if (expression instanceof ArrayInitializer) {
		visit((ArrayInitializer) expression);
	} else if (expression instanceof Assignment) {
		visit((Assignment) expression);
	} else if (expression instanceof BooleanLiteral) {
		visit((BooleanLiteral) expression);
	} else if (expression instanceof CastExpression) {
		visit((CastExpression) expression);
	} else if (expression instanceof CharacterLiteral) {
		visit((CharacterLiteral) expression);
	} else if (expression instanceof ClassInstanceCreation) {
		visit((ClassInstanceCreation) expression);
	} else if (expression instanceof ConditionalExpression) {
		visit((ConditionalExpression) expression);
	} else if (expression instanceof FieldAccess) {
		visit((FieldAccess) expression);
	} else if (expression instanceof InfixExpression) {
		visit((InfixExpression) expression);
	} else if (expression instanceof InstanceofExpression) {
		visit((InstanceofExpression) expression);
	} else if (expression instanceof MethodInvocation) {
		visit((MethodInvocation) expression);
	} else if (expression instanceof NullLiteral) {
		visit((NullLiteral) expression);
	} else if (expression instanceof NumberLiteral) {
		visit((NumberLiteral) expression);
	} else if (expression instanceof ParenthesizedExpression) {
		visit((ParenthesizedExpression) expression);
	} else if (expression instanceof PostfixExpression) {
		visit((PostfixExpression) expression);
	} else if (expression instanceof PrefixExpression) {
		visit((PrefixExpression) expression);
	} else if ((expression instanceof QualifiedName)) {
		visit((QualifiedName) expression);
	} else if (expression instanceof SimpleName) {
		visit((SimpleName) expression);
	} else if (expression instanceof StringLiteral) {
		visit((StringLiteral) expression);
	} else if (expression instanceof SuperFieldAccess) {
		visit((SuperFieldAccess) expression);
	} else if (expression instanceof SuperMethodInvocation) {
		visit((SuperMethodInvocation) expression);
	} else if (expression instanceof ThisExpression) {
		visit((ThisExpression) expression);
	} else if (expression instanceof TypeLiteral) {
		visit((TypeLiteral) expression);
	} else if (expression instanceof VariableDeclarationExpression) {
		visit((VariableDeclarationExpression) expression);
	}
}
 
Example #22
Source File: GenericVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(ArrayAccess node) {
	return visitNode(node);
}
 
Example #23
Source File: GenericVisitor.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void endVisit(ArrayAccess node) {
	endVisitNode(node);
}
 
Example #24
Source File: Bindings.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Resolve the binding (<em>not</em> the type binding) for the expression or a nested expression
 * (e.g. nested in parentheses, cast, ...).
 * 
 * @param expression an expression node
 * @param goIntoCast iff <code>true</code>, go into a CastExpression's expression to resolve
 * @return the expression binding, or <code>null</code> if the expression has no binding or the
 *         binding could not be resolved
 * 
 * @see StubUtility#getVariableNameSuggestions(int, IJavaProject, ITypeBinding, Expression, java.util.Collection)
 * @since 3.5
 */
public static IBinding resolveExpressionBinding(Expression expression, boolean goIntoCast) {
	//TODO: search for callers of resolve*Binding() methods and replace with call to this method
	
	// similar to StubUtility#getVariableNameSuggestions(int, IJavaProject, ITypeBinding, Expression, Collection)
	switch (expression.getNodeType()) {
		case ASTNode.SIMPLE_NAME:
		case ASTNode.QUALIFIED_NAME:
			return ((Name) expression).resolveBinding();
			
		case ASTNode.FIELD_ACCESS:
			return ((FieldAccess) expression).resolveFieldBinding();
		case ASTNode.SUPER_FIELD_ACCESS:
			return ((SuperFieldAccess) expression).resolveFieldBinding();
			
		case ASTNode.METHOD_INVOCATION:
			return ((MethodInvocation) expression).resolveMethodBinding();
		case ASTNode.SUPER_METHOD_INVOCATION:
			return ((SuperMethodInvocation) expression).resolveMethodBinding();
		case ASTNode.CLASS_INSTANCE_CREATION:
			return ((ClassInstanceCreation) expression).resolveConstructorBinding();
			
		case ASTNode.MARKER_ANNOTATION:
		case ASTNode.SINGLE_MEMBER_ANNOTATION:
		case ASTNode.NORMAL_ANNOTATION:
			return ((Annotation) expression).resolveAnnotationBinding();
			
		case ASTNode.ARRAY_ACCESS:
			return resolveExpressionBinding(((ArrayAccess) expression).getArray(), goIntoCast);
		case ASTNode.CAST_EXPRESSION:
			if (goIntoCast) {
				return resolveExpressionBinding(((CastExpression) expression).getExpression(), true);
			} else {
				return null;
			}
		case ASTNode.PARENTHESIZED_EXPRESSION:
			return resolveExpressionBinding(((ParenthesizedExpression) expression).getExpression(), goIntoCast);
		case ASTNode.PREFIX_EXPRESSION:
			return resolveExpressionBinding(((PrefixExpression) expression).getOperand(), goIntoCast);
		case ASTNode.POSTFIX_EXPRESSION:
			return resolveExpressionBinding(((PostfixExpression) expression).getOperand(), goIntoCast);
		default:
			return null;
	}
}
 
Example #25
Source File: ConstraintCollector.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(ArrayAccess node) {
	add(fCreator.create(node));
	return true;
}
 
Example #26
Source File: AstMatchingNodeFinder.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public boolean visit(ArrayAccess node) {
	if (node.subtreeMatch(fMatcher, fNodeToMatch))
		return matches(node);
	return super.visit(node);
}
 
Example #27
Source File: FlowAnalyzer.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void endVisit(ArrayAccess node) {
	if (skipNode(node))
		return;
	processSequential(node, node.getArray(), node.getIndex());
}
 
Example #28
Source File: SuperTypeConstraintsCreator.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public final void endVisit(final ArrayAccess node) {
	node.setProperty(PROPERTY_CONSTRAINT_VARIABLE, node.getArray().getProperty(PROPERTY_CONSTRAINT_VARIABLE));
}
 
Example #29
Source File: Visitor.java    From RefactoringMiner with MIT License 4 votes vote down vote up
private static boolean invalidArrayAccess(ArrayAccess e) {
	return e.getArray() instanceof SimpleName && simpleNameOrNumberLiteral(e.getIndex());
}
 
Example #30
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
@Override
public boolean visit(final PrefixExpression node) {
  final Expression operand = node.getOperand();
  PrefixExpression.Operator _operator = node.getOperator();
  boolean _matched = false;
  if (Objects.equal(_operator, PrefixExpression.Operator.DECREMENT)) {
    _matched=true;
  }
  if (!_matched) {
    if (Objects.equal(_operator, PrefixExpression.Operator.INCREMENT)) {
      _matched=true;
    }
  }
  if (_matched) {
    if ((operand instanceof ArrayAccess)) {
      final String arrayName = this.computeArrayName(((ArrayAccess)operand));
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("_tPreInx_");
      _builder.append(arrayName);
      final String idxName = _builder.toString();
      String op = "-";
      PrefixExpression.Operator _operator_1 = node.getOperator();
      boolean _equals = Objects.equal(_operator_1, PrefixExpression.Operator.INCREMENT);
      if (_equals) {
        op = "+";
      }
      StringConcatenation _builder_1 = new StringConcatenation();
      _builder_1.append("{val ");
      _builder_1.append(idxName);
      _builder_1.append("=");
      this.appendToBuffer(_builder_1.toString());
      ((ArrayAccess)operand).getIndex().accept(this);
      StringConcatenation _builder_2 = new StringConcatenation();
      _builder_2.append(" ");
      _builder_2.append("val ");
      _builder_2.append(idxName, " ");
      _builder_2.append("_res=");
      _builder_2.append(arrayName, " ");
      _builder_2.append(".get(");
      _builder_2.append(idxName, " ");
      _builder_2.append(")");
      _builder_2.append(op, " ");
      _builder_2.append("1");
      this.appendToBuffer(_builder_2.toString());
      StringConcatenation _builder_3 = new StringConcatenation();
      _builder_3.append(" ");
      _builder_3.append(arrayName, " ");
      _builder_3.append(".set(");
      _builder_3.append(idxName, " ");
      _builder_3.append(", ");
      _builder_3.append(idxName, " ");
      _builder_3.append("_res)  ");
      _builder_3.append(idxName, " ");
      _builder_3.append("_res}");
      this.appendToBuffer(_builder_3.toString());
      return false;
    } else {
      final AST dummyAST = AST.newAST(node.getAST().apiLevel());
      final Assignment assigment = dummyAST.newAssignment();
      final InfixExpression infixOp = dummyAST.newInfixExpression();
      ASTNode _copySubtree = ASTNode.copySubtree(dummyAST, operand);
      infixOp.setLeftOperand(((Expression) _copySubtree));
      PrefixExpression.Operator _operator_2 = node.getOperator();
      boolean _equals_1 = Objects.equal(_operator_2, PrefixExpression.Operator.DECREMENT);
      if (_equals_1) {
        infixOp.setOperator(InfixExpression.Operator.MINUS);
      } else {
        infixOp.setOperator(InfixExpression.Operator.PLUS);
      }
      infixOp.setRightOperand(dummyAST.newNumberLiteral("1"));
      ASTNode _copySubtree_1 = ASTNode.copySubtree(dummyAST, operand);
      final Expression leftSide = ((Expression) _copySubtree_1);
      assigment.setLeftHandSide(leftSide);
      assigment.setRightHandSide(infixOp);
      this.appendToBuffer("{");
      Type type = null;
      if ((operand instanceof SimpleName)) {
        type = this._aSTFlattenerUtils.findDeclaredType(((SimpleName)operand));
      }
      this.handleAssignment(assigment, leftSide, type);
      this.appendToBuffer("}");
      return false;
    }
  }
  if (!_matched) {
    if (Objects.equal(_operator, PrefixExpression.Operator.COMPLEMENT)) {
      _matched=true;
      node.getOperand().accept(this);
      this.appendToBuffer(".bitwiseNot");
    }
  }
  if (!_matched) {
    {
      this.appendToBuffer(node.getOperator().toString());
      node.getOperand().accept(this);
    }
  }
  return false;
}