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


Java ASTRewrite.getAST方法代码示例

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


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

示例1: getNewCastTypeNode

import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; //导入方法依赖的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: copyTypeAndAddDimensions

import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; //导入方法依赖的package包/类
/**
 * Creates a {@link ASTRewrite#createCopyTarget(ASTNode) copy} of <code>type</code>
 * and adds <code>extraDimensions</code> to it.
 *
 * @param type the type to copy
 * @param extraDimensions the dimensions to add
 * @param rewrite the ASTRewrite with which to create new nodes
 * @return the copy target with added dimensions
 */
public static Type copyTypeAndAddDimensions(Type type, List<Dimension> extraDimensions, ASTRewrite rewrite) {
	AST ast= rewrite.getAST();
	if (extraDimensions.isEmpty()) {
		return (Type) rewrite.createCopyTarget(type);
	}

	ArrayType result;
	if (type instanceof ArrayType) {
		ArrayType arrayType= (ArrayType) type;
		Type varElementType= (Type) rewrite.createCopyTarget(arrayType.getElementType());
		result= ast.newArrayType(varElementType, 0);
		result.dimensions().addAll(copyDimensions(extraDimensions, rewrite));
		result.dimensions().addAll(copyDimensions(arrayType.dimensions(), rewrite));
	} else {
		Type elementType= (Type) rewrite.createCopyTarget(type);
		result= ast.newArrayType(elementType, 0);
		result.dimensions().addAll(copyDimensions(extraDimensions, rewrite));
	}
	return result;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:30,代码来源:DimensionRewrite.java

示例3: getNewType

import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; //导入方法依赖的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

示例4: addNewParameters

import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; //导入方法依赖的package包/类
@Override
protected void addNewParameters(ASTRewrite rewrite, List<String> takenNames, List<SingleVariableDeclaration> params, ImportRewriteContext context) throws CoreException {
	AST ast= rewrite.getAST();

	List<Expression> arguments= fArguments;

	for (int i= 0; i < arguments.size(); i++) {
		Expression elem= arguments.get(i);
		SingleVariableDeclaration param= ast.newSingleVariableDeclaration();

		// argument type
		String argTypeKey= "arg_type_" + i; //$NON-NLS-1$
		Type type= evaluateParameterType(ast, elem, argTypeKey, context);
		param.setType(type);

		// argument name
		String argNameKey= "arg_name_" + i; //$NON-NLS-1$
		String name= evaluateParameterName(takenNames, elem, type, argNameKey);
		param.setName(ast.newSimpleName(name));

		params.add(param);
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:24,代码来源:NewMethodCorrectionProposal.java

示例5: createOverrideAnnotation

import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; //导入方法依赖的package包/类
public static void createOverrideAnnotation(ASTRewrite rewrite, ImportRewrite imports, MethodDeclaration decl, TextEditGroup group) {
	if (findAnnotation("java.lang.Override", decl.modifiers()) != null) { //$NON-NLS-1$
		return; // No need to add duplicate annotation
	}
	AST ast= rewrite.getAST();
	ASTNode root= decl.getRoot();
	ImportRewriteContext context= null;
	if (root instanceof CompilationUnit) {
		context= new ContextSensitiveImportRewriteContext((CompilationUnit) root, decl.getStartPosition(), imports);
	}
	Annotation marker= ast.newMarkerAnnotation();
	marker.setTypeName(ast.newName(imports.addImport("java.lang.Override", context))); //$NON-NLS-1$
	rewrite.getListRewrite(decl, MethodDeclaration.MODIFIERS2_PROPERTY).insertFirst(marker, group);
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:15,代码来源:StubUtility2.java

示例6: addNewParameters

import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; //导入方法依赖的package包/类
private void addNewParameters(ASTRewrite rewrite, List<SingleVariableDeclaration> params, ImportRewriteContext context) throws CoreException {
	if (!isGetter) {
		AST ast = rewrite.getAST();

		SingleVariableDeclaration param = ast.newSingleVariableDeclaration();
		Type type = getImportRewrite().addImport(fVariableBinding.getType(), ast, context, TypeLocation.PARAMETER);
		param.setType(type);
		param.setName(ast.newSimpleName(getArgumentName()));
		params.add(param);
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:12,代码来源:SelfEncapsulateFieldProposal.java

示例7: getNewName

import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; //导入方法依赖的package包/类
private SimpleName getNewName(ASTRewrite rewrite) {
	try {
		AST ast = rewrite.getAST();
		SimpleName newNameNode = ast.newSimpleName(getFunctionName());
		return newNameNode;
	} catch (CoreException e) {
		JavaLanguageServerPlugin.logException("Get newname for getter/setter ", e);
	}
	return null;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:11,代码来源:SelfEncapsulateFieldProposal.java

示例8: getNewMethodType

import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; //导入方法依赖的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

示例9: getNewName

import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; //导入方法依赖的package包/类
private SimpleName getNewName(ASTRewrite rewrite) {
	AST ast= rewrite.getAST();
	String name;
	if (fInvocationNode.getLocationInParent() == MemberValuePair.NAME_PROPERTY) {
		name= ((SimpleName) fInvocationNode).getIdentifier();
	} else {
		name= "value"; //$NON-NLS-1$
	}


	SimpleName newNameNode= ast.newSimpleName(name);
	return newNameNode;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:14,代码来源:NewAnnotationMemberProposal.java

示例10: fixupNames

import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; //导入方法依赖的package包/类
private void fixupNames(ASTRewrite rewrite, ArrayList<String> usedNames) {
	AST ast= rewrite.getAST();
	// set names for new parameters
	for (int i= 0; i < fParameterChanges.length; i++) {
		ChangeDescription curr= fParameterChanges[i];
		if (curr instanceof ModifyDescription) {
			ModifyDescription desc= (ModifyDescription) curr;

			String typeKey= getParamTypeGroupId(i);
			String nameKey= getParamNameGroupId(i);

			// collect name suggestions
			String favourite= null;
			String[] excludedNames= usedNames.toArray(new String[usedNames.size()]);

			String suggestedName= desc.name;
			if (suggestedName != null) {
				favourite= StubUtility.suggestArgumentName(getCompilationUnit().getJavaProject(), suggestedName, excludedNames);
			}

			Type type= desc.resultingParamType;
			String[] suggestedNames= StubUtility.getArgumentNameSuggestions(getCompilationUnit().getJavaProject(), type, excludedNames);
			if (favourite == null) {
				favourite= suggestedNames[0];
			}
			usedNames.add(favourite);

			SimpleName[] names= desc.resultingParamName;
			for (int j= 0; j < names.length; j++) {
				names[j].setIdentifier(favourite);
			}

			SimpleName tagArg= desc.resultingTagArg;
			if (tagArg != null) {
				tagArg.setIdentifier(favourite);
			}
		}
	}
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:40,代码来源:ChangeMethodSignatureProposal.java

示例11: getNewName

import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; //导入方法依赖的package包/类
@Override
protected SimpleName getNewName(ASTRewrite rewrite) {
	ASTNode invocationNode= getInvocationNode();
	String name;
	if (invocationNode instanceof MethodInvocation) {
		name= ((MethodInvocation)invocationNode).getName().getIdentifier();
	} else if (invocationNode instanceof SuperMethodInvocation) {
		name= ((SuperMethodInvocation)invocationNode).getName().getIdentifier();
	} else {
		name= getSenderBinding().getName(); // name of the class
	}
	AST ast= rewrite.getAST();
	SimpleName newNameNode= ast.newSimpleName(name);
	return newNameNode;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:16,代码来源:NewMethodCorrectionProposal.java

示例12: getAssignedValue

import org.eclipse.jdt.core.dom.rewrite.ASTRewrite; //导入方法依赖的package包/类
/**
 * Converts an assignment, postfix expression or prefix expression into an
 * assignable equivalent expression using the getter.
 *
 * @param node
 *            the assignment/prefix/postfix node
 * @param astRewrite
 *            the astRewrite to use
 * @param getterExpression
 *            the expression to insert for read accesses or
 *            <code>null</code> if such an expression does not exist
 * @param variableType
 *            the type of the variable that the result will be assigned to
 * @param is50OrHigher
 *            <code>true</code> if a 5.0 or higher environment can be used
 * @return an expression that can be assigned to the type variableType with
 *         node being replaced by a equivalent expression using the getter
 */
public static Expression getAssignedValue(ASTNode node, ASTRewrite astRewrite, Expression getterExpression, ITypeBinding variableType, boolean is50OrHigher) {
	InfixExpression.Operator op = null;
	AST ast = astRewrite.getAST();
	if (isNotInBlock(node)) {
		return null;
	}
	if (node.getNodeType() == ASTNode.ASSIGNMENT) {
		Assignment assignment = ((Assignment) node);
		Expression rightHandSide = assignment.getRightHandSide();
		Expression copiedRightOp = (Expression) astRewrite.createCopyTarget(rightHandSide);
		if (assignment.getOperator() == Operator.ASSIGN) {
			ITypeBinding rightHandSideType = rightHandSide.resolveTypeBinding();
			copiedRightOp = createNarrowCastIfNessecary(copiedRightOp, rightHandSideType, ast, variableType, is50OrHigher);
			return copiedRightOp;
		}
		if (getterExpression != null) {
			InfixExpression infix = ast.newInfixExpression();
			infix.setLeftOperand(getterExpression);
			infix.setOperator(ASTNodes.convertToInfixOperator(assignment.getOperator()));
			ITypeBinding infixType = infix.resolveTypeBinding();
			if (NecessaryParenthesesChecker.needsParenthesesForRightOperand(rightHandSide, infix, variableType)) {
				ParenthesizedExpression p = ast.newParenthesizedExpression();
				p.setExpression(copiedRightOp);
				copiedRightOp = p;
			}
			infix.setRightOperand(copiedRightOp);
			return createNarrowCastIfNessecary(infix, infixType, ast, variableType, is50OrHigher);
		}
	} else if (node.getNodeType() == ASTNode.POSTFIX_EXPRESSION) {
		PostfixExpression po = (PostfixExpression) node;
		if (po.getOperator() == PostfixExpression.Operator.INCREMENT) {
			op = InfixExpression.Operator.PLUS;
		}
		if (po.getOperator() == PostfixExpression.Operator.DECREMENT) {
			op = InfixExpression.Operator.MINUS;
		}
	} else if (node.getNodeType() == ASTNode.PREFIX_EXPRESSION) {
		PrefixExpression pe = (PrefixExpression) node;
		if (pe.getOperator() == PrefixExpression.Operator.INCREMENT) {
			op = InfixExpression.Operator.PLUS;
		}
		if (pe.getOperator() == PrefixExpression.Operator.DECREMENT) {
			op= InfixExpression.Operator.MINUS;
		}
	}
	if (op != null && getterExpression != null) {
		return createInfixInvocationFromPostPrefixExpression(op, getterExpression, ast, variableType, is50OrHigher);
	}
	return null;
}
 
开发者ID:eclipse,项目名称:eclipse.jdt.ls,代码行数:69,代码来源:GetterSetterUtil.java


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