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


Java Assignment.setOperator方法代码示例

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


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

示例1: 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

示例2: 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

示例3: getForBodyAssignment

import org.eclipse.jdt.core.dom.Assignment; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:eclipse,项目名称:che,代码行数:46,代码来源:GenerateForLoopAssistProposal.java

示例4: getIndexBasedForBodyAssignment

import org.eclipse.jdt.core.dom.Assignment; //导入方法依赖的package包/类
/**
 * Creates an {@link Assignment} as first expression appearing in an index based <code>for</code>
 * loop's body. This Assignment declares a local variable and initializes it using the {@link
 * List}'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 Expression getIndexBasedForBodyAssignment(
    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
  MethodInvocation invokeGetExpression = ast.newMethodInvocation();
  invokeGetExpression.setName(ast.newSimpleName("get")); // $NON-NLS-1$
  SimpleName indexVariableName = ast.newSimpleName(loopVariableName.getIdentifier());
  addLinkedPosition(
      rewrite.track(indexVariableName),
      LinkedPositionGroup.NO_STOP,
      indexVariableName.getIdentifier());
  invokeGetExpression.arguments().add(indexVariableName);
  invokeGetExpression.setExpression((Expression) rewrite.createCopyTarget(fCurrentExpression));
  assignResolvedVariable.setRightHandSide(invokeGetExpression);

  assignResolvedVariable.setOperator(Assignment.Operator.ASSIGN);

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

示例5: 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:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:36,代码来源:GenerateForLoopAssistProposal.java

示例6: 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:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:16,代码来源:ConvertAnonymousToNestedRefactoring.java

示例7: createAssignmentStatement

import org.eclipse.jdt.core.dom.Assignment; //导入方法依赖的package包/类
private static Statement createAssignmentStatement(ASTRewrite rewrite, Assignment.Operator assignmentOperator, Expression origAssignee, Expression origAssigned) {
	AST ast= rewrite.getAST();
	Assignment elseAssignment= ast.newAssignment();
	elseAssignment.setOperator(assignmentOperator);
	elseAssignment.setLeftHandSide((Expression) rewrite.createCopyTarget(origAssignee));
	elseAssignment.setRightHandSide((Expression) rewrite.createCopyTarget(origAssigned));
	ExpressionStatement statement= ast.newExpressionStatement(elseAssignment);
	return statement;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:10,代码来源:AdvancedQuickAssistProcessor.java

示例8: getForBodyAssignment

import org.eclipse.jdt.core.dom.Assignment; //导入方法依赖的package包/类
/**
 * 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;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:37,代码来源:GenerateForLoopAssistProposal.java

示例9: getIndexBasedForBodyAssignment

import org.eclipse.jdt.core.dom.Assignment; //导入方法依赖的package包/类
/**
 * Creates an {@link Assignment} as first expression appearing in an index based
 * <code>for</code> loop's body. This Assignment declares a local variable and initializes it
 * using the {@link List}'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 Expression getIndexBasedForBodyAssignment(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
	MethodInvocation invokeGetExpression= ast.newMethodInvocation();
	invokeGetExpression.setName(ast.newSimpleName("get")); //$NON-NLS-1$
	SimpleName indexVariableName= ast.newSimpleName(loopVariableName.getIdentifier());
	addLinkedPosition(rewrite.track(indexVariableName), LinkedPositionGroup.NO_STOP, indexVariableName.getIdentifier());
	invokeGetExpression.arguments().add(indexVariableName);
	invokeGetExpression.setExpression((Expression) rewrite.createCopyTarget(fCurrentExpression));
	assignResolvedVariable.setRightHandSide(invokeGetExpression);

	assignResolvedVariable.setOperator(Assignment.Operator.ASSIGN);

	return assignResolvedVariable;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:38,代码来源:GenerateForLoopAssistProposal.java

示例10: createConstructorStub

import org.eclipse.jdt.core.dom.Assignment; //导入方法依赖的package包/类
public static MethodDeclaration createConstructorStub(ICompilationUnit unit, ASTRewrite rewrite, ImportRewrite imports, ImportRewriteContext context, ITypeBinding typeBinding, IMethodBinding superConstructor, IVariableBinding[] variableBindings, int modifiers, CodeGenerationSettings settings) throws CoreException {
	AST ast= rewrite.getAST();

	MethodDeclaration decl= ast.newMethodDeclaration();
	decl.modifiers().addAll(ASTNodeFactory.newModifiers(ast, modifiers & ~Modifier.ABSTRACT & ~Modifier.NATIVE));
	decl.setName(ast.newSimpleName(typeBinding.getName()));
	decl.setConstructor(true);

	List<SingleVariableDeclaration> parameters= decl.parameters();
	if (superConstructor != null) {
		createTypeParameters(imports, context, ast, superConstructor, decl);

		createParameters(unit.getJavaProject(), imports, context, ast, superConstructor, null, decl);

		createThrownExceptions(decl, superConstructor, imports, context, ast);
	}

	Block body= ast.newBlock();
	decl.setBody(body);

	String delimiter= StubUtility.getLineDelimiterUsed(unit);

	if (superConstructor != null) {
		SuperConstructorInvocation invocation= ast.newSuperConstructorInvocation();
		SingleVariableDeclaration varDecl= null;
		for (Iterator<SingleVariableDeclaration> iterator= parameters.iterator(); iterator.hasNext();) {
			varDecl= iterator.next();
			invocation.arguments().add(ast.newSimpleName(varDecl.getName().getIdentifier()));
		}
		body.statements().add(invocation);
	}

	List<String> prohibited= new ArrayList<String>();
	for (final Iterator<SingleVariableDeclaration> iterator= parameters.iterator(); iterator.hasNext();)
		prohibited.add(iterator.next().getName().getIdentifier());
	String param= null;
	List<String> list= new ArrayList<String>(prohibited);
	String[] excluded= null;
	for (int i= 0; i < variableBindings.length; i++) {
		SingleVariableDeclaration var= ast.newSingleVariableDeclaration();
		var.setType(imports.addImport(variableBindings[i].getType(), ast, context));
		excluded= new String[list.size()];
		list.toArray(excluded);
		param= suggestParameterName(unit, variableBindings[i], excluded);
		list.add(param);
		var.setName(ast.newSimpleName(param));
		parameters.add(var);
	}

	list= new ArrayList<String>(prohibited);
	for (int i= 0; i < variableBindings.length; i++) {
		excluded= new String[list.size()];
		list.toArray(excluded);
		final String paramName= suggestParameterName(unit, variableBindings[i], excluded);
		list.add(paramName);
		final String fieldName= variableBindings[i].getName();
		Expression expression= null;
		if (paramName.equals(fieldName) || settings.useKeywordThis) {
			FieldAccess access= ast.newFieldAccess();
			access.setExpression(ast.newThisExpression());
			access.setName(ast.newSimpleName(fieldName));
			expression= access;
		} else
			expression= ast.newSimpleName(fieldName);
		Assignment assignment= ast.newAssignment();
		assignment.setLeftHandSide(expression);
		assignment.setRightHandSide(ast.newSimpleName(paramName));
		assignment.setOperator(Assignment.Operator.ASSIGN);
		body.statements().add(ast.newExpressionStatement(assignment));
	}

	if (settings != null && settings.createComments) {
		String string= CodeGeneration.getMethodComment(unit, typeBinding.getName(), decl, superConstructor, delimiter);
		if (string != null) {
			Javadoc javadoc= (Javadoc) rewrite.createStringPlaceholder(string, ASTNode.JAVADOC);
			decl.setJavadoc(javadoc);
		}
	}
	return decl;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:81,代码来源:StubUtility2.java


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