• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java CastExpression类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: createUnobservedInitStmt

import org.eclipse.jdt.core.dom.CastExpression; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private void createUnobservedInitStmt(final int logRecNo, final Block methodBlock, final AST ast)
{
	// NOTE: PLAIN INIT: has always one non-null param
	// TODO: use primitives
	final int    oid     = this.log.objectIds.get(logRecNo);
	final String type    = this.log.oidClassNames.get(this.log.oidRecMapping.get(oid));
	final Object value   = this.log.params.get(logRecNo)[0];
	this.isXStreamNeeded = true;
	
	final VariableDeclarationFragment vd = ast.newVariableDeclarationFragment();
	// handling because there must always be a new instantiation statement for pseudo inits
	this.oidToVarMapping.remove(oid);
	vd.setName(ast.newSimpleName(this.createNewVarName(oid, type)));
	
	final MethodInvocation methodInvocation = ast.newMethodInvocation();
	final Name name = ast.newSimpleName("XSTREAM");
	methodInvocation.setExpression(name);
	methodInvocation.setName(ast.newSimpleName("fromXML")); 
	
	final StringLiteral xmlParam = ast.newStringLiteral();
	xmlParam.setLiteralValue((String) value);
	methodInvocation.arguments().add(xmlParam);
	
	final CastExpression castExpr = ast.newCastExpression();
	castExpr.setType(this.createAstType(type, ast));
	castExpr.setExpression(methodInvocation);
	
	vd.setInitializer(castExpr);
	
	final VariableDeclarationStatement vs = ast.newVariableDeclarationStatement(vd);
	vs.setType(this.createAstType(type, ast));
			
	methodBlock.statements().add(vs);
}
 
开发者ID:EvoSuite,项目名称:evosuite,代码行数:36,代码来源:CodeGenerator.java


示例2: getNewCastTypeNode

