Java源码示例:org.eclipse.text.edits.TextEditGroup

示例1
protected void handleManyMany(ASTNode[] replacements, TextEditGroup description) {
	ListRewrite container= fRewrite.getListRewrite(fToReplace[0].getParent(), (ChildListPropertyDescriptor)fDescriptor);
	if (fToReplace.length == replacements.length) {
		for (int i= 0; i < fToReplace.length; i++) {
			container.replace(fToReplace[i], replacements[i], description);
		}
	} else if (fToReplace.length < replacements.length) {
		for (int i= 0; i < fToReplace.length; i++) {
			container.replace(fToReplace[i], replacements[i], description);
		}
		for (int i= fToReplace.length; i < replacements.length; i++) {
			container.insertAfter(replacements[i], replacements[i - 1], description);
		}
	} else if (fToReplace.length > replacements.length) {
		int delta= fToReplace.length - replacements.length;
		for(int i= 0; i < delta; i++) {
			container.remove(fToReplace[i], description);
		}
		for (int i= delta, r= 0; i < fToReplace.length; i++, r++) {
			container.replace(fToReplace[i], replacements[r], description);
		}
	}
}
 
示例2
/**
 * {@inheritDoc}
 */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException {

	TextEditGroup group= createTextEditGroup(FixMessages.UnusedCodeFix_RemoveCast_description, cuRewrite);

	ASTRewrite rewrite= cuRewrite.getASTRewrite();

	CastExpression cast= fCast;
	Expression expression= cast.getExpression();
	if (expression instanceof ParenthesizedExpression) {
		Expression childExpression= ((ParenthesizedExpression) expression).getExpression();
		if (NecessaryParenthesesChecker.needsParentheses(childExpression, cast, CastExpression.EXPRESSION_PROPERTY)) {
			expression= childExpression;
		}
	}
	
	replaceCast(cast, expression, rewrite, group);
}
 
示例3
private void addRequiredImportDeclarationsToContext() {
	ImportRewrite sourceImportRewrite = ImportRewrite.create(sourceCompilationUnit, true);
	for(ITypeBinding typeBinding : requiredImportDeclarationsForContext) {
		if(!typeBinding.isNested())
			sourceImportRewrite.addImport(typeBinding);
	}

	try {
		TextEdit sourceImportEdit = sourceImportRewrite.rewriteImports(null);
		if(sourceImportRewrite.getCreatedImports().length > 0) {
			ICompilationUnit sourceICompilationUnit = (ICompilationUnit)sourceCompilationUnit.getJavaElement();
			CompilationUnitChange change = compilationUnitChanges.get(sourceICompilationUnit);
			change.getEdit().addChild(sourceImportEdit);
			change.addTextEditGroup(new TextEditGroup("Add required import declarations", new TextEdit[] {sourceImportEdit}));
		}
	} catch (CoreException e) {
		e.printStackTrace();
	}
}
 
示例4
/**
 * Removes all {@link Annotation} whose only {@link Target} is {@link ElementType#TYPE_USE} from
 * <code>node</code>'s <code>childListProperty</code>.
 * <p>
 * In a combination of {@link ElementType#TYPE_USE} and {@link ElementType#TYPE_PARAMETER}
 * the latter is ignored, because this is implied by the former and creates no ambiguity.</p>
 *
 * @param node ASTNode
 * @param childListProperty child list property
 * @param rewrite rewrite that removes the nodes
 * @param editGroup the edit group in which to collect the corresponding text edits, or null if
 *            ungrouped
 */
public static void removePureTypeAnnotations(ASTNode node, ChildListPropertyDescriptor childListProperty, ASTRewrite rewrite, TextEditGroup editGroup) {
	CompilationUnit root= (CompilationUnit) node.getRoot();
	if (!JavaModelUtil.is18OrHigher(root.getJavaElement().getJavaProject())) {
		return;
	}
	ListRewrite listRewrite= rewrite.getListRewrite(node, childListProperty);
	@SuppressWarnings("unchecked")
	List<? extends ASTNode> children= (List<? extends ASTNode>) node.getStructuralProperty(childListProperty);
	for (ASTNode child : children) {
		if (child instanceof Annotation) {
			Annotation annotation= (Annotation) child;
			if (isPureTypeAnnotation(annotation)) {
				listRewrite.remove(child, editGroup);
			}
		}
	}
}
 
