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

The following examples show how to use org.eclipse.xtext.xbase.lib.ExclusiveRange. 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: AbstractConstantExpressionsInterpreter.java    From xtext-extras with Eclipse Public License 2.0 6 votes vote down vote up
protected JvmTypeReference toTypeReference(final JvmType type, final int arrayDimensions) {
  if ((type == null)) {
    return null;
  }
  JvmParameterizedTypeReference _createJvmParameterizedTypeReference = TypesFactory.eINSTANCE.createJvmParameterizedTypeReference();
  final Procedure1<JvmParameterizedTypeReference> _function = (JvmParameterizedTypeReference it) -> {
    it.setType(type);
  };
  JvmTypeReference resultTypeRef = ObjectExtensions.<JvmParameterizedTypeReference>operator_doubleArrow(_createJvmParameterizedTypeReference, _function);
  ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, arrayDimensions, true);
  for (final Integer i : _doubleDotLessThan) {
    {
      final JvmGenericArrayTypeReference arrayRef = TypesFactory.eINSTANCE.createJvmGenericArrayTypeReference();
      arrayRef.setComponentType(resultTypeRef);
      resultTypeRef = arrayRef;
    }
  }
  return resultTypeRef;
}
 
Example #2
Source File: SemanticHighlightingRegistry.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected List<SemanticHighlightingInformation> appendEmptyLineTokens(final List<SemanticHighlightingInformation> infos, final Document document) {
  final int lineCount = document.getLineCount();
  final Function<SemanticHighlightingInformation, Integer> _function = (SemanticHighlightingInformation it) -> {
    return Integer.valueOf(it.getLine());
  };
  final HashMap<Integer, SemanticHighlightingInformation> tokens = Maps.<Integer, SemanticHighlightingInformation>newHashMap(Maps.<Integer, SemanticHighlightingInformation>uniqueIndex(infos, _function));
  ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, lineCount, true);
  for (final Integer i : _doubleDotLessThan) {
    boolean _containsKey = tokens.containsKey(i);
    boolean _not = (!_containsKey);
    if (_not) {
      SemanticHighlightingInformation _semanticHighlightingInformation = new SemanticHighlightingInformation((i).intValue(), null);
      tokens.put(i, _semanticHighlightingInformation);
    }
  }
  return IterableExtensions.<SemanticHighlightingInformation>toList(tokens.values());
}
 
Example #3
Source File: DefaultTaskParserTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testLongInputManyTasks() {
  final int expectation = 100000;
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("/*");
  _builder.newLine();
  {
    IntegerRange _upTo = new IntegerRange(1, expectation);
    for(final Integer i : _upTo) {
      _builder.append(" ");
      _builder.append("* FIXME this cannot work");
      _builder.newLine();
    }
  }
  _builder.append(" ");
  _builder.append("*/");
  _builder.newLine();
  final String source = _builder.toString();
  final List<Task> parsed = this.parser.parseTasks(LineDelimiters.toUnix(source), this.definitions);
  Assert.assertEquals(expectation, parsed.size());
  ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, expectation, true);
  for (final Integer i_1 : _doubleDotLessThan) {
    Assert.assertEquals(((i_1).intValue() + 2), parsed.get((i_1).intValue()).getLineNumber());
  }
}
 
Example #4
Source File: GeneratorNodeTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
private String someCodeGen_noTrace(final int n) {
  StringConcatenation _builder = new StringConcatenation();
  {
    ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, n, true);
    for(final Integer i : _doubleDotLessThan) {
      _builder.append("before ");
      _builder.append("Hello");
      _builder.append(" after");
      _builder.newLineIfNotEmpty();
      _builder.append("  ");
      String _someCodeGen_noTrace = this.someCodeGen_noTrace((n - 1));
      _builder.append(_someCodeGen_noTrace, "  ");
      _builder.newLineIfNotEmpty();
    }
  }
  return _builder.toString();
}
 
