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

The following examples show how to use org.eclipse.xtext.xbase.lib.IterableExtensions#findFirst() . 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: JSDocNodeImpl.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public void setMarker(final String theKey, final String value) {
	final Function1<Marker, Boolean> _function = new Function1<Marker, Boolean>() {
		public Boolean apply(final Marker it) {
			String _key = it.getKey();
			String _key_1 = it.getKey();
			return Boolean.valueOf(Objects.equal(_key, _key_1));
		}
	};
	Marker marker = IterableExtensions.<Marker>findFirst(this.getMarkers(), _function);
	if ((marker == null)) {
		marker = DomFactory.eINSTANCE.createMarker();
		marker.setKey(theKey);
		this.getMarkers().add(marker);
	}
	marker.setValue(value);
}
 
Example 2
Source File: Ecore2XtextExtensions.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public static EAttribute idAttribute(final EClass it) {
  EAttribute _xblockexpression = null;
  {
    final EAttribute idAttr = Ecore2XtextExtensions.idAttributeInternal(it);
    EAttribute _xifexpression = null;
    if ((idAttr != null)) {
      _xifexpression = idAttr;
    } else {
      final Function1<EAttribute, Boolean> _function = (EAttribute a) -> {
        return Boolean.valueOf((((Ecore2XtextExtensions.needsAssignment(a) && Objects.equal(a.getName(), "name")) && Objects.equal(a.getEType().getName(), "EString")) && (!a.isMany())));
      };
      _xifexpression = IterableExtensions.<EAttribute>findFirst(it.getEAllAttributes(), _function);
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
 
Example 3
Source File: InsertionOffsets.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected int inEmpty(final XtendTypeDeclaration ownerType) {
  int _xblockexpression = (int) 0;
  {
    final ICompositeNode classNode = NodeModelUtils.findActualNodeFor(ownerType);
    final Function1<ILeafNode, Boolean> _function = (ILeafNode it) -> {
      String _text = it.getText();
      return Boolean.valueOf(Objects.equal(_text, "{"));
    };
    final ILeafNode openingBraceNode = IterableExtensions.<ILeafNode>findFirst(classNode.getLeafNodes(), _function);
    int _xifexpression = (int) 0;
    if ((openingBraceNode != null)) {
      int _offset = openingBraceNode.getOffset();
      _xifexpression = (_offset + 1);
    } else {
      _xifexpression = classNode.getEndOffset();
    }
    _xblockexpression = _xifexpression;
  }
  return _xblockexpression;
}
 
Example 4
Source File: JvmTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public ConstructorDeclaration findDeclaredConstructor(final TypeReference... parameterTypes) {
  ConstructorDeclaration _xblockexpression = null;
  {
    ConditionUtils.checkIterable(((Iterable<?>)Conversions.doWrapArray(parameterTypes)), "parameterTypes");
    final Function1<ConstructorDeclaration, Boolean> _function = (ConstructorDeclaration constructor) -> {
      final Function1<ParameterDeclaration, TypeReference> _function_1 = (ParameterDeclaration it) -> {
        return it.getType();
      };
      List<TypeReference> _list = IterableExtensions.<TypeReference>toList(IterableExtensions.map(constructor.getParameters(), _function_1));
      List<TypeReference> _list_1 = IterableExtensions.<TypeReference>toList(((Iterable<TypeReference>)Conversions.doWrapArray(parameterTypes)));
      return Boolean.valueOf(Objects.equal(_list, _list_1));
    };
    _xblockexpression = IterableExtensions.findFirst(this.getDeclaredConstructors(), _function);
  }
  return _xblockexpression;
}
 
Example 5
Source File: JvmTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public MutableConstructorDeclaration addConstructor(final Procedure1<MutableConstructorDeclaration> initializer) {
  this.checkMutable();
  Preconditions.checkArgument((initializer != null), "initializer cannot be null");
  final Function1<JvmConstructor, Boolean> _function = (JvmConstructor it) -> {
    return Boolean.valueOf(this.getCompilationUnit().getTypeExtensions().isSingleSyntheticDefaultConstructor(it));
  };
  final JvmConstructor constructor = IterableExtensions.<JvmConstructor>findFirst(Iterables.<JvmConstructor>filter(this.getDelegate().getMembers(), JvmConstructor.class), _function);
  if ((constructor != null)) {
    EcoreUtil.remove(constructor);
  }
  final JvmConstructor newConstructor = TypesFactory.eINSTANCE.createJvmConstructor();
  newConstructor.setVisibility(JvmVisibility.PUBLIC);
  newConstructor.setSimpleName(this.getSimpleName());
  this.getDelegate().getMembers().add(newConstructor);
  MemberDeclaration _memberDeclaration = this.getCompilationUnit().toMemberDeclaration(newConstructor);
  final MutableConstructorDeclaration mutableConstructorDeclaration = ((MutableConstructorDeclaration) _memberDeclaration);
  initializer.apply(mutableConstructorDeclaration);
  return mutableConstructorDeclaration;
}
 
Example 6
Source File: MutableJvmClassDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void setExtendedClass(final TypeReference superclass) {
  this.checkMutable();
  ConditionUtils.checkInferredTypeReferences("extended class", superclass);
  JvmTypeReference _xifexpression = null;
  if ((superclass != null)) {
    _xifexpression = this.getCompilationUnit().toJvmTypeReference(superclass);
  } else {
    _xifexpression = this.getCompilationUnit().getTypeReferences().getTypeForName(Object.class, this.getCompilationUnit().getXtendFile());
  }
  final JvmTypeReference newTypeRef = _xifexpression;
  final Function1<JvmTypeReference, Boolean> _function = (JvmTypeReference it) -> {
    return Boolean.valueOf(((it.getType() instanceof JvmGenericType) && (!((JvmGenericType) it.getType()).isInterface())));
  };
  final JvmTypeReference oldType = IterableExtensions.<JvmTypeReference>findFirst(this.getDelegate().getSuperTypes(), _function);
  if ((oldType != null)) {
    this.getDelegate().getSuperTypes().remove(oldType);
  }
  this.getDelegate().getSuperTypes().add(newTypeRef);
}
 
Example 7
Source File: DocumentSymbolService.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public List<Either<SymbolInformation, DocumentSymbol>> getSymbols(XtextResource resource,
		CancelIndicator cancelIndicator) {
	String uri = uriExtensions.toUriString(resource.getURI());
	ArrayList<SymbolInformation> infos = new ArrayList<>();
	List<DocumentSymbol> rootSymbols = Lists
			.transform(hierarchicalDocumentSymbolService.getSymbols(resource, cancelIndicator), Either::getRight);
	for (DocumentSymbol rootSymbol : rootSymbols) {
		Iterable<DocumentSymbol> symbols = Traverser.forTree(DocumentSymbol::getChildren)
				.depthFirstPreOrder(rootSymbol);
		Function1<? super DocumentSymbol, ? extends String> containerNameProvider = (DocumentSymbol symbol) -> {
			DocumentSymbol firstSymbol = IterableExtensions.findFirst(symbols, (DocumentSymbol it) -> {
				return it != symbol && !IterableExtensions.isNullOrEmpty(it.getChildren())
						&& it.getChildren().contains(symbol);
			});
			if (firstSymbol != null) {
				return firstSymbol.getName();
			}
			return null;
		};
		for (DocumentSymbol s : symbols) {
			infos.add(createSymbol(uri, s, containerNameProvider));
		}
	}
	return Lists.transform(infos, Either::forLeft);
}
 
Example 8
Source File: AnnotationReferenceBuildContextImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected JvmOperation findOperation(final String name) {
  ConditionUtils.checkJavaIdentifier(name, "name");
  final JvmAnnotationType annotationType = this.delegate.getAnnotation();
  final Function1<JvmOperation, Boolean> _function = (JvmOperation it) -> {
    String _simpleName = it.getSimpleName();
    return Boolean.valueOf(Objects.equal(_simpleName, name));
  };
  final JvmOperation jvmOperation = IterableExtensions.<JvmOperation>findFirst(annotationType.getDeclaredOperations(), _function);
  if ((jvmOperation == null)) {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("The annotation property \'");
    _builder.append(name);
    _builder.append("\' is not declared on the annotation type \'");
    String _identifier = annotationType.getIdentifier();
    _builder.append(_identifier);
    _builder.append("\'.");
    throw new IllegalArgumentException(_builder.toString());
  }
  return jvmOperation;
}
 
Example 9
Source File: XtendAnnotationReferenceImpl.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
protected XExpression findValue(final String property) {
  XExpression _xblockexpression = null;
  {
    if ((Objects.equal(property, "value") && (this.getDelegate().getValue() != null))) {
      return this.getDelegate().getValue();
    }
    final Function1<XAnnotationElementValuePair, Boolean> _function = (XAnnotationElementValuePair it) -> {
      String _simpleName = it.getElement().getSimpleName();
      return Boolean.valueOf(Objects.equal(_simpleName, property));
    };
    XAnnotationElementValuePair _findFirst = IterableExtensions.<XAnnotationElementValuePair>findFirst(this.getDelegate().getElementValuePairs(), _function);
    XExpression _value = null;
    if (_findFirst!=null) {
      _value=_findFirst.getValue();
    }
    _xblockexpression = _value;
  }
  return _xblockexpression;
}
 
Example 10
Source File: JvmClassDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public MethodDeclaration findDeclaredMethod(final String name, final TypeReference... parameterTypes) {
  MethodDeclaration _xblockexpression = null;
  {
    ConditionUtils.checkIterable(((Iterable<?>)Conversions.doWrapArray(parameterTypes)), "parameterTypes");
    final Function1<MethodDeclaration, Boolean> _function = (MethodDeclaration it) -> {
      return Boolean.valueOf((Objects.equal(it.getSimpleName(), name) && Objects.equal(IterableExtensions.<TypeReference>toList(IterableExtensions.map(it.getParameters(), ((Function1<ParameterDeclaration, TypeReference>) (ParameterDeclaration it_1) -> {
        return it_1.getType();
      }))), IterableExtensions.<TypeReference>toList(((Iterable<TypeReference>)Conversions.doWrapArray(parameterTypes))))));
    };
    _xblockexpression = IterableExtensions.<MethodDeclaration>findFirst(Iterables.<MethodDeclaration>filter(this.getDeclaredMembers(), MethodDeclaration.class), _function);
  }
  return _xblockexpression;
}
 
Example 11
Source File: InlineTagImpl.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public TagValue getValueByKey(final String theKey) {
	final Function1<TagValue, Boolean> _function = new Function1<TagValue, Boolean>() {
		public Boolean apply(final TagValue it) {
			String _key = it.getKey();
			return Boolean.valueOf(Objects.equal(_key, theKey));
		}
	};
	return IterableExtensions.<TagValue>findFirst(this.getValues(), _function);
}
 
Example 12
Source File: TagImpl.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public TagValue getValueByKey(final String theKey) {
	final Function1<TagValue, Boolean> _function = new Function1<TagValue, Boolean>() {
		public Boolean apply(final TagValue it) {
			String _key = it.getKey();
			return Boolean.valueOf(Objects.equal(_key, theKey));
		}
	};
	return IterableExtensions.<TagValue>findFirst(this.getValues(), _function);
}
 
Example 13
Source File: SwitchStatementImpl.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
@Override
public DefaultClause getDefaultClause() {
	final Function1<AbstractCaseClause, Boolean> _function = new Function1<AbstractCaseClause, Boolean>() {
		public Boolean apply(final AbstractCaseClause it) {
			return Boolean.valueOf((it instanceof DefaultClause));
		}
	};
	AbstractCaseClause _findFirst = IterableExtensions.<AbstractCaseClause>findFirst(this.getCases(), _function);
	return ((DefaultClause) _findFirst);
}
 
Example 14
Source File: WizardConfigurationTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void inlinedTestProjectsDontOverrideMainSources() {
	config.getRuntimeProject().getTestProject().setEnabled(true);
	config.setPreferredBuildSystem(BuildSystem.MAVEN);
	config.setSourceLayout(SourceLayout.MAVEN);
	AbstractFile pom = IterableExtensions.findFirst(config.getRuntimeProject().getFiles(),
			(AbstractFile it) -> "pom.xml".equals(it.getRelativePath()));
	assertTrue(pom instanceof PomFile);
	assertTrue(((PomFile) pom).getContent().toString().contains("<artifactId>org.example.mydsl</artifactId>"));
}
 
Example 15
Source File: JvmAnnotationTargetImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public AnnotationReference findAnnotation(final Type annotationType) {
  final Function1<AnnotationReference, Boolean> _function = (AnnotationReference it) -> {
    AnnotationTypeDeclaration _annotationTypeDeclaration = it.getAnnotationTypeDeclaration();
    return Boolean.valueOf(Objects.equal(_annotationTypeDeclaration, annotationType));
  };
  return IterableExtensions.findFirst(this.getAnnotations(), _function);
}
 
Example 16
Source File: XtendAnnotationTargetImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public AnnotationReference findAnnotation(final Type annotationType) {
  final Function1<AnnotationReference, Boolean> _function = (AnnotationReference it) -> {
    AnnotationTypeDeclaration _annotationTypeDeclaration = it.getAnnotationTypeDeclaration();
    return Boolean.valueOf(Objects.equal(_annotationTypeDeclaration, annotationType));
  };
  return IterableExtensions.findFirst(this.getAnnotations(), _function);
}
 
Example 17
Source File: JvmEnumerationTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public EnumerationValueDeclaration findDeclaredValue(final String name) {
  final Function1<EnumerationValueDeclaration, Boolean> _function = (EnumerationValueDeclaration value) -> {
    String _simpleName = value.getSimpleName();
    return Boolean.valueOf(Objects.equal(_simpleName, name));
  };
  return IterableExtensions.findFirst(this.getDeclaredValues(), _function);
}
 
Example 18
Source File: JvmAnnotationTypeDeclarationImpl.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public AnnotationTypeElementDeclaration findDeclaredAnnotationTypeElement(final String name) {
  final Function1<AnnotationTypeElementDeclaration, Boolean> _function = (AnnotationTypeElementDeclaration it) -> {
    String _simpleName = it.getSimpleName();
    return Boolean.valueOf(Objects.equal(_simpleName, name));
  };
  return IterableExtensions.findFirst(this.getDeclaredAnnotationTypeElements(), _function);
}
 
Example 19
Source File: AbstractQueuedBuildDataTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public Collection<? extends IResourceDescription.Delta> assertThereAreDeltas(final Collection<? extends IResourceDescription.Delta> deltas, final String... expectedExportedNames) {
  Collection<? extends IResourceDescription.Delta> _xblockexpression = null;
  {
    int _size = deltas.size();
    boolean _notEquals = (0 != _size);
    Assert.assertTrue("There are not deltas", _notEquals);
    int _length = expectedExportedNames.length;
    boolean _notEquals_1 = (_length != 0);
    if (_notEquals_1) {
      final HashSet<String> remainingExportedNames = CollectionLiterals.<String>newHashSet(expectedExportedNames);
      final HashSet<String> unexpectedExportedNames = CollectionLiterals.<String>newHashSet();
      HashSet<String> _exportedNames = this.getExportedNames(deltas);
      for (final String exportedName : _exportedNames) {
        {
          final Function1<String, Boolean> _function = (String it) -> {
            return Boolean.valueOf(Objects.equal(exportedName, it));
          };
          final String qualifiedName = IterableExtensions.<String>findFirst(((Iterable<String>)Conversions.doWrapArray(expectedExportedNames)), _function);
          if ((qualifiedName == null)) {
            unexpectedExportedNames.add(exportedName);
          } else {
            remainingExportedNames.remove(qualifiedName);
          }
        }
      }
      StringConcatenation _builder = new StringConcatenation();
      _builder.append("There are unexpected exported names: ");
      _builder.append(unexpectedExportedNames);
      Assert.assertEquals(_builder.toString(), 0, 
        ((Object[])Conversions.unwrapArray(unexpectedExportedNames, Object.class)).length);
      StringConcatenation _builder_1 = new StringConcatenation();
      _builder_1.append("There are not expected exported names ");
      _builder_1.append(remainingExportedNames);
      Assert.assertEquals(_builder_1.toString(), 0, 
        ((Object[])Conversions.unwrapArray(remainingExportedNames, Object.class)).length);
    }
    _xblockexpression = deltas;
  }
  return _xblockexpression;
}
 
Example 20
Source File: CheckCfgUtil.java    From dsl-devkit with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Retrieves an {@link ICheckCfgPropertySpecification} contribution from the checkcfg property extension point by name.
 *
 * @param propertyName
 *          the name of the property, must not be {@code null}
 * @return the {@link ICheckCfgPropertySpecification} or {@code null}
 */
public static ICheckCfgPropertySpecification getPropertySpecification(final String propertyName) {
  return IterableExtensions.findFirst(getAllPropertyContributions(), contribution -> propertyName.equalsIgnoreCase(contribution.getName()));
}