示例5
private void addReplaceExpressionWithTemp() throws JavaModelException {
	IASTFragment[] fragmentsToReplace = retainOnlyReplacableMatches(getMatchingFragments());
	//TODO: should not have to prune duplicates here...
	ASTRewrite rewrite = fCURewrite.getASTRewrite();
	HashSet<IASTFragment> seen = new HashSet<>();
	for (int i = 0; i < fragmentsToReplace.length; i++) {
		IASTFragment fragment = fragmentsToReplace[i];
		if (!seen.add(fragment)) {
			continue;
		}
		SimpleName tempName = fCURewrite.getAST().newSimpleName(fTempName);
		TextEditGroup description = fCURewrite.createGroupDescription(RefactoringCoreMessages.ExtractTempRefactoring_replace);

		fragment.replace(rewrite, tempName, description);
		if (fLinkedProposalModel != null) {
			fLinkedProposalModel.getPositionGroup(KEY_NAME, true).addPosition(rewrite.track(tempName), false);
		}
	}
}
 
示例6
/**
 * {@inheritDoc}
 */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException {
	ASTRewrite rewrite= cuRewrite.getASTRewrite();
	TextEditGroup group= createTextEditGroup(getDescription(), cuRewrite);
	AST ast= rewrite.getAST();

	FieldAccess fieldAccess= ast.newFieldAccess();

	ThisExpression thisExpression= ast.newThisExpression();
	if (fQualifier != null)
		thisExpression.setQualifier(ast.newName(fQualifier));

	fieldAccess.setExpression(thisExpression);
	fieldAccess.setName((SimpleName) rewrite.createMoveTarget(fName));

	rewrite.replace(fName, fieldAccess, group);
}
 
示例7
private void addAdditionalMethodsToTargetClass() {
	AST ast = targetTypeDeclaration.getAST();
	Set<MethodDeclaration> methodsToBeMoved = new LinkedHashSet<MethodDeclaration>(additionalMethodsToBeMoved.values());
	for(MethodDeclaration methodDeclaration : methodsToBeMoved) {
		TypeVisitor typeVisitor = new TypeVisitor();
		methodDeclaration.accept(typeVisitor);
		for(ITypeBinding typeBinding : typeVisitor.getTypeBindings()) {
			this.additionalTypeBindingsToBeImportedInTargetClass.add(typeBinding);
		}
		MethodDeclaration newMethodDeclaration = (MethodDeclaration)ASTNode.copySubtree(ast, methodDeclaration);
		ASTRewrite targetRewriter = ASTRewrite.create(targetCompilationUnit.getAST());
		ListRewrite targetClassBodyRewrite = targetRewriter.getListRewrite(targetTypeDeclaration, TypeDeclaration.BODY_DECLARATIONS_PROPERTY);
		targetClassBodyRewrite.insertLast(newMethodDeclaration, null);
		try {
			TextEdit targetEdit = targetRewriter.rewriteAST();
			targetMultiTextEdit.addChild(targetEdit);
			targetCompilationUnitChange.addTextEditGroup(new TextEditGroup("Add additional moved method", new TextEdit[] {targetEdit}));
		}
		catch(JavaModelException javaModelException) {
			javaModelException.printStackTrace();
		}
	}
}
 
示例8
/**
 * {@inheritDoc}
 */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException {
	TextEditGroup group= createTextEditGroup(FixMessages.ExpressionsFix_addParanoiacParentheses_description, cuRewrite);

	ASTRewrite rewrite= cuRewrite.getASTRewrite();
	AST ast= cuRewrite.getRoot().getAST();

	for (int i= 0; i < fExpressions.length; i++) {
		// add parenthesis around expression
		Expression expression= fExpressions[i];

		ParenthesizedExpression parenthesizedExpression= ast.newParenthesizedExpression();
		parenthesizedExpression.setExpression((Expression) rewrite.createCopyTarget(expression));
		rewrite.replace(expression, parenthesizedExpression, group);
	}
}
 
