Skip to content

Commit

Permalink
allow for the custom Xbase converter to be further customized,e.g.,Xtend
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoBettini committed Apr 27, 2024
1 parent 38adf67 commit 9f1f33f
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ public Class<? extends XbaseValueConverterService.IntUnderscoreValueConverter> b
return IntUnderscoreValueConverter.class;
}

@Override
public Class<? extends STRINGValueConverter> bindSTRINGValueConverter() {
return StringValueConverter.class;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@

import org.antlr.runtime.TokenSource;
import org.eclipse.xtend.core.parser.antlr.internal.FlexerFactory;
import org.eclipse.xtext.conversion.impl.STRINGValueConverter;
import org.eclipse.xtext.xbase.conversion.XbaseStringValueConverter;

import com.google.inject.Inject;

/**
* @author Sebastian Zarnekow - Initial contribution and API
*/
public class StringValueConverter extends STRINGValueConverter {
public class StringValueConverter extends XbaseStringValueConverter {

@Inject
private FlexerFactory flexerFactory;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

import org.eclipse.xtext.common.types.DefaultCommonTypesRuntimeModule;
import org.eclipse.xtext.conversion.IValueConverterService;
import org.eclipse.xtext.conversion.impl.STRINGValueConverter;
import org.eclipse.xtext.debug.IStratumBreakpointSupport;
import org.eclipse.xtext.documentation.IJavaDocTypeReferenceProvider;
import org.eclipse.xtext.findReferences.TargetURICollector;
Expand Down Expand Up @@ -39,6 +40,7 @@
import org.eclipse.xtext.xbase.annotations.validation.UnresolvedFeatureCallTypeAwareMessageProvider;
import org.eclipse.xtext.xbase.compiler.JvmModelGenerator;
import org.eclipse.xtext.xbase.compiler.output.TraceAwarePostProcessor;
import org.eclipse.xtext.xbase.conversion.XbaseStringValueConverter;
import org.eclipse.xtext.xbase.conversion.XbaseValueConverterService;
import org.eclipse.xtext.xbase.debug.XbaseStratumBreakpointSupport;
import org.eclipse.xtext.xbase.featurecalls.IdentifiableSimpleNameProvider;
Expand Down Expand Up @@ -242,5 +244,11 @@ public Class<? extends TargetURICollector> bindTargetURICollector() {
public Class<? extends IJavaDocTypeReferenceProvider> bindIJavaDocReferenceProvider() {
return XbaseJavaDocTypeReferenceProvider.class;
}


/**
* @since 2.35
*/
public Class<? extends STRINGValueConverter> bindSTRINGValueConverter() {
return XbaseStringValueConverter.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*******************************************************************************
* Copyright (c) 2024 Lorenzo Bettini and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package org.eclipse.xtext.xbase.conversion;

import org.eclipse.xtext.conversion.impl.STRINGValueConverter;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.util.Strings;

/**
* Avoid Windows EOL characters from the original parsed text: this would result
* in different generated Java files in Windows see
* https://github.com/eclipse/xtext/issues/2293 This is aligned with Java text
* blocks' "Normalization of Line Terminators"
*
* @author Lorenzo Bettini - Initial contribution and API
* @since 2.35
*/
public class XbaseStringValueConverter extends STRINGValueConverter {
@Override
public String toValue(String string, INode node) {
return super.toValue(Strings.toUnixLineSeparator(string), node);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.eclipse.xtext.conversion.impl.KeywordAlternativeConverter;
import org.eclipse.xtext.conversion.impl.KeywordBasedValueConverter;
import org.eclipse.xtext.conversion.impl.QualifiedNameValueConverter;
import org.eclipse.xtext.conversion.impl.STRINGValueConverter;
import org.eclipse.xtext.nodemodel.INode;
import org.eclipse.xtext.util.Strings;

Expand Down Expand Up @@ -255,28 +254,4 @@ public Integer toValue(String string, INode node) {
}
}

@Inject
private WindowsEOLsAwareSTRINGValueConverter windowsEOLsAwareSTRINGValueConverter;

@Override
@ValueConverter(rule = "STRING")
public IValueConverter<String> STRING() {
return windowsEOLsAwareSTRINGValueConverter;
}

/**
* Avoid Windows EOL characters from the original parsed text: this would
* result in different generated Java files in Windows see
* https://github.com/eclipse/xtext/issues/2293 This is aligned with Java
* text blocks' "Normalization of Line Terminators"
*
* @author Lorenzo Bettini - Initial contribution and API
* @since 2.35
*/
public static class WindowsEOLsAwareSTRINGValueConverter extends STRINGValueConverter {
@Override
public String toValue(String string, INode node) {
return super.toValue(Strings.toUnixLineSeparator(string), node);
}
}
}

0 comments on commit 9f1f33f

Please sign in to comment.