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


Java Expression.getNodeType方法代碼示例

本文整理匯總了Java中org.eclipse.jdt.core.dom.Expression.getNodeType方法的典型用法代碼示例。如果您正苦於以下問題:Java Expression.getNodeType方法的具體用法?Java Expression.getNodeType怎麽用?Java Expression.getNodeType使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.eclipse.jdt.core.dom.Expression的用法示例。


在下文中一共展示了Expression.getNodeType方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getAssignedVariable

import org.eclipse.jdt.core.dom.Expression; //導入方法依賴的package包/類
/**
 * Returns the binding of the variable written in an Assignment.
 * @param assignment The assignment
 * @return The binding or <code>null</code> if no bindings are available.
 */
public static IVariableBinding getAssignedVariable(Assignment assignment) {
	Expression leftHand = assignment.getLeftHandSide();
	switch (leftHand.getNodeType()) {
	case ASTNode.SIMPLE_NAME:
		return (IVariableBinding) ((SimpleName) leftHand).resolveBinding();
	case ASTNode.QUALIFIED_NAME:
		return (IVariableBinding) ((QualifiedName) leftHand).getName().resolveBinding();
	case ASTNode.FIELD_ACCESS:
		return ((FieldAccess) leftHand).resolveFieldBinding();
	case ASTNode.SUPER_FIELD_ACCESS:
		return ((SuperFieldAccess) leftHand).resolveFieldBinding();
	default:
		return null;
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:21,代碼來源:Bindings.java

示例2: isLeftHandSideOfAssignment

import org.eclipse.jdt.core.dom.Expression; //導入方法依賴的package包/類
static boolean isLeftHandSideOfAssignment(ASTNode node) {
	Assignment assignment = (Assignment) ASTNodes.getParent(node, ASTNode.ASSIGNMENT);
	if (assignment != null) {
		Expression leftHandSide = assignment.getLeftHandSide();
		if (leftHandSide == node) {
			return true;
		}
		if (ASTNodes.isParent(node, leftHandSide)) {
			switch (leftHandSide.getNodeType()) {
				case ASTNode.SIMPLE_NAME:
					return true;
				case ASTNode.FIELD_ACCESS:
					return node == ((FieldAccess) leftHandSide).getName();
				case ASTNode.QUALIFIED_NAME:
					return node == ((QualifiedName) leftHandSide).getName();
				case ASTNode.SUPER_FIELD_ACCESS:
					return node == ((SuperFieldAccess) leftHandSide).getName();
				default:
					return false;
			}
		}
	}
	return false;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:25,代碼來源:SnippetFinder.java

示例3: expressionTypeNeedsParentheses

import org.eclipse.jdt.core.dom.Expression; //導入方法依賴的package包/類
private static boolean expressionTypeNeedsParentheses(Expression expression) {
	int type= expression.getNodeType();
	return type == ASTNode.INFIX_EXPRESSION
			|| type == ASTNode.CONDITIONAL_EXPRESSION
			|| type == ASTNode.PREFIX_EXPRESSION
			|| type == ASTNode.POSTFIX_EXPRESSION
			|| type == ASTNode.CAST_EXPRESSION
			|| type == ASTNode.INSTANCEOF_EXPRESSION
			|| type == ASTNode.ARRAY_CREATION
			|| type == ASTNode.ASSIGNMENT;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:12,代碼來源:NecessaryParenthesesChecker.java

示例4: createCastProposal

import org.eclipse.jdt.core.dom.Expression; //導入方法依賴的package包/類
public static ASTRewriteCorrectionProposal createCastProposal(IInvocationContext context, ITypeBinding castTypeBinding, Expression nodeToCast, int relevance) {
	ICompilationUnit cu= context.getCompilationUnit();

	String label;
	String castType= BindingLabelProvider.getBindingLabel(castTypeBinding, JavaElementLabels.ALL_DEFAULT);
	if (nodeToCast.getNodeType() == ASTNode.CAST_EXPRESSION) {
		label= Messages.format(CorrectionMessages.TypeMismatchSubProcessor_changecast_description, castType);
	} else {
		label= Messages.format(CorrectionMessages.TypeMismatchSubProcessor_addcast_description, castType);
	}
	return new CastCorrectionProposal(label, cu, nodeToCast, castTypeBinding, relevance);
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:13,代碼來源:TypeMismatchSubProcessor.java

示例5: parseExpression

import org.eclipse.jdt.core.dom.Expression; //導入方法依賴的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());
    }
}
 
開發者ID:linzeqipku,項目名稱:SnowGraph,代碼行數:59,代碼來源:JavaASTVisitor.java

示例6: resolveExpressionBinding

import org.eclipse.jdt.core.dom.Expression; //導入方法依賴的package包/類
/**
 * Resolve the binding (<em>not</em> the type binding) for the expression or a nested expression
 * (e.g. nested in parentheses, cast, ...).
 *
 * @param expression an expression node
 * @param goIntoCast iff <code>true</code>, go into a CastExpression's expression to resolve
 * @return the expression binding, or <code>null</code> if the expression has no binding or the
 *         binding could not be resolved
 *
 * @since 3.5
 */
public static IBinding resolveExpressionBinding(Expression expression, boolean goIntoCast) {
	//TODO: search for callers of resolve*Binding() methods and replace with call to this method

	// similar to StubUtility#getVariableNameSuggestions(int, IJavaProject, ITypeBinding, Expression, Collection)
	switch (expression.getNodeType()) {
	case ASTNode.SIMPLE_NAME:
	case ASTNode.QUALIFIED_NAME:
		return ((Name) expression).resolveBinding();

	case ASTNode.FIELD_ACCESS:
		return ((FieldAccess) expression).resolveFieldBinding();
	case ASTNode.SUPER_FIELD_ACCESS:
		return ((SuperFieldAccess) expression).resolveFieldBinding();

	case ASTNode.METHOD_INVOCATION:
		return ((MethodInvocation) expression).resolveMethodBinding();
	case ASTNode.SUPER_METHOD_INVOCATION:
		return ((SuperMethodInvocation) expression).resolveMethodBinding();
	case ASTNode.CLASS_INSTANCE_CREATION:
		return ((ClassInstanceCreation) expression).resolveConstructorBinding();

	case ASTNode.MARKER_ANNOTATION:
	case ASTNode.SINGLE_MEMBER_ANNOTATION:
	case ASTNode.NORMAL_ANNOTATION:
		return ((Annotation) expression).resolveAnnotationBinding();

	case ASTNode.ARRAY_ACCESS:
		return resolveExpressionBinding(((ArrayAccess) expression).getArray(), goIntoCast);
	case ASTNode.CAST_EXPRESSION:
		if (goIntoCast) {
			return resolveExpressionBinding(((CastExpression) expression).getExpression(), true);
		} else {
			return null;
		}
	case ASTNode.PARENTHESIZED_EXPRESSION:
		return resolveExpressionBinding(((ParenthesizedExpression) expression).getExpression(), goIntoCast);
	case ASTNode.PREFIX_EXPRESSION:
		return resolveExpressionBinding(((PrefixExpression) expression).getOperand(), goIntoCast);
	case ASTNode.POSTFIX_EXPRESSION:
		return resolveExpressionBinding(((PostfixExpression) expression).getOperand(), goIntoCast);
	default:
		return null;
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:56,代碼來源:Bindings.java

示例7: isLiteral

import org.eclipse.jdt.core.dom.Expression; //導入方法依賴的package包/類
public static boolean isLiteral(Expression expression) {
	int type= expression.getNodeType();
	return type == ASTNode.BOOLEAN_LITERAL || type == ASTNode.CHARACTER_LITERAL || type == ASTNode.NULL_LITERAL ||
			type == ASTNode.NUMBER_LITERAL || type == ASTNode.STRING_LITERAL || type == ASTNode.TYPE_LITERAL;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:6,代碼來源:ASTNodes.java

示例8: initReturnType

import org.eclipse.jdt.core.dom.Expression; //導入方法依賴的package包/類
private void initReturnType(ImportRewrite rewriter) {
	AST ast = fEnclosingBodyDeclaration.getAST();
	fReturnType = null;
	fReturnTypeBinding = null;
	switch (fReturnKind) {
		case ACCESS_TO_LOCAL:
			VariableDeclaration declaration = ASTNodes.findVariableDeclaration(fReturnValue, fEnclosingBodyDeclaration);
			fReturnType = ASTNodeFactory.newType(ast, declaration, rewriter, new ContextSensitiveImportRewriteContext(declaration, rewriter));
			if (declaration.resolveBinding() != null) {
				fReturnTypeBinding = declaration.resolveBinding().getType();
			}
			break;
		case EXPRESSION:
			Expression expression = (Expression) getFirstSelectedNode();
			if (expression.getNodeType() == ASTNode.CLASS_INSTANCE_CREATION) {
				fExpressionBinding = ((ClassInstanceCreation) expression).getType().resolveBinding();
			} else {
				fExpressionBinding = expression.resolveTypeBinding();
			}
			if (fExpressionBinding != null) {
				if (fExpressionBinding.isNullType()) {
					getStatus().addFatalError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_extract_null_type, JavaStatusContext.create(fCUnit, expression));
				} else {
					ITypeBinding normalizedBinding = Bindings.normalizeForDeclarationUse(fExpressionBinding, ast);
					if (normalizedBinding != null) {
						ImportRewriteContext context = new ContextSensitiveImportRewriteContext(fEnclosingBodyDeclaration, rewriter);
						fReturnType = rewriter.addImport(normalizedBinding, ast, context, TypeLocation.RETURN_TYPE);
						fReturnTypeBinding = normalizedBinding;
					}
				}
			} else {
				fReturnType = ast.newPrimitiveType(PrimitiveType.VOID);
				fReturnTypeBinding = ast.resolveWellKnownType("void"); //$NON-NLS-1$
				getStatus().addError(RefactoringCoreMessages.ExtractMethodAnalyzer_cannot_determine_return_type, JavaStatusContext.create(fCUnit, expression));
			}
			break;
		case RETURN_STATEMENT_VALUE:
			LambdaExpression enclosingLambdaExpr = ASTResolving.findEnclosingLambdaExpression(getFirstSelectedNode());
			if (enclosingLambdaExpr != null) {
				fReturnType = ASTNodeFactory.newReturnType(enclosingLambdaExpr, ast, rewriter, null);
				IMethodBinding methodBinding = enclosingLambdaExpr.resolveMethodBinding();
				fReturnTypeBinding = methodBinding != null ? methodBinding.getReturnType() : null;
			} else if (fEnclosingBodyDeclaration.getNodeType() == ASTNode.METHOD_DECLARATION) {
				fReturnType = ((MethodDeclaration) fEnclosingBodyDeclaration).getReturnType2();
				fReturnTypeBinding = fReturnType != null ? fReturnType.resolveBinding() : null;
			}
			break;
		default:
			fReturnType = ast.newPrimitiveType(PrimitiveType.VOID);
			fReturnTypeBinding = ast.resolveWellKnownType("void"); //$NON-NLS-1$
	}
	if (fReturnType == null) {
		fReturnType = ast.newPrimitiveType(PrimitiveType.VOID);
		fReturnTypeBinding = ast.resolveWellKnownType("void"); //$NON-NLS-1$
	}
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:57,代碼來源:ExtractMethodAnalyzer.java


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