use of org.eclipse.xtext.ui.refactoring.impl.RefactoringCrossReferenceSerializer.RefTextEvaluator in project xtext-eclipse by eclipse.
the class DefaultReferenceUpdater method createReferenceUpdate.
protected void createReferenceUpdate(EObject referringElement, URI referringResourceURI, EReference reference, int indexInList, EObject newTargetElement, IRefactoringUpdateAcceptor updateAcceptor) {
if (!transientValueService.isValueInListTransient(referringElement, indexInList, reference)) {
ITextRegion referenceTextRegion = locationInFileProvider.getFullTextRegion(referringElement, reference, indexInList);
if (referenceTextRegion != null) {
CrossReference crossReference = getCrossReference(referringElement, referenceTextRegion.getOffset());
if (crossReference != null) {
RefTextEvaluator refTextComparator = getRefTextEvaluator(referringElement, referringResourceURI, reference, indexInList, newTargetElement);
String newReferenceText = crossReferenceSerializer.getCrossRefText(referringElement, crossReference, newTargetElement, refTextComparator, referenceTextRegion, updateAcceptor.getRefactoringStatus());
if (newReferenceText == null) {
newReferenceText = resolveNameConflict(referringElement, reference, newTargetElement, updateAcceptor);
}
if (newReferenceText == null) {
updateAcceptor.getRefactoringStatus().add(RefactoringStatus.ERROR, "Refactoring introduces a name conflict.", referringElement, referenceTextRegion);
}
createTextChange(referenceTextRegion, newReferenceText, referringElement, newTargetElement, reference, referringResourceURI, updateAcceptor);
}
}
}
}
use of org.eclipse.xtext.ui.refactoring.impl.RefactoringCrossReferenceSerializer.RefTextEvaluator in project xtext-eclipse by eclipse.
the class JvmModelReferenceUpdater method getRefTextEvaluator.
/**
* Preserves the syntax of method calls if the target is refactored.
*
* @since 2.4
*/
@Override
protected RefTextEvaluator getRefTextEvaluator(final EObject referringElement, URI referringResourceURI, final EReference reference, int indexInList, EObject newTargetElement) {
final ReferenceSyntax oldReferenceSyntax = getReferenceSyntax(referringElement, reference, indexInList);
if (oldReferenceSyntax == null)
return super.getRefTextEvaluator(referringElement, referringResourceURI, reference, indexInList, newTargetElement);
return new RefTextEvaluator() {
@Override
public boolean isValid(IEObjectDescription newTarget) {
IScope scope = linkingScopeProvider.getScope(referringElement, reference);
IEObjectDescription element = scope.getSingleElement(newTarget.getName());
// TODO here we need to simulate linking with the new name instead of the old name
if (element instanceof IIdentifiableElementDescription) {
IIdentifiableElementDescription casted = (IIdentifiableElementDescription) element;
if (!casted.isVisible() || !casted.isValidStaticState())
return false;
}
return element != null && element.getEObjectURI() != null && element.getEObjectURI().equals(newTarget.getEObjectURI());
}
@Override
public boolean isBetterThan(String newText, String currentText) {
ReferenceSyntax newSyntax = getReferenceSyntax(newText);
ReferenceSyntax currentSyntax = getReferenceSyntax(currentText);
// prefer the one with the same syntax as before
if (newSyntax == oldReferenceSyntax && currentSyntax != oldReferenceSyntax)
return true;
else if (newSyntax != oldReferenceSyntax && currentSyntax == oldReferenceSyntax)
return false;
else
// in doubt shorter is better
return newText.length() < currentText.length();
}
};
}
Aggregations