Java Code Examples for org.eclipse.xtext.xbase.lib.Extension

The following examples show how to use org.eclipse.xtext.xbase.lib.Extension. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: xtext-extras   Source File: XbaseFormatter.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected void _format(final XCollectionLiteral literal, @Extension final IFormattableDocument document) {
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.noSpace();
  };
  document.append(this.textRegionExtensions.regionFor(literal).keyword("#"), _function);
  ISemanticRegion _elvis = null;
  ISemanticRegion _keyword = this.textRegionExtensions.regionFor(literal).keyword("[");
  if (_keyword != null) {
    _elvis = _keyword;
  } else {
    ISemanticRegion _keyword_1 = this.textRegionExtensions.regionFor(literal).keyword("{");
    _elvis = _keyword_1;
  }
  final ISemanticRegion open = _elvis;
  ISemanticRegion _elvis_1 = null;
  ISemanticRegion _keyword_2 = this.textRegionExtensions.regionFor(literal).keyword("]");
  if (_keyword_2 != null) {
    _elvis_1 = _keyword_2;
  } else {
    ISemanticRegion _keyword_3 = this.textRegionExtensions.regionFor(literal).keyword("}");
    _elvis_1 = _keyword_3;
  }
  final ISemanticRegion close = _elvis_1;
  this.formatCommaSeparatedList(literal.getElements(), open, close, document);
}
 
Example 2
protected void _format(final Unit unit, @Extension final IFormattableDocument document) {
  EList<SimpleTypeRef> _implements = unit.getImplements();
  for (final SimpleTypeRef simpleTypeRef : _implements) {
    document.<SimpleTypeRef>format(simpleTypeRef);
  }
  EList<ProvidedCapability> _providedCapabilities = unit.getProvidedCapabilities();
  for (final ProvidedCapability providedCapability : _providedCapabilities) {
    document.<ProvidedCapability>format(providedCapability);
  }
  EList<AliasedRequiredCapability> _requiredCapabilities = unit.getRequiredCapabilities();
  for (final AliasedRequiredCapability aliasedRequiredCapability : _requiredCapabilities) {
    document.<AliasedRequiredCapability>format(aliasedRequiredCapability);
  }
  EList<RequiredCapability> _metaRequiredCapabilities = unit.getMetaRequiredCapabilities();
  for (final RequiredCapability requiredCapability : _metaRequiredCapabilities) {
    document.<RequiredCapability>format(requiredCapability);
  }
  EList<Function> _functions = unit.getFunctions();
  for (final Function function : _functions) {
    document.<Function>format(function);
  }
}
 
Example 3
Source Project: xtext-xtend   Source File: ToAnnoProcessor.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void doTransform(final MutableClassDeclaration annotatedClass, @Extension final TransformationContext context) {
  super.doTransform(annotatedClass, context);
  Type _findTypeGlobally = context.findTypeGlobally(this.generatedAnnotationName(annotatedClass));
  final MutableAnnotationTypeDeclaration annotationType = ((MutableAnnotationTypeDeclaration) _findTypeGlobally);
  final Procedure1<MutableAnnotationTypeElementDeclaration> _function = (MutableAnnotationTypeElementDeclaration it) -> {
    it.setDocComment("Best building strategy game ever");
    it.setType(context.newTypeReference(Integer.TYPE));
    boolean _booleanValue = annotatedClass.findAnnotation(context.findTypeGlobally(ToAnno.class)).getBooleanValue("defaultValue");
    if (_booleanValue) {
      StringConcatenationClient _client = new StringConcatenationClient() {
        @Override
        protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
          _builder.append("1602");
        }
      };
      it.setDefaultValueExpression(_client);
    }
  };
  annotationType.addAnnotationTypeElement("anno", _function);
}
 
