use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.
the class ExtractMethodRefactoring method initialize.
public boolean initialize(XtextEditor editor, List<XExpression> selectedExpressions, boolean doSave) {
if (selectedExpressions.isEmpty() || editor.getDocument() == null)
return false;
this.document = editor.getDocument();
this.doSave = doSave;
this.editor = editor;
this.expressions = calculateExpressions(selectedExpressions);
this.firstExpression = this.expressions.get(0);
this.originalMethod = EcoreUtil2.getContainerOfType(firstExpression, XtendFunction.class);
this.lastExpression = this.expressions.get(this.expressions.size() - 1);
this.resourceURI = EcoreUtil2.getPlatformResourceOrNormalizedURI(firstExpression).trimFragment();
this.xtendClass = EcoreUtil2.getContainerOfType(firstExpression, XtendClass.class);
if (xtendClass == null || originalMethod == null)
return false;
this.visibility = JvmVisibility.PROTECTED;
this.isStatic = originalMethod.isStatic();
this.isExplicitlyDeclareReturnType = true;
XExpression successorExpression = expressionUtil.findSuccessorExpressionForVariableDeclaration(lastExpression);
nameUtil.setFeatureScopeContext(successorExpression);
rewriter = rewriterFactory.create(document, (XtextResource) firstExpression.eResource());
return true;
}
use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.
the class XtendHighlightingCalculator method highlightElement.
protected void highlightElement(XtendFunction function, IHighlightedPositionAcceptor acceptor, CancelIndicator cancelIndicator) {
highlightFeature(acceptor, function, XtendPackage.Literals.XTEND_FUNCTION__NAME, METHOD);
XExpression rootExpression = function.getExpression();
highlightRichStrings(rootExpression, acceptor);
CreateExtensionInfo createExtensionInfo = function.getCreateExtensionInfo();
if (createExtensionInfo != null) {
highlightRichStrings(createExtensionInfo.getCreateExpression(), acceptor);
}
}
use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.
the class XtendHighlightingCalculator method highlightElement.
protected void highlightElement(XtendField field, IHighlightedPositionAcceptor acceptor, CancelIndicator cancelIndicator) {
highlightFeature(acceptor, field, XtendPackage.Literals.XTEND_FIELD__NAME, FIELD);
if (field.isStatic()) {
highlightFeature(acceptor, field, XtendPackage.Literals.XTEND_FIELD__NAME, STATIC_FIELD);
if (field.isFinal()) {
highlightFeature(acceptor, field, XtendPackage.Literals.XTEND_FIELD__NAME, STATIC_FINAL_FIELD);
}
}
XExpression initializer = field.getInitialValue();
highlightRichStrings(initializer, acceptor);
}
use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.
the class XtendFormatter method _format.
protected void _format(final XtendField field, @Extension final IFormattableDocument document) {
final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
it.oneSpace();
};
document.append(this.textRegionExtensions.regionFor(field).keyword("extension"), _function);
this.formatAnnotations(field, document, XbaseFormatterPreferenceKeys.newLineAfterFieldAnnotations);
this.formatModifiers(field, document);
String _name = field.getName();
boolean _tripleNotEquals = (_name != null);
if (_tripleNotEquals) {
final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
it.oneSpace();
};
document.<JvmTypeReference>append(field.getType(), _function_1);
}
final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
it.oneSpace();
};
final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
it.oneSpace();
};
document.append(document.prepend(this.textRegionExtensions.regionFor(field).keyword("="), _function_2), _function_3);
document.<JvmTypeReference>format(field.getType());
document.<XExpression>format(field.getInitialValue());
}
use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.
the class XtendFormatter method _format.
protected void _format(final XtendFunction func, @Extension final IFormattableDocument format) {
this.formatAnnotations(func, format, XbaseFormatterPreferenceKeys.newLineAfterMethodAnnotations);
this.formatModifiers(func, format);
boolean _isEmpty = func.getTypeParameters().isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
it.noSpace();
};
format.append(this.textRegionExtensions.regionFor(func).keyword("<"), _function);
EList<JvmTypeParameter> _typeParameters = func.getTypeParameters();
for (final JvmTypeParameter arg : _typeParameters) {
{
format.<JvmTypeParameter>format(arg);
final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
it.noSpace();
};
final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
it.oneSpace();
};
format.append(format.prepend(this.textRegionExtensions.immediatelyFollowing(arg).keyword(","), _function_1), _function_2);
}
}
final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
it.noSpace();
};
final Procedure1<IHiddenRegionFormatter> _function_2 = (IHiddenRegionFormatter it) -> {
it.oneSpace();
};
format.append(format.prepend(this.textRegionExtensions.regionFor(func).keyword(">"), _function_1), _function_2);
}
final ISemanticRegion nameNode = this.textRegionExtensions.regionFor(func).feature(XtendPackage.Literals.XTEND_FUNCTION__NAME);
ISemanticRegionFinder _immediatelyFollowing = null;
if (nameNode != null) {
_immediatelyFollowing = nameNode.immediatelyFollowing();
}
ISemanticRegion _keyword = null;
if (_immediatelyFollowing != null) {
_keyword = _immediatelyFollowing.keyword("(");
}
final ISemanticRegion open = _keyword;
final ISemanticRegion close = this.textRegionExtensions.regionFor(func).keyword(")");
final Procedure1<IHiddenRegionFormatter> _function_3 = (IHiddenRegionFormatter it) -> {
it.oneSpace();
};
format.<JvmTypeReference>append(func.getReturnType(), _function_3);
final Procedure1<IHiddenRegionFormatter> _function_4 = (IHiddenRegionFormatter it) -> {
it.noSpace();
};
format.prepend(open, _function_4);
XExpression _expression = func.getExpression();
boolean _tripleNotEquals = (_expression != null);
if (_tripleNotEquals) {
format.append(close, XbaseFormatterPreferenceKeys.bracesInNewLine);
}
this.formatCommaSeparatedList(func.getParameters(), open, close, format);
format.<JvmTypeReference>format(func.getReturnType());
format.<XExpression>format(func.getExpression());
}
Aggregations