Example #5
Source File: SwtBotProjectHelper.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected static void fileNew(final SWTWorkbenchBot it, final String newWhat) {
  int retries = 3;
  ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, retries, true);
  for (final Integer i : _doubleDotLessThan) {
    try {
      it.menu("File").menu("New").menu(newWhat).click();
      return;
    } catch (final Throwable _t) {
      if (_t instanceof WidgetNotFoundException) {
        final WidgetNotFoundException e = (WidgetNotFoundException)_t;
        if (((i).intValue() == (retries - 1))) {
          throw e;
        }
        String _message = e.getMessage();
        String _plus = ("failed: " + _message);
        InputOutput.<String>println(_plus);
        InputOutput.<String>println("retrying...");
        it.sleep(1000);
      } else {
        throw Exceptions.sneakyThrow(_t);
      }
    }
  }
}
 
Example #6
Source File: GeneratorNodeTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
private StringConcatenationClient someCodeGen(final int n) {
  StringConcatenationClient _client = new StringConcatenationClient() {
    @Override
    protected void appendTo(StringConcatenationClient.TargetStringConcatenation _builder) {
      {
        ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, n, true);
        for(final Integer i : _doubleDotLessThan) {
          _builder.append("before ");
          CompositeGeneratorNode _append = GeneratorNodeTest.this.exts.append(GeneratorNodeTest.this.exts.trace(GeneratorNodeTest.this.loc((10 + (i).intValue()))), "Hello");
          _builder.append(_append);
          _builder.append(" after");
          _builder.newLineIfNotEmpty();
          _builder.append("  ");
          StringConcatenationClient _someCodeGen = GeneratorNodeTest.this.someCodeGen((n - 1));
          _builder.append(_someCodeGen, "  ");
          _builder.newLineIfNotEmpty();
        }
      }
    }
  };
  return _client;
}
 
Example #7
Source File: ResolvedExecutableImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public Iterable<? extends ResolvedParameter> getResolvedParameters() {
  Iterable<? extends ResolvedParameter> _xblockexpression = null;
  {
    if ((this.resolvedParameters == null)) {
      int _size = this.getDelegate().getDeclaration().getParameters().size();
      final Function1<Integer, ResolvedParameterImpl> _function = (Integer i) -> {
        ParameterDeclaration _parameterDeclaration = this.getCompilationUnit().toParameterDeclaration(this.getDelegate().getDeclaration().getParameters().get((i).intValue()));
        TypeReference _typeReference = this.getCompilationUnit().toTypeReference(this.getDelegate().getResolvedParameterTypes().get((i).intValue()));
        return new ResolvedParameterImpl(_parameterDeclaration, _typeReference);
      };
      this.resolvedParameters = IterableExtensions.<Integer, ResolvedParameterImpl>map(new ExclusiveRange(0, _size, true), _function);
    }
    _xblockexpression = this.resolvedParameters;
  }
  return _xblockexpression;
}
 
Example #8
Source File: ExclusiveRangeTest.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testContent() {
	assertEquals("1,2,3,4", join(new ExclusiveRange(1, 5, true), ","));
	assertEquals("", join(new ExclusiveRange(0, 0, true), ","));
	assertEquals("", join(new ExclusiveRange(0, -1, true), ","));
	assertEquals("-1", join(new ExclusiveRange(-1, 0, true), ","));
	assertEquals("4,3,2,1", join(new ExclusiveRange(5, 1, false), ","));
	assertEquals("", join(new ExclusiveRange(0, 0, false), ","));
	assertEquals("", join(new ExclusiveRange(-1, 0, false), ","));
	assertEquals("-1", join(new ExclusiveRange(0, -1, false), ","));
}
 
