当前位置: 首页>>代码示例>>Java>>正文


Java Assignment类代码示例

本文整理汇总了Java中org.eclipse.jdt.core.dom.Assignment的典型用法代码示例。如果您正苦于以下问题:Java Assignment类的具体用法?Java Assignment怎么用?Java Assignment使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Assignment类属于org.eclipse.jdt.core.dom包,在下文中一共展示了Assignment类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isAcumulationAssign

import org.eclipse.jdt.core.dom.Assignment; //导入依赖的package包/类
private static boolean isAcumulationAssign(Assignment assignment, InfixExpression.Operator op, Predicate<Expression> acceptExpression) {
	if(!(
			assignment.getRightHandSide() instanceof InfixExpression && 
			assignment.getLeftHandSide() instanceof SimpleName &&
			assignment.getOperator() == Assignment.Operator.ASSIGN))
		return false;

	InfixExpression exp = (InfixExpression) assignment.getRightHandSide();
	if(exp.getOperator() != op)
		return false;

	String assignVar = assignment.getLeftHandSide().toString();
	if(	exp.getLeftOperand() instanceof SimpleName &&
			exp.getLeftOperand().toString().equals(assignVar) &&
			acceptExpression.test(exp.getRightOperand()))
		return true;

	if(	exp.getRightOperand() instanceof SimpleName && 
			exp.getRightOperand().toString().equals(assignVar) &&
			acceptExpression.test(exp.getLeftOperand()))
		return true;

	return false;
}
 
开发者ID:andre-santos-pt,项目名称:pandionj,代码行数:25,代码来源:VarParser.java

示例2: createWithMethodBody

import org.eclipse.jdt.core.dom.Assignment; //导入依赖的package包/类
private Block createWithMethodBody(AST ast, BuilderField builderField) {
    String originalFieldName = builderField.getOriginalFieldName();
    String builderFieldName = builderField.getBuilderFieldName();

    Block newBlock = ast.newBlock();
    ReturnStatement builderReturnStatement = ast.newReturnStatement();
    builderReturnStatement.setExpression(ast.newThisExpression());

    Assignment newAssignment = ast.newAssignment();

    FieldAccess fieldAccess = ast.newFieldAccess();
    fieldAccess.setExpression(ast.newThisExpression());
    fieldAccess.setName(ast.newSimpleName(originalFieldName));
    newAssignment.setLeftHandSide(fieldAccess);
    newAssignment.setRightHandSide(ast.newSimpleName(builderFieldName));

    newBlock.statements().add(ast.newExpressionStatement(newAssignment));
    newBlock.statements().add(builderReturnStatement);
    return newBlock;
}
 
开发者ID:helospark,项目名称:SparkBuilderGenerator,代码行数:21,代码来源:StagedBuilderWithMethodAdderFragment.java

示例3: createWithMethodBody

import org.eclipse.jdt.core.dom.Assignment; //导入依赖的package包/类
private Block createWithMethodBody(AST ast, String originalFieldName, String builderFieldName) {
    Block newBlock = ast.newBlock();
    ReturnStatement builderReturnStatement = ast.newReturnStatement();
    builderReturnStatement.setExpression(ast.newThisExpression());

    Assignment newAssignment = ast.newAssignment();

    FieldAccess fieldAccess = ast.newFieldAccess();
    fieldAccess.setExpression(ast.newThisExpression());
    fieldAccess.setName(ast.newSimpleName(originalFieldName));
    newAssignment.setLeftHandSide(fieldAccess);
    newAssignment.setRightHandSide(ast.newSimpleName(builderFieldName));

    newBlock.statements().add(ast.newExpressionStatement(newAssignment));
    newBlock.statements().add(builderReturnStatement);
    return newBlock;
}
 
开发者ID:helospark,项目名称:SparkBuilderGenerator,代码行数:18,代码来源:RegularBuilderWithMethodAdderFragment.java

示例4: getAssignedVariable

import org.eclipse.jdt.core.dom.Assignment; //导入依赖的package包/类
/**
 * Returns the binding of the variable written in an Assignment.
 * @param assignment The assignment
 * @return The binding or <code>null</code> if no bindings are available.
 */
