use of org.eclipse.xtend.core.xtend.XtendField in project xtext-xtend by eclipse.
the class XtendFormatter method formatBody.
protected ISemanticRegion formatBody(final XtendTypeDeclaration type, @Extension final IFormattableDocument format) {
ISemanticRegion _xblockexpression = null;
{
final ISemanticRegion open = this.textRegionExtensions.regionFor(type).keyword("{");
final ISemanticRegion close = this.textRegionExtensions.regionFor(type).keyword("}");
final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
it.indent();
};
format.<ISemanticRegion, ISemanticRegion>interior(open, close, _function);
format.prepend(open, XbaseFormatterPreferenceKeys.bracesInNewLine);
ISemanticRegion _xifexpression = null;
boolean _isEmpty = type.getMembers().isEmpty();
boolean _not = (!_isEmpty);
if (_not) {
format.append(open, XtendFormatterPreferenceKeys.blankLinesBeforeFirstMember);
int _size = type.getMembers().size();
int _minus = (_size - 1);
IntegerRange _upTo = new IntegerRange(0, _minus);
for (final Integer i : _upTo) {
{
final XtendMember current = type.getMembers().get((i).intValue());
format.<XtendMember>format(current);
int _size_1 = type.getMembers().size();
int _minus_1 = (_size_1 - 1);
boolean _lessThan = ((i).intValue() < _minus_1);
if (_lessThan) {
final XtendMember next = type.getMembers().get(((i).intValue() + 1));
if (((current instanceof XtendField) && (next instanceof XtendField))) {
format.<XtendMember>append(current, XtendFormatterPreferenceKeys.blankLinesBetweenFields);
} else {
if (((current instanceof XtendFunction) && (next instanceof XtendFunction))) {
format.<XtendMember>append(current, XtendFormatterPreferenceKeys.blankLinesBetweenMethods);
} else {
format.<XtendMember>append(current, XtendFormatterPreferenceKeys.blankLinesBetweenFieldsAndMethods);
}
}
} else {
final XtendMember member = type.getMembers().get((i).intValue());
format.<XtendMember>append(member, XtendFormatterPreferenceKeys.blankLinesAfterLastMember);
}
}
}
} else {
final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it) -> {
it.newLine();
};
_xifexpression = format.append(open, _function_1);
}
_xblockexpression = _xifexpression;
}
return _xblockexpression;
}
use of org.eclipse.xtend.core.xtend.XtendField in project xtext-xtend by eclipse.
the class XAnnotationExtensions method getAnnotatedTarget.
public XtendAnnotationTarget getAnnotatedTarget(final XAnnotation annotation) {
XtendAnnotationTarget _switchResult = null;
EObject _eContainer = annotation.eContainer();
final EObject container = _eContainer;
boolean _matched = false;
if (container instanceof XtendAnnotationType) {
_matched = true;
}
if (!_matched) {
if (container instanceof XtendClass) {
_matched = true;
}
}
if (!_matched) {
if (container instanceof XtendInterface) {
_matched = true;
}
}
if (!_matched) {
if (container instanceof XtendEnum) {
_matched = true;
}
}
if (!_matched) {
if (container instanceof XtendField) {
_matched = true;
}
}
if (!_matched) {
if (container instanceof XtendFunction) {
_matched = true;
}
}
if (!_matched) {
if (container instanceof XtendConstructor) {
_matched = true;
}
}
if (!_matched) {
if (container instanceof XtendEnumLiteral) {
_matched = true;
}
}
if (!_matched) {
if (container instanceof XtendParameter) {
_matched = true;
}
}
if (_matched) {
_switchResult = ((XtendAnnotationTarget) container);
}
if (!_matched) {
if (container instanceof XtendAnnotationTarget) {
_matched = true;
XtendAnnotationTarget _xblockexpression = null;
{
final EObject containerContainer = ((XtendAnnotationTarget) container).eContainer();
XtendAnnotationTarget _xifexpression = null;
if ((containerContainer instanceof XtendAnnotationTarget)) {
_xifexpression = ((XtendAnnotationTarget) containerContainer);
} else {
_xifexpression = ((XtendAnnotationTarget) container);
}
_xblockexpression = _xifexpression;
}
_switchResult = _xblockexpression;
}
}
if (!_matched) {
if (container instanceof XAnnotation) {
_matched = true;
_switchResult = this.getAnnotatedTarget(((XAnnotation) container));
}
}
if (!_matched) {
_switchResult = null;
}
return _switchResult;
}
use of org.eclipse.xtend.core.xtend.XtendField in project xtext-xtend by eclipse.
the class CompilationUnitImpl method toXtendMemberDeclaration.
public MemberDeclaration toXtendMemberDeclaration(final XtendMember delegate) {
final Function1<XtendMember, XtendMemberDeclarationImpl<? extends XtendMember>> _function = (XtendMember it) -> {
XtendMemberDeclarationImpl<? extends XtendMember> _switchResult = null;
boolean _matched = false;
if (delegate instanceof XtendTypeDeclaration) {
_matched = true;
_switchResult = this.toXtendTypeDeclaration(((XtendTypeDeclaration) delegate));
}
if (!_matched) {
if (delegate instanceof XtendFunction) {
_matched = true;
XtendMethodDeclarationImpl _xtendMethodDeclarationImpl = new XtendMethodDeclarationImpl();
final Procedure1<XtendMethodDeclarationImpl> _function_1 = (XtendMethodDeclarationImpl it_1) -> {
it_1.setDelegate(((XtendFunction) delegate));
it_1.setCompilationUnit(this);
};
_switchResult = ObjectExtensions.<XtendMethodDeclarationImpl>operator_doubleArrow(_xtendMethodDeclarationImpl, _function_1);
}
}
if (!_matched) {
if (delegate instanceof XtendConstructor) {
_matched = true;
XtendConstructorDeclarationImpl _xtendConstructorDeclarationImpl = new XtendConstructorDeclarationImpl();
final Procedure1<XtendConstructorDeclarationImpl> _function_1 = (XtendConstructorDeclarationImpl it_1) -> {
it_1.setDelegate(((XtendConstructor) delegate));
it_1.setCompilationUnit(this);
};
_switchResult = ObjectExtensions.<XtendConstructorDeclarationImpl>operator_doubleArrow(_xtendConstructorDeclarationImpl, _function_1);
}
}
if (!_matched) {
if (delegate instanceof XtendField) {
_matched = true;
XtendMemberDeclarationImpl<XtendField> _xifexpression = null;
EObject _eContainer = ((XtendField) delegate).eContainer();
if ((_eContainer instanceof XtendAnnotationType)) {
XtendAnnotationTypeElementDeclarationImpl _xtendAnnotationTypeElementDeclarationImpl = new XtendAnnotationTypeElementDeclarationImpl();
final Procedure1<XtendAnnotationTypeElementDeclarationImpl> _function_1 = (XtendAnnotationTypeElementDeclarationImpl it_1) -> {
it_1.setDelegate(((XtendField) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<XtendAnnotationTypeElementDeclarationImpl>operator_doubleArrow(_xtendAnnotationTypeElementDeclarationImpl, _function_1);
} else {
XtendFieldDeclarationImpl _xtendFieldDeclarationImpl = new XtendFieldDeclarationImpl();
final Procedure1<XtendFieldDeclarationImpl> _function_2 = (XtendFieldDeclarationImpl it_1) -> {
it_1.setDelegate(((XtendField) delegate));
it_1.setCompilationUnit(this);
};
_xifexpression = ObjectExtensions.<XtendFieldDeclarationImpl>operator_doubleArrow(_xtendFieldDeclarationImpl, _function_2);
}
_switchResult = _xifexpression;
}
}
if (!_matched) {
if (delegate instanceof XtendEnumLiteral) {
_matched = true;
XtendEnumerationValueDeclarationImpl _xtendEnumerationValueDeclarationImpl = new XtendEnumerationValueDeclarationImpl();
final Procedure1<XtendEnumerationValueDeclarationImpl> _function_1 = (XtendEnumerationValueDeclarationImpl it_1) -> {
it_1.setDelegate(((XtendEnumLiteral) delegate));
it_1.setCompilationUnit(this);
};
_switchResult = ObjectExtensions.<XtendEnumerationValueDeclarationImpl>operator_doubleArrow(_xtendEnumerationValueDeclarationImpl, _function_1);
}
}
return _switchResult;
};
return this.<XtendMember, XtendMemberDeclarationImpl<? extends XtendMember>>getOrCreate(delegate, _function);
}
use of org.eclipse.xtend.core.xtend.XtendField 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.xtend.core.xtend.XtendField in project xtext-xtend by eclipse.
the class XtendQualifiedNameProvider method getFullyQualifiedName.
@Override
public QualifiedName getFullyQualifiedName(EObject obj) {
if (obj instanceof XtendTypeDeclaration) {
XtendTypeDeclaration typeDecl = (XtendTypeDeclaration) obj;
String typeName = typeDecl.getName();
if (typeDecl.eContainer() instanceof XtendFile) {
if (typeName == null)
return null;
XtendFile file = (XtendFile) typeDecl.eContainer();
String packageName = file.getPackage();
if (packageName != null) {
return qualifiedNameConverter.toQualifiedName(packageName).append(typeName);
}
return QualifiedName.create(typeName);
} else {
return concatNames(obj, typeName);
}
}
if (obj instanceof XtendConstructor) {
return getFullyQualifiedName(obj.eContainer());
}
if (obj instanceof JvmIdentifiableElement && !(obj instanceof JvmTypeParameter)) {
return getFullyQualifiedName((JvmIdentifiableElement) obj);
}
if (obj instanceof XtendField) {
return concatNames(obj, ((XtendField) obj).getName());
}
if (obj instanceof XtendFunction) {
return concatNames(obj, ((XtendFunction) obj).getName());
}
if (obj instanceof XtendEnumLiteral) {
return concatNames(obj, ((XtendEnumLiteral) obj).getName());
}
return null;
}
Aggregations