當前位置: 首頁>>代碼示例>>Java>>正文


Java Expression類代碼示例

本文整理匯總了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");
}
 
開發者ID:opaluchlukasz,項目名稱:junit2spock,代碼行數:18,代碼來源:MockitoThrowFeature.java

示例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;
}
 
開發者ID:opaluchlukasz,項目名稱:junit2spock,代碼行數:8,代碼來源:ASTNodeFactory.java

示例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;
}
 
開發者ID:aserg-ufmg,項目名稱:RefDiff,代碼行數:25,代碼來源:BindingsRecoveryAstVisitor.java

示例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;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:11,代碼來源:ExtractMethodRefactoring.java

示例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;
}
 
開發者ID:capergroup,項目名稱:bayou,代碼行數:27,代碼來源:DOMClassInstanceCreation.java

示例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);
}
 
開發者ID:capergroup,項目名稱:bayou,代碼行數:17,代碼來源:RefinementString.java

示例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");
}
 
開發者ID:opaluchlukasz,項目名稱:junit2spock,代碼行數:12,代碼來源:AssertTrueFeature.java

示例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");
}
 
開發者ID:opaluchlukasz,項目名稱:junit2spock,代碼行數:12,代碼來源:AssertFalseFeature.java

示例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))));
}
 
開發者ID:opaluchlukasz,項目名稱:junit2spock,代碼行數:8,代碼來源:MockitoVerifyNoMoreInteractionsFeature.java

示例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))));
}
 
開發者ID:opaluchlukasz,項目名稱:junit2spock,代碼行數:12,代碼來源:MockitoVerifyFeature.java

示例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();
}
 
開發者ID:opaluchlukasz,項目名稱:junit2spock,代碼行數:24,代碼來源:ClosureHelper.java

示例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;
}
 
開發者ID:aserg-ufmg,項目名稱:RefDiff,代碼行數:18,代碼來源:ASTVisitorAtomicChange.java

示例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));
	}

}
 
開發者ID:andre-santos-pt,項目名稱:pandionj,代碼行數:11,代碼來源:VarParser.java

示例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;
}
 
開發者ID:andre-santos-pt,項目名稱:pandionj,代碼行數:18,代碼來源:VarParser.java

示例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;
}
 
開發者ID:andre-santos-pt,項目名稱:pandionj,代碼行數:25,代碼來源:VarParser.java


注:本文中的org.eclipse.jdt.core.dom.Expression類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。