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

The following examples show how to use org.eclipse.xtext.xbase.lib.Extension. 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 File: XtendJvmModelInferrer.java    From xtext-xtend with 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 #2
Source File: AbstractLanguageServerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
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 #3
Source File: ToAnnoProcessor.java    From xtext-xtend with 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
Source File: XbaseFormatter.java    From xtext-extras with 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 #5
Source File: CommandServiceTest.java    From xtext-core with 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 #6
Source File: AbstractLanguageServerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
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 #7
Source File: AccessObjectProcessor.java    From xtext-xtend with 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 #8
Source File: AnnotationWithNestedEnumProcessor.java    From xtext-xtend with Eclipse Public License 2.0 6 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);
  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 #9
Source File: BeeLangTestLanguageFormatter.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
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 #10
Source File: ExternalizedProcessor.java    From xtext-xtend with 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 #11
Source File: FileProcessor.java    From xtext-xtend with 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 #12
Source File: XtendFormatter.java    From xtext-xtend with 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 #13
Source File: ToStringProcessor.java    From xtext-lib with 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 #14
Source File: XbaseFormatter.java    From xtext-extras with 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 #15
Source File: DelegateProcessor.java    From xtext-lib with 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 #16
Source File: XtypeFormatter.java    From xtext-extras with 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 #17
Source File: XbaseFormatter.java    From xtext-extras with 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 #18
Source File: XtypeFormatter.java    From xtext-extras with 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 #19
Source File: XtypeFormatter.java    From xtext-extras with 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 #20
Source File: ExtractProcessor.java    From xtext-xtend with 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 #21
Source File: XtextAntlrGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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 #22
Source File: XtendFormatter.java    From xtext-xtend with 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 #23
Source File: AbstractLanguageServerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
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 #24
Source File: JsonRpcDataProcessor.java    From lsp4j with 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 #25
Source File: XtendFormatter.java    From xtext-xtend with 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);
}
 
Example #26
Source File: XtendFormatter.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Always put existing modifiers into this fixed order
 */
protected void formatModifiers(final XtendMember member, @Extension final IFormattableDocument document) {
  final Consumer<ISemanticRegion> _function = (ISemanticRegion it) -> {
    final Procedure1<IHiddenRegionFormatter> _function_1 = (IHiddenRegionFormatter it_1) -> {
      it_1.oneSpace();
    };
    document.append(it, _function_1);
  };
  this.textRegionExtensions.regionFor(member).ruleCallsTo(this._xtendGrammarAccess.getCommonModifierRule(), this._xtendGrammarAccess.getMethodModifierRule(), this._xtendGrammarAccess.getFieldModifierRule()).forEach(_function);
}
 
Example #27
Source File: DomainmodelFormatter.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void _format(final Property property, @Extension final IFormattableDocument document) {
  final Procedure1<IHiddenRegionFormatter> _function = (IHiddenRegionFormatter it) -> {
    it.noSpace();
  };
  document.surround(this.textRegionExtensions.regionFor(property).keyword(":"), _function);
  document.<JvmTypeReference>format(property.getType());
}
 
Example #28
Source File: EqualsHashCodeProcessor.java    From xtext-lib with 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 EqualsHashCodeProcessor.Util util = new EqualsHashCodeProcessor.Util(context);
  boolean _hasEquals = util.hasEquals(it);
  if (_hasEquals) {
    final AnnotationReference annotation = it.findAnnotation(context.findTypeGlobally(EqualsHashCode.class));
    context.addWarning(annotation, "equals is already defined, this annotation has no effect");
  } else {
    boolean _hasHashCode = util.hasHashCode(it);
    if (_hasHashCode) {
      context.addWarning(it, "hashCode is already defined, this annotation has no effect");
    } else {
      final Function1<MutableFieldDeclaration, Boolean> _function = (MutableFieldDeclaration it_1) -> {
        return Boolean.valueOf((((!it_1.isStatic()) && (!it_1.isTransient())) && context.isThePrimaryGeneratedJavaElement(it_1)));
      };
      final Iterable<? extends MutableFieldDeclaration> fields = IterableExtensions.filter(it.getDeclaredFields(), _function);
      util.addEquals(it, fields, util.hasSuperEquals(it));
      util.addHashCode(it, fields, util.hasSuperHashCode(it));
    }
  }
}
 
Example #29
Source File: FinalFieldsConstructorProcessor.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void doTransform(final List<? extends MutableTypeParameterDeclarator> elements, @Extension final TransformationContext context) {
  final Consumer<MutableTypeParameterDeclarator> _function = (MutableTypeParameterDeclarator it) -> {
    this.transform(it, context);
  };
  elements.forEach(_function);
}
 
Example #30
Source File: ExtractTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testExtractAnnotation() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("@extract.Extract");
  _builder.newLine();
  _builder.append("class MyClass {");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("override doStuff(String myParam) throws IllegalArgumentException {");
  _builder.newLine();
  _builder.append("\t\t");
  _builder.append("return myParam");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("}");
  _builder.newLine();
  _builder.append("}");
  _builder.newLine();
  final IAcceptor<XtendCompilerTester.CompilationResult> _function = (XtendCompilerTester.CompilationResult it) -> {
    @Extension
    final TransformationContext ctx = it.getTransformationContext();
    final MutableInterfaceDeclaration interf = ctx.findInterface("MyClassInterface");
    final MutableClassDeclaration clazz = ctx.findClass("MyClass");
    Assert.assertEquals(IterableExtensions.head(clazz.getImplementedInterfaces()).getType(), interf);
    MutableMethodDeclaration _head = IterableExtensions.head(interf.getDeclaredMethods());
    final Procedure1<MutableMethodDeclaration> _function_1 = (MutableMethodDeclaration it_1) -> {
      Assert.assertEquals("doStuff", it_1.getSimpleName());
      Assert.assertEquals(ctx.getString(), it_1.getReturnType());
      Assert.assertEquals(ctx.newTypeReference(IllegalArgumentException.class), IterableExtensions.head(it_1.getExceptions()));
    };
    ObjectExtensions.<MutableMethodDeclaration>operator_doubleArrow(_head, _function_1);
  };
  this.compilerTester.compile(_builder, _function);
}