Java Code Examples for org.eclipse.xtext.xbase.lib.IterableExtensions#isNullOrEmpty()

The following examples show how to use org.eclipse.xtext.xbase.lib.IterableExtensions#isNullOrEmpty() . 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: XLanguageServerImpl.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public void didRefreshOpenFile(OpenFileContext ofc, CancelIndicator ci) {
	if (client instanceof LanguageClientExtensions) {

		LanguageClientExtensions clientExtensions = (LanguageClientExtensions) client;
		XtextResource resource = ofc.getResource();
		IResourceServiceProvider resourceServiceProvider = resource.getResourceServiceProvider();
		IColoringService coloringService = resourceServiceProvider.get(IColoringService.class);

		if (coloringService != null) {
			XDocument doc = ofc.getDocument();
			List<? extends ColoringInformation> colInfos = coloringService.getColoring(resource, doc);

			if (!IterableExtensions.isNullOrEmpty(colInfos)) {
				String uri = resource.getURI().toString();
				ColoringParams colParams = new ColoringParams(uri, colInfos);
				clientExtensions.updateColoring(colParams);
			}
		}
	}

	ILanguageServerAccess.Context ctx = new ILanguageServerAccess.Context(ofc.getResource(), ofc.getDocument(),
			true, ci);
	semanticHighlightingRegistry.update(ctx);
}
 
Example 2
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public boolean handleLambdaExpression(final ASTNode node) {
  this.appendToBuffer("[");
  final List<ASTNode> params = this._aSTFlattenerUtils.genericChildListProperty(node, "parameters");
  boolean _isNullOrEmpty = IterableExtensions.isNullOrEmpty(params);
  boolean _not = (!_isNullOrEmpty);
  if (_not) {
    this.visitAllSeparatedByComma(params);
    this.appendToBuffer(" | ");
  }
  ASTNode _genericChildProperty = this._aSTFlattenerUtils.genericChildProperty(node, "body");
  if (_genericChildProperty!=null) {
    _genericChildProperty.accept(this);
  }
  this.appendToBuffer("]");
  return false;
}
 
Example 3
Source File: SemanticHighlightingTokens.java    From lsp4j with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Encodes the iterable of tokens into a compact, {@code base64} string. Returns
 * with an empty string if the {@code tokens} argument is {@code null} or empty.
 */
public static String encode(Iterable<? extends Token> tokens) {
	if (IterableExtensions.isNullOrEmpty(tokens)) {
		return "";
	}
	// 2 stands for: number of elements for the output; the "character" and the
	// "length and scope".
	// 4 stands for: 4 byte for a primitive integer.
	ByteBuffer buffer = ByteBuffer.allocate(Iterables.size(tokens) * 2 * 4);
	for (Token token : tokens) {
		int character = token.character;
		int length = token.length;
		int scope = token.scope;

		int lengthAndScope = length;
		lengthAndScope = lengthAndScope << LENGTH_SHIFT;
		lengthAndScope |= scope;

		buffer.putInt(character);
		buffer.putInt(lengthAndScope);
	}
	return Base64.getEncoder().encodeToString(buffer.array());
}
 
Example 4
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public boolean hasDimensions(final VariableDeclarationFragment fragment) {
  boolean _java8orHigher = this.java8orHigher();
  if (_java8orHigher) {
    List<ASTNode> dimensions = this._aSTFlattenerUtils.genericChildListProperty(fragment, "extraDimensions2");
    boolean _isNullOrEmpty = IterableExtensions.isNullOrEmpty(dimensions);
    return (!_isNullOrEmpty);
  } else {
    int _extraDimensions = fragment.getExtraDimensions();
    return (_extraDimensions > 0);
  }
}
 
Example 5
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean visit(final TryStatement node) {
  this.appendToBuffer("try ");
  final List<ASTNode> resources = this._aSTFlattenerUtils.genericChildListProperty(node, "resources");
  boolean _isNullOrEmpty = IterableExtensions.isNullOrEmpty(resources);
  boolean _not = (!_isNullOrEmpty);
  if (_not) {
    this.appendToBuffer("(");
    for (final ASTNode child : resources) {
      child.accept(this);
    }
    this.appendToBuffer(")");
    this.addProblem(node, "Try with resource is not yet supported.");
  }
  node.getBody().accept(this);
  final Consumer<Object> _function = (Object it) -> {
    ((ASTNode) it).accept(this);
  };
  node.catchClauses().forEach(_function);
  Block _finally = node.getFinally();
  boolean _tripleNotEquals = (_finally != null);
  if (_tripleNotEquals) {
    this.appendToBuffer(" finally ");
    node.getFinally().accept(this);
  } else {
    this.appendLineWrapToBuffer();
  }
  return false;
}
 