示例9
protected void handleManyMany(ASTNode[] replacements, TextEditGroup description) {
	ListRewrite container= fRewrite.getListRewrite(fToReplace[0].getParent(), (ChildListPropertyDescriptor)fDescriptor);
	if (fToReplace.length == replacements.length) {
		for (int i= 0; i < fToReplace.length; i++) {
			container.replace(fToReplace[i], replacements[i], description);
		}
	} else if (fToReplace.length < replacements.length) {
		for (int i= 0; i < fToReplace.length; i++) {
			container.replace(fToReplace[i], replacements[i], description);
		}
		for (int i= fToReplace.length; i < replacements.length; i++) {
			container.insertAfter(replacements[i], replacements[i - 1], description);
		}
	} else if (fToReplace.length > replacements.length) {
		int delta= fToReplace.length - replacements.length;
		for(int i= 0; i < delta; i++) {
			container.remove(fToReplace[i], description);
		}
		for (int i= delta, r= 0; i < fToReplace.length; i++, r++) {
			container.replace(fToReplace[i], replacements[r], description);
		}
	}
}
 
示例10
/**
 * Moves the given text edit groups (and its text edits) into the given
 * change.
 */
public static void moveTextEditGroupsIntoChange(
    TextEditBasedChangeGroup[] groups, TextChange textChange) {
  for (TextEditBasedChangeGroup changeGroup : groups) {
    TextEditGroup group = changeGroup.getTextEditGroup();
    for (TextEdit edit : group.getTextEdits()) {
      if (edit.getParent() != null) {
        edit.getParent().removeChild(edit);
      }

      textChange.addEdit(edit);
    }

    // We must create a new change group since it doesn't have API to change
    // the parent change
    TextEditBasedChangeGroup newChangeGroup = new TextEditBasedChangeGroup(
        textChange, group);
    newChangeGroup.setEnabled(changeGroup.isEnabled());
    textChange.addChangeGroup(newChangeGroup);
  }
}
 
示例11
private void addInheritedTypeQualifications(final AbstractTypeDeclaration declaration, final CompilationUnitRewrite targetRewrite, final TextEditGroup group) {
	Assert.isNotNull(declaration);
	Assert.isNotNull(targetRewrite);
	final CompilationUnit unit= (CompilationUnit) declaration.getRoot();
	final ITypeBinding binding= declaration.resolveBinding();
	if (binding != null) {
		Type type= null;
		if (declaration instanceof TypeDeclaration) {
			type= ((TypeDeclaration) declaration).getSuperclassType();
			if (type != null && unit.findDeclaringNode(binding) != null)
				addTypeQualification(type, targetRewrite, group);
		}
		List<Type> types= null;
		if (declaration instanceof TypeDeclaration)
			types= ((TypeDeclaration) declaration).superInterfaceTypes();
		else if (declaration instanceof EnumDeclaration)
			types= ((EnumDeclaration) declaration).superInterfaceTypes();
		if (types != null) {
			for (final Iterator<Type> iterator= types.iterator(); iterator.hasNext();) {
				type= iterator.next();
				if (unit.findDeclaringNode(type.resolveBinding()) != null)
					addTypeQualification(type, targetRewrite, group);
			}
		}
	}
}
 
示例12
private void rewriteExtraDimensions(int oldDim, int newDim, int pos, TextEditGroup editGroup) {

		if (oldDim < newDim) {
			for (int i= oldDim; i < newDim; i++) {
				doTextInsert(pos, "[]", editGroup); //$NON-NLS-1$
			}
		} else if (newDim < oldDim) {
			try {
				getScanner().setOffset(pos);
				for (int i= newDim; i < oldDim; i++) {
					getScanner().readToToken(TerminalTokens.TokenNameRBRACKET);
				}
				doTextRemove(pos, getScanner().getCurrentEndOffset() - pos, editGroup);
			} catch (CoreException e) {
				handleException(e);
			}
		}
	}
 
