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


Java CastExpression类代码示例

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


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


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