本文整理汇总了Java中org.eclipse.jdt.core.dom.InstanceofExpression类的典型用法代码示例。如果您正苦于以下问题:Java InstanceofExpression类的具体用法?Java InstanceofExpression怎么用?Java InstanceofExpression使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
InstanceofExpression类属于org.eclipse.jdt.core.dom包,在下文中一共展示了InstanceofExpression类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: needsParentesis
import org.eclipse.jdt.core.dom.InstanceofExpression; //导入依赖的package包/类
private boolean needsParentesis(ASTNode node) {
if (!(node.getParent() instanceof InfixExpression))
return false;
if (node instanceof InstanceofExpression)
return true;
if (node instanceof InfixExpression) {
InfixExpression expression = (InfixExpression) node;
InfixExpression.Operator operator = expression.getOperator();
InfixExpression parentExpression = (InfixExpression) node.getParent();
InfixExpression.Operator parentOperator = parentExpression.getOperator();
if (parentOperator == operator)
return false;
return true;
}
return false;
}
示例2: fillInstanceof
import org.eclipse.jdt.core.dom.InstanceofExpression; //导入依赖的package包/类
/**
* Fills instanceof skeleton pieces.
* @param instance The instanceof part of the skeleton.
* @param parentsOfHoles All nodes that are parents of some hole.
* @return The synthesized expressions corresponding to this
* skeleton piece and the type constraint representing their types.
*/
private ExpressionsAndTypeConstraints fillInstanceof(InstanceofExpression instance, Set<ASTNode> parentsOfHoles) {
try {
codehint.ast.Type rightOperand = ASTConverter.copy(instance.getRightOperand());
IJavaType targetType = EclipseUtils.getType(instance.getRightOperand().toString(), stack, target, typeCache);
rightOperand.setStaticType(targetType);
ExpressionsAndTypeConstraints exprResult = fillSkeleton(instance.getLeftOperand(), new SameHierarchy(targetType), parentsOfHoles);
Map<String, ArrayList<codehint.ast.Expression>> resultExprs = new HashMap<String, ArrayList<codehint.ast.Expression>>(exprResult.getExprs().size());
for (Map.Entry<String, ArrayList<codehint.ast.Expression>> res: exprResult.getExprs().entrySet())
for (codehint.ast.Expression expr: res.getValue()) {
IJavaValue exprValue = expressionEvaluator.getValue(expr, Collections.<Effect>emptySet());
Utils.addToListMap(resultExprs, res.getKey(), expressionMaker.makeInstanceOf(expr, rightOperand, booleanType, exprValue == null ? null : valueCache.getBooleanJavaValue(!exprValue.isNull() && subtypeChecker.isSubtypeOf(exprValue.getJavaType(), targetType))));
}
return new ExpressionsAndTypeConstraints(resultExprs, new SupertypeBound(booleanType));
} catch (DebugException e) {
throw new RuntimeException(e);
}
}
示例3: endVisit
import org.eclipse.jdt.core.dom.InstanceofExpression; //导入依赖的package包/类
@Override
public void endVisit(InstanceofExpression node) {
if (skipNode(node)) {
return;
}
processSequential(node, node.getLeftOperand(), node.getRightOperand());
}
示例4: getExpressionPrecedence
import org.eclipse.jdt.core.dom.InstanceofExpression; //导入依赖的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;
}
示例5: getExpressionPrecedence
import org.eclipse.jdt.core.dom.InstanceofExpression; //导入依赖的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>
*
* <p>the precedence order is
*
* <ul>
* <li>3
* <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;
}
示例6: create
import org.eclipse.jdt.core.dom.InstanceofExpression; //导入依赖的package包/类
@Override
public ITypeConstraint[] create(InstanceofExpression instanceofExpression) {
Expression expression = instanceofExpression.getLeftOperand();
Type type = instanceofExpression.getRightOperand();
if (isClassBinding(expression.resolveTypeBinding()) && isClassBinding(type.resolveBinding())) {
ConstraintVariable expressionVar =
fConstraintVariableFactory.makeExpressionOrTypeVariable(expression, getContext());
ConstraintVariable typeVariable = fConstraintVariableFactory.makeTypeVariable(type);
return createOrOrSubtypeConstraint(expressionVar, typeVariable);
} else return new ITypeConstraint[0];
}
示例7: create
import org.eclipse.jdt.core.dom.InstanceofExpression; //导入依赖的package包/类
@Override
public ITypeConstraint[] create(InstanceofExpression instanceofExpression){
Expression expression= instanceofExpression.getLeftOperand();
Type type= instanceofExpression.getRightOperand();
if (isClassBinding(expression.resolveTypeBinding()) && isClassBinding(type.resolveBinding())) {
ConstraintVariable expressionVar= fConstraintVariableFactory.makeExpressionOrTypeVariable(expression, getContext());
ConstraintVariable typeVariable= fConstraintVariableFactory.makeTypeVariable(type);
return createOrOrSubtypeConstraint(expressionVar, typeVariable);
} else
return new ITypeConstraint[0];
}
示例8: addUnnecessaryInstanceofProposal
import org.eclipse.jdt.core.dom.InstanceofExpression; //导入依赖的package包/类
public static void addUnnecessaryInstanceofProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
ASTNode curr= selectedNode;
while (curr instanceof ParenthesizedExpression) {
curr= ((ParenthesizedExpression) curr).getExpression();
}
if (curr instanceof InstanceofExpression) {
AST ast= curr.getAST();
ASTRewrite rewrite= ASTRewrite.create(ast);
InstanceofExpression inst= (InstanceofExpression) curr;
InfixExpression expression= ast.newInfixExpression();
expression.setLeftOperand((Expression) rewrite.createCopyTarget(inst.getLeftOperand()));
expression.setOperator(InfixExpression.Operator.NOT_EQUALS);
expression.setRightOperand(ast.newNullLiteral());
rewrite.replace(inst, expression, null);
String label= CorrectionMessages.LocalCorrectionsSubProcessor_unnecessaryinstanceof_description;
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, IProposalRelevance.UNNECESSARY_INSTANCEOF, image);
proposals.add(proposal);
}
}
示例9: visit
import org.eclipse.jdt.core.dom.InstanceofExpression; //导入依赖的package包/类
@Override
public boolean visit(InstanceofExpression node) {
node.getLeftOperand().accept(this);
this.fBuffer.append(" instanceof ");//$NON-NLS-1$
node.getRightOperand().accept(this);
return false;
}
示例10: addUnnecessaryInstanceofProposal
import org.eclipse.jdt.core.dom.InstanceofExpression; //导入依赖的package包/类
public static void addUnnecessaryInstanceofProposal(IInvocationContext context, IProblemLocation problem, Collection<ICommandAccess> proposals) {
ASTNode selectedNode= problem.getCoveringNode(context.getASTRoot());
ASTNode curr= selectedNode;
while (curr instanceof ParenthesizedExpression) {
curr= ((ParenthesizedExpression) curr).getExpression();
}
if (curr instanceof InstanceofExpression) {
AST ast= curr.getAST();
ASTRewrite rewrite= ASTRewrite.create(ast);
InstanceofExpression inst= (InstanceofExpression) curr;
InfixExpression expression= ast.newInfixExpression();
expression.setLeftOperand((Expression) rewrite.createCopyTarget(inst.getLeftOperand()));
expression.setOperator(InfixExpression.Operator.NOT_EQUALS);
expression.setRightOperand(ast.newNullLiteral());
rewrite.replace(inst, expression, null);
String label= CorrectionMessages.LocalCorrectionsSubProcessor_unnecessaryinstanceof_description;
Image image= JavaPluginImages.get(JavaPluginImages.IMG_CORRECTION_CHANGE);
ASTRewriteCorrectionProposal proposal= new ASTRewriteCorrectionProposal(label, context.getCompilationUnit(), rewrite, 10, image);
proposals.add(proposal);
}
}
开发者ID:trylimits,项目名称:Eclipse-Postfix-Code-Completion-Juno38,代码行数:30,代码来源:LocalCorrectionsSubProcessor.java
示例11: visit
import org.eclipse.jdt.core.dom.InstanceofExpression; //导入依赖的package包/类
@Override
public boolean visit(InstanceofExpression node) {
//System.out.println("Found: " + node.getClass());
print("(cast(");
node.getRightOperand().accept(this);
print(")(");
node.getLeftOperand().accept(this);
print(") !is null)");
return false;
}
示例12: visit
import org.eclipse.jdt.core.dom.InstanceofExpression; //导入依赖的package包/类
@Override
public boolean visit(InstanceofExpression node)
{
Type type = node.getRightOperand();
processType(type, TypeReferenceLocation.INSTANCE_OF, compilationUnit.getLineNumber(node.getStartPosition()),
compilationUnit.getColumnNumber(type.getStartPosition()), type.getLength(), node.toString());
return super.visit(node);
}
示例13: parseExpression
import org.eclipse.jdt.core.dom.InstanceofExpression; //导入依赖的package包/类
private void parseExpression(MethodInfo methodInfo, Expression expression) {
if (expression == null) {
return;
}//System.out.println(expression.toString()+" "+Annotation.nodeClassForType(expression.getNodeType()));
if (expression.getNodeType() == ASTNode.ARRAY_INITIALIZER) {
List<Expression> expressions = ((ArrayInitializer) expression).expressions();
for (Expression expression2 : expressions) {
parseExpression(methodInfo, expression2);
}
}
if (expression.getNodeType() == ASTNode.CAST_EXPRESSION) {
parseExpression(methodInfo, ((CastExpression) expression).getExpression());
}
if (expression.getNodeType() == ASTNode.CONDITIONAL_EXPRESSION) {
parseExpression(methodInfo, ((ConditionalExpression) expression).getExpression());
parseExpression(methodInfo, ((ConditionalExpression) expression).getElseExpression());
parseExpression(methodInfo, ((ConditionalExpression) expression).getThenExpression());
}
if (expression.getNodeType() == ASTNode.INFIX_EXPRESSION) {
parseExpression(methodInfo, ((InfixExpression) expression).getLeftOperand());
parseExpression(methodInfo, ((InfixExpression) expression).getRightOperand());
}
if (expression.getNodeType() == ASTNode.INSTANCEOF_EXPRESSION) {
parseExpression(methodInfo, ((InstanceofExpression) expression).getLeftOperand());
}
if (expression.getNodeType() == ASTNode.PARENTHESIZED_EXPRESSION) {
parseExpression(methodInfo, ((ParenthesizedExpression) expression).getExpression());
}
if (expression.getNodeType() == ASTNode.POSTFIX_EXPRESSION) {
parseExpression(methodInfo, ((PostfixExpression) expression).getOperand());
}
if (expression.getNodeType() == ASTNode.PREFIX_EXPRESSION) {
parseExpression(methodInfo, ((PrefixExpression) expression).getOperand());
}
if (expression.getNodeType() == ASTNode.THIS_EXPRESSION) {
parseExpression(methodInfo, ((ThisExpression) expression).getQualifier());
}
if (expression.getNodeType() == ASTNode.METHOD_INVOCATION) {
List<Expression> arguments = ((MethodInvocation) expression).arguments();
IMethodBinding methodBinding = ((MethodInvocation) expression).resolveMethodBinding();
if (methodBinding != null)
methodInfo.methodCalls.add(methodBinding);
for (Expression exp : arguments)
parseExpression(methodInfo, exp);
parseExpression(methodInfo, ((MethodInvocation) expression).getExpression());
}
if (expression.getNodeType() == ASTNode.ASSIGNMENT) {
parseExpression(methodInfo, ((Assignment) expression).getLeftHandSide());
parseExpression(methodInfo, ((Assignment) expression).getRightHandSide());
}
if (expression.getNodeType() == ASTNode.QUALIFIED_NAME) {
if (((QualifiedName) expression).getQualifier().resolveTypeBinding() != null) {
String name = ((QualifiedName) expression).getQualifier().resolveTypeBinding().getQualifiedName() + "." + ((QualifiedName) expression).getName().getIdentifier();
methodInfo.fieldUsesSet.add(name);
}
parseExpression(methodInfo, ((QualifiedName) expression).getQualifier());
}
}
示例14: visit
import org.eclipse.jdt.core.dom.InstanceofExpression; //导入依赖的package包/类
@Override
public boolean visit(InstanceofExpression node) {
addNewTypeBinding(node.getRightOperand().resolveBinding());
return true;
}
示例15: needsParentesis
import org.eclipse.jdt.core.dom.InstanceofExpression; //导入依赖的package包/类
private boolean needsParentesis(ASTNode node) {
if (!(node.getParent() instanceof InfixExpression)) return false;
if (node instanceof InstanceofExpression) return true;
if (node instanceof InfixExpression) {
InfixExpression expression = (InfixExpression) node;
InfixExpression.Operator operator = expression.getOperator();
InfixExpression parentExpression = (InfixExpression) node.getParent();
InfixExpression.Operator parentOperator = parentExpression.getOperator();
if (parentOperator == operator) return false;
return true;
}
return false;
}