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

The following examples show how to use org.eclipse.xtext.xbase.lib.IterableExtensions#size() . 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: UniqueClassNameValidator.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected boolean checkUniqueInIndex(JvmDeclaredType type, Iterable<IEObjectDescription> descriptions) {
	Set<URI> resourceURIs = new HashSet<>();
	for (IEObjectDescription d : descriptions) {
		resourceURIs.add(d.getEObjectURI().trimFragment());
	}
	if (resourceURIs.size() > 1) {
		for (URI uri : resourceURIs) {
			if (!Objects.equal(uri, type.eResource().getURI())) {
				addIssue(type, uri.lastSegment());
				break;
			}
		}
		return false;
	} else {
		if (IterableExtensions.size(descriptions) > 1) {
			addIssue(type);
			return false;
		}
	}
	return true;
}
 
Example 2
Source File: JavaFileConverterTest.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public JavaConverter.ConversionResult converToXtend(final String unitName, final String javaCode) {
  try {
    final JavaConverter j2x = this.javaConverter.get();
    JavaConverter.ConversionResult result = j2x.toXtend(unitName, javaCode);
    int _size = IterableExtensions.size(result.getProblems());
    boolean _equals = (_size == 0);
    if (_equals) {
      try {
        this.file(result.getXtendCode(), true);
      } catch (final Throwable _t) {
        if (_t instanceof AssertionError) {
          result = j2x.useRobustSyntax().toXtend(unitName, javaCode);
        } else {
          throw Exceptions.sneakyThrow(_t);
        }
      }
    }
    return result;
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 3
Source File: CompilationUnitImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected Object translateAnnotationValue(final XExpression value, final JvmTypeReference expectedType) {
  Object _xblockexpression = null;
  {
    if ((value instanceof XAnnotation)) {
      return this.translateAnnotation(((XAnnotation)value));
    }
    if ((value instanceof XListLiteral)) {
      final Iterable<XAnnotation> annotations = Iterables.<XAnnotation>filter(((XListLiteral)value).getElements(), XAnnotation.class);
      int _size = ((XListLiteral)value).getElements().size();
      int _size_1 = IterableExtensions.size(annotations);
      boolean _equals = (_size == _size_1);
      if (_equals) {
        final ArrayList<AnnotationReference> annotationReferences = CollectionLiterals.<AnnotationReference>newArrayList();
        for (final XAnnotation annotation : annotations) {
          AnnotationReference _translateAnnotation = this.translateAnnotation(annotation);
          annotationReferences.add(_translateAnnotation);
        }
        final AnnotationReference[] result = ((AnnotationReference[])Conversions.unwrapArray(annotationReferences, AnnotationReference.class));
        return result;
      }
    }
    _xblockexpression = this.translate(this.evaluate(value, expectedType));
  }
  return _xblockexpression;
}
 
Example 4
Source File: ASTFlattenerUtils.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
private IMethodBinding internalFindOverride(final IMethodBinding method, final ITypeBinding superType, final boolean onlyPrimarylevel) {
  final Function1<IMethodBinding, Boolean> _function = (IMethodBinding it) -> {
    return Boolean.valueOf(method.overrides(it));
  };
  final Iterable<IMethodBinding> superClassOverride = IterableExtensions.<IMethodBinding>filter(((Iterable<IMethodBinding>)Conversions.doWrapArray(superType.getDeclaredMethods())), _function);
  int _size = IterableExtensions.size(superClassOverride);
  boolean _equals = (_size == 1);
  if (_equals) {
    return ((IMethodBinding[])Conversions.unwrapArray(superClassOverride, IMethodBinding.class))[0];
  } else {
    if ((!onlyPrimarylevel)) {
      return this.findOverride(method, superType);
    } else {
      return null;
    }
  }
}
 
Example 5
Source File: LoopExtensions.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Uses curly braces and comma as delimiters. Doesn't use them for single
 * valued iterables.
 */
public <T> void forEachWithShortcut(ITreeAppendable appendable, Iterable<T> elements,
		Procedure1<? super T> procedure) {
	if (IterableExtensions.size(elements) == 1) {
		procedure.apply(Iterables.getFirst(elements, null));
	} else {
		appendable.append("{");
		forEach(appendable, elements, (LoopParams it) -> {
			it.setPrefix(" ");
			it.setSeparator(", ");
			it.setSuffix(" ");
		}, procedure);
		appendable.append("}");
	}
}
 
Example 6
Source File: XbaseFormatter2.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean _isMultiParamInOwnLine(final XMemberFeatureCall fc, final FormattableDocument doc) {
  final ILeafNode closingBracket = this._nodeModelAccess.nodeForKeyword(fc, ")");
  HiddenLeafs _hiddenLeafsBefore = null;
  if (closingBracket!=null) {
    _hiddenLeafsBefore=this._hiddenLeafAccess.getHiddenLeafsBefore(closingBracket);
  }
  boolean _tripleNotEquals = (_hiddenLeafsBefore != null);
  if (_tripleNotEquals) {
    int _newLines = this._hiddenLeafAccess.getHiddenLeafsBefore(closingBracket).getNewLines();
    return (_newLines > 0);
  }
  final Iterable<XExpression> params = this.explicitParams(fc.getMemberCallArguments());
  return ((IterableExtensions.size(params) > 1) && this.isEachExpressionInOwnLine(params));
}
 
Example 7
Source File: XbaseFormatter2.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean _isMultiParamInOwnLine(final XFeatureCall fc, final FormattableDocument doc) {
  final ILeafNode closingBracket = this._nodeModelAccess.nodeForKeyword(fc, ")");
  HiddenLeafs _hiddenLeafsBefore = null;
  if (closingBracket!=null) {
    _hiddenLeafsBefore=this._hiddenLeafAccess.getHiddenLeafsBefore(closingBracket);
  }
  boolean _tripleNotEquals = (_hiddenLeafsBefore != null);
  if (_tripleNotEquals) {
    int _newLines = this._hiddenLeafAccess.getHiddenLeafsBefore(closingBracket).getNewLines();
    return (_newLines > 0);
  }
  final Iterable<XExpression> params = this.explicitParams(fc.getFeatureCallArguments());
  return ((IterableExtensions.size(params) > 1) && this.isEachExpressionInOwnLine(params));
}
 
Example 8
Source File: XbaseFormatter2.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
protected boolean _isMultiParamInOwnLine(final XConstructorCall fc, final FormattableDocument doc) {
  final ILeafNode closingBracket = this._nodeModelAccess.nodeForKeyword(fc, ")");
  HiddenLeafs _hiddenLeafsBefore = null;
  if (closingBracket!=null) {
    _hiddenLeafsBefore=this._hiddenLeafAccess.getHiddenLeafsBefore(closingBracket);
  }
  boolean _tripleNotEquals = (_hiddenLeafsBefore != null);
  if (_tripleNotEquals) {
    int _newLines = this._hiddenLeafAccess.getHiddenLeafsBefore(closingBracket).getNewLines();
    return (_newLines > 0);
  }
  final Iterable<XExpression> params = this.explicitParams(fc.getArguments());
  return ((IterableExtensions.size(params) > 1) && this.isEachExpressionInOwnLine(params));
}
 
Example 9
Source File: JavaIoFileSystemTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testGetProjectChildren() {
  final Path projectFolder = new Path("/foo");
  Assert.assertTrue(this.fs.exists(projectFolder));
  int _size = IterableExtensions.size(this.fs.getChildren(projectFolder));
  final int expectedChildrenSize = (_size + 1);
  Path _path = new Path("/foo/Foo.text");
  this.fs.setContents(_path, "Hello Foo");
  Iterable<? extends Path> _children = this.fs.getChildren(projectFolder);
  String _plus = ("" + _children);
  Assert.assertEquals(_plus, expectedChildrenSize, 
    IterableExtensions.size(this.fs.getChildren(projectFolder)));
}
 
Example 10
Source File: JavaIoFileSystemTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testGetProjectChildren() {
  final Path projectFolder = new Path("/foo");
  Assert.assertTrue(this.fs.exists(projectFolder));
  int _size = IterableExtensions.size(this.fs.getChildren(projectFolder));
  final int expectedChildrenSize = (_size + 1);
  Path _path = new Path("/foo/Foo.text");
  this.fs.setContents(_path, "Hello Foo");
  Iterable<? extends Path> _children = this.fs.getChildren(projectFolder);
  String _plus = ("" + _children);
  Assert.assertEquals(_plus, expectedChildrenSize, 
    IterableExtensions.size(this.fs.getChildren(projectFolder)));
}
 
Example 11
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public void visitAll(final Iterable<? extends ASTNode> iterable, final String separator) {
  final Procedure2<ASTNode, Integer> _function = (ASTNode node, Integer counter) -> {
    node.accept(this);
    if (((separator != null) && ((counter).intValue() < (IterableExtensions.size(iterable) - 1)))) {
      this.appendToBuffer(separator);
    }
  };
  IterableExtensions.forEach(iterable, _function);
}
 
Example 12
Source File: XtextValidator.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Check
public void checkCrossReferenceNotInAlternatives(Alternatives alternatives) {
	int numOfCrossRefs = IterableExtensions.size(IterableExtensions.filter(alternatives.getElements(), CrossReference.class));
	if (numOfCrossRefs > 1) {
		String errorMessage = "Cross references using the pattern 'feature=([SomeClass|ID] | [SomeClass|STRING])' are not allowed."
				+ " Use the pattern '(feature=[SomeClass|ID] | feature=[SomeClass|STRING])' instead.";
		error(errorMessage, alternatives, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, CROSS_REFERENCE_IN_ALTERNATIVES);
	}
}
 
Example 13
Source File: HiddenLeafs.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public boolean containsComment() {
	return IterableExtensions.size(Iterables.filter(leafs, CommentInfo.class)) > 0;
}
 
Example 14
Source File: JvmTypeExtensions.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public boolean isSingleSyntheticDefaultConstructor(JvmConstructor it) {
	return it.getParameters().isEmpty() && logicalContainerProvider.getAssociatedExpression(it) == null
			&& getCompilationStrategy(it) == null && getCompilationTemplate(it) == null && IterableExtensions
					.size(Iterables.filter(it.getDeclaringType().getMembers(), JvmConstructor.class)) == 1;
}
 
Example 15
Source File: EqualsHashCodeProcessor.java    From xtext-lib with Eclipse Public License 2.0 4 votes vote down vote up
public void addEquals(final MutableClassDeclaration cls, final Iterable<? extends FieldDeclaration> includedFields, final boolean includeSuper) {
  final Procedure1<MutableMethodDeclaration> _function = (MutableMethodDeclaration it) -> {
    this.context.setPrimarySourceElement(it, this.context.getPrimarySourceElement(cls));
    it.setReturnType(this.context.getPrimitiveBoolean());
    it.addAnnotation(this.context.newAnnotationReference(Override.class));
    it.addAnnotation(this.context.newAnnotationReference(Pure.class));
    it.addParameter("obj", this.context.getObject());
    StringConcatenationClient _client = new StringConcatenationClient() {
      @Override
      protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
        _builder.append("if (this == obj)");
        _builder.newLine();
        _builder.append("  ");
        _builder.append("return true;");
        _builder.newLine();
        _builder.append("if (obj == null)");
        _builder.newLine();
        _builder.append("  ");
        _builder.append("return false;");
        _builder.newLine();
        _builder.append("if (getClass() != obj.getClass())");
        _builder.newLine();
        _builder.append("  ");
        _builder.append("return false;");
        _builder.newLine();
        {
          if (includeSuper) {
            _builder.append("if (!super.equals(obj))");
            _builder.newLine();
            _builder.append("  ");
            _builder.append("return false;");
            _builder.newLine();
          }
        }
        {
          int _size = IterableExtensions.size(includedFields);
          boolean _greaterThan = (_size > 0);
          if (_greaterThan) {
            TypeReference _newWildCardSelfTypeReference = Util.this.newWildCardSelfTypeReference(cls);
            _builder.append(_newWildCardSelfTypeReference);
            _builder.append(" other = (");
            TypeReference _newWildCardSelfTypeReference_1 = Util.this.newWildCardSelfTypeReference(cls);
            _builder.append(_newWildCardSelfTypeReference_1);
            _builder.append(") obj;");
            _builder.newLineIfNotEmpty();
          }
        }
        {
          for(final FieldDeclaration field : includedFields) {
            StringConcatenationClient _contributeToEquals = Util.this.contributeToEquals(field);
            _builder.append(_contributeToEquals);
            _builder.newLineIfNotEmpty();
          }
        }
        _builder.append("return true;");
        _builder.newLine();
      }
    };
    it.setBody(_client);
  };
  cls.addMethod("equals", _function);
}
 
Example 16
Source File: EqualsHashCodeProcessor.java    From xtext-lib with Eclipse Public License 2.0 4 votes vote down vote up
public void addHashCode(final MutableClassDeclaration cls, final Iterable<? extends FieldDeclaration> includedFields, final boolean includeSuper) {
  String _xifexpression = null;
  if (includeSuper) {
    _xifexpression = "super.hashCode()";
  } else {
    _xifexpression = "1";
  }
  final String defaultBase = _xifexpression;
  final int fields = IterableExtensions.size(includedFields);
  final Procedure1<MutableMethodDeclaration> _function = (MutableMethodDeclaration it) -> {
    this.context.setPrimarySourceElement(it, this.context.getPrimarySourceElement(cls));
    it.setReturnType(this.context.getPrimitiveInt());
    it.addAnnotation(this.context.newAnnotationReference(Override.class));
    it.addAnnotation(this.context.newAnnotationReference(Pure.class));
    StringConcatenationClient _client = new StringConcatenationClient() {
      @Override
      protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
        {
          if ((fields >= 2)) {
            _builder.append("final int prime = ");
            _builder.append(EqualsHashCodeProcessor.Util.PRIME_VALUE);
            _builder.append(";");
            _builder.newLineIfNotEmpty();
            _builder.append("int result = ");
            _builder.append(defaultBase);
            _builder.append(";");
            _builder.newLineIfNotEmpty();
            {
              ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, fields, true);
              for(final Integer i : _doubleDotLessThan) {
                {
                  if (((i).intValue() == (fields - 1))) {
                    _builder.append("return");
                  } else {
                    _builder.append("result =");
                  }
                }
                _builder.append(" prime * result + ");
                StringConcatenationClient _contributeToHashCode = Util.this.contributeToHashCode(((FieldDeclaration[])Conversions.unwrapArray(includedFields, FieldDeclaration.class))[(i).intValue()]);
                _builder.append(_contributeToHashCode);
                _builder.append(";");
                _builder.newLineIfNotEmpty();
              }
            }
          } else {
            if ((fields == 1)) {
              _builder.append("return ");
              _builder.append(EqualsHashCodeProcessor.Util.PRIME_VALUE);
              _builder.append(" * ");
              _builder.append(defaultBase);
              _builder.append(" + ");
              StringConcatenationClient _contributeToHashCode_1 = Util.this.contributeToHashCode(IterableExtensions.head(includedFields));
              _builder.append(_contributeToHashCode_1);
              _builder.append(";");
              _builder.newLineIfNotEmpty();
            } else {
              _builder.append("return ");
              _builder.append(defaultBase);
              _builder.append(";");
              _builder.newLineIfNotEmpty();
            }
          }
        }
      }
    };
    it.setBody(_client);
  };
  cls.addMethod("hashCode", _function);
}