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


Java AST.newPrimitiveType方法代碼示例

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


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

示例1: getNewMethodType

import org.eclipse.jdt.core.dom.AST; //導入方法依賴的package包/類
private Type getNewMethodType(ASTRewrite rewrite, ImportRewriteContext context) throws CoreException {
	AST ast = rewrite.getAST();
	Type newTypeNode = null;
	if (isGetter) {
		newTypeNode = getImportRewrite().addImport(fVariableBinding.getType(), ast, context, TypeLocation.RETURN_TYPE);
	} else {
		newTypeNode = ast.newPrimitiveType(PrimitiveType.VOID);
	}
	return newTypeNode;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:11,代碼來源:SelfEncapsulateFieldProposal.java

示例2: createNarrowCastIfNessecary

import org.eclipse.jdt.core.dom.AST; //導入方法依賴的package包/類
/**
 * Checks if the assignment needs a downcast and inserts it if necessary
 *
 * @param expression
 *            the right hand-side
 * @param expressionType
 *            the type of the right hand-side. Can be null
 * @param ast
 *            the AST
 * @param variableType
 *            the Type of the variable the expression will be assigned to
 * @param is50OrHigher
 *            if <code>true</code> java 5.0 code will be assumed
 * @return the casted expression if necessary
 */
private static Expression createNarrowCastIfNessecary(Expression expression, ITypeBinding expressionType, AST ast, ITypeBinding variableType, boolean is50OrHigher) {
	PrimitiveType castTo = null;
	if (variableType.isEqualTo(expressionType))
	 {
		return expression; //no cast for same type
	}
	if (is50OrHigher) {
		if (ast.resolveWellKnownType("java.lang.Character").isEqualTo(variableType)) {
			castTo = ast.newPrimitiveType(PrimitiveType.CHAR);
		}
		if (ast.resolveWellKnownType("java.lang.Byte").isEqualTo(variableType)) {
			castTo = ast.newPrimitiveType(PrimitiveType.BYTE);
		}
		if (ast.resolveWellKnownType("java.lang.Short").isEqualTo(variableType)) {
			castTo= ast.newPrimitiveType(PrimitiveType.SHORT);
		}
	}
	if (ast.resolveWellKnownType("char").isEqualTo(variableType)) {
		castTo = ast.newPrimitiveType(PrimitiveType.CHAR);
	}
	if (ast.resolveWellKnownType("byte").isEqualTo(variableType)) {
		castTo = ast.newPrimitiveType(PrimitiveType.BYTE);
	}
	if (ast.resolveWellKnownType("short").isEqualTo(variableType)) {
		castTo= ast.newPrimitiveType(PrimitiveType.SHORT);
	}
	if (castTo != null) {
		CastExpression cast = ast.newCastExpression();
		if (NecessaryParenthesesChecker.needsParentheses(expression, cast, CastExpression.EXPRESSION_PROPERTY)) {
			ParenthesizedExpression parenthesized = ast.newParenthesizedExpression();
			parenthesized.setExpression(expression);
			cast.setExpression(parenthesized);
		} else {
			cast.setExpression(expression);
		}
		cast.setType(castTo);
		return cast;
	}
	return expression;
}
 
開發者ID:eclipse,項目名稱:eclipse.jdt.ls,代碼行數:56,代碼來源:GetterSetterUtil.java

示例3: initReturnType

import org.eclipse.jdt.core.dom.AST; //導入方法依賴的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.AST.newPrimitiveType方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。