public static IVariableBinding getAssignedVariable(Assignment assignment) {
	Expression leftHand = assignment.getLeftHandSide();
	switch (leftHand.getNodeType()) {
	case ASTNode.SIMPLE_NAME:
		return (IVariableBinding) ((SimpleName) leftHand).resolveBinding();
	case ASTNode.QUALIFIED_NAME:
		return (IVariableBinding) ((QualifiedName) leftHand).getName().resolveBinding();
	case ASTNode.FIELD_ACCESS:
		return ((FieldAccess) leftHand).resolveFieldBinding();
	case ASTNode.SUPER_FIELD_ACCESS:
		return ((SuperFieldAccess) leftHand).resolveFieldBinding();
	default:
		return null;
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:21,代码来源:Bindings.java

示例5: isLeftHandSideOfAssignment

import org.eclipse.jdt.core.dom.Assignment; //导入依赖的package包/类
static boolean isLeftHandSideOfAssignment(ASTNode node) {
	Assignment assignment = (Assignment) ASTNodes.getParent(node, ASTNode.ASSIGNMENT);
	if (assignment != null) {
		Expression leftHandSide = assignment.getLeftHandSide();
		if (leftHandSide == node) {
			return true;
		}
		if (ASTNodes.isParent(node, leftHandSide)) {
			switch (leftHandSide.getNodeType()) {
				case ASTNode.SIMPLE_NAME:
					return true;
				case ASTNode.FIELD_ACCESS:
					return node == ((FieldAccess) leftHandSide).getName();
				case ASTNode.QUALIFIED_NAME:
					return node == ((QualifiedName) leftHandSide).getName();
				case ASTNode.SUPER_FIELD_ACCESS:
					return node == ((SuperFieldAccess) leftHandSide).getName();
				default:
					return false;
			}
		}
	}
	return false;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:25,代码来源:SnippetFinder.java

示例6: endVisit

import org.eclipse.jdt.core.dom.Assignment; //导入依赖的package包/类
@Override
public void endVisit(Assignment node) {
	if (skipNode(node)) {
		return;
	}
	FlowInfo lhs = getFlowInfo(node.getLeftHandSide());
	FlowInfo rhs = getFlowInfo(node.getRightHandSide());
	if (lhs instanceof LocalFlowInfo) {
		LocalFlowInfo llhs = (LocalFlowInfo) lhs;
		llhs.setWriteAccess(fFlowContext);
		if (node.getOperator() != Assignment.Operator.ASSIGN) {
			GenericSequentialFlowInfo tmp = createSequential();
			tmp.merge(new LocalFlowInfo(llhs, FlowInfo.READ, fFlowContext), fFlowContext);
			tmp.merge(rhs, fFlowContext);
			rhs = tmp;
		}
	}
	GenericSequentialFlowInfo info = createSequential(node);
	// first process right and side and then left hand side.
	info.merge(rhs, fFlowContext);
	info.merge(lhs, fFlowContext);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:23,代码来源:FlowAnalyzer.java

示例7: getLeftHandSideVarBinding

import org.eclipse.jdt.core.dom.Assignment; //导入依赖的package包/类
/**
 * for an assignment x = y returns the variable binding of x
 * 
 * @param varBinding
 * @param assignment
 * @return
 */
private static IVariableBinding getLeftHandSideVarBinding(Assignment assignment) {
	Expression leftHnsd = assignment.getLeftHandSide();
	if (leftHnsd instanceof SimpleName) {
		IBinding bind = ((SimpleName) leftHnsd).resolveBinding();
		if (bind instanceof IVariableBinding) {
			return ((IVariableBinding) bind).getVariableDeclaration();
		}
	}
	if (leftHnsd instanceof FieldAccess) {
		FieldAccess fa = (FieldAccess) leftHnsd;
		return fa.resolveFieldBinding();
	}
	// Leave it null - cannot determine actual domains for arrays
	// workaround for bugs related to objects created in complex expression
	// if (leftHnsd instanceof ArrayAccess) {
	// ArrayAccess aa = (ArrayAccess) leftHnsd;
	// return getArrayAccessVarBinding(aa);
	// }
	return null;
}
 
开发者ID:aroog,项目名称:code,代码行数:28,代码来源:Utils.java

示例8: getSimpleAssignName

import org.eclipse.jdt.core.dom.Assignment; //导入依赖的package包/类
/**
 * returns the name associated with an assignment instruction
 * 
 * @param instr
 * @return
 */
public static String getSimpleAssignName(AssignmentInstruction instr) {
	if (instr instanceof LoadLiteralInstruction)
		return ((LoadLiteralInstruction) instr).getLiteral().toString();
	ASTNode parentInstr = instr.getNode().getParent();

	if (parentInstr instanceof VariableDeclarationFragment) {
		return ((VariableDeclarationFragment) parentInstr).getName().getFullyQualifiedName();
	}
	if (parentInstr instanceof Assignment) {
		Expression leftHnsd = ((Assignment) parentInstr).getLeftHandSide();
		if (leftHnsd instanceof SimpleName) {
			return ((SimpleName) leftHnsd).getFullyQualifiedName();
		}
		else if (leftHnsd instanceof FieldAccess) {
			return ((FieldAccess) leftHnsd).getName().getFullyQualifiedName();
		}
	}
	throw new IllegalStateException("cannot find local variable associated with " + instr);
}
 
开发者ID:aroog,项目名称:code,代码行数:26,代码来源:Utils.java

示例9: createFrom

import org.eclipse.jdt.core.dom.Assignment; //导入依赖的package包/类
public static FieldWrite createFrom(ASTNode node){
	FieldWrite retNode = null;
	boolean compatibleType = false;
	if(node instanceof Assignment){
		compatibleType = true;
	} else if (node instanceof VariableDeclarationFragment){
		VariableDeclarationFragment vdf = (VariableDeclarationFragment)node;
		if (vdf.getInitializer()!=null){
			compatibleType = true;
		}
	} 
	if (compatibleType){
		Adapter factory = Adapter.getInstance();

		AstNode astNode = factory.get(node);
		if ( astNode instanceof FieldWrite ) {
			retNode = (FieldWrite)astNode;
		}
		else {
			retNode = FieldWrite.create();
			retNode.complexExpression = node.toString();
			factory.map(node, retNode);
		}
	} else {
		throw new IllegalArgumentException();
	}
	return retNode;
}
 
开发者ID:aroog,项目名称:code,代码行数:29,代码来源:FieldWrite.java

示例10: getAssignedVariable

import org.eclipse.jdt.core.dom.Assignment; //导入依赖的package包/类
/**
 * Returns the binding of the variable written in an Assignment.
 *
 * @param assignment The assignment
 * @return The binding or <code>null</code> if no bindings are available.
 */
public static IVariableBinding getAssignedVariable(Assignment assignment) {
  Expression leftHand = assignment.getLeftHandSide();
  switch (leftHand.getNodeType()) {
    case ASTNode.SIMPLE_NAME:
      return (IVariableBinding) ((SimpleName) leftHand).resolveBinding();
    case ASTNode.QUALIFIED_NAME:
      return (IVariableBinding) ((QualifiedName) leftHand).getName().resolveBinding();
    case ASTNode.FIELD_ACCESS:
      return ((FieldAccess) leftHand).resolveFieldBinding();
    case ASTNode.SUPER_FIELD_ACCESS:
      return ((SuperFieldAccess) leftHand).resolveFieldBinding();
    default:
      return null;
  }
}
 
开发者ID:eclipse,项目名称:che,代码行数:22,代码来源:Bindings.java

示例11: newFieldAssignment

import org.eclipse.jdt.core.dom.Assignment; //导入依赖的package包/类
private Statement newFieldAssignment(
    AST ast, SimpleName fieldNameNode, Expression initializer, boolean useThisAccess) {
  Assignment assignment = ast.newAssignment();
  if (useThisAccess) {
    FieldAccess access = ast.newFieldAccess();
    access.setExpression(ast.newThisExpression());
    access.setName(fieldNameNode);
    assignment.setLeftHandSide(access);
  } else {
    assignment.setLeftHandSide(fieldNameNode);
  }
  assignment.setOperator(Assignment.Operator.ASSIGN);
  assignment.setRightHandSide(initializer);

  return ast.newExpressionStatement(assignment);
}
 
开发者ID:eclipse,项目名称:che,代码行数:17,代码来源:ConvertAnonymousToNestedRefactoring.java

示例12: isLeftHandSideOfAssignment

import org.eclipse.jdt.core.dom.Assignment; //导入依赖的package包/类
private static boolean isLeftHandSideOfAssignment(ASTNode node) {
  Assignment assignment = (Assignment) ASTNodes.getParent(node, ASTNode.ASSIGNMENT);
  if (assignment != null) {
    Expression leftHandSide = assignment.getLeftHandSide();
    if (leftHandSide == node) {
      return true;
    }
    if (ASTNodes.isParent(node, leftHandSide)) {
      switch (leftHandSide.getNodeType()) {
        case ASTNode.SIMPLE_NAME:
          return true;
        case ASTNode.FIELD_ACCESS:
          return node == ((FieldAccess) leftHandSide).getName();
        case ASTNode.QUALIFIED_NAME:
          return node == ((QualifiedName) leftHandSide).getName();
        case ASTNode.SUPER_FIELD_ACCESS:
          return node == ((SuperFieldAccess) leftHandSide).getName();
        default:
          return false;
      }
    }
  }
  return false;
}
 
开发者ID:eclipse,项目名称:che,代码行数:25,代码来源:SnippetFinder.java

示例13: resolveBinding

import org.eclipse.jdt.core.dom.Assignment; //导入依赖的package包/类
public static IBinding resolveBinding(Expression expression) {
  if (expression instanceof Name) return ((Name) expression).resolveBinding();
  if (expression instanceof ParenthesizedExpression)
    return resolveBinding(((ParenthesizedExpression) expression).getExpression());
  else if (expression instanceof Assignment)
    return resolveBinding(((Assignment) expression).getLeftHandSide()); // TODO ???
  else if (expression instanceof MethodInvocation)
    return ((MethodInvocation) expression).resolveMethodBinding();
  else if (expression instanceof SuperMethodInvocation)
    return ((SuperMethodInvocation) expression).resolveMethodBinding();
  else if (expression instanceof FieldAccess)
    return ((FieldAccess) expression).resolveFieldBinding();
  else if (expression instanceof SuperFieldAccess)
    return ((SuperFieldAccess) expression).resolveFieldBinding();
  else if (expression instanceof ConditionalExpression)
    return resolveBinding(((ConditionalExpression) expression).getThenExpression());
  return null;
}
 
开发者ID:eclipse,项目名称:che,代码行数:19,代码来源:ExpressionVariable.java

示例14: generateIteratorBasedForRewrite

import org.eclipse.jdt.core.dom.Assignment; //导入依赖的package包/类
/**
 * Helper to generate an iterator based <code>for</code> loop to iterate over an {@link Iterable}.
 *
 * @param ast the {@link AST} instance to rewrite the loop to
 * @return the complete {@link ASTRewrite} object
 */
private ASTRewrite generateIteratorBasedForRewrite(AST ast) {
  ASTRewrite rewrite = ASTRewrite.create(ast);
  ForStatement loopStatement = ast.newForStatement();

  ITypeBinding loopOverType = extractElementType(ast);

  SimpleName loopVariableName =
      resolveLinkedVariableNameWithProposals(rewrite, "iterator", null, true); // $NON-NLS-1$
  loopStatement.initializers().add(getIteratorBasedForInitializer(rewrite, loopVariableName));

  MethodInvocation loopExpression = ast.newMethodInvocation();
  loopExpression.setName(ast.newSimpleName("hasNext")); // $NON-NLS-1$
  SimpleName expressionName = ast.newSimpleName(loopVariableName.getIdentifier());
  addLinkedPosition(
      rewrite.track(expressionName), LinkedPositionGroup.NO_STOP, expressionName.getIdentifier());
  loopExpression.setExpression(expressionName);

  loopStatement.setExpression(loopExpression);

  Block forLoopBody = ast.newBlock();
  Assignment assignResolvedVariable =
      getIteratorBasedForBodyAssignment(rewrite, loopOverType, loopVariableName);
  forLoopBody.statements().add(ast.newExpressionStatement(assignResolvedVariable));
  forLoopBody.statements().add(createBlankLineStatementWithCursorPosition(rewrite));

  loopStatement.setBody(forLoopBody);

  rewrite.replace(fCurrentNode, loopStatement, null);

  return rewrite;
}
 
开发者ID:eclipse,项目名称:che,代码行数:38,代码来源:GenerateForLoopAssistProposal.java

示例15: getIteratorBasedForBodyAssignment

import org.eclipse.jdt.core.dom.Assignment; //导入依赖的package包/类
/**
 * Generates the Assignment in an iterator based for, used in the first statement of an iterator
 * based <code>for</code> loop body, to retrieve the next element of the {@link Iterable}
 * instance.
 *
 * @param rewrite the current instance of {@link ASTRewrite}
 * @param loopOverType the {@link ITypeBinding} of the loop variable
 * @param loopVariableName the name of the loop variable
 * @return an {@link Assignment}, which retrieves the next element of the {@link Iterable} using
 *     the active {@link Iterator}
 */
private Assignment getIteratorBasedForBodyAssignment(
    ASTRewrite rewrite, ITypeBinding loopOverType, SimpleName loopVariableName) {
  AST ast = rewrite.getAST();
  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
  MethodInvocation invokeIteratorNextExpression = ast.newMethodInvocation();
  invokeIteratorNextExpression.setName(ast.newSimpleName("next")); // $NON-NLS-1$
  SimpleName currentElementName = ast.newSimpleName(loopVariableName.getIdentifier());
  addLinkedPosition(
      rewrite.track(currentElementName),
      LinkedPositionGroup.NO_STOP,
      currentElementName.getIdentifier());
  invokeIteratorNextExpression.setExpression(currentElementName);
  assignResolvedVariable.setRightHandSide(invokeIteratorNextExpression);

  assignResolvedVariable.setOperator(Assignment.Operator.ASSIGN);

  return assignResolvedVariable;
}
 
开发者ID:eclipse,项目名称:che,代码行数:49,代码来源:GenerateForLoopAssistProposal.java


注:本文中的org.eclipse.jdt.core.dom.Assignment类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。