Example 4
@Override
public void doTransform(final MutableClassDeclaration annotatedClass, @Extension final TransformationContext context) {
  final MutableInterfaceDeclaration interfaceType = context.findInterface(this.getInterfaceName(annotatedClass));
  context.setPrimarySourceElement(interfaceType, annotatedClass);
  try {
    final EnumerationValueDeclaration value = annotatedClass.findAnnotation(context.findTypeGlobally(AnnotationWithNestedEnum.class)).getEnumValue("value");
    final Procedure1<AnnotationReferenceBuildContext> _function = (AnnotationReferenceBuildContext it) -> {
      it.setEnumValue("value", value);
    };
    final AnnotationReference ref = context.newAnnotationReference(AnnotationWithNestedEnum.class, _function);
    interfaceType.addAnnotation(ref);
  } catch (final Throwable _t) {
    if (_t instanceof Exception) {
      final Exception exc = (Exception)_t;
      String _message = exc.getMessage();
      String _plus = ("failed: " + _message);
      context.addError(annotatedClass, _plus);
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  }
}
 
Example 5
Source Project: xtext-xtend   Source File: XtendJvmModelInferrer.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected void translateParameter(JvmExecutable executable, XtendParameter parameter) {
	JvmFormalParameter jvmParam = typesFactory.createJvmFormalParameter();
	jvmParam.setName(parameter.getName());
	if (parameter.isVarArg()) {
		executable.setVarArgs(true);
		JvmGenericArrayTypeReference arrayType = typeReferences.createArrayType(jvmTypesBuilder
				.cloneWithProxies(parameter.getParameterType()));
		jvmParam.setParameterType(arrayType);
	} else {
		jvmParam.setParameterType(jvmTypesBuilder.cloneWithProxies(parameter.getParameterType()));
	}
	associator.associate(parameter, jvmParam);
	translateAnnotationsTo(parameter.getAnnotations(), jvmParam);
	if (parameter.isExtension() && typeReferences.findDeclaredType(Extension.class, parameter) != null) {
		jvmParam.getAnnotations().add(_annotationTypesBuilder.annotationRef(Extension.class));
	}
	executable.getParameters().add(jvmParam);
}
 
Example 6
protected void testSymbol(final Procedure1<? super WorkspaceSymbolConfiguration> configurator) {
  try {
    @Extension
    final WorkspaceSymbolConfiguration configuration = new WorkspaceSymbolConfiguration();
    configuration.setFilePath(("MyModel." + this.fileExtension));
    configurator.apply(configuration);
    this.initializeContext(configuration);
    String _query = configuration.getQuery();
    WorkspaceSymbolParams _workspaceSymbolParams = new WorkspaceSymbolParams(_query);
    final List<? extends SymbolInformation> symbols = this.languageServer.symbol(_workspaceSymbolParams).get();
    Procedure1<? super List<? extends SymbolInformation>> _assertSymbols = configuration.getAssertSymbols();
    boolean _tripleNotEquals = (_assertSymbols != null);
    if (_tripleNotEquals) {
      configuration.getAssertSymbols().apply(symbols);
    } else {
      final String actualSymbols = this.toExpectation(symbols);
      this.assertEquals(configuration.getExpectedSymbols(), actualSymbols);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 7
Source Project: xtext-xtend   Source File: ExternalizedProcessor.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void doGenerateCode(final List<? extends ClassDeclaration> annotatedSourceElements, @Extension final CodeGenerationContext context) {
  for (final ClassDeclaration clazz : annotatedSourceElements) {
    {
      final Path filePath = clazz.getCompilationUnit().getFilePath();
      Path _targetFolder = context.getTargetFolder(filePath);
      String _replace = clazz.getQualifiedName().replace(".", "/");
      String _plus = (_replace + ".properties");
      final Path file = _targetFolder.append(_plus);
      StringConcatenation _builder = new StringConcatenation();
      {
        Iterable<? extends FieldDeclaration> _declaredFields = clazz.getDeclaredFields();
        for(final FieldDeclaration field : _declaredFields) {
          String _simpleName = field.getSimpleName();
          _builder.append(_simpleName);
          _builder.append(" = ");
          String _initializerAsString = this.getInitializerAsString(field);
          _builder.append(_initializerAsString);
          _builder.newLineIfNotEmpty();
        }
      }
      context.setContents(file, _builder);
    }
  }
}
 
Example 8
Source Project: xtext-xtend   Source File: AccessObjectProcessor.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void doRegisterGlobals(final List<? extends ClassDeclaration> annotatedSourceElements, @Extension final RegisterGlobalsContext ctx) {
  final Consumer<ClassDeclaration> _function = (ClassDeclaration it) -> {
    String _qualifiedName = it.getQualifiedName();
    int _length = it.getQualifiedName().length();
    int _length_1 = it.getSimpleName().length();
    int _minus = (_length - _length_1);
    final String pkg = _qualifiedName.substring(0, _minus);
    String _simpleName = it.getSimpleName();
    final String PVersionName = ((pkg + "P") + _simpleName);
    String _simpleName_1 = it.getSimpleName();
    final String GVersionName = ((pkg + "G") + _simpleName_1);
    ctx.registerClass(PVersionName);
    ctx.registerClass(GVersionName);
  };
  annotatedSourceElements.forEach(_function);
}
 
Example 9
protected void testFormatting(final Procedure1<? super DocumentFormattingParams> paramsConfigurator, final Procedure1<? super FormattingConfiguration> configurator) {
  try {
    @Extension
    final FormattingConfiguration configuration = new FormattingConfiguration();
    configuration.setFilePath(("MyModel." + this.fileExtension));
    configurator.apply(configuration);
    final FileInfo fileInfo = this.initializeContext(configuration);
    DocumentFormattingParams _documentFormattingParams = new DocumentFormattingParams();
    final Procedure1<DocumentFormattingParams> _function = (DocumentFormattingParams it) -> {
      String _uri = fileInfo.getUri();
      TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(_uri);
      it.setTextDocument(_textDocumentIdentifier);
      if ((paramsConfigurator != null)) {
        paramsConfigurator.apply(it);
      }
    };
    DocumentFormattingParams _doubleArrow = ObjectExtensions.<DocumentFormattingParams>operator_doubleArrow(_documentFormattingParams, _function);
    final CompletableFuture<List<? extends TextEdit>> changes = this.languageServer.formatting(_doubleArrow);
    String _contents = fileInfo.getContents();
    final Document result = new Document(Integer.valueOf(1), _contents).applyChanges(ListExtensions.<TextEdit>reverse(CollectionLiterals.<TextEdit>newArrayList(((TextEdit[])Conversions.unwrapArray(changes.get(), TextEdit.class)))));
    this.assertEqualsStricter(configuration.getExpectedText(), result.getContents());
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 10
Source Project: xtext-core   Source File: CommandServiceTest.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected void testExecuteCommand(final Procedure1<? super CommandServiceTest.TestExecuteCommandConfiguration> configurator) {
  try {
    @Extension
    final CommandServiceTest.TestExecuteCommandConfiguration configuration = new CommandServiceTest.TestExecuteCommandConfiguration();
    configurator.apply(configuration);
    final String command = configuration.command;
    final List<Object> args = configuration.args;
    ExecuteCommandParams _executeCommandParams = new ExecuteCommandParams(command, args);
    final CompletableFuture<Object> result = this.languageServer.executeCommand(_executeCommandParams);
    if ((configuration.assertCommandResult != null)) {
      final Object value = result.get();
      configuration.assertCommandResult.accept(value);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 11
Source Project: xtext-xtend   Source File: XtendFormatter.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void _format(final XVariableDeclaration expr, @Extension final IFormattableDocument format) {
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.oneSpace();
  };
  format.append(this.textRegionExtensions.regionFor(expr).keyword("extension"), _function);
  super._format(expr, format);
}
 
Example 12
protected boolean isExtensionProvider(JvmAnnotationTarget annotatedElement) {
	// coding style to simplify debugging
	if (annotationLookup.findAnnotation(annotatedElement, Extension.class) != null) {
		return true;
	}
	return false;
}
 
Example 13
@Test
public void regionForKeywordPairs2() throws Exception {
	@Extension
	RegionAccessTestLanguageGrammarAccess.ParenthesizedElements rule = grammarAccess
			.getParenthesizedAccess();
	Expression expr = parseAs("5 (a + ((b) + c) + d)", Expression.class);
	ISemanticRegionsFinder finder = toAccess(expr).regionForRootEObject().getAllRegionsFor();
	String actual1 = pairsToString(finder.keywordPairs("(", ")"));
	String actual2 = pairsToString(
			finder.keywordPairs(rule.getLeftParenthesisKeyword_0(), rule.getRightParenthesisKeyword_2()));
	String expected = "(b); ((b) + c); (a + ((b) + c) + d)";
	Assert.assertEquals(expected, actual1);
	Assert.assertEquals(expected, actual2);
}
 
Example 14
Source Project: xtext-lib   Source File: AccessorsProcessor.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void doTransform(final List<? extends MutableMemberDeclaration> elements, @Extension final TransformationContext context) {
  final Consumer<MutableMemberDeclaration> _function = (MutableMemberDeclaration it) -> {
    this.transform(it, context);
  };
  elements.forEach(_function);
}
 
Example 15
Source Project: xtext-extras   Source File: XbaseFormatter.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected void _format(final XThrowExpression expr, @Extension final IFormattableDocument format) {
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.oneSpace();
  };
  format.<XExpression>prepend(expr.getExpression(), _function);
  format.<XExpression>format(expr.getExpression());
}
 
Example 16
Source Project: xtext-extras   Source File: XbaseFormatter.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected void _format(final XExpression expr, @Extension final IFormattableDocument format) {
  EList<EObject> _eContents = expr.eContents();
  for (final EObject obj : _eContents) {
    boolean _matched = false;
    if (obj instanceof XExpression) {
      _matched=true;
      format.<XExpression>format(((XExpression)obj));
    }
  }
}
 
Example 17
Source Project: xtext-extras   Source File: XbaseFormatter.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected void _format(final XCastedExpression expr, @Extension final IFormattableDocument doc) {
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.oneSpace();
  };
  doc.surround(this.textRegionExtensions.regionFor(expr).keyword("as"), _function);
  doc.<XExpression>format(expr.getTarget());
  doc.<JvmTypeReference>format(expr.getType());
}
 
Example 18
Source Project: xtext-extras   Source File: XtypeFormatter.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected void _format(final JvmWildcardTypeReference ref, @Extension final IFormattableDocument document) {
  boolean _isEmpty = ref.getConstraints().isEmpty();
  boolean _not = (!_isEmpty);
  if (_not) {
    final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
      it.oneSpace();
    };
    document.append(this.textRegionExtensions.regionFor(ref).keyword("?"), _function);
  }
  EList<JvmTypeConstraint> _constraints = ref.getConstraints();
  for (final JvmTypeConstraint c : _constraints) {
    document.<JvmTypeConstraint>format(c);
  }
}
 
Example 19
Source Project: xtext-extras   Source File: XtypeFormatter.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected void _format(final JvmTypeParameter ref, @Extension final IFormattableDocument document) {
  EList<JvmTypeConstraint> _constraints = ref.getConstraints();
  for (final JvmTypeConstraint c : _constraints) {
    {
      final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
        it.oneSpace();
      };
      document.<JvmTypeConstraint>prepend(c, _function);
      document.<JvmTypeConstraint>format(c);
    }
  }
}
 
Example 20
Source Project: xtext-extras   Source File: XtypeFormatter.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected void _format(final XImportSection section, @Extension final IFormattableDocument format) {
  EList<XImportDeclaration> _importDeclarations = section.getImportDeclarations();
  for (final XImportDeclaration imp : _importDeclarations) {
    {
      format.<XImportDeclaration>format(imp);
      XImportDeclaration _last = IterableExtensions.<XImportDeclaration>last(section.getImportDeclarations());
      boolean _notEquals = (!Objects.equal(imp, _last));
      if (_notEquals) {
        format.<XImportDeclaration>append(imp, XbaseFormatterPreferenceKeys.blankLinesBetweenImports);
      } else {
        format.<XImportDeclaration>append(imp, XbaseFormatterPreferenceKeys.blankLinesAfterImports);
      }
    }
  }
}
 
Example 21
Source Project: xtext-xtend   Source File: FileProcessor.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void doTransform(final MutableClassDeclaration annotatedClass, @Extension final TransformationContext context) {
  final Path path = annotatedClass.getCompilationUnit().getFilePath();
  final String contents = context.getContents(context.getProjectFolder(path).append("res/template.txt")).toString();
  final String[] segments = contents.trim().split(",");
  for (final String segment : segments) {
    final Procedure1<MutableFieldDeclaration> _function = (MutableFieldDeclaration it) -> {
      it.setType(context.getString());
    };
    annotatedClass.addField(segment, _function);
  }
}
 
Example 22
protected void testDefinition(final Procedure1<? super DefinitionTestConfiguration> configurator) {
  try {
    @Extension
    final DefinitionTestConfiguration configuration = new DefinitionTestConfiguration();
    configuration.setFilePath(("MyModel." + this.fileExtension));
    configurator.apply(configuration);
    final String fileUri = this.initializeContext(configuration).getUri();
    DefinitionParams _definitionParams = new DefinitionParams();
    final Procedure1<DefinitionParams> _function = (DefinitionParams it) -> {
      TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(fileUri);
      it.setTextDocument(_textDocumentIdentifier);
      int _line = configuration.getLine();
      int _column = configuration.getColumn();
      Position _position = new Position(_line, _column);
      it.setPosition(_position);
    };
    DefinitionParams _doubleArrow = ObjectExtensions.<DefinitionParams>operator_doubleArrow(_definitionParams, _function);
    final CompletableFuture<Either<List<? extends Location>, List<? extends LocationLink>>> definitionsFuture = this.languageServer.definition(_doubleArrow);
    final Either<List<? extends Location>, List<? extends LocationLink>> definitions = definitionsFuture.get();
    Procedure1<? super List<? extends Location>> _assertDefinitions = configuration.getAssertDefinitions();
    boolean _tripleNotEquals = (_assertDefinitions != null);
    if (_tripleNotEquals) {
      configuration.getAssertDefinitions().apply(definitions.getLeft());
    } else {
      final String actualDefinitions = this.toExpectation(definitions);
      this.assertEquals(configuration.getExpectedDefinitions(), actualDefinitions);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 23
Source Project: xtext-lib   Source File: ToStringProcessor.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void doTransform(final MutableClassDeclaration it, @Extension final TransformationContext context) {
  AnnotationReference _findAnnotation = it.findAnnotation(context.findTypeGlobally(Data.class));
  boolean _tripleNotEquals = (_findAnnotation != null);
  if (_tripleNotEquals) {
    return;
  }
  @Extension
  final ToStringProcessor.Util util = new ToStringProcessor.Util(context);
  final AnnotationReference annotation = it.findAnnotation(context.findTypeGlobally(ToString.class));
  final ToStringConfiguration configuration = new ToStringConfiguration(annotation);
  boolean _hasToString = util.hasToString(it);
  if (_hasToString) {
    context.addWarning(annotation, "toString is already defined, this annotation has no effect.");
  } else {
    TypeReference _extendedClass = it.getExtendedClass();
    TypeReference _object = context.getObject();
    boolean _notEquals = (!Objects.equal(_extendedClass, _object));
    if (_notEquals) {
      util.addReflectiveToString(it, configuration);
    } else {
      final Function1<MutableFieldDeclaration, Boolean> _function = (MutableFieldDeclaration it_1) -> {
        return Boolean.valueOf(((context.isThePrimaryGeneratedJavaElement(it_1) && (!it_1.isStatic())) && (!it_1.isTransient())));
      };
      util.addToString(it, IterableExtensions.filter(it.getDeclaredFields(), _function), configuration);
    }
  }
}
 
Example 24
Source Project: xtext-xtend   Source File: XtendFormatter.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected void formatAnnotations(final XtendAnnotationTarget target, @Extension final IFormattableDocument document, final Procedure1<? super IHiddenRegionFormatter> configKey) {
  boolean _isEmpty = target.getAnnotations().isEmpty();
  if (_isEmpty) {
    return;
  }
  EList<XAnnotation> _annotations = target.getAnnotations();
  for (final XAnnotation a : _annotations) {
    {
      document.<XAnnotation>format(a);
      document.<XAnnotation>append(a, configKey);
    }
  }
}
 
Example 25
Source Project: xtext-xtend   Source File: ExtractProcessor.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void doTransform(final MutableClassDeclaration annotatedClass, @Extension final TransformationContext context) {
  final MutableInterfaceDeclaration interfaceType = context.findInterface(this.getInterfaceName(annotatedClass));
  context.setPrimarySourceElement(interfaceType, annotatedClass);
  Iterable<? extends TypeReference> _implementedInterfaces = annotatedClass.getImplementedInterfaces();
  TypeReference _newTypeReference = context.newTypeReference(interfaceType);
  Iterable<TypeReference> _plus = Iterables.<TypeReference>concat(_implementedInterfaces, Collections.<TypeReference>unmodifiableList(CollectionLiterals.<TypeReference>newArrayList(_newTypeReference)));
  annotatedClass.setImplementedInterfaces(_plus);
  Iterable<? extends MutableMethodDeclaration> _declaredMethods = annotatedClass.getDeclaredMethods();
  for (final MutableMethodDeclaration method : _declaredMethods) {
    Visibility _visibility = method.getVisibility();
    boolean _equals = Objects.equal(_visibility, Visibility.PUBLIC);
    if (_equals) {
      final Procedure1<MutableMethodDeclaration> _function = (MutableMethodDeclaration it) -> {
        it.setDocComment(method.getDocComment());
        it.setReturnType(method.getReturnType());
        Iterable<? extends MutableParameterDeclaration> _parameters = method.getParameters();
        for (final MutableParameterDeclaration p : _parameters) {
          it.addParameter(p.getSimpleName(), p.getType());
        }
        it.setExceptions(((TypeReference[])Conversions.unwrapArray(method.getExceptions(), TypeReference.class)));
        context.setPrimarySourceElement(it, method);
      };
      interfaceType.addMethod(method.getSimpleName(), _function);
    }
  }
}
 
Example 26
protected void generateProductionGrammar() {
  @Extension
  final GrammarNaming naming = this.productionNaming;
  final IXtextGeneratorFileSystemAccess fsa = this.getProjectConfig().getRuntime().getSrcGen();
  this.productionGenerator.generate(this.getGrammar(), this.getOptions(), fsa);
  this.runAntlr(naming.getParserGrammar(this.getGrammar()), naming.getLexerGrammar(this.getGrammar()), fsa);
  this.simplifyUnorderedGroupPredicatesIfRequired(this.getGrammar(), fsa, naming.getInternalParserClass(this.getGrammar()));
  this.splitParserAndLexerIfEnabled(fsa, naming.getInternalParserClass(this.getGrammar()), naming.getLexerClass(this.getGrammar()));
  this.normalizeTokens(fsa, naming.getLexerGrammar(this.getGrammar()).getTokensFileName());
  this.suppressWarnings(fsa, naming.getInternalParserClass(this.getGrammar()), naming.getLexerClass(this.getGrammar()));
  this.normalizeLineDelimiters(fsa, naming.getInternalParserClass(this.getGrammar()), naming.getLexerClass(this.getGrammar()));
}
 
Example 27
Source Project: xtext-lib   Source File: DelegateProcessor.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void doTransform(final List<? extends MutableMemberDeclaration> elements, @Extension final TransformationContext context) {
  @Extension
  final DelegateProcessor.Util util = new DelegateProcessor.Util(context);
  final Consumer<MutableMemberDeclaration> _function = (MutableMemberDeclaration it) -> {
    boolean _isValidDelegate = util.isValidDelegate(it);
    if (_isValidDelegate) {
      final Consumer<ResolvedMethod> _function_1 = (ResolvedMethod method) -> {
        util.implementMethod(it, method);
      };
      util.getMethodsToImplement(it).forEach(_function_1);
    }
  };
  elements.forEach(_function);
}
 
Example 28
protected void testDocumentSymbol(final Procedure1<? super DocumentSymbolConfiguraiton> configurator) {
  try {
    @Extension
    final DocumentSymbolConfiguraiton configuration = new DocumentSymbolConfiguraiton();
    configuration.setFilePath(("MyModel." + this.fileExtension));
    configurator.apply(configuration);
    final String fileUri = this.initializeContext(configuration).getUri();
    TextDocumentIdentifier _textDocumentIdentifier = new TextDocumentIdentifier(fileUri);
    DocumentSymbolParams _documentSymbolParams = new DocumentSymbolParams(_textDocumentIdentifier);
    final CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> symbolsFuture = this.languageServer.documentSymbol(_documentSymbolParams);
    final List<Either<SymbolInformation, DocumentSymbol>> symbols = symbolsFuture.get();
    Procedure1<? super List<Either<SymbolInformation, DocumentSymbol>>> _assertSymbols = configuration.getAssertSymbols();
    boolean _tripleNotEquals = (_assertSymbols != null);
    if (_tripleNotEquals) {
      configuration.getAssertSymbols().apply(symbols);
    } else {
      final Function1<Either<SymbolInformation, DocumentSymbol>, Object> _function = (Either<SymbolInformation, DocumentSymbol> it) -> {
        Object _xifexpression = null;
        if (this.hierarchicalDocumentSymbolSupport) {
          _xifexpression = it.getRight();
        } else {
          _xifexpression = it.getLeft();
        }
        return _xifexpression;
      };
      final List<Object> unwrappedSymbols = ListExtensions.<Either<SymbolInformation, DocumentSymbol>, Object>map(symbols, _function);
      final String actualSymbols = this.toExpectation(unwrappedSymbols);
      this.assertEquals(configuration.getExpectedSymbols(), actualSymbols);
    }
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 29
Source Project: lsp4j   Source File: JsonRpcDataProcessor.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected void addEitherSetter(final MutableFieldDeclaration field, final String setterName, final EitherTypeArgument argument, @Extension final JsonRpcDataTransformationContext context) {
  final Procedure1<MutableMethodDeclaration> _function = (MutableMethodDeclaration method) -> {
    context.setPrimarySourceElement(method, context.getPrimarySourceElement(field));
    method.addParameter(field.getSimpleName(), argument.getType());
    method.setStatic(field.isStatic());
    method.setVisibility(Visibility.PUBLIC);
    method.setReturnType(context.getPrimitiveVoid());
    final CompilationStrategy _function_1 = (CompilationStrategy.CompilationContext ctx) -> {
      return this.compileEitherSetterBody(field, argument, field.getSimpleName(), ctx, context);
    };
    method.setBody(_function_1);
  };
  field.getDeclaringType().addMethod(setterName, _function);
}
 
Example 30
Source Project: xtext-xtend   Source File: XtendFormatter.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected void _format(final XtendAnnotationType annotationType, @Extension final IFormattableDocument format) {
  this.formatAnnotations(annotationType, format, XbaseFormatterPreferenceKeys.newLineAfterClassAnnotations);
  this.formatModifiers(annotationType, format);
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.oneSpace();
  };
  format.append(this.textRegionExtensions.regionFor(annotationType).keyword("annotation"), _function);
  this.formatBody(annotationType, format);
}