Example #9
Source File: StateVectorExtensions.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * This function calculates the final state impact vector.
 * This vector is an array of the size of the state machines state vector.
 * Each array slot holds a List of ExecutionState instances that map to FinalState elements
 * in the orginal model. The assignment of a final state to a slot means that if this state is
 * active it has impact on the vector slot. Here two cases have to be distinguished:
 * 
 * 1. The final state is directly assigned to the slot (the states vector offset). If the state is active
 *    then the slot will contain a reference to this state
 * 2. If the parent region contains orthogonal states then all other vector positions covered by the region
 *    are empty (refer to no state) if the state is active so there is an indirect impact on the vector.
 */
public List<ExecutionState>[] finalStateImpactVector(final ExecutionFlow flow) {
  final List<ExecutionState>[] vector = new List[flow.getStateVector().getSize()];
  final Function1<ExecutionState, Boolean> _function = (ExecutionState s) -> {
    EObject _sourceElement = s.getSourceElement();
    return Boolean.valueOf((_sourceElement instanceof FinalState));
  };
  final Consumer<ExecutionState> _function_1 = (ExecutionState fs) -> {
    StateVector regionVector = fs.getSuperScope().getStateVector();
    int _offset = regionVector.getOffset();
    int _offset_1 = regionVector.getOffset();
    int _size = regionVector.getSize();
    int _plus = (_offset_1 + _size);
    ExclusiveRange _doubleDotLessThan = new ExclusiveRange(_offset, _plus, true);
    for (final Integer i : _doubleDotLessThan) {
      {
        List<ExecutionState> _get = vector[(i).intValue()];
        boolean _tripleEquals = (_get == null);
        if (_tripleEquals) {
          ArrayList<ExecutionState> _arrayList = new ArrayList<ExecutionState>();
          vector[(i).intValue()] = _arrayList;
        }
        vector[(i).intValue()].add(fs);
      }
    }
  };
  IterableExtensions.<ExecutionState>filter(flow.getStates(), _function).forEach(_function_1);
  return vector;
}
 
Example #10
Source File: DefaultTaskParserTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private void assertContainsTasks(final CharSequence source, final List<Task> expectedTasks) {
  final List<Task> actualTasks = this.parser.parseTasks(LineDelimiters.toUnix(source.toString()), this.definitions);
  Assert.assertEquals(expectedTasks.size(), actualTasks.size());
  int _size = expectedTasks.size();
  ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _size, true);
  for (final Integer i : _doubleDotLessThan) {
    Assert.assertEquals(expectedTasks.get((i).intValue()), actualTasks.get((i).intValue()));
  }
}
 
Example #11
Source File: DefaultTaskFinderTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private void assertContainsTasks(final Resource resource, final List<Task> expectedTasks) {
  final List<Task> actualTasks = this.finder.findTasks(resource);
  Assert.assertEquals(expectedTasks.size(), actualTasks.size());
  int _size = expectedTasks.size();
  ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _size, true);
  for (final Integer i : _doubleDotLessThan) {
    Assert.assertEquals(expectedTasks.get((i).intValue()), actualTasks.get((i).intValue()));
  }
}
 
Example #12
Source File: XtendTaskFinderTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
private void assertContainsTasks(final Resource resource, final List<Task> expectedTasks) {
  final List<Task> actualTasks = this.finder.findTasks(resource);
  Assert.assertEquals(expectedTasks.size(), actualTasks.size());
  int _size = expectedTasks.size();
  ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _size, true);
  for (final Integer i : _doubleDotLessThan) {
    XtendTaskFinderTest.assertExactMatch(expectedTasks.get((i).intValue()), actualTasks.get((i).intValue()));
  }
}
 