示例13
@Override
protected void changeParamgumentName(ParameterInfo info) {
	VariableDeclaration param= getParameter(info.getOldIndex());
	if (!info.getOldName().equals(param.getName().getIdentifier()))
		return; //don't change if original parameter name != name in rippleMethod

	String msg= RefactoringCoreMessages.ChangeSignatureRefactoring_update_parameter_references;
	TextEditGroup description= fCuRewrite.createGroupDescription(msg);
	TempOccurrenceAnalyzer analyzer= new TempOccurrenceAnalyzer(param, false);
	analyzer.perform();
	SimpleName[] paramOccurrences= analyzer.getReferenceAndDeclarationNodes(); // @param tags are updated in changeJavaDocTags()
	for (int j= 0; j < paramOccurrences.length; j++) {
		SimpleName occurence= paramOccurrences[j];
		getASTRewrite().set(occurence, SimpleName.IDENTIFIER_PROPERTY, info.getNewName(), description);
	}
}
 
示例14
private void addReplaceExpressionWithTemp() throws JavaModelException {
	IASTFragment[] fragmentsToReplace= retainOnlyReplacableMatches(getMatchingFragments());
	//TODO: should not have to prune duplicates here...
	ASTRewrite rewrite= fCURewrite.getASTRewrite();
	HashSet<IASTFragment> seen= new HashSet<IASTFragment>();
	for (int i= 0; i < fragmentsToReplace.length; i++) {
		IASTFragment fragment= fragmentsToReplace[i];
		if (! seen.add(fragment))
			continue;
		SimpleName tempName= fCURewrite.getAST().newSimpleName(fTempName);
		TextEditGroup description= fCURewrite.createGroupDescription(RefactoringCoreMessages.ExtractTempRefactoring_replace);

		fragment.replace(rewrite, tempName, description);
		if (fLinkedProposalModel != null)
			fLinkedProposalModel.getPositionGroup(KEY_NAME, true).addPosition(rewrite.track(tempName), false);
	}
}
 
示例15
private void createStateField() {
	ASTRewrite sourceRewriter = ASTRewrite.create(sourceTypeDeclaration.getAST());
	AST contextAST = sourceTypeDeclaration.getAST();
	ListRewrite contextBodyRewrite = sourceRewriter.getListRewrite(sourceTypeDeclaration, TypeDeclaration.BODY_DECLARATIONS_PROPERTY);
	VariableDeclarationFragment typeFragment = createStateFieldVariableDeclarationFragment(sourceRewriter, contextAST);
	
	FieldDeclaration typeFieldDeclaration = contextAST.newFieldDeclaration(typeFragment);
	sourceRewriter.set(typeFieldDeclaration, FieldDeclaration.TYPE_PROPERTY, contextAST.newSimpleName(abstractClassName), null);
	ListRewrite typeFieldDeclarationModifiersRewrite = sourceRewriter.getListRewrite(typeFieldDeclaration, FieldDeclaration.MODIFIERS2_PROPERTY);
	typeFieldDeclarationModifiersRewrite.insertLast(contextAST.newModifier(Modifier.ModifierKeyword.PRIVATE_KEYWORD), null);
	contextBodyRewrite.insertBefore(typeFieldDeclaration, typeCheckElimination.getTypeField().getParent(), null);
	
	try {
		TextEdit sourceEdit = sourceRewriter.rewriteAST();
		ICompilationUnit sourceICompilationUnit = (ICompilationUnit)sourceCompilationUnit.getJavaElement();
		CompilationUnitChange change = compilationUnitChanges.get(sourceICompilationUnit);
		change.getEdit().addChild(sourceEdit);
		change.addTextEditGroup(new TextEditGroup("Create field holding the current state", new TextEdit[] {sourceEdit}));
	} catch (JavaModelException e) {
		e.printStackTrace();
	}
}
 
