当前位置: 首页>>代码示例>>Java>>正文


Java AST.newSimpleType方法代码示例

本文整理汇总了Java中org.eclipse.jdt.core.dom.AST.newSimpleType方法的典型用法代码示例。如果您正苦于以下问题:Java AST.newSimpleType方法的具体用法?Java AST.newSimpleType怎么用?Java AST.newSimpleType使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.eclipse.jdt.core.dom.AST的用法示例。


在下文中一共展示了AST.newSimpleType方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getNewCastTypeNode

import org.eclipse.jdt.core.dom.AST; //导入方法依赖的package包/类
private Type getNewCastTypeNode(ASTRewrite rewrite, ImportRewrite importRewrite) {
	AST ast= rewrite.getAST();

	ImportRewriteContext context= new ContextSensitiveImportRewriteContext((CompilationUnit) fNodeToCast.getRoot(), fNodeToCast.getStartPosition(), importRewrite);

	if (fCastType != null) {
		return importRewrite.addImport(fCastType, ast,context, TypeLocation.CAST);
	}

	ASTNode node= fNodeToCast;
	ASTNode parent= node.getParent();
	if (parent instanceof CastExpression) {
		node= parent;
		parent= parent.getParent();
	}
	while (parent instanceof ParenthesizedExpression) {
		node= parent;
		parent= parent.getParent();
	}
	if (parent instanceof MethodInvocation) {
		MethodInvocation invocation= (MethodInvocation) node.getParent();
		if (invocation.getExpression() == node) {
			IBinding targetContext= ASTResolving.getParentMethodOrTypeBinding(node);
			ITypeBinding[] bindings= ASTResolving.getQualifierGuess(node.getRoot(), invocation.getName().getIdentifier(), invocation.arguments(), targetContext);
			if (bindings.length > 0) {
				ITypeBinding first= getCastFavorite(bindings, fNodeToCast.resolveTypeBinding());

				Type newTypeNode= importRewrite.addImport(first, ast, context, TypeLocation.CAST);
				return newTypeNode;
			}
		}
	}
	Type newCastType= ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
	return newCastType;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:36,代码来源:CastCorrectionProposal.java

示例2: newType

import org.eclipse.jdt.core.dom.AST; //导入方法依赖的package包/类
private static Type newType(LambdaExpression lambdaExpression, VariableDeclarationFragment declaration, AST ast, ImportRewrite importRewrite, ImportRewriteContext context) {
	IMethodBinding method= lambdaExpression.resolveMethodBinding();
	if (method != null) {
		ITypeBinding[] parameterTypes= method.getParameterTypes();
		int index= lambdaExpression.parameters().indexOf(declaration);
		ITypeBinding typeBinding= parameterTypes[index];
		if (importRewrite != null) {
			return importRewrite.addImport(typeBinding, ast, context);
		} else {
			String qualifiedName= typeBinding.getQualifiedName();
			if (qualifiedName.length() > 0) {
				return newType(ast, qualifiedName);
			}
		}
	}
	// fall-back
	return ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:19,代码来源:ASTNodeFactory.java

示例3: newReturnType

import org.eclipse.jdt.core.dom.AST; //导入方法依赖的package包/类
/**
 * Returns the new type node representing the return type of <code>lambdaExpression</code>
 * including the extra dimensions.
 *
 * @param lambdaExpression the lambda expression
 * @param ast the AST to create the return type with
 * @param importRewrite the import rewrite to use, or <code>null</code>
 * @param context the import rewrite context, or <code>null</code>
 * @return a new type node created with the given AST representing the return type of
 *         <code>lambdaExpression</code>
 *
 * @since 3.10
 */
public static Type newReturnType(LambdaExpression lambdaExpression, AST ast, ImportRewrite importRewrite, ImportRewriteContext context) {
	IMethodBinding method= lambdaExpression.resolveMethodBinding();
	if (method != null) {
		ITypeBinding returnTypeBinding= method.getReturnType();
		if (importRewrite != null) {
			return importRewrite.addImport(returnTypeBinding, ast);
		} else {
			String qualifiedName= returnTypeBinding.getQualifiedName();
			if (qualifiedName.length() > 0) {
				return newType(ast, qualifiedName);
			}
		}
	}
	// fall-back
	return ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:30,代码来源:ASTNodeFactory.java

示例4: evaluateVariableType

import org.eclipse.jdt.core.dom.AST; //导入方法依赖的package包/类
private Type evaluateVariableType(AST ast, ImportRewrite imports, ImportRewriteContext importRewriteContext, IBinding targetContext, TypeLocation location) {
	if (fOriginalNode.getParent() instanceof MethodInvocation) {
		MethodInvocation parent= (MethodInvocation) fOriginalNode.getParent();
		if (parent.getExpression() == fOriginalNode) {
			// _x_.foo() -> guess qualifier type by looking for a type with method 'foo'
			ITypeBinding[] bindings= ASTResolving.getQualifierGuess(fOriginalNode.getRoot(), parent.getName().getIdentifier(), parent.arguments(), targetContext);
			if (bindings.length > 0) {
				return imports.addImport(bindings[0], ast, importRewriteContext, location);
			}
		}
	}

	ITypeBinding binding= ASTResolving.guessBindingForReference(fOriginalNode);
	if (binding != null) {
		if (binding.isWildcardType()) {
			binding= ASTResolving.normalizeWildcardType(binding, isVariableAssigned(), ast);
			if (binding == null) {
				// only null binding applies
				binding= ast.resolveWellKnownType("java.lang.Object"); //$NON-NLS-1$
			}
		}

		return imports.addImport(binding, ast, importRewriteContext, location);
	}
	// no binding, find type AST node instead -> ABC a= x-> use 'ABC' as is
	Type type = ASTResolving.guessTypeForReference(ast, fOriginalNode);
	if (type != null) {
		return type;
	}
	if (fVariableKind == CONST_FIELD) {
		return ast.newSimpleType(ast.newSimpleName("String")); //$NON-NLS-1$
	}
	return ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:35,代码来源:NewVariableCorrectionProposal.java

示例5: getNewType

import org.eclipse.jdt.core.dom.AST; //导入方法依赖的package包/类
private Type getNewType(ASTRewrite rewrite) {
	AST ast= rewrite.getAST();
	Type newTypeNode= null;
	ITypeBinding binding= null;
	if (fInvocationNode.getLocationInParent() == MemberValuePair.NAME_PROPERTY) {
		Expression value= ((MemberValuePair) fInvocationNode.getParent()).getValue();
		binding= value.resolveTypeBinding();
	} else if (fInvocationNode instanceof Expression) {
		binding= ((Expression) fInvocationNode).resolveTypeBinding();
	}
	if (binding != null) {
		ImportRewriteContext importRewriteContext= new ContextSensitiveImportRewriteContext(fInvocationNode, getImportRewrite());
		newTypeNode= getImportRewrite().addImport(binding, ast, importRewriteContext);
	}
	if (newTypeNode == null) {
		newTypeNode= ast.newSimpleType(ast.newSimpleName("String")); //$NON-NLS-1$
	}
	return newTypeNode;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:20,代码来源:NewAnnotationMemberProposal.java

示例6: evaluateParameterType

import org.eclipse.jdt.core.dom.AST; //导入方法依赖的package包/类
private Type evaluateParameterType(AST ast, Expression elem, String key, ImportRewriteContext context) {
	ITypeBinding binding= Bindings.normalizeTypeBinding(elem.resolveTypeBinding());
	if (binding != null && binding.isWildcardType()) {
		binding= ASTResolving.normalizeWildcardType(binding, true, ast);
	}
	if (binding != null) {
		return getImportRewrite().addImport(binding, ast, context, TypeLocation.PARAMETER);
	}
	return ast.newSimpleType(ast.newSimpleName("Object")); //$NON-NLS-1$
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:11,代码来源:NewMethodCorrectionProposal.java

示例7: setInterface

import org.eclipse.jdt.core.dom.AST; //导入方法依赖的package包/类
public void setInterface(AST ast, TypeDeclaration type, TypeDeclaration interfaceToAdd) {
    SimpleType interfaceType = ast.newSimpleType(ast.newSimpleName(interfaceToAdd.getName().getFullyQualifiedName()));
    type.superInterfaceTypes().add(interfaceType);
}
 
开发者ID:helospark,项目名称:SparkBuilderGenerator,代码行数:5,代码来源:InterfaceSetter.java


注:本文中的org.eclipse.jdt.core.dom.AST.newSimpleType方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。