Java Code Examples for org.eclipse.xtext.xbase.lib.ListExtensions#map()

The following examples show how to use org.eclipse.xtext.xbase.lib.ListExtensions#map() . 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: EclipseFileSystemSupportImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Iterable<? extends Path> getChildren(final URI uri, final Path path) {
  final IResource resource = this.findMember(uri);
  if ((resource instanceof IContainer)) {
    try {
      final Function1<IResource, Path> _function = (IResource it) -> {
        String _string = it.getFullPath().toString();
        return new Path(_string);
      };
      return ListExtensions.<IResource, Path>map(((List<IResource>)Conversions.doWrapArray(((IContainer)resource).members())), _function);
    } catch (final Throwable _t) {
      if (_t instanceof CoreException) {
        final CoreException exc = (CoreException)_t;
        String _message = exc.getMessage();
        throw new IllegalArgumentException(_message, exc);
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
  }
  return CollectionLiterals.<Path>emptyList();
}
 
Example 2
Source File: AbstractExpectationTest.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
public void recordExpectation(final XExpression expression, final ITypeComputationState state) {
  List<? extends ITypeExpectation> _expectations = state.getExpectations();
  Iterables.<ITypeExpectation>addAll(this.finalExpectations, _expectations);
  final Function1<ITypeExpectation, String> _function = (ITypeExpectation it) -> {
    LightweightTypeReference _expectedType = it.getExpectedType();
    String _simpleName = null;
    if (_expectedType!=null) {
      _simpleName=_expectedType.getSimpleName();
    }
    return _simpleName;
  };
  List<String> _map = ListExtensions.map(state.getExpectations(), _function);
  Iterables.<String>addAll(this.expectations, _map);
  this.expressions.add(expression);
}
 
Example 3
Source File: GrammarKeywordAccessFragment2.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Returns all grammars from the hierarchy that are used from rules of this grammar.
 *
 * @param grammar the grammar.
 * @return the used grammars.
 */
protected static List<Grammar> getEffectivelyUsedGrammars(final Grammar grammar) {
	final List<AbstractRule> allRules = GrammarUtil.allRules(grammar);
	final List<Grammar> map = ListExtensions.<AbstractRule, Grammar>map(allRules, it -> GrammarUtil.getGrammar(it));
	final Iterable<Grammar> filter = IterableExtensions.<Grammar>filter(map, it -> Boolean.valueOf(it != grammar));
	final Set<Grammar> set = IterableExtensions.<Grammar>toSet(filter);
	return IterableExtensions.<Grammar>toList(set);
}
 
Example 4
Source File: JavaIOFileSystemSupport.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<? extends Path> getChildren(final URI uri, final Path path) {
  java.net.URI _uRI = this.toURI(uri);
  final Function1<String, Path> _function = (String it) -> {
    return path.getAbsolutePath(it);
  };
  return ListExtensions.<String, Path>map(((List<String>)Conversions.doWrapArray(new File(_uRI).list())), _function);
}
 
Example 5
Source File: XtendMethodDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<? extends ParameterDeclaration> getParameters() {
  final Function1<XtendParameter, XtendParameterDeclarationImpl> _function = (XtendParameter it) -> {
    return this.getCompilationUnit().toXtendParameterDeclaration(it);
  };
  return ListExtensions.<XtendParameter, XtendParameterDeclarationImpl>map(this.getDelegate().getParameters(), _function);
}
 
Example 6
Source File: LiveShadowedChunkedContainerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private ResourceDescriptionsData createResourceDescriptionData(final Resource... resources) {
  final Function1<Resource, IResourceDescription> _function = (Resource it) -> {
    return this.resourceDescriptionManager.getResourceDescription(it);
  };
  List<IResourceDescription> _map = ListExtensions.<Resource, IResourceDescription>map(((List<Resource>)Conversions.doWrapArray(resources)), _function);
  return new ResourceDescriptionsData(_map);
}
 
Example 7
Source File: TypeReferenceImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<? extends ResolvedMethod> getAllResolvedMethods() {
  final Function1<IResolvedOperation, ResolvedMethod> _function = (IResolvedOperation it) -> {
    return this.getCompilationUnit().toResolvedMethod(it);
  };
  return ListExtensions.<IResolvedOperation, ResolvedMethod>map(this.getCompilationUnit().getOverrideHelper().getResolvedFeatures(this.getDelegate()).getAllOperations(), _function);
}
 
Example 8
Source File: ResolvedExecutableImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<? extends TypeReference> getResolvedExceptionTypes() {
  final Function1<LightweightTypeReference, TypeReference> _function = (LightweightTypeReference it) -> {
    return this.getCompilationUnit().toTypeReference(it);
  };
  return ListExtensions.<LightweightTypeReference, TypeReference>map(this.getDelegate().getResolvedExceptions(), _function);
}
 
Example 9
Source File: JvmClassDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<? extends TypeParameterDeclaration> getTypeParameters() {
  final Function1<JvmTypeParameter, TypeParameterDeclaration> _function = (JvmTypeParameter it) -> {
    return this.getCompilationUnit().toTypeParameterDeclaration(it);
  };
  return ListExtensions.<JvmTypeParameter, TypeParameterDeclaration>map(this.getDelegate().getTypeParameters(), _function);
}
 
Example 10
Source File: JvmInterfaceDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<? extends TypeParameterDeclaration> getTypeParameters() {
  final Function1<JvmTypeParameter, TypeParameterDeclaration> _function = (JvmTypeParameter it) -> {
    return this.getCompilationUnit().toTypeParameterDeclaration(it);
  };
  return ListExtensions.<JvmTypeParameter, TypeParameterDeclaration>map(this.getDelegate().getTypeParameters(), _function);
}
 
Example 11
Source File: TypeReferenceImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<? extends ResolvedConstructor> getDeclaredResolvedConstructors() {
  final Function1<IResolvedConstructor, ResolvedConstructor> _function = (IResolvedConstructor it) -> {
    return this.getCompilationUnit().toResolvedConstructor(it);
  };
  return ListExtensions.<IResolvedConstructor, ResolvedConstructor>map(this.getCompilationUnit().getOverrideHelper().getResolvedFeatures(this.getDelegate()).getDeclaredConstructors(), _function);
}
 
Example 12
Source File: ServerRefactoringIssueAcceptor.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public ResponseError toResponseError() {
	Severity maxSeverity = getMaximumSeverity();
	ResponseError responseError = new ResponseError();
	responseError.setMessage(getMessageBySeverity(maxSeverity));
	responseError.setCode(getCodeBySeverity(maxSeverity));
	List<Issue> bySeverity = IterableExtensions.sortBy(issues, (i) -> i.severity);
	List<String> messages = ListExtensions.map(ListExtensions.reverse(bySeverity), (i) -> i.message);
	responseError.setData(IterableExtensions.join(messages, "\n"));
	return responseError;
}
 
Example 13
Source File: XtendClassDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<? extends TypeReference> getImplementedInterfaces() {
  final Function1<JvmTypeReference, TypeReference> _function = (JvmTypeReference it) -> {
    return this.getCompilationUnit().toTypeReference(it);
  };
  return ListExtensions.<JvmTypeReference, TypeReference>map(this.getDelegate().getImplements(), _function);
}
 
Example 14
Source File: TypeReferenceImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<? extends ResolvedMethod> getDeclaredResolvedMethods() {
  final Function1<IResolvedOperation, ResolvedMethod> _function = (IResolvedOperation it) -> {
    return this.getCompilationUnit().toResolvedMethod(it);
  };
  return ListExtensions.<IResolvedOperation, ResolvedMethod>map(this.getCompilationUnit().getOverrideHelper().getResolvedFeatures(this.getDelegate()).getDeclaredOperations(), _function);
}
 
Example 15
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 16
Source File: XtendClassDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Iterable<? extends TypeParameterDeclaration> getTypeParameters() {
  final Function1<JvmTypeParameter, XtendTypeParameterDeclarationImpl> _function = (JvmTypeParameter it) -> {
    return this.getCompilationUnit().toXtendTypeParameterDeclaration(it);
  };
  return ListExtensions.<JvmTypeParameter, XtendTypeParameterDeclarationImpl>map(this.getDelegate().getTypeParameters(), _function);
}
 
Example 17
Source File: AnnotationProcessor.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public Object validationPhase(final ActiveAnnotationContext ctx, final CancelIndicator monitor) {
  Object _xblockexpression = null;
  {
    final Stopwatches.StoppedTask task = Stopwatches.forTask("[macros] validationPhase (AnnotationProcessor.validationPhase)");
    task.start();
    Object _xtrycatchfinallyexpression = null;
    try {
      Object _switchResult = null;
      Object _processorInstance = ctx.getProcessorInstance();
      final Object processor = _processorInstance;
      boolean _matched = false;
      if (processor instanceof ValidationParticipant) {
        _matched=true;
        Object _xblockexpression_1 = null;
        {
          final ValidationContextImpl validationContext = this.validationContextProvider.get();
          validationContext.setUnit(ctx.getCompilationUnit());
          final Runnable _function = () -> {
            final Function1<XtendAnnotationTarget, NamedElement> _function_1 = (XtendAnnotationTarget it) -> {
              Declaration _switchResult_1 = null;
              boolean _matched_1 = false;
              if (it instanceof XtendMember) {
                _matched_1=true;
                _switchResult_1 = ctx.getCompilationUnit().toXtendMemberDeclaration(((XtendMember)it));
              }
              if (!_matched_1) {
                if (it instanceof XtendParameter) {
                  _matched_1=true;
                  _switchResult_1 = ctx.getCompilationUnit().toXtendParameterDeclaration(((XtendParameter)it));
                }
              }
              final Declaration xtendMember = _switchResult_1;
              Element _primaryGeneratedJavaElement = validationContext.getPrimaryGeneratedJavaElement(xtendMember);
              return ((NamedElement) _primaryGeneratedJavaElement);
            };
            final List<NamedElement> map = ListExtensions.<XtendAnnotationTarget, NamedElement>map(ctx.getAnnotatedSourceElements(), _function_1);
            ((ValidationParticipant<NamedElement>)processor).doValidate(map, validationContext);
          };
          _xblockexpression_1 = this.runWithCancelIndiciator(ctx, monitor, _function);
        }
        _switchResult = _xblockexpression_1;
      }
      _xtrycatchfinallyexpression = _switchResult;
    } finally {
      task.stop();
    }
    _xblockexpression = _xtrycatchfinallyexpression;
  }
  return _xblockexpression;
}
 
Example 18
Source File: JvmExecutableDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public List<TypeReference> getExceptions() {
  final Function1<JvmTypeReference, TypeReference> _function = (JvmTypeReference it) -> {
    return this.getCompilationUnit().toTypeReference(it);
  };
  return ListExtensions.<JvmTypeReference, TypeReference>map(this.getDelegate().getExceptions(), _function);
}
 
Example 19
Source File: Xbase10_Switch.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public List<String> myMethod() throws Throwable {
  List<String> _xblockexpression = null;
  {
    final ArrayList<String> list = CollectionLiterals.<String>newArrayList("foo", "bar", "baz");
    String _head = IterableExtensions.<String>head(list);
    if (_head != null) {
      switch (_head) {
        case "foo":
          /* "it\'s foo" */
          break;
        case "bar":
          /* "a bar" */
          break;
        default:
          /* "don\'t know" */
          break;
      }
    } else {
      /* "don\'t know" */
    }
    Rectangle _rectangle = new Rectangle(5, 5);
    Circle _circle = new Circle(4);
    Rectangle _rectangle_1 = new Rectangle(6, 8);
    final ArrayList<Shape> list2 = CollectionLiterals.<Shape>newArrayList(_rectangle, _circle, _rectangle_1);
    final Function1<Shape, String> _function = (Shape shape) -> {
      String _switchResult_1 = null;
      boolean _matched = false;
      if (shape instanceof Circle) {
        _matched=true;
        _switchResult_1 = ("a circle : diameter=" + Integer.valueOf(((Circle)shape).diameter));
      }
      if (!_matched) {
        if (shape instanceof Rectangle) {
          if ((((Rectangle)shape).height == ((Rectangle)shape).width)) {
            _matched=true;
            _switchResult_1 = ("a square : size=" + Integer.valueOf(((Rectangle)shape).width));
          }
        }
      }
      if (!_matched) {
        if (shape instanceof Rectangle) {
          _matched=true;
          _switchResult_1 = ((("a rectangle : width=" + Integer.valueOf(((Rectangle)shape).width)) + ", height=") + Integer.valueOf(((Rectangle)shape).height));
        }
      }
      return _switchResult_1;
    };
    _xblockexpression = ListExtensions.<Shape, String>map(list2, _function);
  }
  return _xblockexpression;
}
 
Example 20
Source File: FragmentAdapter.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
private GuiceModuleAccess.Binding translateBinding(final Binding it) {
  GuiceModuleAccess.Binding _xblockexpression = null;
  {
    GuiceModuleAccess.BindKey _xifexpression = null;
    if (((it.getValue().getStatements() == null) || ((List<String>)Conversions.doWrapArray(it.getValue().getStatements())).isEmpty())) {
      String _type = it.getKey().getType();
      TypeReference _guessTypeRef = null;
      if (_type!=null) {
        _guessTypeRef=TypeReference.guessTypeRef(_type);
      }
      boolean _isSingleton = it.getKey().isSingleton();
      boolean _isEagerSingleton = it.getKey().isEagerSingleton();
      _xifexpression = new GuiceModuleAccess.BindKey(null, _guessTypeRef, _isSingleton, _isEagerSingleton);
    } else {
      String _className = this.getClassName(it.getKey().getType());
      boolean _isSingleton_1 = it.getKey().isSingleton();
      boolean _isEagerSingleton_1 = it.getKey().isEagerSingleton();
      _xifexpression = new GuiceModuleAccess.BindKey(_className, null, _isSingleton_1, _isEagerSingleton_1);
    }
    final GuiceModuleAccess.BindKey newKey = _xifexpression;
    String _expression = it.getValue().getExpression();
    String _typeName = it.getValue().getTypeName();
    TypeReference _guessTypeRef_1 = null;
    if (_typeName!=null) {
      _guessTypeRef_1=TypeReference.guessTypeRef(_typeName);
    }
    boolean _isProvider = it.getValue().isProvider();
    final Function1<String, Object> _function = (String s) -> {
      String _xifexpression_1 = null;
      boolean _endsWith = s.endsWith(";");
      if (_endsWith) {
        _xifexpression_1 = s;
      } else {
        _xifexpression_1 = (s + ";");
      }
      return _xifexpression_1;
    };
    List<Object> _map = ListExtensions.<String, Object>map(((List<String>)Conversions.doWrapArray(it.getValue().getStatements())), _function);
    final GuiceModuleAccess.BindValue newValue = new GuiceModuleAccess.BindValue(_expression, _guessTypeRef_1, _isProvider, _map);
    boolean _isFinal = it.isFinal();
    String _contributedBy = it.getContributedBy();
    _xblockexpression = new GuiceModuleAccess.Binding(newKey, newValue, _isFinal, _contributedBy);
  }
  return _xblockexpression;
}