本文整理汇总了Java中org.eclipse.jdt.core.dom.CastExpression.getExpression方法的典型用法代码示例。如果您正苦于以下问题:Java CastExpression.getExpression方法的具体用法?Java CastExpression.getExpression怎么用?Java CastExpression.getExpression使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jdt.core.dom.CastExpression
的用法示例。
在下文中一共展示了CastExpression.getExpression方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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;
}
示例2: 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);
}
示例3: 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;
}
示例4: 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);
}
示例5: 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;
}
示例6: 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;
}
示例7: 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);
}
示例8: 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;
}
示例9: 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:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:29,代码来源:InferTypeArgumentsRefactoring.java
示例10: endVisit
import org.eclipse.jdt.core.dom.CastExpression; //导入方法依赖的package包/类
@Override
public void endVisit(CastExpression node) {
// if (! (expressionCv instanceof CollectionElementVariable2))
// return; //TODO: returns too early when dealing with nested collections.
Type type = node.getType();
ITypeBinding typeBinding = type.resolveBinding();
if (typeBinding.isPrimitive()) {
ImmutableTypeVariable2 boxed = fTCModel.makeImmutableTypeVariable(typeBinding, node);
setConstraintVariable(node, boxed);
return; // avoid removing numeric conversions
}
ConstraintVariable2 typeCv = getConstraintVariable(type);
if (typeCv == null) return;
// TODO: can this be loosened when we remove casts?
setConstraintVariable(node, typeCv);
Expression expression = node.getExpression();
ConstraintVariable2 expressionCv = getConstraintVariable(expression);
// Avoid removing casts that have not been made obsolete by this refactoring:
if (expressionCv == null) return;
if (expressionCv instanceof ImmutableTypeVariable2) return;
if (!(expressionCv instanceof TypeVariable2
|| expressionCv instanceof IndependentTypeVariable2
|| expressionCv instanceof CollectionElementVariable2)
&& fTCModel.getElementVariables(expressionCv).size() == 0
&& fTCModel.getArrayElementVariable(expressionCv) == null) return;
fTCModel.createAssignmentElementConstraints(typeCv, expressionCv);
if (expression instanceof MethodInvocation) {
MethodInvocation invoc = (MethodInvocation) expression;
if (!isSpecialCloneInvocation(invoc.resolveMethodBinding(), invoc.getExpression())) {
fTCModel.makeCastVariable(node, expressionCv);
}
} else {
fTCModel.makeCastVariable(node, expressionCv);
}
boolean eitherIsIntf =
typeBinding.isInterface() || expression.resolveTypeBinding().isInterface();
if (eitherIsIntf) return;
// TODO: preserve up- and down-castedness!
}
示例11: endVisit
import org.eclipse.jdt.core.dom.CastExpression; //导入方法依赖的package包/类
@Override
public void endVisit(CastExpression node) {
// if (! (expressionCv instanceof CollectionElementVariable2))
// return; //TODO: returns too early when dealing with nested collections.
Type type= node.getType();
ITypeBinding typeBinding= type.resolveBinding();
if (typeBinding.isPrimitive()) {
ImmutableTypeVariable2 boxed= fTCModel.makeImmutableTypeVariable(typeBinding, node);
setConstraintVariable(node, boxed);
return; // avoid removing numeric conversions
}
ConstraintVariable2 typeCv= getConstraintVariable(type);
if (typeCv == null)
return;
//TODO: can this be loosened when we remove casts?
setConstraintVariable(node, typeCv);
Expression expression= node.getExpression();
ConstraintVariable2 expressionCv= getConstraintVariable(expression);
//Avoid removing casts that have not been made obsolete by this refactoring:
if (expressionCv == null)
return;
if (expressionCv instanceof ImmutableTypeVariable2)
return;
if (! (expressionCv instanceof TypeVariable2 || expressionCv instanceof IndependentTypeVariable2 || expressionCv instanceof CollectionElementVariable2)
&& fTCModel.getElementVariables(expressionCv).size() == 0 && fTCModel.getArrayElementVariable(expressionCv) == null)
return;
fTCModel.createAssignmentElementConstraints(typeCv, expressionCv);
if (expression instanceof MethodInvocation) {
MethodInvocation invoc= (MethodInvocation) expression;
if (! isSpecialCloneInvocation(invoc.resolveMethodBinding(), invoc.getExpression())) {
fTCModel.makeCastVariable(node, expressionCv);
}
} else {
fTCModel.makeCastVariable(node, expressionCv);
}
boolean eitherIsIntf= typeBinding.isInterface() || expression.resolveTypeBinding().isInterface();
if (eitherIsIntf)
return;
//TODO: preserve up- and down-castedness!
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion,代码行数:51,代码来源:InferTypeArgumentsConstraintCreator.java