Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2012 itemis AG ( and others. All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse Public License v1.0 which accompanies this distribution, and is available at /
 package org.eclipse.xtext.ui.refactoring.impl;
import static org.eclipse.ltk.core.refactoring.RefactoringStatus.*;
import  org.eclipse.ltk.core.refactoring.RefactoringStatus;
Calculates the new text for a cross reference when the target is renamed. The functionality differs from the original cross reference serializers CrossReferenceSerializer´┐Żand org.eclipse.xtext.serializer.tokens.CrossReferenceSerializer as we have to preserve the syntax of the original cross-reference, e.g. short-cut syntax for a getter call.

Jan Koehnlein - Initial contribution and API
	private static final Logger log = Logger.getLogger(RefactoringCrossReferenceSerializer.class);
	public String getCrossRefText(EObject ownerCrossReference crossrefEObject target,
			RefTextEvaluator refTextEvaluatorITextRegion linkTextRegionStatusWrapper status) {
		try {
			final EReference ref = GrammarUtil.getReference(crossrefowner.eClass());
			final IScope scope = .getScope(ownerref);
			if (scope == null) {
				throw new IllegalStateException("Could not create scope for the given cross reference.");
			String ruleName = .getRuleNameFrom(crossref);
			Iterable<IEObjectDescriptiondescriptionsForCrossRef = scope.getElements(target);
			String bestRefText = null;
			for (IEObjectDescription desc : descriptionsForCrossRef) {
				try {
					String unconvertedRefText = .toString(desc.getName());
					String convertedRefText = .toString(unconvertedRefTextruleName);
					if (refTextEvaluator.isValid(desc) && (bestRefText == null || refTextEvaluator.isBetterThan(convertedRefTextbestRefText)))
						bestRefText = convertedRefText;
catch (ValueConverterException e) {
							"Missconfigured language: New reference text has invalid syntax."ownerlinkTextRegion);
			return bestRefText;
catch (Exception exc) {
			.error(exc.getMessage(), exc);
			status.add(ERROR, exc.getMessage(), ownerlinkTextRegion);
			return null;
	public static interface RefTextEvaluator {
		boolean isBetterThan(String newTextString currentText);
		boolean isValid(IEObjectDescription target);
New to GrepCode? Check out our FAQ X