Example 6
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean visit(final ArrayType node) {
  boolean _java8orHigher = this.java8orHigher();
  boolean _not = (!_java8orHigher);
  if (_not) {
    node.getComponentType().accept(this);
    this.appendToBuffer("[]");
  } else {
    ASTNode _genericChildProperty = this._aSTFlattenerUtils.genericChildProperty(node, "elementType");
    if (_genericChildProperty!=null) {
      _genericChildProperty.accept(this);
    }
    List<ASTNode> dimensions = this._aSTFlattenerUtils.genericChildListProperty(node, "dimensions");
    boolean _isNullOrEmpty = IterableExtensions.isNullOrEmpty(dimensions);
    boolean _not_1 = (!_isNullOrEmpty);
    if (_not_1) {
      final Consumer<ASTNode> _function = (ASTNode dim) -> {
        List<ASTNode> _genericChildListProperty = this._aSTFlattenerUtils.genericChildListProperty(dim, "annotations");
        if (_genericChildListProperty!=null) {
          this.visitAll(_genericChildListProperty);
        }
        this.appendToBuffer("[]");
      };
      dimensions.forEach(_function);
    }
  }
  return false;
}
 
Example 7
Source File: AbstractLanguageServerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected String _toExpectation(final CodeAction it) {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("title : ");
  String _title = it.getTitle();
  _builder.append(_title);
  _builder.newLineIfNotEmpty();
  _builder.append("kind : ");
  String _kind = it.getKind();
  _builder.append(_kind);
  _builder.newLineIfNotEmpty();
  _builder.append("command : ");
  Command _command = it.getCommand();
  _builder.append(_command);
  _builder.newLineIfNotEmpty();
  {
    boolean _isNullOrEmpty = IterableExtensions.isNullOrEmpty(it.getDiagnostics());
    boolean _not = (!_isNullOrEmpty);
    if (_not) {
      _builder.append("codes : ");
      final Function1<Diagnostic, Object> _function = (Diagnostic it_1) -> {
        return it_1.getCode().get();
      };
      String _join = IterableExtensions.join(ListExtensions.<Diagnostic, Object>map(it.getDiagnostics(), _function), ",");
      _builder.append(_join);
    }
  }
  _builder.newLineIfNotEmpty();
  _builder.append("edit : ");
  String _expectation = this.toExpectation(it.getEdit());
  _builder.append(_expectation);
  _builder.newLineIfNotEmpty();
  return _builder.toString();
}
 
