本文整理匯總了Java中org.eclipse.jdt.core.dom.Expression類的典型用法代碼示例。如果您正苦於以下問題:Java Expression類的具體用法?Java Expression怎麽用?Java Expression使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Expression類屬於org.eclipse.jdt.core.dom包,在下文中一共展示了Expression類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: apply
import org.eclipse.jdt.core.dom.Expression; //導入依賴的package包/類
@Override
public Expression apply(Object object, MethodInvocation whenMethodInvocation) {
MethodInvocation methodInvocation = methodInvocation(object, thenThrow).get();
List arguments = methodInvocation.arguments();
if (arguments.size() == 1) {
MethodInvocation mockedMethodInvocation = (MethodInvocation) whenMethodInvocation.arguments().get(0);
Expression toBeThrown = argumentAsExpression(arguments.get(0));
Expression throwingClosure = groovyClosureBuilder.aClosure()
.withBodyStatement(nodeFactory.throwStatement(toBeThrown))
.build()
.asExpression();
return nodeFactory.infixExpression(RIGHT_SHIFT_SIGNED,
mockedMethodWithMatchers(mockedMethodInvocation),
throwingClosure);
}
throw new UnsupportedOperationException("Supported only 1-arity thenThrow invocation");
}
示例2: variableDeclarationStatement
import org.eclipse.jdt.core.dom.Expression; //導入依賴的package包/類
public VariableDeclarationStatement variableDeclarationStatement(String name, Type type, Expression initializer) {
VariableDeclarationFragment variableDeclarationFragment = variableDeclarationFragment(name);
variableDeclarationFragment.setInitializer(initializer);
VariableDeclarationStatement statement = ast.get().newVariableDeclarationStatement(variableDeclarationFragment);
statement.setType(type);
return statement;
}
示例3: visit
import org.eclipse.jdt.core.dom.Expression; //導入依賴的package包/類
@Override
public boolean visit(FieldDeclaration fieldDeclaration) {
Type fieldType = fieldDeclaration.getType();
int fieldModifiers = fieldDeclaration.getModifiers();
Visibility visibility = getVisibility(fieldModifiers);
// boolean isFinal = (fieldModifiers & Modifier.FINAL) != 0;
boolean isStatic = (fieldModifiers & Modifier.STATIC) != 0;
List<VariableDeclarationFragment> fragments = fieldDeclaration.fragments();
for (VariableDeclarationFragment fragment : fragments) {
String fieldName = fragment.getName().getIdentifier();
final SDAttribute attribute = model.createAttribute(fieldName, containerStack.peek());
attribute.setStatic(isStatic);
attribute.setVisibility(visibility);
attribute.setType(AstUtils.normalizeTypeName(fieldType, fragment.getExtraDimensions(), false));
Expression expression = fragment.getInitializer();
if (expression != null) {
//attribute.setAssignment(srbForAttributes.buildSourceRepresentation(fileContent, expression.getStartPosition(), expression.getLength()));
addClientCode(attribute.key().toString(), srbForAttributes.buildPartialSourceRepresentation(fileContent, expression));
}
attribute.setClientCode(srbForAttributes.buildEmptySourceRepresentation());
}
return true;
}
示例4: createDeclaration
import org.eclipse.jdt.core.dom.Expression; //導入依賴的package包/類
private VariableDeclarationStatement createDeclaration(IVariableBinding binding, Expression intilizer) {
VariableDeclaration original = ASTNodes.findVariableDeclaration(binding, fAnalyzer.getEnclosingBodyDeclaration());
VariableDeclarationFragment fragment = fAST.newVariableDeclarationFragment();
fragment.setName((SimpleName) ASTNode.copySubtree(fAST, original.getName()));
fragment.setInitializer(intilizer);
VariableDeclarationStatement result = fAST.newVariableDeclarationStatement(fragment);
result.modifiers().addAll(ASTNode.copySubtrees(fAST, ASTNodes.getModifiers(original)));
result.setType(ASTNodeFactory.newType(fAST, original, fImportRewriter, new ContextSensitiveImportRewriteContext(original, fImportRewriter)));
return result;
}
示例5: handle
import org.eclipse.jdt.core.dom.Expression; //導入依賴的package包/類
@Override
public DSubTree handle() {
DSubTree tree = new DSubTree();
// add the expression's subtree (e.g: foo(..).bar() should handle foo(..) first)
DSubTree Texp = new DOMExpression(creation.getExpression()).handle();
tree.addNodes(Texp.getNodes());
// evaluate arguments first
for (Object o : creation.arguments()) {
DSubTree Targ = new DOMExpression((Expression) o).handle();
tree.addNodes(Targ.getNodes());
}
IMethodBinding binding = creation.resolveConstructorBinding();
// get to the generic declaration, if this binding is an instantiation
while (binding != null && binding.getMethodDeclaration() != binding)
binding = binding.getMethodDeclaration();
MethodDeclaration localMethod = Utils.checkAndGetLocalMethod(binding);
if (localMethod != null) {
DSubTree Tmethod = new DOMMethodDeclaration(localMethod).handle();
tree.addNodes(Tmethod.getNodes());
}
else if (Utils.isRelevantCall(binding))
tree.addNode(new DAPICall(binding, Visitor.V().getLineNumber(creation)));
return tree;
}
示例6: RefinementString
import org.eclipse.jdt.core.dom.Expression; //導入依賴的package包/類
public RefinementString(Expression e) {
if (knownConstants(e))
return;
if ( !(e instanceof StringLiteral)) {
this.exists = false;
this.length = 0;
this.containsPunct = false;
return;
}
String s = ((StringLiteral) e).getLiteralValue();
this.exists = true;
this.length = s.length();
this.containsPunct = hasPunct(s);
}
示例7: apply
import org.eclipse.jdt.core.dom.Expression; //導入依賴的package包/類
@Override
public Expression apply(Object object, MethodInvocation methodInvocation) {
List arguments = methodInvocation.arguments();
if (arguments.size() == 1) {
return argumentAsExpression(arguments.get(0));
}
if (arguments.size() == 2) {
return argumentAsExpression(arguments.get(1));
}
throw new UnsupportedOperationException("Supported only 1-, 2-arity assertTrue invocation");
}
示例8: apply
import org.eclipse.jdt.core.dom.Expression; //導入依賴的package包/類
@Override
public Expression apply(Object object, MethodInvocation methodInvocation) {
List arguments = methodInvocation.arguments();
if (arguments.size() == 1) {
return astNodeFactory.prefixExpression(NOT, argumentAsExpression(arguments.get(0)));
}
if (arguments.size() == 2) {
return astNodeFactory.prefixExpression(NOT, argumentAsExpression(arguments.get(1)));
}
throw new UnsupportedOperationException("Supported only 1-, 2-arity assertFalse invocation");
}
示例9: apply
import org.eclipse.jdt.core.dom.Expression; //導入依賴的package包/類
@Override
public InfixExpression apply(Object object, MethodInvocation verifyMethodInvocation) {
List arguments = verifyMethodInvocation.arguments();
return nodeFactory.infixExpression(TIMES,
nodeFactory.numberLiteral("0"),
nodeFactory.fieldAccess("_", nodeFactory.clone((Expression) arguments.get(0))));
}
示例10: apply
import org.eclipse.jdt.core.dom.Expression; //導入依賴的package包/類
@Override
public InfixExpression apply(Object object, MethodInvocation verifyMethodInvocation) {
List arguments = verifyMethodInvocation.arguments();
MethodInvocation parentMethodInvocation = (MethodInvocation) verifyMethodInvocation.getParent();
return nodeFactory.infixExpression(TIMES,
cardinality(arguments.size() == 2 ? Optional.of(arguments.get(1)) : empty()),
nodeFactory.methodInvocation(parentMethodInvocation.getName().getFullyQualifiedName(),
(List<Expression>) parentMethodInvocation.arguments().stream()
.map(matcherHandler::applyMatchers).collect(toList()),
nodeFactory.clone((Expression) arguments.get(0))));
}
示例11: asClosure
import org.eclipse.jdt.core.dom.Expression; //導入依賴的package包/類
public static Optional<GroovyClosure> asClosure(ASTNodeFactory nodeFactory, GroovyClosureBuilder groovyClosureBuilder,
Expression expression, String methodName) {
if (expression instanceof ClassInstanceCreation) {
ClassInstanceCreation classInstanceCreation = (ClassInstanceCreation) expression;
if (classInstanceCreation.getAnonymousClassDeclaration() != null) {
AnonymousClassDeclaration classDeclaration = classInstanceCreation.getAnonymousClassDeclaration();
if (classDeclaration.bodyDeclarations().size() == 1 &&
classDeclaration.bodyDeclarations().get(0) instanceof MethodDeclaration &&
((MethodDeclaration) classDeclaration.bodyDeclarations().get(0))
.getName().getIdentifier().equals(methodName)) {
MethodDeclaration methodDeclaration = (MethodDeclaration) classDeclaration.bodyDeclarations().get(0);
List<Statement> statements = nodeFactory.clone(methodDeclaration.getBody()).statements();
GroovyClosure closure = groovyClosureBuilder.aClosure()
.withBodyStatements(statements)
.withTypeLiteral(nodeFactory.typeLiteral(type(nodeFactory, classInstanceCreation)))
.withArgument(nodeFactory.clone((SingleVariableDeclaration) methodDeclaration.parameters().get(0)))
.build();
return Optional.of(closure);
}
}
}
return empty();
}
示例12: visit
import org.eclipse.jdt.core.dom.Expression; //導入依賴的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;
}
示例13: handleVarDeclaration
import org.eclipse.jdt.core.dom.Expression; //導入依賴的package包/類
private void handleVarDeclaration(VariableDeclarationFragment var, boolean isField) {
String varName = var.getName().getIdentifier();
VariableInfo varInfo = current.addVar(varName, isField);
Expression init = var.getInitializer();
if(init instanceof SimpleName) {
String initVar = ((SimpleName) init).getIdentifier();
varInfo.addOperation(new VariableOperation(varName, VariableOperation.Type.INIT, initVar));
}
}
示例14: accessExpressions
import org.eclipse.jdt.core.dom.Expression; //導入依賴的package包/類
private Object[] accessExpressions(ArrayAccess node) {
Object[] exp = new Object[indexDepth(node)+1];
ArrayAccess a = node;
int i = exp.length-1;
do {
Expression indexExp = a.getIndex();
if(!(indexExp instanceof SimpleName)) // TODO no modifiers
return null;
exp[i] = indexExp.toString();
Expression temp = a.getArray();
a = temp instanceof ArrayAccess ? (ArrayAccess) temp : null;
i--;
}
while(i >= 0);
return exp;
}
示例15: isAcumulationAssign
import org.eclipse.jdt.core.dom.Expression; //導入依賴的package包/類
private static boolean isAcumulationAssign(Assignment assignment, InfixExpression.Operator op, Predicate<Expression> acceptExpression) {
if(!(
assignment.getRightHandSide() instanceof InfixExpression &&
assignment.getLeftHandSide() instanceof SimpleName &&
assignment.getOperator() == Assignment.Operator.ASSIGN))
return false;
InfixExpression exp = (InfixExpression) assignment.getRightHandSide();
if(exp.getOperator() != op)
return false;
String assignVar = assignment.getLeftHandSide().toString();
if( exp.getLeftOperand() instanceof SimpleName &&
exp.getLeftOperand().toString().equals(assignVar) &&
acceptExpression.test(exp.getRightOperand()))
return true;
if( exp.getRightOperand() instanceof SimpleName &&
exp.getRightOperand().toString().equals(assignVar) &&
acceptExpression.test(exp.getLeftOperand()))
return true;
return false;
}