Example #13
Source File: AbstractExecutableBuilder.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected ISourceAppender appendParameters(final ISourceAppender appendable) {
  ISourceAppender _xblockexpression = null;
  {
    appendable.append("(");
    final HashSet<String> notAllowed = CollectionLiterals.<String>newHashSet();
    boolean _isEmpty = this.parameterBuilders.isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
      AbstractParameterBuilder _last = IterableExtensions.<AbstractParameterBuilder>last(this.parameterBuilders);
      _last.setVarArgsFlag(this.varArgsFlag);
    }
    int _size = this.parameterBuilders.size();
    ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _size, true);
    for (final Integer i : _doubleDotLessThan) {
      {
        final AbstractParameterBuilder parameterBuilder = this.parameterBuilders.get((i).intValue());
        final VariableNameAcceptor acceptor = new VariableNameAcceptor(notAllowed);
        String _name = parameterBuilder.getName();
        boolean _tripleEquals = (_name == null);
        if (_tripleEquals) {
          this._jdtVariableCompletions.getVariableProposals(parameterBuilder.getType().getIdentifier(), this.getContext(), 
            JdtVariableCompletions.VariableType.PARAMETER, notAllowed, acceptor);
          parameterBuilder.setName(acceptor.getVariableName());
        }
        parameterBuilder.build(appendable);
        int _size_1 = this.parameterBuilders.size();
        int _minus = (_size_1 - 1);
        boolean _notEquals = ((i).intValue() != _minus);
        if (_notEquals) {
          appendable.append(", ");
        }
      }
    }
    _xblockexpression = appendable.append(")");
  }
  return _xblockexpression;
}
 
Example #14
Source File: ExclusiveRangeTest.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testContains() {
	assertFalse(new ExclusiveRange(1, 5, true).contains(0));
	assertTrue(new ExclusiveRange(1, 5, true).contains(1));
	assertTrue(new ExclusiveRange(1, 5, true).contains(2));
	assertTrue(new ExclusiveRange(1, 5, true).contains(3));
	assertTrue(new ExclusiveRange(1, 5, true).contains(4));
	assertFalse(new ExclusiveRange(1, 5, true).contains(5));

	assertFalse(new ExclusiveRange(0, 0, true).contains(0));

	assertFalse(new ExclusiveRange(0, -1, true).contains(0));
	assertFalse(new ExclusiveRange(0, -1, true).contains(-1));

	assertFalse(new ExclusiveRange(-1, 0, true).contains(-2));
	assertTrue(new ExclusiveRange(-1, 0, true).contains(-1));
	assertFalse(new ExclusiveRange(-1, 0, true).contains(-0));

	assertFalse(new ExclusiveRange(5, 1, false).contains(0));
	assertTrue(new ExclusiveRange(5, 1, false).contains(1));
	assertTrue(new ExclusiveRange(5, 1, false).contains(2));
	assertTrue(new ExclusiveRange(5, 1, false).contains(3));
	assertTrue(new ExclusiveRange(5, 1, false).contains(4));
	assertFalse(new ExclusiveRange(5, 1, false).contains(5));

	assertFalse(new ExclusiveRange(0, 0, false).contains(0));

	assertFalse(new ExclusiveRange(-1, 0, false).contains(0));
	assertFalse(new ExclusiveRange(-1, 0, false).contains(-1));

	assertFalse(new ExclusiveRange(0, -1, false).contains(-2));
	assertTrue(new ExclusiveRange(0, -1, false).contains(-1));
	assertFalse(new ExclusiveRange(0, -1, false).contains(-0));
}
 
Example #15
Source File: ExclusiveRangeTest.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testIsEmpty() {
	assertFalse(new ExclusiveRange(1, 5, true).isEmpty());
	assertTrue(new ExclusiveRange(0, 0, true).isEmpty());
	assertTrue(new ExclusiveRange(0, -1, true).isEmpty());
	assertFalse(new ExclusiveRange(-1, 0, true).isEmpty());
	assertFalse(new ExclusiveRange(5, 1, false).isEmpty());
	assertTrue(new ExclusiveRange(0, 0, false).isEmpty());
	assertTrue(new ExclusiveRange(-1, 0, false).isEmpty());
	assertFalse(new ExclusiveRange(0, -1, false).isEmpty());
}
 