Example 8
Source File: SemanticHighlightingTokens.java    From lsp4j with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Converts an iterable of tokens into an array of primitive integers. Returns
 * with an empty array if the argument is {@code null} or empty.
 * 
 * <p>
 * <ul>
 * <li>{@code array[3*i]} is the {@link Token#character character} of the
 * token.</li>
 * <li>{@code array[3*i+1]} is the {@link Token#length length} of the
 * token.</li>
 * <li>{@code array[3*i+2]} is the token {@link Token#scope scope}.</li>
 * </ul>
 */
public static int[] toIntArray(Iterable<? extends Token> tokens) {
	if (IterableExtensions.isNullOrEmpty(tokens)) {
		return EMPTY_ARRAY;
	}
	int[] array = new int[Iterables.size(tokens) * 3];
	int i = 0;
	for (Token token : tokens) {
		array[i++] = token.character;
		array[i++] = token.length;
		array[i++] = token.scope;
	}
	return array;
}
 
Example 9
Source File: CompletionTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected String _toExpectation(final CompletionItem it) {
  StringConcatenation _builder = new StringConcatenation();
  {
    if (this.withKind) {
      _builder.append("(");
      CompletionItemKind _kind = it.getKind();
      _builder.append(_kind);
      {
        InsertTextFormat _insertTextFormat = it.getInsertTextFormat();
        boolean _tripleNotEquals = (_insertTextFormat != null);
        if (_tripleNotEquals) {
          _builder.append("|");
          InsertTextFormat _insertTextFormat_1 = it.getInsertTextFormat();
          _builder.append(_insertTextFormat_1);
        }
      }
      _builder.append(") ");
    }
  }
  String _label = it.getLabel();
  _builder.append(_label);
  {
    boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(it.getDetail());
    boolean _not = (!_isNullOrEmpty);
    if (_not) {
      _builder.append(" (");
      String _detail = it.getDetail();
      _builder.append(_detail);
      _builder.append(")");
    }
  }
  {
    TextEdit _textEdit = it.getTextEdit();
    boolean _tripleNotEquals_1 = (_textEdit != null);
    if (_tripleNotEquals_1) {
      _builder.append(" -> ");
      String _expectation = this.toExpectation(it.getTextEdit());
      _builder.append(_expectation);
      {
        boolean _isNullOrEmpty_1 = IterableExtensions.isNullOrEmpty(it.getAdditionalTextEdits());
        boolean _not_1 = (!_isNullOrEmpty_1);
        if (_not_1) {
          _builder.append("   + ");
          final Function1<TextEdit, String> _function = (TextEdit it_1) -> {
            return this.toExpectation(it_1);
          };
          String _join = IterableExtensions.join(ListExtensions.<TextEdit, String>map(it.getAdditionalTextEdits(), _function), "   + ");
          _builder.append(_join);
        }
      }
    } else {
      if (((it.getInsertText() != null) && (!Objects.equal(it.getInsertText(), it.getLabel())))) {
        _builder.append(" -> ");
        String _insertText = it.getInsertText();
        _builder.append(_insertText);
      }
    }
  }
  _builder.newLineIfNotEmpty();
  return _builder.toString();
}
 
Example 10
Source File: AbstractLanguageServerTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * @since 2.16
 */
protected String _toExpectation(final DocumentSymbol it) {
  String _xblockexpression = null;
  {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("selectionRange must be contained in the range: ");
    _builder.append(it);
    Assert.assertTrue(_builder.toString(), Ranges.containsRange(it.getRange(), it.getSelectionRange()));
    StringConcatenation _builder_1 = new StringConcatenation();
    _builder_1.append("symbol \"");
    String _name = it.getName();
    _builder_1.append(_name);
    _builder_1.append("\" {");
    _builder_1.newLineIfNotEmpty();
    _builder_1.append("    ");
    _builder_1.append("kind: ");
    int _value = it.getKind().getValue();
    _builder_1.append(_value, "    ");
    _builder_1.newLineIfNotEmpty();
    _builder_1.append("    ");
    _builder_1.append("range: ");
    String _expectation = this.toExpectation(it.getRange());
    _builder_1.append(_expectation, "    ");
    _builder_1.newLineIfNotEmpty();
    _builder_1.append("    ");
    _builder_1.append("selectionRange: ");
    String _expectation_1 = this.toExpectation(it.getSelectionRange());
    _builder_1.append(_expectation_1, "    ");
    _builder_1.newLineIfNotEmpty();
    _builder_1.append("    ");
    _builder_1.append("details: ");
    String _detail = it.getDetail();
    _builder_1.append(_detail, "    ");
    _builder_1.newLineIfNotEmpty();
    _builder_1.append("    ");
    _builder_1.append("deprecated: ");
    Boolean _deprecated = it.getDeprecated();
    _builder_1.append(_deprecated, "    ");
    _builder_1.newLineIfNotEmpty();
    {
      boolean _isNullOrEmpty = IterableExtensions.isNullOrEmpty(it.getChildren());
      boolean _not = (!_isNullOrEmpty);
      if (_not) {
        _builder_1.append("    ");
        _builder_1.append("children: [");
        _builder_1.newLine();
        _builder_1.append("    ");
        _builder_1.append("\t");
        {
          List<DocumentSymbol> _children = it.getChildren();
          boolean _hasElements = false;
          for(final DocumentSymbol child : _children) {
            if (!_hasElements) {
              _hasElements = true;
            } else {
              _builder_1.appendImmediate("\n", "    \t");
            }
            String _expectation_2 = this.toExpectation(child);
            _builder_1.append(_expectation_2, "    \t");
          }
        }
        _builder_1.newLineIfNotEmpty();
        _builder_1.append("    ");
        _builder_1.append("]");
        _builder_1.newLine();
      }
    }
    _builder_1.append("}");
    _xblockexpression = _builder_1.toString();
  }
  return _xblockexpression;
}
 
Example 11
Source File: AbstractLanguageServerTest.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected String _toExpectation(final CompletionItem it) {
  StringConcatenation _builder = new StringConcatenation();
  String _label = it.getLabel();
  _builder.append(_label);
  {
    boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(it.getDetail());
    boolean _not = (!_isNullOrEmpty);
    if (_not) {
      _builder.append(" (");
      String _detail = it.getDetail();
      _builder.append(_detail);
      _builder.append(")");
    }
  }
  {
    TextEdit _textEdit = it.getTextEdit();
    boolean _tripleNotEquals = (_textEdit != null);
    if (_tripleNotEquals) {
      _builder.append(" -> ");
      String _expectation = this.toExpectation(it.getTextEdit());
      _builder.append(_expectation);
      {
        boolean _isNullOrEmpty_1 = IterableExtensions.isNullOrEmpty(it.getAdditionalTextEdits());
        boolean _not_1 = (!_isNullOrEmpty_1);
        if (_not_1) {
          _builder.append("   + ");
          final Function1<TextEdit, String> _function = (TextEdit it_1) -> {
            return this.toExpectation(it_1);
          };
          String _join = IterableExtensions.join(ListExtensions.<TextEdit, String>map(it.getAdditionalTextEdits(), _function), "   + ");
          _builder.append(_join);
        }
      }
    } else {
      if (((it.getInsertText() != null) && (!Objects.equal(it.getInsertText(), it.getLabel())))) {
        _builder.append(" -> ");
        String _insertText = it.getInsertText();
        _builder.append(_insertText);
      }
    }
  }
  _builder.newLineIfNotEmpty();
  return _builder.toString();
}