示例16
private static void markAsDeleted(List<ASTNode> list, IJavaElement element, CompilationUnitRewrite rewrite, TextEditGroup group) throws JavaModelException {
	ASTNode[] declarationNodes= getNodesToDelete(element, rewrite.getRoot());
	for (int i= 0; i < declarationNodes.length; i++) {
		ASTNode node= declarationNodes[i];
		if (node != null) {
			list.add(node);
			rewrite.getASTRewrite().remove(node, group);
			rewrite.getImportRemover().registerRemovedNode(node);
		}
	}
}
 
示例17
public void replace(ASTNode[] replacements, TextEditGroup description) {
	if (fToReplace.length == 1) {
		if (replacements.length == 1) {
			handleOneOne(replacements, description);
		} else {
			handleOneMany(replacements, description);
		}
	} else {
		handleManyMany(replacements, description);
	}
}
 
示例18
public static void markAsDeleted(IJavaElement[] javaElements, CompilationUnitRewrite rewrite, TextEditGroup group) throws JavaModelException {
	final List<ASTNode> removed= new ArrayList<ASTNode>();
	for (int i= 0; i < javaElements.length; i++) {
		markAsDeleted(removed, javaElements[i], rewrite, group);
	}
	propagateFieldDeclarationNodeDeletions(removed, rewrite, group);
}
 
示例19
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel linkedModel) throws CoreException {
	AST ast= cuRewrite.getRoot().getAST();
	ListRewrite listRewrite= cuRewrite.getASTRewrite().getListRewrite(fArgument, SingleVariableDeclaration.MODIFIERS2_PROPERTY);
	TextEditGroup group= createTextEditGroup(fMessage, cuRewrite);
	if (!checkExisting(fArgument.modifiers(), listRewrite, group))
		return;
	Annotation newAnnotation= ast.newMarkerAnnotation();
	ImportRewrite importRewrite= cuRewrite.getImportRewrite();
	String resolvableName= importRewrite.addImport(fAnnotationToAdd);
	newAnnotation.setTypeName(ast.newName(resolvableName));
	listRewrite.insertLast(newAnnotation, group); // null annotation is last modifier, directly preceding the type
}
 
示例20
public boolean visit(Modifier node) {
	if (!hasChildrenChanges(node)) {
		return doVisitUnchangedChildren(node);
	}
	String newText= getNewValue(node, Modifier.KEYWORD_PROPERTY).toString(); // type Modifier.ModifierKeyword
	TextEditGroup group = getEditGroup(node, Modifier.KEYWORD_PROPERTY);
	doTextReplace(node.getStartPosition(), node.getLength(), newText, group);
	return false;
}
 
示例21
private void removeKey(NLSSubstitution sub, TextChange change) {
	ASTNode node= findField(fRoot, sub.getInitialKey());
	if (node == null)
		return;

	String name= Messages.format(NLSMessages.AccessorClassModifier_remove_entry, BasicElementLabels.getJavaElementName(sub.getKey()));
	TextEditGroup editGroup= new TextEditGroup(name);
	fListRewrite.remove(node, editGroup);
	change.addTextEditGroup(editGroup);
	fFields.remove(node);
}
 
示例22
@Override
public void replace(ASTRewrite rewrite, ASTNode replacement, TextEditGroup textEditGroup) {
	if (replacement instanceof Name && fNode.getParent() instanceof ParenthesizedExpression) {
		// replace including the parenthesized expression around it
		rewrite.replace(fNode.getParent(), replacement, textEditGroup);
	} else {
		rewrite.replace(fNode, replacement, textEditGroup);
	}
}
 
示例23
/**
 * Replaces the given node in this rewriter. The replacement node
 * must either be brand new (not part of the original AST) or a placeholder
 * node (for example, one created by {@link #createCopyTarget(ASTNode)}
 * or {@link #createStringPlaceholder(String, int)}). The AST itself
    * is not actually modified in any way; rather, the rewriter just records
    * a note that this node has been replaced.
 *
 * @param node the node being replaced. The node can either be an original node in the AST
 * or (since 3.4) a new node already inserted or used as replacement in this AST rewriter.
 * @param replacement the replacement node, or <code>null</code> if no
 * replacement
 * @param editGroup the edit group in which to collect the corresponding
 * text edits, or <code>null</code> if ungrouped
 * @throws IllegalArgumentException if the node is null, or if the node is not part
 * of this rewriter's AST, or if the replacement node is not a new node (or
    * placeholder), or if the described modification is otherwise invalid
 */