import org.eclipse.jdt.core.dom.CastExpression; //导入依赖的package包/类
private Type getNewCastTypeNode(ASTRewrite rewrite, ImportRewrite importRewrite) {
	AST ast= rewrite.getAST();

	ImportRewriteContext context= new ContextSensitiveImportRewriteContext((CompilationUnit) fNodeToCast.getRoot(), fNodeToCast.getStartPosition(), importRewrite);

	if (fCastType != null) {
		return importRewrite.addImport(fCastType, ast,context, TypeLocation.CAST);
	}

	ASTNode node= fNodeToCast;
	ASTNode parent= node.getParent();
	if (parent instanceof CastExpression) {
		node= parent;
		parent= parent.getParent();
	}
	while (parent instanceof ParenthesizedExpression) {
		node= parent;
		parent= parent.getParent();
	}
	if (parent instanceof MethodInvocation) {
		MethodInvocation invocation= (MethodInvocation) node.getParent();
		if (invocation.getExpression() == node) {
			IBinding targetContext= ASTResolving.getParentMethodOrTypeBinding(node);
			ITypeBinding[] bindings= ASTResolving.getQualifierGuess(node.getRoot(), invocation.getName().getIdentifier(), invocation.arguments(), targetContext);
			if (bindings.length > 0) {
				ITypeBinding first= getCastFavorite(bindings, fNodeToCast.resolveTypeBinding());

				Type newTypeNode= importRewrite.addImport(first, ast, context, TypeLocation.CAST);
				return newTypeNode;
			}
		}
	}
	Type newCastType= ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
	return newCastType;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:36,代码来源:CastCorrectionProposal.java


示例3: visit

import org.eclipse.jdt.core.dom.CastExpression; //导入依赖的package包/类
public boolean visit(CastExpression node) {
	if (mtbStack.isEmpty()) // not part of a method
		return true;

	Expression expression = node.getExpression();
	ITypeBinding type = node.getType().resolveBinding();
	IMethodBinding mtb = mtbStack.peek();
	String exprStr = expression.toString();
	String typeStr = getQualifiedName(type);
	String methodStr = getQualifiedName(mtb);

	exprStr = edit_str(exprStr);

	facts.add(Fact.makeCastFact(exprStr, typeStr, methodStr));

	return true;
}
 
开发者ID:aserg-ufmg,项目名称:RefDiff,代码行数:18,代码来源:ASTVisitorAtomicChange.java


示例4: rewriteAST

import org.eclipse.jdt.core.dom.CastExpression; //导入依赖的package包/类
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException {

	TextEditGroup group= createTextEditGroup(FixMessages.UnusedCodeFix_RemoveCast_description, cuRewrite);

	ASTRewrite rewrite= cuRewrite.getASTRewrite();

	CastExpression cast= fCast;
	Expression expression= cast.getExpression();
	if (expression instanceof ParenthesizedExpression) {
		Expression childExpression= ((ParenthesizedExpression) expression).getExpression();
		if (NecessaryParenthesesChecker.needsParentheses(childExpression, cast, CastExpression.EXPRESSION_PROPERTY)) {
			expression= childExpression;
		}
	}

	replaceCast(cast, expression, rewrite, group);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:19,代码来源:UnusedCodeFix.java


示例5: createRemoveUnusedCastFix

import org.eclipse.jdt.core.dom.CastExpression; //导入依赖的package包/类
public static UnusedCodeFix createRemoveUnusedCastFix(CompilationUnit compilationUnit, IProblemLocation problem) {
	if (problem.getProblemId() != IProblem.UnnecessaryCast) {
		return null;
	}

	ASTNode selectedNode= problem.getCoveringNode(compilationUnit);

	ASTNode curr= selectedNode;
	while (curr instanceof ParenthesizedExpression) {
		curr= ((ParenthesizedExpression) curr).getExpression();
	}

	if (!(curr instanceof CastExpression)) {
		return null;
	}

	return new UnusedCodeFix(FixMessages.UnusedCodeFix_RemoveCast_description, compilationUnit, new CompilationUnitRewriteOperation[] {new RemoveCastOperation((CastExpression)curr)});
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:19,代码来源:UnusedCodeFix.java


示例6: replaceCast

import org.eclipse.jdt.core.dom.CastExpression; //导入依赖的package包/类
private static void replaceCast(CastExpression castExpression, Expression replacement, ASTRewrite rewrite, TextEditGroup group) {
	boolean castEnclosedInNecessaryParentheses= castExpression.getParent() instanceof ParenthesizedExpression
			&& NecessaryParenthesesChecker.needsParentheses(castExpression, castExpression.getParent().getParent(), castExpression.getParent().getLocationInParent());

	ASTNode toReplace= castEnclosedInNecessaryParentheses ? castExpression.getParent() : castExpression;
	ASTNode move;
	if (NecessaryParenthesesChecker.needsParentheses(replacement, toReplace.getParent(), toReplace.getLocationInParent())) {
		if (replacement.getParent() instanceof ParenthesizedExpression) {
			move= rewrite.createMoveTarget(replacement.getParent());
		} else if (castEnclosedInNecessaryParentheses) {
			toReplace= castExpression;
			move= rewrite.createMoveTarget(replacement);
		} else {
			ParenthesizedExpression parentheses= replacement.getAST().newParenthesizedExpression();
			parentheses.setExpression((Expression) rewrite.createMoveTarget(replacement));
			move= parentheses;
		}
	} else {
		move= rewrite.createMoveTarget(replacement);
	}
	rewrite.replace(toReplace, move, group);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:23,代码来源:UnusedCodeFix.java


示例7: visit

import org.eclipse.jdt.core.dom.CastExpression; //导入依赖的package包/类
public boolean visit(CastExpression node)
{
  if (this.mtbStack.isEmpty()) {
    return true;
  }
  Expression expression = node.getExpression();
  ITypeBinding type = node.getType().resolveBinding();
  IMethodBinding mtb = (IMethodBinding)this.mtbStack.peek();
  String exprStr = expression.toString();
  String typeStr = getQualifiedName(type);
  String methodStr = getQualifiedName(mtb);
  
  exprStr = edit_str(exprStr);
  
  this.facts.add(Fact.makeCastFact(exprStr, typeStr, methodStr));
  
  return true;
}
 
开发者ID:SEAL-UCLA,项目名称:Ref-Finder,代码行数:19,代码来源:ASTVisitorAtomicChange.java


示例8: rewriteAST

import org.eclipse.jdt.core.dom.CastExpression; //导入依赖的package包/类
/** {@inheritDoc} */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model)
    throws CoreException {

  TextEditGroup group =
      createTextEditGroup(FixMessages.UnusedCodeFix_RemoveCast_description, cuRewrite);

  ASTRewrite rewrite = cuRewrite.getASTRewrite();

  CastExpression cast = fCast;
  Expression expression = cast.getExpression();
  if (expression instanceof ParenthesizedExpression) {
    Expression childExpression = ((ParenthesizedExpression) expression).getExpression();
    if (NecessaryParenthesesChecker.needsParentheses(
        childExpression, cast, CastExpression.EXPRESSION_PROPERTY)) {
      expression = childExpression;
    }
  }

  replaceCast(cast, expression, rewrite, group);
}
 
开发者ID:eclipse,项目名称:che,代码行数:23,代码来源:UnusedCodeFix.java


示例9: createRemoveUnusedCastFix

import org.eclipse.jdt.core.dom.CastExpression; //导入依赖的package包/类
public static UnusedCodeFix createRemoveUnusedCastFix(
    CompilationUnit compilationUnit, IProblemLocation problem) {
  if (problem.getProblemId() != IProblem.UnnecessaryCast) return null;

  ASTNode selectedNode = problem.getCoveringNode(compilationUnit);

  ASTNode curr = selectedNode;
  while (curr instanceof ParenthesizedExpression) {
    curr = ((ParenthesizedExpression) curr).getExpression();
  }

  if (!(curr instanceof CastExpression)) return null;

  return new UnusedCodeFix(
      FixMessages.UnusedCodeFix_RemoveCast_description,
      compilationUnit,
      new CompilationUnitRewriteOperation[] {new RemoveCastOperation((CastExpression) curr)});
}
 
开发者ID:eclipse,项目名称:che,代码行数:19,代码来源:UnusedCodeFix.java


示例10: create

import org.eclipse.jdt.core.dom.CastExpression; //导入依赖的package包/类
@Override
public ITypeConstraint[] create(CastExpression castExpression) {
  Expression expression = castExpression.getExpression();
  Type type = castExpression.getType();
  ITypeConstraint[] definesConstraint =
      fTypeConstraintFactory.createDefinesConstraint(
          fConstraintVariableFactory.makeExpressionOrTypeVariable(castExpression, getContext()),
          fConstraintVariableFactory.makeTypeVariable(castExpression.getType()));
  if (isClassBinding(expression.resolveTypeBinding()) && isClassBinding(type.resolveBinding())) {
    ConstraintVariable expressionVariable =
        fConstraintVariableFactory.makeExpressionOrTypeVariable(expression, getContext());
    ConstraintVariable castExpressionVariable =
        fConstraintVariableFactory.makeExpressionOrTypeVariable(castExpression, getContext());
    ITypeConstraint[] c2 =
        createOrOrSubtypeConstraint(expressionVariable, castExpressionVariable);
    if (definesConstraint.length == 0) {
      return c2;
    } else {
      ITypeConstraint c1 = definesConstraint[0];
      Collection<ITypeConstraint> constraints = new ArrayList<ITypeConstraint>();
      constraints.add(c1);
      constraints.addAll(Arrays.asList(c2));
      return constraints.toArray(new ITypeConstraint[constraints.size()]);
    }
  } else return definesConstraint;
}
 
开发者ID:eclipse,项目名称:che,代码行数:27,代码来源:FullConstraintCreator.java


示例11: create

import org.eclipse.jdt.core.dom.CastExpression; //导入依赖的package包/类
@Override
public ITypeConstraint[] create(CastExpression castExpression){
	Expression expression= castExpression.getExpression();
	Type type= castExpression.getType();
	ITypeConstraint[] definesConstraint= fTypeConstraintFactory.createDefinesConstraint(fConstraintVariableFactory.makeExpressionOrTypeVariable(castExpression, getContext()),
			                                                                        fConstraintVariableFactory.makeTypeVariable(castExpression.getType()));
	if (isClassBinding(expression.resolveTypeBinding()) && isClassBinding(type.resolveBinding())){
		ConstraintVariable expressionVariable= fConstraintVariableFactory.makeExpressionOrTypeVariable(expression, getContext());
		ConstraintVariable castExpressionVariable= fConstraintVariableFactory.makeExpressionOrTypeVariable(castExpression, getContext());
		ITypeConstraint[] c2 = createOrOrSubtypeConstraint(expressionVariable, castExpressionVariable);
		if (definesConstraint.length == 0){
			return c2;
		} else {
			ITypeConstraint c1 = definesConstraint[0];
			Collection<ITypeConstraint> constraints= new ArrayList<ITypeConstraint>();
			constraints.add(c1);
			constraints.addAll(Arrays.asList(c2));
			return constraints.toArray(new ITypeConstraint[constraints.size()]);
		}
	} else
		return definesConstraint;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:23,代码来源:FullConstraintCreator.java


示例12: createShiftAssignment

import org.eclipse.jdt.core.dom.CastExpression; //导入依赖的package包/类
private Expression createShiftAssignment(Expression shift1, Expression shift2) {
	// (int)(element ^ (element >>> 32));
	// see implementation in Arrays.hashCode(), Double.hashCode() and
	// Long.hashCode()
	CastExpression ce= fAst.newCastExpression();
	ce.setType(fAst.newPrimitiveType(PrimitiveType.INT));

	InfixExpression unsignedShiftRight= fAst.newInfixExpression();
	unsignedShiftRight.setLeftOperand(shift1);
	unsignedShiftRight.setRightOperand(fAst.newNumberLiteral("32")); //$NON-NLS-1$
	unsignedShiftRight.setOperator(Operator.RIGHT_SHIFT_UNSIGNED);

	InfixExpression xor= fAst.newInfixExpression();
	xor.setLeftOperand(shift2);
	xor.setRightOperand(parenthesize(unsignedShiftRight));
	xor.setOperator(InfixExpression.Operator.XOR);

	ce.setExpression(parenthesize(xor));
	return ce;
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:21,代码来源:GenerateHashCodeEqualsOperation.java


示例13: rewriteAST

import org.eclipse.jdt.core.dom.CastExpression; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException {

	TextEditGroup group= createTextEditGroup(FixMessages.UnusedCodeFix_RemoveCast_description, cuRewrite);

	ASTRewrite rewrite= cuRewrite.getASTRewrite();

	CastExpression cast= fCast;
	Expression expression= cast.getExpression();
	if (expression instanceof ParenthesizedExpression) {
		Expression childExpression= ((ParenthesizedExpression) expression).getExpression();
		if (NecessaryParenthesesChecker.needsParentheses(childExpression, cast, CastExpression.EXPRESSION_PROPERTY)) {
			expression= childExpression;
		}
	}
	
	replaceCast(cast, expression, rewrite, group);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:22,代码来源:UnusedCodeFix.java


示例14: createRemoveUnusedCastFix

import org.eclipse.jdt.core.dom.CastExpression; //导入依赖的package包/类
public static UnusedCodeFix createRemoveUnusedCastFix(CompilationUnit compilationUnit, IProblemLocation problem) {
	if (problem.getProblemId() != IProblem.UnnecessaryCast)
		return null;

	ASTNode selectedNode= problem.getCoveringNode(compilationUnit);

	ASTNode curr= selectedNode;
	while (curr instanceof ParenthesizedExpression) {
		curr= ((ParenthesizedExpression) curr).getExpression();
	}

	if (!(curr instanceof CastExpression))
		return null;

	return new UnusedCodeFix(FixMessages.UnusedCodeFix_RemoveCast_description, compilationUnit, new CompilationUnitRewriteOperation[] {new RemoveCastOperation((CastExpression)curr)});
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:17,代码来源:UnusedCodeFix.java


示例15: replaceCast

import org.eclipse.jdt.core.dom.CastExpression; //导入依赖的package包/类
private static void replaceCast(CastExpression castExpression, Expression replacement, ASTRewrite rewrite, TextEditGroup group) {
	boolean castEnclosedInNecessaryParentheses= castExpression.getParent() instanceof ParenthesizedExpression
			&& NecessaryParenthesesChecker.needsParentheses(castExpression, castExpression.getParent().getParent(), castExpression.getParent().getLocationInParent());
	
	ASTNode toReplace= castEnclosedInNecessaryParentheses ? castExpression.getParent() : castExpression;
	ASTNode move;
	if (NecessaryParenthesesChecker.needsParentheses(replacement, toReplace.getParent(), toReplace.getLocationInParent())) {
		if (replacement.getParent() instanceof ParenthesizedExpression) {
			move= rewrite.createMoveTarget(replacement.getParent());
		} else if (castEnclosedInNecessaryParentheses) {
			toReplace= castExpression;
			move= rewrite.createMoveTarget(replacement);
		} else {
			ParenthesizedExpression parentheses= replacement.getAST().newParenthesizedExpression();
			parentheses.setExpression((Expression) rewrite.createMoveTarget(replacement));
			move= parentheses;
		}
	} else {
		move= rewrite.createMoveTarget(replacement);
	}
	rewrite.replace(toReplace, move, group);
}
 
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:23,代码来源:UnusedCodeFix.java


示例16: endVisit

import org.eclipse.jdt.core.dom.CastExpression; //导入依赖的package包/类
@Override
public void endVisit(CastExpression node) {
	if (skipNode(node)) {
		return;
	}
	processSequential(node, node.getType(), node.getExpression());
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:8,代码来源:FlowAnalyzer.java


示例17: getExpressionPrecedence

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


示例18: createNarrowCastIfNessecary

import org.eclipse.jdt.core.dom.CastExpression; //导入依赖的package包/类
/**
 * Checks if the assignment needs a downcast and inserts it if necessary
 *
 * @param expression the right hand-side
 * @param expressionType the type of the right hand-side. Can be null
 * @param ast the AST
 * @param variableType the Type of the variable the expression will be assigned to
 * @param is50OrHigher if <code>true</code> java 5.0 code will be assumed
 * @return the casted expression if necessary
 */
private static Expression createNarrowCastIfNessecary(
    Expression expression,
    ITypeBinding expressionType,
    AST ast,
    ITypeBinding variableType,
    boolean is50OrHigher) {
  PrimitiveType castTo = null;
  if (variableType.isEqualTo(expressionType)) return expression; // no cast for same type
  if (is50OrHigher) {
    if (ast.resolveWellKnownType("java.lang.Character").isEqualTo(variableType)) // $NON-NLS-1$
    castTo = ast.newPrimitiveType(PrimitiveType.CHAR);
    if (ast.resolveWellKnownType("java.lang.Byte").isEqualTo(variableType)) // $NON-NLS-1$
    castTo = ast.newPrimitiveType(PrimitiveType.BYTE);
    if (ast.resolveWellKnownType("java.lang.Short").isEqualTo(variableType)) // $NON-NLS-1$
    castTo = ast.newPrimitiveType(PrimitiveType.SHORT);
  }
  if (ast.resolveWellKnownType("char").isEqualTo(variableType)) // $NON-NLS-1$
  castTo = ast.newPrimitiveType(PrimitiveType.CHAR);
  if (ast.resolveWellKnownType("byte").isEqualTo(variableType)) // $NON-NLS-1$
  castTo = ast.newPrimitiveType(PrimitiveType.BYTE);
  if (ast.resolveWellKnownType("short").isEqualTo(variableType)) // $NON-NLS-1$
  castTo = ast.newPrimitiveType(PrimitiveType.SHORT);
  if (castTo != null) {
    CastExpression cast = ast.newCastExpression();
    if (NecessaryParenthesesChecker.needsParentheses(
        expression, cast, CastExpression.EXPRESSION_PROPERTY)) {
      ParenthesizedExpression parenthesized = ast.newParenthesizedExpression();
      parenthesized.setExpression(expression);
      cast.setExpression(parenthesized);
    } else cast.setExpression(expression);
    cast.setType(castTo);
    return cast;
  }
  return expression;
}
 
开发者ID:eclipse,项目名称:che,代码行数:46,代码来源:GetterSetterUtil.java


示例19: replaceCast

import org.eclipse.jdt.core.dom.CastExpression; //导入依赖的package包/类
private static void replaceCast(
    CastExpression castExpression,
    Expression replacement,
    ASTRewrite rewrite,
    TextEditGroup group) {
  boolean castEnclosedInNecessaryParentheses =
      castExpression.getParent() instanceof ParenthesizedExpression
          && NecessaryParenthesesChecker.needsParentheses(
              castExpression,
              castExpression.getParent().getParent(),
              castExpression.getParent().getLocationInParent());

  ASTNode toReplace =
      castEnclosedInNecessaryParentheses ? castExpression.getParent() : castExpression;
  ASTNode move;
  if (NecessaryParenthesesChecker.needsParentheses(
      replacement, toReplace.getParent(), toReplace.getLocationInParent())) {
    if (replacement.getParent() instanceof ParenthesizedExpression) {
      move = rewrite.createMoveTarget(replacement.getParent());
    } else if (castEnclosedInNecessaryParentheses) {
      toReplace = castExpression;
      move = rewrite.createMoveTarget(replacement);
    } else {
      ParenthesizedExpression parentheses = replacement.getAST().newParenthesizedExpression();
      parentheses.setExpression((Expression) rewrite.createMoveTarget(replacement));
      move = parentheses;
    }
  } else {
    move = rewrite.createMoveTarget(replacement);
  }
  rewrite.replace(toReplace, move, group);
}
 
开发者ID:eclipse,项目名称:che,代码行数:33,代码来源:UnusedCodeFix.java


示例20: rewriteCastVariable

import org.eclipse.jdt.core.dom.CastExpression; //导入依赖的package包/类
private static ASTNode rewriteCastVariable(
    CastVariable2 castCv,
    CompilationUnitRewrite rewrite,
    InferTypeArgumentsTCModel tCModel) { // , List positionGroups) {
  ASTNode node = castCv.getRange().getNode(rewrite.getRoot());

  ConstraintVariable2 expressionVariable = castCv.getExpressionVariable();
  ConstraintVariable2 methodReceiverCv = tCModel.getMethodReceiverCv(expressionVariable);
  if (methodReceiverCv != null) {
    TType chosenReceiverType =
        InferTypeArgumentsConstraintsSolver.getChosenType(methodReceiverCv);
    if (chosenReceiverType == null) return null;
    else if (!InferTypeArgumentsTCModel.isAGenericType(chosenReceiverType)) return null;
    else if (hasUnboundElement(methodReceiverCv, tCModel)) return null;
  }

  CastExpression castExpression = (CastExpression) node;
  Expression expression = castExpression.getExpression();
  ASTNode nodeToReplace;
  if (castExpression.getParent() instanceof ParenthesizedExpression)
    nodeToReplace = castExpression.getParent();
  else nodeToReplace = castExpression;

  Expression newExpression = (Expression) rewrite.getASTRewrite().createMoveTarget(expression);
  rewrite
      .getASTRewrite()
      .replace(
          nodeToReplace,
          newExpression,
          rewrite.createGroupDescription(
              RefactoringCoreMessages.InferTypeArgumentsRefactoring_removeCast));
  rewrite.getImportRemover().registerRemovedNode(nodeToReplace);
  return newExpression;
}
 
开发者ID:eclipse,项目名称:che,代码行数:35,代码来源:InferTypeArgumentsRefactoring.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java InhibitAnyPolicyExtension类代码示例发布时间:2022-05-21
下一篇:
Java FileImageOutputStreamSpi类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap