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

The following examples show how to use org.eclipse.xtext.xbase.lib.IterableExtensions#isEmpty() . 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: TracedAccessorsProcessor.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public boolean isSupportedGetter(final ResolvedMethod it) {
  boolean _isEmpty = IterableExtensions.isEmpty(it.getDeclaration().getParameters());
  boolean _not = (!_isEmpty);
  if (_not) {
    return false;
  }
  boolean _isStatic = it.getDeclaration().isStatic();
  if (_isStatic) {
    return false;
  }
  final String n = it.getDeclaration().getSimpleName();
  String _qualifiedName = it.getDeclaration().getDeclaringType().getQualifiedName();
  String _name = Object.class.getName();
  boolean _equals = Objects.equal(_qualifiedName, _name);
  if (_equals) {
    return false;
  }
  return (n.startsWith("get") || n.startsWith("is"));
}
 
Example 2
Source File: ASTFlattenerUtils.java    From xtext-xtend with Eclipse Public License 2.0 6 votes vote down vote up
public boolean canConvertToRichText(final InfixExpression node) {
  final FieldDeclaration parentFieldDecl = this.<FieldDeclaration>findParentOfType(node, FieldDeclaration.class);
  if ((parentFieldDecl != null)) {
    final TypeDeclaration typeDeclr = this.<TypeDeclaration>findParentOfType(parentFieldDecl, TypeDeclaration.class);
    if ((typeDeclr.isInterface() || (this.isFinal(parentFieldDecl.modifiers()) && this.isStatic(parentFieldDecl.modifiers())))) {
      return false;
    }
  }
  final SingleMemberAnnotation parentSingleMemberAnnotation = this.<SingleMemberAnnotation>findParentOfType(node, SingleMemberAnnotation.class);
  if ((parentSingleMemberAnnotation != null)) {
    return false;
  }
  final Iterable<StringLiteral> nodes = this.collectCompatibleNodes(node);
  return ((!IterableExtensions.isEmpty(nodes)) && IterableExtensions.<StringLiteral>forall(nodes, ((Function1<StringLiteral, Boolean>) (StringLiteral it) -> {
    return Boolean.valueOf(this.canTranslate(it));
  })));
}
 
Example 3
Source File: Ecore2XtextExtensions.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public static boolean needsDispatcherRule(final EClassifier eClassifier) {
  boolean _switchResult = false;
  boolean _matched = false;
  if (eClassifier instanceof EClass) {
    _matched=true;
    final Function1<EClass, Boolean> _function = (EClass c) -> {
      return Boolean.valueOf(Ecore2XtextExtensions.needsConcreteRule(c));
    };
    boolean _isEmpty = IterableExtensions.isEmpty(IterableExtensions.<EClass>filter(Ecore2XtextExtensions.subClasses(((EClass)eClassifier)), _function));
    _switchResult = (!_isEmpty);
  }
  if (!_matched) {
    _switchResult = false;
  }
  return _switchResult;
}
 
Example 4
Source File: TypeReference.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private static String getPackageName(final String qualifiedName, final boolean strict) {
  final List<String> segments = IterableExtensions.<String>toList(Splitter.on(".").split(qualifiedName));
  int _size = segments.size();
  boolean _equals = (_size == 1);
  if (_equals) {
    return "";
  }
  if (strict) {
    int _length = ((Object[])Conversions.unwrapArray(segments, Object.class)).length;
    int _minus = (_length - 1);
    final List<String> packageSegments = segments.subList(0, _minus);
    final Function1<String, Boolean> _function = (String it) -> {
      return Boolean.valueOf(Character.isUpperCase(it.charAt(0)));
    };
    boolean _isEmpty = IterableExtensions.isEmpty(IterableExtensions.<String>filter(packageSegments, _function));
    boolean _not = (!_isEmpty);
    if (_not) {
      throw new IllegalArgumentException((("Cannot determine the package name of \'" + qualifiedName) + "\'. Please use the TypeReference(packageName, className) constructor"));
    }
    return IterableExtensions.join(packageSegments, ".");
  } else {
    int _length_1 = ((Object[])Conversions.unwrapArray(segments, Object.class)).length;
    int _minus_1 = (_length_1 - 1);
    List<String> packageSegments_1 = segments.subList(0, _minus_1);
    while ((!packageSegments_1.isEmpty())) {
      boolean _isUpperCase = Character.isUpperCase(IterableExtensions.<String>last(packageSegments_1).charAt(0));
      if (_isUpperCase) {
        final List<String> _converted_packageSegments_1 = (List<String>)packageSegments_1;
        int _length_2 = ((Object[])Conversions.unwrapArray(_converted_packageSegments_1, Object.class)).length;
        int _minus_2 = (_length_2 - 1);
        packageSegments_1 = packageSegments_1.subList(0, _minus_2);
      } else {
        return IterableExtensions.join(packageSegments_1, ".");
      }
    }
    return "";
  }
}
 
Example 5
Source File: ProjectDescriptor.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private String buildPropertiesEntry(final String key, final Iterable<String> value) {
  String _xblockexpression = null;
  {
    boolean _isEmpty = IterableExtensions.isEmpty(value);
    if (_isEmpty) {
      return "";
    }
    final String assignment = (key + " = ");
    final String indent = Strings.repeat(" ", assignment.length());
    String _join = IterableExtensions.join(value, (",\\\n" + indent));
    _xblockexpression = (assignment + _join);
  }
  return _xblockexpression;
}
 
Example 6
Source File: ASTFlattenerUtils.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public Boolean isAssignedInBody(final Block scope, final SimpleName nameToLookFor) {
  final Function1<Expression, Boolean> _function = (Expression it) -> {
    Expression simpleName = null;
    boolean _matched = false;
    if (it instanceof Assignment) {
      _matched=true;
      simpleName = ((Assignment)it).getLeftHandSide();
    }
    if (!_matched) {
      if (it instanceof PrefixExpression) {
        _matched=true;
        simpleName = ((PrefixExpression)it).getOperand();
      }
    }
    if (!_matched) {
      if (it instanceof PostfixExpression) {
        _matched=true;
        simpleName = ((PostfixExpression)it).getOperand();
      }
    }
    if ((simpleName instanceof SimpleName)) {
      return Boolean.valueOf(((simpleName != null) && nameToLookFor.getIdentifier().equals(((SimpleName)simpleName).getIdentifier())));
    }
    return Boolean.valueOf(false);
  };
  boolean _isEmpty = IterableExtensions.isEmpty(this.findAssignmentsInBlock(scope, _function));
  return Boolean.valueOf((!_isEmpty));
}
 
Example 7
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) {
  boolean _isEmpty = IterableExtensions.isEmpty(iterable);
  if (_isEmpty) {
    return;
  } else {
    this.visitAll(iterable, null);
  }
}
 
Example 8
Source File: JavaASTFlattener.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public boolean visit(final VariableDeclarationStatement it) {
  boolean _isEmpty = IterableExtensions.isEmpty(Iterables.<Annotation>filter(it.modifiers(), Annotation.class));
  final boolean hasAnnotations = (!_isEmpty);
  final Consumer<VariableDeclarationFragment> _function = (VariableDeclarationFragment frag) -> {
    if (hasAnnotations) {
      this.appendToBuffer("/*FIXME Cannot add Annotation to Variable declaration. Java code: ");
    }
    final Function1<ASTNode, StringBuffer> _function_1 = (ASTNode it_1) -> {
      StringBuffer _xifexpression = null;
      if (hasAnnotations) {
        StringBuffer _xblockexpression = null;
        {
          this.appendToBuffer("*/");
          _xblockexpression = this.appendLineWrapToBuffer();
        }
        _xifexpression = _xblockexpression;
      }
      return _xifexpression;
    };
    this.appendModifiers(it, it.modifiers(), _function_1);
    this.appendToBuffer(this._aSTFlattenerUtils.handleVariableDeclaration(it.modifiers()));
    this.appendSpaceToBuffer();
    boolean _isMissingType = this.isMissingType(it.getType());
    boolean _not = (!_isMissingType);
    if (_not) {
      it.getType().accept(this);
    }
    this.appendExtraDimensions(frag.getExtraDimensions());
    this.appendSpaceToBuffer();
    frag.accept(this);
    this.appendSpaceToBuffer();
  };
  it.fragments().forEach(_function);
  return false;
}
 
Example 9
Source File: IssueAcceptor.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Convert the given issues to diagnostics. Does not return issues in files that are neither in the workspace nor
 * currently opened in the editor. Does not return any issue with severity {@link Severity#IGNORE ignore}.
 */
protected List<Diagnostic> toDiagnostics(Iterable<? extends LSPIssue> issues) {
	if (IterableExtensions.isEmpty(issues)) {
		return Collections.emptyList();
	}

	List<Diagnostic> sortedDiags = new ArrayList<>();
	for (LSPIssue issue : issues) {
		if (issue.getSeverity() != Severity.IGNORE) {
			sortedDiags.add(diagnosticIssueConverter.toDiagnostic(issue));
		}
	}

	// Sort issues according to line and position
	final Comparator<Diagnostic> comparator = new Comparator<>() {
		@Override
		public int compare(Diagnostic d1, Diagnostic d2) {
			Position p1 = d1.getRange().getStart();
			Position p2 = d2.getRange().getStart();
			int result = ComparisonChain.start()
					.compare(p1.getLine(), p2.getLine())
					.compare(p2.getCharacter(), p2.getCharacter())
					.result();
			return result;
		}
	};

	Collections.sort(sortedDiags, comparator);

	return sortedDiags;
}
 
Example 10
Source File: ProjectDescriptor.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private String manifestEntry(final String key, final Iterable<String> value) {
  boolean _isEmpty = IterableExtensions.isEmpty(value);
  if (_isEmpty) {
    return "";
  }
  StringConcatenation _builder = new StringConcatenation();
  _builder.append(key);
  _builder.append(": ");
  String _join = IterableExtensions.join(value, ",\n ");
  _builder.append(_join);
  return _builder.toString();
}
 
Example 11
Source File: XImportSectionValidationTest.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
public void assertFeatureCallError(final XtendFile file, final EClass objectType) {
  final Resource resource = file.eResource();
  final List<Issue> allIssues = this._validationTestHelper.validate(resource);
  final Function1<Issue, Boolean> _function = (Issue it) -> {
    EObject object = resource.getResourceSet().getEObject(it.getUriToProblem(), true);
    final boolean featureCall = ArrayExtensions.contains(it.getData(), UnresolvedFeatureCallTypeAwareMessageProvider.FEATURE_CALL);
    return Boolean.valueOf((((Objects.equal(it.getCode(), Diagnostic.LINKING_DIAGNOSTIC) && (it.getSeverity() == Severity.ERROR)) && 
      objectType.isInstance(object)) && featureCall));
  };
  final Iterable<Issue> match = IterableExtensions.<Issue>filter(allIssues, _function);
  boolean _isEmpty = IterableExtensions.isEmpty(match);
  if (_isEmpty) {
    Assert.fail("No Diagnostic.LINKING_DIAGNOSTIC issue with user data FEATURE_CALL found");
  }
}
 
Example 12
Source File: Ecore2XtextExtensions.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public static boolean onlyOptionalFeatures(final EClass it) {
  boolean _xblockexpression = false;
  {
    Iterable<EStructuralFeature> _prefixFeatures = Ecore2XtextExtensions.prefixFeatures(it);
    Iterable<EStructuralFeature> _inlinedFeatures = Ecore2XtextExtensions.inlinedFeatures(it);
    final Iterable<EStructuralFeature> features = Iterables.<EStructuralFeature>concat(_prefixFeatures, _inlinedFeatures);
    final Function1<EStructuralFeature, Boolean> _function = (EStructuralFeature f) -> {
      return Boolean.valueOf(f.isRequired());
    };
    _xblockexpression = IterableExtensions.isEmpty(IterableExtensions.<EStructuralFeature>filter(features, _function));
  }
  return _xblockexpression;
}
 
Example 13
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Returns the errors that are produced for elements that are directly contained
 * in this feature (e.g. unresolved type proxies) or that are associated with
 * the expression that may be logically contained in the given feature.
 */
private Iterable<Issue> getDirectErrorsOrLogicallyContainedErrors(final JvmFeature feature) {
  Iterable<Issue> errors = this._errorSafeExtensions.getErrors(feature);
  boolean _isEmpty = IterableExtensions.isEmpty(errors);
  if (_isEmpty) {
    final XExpression expression = this._iLogicalContainerProvider.getAssociatedExpression(feature);
    if ((expression != null)) {
      errors = this._errorSafeExtensions.getErrors(expression);
    }
  }
  return errors;
}
 
Example 14
Source File: FinalFieldsConstructorProcessor.java    From xtext-lib with Eclipse Public License 2.0 4 votes vote down vote up
public boolean needsFinalFieldConstructor(final MutableClassDeclaration it) {
  return ((!this.hasFinalFieldsConstructor(it)) && IterableExtensions.isEmpty(((ClassDeclaration) this.context.getPrimarySourceElement(it)).getDeclaredConstructors()));
}
 
Example 15
Source File: AntlrGrammarGenerator.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
@Override
protected String compileParserImports(final Grammar it, final AntlrOptions options) {
  StringConcatenation _builder = new StringConcatenation();
  _builder.newLine();
  _builder.append("import org.eclipse.xtext.*;");
  _builder.newLine();
  _builder.append("import org.eclipse.xtext.parser.*;");
  _builder.newLine();
  _builder.append("import org.eclipse.xtext.parser.impl.*;");
  _builder.newLine();
  _builder.append("import org.eclipse.emf.ecore.util.EcoreUtil;");
  _builder.newLine();
  _builder.append("import org.eclipse.emf.ecore.EObject;");
  _builder.newLine();
  {
    boolean _isEmpty = GrammarUtil.allEnumRules(it).isEmpty();
    boolean _not = (!_isEmpty);
    if (_not) {
      _builder.append("import org.eclipse.emf.common.util.Enumerator;");
      _builder.newLine();
    }
  }
  _builder.append("import ");
  String _name = this.getGrammarNaming().getInternalParserSuperClass(it).getName();
  _builder.append(_name);
  _builder.append(";");
  _builder.newLineIfNotEmpty();
  _builder.append("import org.eclipse.xtext.parser.antlr.XtextTokenStream;");
  _builder.newLine();
  _builder.append("import org.eclipse.xtext.parser.antlr.XtextTokenStream.HiddenTokens;");
  _builder.newLine();
  {
    if (((!IterableExtensions.isEmpty(Iterables.<UnorderedGroup>filter((Iterables.<EObject>concat(ListExtensions.<ParserRule, List<EObject>>map(GrammarUtil.allParserRules(it), ((Function1<ParserRule, List<EObject>>) (ParserRule it_1) -> {
      return EcoreUtil2.eAllContentsAsList(it_1);
    })))), UnorderedGroup.class))) && options.isBacktrack())) {
      _builder.append("import org.eclipse.xtext.parser.antlr.IUnorderedGroupHelper.UnorderedGroupState;");
      _builder.newLine();
    }
  }
  _builder.append("import org.eclipse.xtext.parser.antlr.AntlrDatatypeRuleToken;");
  _builder.newLine();
  _builder.append("import ");
  String _name_1 = this._grammarAccessExtensions.getGrammarAccess(it).getName();
  _builder.append(_name_1);
  _builder.append(";");
  _builder.newLineIfNotEmpty();
  _builder.newLine();
  return _builder.toString();
}
 
Example 16
Source File: ASTFlattenerUtils.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public boolean isPackageVisibility(final Iterable<Modifier> modifier) {
  final Function1<Modifier, Boolean> _function = (Modifier it) -> {
    return Boolean.valueOf(((it.isPublic() || it.isPrivate()) || it.isProtected()));
  };
  return IterableExtensions.isEmpty(IterableExtensions.<Modifier>filter(modifier, _function));
}
 
Example 17
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public void generateExecutableBody(final JvmExecutable op, final ITreeAppendable appendable, final GeneratorConfig config) {
  Procedure1<? super ITreeAppendable> _compilationStrategy = this._jvmTypeExtensions.getCompilationStrategy(op);
  boolean _tripleNotEquals = (_compilationStrategy != null);
  if (_tripleNotEquals) {
    Iterable<Issue> errors = this.getDirectErrorsOrLogicallyContainedErrors(op);
    boolean _isEmpty = IterableExtensions.isEmpty(errors);
    if (_isEmpty) {
      appendable.increaseIndentation().append("{").newLine();
      this._jvmTypeExtensions.getCompilationStrategy(op).apply(appendable);
      appendable.decreaseIndentation().newLine().append("}");
    } else {
      this.generateBodyWithIssues(op, appendable, errors);
    }
  } else {
    StringConcatenationClient _compilationTemplate = this._jvmTypeExtensions.getCompilationTemplate(op);
    boolean _tripleNotEquals_1 = (_compilationTemplate != null);
    if (_tripleNotEquals_1) {
      final Iterable<Issue> errors_1 = this.getDirectErrorsOrLogicallyContainedErrors(op);
      boolean _isEmpty_1 = IterableExtensions.isEmpty(errors_1);
      if (_isEmpty_1) {
        appendable.increaseIndentation().append("{").newLine();
        this.appendCompilationTemplate(appendable, op);
        appendable.decreaseIndentation().newLine().append("}");
      } else {
        this.generateBodyWithIssues(op, appendable, errors_1);
      }
    } else {
      final XExpression expression = this._iLogicalContainerProvider.getAssociatedExpression(op);
      if (((expression != null) && config.isGenerateExpressions())) {
        final Iterable<Issue> errors_2 = this._errorSafeExtensions.getErrors(expression);
        boolean _isEmpty_2 = IterableExtensions.isEmpty(errors_2);
        if (_isEmpty_2) {
          JvmTypeReference _switchResult = null;
          boolean _matched = false;
          if (op instanceof JvmOperation) {
            _matched=true;
            _switchResult = ((JvmOperation)op).getReturnType();
          }
          if (!_matched) {
            if (op instanceof JvmConstructor) {
              _matched=true;
              _switchResult = this._typeReferences.getTypeForName(Void.TYPE, op);
            }
          }
          if (!_matched) {
            _switchResult = null;
          }
          final JvmTypeReference returnType = _switchResult;
          appendable.append("{").increaseIndentation();
          this.compile(op, expression, returnType, appendable, config);
          appendable.decreaseIndentation().newLine().append("}");
        } else {
          this.generateBodyWithIssues(op, appendable, errors_2);
        }
      } else {
        if ((op instanceof JvmOperation)) {
          appendable.increaseIndentation().append("{").newLine();
          appendable.append("throw new UnsupportedOperationException(\"");
          appendable.append(((JvmOperation)op).getSimpleName());
          appendable.append(" is not implemented\");");
          appendable.decreaseIndentation().newLine().append("}");
        } else {
          if ((op instanceof JvmConstructor)) {
            appendable.append("{").newLine().append("}");
          }
        }
      }
    }
  }
}
 
Example 18
Source File: ASTFlattenerUtils.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public Boolean isAssignedInBody(final Block scope, final VariableDeclarationFragment fieldDeclFragment) {
  boolean _isEmpty = IterableExtensions.isEmpty(this.findAssignmentsInBlock(scope, fieldDeclFragment));
  return Boolean.valueOf((!_isEmpty));
}
 
Example 19
Source File: JvmModelGenerator.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public void generateInitialization(final JvmField it, final ITreeAppendable appendable, final GeneratorConfig config) {
  Procedure1<? super ITreeAppendable> _compilationStrategy = this._jvmTypeExtensions.getCompilationStrategy(it);
  boolean _tripleNotEquals = (_compilationStrategy != null);
  if (_tripleNotEquals) {
    final Iterable<Issue> errors = this.getDirectErrorsOrLogicallyContainedErrors(it);
    boolean _isEmpty = IterableExtensions.isEmpty(errors);
    if (_isEmpty) {
      appendable.append(" = ");
      appendable.increaseIndentation();
      this._jvmTypeExtensions.getCompilationStrategy(it).apply(appendable);
      appendable.decreaseIndentation();
    } else {
      appendable.append(" /* Skipped initializer because of errors */");
    }
  } else {
    StringConcatenationClient _compilationTemplate = this._jvmTypeExtensions.getCompilationTemplate(it);
    boolean _tripleNotEquals_1 = (_compilationTemplate != null);
    if (_tripleNotEquals_1) {
      final Iterable<Issue> errors_1 = this.getDirectErrorsOrLogicallyContainedErrors(it);
      boolean _isEmpty_1 = IterableExtensions.isEmpty(errors_1);
      if (_isEmpty_1) {
        appendable.append(" = ").increaseIndentation();
        this.appendCompilationTemplate(appendable, it);
        appendable.decreaseIndentation();
      } else {
        appendable.append(" /* Skipped initializer because of errors */");
      }
    } else {
      final XExpression expression = this._iLogicalContainerProvider.getAssociatedExpression(it);
      if (((expression != null) && config.isGenerateExpressions())) {
        boolean _hasErrors = this._errorSafeExtensions.hasErrors(expression);
        if (_hasErrors) {
          appendable.append(" /* Skipped initializer because of errors */");
        } else {
          appendable.append(" = ");
          this.compiler.compileAsJavaExpression(expression, appendable, it.getType());
        }
      }
    }
  }
}
 
Example 20
Source File: ErrorSafeExtensions.java    From xtext-extras with Eclipse Public License 2.0 4 votes vote down vote up
public boolean hasErrors(EObject element) {
	return !IterableExtensions.isEmpty(getErrors(element));
}