mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 08:48:55 +00:00
commit
cb97d73dae
9 changed files with 52 additions and 30 deletions
|
@ -56,6 +56,10 @@ class XtextVersion {
|
|||
xtextGradlePluginVersion
|
||||
}
|
||||
|
||||
def getXtendAndroidGradlePluginVersion() {
|
||||
'0.4.14'
|
||||
}
|
||||
|
||||
def getXtextGradlePluginVersion() {
|
||||
'1.0.1'
|
||||
}
|
||||
|
|
|
@ -85,7 +85,7 @@ class GenModelUtil2 {
|
|||
def static Resource getGenModelResource(String locationInfo, String nsURI, ResourceSet resourceSet) {
|
||||
val genModelURI = EcorePlugin.getEPackageNsURIToGenModelLocationMap(false).get(nsURI)
|
||||
if (genModelURI === null) {
|
||||
if (EcorePackage.eNS_URI.equals(nsURI)) // If we really want to use the registered ecore ...
|
||||
if (EcorePackage.eNS_URI == nsURI) // If we really want to use the registered ecore ...
|
||||
return null // look into the resource set to find a genpackage for the given URI
|
||||
for (res : resourceSet.resources) {
|
||||
// We only look into the first level, as genmodels are usually among the top level elements.
|
||||
|
@ -93,7 +93,7 @@ class GenModelUtil2 {
|
|||
for (obj : res.contents) {
|
||||
if (obj instanceof GenModel) {
|
||||
for (genPackage : obj.genPackages) {
|
||||
if (genPackage.NSURI.equals(nsURI)) {
|
||||
if (genPackage.NSURI == nsURI) {
|
||||
return genPackage.eResource
|
||||
}
|
||||
}
|
||||
|
|
|
@ -254,6 +254,11 @@ class RuntimeProjectDescriptor extends TestedProjectDescriptor {
|
|||
dependencies {
|
||||
mwe2 "org.eclipse.emf:org.eclipse.emf.mwe2.launch:«config.xtextVersion.mweVersion»"
|
||||
mwe2 "org.eclipse.xtext:org.eclipse.xtext.xtext.generator:${xtextVersion}"
|
||||
«IF fromExistingEcoreModels»
|
||||
mwe2 "org.eclipse.xtext:org.eclipse.xtext.generator:${xtextVersion}"
|
||||
mwe2 "org.eclipse.xpand:org.eclipse.xpand:2.0.0"
|
||||
mwe2 "org.eclipse.xpand:org.eclipse.xtend:2.0.0"
|
||||
«ENDIF»
|
||||
}
|
||||
|
||||
task generateXtextLanguage(type: JavaExec) {
|
||||
|
|
|
@ -30,6 +30,7 @@ import org.eclipse.xtext.nodemodel.INode;
|
|||
import org.eclipse.xtext.nodemodel.SyntaxErrorMessage;
|
||||
import org.eclipse.xtext.nodemodel.impl.AbstractNode;
|
||||
import org.eclipse.xtext.nodemodel.impl.InternalNodeModelUtils;
|
||||
import org.eclipse.xtext.nodemodel.impl.RootNode;
|
||||
import org.eclipse.xtext.resource.EObjectAtOffsetHelper;
|
||||
import org.eclipse.xtext.resource.ILocationInFileProvider;
|
||||
import org.eclipse.xtext.util.LineAndColumn;
|
||||
|
@ -123,7 +124,7 @@ public class NodeModelUtils extends InternalNodeModelUtils {
|
|||
*/
|
||||
public static LineAndColumn getLineAndColumn(INode anyNode, int documentOffset) {
|
||||
// special treatment for inconsistent nodes such as SyntheticLinkingLeafNode
|
||||
if (anyNode.getParent() == null) {
|
||||
if (anyNode.getParent() == null && !(anyNode instanceof RootNode)) {
|
||||
return LineAndColumn.from(1,1);
|
||||
}
|
||||
return InternalNodeModelUtils.getLineAndColumn(anyNode, documentOffset);
|
||||
|
|
|
@ -37,29 +37,20 @@ public class TokenRegionProvider {
|
|||
lexer.setCharStream(new ANTLRStringStream(text));
|
||||
int currentStart = 0;
|
||||
int currentEnd = 0;
|
||||
CommonToken currentToken = (CommonToken) lexer.nextToken();
|
||||
int regionStartOffset = region.getOffset();
|
||||
int regionEnd = regionStartOffset + region.getLength();
|
||||
while (currentToken != Token.EOF_TOKEN) {
|
||||
currentStart = currentToken.getStartIndex();
|
||||
currentEnd = currentToken.getStopIndex() + 1;
|
||||
if (currentToken.getStopIndex() >= regionStartOffset)
|
||||
break;
|
||||
currentToken = (CommonToken) lexer.nextToken();
|
||||
CommonToken nextToken = (CommonToken) lexer.nextToken();
|
||||
int regionStart = region.getOffset();
|
||||
int regionEnd = regionStart + region.getLength();
|
||||
while (nextToken != Token.EOF_TOKEN && currentEnd <= regionStart) {
|
||||
currentStart = nextToken.getStartIndex();
|
||||
currentEnd = nextToken.getStopIndex() + 1;
|
||||
nextToken = (CommonToken) lexer.nextToken();
|
||||
}
|
||||
if (region.getLength() == 0 && regionStartOffset == currentToken.getStopIndex() + 1) {
|
||||
currentEnd = currentStart;
|
||||
} else {
|
||||
// currentToken is first token overlapping with the region or EOF
|
||||
while (currentToken != Token.EOF_TOKEN) {
|
||||
currentEnd = currentToken.getStopIndex() + 1;
|
||||
if (currentEnd >= regionEnd) {
|
||||
break;
|
||||
}
|
||||
currentToken = (CommonToken) lexer.nextToken();
|
||||
}
|
||||
// nextToken is either EOF or the first token that follows the start of the given region
|
||||
while (nextToken != Token.EOF_TOKEN && currentEnd < regionEnd) {
|
||||
currentEnd = nextToken.getStopIndex() + 1;
|
||||
nextToken = (CommonToken) lexer.nextToken();
|
||||
}
|
||||
if (currentStart != regionStartOffset || currentEnd != regionEnd)
|
||||
if (currentStart != regionStart || currentEnd != regionEnd)
|
||||
return new TextRegion(currentStart, currentEnd - currentStart);
|
||||
else
|
||||
return region;
|
||||
|
|
|
@ -37,7 +37,7 @@ public class XtextPlatformResourceURIHandler extends URIHandlerImpl {
|
|||
|
||||
@Override
|
||||
public URI resolve(URI uri) {
|
||||
if (resolve && uri.isRelative() && uri.hasRelativePath() && !resourceSet.getPackageRegistry().containsKey(uri.trimFragment().toString())) {
|
||||
if (resolve && baseURI != null && uri.isRelative() && uri.hasRelativePath() && !resourceSet.getPackageRegistry().containsKey(uri.trimFragment().toString())) {
|
||||
URI result = uri.resolve(baseURI);
|
||||
if (baseURI.isPlatform()) {
|
||||
if (result.isPlatform() && !(result.isPlatformPlugin() || result.isPlatformResource())) {
|
||||
|
|
|
@ -13,7 +13,6 @@ import java.lang.reflect.Type;
|
|||
|
||||
import org.eclipse.xtext.util.ReflectionUtil;
|
||||
|
||||
import com.google.inject.Provider;
|
||||
import com.google.inject.binder.LinkedBindingBuilder;
|
||||
|
||||
public class ProviderModule extends MethodBasedModule {
|
||||
|
@ -26,20 +25,26 @@ public class ProviderModule extends MethodBasedModule {
|
|||
@Override
|
||||
protected void bindToInstance(LinkedBindingBuilder<Object> bind, Object instance) {
|
||||
if (instance != null) // provider may not be null
|
||||
bind.toProvider((Provider<? extends Object>) instance);
|
||||
bind.toProvider((com.google.inject.Provider<? extends Object>) instance);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
protected void bindToClass(LinkedBindingBuilder<Object> bind, Class<?> value) {
|
||||
bind.toProvider((Class<? extends Provider<?>>)value);
|
||||
bind.toProvider((Class<? extends javax.inject.Provider<?>>) value);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Type getKeyType() {
|
||||
Type keyType = super.getKeyType();
|
||||
if (!(isInstanceOf(keyType, Provider.class)))
|
||||
throw new IllegalStateException("The method "+getMethod().getName()+" is expected to return a Class<? extends Provider<Something>> or directly Provider<Something>.");
|
||||
if (!isInstanceOf(keyType, com.google.inject.Provider.class)) {
|
||||
if (isInstanceOf(keyType, javax.inject.Provider.class)) {
|
||||
if (!isClassBinding())
|
||||
throw new IllegalStateException("The method "+getMethod().getName()+" returns javax.inject.Provider, but this kind of binding is allowed only for com.google.inject.Provider.");
|
||||
} else {
|
||||
throw new IllegalStateException("The method "+getMethod().getName()+" is expected to return a Class<? extends Provider<Something>> or directly Provider<Something>.");
|
||||
}
|
||||
}
|
||||
return getFirstTypeParameter((ParameterizedType) keyType);
|
||||
}
|
||||
|
||||
|
|
|
@ -401,5 +401,13 @@ public class PartialParserTest extends AbstractPartialParserTest {
|
|||
assertTrue(resource.getErrors().toString(), resource.getErrors().isEmpty());
|
||||
assertEquals(model, serialize(resource.getContents().get(0)));
|
||||
}
|
||||
|
||||
@Test public void testBug486454() throws Exception {
|
||||
with(SimpleExpressionsTestLanguageStandaloneSetup.class);
|
||||
String model = "tim";
|
||||
XtextResource resource = getResourceFromString(model);
|
||||
resource.update(1, 2, "");
|
||||
assertEquals("t", resource.getParseResult().getRootNode().getText());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -91,6 +91,14 @@ public class TokenRegionProviderTest extends AbstractXtextTests {
|
|||
assertEquals(3, tokenRegion.getLength());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBug486454() throws Exception {
|
||||
String model = "t";
|
||||
ITextRegion tokenRegion = tokenRegionProvider.getTokenRegion(model, new TextRegion(1, 0));
|
||||
assertEquals(0, tokenRegion.getOffset());
|
||||
assertEquals(1, tokenRegion.getLength());
|
||||
}
|
||||
|
||||
protected CommonToken findTokenStartingAt(final int offset, List<CommonToken> tokens) {
|
||||
return find(tokens, new Predicate<CommonToken>() {
|
||||
@Override
|
||||
|
|
Loading…
Reference in a new issue