public final void replace(ASTNode node, ASTNode replacement, TextEditGroup editGroup) {
	if (node == null) {
		throw new IllegalArgumentException();
	}

	StructuralPropertyDescriptor property;
	ASTNode parent;
	if (RewriteEventStore.isNewNode(node)) { // replace a new node, bug 164862
		PropertyLocation location= this.eventStore.getPropertyLocation(node, RewriteEventStore.NEW);
		if (location != null) {
			property= location.getProperty();
			parent= location.getParent();
		} else {
			throw new IllegalArgumentException("Node is not part of the rewriter's AST"); //$NON-NLS-1$
		}
	} else {
		property= node.getLocationInParent();
		parent= node.getParent();
	}

	if (property.isChildListProperty()) {
		getListRewrite(parent, (ChildListPropertyDescriptor) property).replace(node, replacement, editGroup);
	} else {
		set(parent, property, replacement, editGroup);
	}
}
 
示例24
public void copyAllAnnotations(ASTNode otherDecl, TextEditGroup editGroup) {
	ListRewrite modifierList= evaluateListRewrite(fModifierRewrite.getASTRewrite(), otherDecl);
	List<IExtendedModifier> originalList= modifierList.getOriginalList();

	for (Iterator<IExtendedModifier> iterator= originalList.iterator(); iterator.hasNext();) {
		IExtendedModifier modifier= iterator.next();
		if (modifier.isAnnotation()) {
			fModifierRewrite.insertLast(fModifierRewrite.getASTRewrite().createCopyTarget((Annotation) modifier), editGroup);
		}
	}
}
 
示例25
private void createEdits() {
	TextEdit declarationEdit= createRenameEdit(fTempDeclarationNode.getName().getStartPosition());
	TextEdit[] allRenameEdits= getAllRenameEdits(declarationEdit);

	TextEdit[] allUnparentedRenameEdits= new TextEdit[allRenameEdits.length];
	TextEdit unparentedDeclarationEdit= null;

	fChange= new CompilationUnitChange(RefactoringCoreMessages.RenameTempRefactoring_rename, fCu);
	MultiTextEdit rootEdit= new MultiTextEdit();
	fChange.setEdit(rootEdit);
	fChange.setKeepPreviewEdits(true);

	for (int i= 0; i < allRenameEdits.length; i++) {
		if (fIsComposite) {
			// Add a copy of the text edit (text edit may only have one
			// parent) to keep problem reporting code clean
			TextChangeCompatibility.addTextEdit(fChangeManager.get(fCu), RefactoringCoreMessages.RenameTempRefactoring_changeName, allRenameEdits[i].copy(), fCategorySet);

			// Add a separate copy for problem reporting
			allUnparentedRenameEdits[i]= allRenameEdits[i].copy();
			if (allRenameEdits[i].equals(declarationEdit)) {
				unparentedDeclarationEdit= allUnparentedRenameEdits[i];
			}
		}
		rootEdit.addChild(allRenameEdits[i]);
		fChange.addTextEditGroup(new TextEditGroup(RefactoringCoreMessages.RenameTempRefactoring_changeName, allRenameEdits[i]));
	}

	// store information for analysis
	if (fIsComposite) {
		fLocalAnalyzePackage= new RenameAnalyzeUtil.LocalAnalyzePackage(unparentedDeclarationEdit, allUnparentedRenameEdits);
	} else {
		fLocalAnalyzePackage= new RenameAnalyzeUtil.LocalAnalyzePackage(declarationEdit, allRenameEdits);
	}
}
 