Example #16
Source File: ExclusiveRangeTest.java    From xtext-lib with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testSize() {
	assertEquals(4, new ExclusiveRange(1, 5, true).size());
	assertEquals(0, new ExclusiveRange(0, 0, true).size());
	assertEquals(0, new ExclusiveRange(0, -1, true).size());
	assertEquals(1, new ExclusiveRange(-1, 0, true).size());
	assertEquals(4, new ExclusiveRange(5, 1, false).size());
	assertEquals(0, new ExclusiveRange(0, 0, false).size());
	assertEquals(0, new ExclusiveRange(-1, 0, false).size());
	assertEquals(1, new ExclusiveRange(0, -1, false).size());
}
 
Example #17
Source File: CompilationUnitImpl.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
protected Object translate(final Object object) {
  if ((object instanceof XAnnotation[])) {
    final AnnotationReference[] result = new AnnotationReference[((Object[])object).length];
    int _length = ((Object[])object).length;
    ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _length, true);
    for (final Integer i : _doubleDotLessThan) {
      result[(i).intValue()] = this.translateAnnotation(((XAnnotation[])object)[(i).intValue()]);
    }
    return result;
  }
  if ((object instanceof XAnnotation)) {
    return this.translateAnnotation(((XAnnotation)object));
  }
  if ((object instanceof JvmTypeReference[])) {
    final TypeReference[] result_1 = new TypeReference[((Object[])object).length];
    int _length_1 = ((Object[])object).length;
    ExclusiveRange _doubleDotLessThan_1 = new ExclusiveRange(0, _length_1, true);
    for (final Integer i_1 : _doubleDotLessThan_1) {
      Object _translate = this.translate(((Object[])object)[(i_1).intValue()]);
      result_1[(i_1).intValue()] = ((TypeReference) _translate);
    }
    return result_1;
  }
  if ((object instanceof JvmTypeReference)) {
    return this.toTypeReference(((JvmTypeReference)object));
  }
  if ((object instanceof JvmEnumerationLiteral[])) {
    final EnumerationValueDeclaration[] result_2 = new EnumerationValueDeclaration[((Object[])object).length];
    int _length_2 = ((Object[])object).length;
    ExclusiveRange _doubleDotLessThan_2 = new ExclusiveRange(0, _length_2, true);
    for (final Integer i_2 : _doubleDotLessThan_2) {
      Object _translate_1 = this.translate(((Object[])object)[(i_2).intValue()]);
      result_2[(i_2).intValue()] = ((EnumerationValueDeclaration) _translate_1);
    }
    return result_2;
  }
  if ((object instanceof JvmEnumerationLiteral)) {
    return this.toMemberDeclaration(((JvmMember)object));
  }
  return object;
}
 
Example #18
Source File: SwtBotProjectHelper.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
protected static Pair<Integer, Integer> getLineAndColumn(final String content, final int offset) {
  Pair<Integer, Integer> _xblockexpression = null;
  {
    int line = 0;
    int column = 0;
    String ignoreNext = null;
    ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, offset, true);
    for (final Integer i : _doubleDotLessThan) {
      String _substring = content.substring((i).intValue(), ((i).intValue() + 1));
      boolean _matched = false;
      if (Objects.equal(_substring, ignoreNext)) {
        _matched=true;
        ignoreNext = null;
      }
      if (!_matched) {
        if (Objects.equal(_substring, "\n")) {
          _matched=true;
          column = 0;
          line = (line + 1);
          ignoreNext = "\r";
        }
      }
      if (!_matched) {
        if (Objects.equal(_substring, "\r")) {
          _matched=true;
          column = 0;
          line = (line + 1);
          ignoreNext = "\n";
        }
      }
      if (!_matched) {
        {
          ignoreNext = null;
          column = (column + 1);
        }
      }
    }
    _xblockexpression = Pair.<Integer, Integer>of(Integer.valueOf(line), Integer.valueOf(column));
  }
  return _xblockexpression;
}
 
Example #19
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);
}