use of org.eclipse.xtext.CrossReference in project xtext-eclipse by eclipse.
the class RefactoringCrossReferenceSerializerTest method testSerializer.
@Test
public void testSerializer() throws Exception {
RefactoringCrossReferenceSerializer.RefTextEvaluator evaluator = new RefactoringCrossReferenceSerializer.RefTextEvaluator() {
@Override
public boolean isValid(IEObjectDescription target) {
return true;
}
@Override
public boolean isBetterThan(String newText, String currentText) {
return newText.length() < currentText.length();
}
};
String model = "bar { ref foo } foo";
String wsRelativePath = "test/test." + getCurrentFileExtension();
IFile file = createFile(wsRelativePath, model);
Main main = (Main) getModel(file.getContents());
XtextResource resource = (XtextResource) main.eResource();
resource.setURI(URI.createPlatformResourceURI(wsRelativePath, true));
Element bar = (Element) main.getElements().get(0);
Element foo = bar.getReferenced().get(0);
assertEquals("foo", foo.getName());
CrossReference crossref = GrammarUtil.containedCrossReferences(grammarAccess.getElementRule()).get(0);
TextRegion linkTextRegion = new TextRegion(model.lastIndexOf("foo"), 3);
String linkText = facade.getCrossRefText(bar, crossref, foo, evaluator, linkTextRegion, status);
assertEquals(linkText, "foo");
assertTrue(status.getRefactoringStatus().isOK());
foo.setName("fooBar");
resource.getCache().clear(resource);
String linkText1 = facade.getCrossRefText(bar, crossref, foo, evaluator, linkTextRegion, status);
assertEquals(linkText1, "fooBar");
assertTrue(status.getRefactoringStatus().isOK());
assertEquals(foo, ((Main) resource.getContents().get(0)).getElements().get(1));
foo.setName("bar");
resource.getCache().clear(resource);
assertNull(facade.getCrossRefText(bar, crossref, foo, evaluator, linkTextRegion, status));
}
use of org.eclipse.xtext.CrossReference in project xtext-eclipse by eclipse.
the class XbaseProposalProvider method getConcreteSyntaxRuleName.
protected String getConcreteSyntaxRuleName(Assignment assignment) {
AbstractElement terminal = assignment.getTerminal();
if (terminal instanceof CrossReference) {
return getConcreteSyntaxRuleName((CrossReference) terminal);
}
String ruleName = null;
if (terminal instanceof RuleCall) {
ruleName = getConcreteSyntaxRuleName((RuleCall) terminal);
}
return ruleName;
}
use of org.eclipse.xtext.CrossReference in project xtext-eclipse by eclipse.
the class XbaseWithAnnotationsProposalProvider method completeXAnnotationElementValuePair_Element.
@Override
public void completeXAnnotationElementValuePair_Element(EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
XAnnotation annotationReference = null;
if (model instanceof XAnnotationElementValuePair) {
annotationReference = (XAnnotation) model.eContainer();
} else if (model instanceof XAnnotation) {
annotationReference = (XAnnotation) model;
}
if (annotationReference != null) {
JvmType annotationType = annotationReference.getAnnotationType();
if (annotationType != null && !annotationType.eIsProxy() && annotationType instanceof JvmAnnotationType) {
// do not propose features like #toString, #hashCode etc
JvmAnnotationType casted = (JvmAnnotationType) annotationType;
final Set<JvmOperation> operations = Sets.newHashSet(casted.getDeclaredOperations());
Predicate<IEObjectDescription> predicate = Predicates.and(new Predicate<IEObjectDescription>() {
@Override
public boolean apply(IEObjectDescription in) {
return operations.contains(in.getEObjectOrProxy());
}
}, getFeatureDescriptionPredicate(context));
lookupCrossReference(((CrossReference) assignment.getTerminal()), context, acceptor, predicate);
}
}
}
use of org.eclipse.xtext.CrossReference in project xtext-eclipse by eclipse.
the class XtextLabelProvider method text.
String text(Assignment object) {
StringBuffer label = new StringBuffer();
label.append(object.getFeature()).append(" ").append(object.getOperator()).append(" ");
AbstractElement terminal = object.getTerminal();
if (terminal instanceof RuleCall) {
RuleCall ruleCall = (RuleCall) terminal;
String string = NodeModelUtils.getNode(ruleCall).getText();
label.append(string);
} else if (terminal instanceof Keyword) {
Keyword keyword = (Keyword) terminal;
String value = "'" + keyword.getValue() + "'";
label.append(value);
} else if (terminal instanceof CrossReference) {
CrossReference crossReference = (CrossReference) terminal;
label.append(getLabel(crossReference));
} else {
label.append("(..)");
}
String cardinality = object.getCardinality();
label.append(cardinality != null ? cardinality : "");
return label.toString();
}
use of org.eclipse.xtext.CrossReference in project xtext-eclipse by eclipse.
the class XtextProposalProvider method completeRuleCall.
private void completeRuleCall(EObject model, Assignment assignment, final ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
final Assignment containingAssignment = GrammarUtil.containingAssignment(model);
CrossReference crossReference = (CrossReference) assignment.getTerminal();
lookupCrossReference(crossReference, context, acceptor, new Predicate<IEObjectDescription>() {
@Override
public boolean apply(IEObjectDescription input) {
if (input.getEClass() == XtextPackage.Literals.TERMINAL_RULE) {
EObject object = resolve(input, context);
if (object instanceof TerminalRule) {
return !((TerminalRule) object).isFragment();
}
}
if (containingAssignment != null && input.getEClass() == XtextPackage.Literals.PARSER_RULE) {
EObject object = resolve(input, context);
if (object instanceof ParserRule) {
return !((ParserRule) object).isFragment();
}
}
return true;
}
});
}
Aggregations