示例26
private void removeParamTag(ASTRewrite rewrite, SingleVariableDeclaration varDecl, TextEditGroup group) {
	if (varDecl.getParent() instanceof MethodDeclaration) {
		Javadoc javadoc= ((MethodDeclaration) varDecl.getParent()).getJavadoc();
		if (javadoc != null) {
			TagElement tagElement= JavadocTagsSubProcessor.findParamTag(javadoc, varDecl.getName().getIdentifier());
			if (tagElement != null) {
				rewrite.remove(tagElement, group);
			}
		}
	}
}
 
示例27
private int rewriteRequiredNode(ASTNode parent, StructuralPropertyDescriptor property) {
	RewriteEvent event= getEvent(parent, property);
	if (event != null && event.getChangeKind() == RewriteEvent.REPLACED) {
		ASTNode node= (ASTNode) event.getOriginalValue();
		TextEditGroup editGroup= getEditGroup(event);
		SourceRange range= getExtendedRange(node);
		int offset= range.getStartPosition();
		int length= range.getLength();
		doTextRemoveAndVisit(offset, length, node, editGroup);
		doTextInsert(offset, (ASTNode) event.getNewValue(), getIndent(offset), true, editGroup);
		return offset + length;
	}
	return doVisit(parent, property, 0);
}
 
示例28
/**
 * {@inheritDoc}
 */
@Override
public void rewriteAST(CompilationUnitRewrite cuRewrite, LinkedProposalModel model) throws CoreException {
	TextEditGroup group= createTextEditGroup(FixMessages.CodeStyleFix_ChangeAccessUsingDeclaring_description, cuRewrite);

	if (fQualifier instanceof MethodInvocation || fQualifier instanceof ClassInstanceCreation)
		extractQualifier(fQualifier, cuRewrite, group);

	Type type= importType(fDeclaringTypeBinding, fQualifier, cuRewrite.getImportRewrite(), cuRewrite.getRoot());
	cuRewrite.getASTRewrite().replace(fQualifier, type, group);
}
 
示例29
private void replaceExpressionsWithConstant() throws JavaModelException {
	ASTRewrite astRewrite = fCuRewrite.getASTRewrite();
	AST ast = astRewrite.getAST();

	IASTFragment[] fragmentsToReplace = getFragmentsToReplace();
	for (int i = 0; i < fragmentsToReplace.length; i++) {
		IASTFragment fragment = fragmentsToReplace[i];
		ASTNode node = fragment.getAssociatedNode();
		boolean inTypeDeclarationAnnotation = isInTypeDeclarationAnnotation(node);
		if (inTypeDeclarationAnnotation && JdtFlags.VISIBILITY_STRING_PRIVATE == getVisibility()) {
			continue;
		}

		SimpleName ref = ast.newSimpleName(fConstantName);
		Name replacement = ref;
		boolean qualifyReference = qualifyReferencesWithDeclaringClassName();
		if (!qualifyReference) {
			qualifyReference = inTypeDeclarationAnnotation;
		}
		if (qualifyReference) {
			replacement = ast.newQualifiedName(ast.newSimpleName(getContainingTypeBinding().getName()), ref);
		}
		TextEditGroup description = fCuRewrite.createGroupDescription(RefactoringCoreMessages.ExtractConstantRefactoring_replace);

		fragment.replace(astRewrite, replacement, description);
		if (fLinkedProposalModel != null) {
			fLinkedProposalModel.getPositionGroup(KEY_NAME, true).addPosition(astRewrite.track(ref), false);
		}
	}
}
 
示例30
private void createEdits(ICompilationUnit unit, ASTRewrite rewriter, List<TextEditGroup> groups, ImportRewrite importRewrite) throws CoreException {
	TextChange change = fChangeManager.get(unit);
	MultiTextEdit root = new MultiTextEdit();
	change.setEdit(root);
	root.addChild(importRewrite.rewriteImports(null));
	root.addChild(rewriter.rewriteAST());
	for (Iterator<TextEditGroup> iter = groups.iterator(); iter.hasNext();) {
		change.addTextEditGroup(iter.next());
	}
}