use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.
the class XtendGenerator method generateMembersInBody.
@Override
public ITreeAppendable generateMembersInBody(final JvmDeclaredType it, final ITreeAppendable appendable, final GeneratorConfig config) {
ITreeAppendable _xifexpression = null;
boolean _isLocal = it.isLocal();
if (_isLocal) {
ITreeAppendable _xblockexpression = null;
{
appendable.append("{").increaseIndentation();
EObject _head = IterableExtensions.<EObject>head(this.getSourceElements(it));
final AnonymousClass anonymousClass = ((AnonymousClass) _head);
if (((!appendable.hasName(Pair.<String, JvmDeclaredType>of("this", it))) && this.needSyntheticThisVariable(anonymousClass, it))) {
final IResolvedTypes resolvedTypes = this.typeResolver.resolveTypes(anonymousClass);
final LightweightTypeReference actualType = resolvedTypes.getActualType(anonymousClass);
Pair<String, JvmDeclaredType> _mappedTo = Pair.<String, JvmDeclaredType>of("this", it);
final String thisName = appendable.declareSyntheticVariable(_mappedTo, "_this");
appendable.newLine().append("final ").append(actualType).append(" ").append(thisName).append(" = this;");
}
final Function1<JvmField, Boolean> _function = (JvmField it_1) -> {
boolean _xblockexpression_1 = false;
{
Procedure1<? super ITreeAppendable> _compilationStrategy = this._jvmTypeExtensions.getCompilationStrategy(it_1);
boolean _tripleNotEquals = (_compilationStrategy != null);
if (_tripleNotEquals) {
return Boolean.valueOf(true);
} else {
StringConcatenationClient _compilationTemplate = this._jvmTypeExtensions.getCompilationTemplate(it_1);
boolean _tripleNotEquals_1 = (_compilationTemplate != null);
if (_tripleNotEquals_1) {
return Boolean.valueOf(true);
} else {
boolean _not = (!(it_1.isFinal() && it_1.isStatic()));
if (_not) {
final XExpression expression = this._iLogicalContainerProvider.getAssociatedExpression(it_1);
if (((expression != null) && config.isGenerateExpressions())) {
return Boolean.valueOf(true);
}
}
}
}
_xblockexpression_1 = false;
}
return Boolean.valueOf(_xblockexpression_1);
};
final Iterable<JvmField> fieldsWithInitializer = IterableExtensions.<JvmField>filter(it.getDeclaredFields(), _function);
boolean _isEmpty = IterableExtensions.isEmpty(fieldsWithInitializer);
boolean _not = (!_isEmpty);
if (_not) {
appendable.newLine().append("{").increaseIndentation();
final Procedure1<LoopParams> _function_1 = (LoopParams it_1) -> {
final Function1<ITreeAppendable, ITreeAppendable> _function_2 = (ITreeAppendable it_2) -> {
return it_2.newLine();
};
it_1.setSeparator(_function_2);
};
final Procedure1<JvmField> _function_2 = (JvmField it_1) -> {
final ITreeAppendable memberAppendable = this._treeAppendableUtil.traceWithComments(appendable, it_1);
memberAppendable.openScope();
appendable.newLine();
final ITreeAppendable tracedAppendable = appendable.trace(it_1);
this._treeAppendableUtil.traceSignificant(tracedAppendable, it_1).append(it_1.getSimpleName());
this.generateInitialization(it_1, tracedAppendable, config);
tracedAppendable.append(";");
memberAppendable.closeScope();
};
this._loopExtensions.<JvmField>forEach(appendable, fieldsWithInitializer, _function_1, _function_2);
appendable.decreaseIndentation().newLine().append("}");
}
final Procedure1<LoopParams> _function_3 = (LoopParams it_1) -> {
final Function1<ITreeAppendable, ITreeAppendable> _function_4 = (ITreeAppendable it_2) -> {
return it_2.newLine();
};
it_1.setSeparator(_function_4);
};
final Procedure1<JvmMember> _function_4 = (JvmMember it_1) -> {
final ITreeAppendable memberAppendable = this._treeAppendableUtil.traceWithComments(appendable, it_1);
memberAppendable.openScope();
this.generateMember(it_1, memberAppendable, config);
memberAppendable.closeScope();
};
this._loopExtensions.<JvmMember>forEach(appendable, this.getMembersToBeCompiled(it), _function_3, _function_4);
_xblockexpression = appendable.decreaseIndentation().newLine().append("}");
}
_xifexpression = _xblockexpression;
} else {
_xifexpression = super.generateMembersInBody(it, appendable, config);
}
return _xifexpression;
}
use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.
the class ExtractVariableIntegrationTest method assertAfterExtract.
protected void assertAfterExtract(final CharSequence input, final CharSequence expected, final boolean isFinal) {
try {
final String inputString = input.toString();
final String model = inputString.replace("$", "");
final IFile file = this.workbenchTestHelper.createFile("Foo", model);
final XtextEditor editor = this.workbenchTestHelper.openEditor(file);
try {
final IUnitOfWork<Change, XtextResource> _function = (XtextResource it) -> {
Change _xblockexpression = null;
{
final int offset = inputString.indexOf("$");
int _lastIndexOf = inputString.lastIndexOf("$");
int _minus = (_lastIndexOf - 1);
final int length = (_minus - offset);
final TextSelection textSelection = new TextSelection(offset, length);
final XExpression selection = this.util.findSelectedExpression(it, textSelection);
final ExtractVariableRefactoring refactoring = this.refactoringProvider.get();
refactoring.setFinal(isFinal);
refactoring.initialize(editor, selection);
NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
final RefactoringStatus status = refactoring.checkAllConditions(_nullProgressMonitor);
Assert.assertTrue(status.toString(), status.isOK());
NullProgressMonitor _nullProgressMonitor_1 = new NullProgressMonitor();
Change _createChange = refactoring.createChange(_nullProgressMonitor_1);
NullProgressMonitor _nullProgressMonitor_2 = new NullProgressMonitor();
_xblockexpression = _createChange.perform(_nullProgressMonitor_2);
}
return _xblockexpression;
};
editor.getDocument().<Change>readOnly(_function);
Assert.assertEquals(expected.toString(), editor.getDocument().get());
} finally {
editor.close(false);
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.
the class ExtractMethodIntegrationTest method assertExtractForbidden.
protected void assertExtractForbidden(final CharSequence input, final Procedure1<? super ExtractMethodRefactoring> initializer, final String messageFragment) {
try {
final String inputString = input.toString();
final IFile file = this.workbenchTestHelper.createFile("Foo", inputString.replace("$", ""));
final XtextEditor editor = this.workbenchTestHelper.openEditor(file);
try {
final IUnitOfWork<String, XtextResource> _function = (XtextResource it) -> {
String _xblockexpression = null;
{
int _indexOf = inputString.indexOf("$");
int _lastIndexOf = inputString.lastIndexOf("$");
int _indexOf_1 = inputString.indexOf("$");
int _minus = (_lastIndexOf - _indexOf_1);
int _minus_1 = (_minus - 1);
TextSelection _textSelection = new TextSelection(_indexOf, _minus_1);
final List<XExpression> selection = this.util.findSelectedSiblingExpressions(it, _textSelection);
final ExtractMethodRefactoring refactoring = this.refactoringProvider.get();
refactoring.initialize(editor, selection, true);
refactoring.setMethodName("bar");
NullProgressMonitor _nullProgressMonitor = new NullProgressMonitor();
final RefactoringStatus status = refactoring.checkInitialConditions(_nullProgressMonitor);
initializer.apply(refactoring);
NullProgressMonitor _nullProgressMonitor_1 = new NullProgressMonitor();
status.merge(refactoring.checkFinalConditions(_nullProgressMonitor_1));
Assert.assertTrue(status.toString(), status.hasError());
final String message = status.getMessageMatchingSeverity(RefactoringStatus.ERROR);
Assert.assertTrue(message, message.toLowerCase().contains(messageFragment.toLowerCase()));
_xblockexpression = "";
}
return _xblockexpression;
};
editor.getDocument().<String>readOnly(_function);
} finally {
editor.close(false);
}
} catch (Throwable _e) {
throw Exceptions.sneakyThrow(_e);
}
}
use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.
the class XtendJvmModelInferrer method initialize.
protected void initialize(XtendAnnotationType source, JvmAnnotationType inferredJvmType) {
inferredJvmType.setVisibility(source.getVisibility());
inferredJvmType.setStatic(source.isStatic() && !isTopLevel(source));
inferredJvmType.setAbstract(true);
translateAnnotationsTo(source.getAnnotations(), inferredJvmType);
jvmTypesBuilder.copyDocumentationTo(source, inferredJvmType);
for (XtendMember member : source.getMembers()) {
if (member instanceof XtendField) {
XtendField field = (XtendField) member;
if (!Strings.isEmpty(field.getName())) {
JvmOperation operation = typesFactory.createJvmOperation();
associator.associatePrimary(member, operation);
operation.setSimpleName(field.getName());
JvmTypeReference returnType = null;
XExpression initialValue = field.getInitialValue();
if (field.getType() != null) {
returnType = jvmTypesBuilder.cloneWithProxies(field.getType());
} else if (initialValue != null) {
returnType = jvmTypesBuilder.inferredType(initialValue);
}
operation.setReturnType(returnType);
if (initialValue != null) {
JvmAnnotationValue jvmAnnotationValue = jvmTypesBuilder.toJvmAnnotationValue(initialValue);
if (jvmAnnotationValue != null) {
operation.setDefaultValue(jvmAnnotationValue);
jvmAnnotationValue.setOperation(operation);
}
jvmTypesBuilder.setBody(operation, initialValue);
}
operation.setVisibility(JvmVisibility.PUBLIC);
translateAnnotationsTo(member.getAnnotations(), operation);
jvmTypesBuilder.copyDocumentationTo(member, operation);
inferredJvmType.getMembers().add(operation);
}
}
}
}
use of org.eclipse.xtext.xbase.XExpression in project xtext-xtend by eclipse.
the class XtendValidator method checkDefaultSuperConstructor.
@Check
public void checkDefaultSuperConstructor(XtendClass xtendClass) {
JvmGenericType inferredType = associations.getInferredType(xtendClass);
if (inferredType == null)
return;
Iterable<JvmConstructor> constructors = filter(inferredType.getMembers(), JvmConstructor.class);
if (inferredType.getExtendedClass() != null) {
JvmType superType = inferredType.getExtendedClass().getType();
if (superType instanceof JvmGenericType) {
Iterable<JvmConstructor> superConstructors = ((JvmGenericType) superType).getDeclaredConstructors();
for (JvmConstructor superConstructor : superConstructors) {
if (superConstructor.getParameters().isEmpty())
// there is a default super constructor. nothing more to check
return;
}
if (size(constructors) == 1 && typeExtensions.isSingleSyntheticDefaultConstructor(constructors.iterator().next())) {
List<String> issueData = newArrayList();
for (JvmConstructor superConstructor : superConstructors) {
issueData.add(EcoreUtil.getURI(superConstructor).toString());
issueData.add(doGetReadableSignature(xtendClass.getName(), superConstructor.getParameters()));
}
error("No default constructor in super type " + superType.getSimpleName() + "." + xtendClass.getName() + " must define an explicit constructor.", xtendClass, XTEND_TYPE_DECLARATION__NAME, MISSING_CONSTRUCTOR, toArray(issueData, String.class));
} else {
for (JvmConstructor constructor : constructors) {
XExpression expression = containerProvider.getAssociatedExpression(constructor);
if (expression instanceof XBlockExpression) {
List<XExpression> expressions = ((XBlockExpression) expression).getExpressions();
if (expressions.isEmpty() || !isDelegateConstructorCall(expressions.get(0))) {
EObject source = associations.getPrimarySourceElement(constructor);
error("No default constructor in super type " + superType.getSimpleName() + ". Another constructor must be invoked explicitly.", source, null, MUST_INVOKE_SUPER_CONSTRUCTOR);
}
}
}
}
}
}
}
Aggregations