Java Code Examples for org.eclipse.xtext.xbase.lib.CollectionLiterals#newHashMap()

The following examples show how to use org.eclipse.xtext.xbase.lib.CollectionLiterals#newHashMap() . 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: EMFGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
private Map<String, EPackage> findEPackagesInGenPackages(final Collection<String> packageNsURIs, final ResourceSet resourceSet) {
  final HashMap<String, EPackage> result = CollectionLiterals.<String, EPackage>newHashMap();
  for (final String nsURI : packageNsURIs) {
    {
      final Resource resource = GenModelUtil2.getGenModelResource(null, nsURI, resourceSet);
      if ((resource != null)) {
        final GenModel loadedGenModel = IterableExtensions.<GenModel>head(Iterables.<GenModel>filter(resource.getContents(), GenModel.class));
        if ((loadedGenModel != null)) {
          final GenPackage genPackage = this.findGenPackageByNsURI(loadedGenModel, nsURI);
          result.put(nsURI, genPackage.getEcorePackage());
        }
      }
    }
  }
  return result;
}
 
Example 2
Source File: SyntacticSequencerExtensions.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
public List<EqualAmbiguousTransitions> getAllAmbiguousTransitionsBySyntax() {
  if ((this.ambiguousTransitions != null)) {
    return this.ambiguousTransitions;
  }
  final Map<GrammarAlias.AbstractElementAlias, EqualAmbiguousTransitions> result = CollectionLiterals.<GrammarAlias.AbstractElementAlias, EqualAmbiguousTransitions>newHashMap();
  Set<ISyntacticSequencerPDAProvider.ISynTransition> _allAmbiguousTransitions = this.getAllAmbiguousTransitions();
  for (final ISyntacticSequencerPDAProvider.ISynTransition transition : _allAmbiguousTransitions) {
    List<GrammarAlias.AbstractElementAlias> _ambiguousSyntaxes = transition.getAmbiguousSyntaxes();
    for (final GrammarAlias.AbstractElementAlias syntax : _ambiguousSyntaxes) {
      {
        EqualAmbiguousTransitions list = result.get(syntax);
        if ((list == null)) {
          String _elementAliasToIdentifier = this.elementAliasToIdentifier(syntax);
          EqualAmbiguousTransitions _equalAmbiguousTransitions = new EqualAmbiguousTransitions(_elementAliasToIdentifier, syntax);
          list = _equalAmbiguousTransitions;
          result.put(syntax, list);
        }
        list.getTransitions().add(transition);
      }
    }
  }
  this.ambiguousTransitions = CollectionLiterals.<EqualAmbiguousTransitions>newArrayList(((EqualAmbiguousTransitions[])Conversions.unwrapArray(result.values(), EqualAmbiguousTransitions.class)));
  ListExtensions.<EqualAmbiguousTransitions>sortInplace(this.ambiguousTransitions);
  return this.ambiguousTransitions;
}
 
Example 3
Source File: AbstractLanguageServerTest.java    From xtext-core with Eclipse Public License 2.0 6 votes vote down vote up
protected Map<String, List<Diagnostic>> getDiagnostics() {
  try {
    final Function1<CancelIndicator, HashMap<String, List<Diagnostic>>> _function = (CancelIndicator it) -> {
      final HashMap<String, List<Diagnostic>> result = CollectionLiterals.<String, List<Diagnostic>>newHashMap();
      final Function1<Pair<String, Object>, Object> _function_1 = (Pair<String, Object> it_1) -> {
        return it_1.getValue();
      };
      Iterable<PublishDiagnosticsParams> _filter = Iterables.<PublishDiagnosticsParams>filter(ListExtensions.<Pair<String, Object>, Object>map(this.notifications, _function_1), PublishDiagnosticsParams.class);
      for (final PublishDiagnosticsParams diagnostic : _filter) {
        result.put(diagnostic.getUri(), diagnostic.getDiagnostics());
      }
      return result;
    };
    return this.languageServer.getRequestManager().<HashMap<String, List<Diagnostic>>>runRead(_function).get();
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 4
Source File: AbstractFileSystemSupport.java    From xtext-xtend with Eclipse Public License 2.0 5 votes vote down vote up
protected Object getAttribute(final URI uri, final String attributeName) {
  Object _xblockexpression = null;
  {
    if ((uri == null)) {
      return null;
    }
    final HashMap<String, Set<String>> options = CollectionLiterals.<String, Set<String>>newHashMap();
    options.put(URIConverter.OPTION_REQUESTED_ATTRIBUTES, Collections.<String>unmodifiableSet(CollectionLiterals.<String>newHashSet(attributeName)));
    _xblockexpression = this.getURIConverter().getAttributes(uri, options).get(attributeName);
  }
  return _xblockexpression;
}
 
Example 5
Source File: EMFGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private Map<String, EPackage> findAllUsedEPackages(final List<EPackage> generatedPackages) {
  final HashMap<String, EPackage> result = CollectionLiterals.<String, EPackage>newHashMap();
  final TreeIterator<EObject> packageContentIterator = EcoreUtil.<EObject>getAllContents(generatedPackages);
  while (packageContentIterator.hasNext()) {
    {
      final EObject current = packageContentIterator.next();
      EList<EObject> _eCrossReferences = current.eCrossReferences();
      for (final EObject referenced : _eCrossReferences) {
        {
          boolean _eIsProxy = referenced.eIsProxy();
          if (_eIsProxy) {
            throw new RuntimeException(((("Unresolved proxy: " + referenced) + " in ") + current));
          }
          if ((referenced instanceof EClassifier)) {
            final EPackage referencedPackage = ((EClassifier)referenced).getEPackage();
            boolean _contains = generatedPackages.contains(referencedPackage);
            boolean _not = (!_contains);
            if (_not) {
              result.put(referencedPackage.getNsURI(), referencedPackage);
            }
          }
        }
      }
    }
  }
  return result;
}
 
Example 6
Source File: EMFGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private Map<EObject, EObject> createENamedElementMapping(final Map<String, EPackage> usedEPackages, final Map<String, EPackage> loadedEPackages) {
  final HashMap<EObject, EObject> result = CollectionLiterals.<EObject, EObject>newHashMap();
  Set<Map.Entry<String, EPackage>> _entrySet = usedEPackages.entrySet();
  for (final Map.Entry<String, EPackage> entry : _entrySet) {
    this.putMappingData(result, entry.getValue(), loadedEPackages.get(entry.getKey()));
  }
  return result;
}
 
Example 7
Source File: EMFGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @since 2.14
 */
protected void saveResource(final Resource resource) {
  try {
    final HashMap<String, Object> saveOptions = CollectionLiterals.<String, Object>newHashMap();
    saveOptions.put(XMLResource.OPTION_URI_HANDLER, new URIHandlerImpl.AbsoluteCrossBundleAware() {
      @Override
      public URI deresolve(final URI uri) {
        boolean _isPlatform = uri.isPlatform();
        boolean _not = (!_isPlatform);
        if (_not) {
          Set<Map.Entry<String, URI>> _entrySet = EcorePlugin.getPlatformResourceMap().entrySet();
          for (final Map.Entry<String, URI> entry : _entrySet) {
            {
              String _key = entry.getKey();
              String _plus = ("platform:/resource/" + _key);
              String _plus_1 = (_plus + "/");
              final URI newPrefix = URI.createURI(_plus_1);
              final URI uri2 = uri.replacePrefix(entry.getValue(), newPrefix);
              if ((uri2 != null)) {
                return super.deresolve(uri2);
              }
            }
          }
        }
        return super.deresolve(uri);
      }
    });
    saveOptions.put(Resource.OPTION_LINE_DELIMITER, this.codeConfig.getLineDelimiter());
    resource.save(saveOptions);
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example 8
Source File: NamedSerializationContextProvider.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
public NamedSerializationContextProvider(final Grammar grammar) {
  final Function1<Pair<Integer, ParserRule>, Pair<ParserRule, Integer>> _function = (Pair<Integer, ParserRule> it) -> {
    ParserRule _value = it.getValue();
    Integer _key = it.getKey();
    return Pair.<ParserRule, Integer>of(_value, _key);
  };
  this.rules = CollectionLiterals.<ParserRule, Integer>newHashMap(((Pair<? extends ParserRule, ? extends Integer>[])Conversions.unwrapArray(IterableExtensions.<Pair<Integer, ParserRule>, Pair<ParserRule, Integer>>map(IterableExtensions.<ParserRule>indexed(GrammarUtil.allParserRules(grammar)), _function), Pair.class)));
}
 
Example 9
Source File: XtendFileGenerator.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public Map<String, ? extends CharSequence> getDependencies() {
  return CollectionLiterals.<String, String>newHashMap(this.getAmount(), this.getCircle(), this.getNetNode(), this.getPerson(), this.getRectangle(), this.getShape());
}
 
Example 10
Source File: XtendFileGenerator.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
public Map<String, ? extends CharSequence> getDependencies() {
  return CollectionLiterals.<String, String>newHashMap(this.getAmount(), this.getCircle(), this.getNetNode(), this.getPerson(), this.getRectangle(), this.getShape());
}
 
Example 11
Source File: ConstantExpressionsInterpreter.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * looks up the static final fields which are accessible in unqualified form for the given expression.
 * That essentially includes static imports and the fields declared in the containing types
 */
protected Map<String, JvmIdentifiableElement> findVisibleFeatures(final XExpression expression) {
  HashMap<String, JvmIdentifiableElement> _xblockexpression = null;
  {
    Resource _eResource = expression.eResource();
    final Resource res = _eResource;
    boolean _matched = false;
    if (res instanceof StorageAwareResource) {
      boolean _isLoadedFromStorage = ((StorageAwareResource)res).isLoadedFromStorage();
      if (_isLoadedFromStorage) {
        _matched=true;
        return CollectionLiterals.<String, JvmIdentifiableElement>newHashMap();
      }
    }
    JvmDeclaredType _switchResult_1 = null;
    JvmIdentifiableElement _nearestLogicalContainer = this.containerProvider.getNearestLogicalContainer(expression);
    final JvmIdentifiableElement cont = _nearestLogicalContainer;
    boolean _matched_1 = false;
    if (cont instanceof JvmGenericType) {
      _matched_1=true;
      _switchResult_1 = ((JvmGenericType)cont);
    }
    if (!_matched_1) {
      if (cont instanceof JvmMember) {
        _matched_1=true;
        _switchResult_1 = ((JvmMember)cont).getDeclaringType();
      }
    }
    final JvmDeclaredType container = _switchResult_1;
    Pair<String, JvmDeclaredType> _mappedTo = Pair.<String, JvmDeclaredType>of("visibleFeaturesForAnnotationValues", container);
    final Provider<HashMap<String, JvmIdentifiableElement>> _function = () -> {
      final HashMap<String, JvmIdentifiableElement> result = CollectionLiterals.<String, JvmIdentifiableElement>newHashMap();
      Resource _eResource_1 = expression.eResource();
      final XImportSection section = this.importSectionLocator.getImportSection(((XtextResource) _eResource_1));
      if ((section != null)) {
        EList<XImportDeclaration> _importDeclarations = section.getImportDeclarations();
        for (final XImportDeclaration imp : _importDeclarations) {
          boolean _isStatic = imp.isStatic();
          if (_isStatic) {
            final String importedTypeName = imp.getImportedTypeName();
            if ((importedTypeName != null)) {
              final JvmType type = this.findTypeByName(imp, importedTypeName);
              boolean _matched_2 = false;
              if (type instanceof JvmGenericType) {
                _matched_2=true;
                this.collectAllVisibleFields(((JvmDeclaredType)type), result);
              }
              if (!_matched_2) {
                if (type instanceof JvmEnumerationType) {
                  _matched_2=true;
                  EList<JvmEnumerationLiteral> _literals = ((JvmEnumerationType)type).getLiterals();
                  for (final JvmEnumerationLiteral feature : _literals) {
                    result.put(feature.getSimpleName(), feature);
                  }
                }
              }
            }
          }
        }
      }
      this.collectAllVisibleFields(container, result);
      return result;
    };
    _xblockexpression = this.cache.<HashMap<String, JvmIdentifiableElement>>get(_mappedTo, expression.eResource(), _function);
  }
  return _xblockexpression;
}
 
Example 12
Source File: ConstantExpressionsInterpreter.java    From xtext-xtend with Eclipse Public License 2.0 4 votes vote down vote up
protected HashMap<String, JvmIdentifiableElement> getAllVisibleFields(final JvmDeclaredType type) {
  final HashMap<String, JvmIdentifiableElement> result = CollectionLiterals.<String, JvmIdentifiableElement>newHashMap();
  new ConstantExpressionsInterpreter.VisibleFieldsCollector().collect(type, result);
  return result;
}
 
Example 13
Source File: GrammarAccessFragment2.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
protected void writeGrammar() {
  final Wrapper<Boolean> isSaving = Wrapper.<Boolean>wrap(Boolean.valueOf(false));
  final ResourceSet cloneInto = new ResourceSetImpl();
  Map<String, Object> _extensionToFactoryMap = cloneInto.getResourceFactoryRegistry().getExtensionToFactoryMap();
  FragmentFakingEcoreResource.FactoryImpl _factoryImpl = new FragmentFakingEcoreResource.FactoryImpl(isSaving);
  _extensionToFactoryMap.put(
    FragmentFakingEcoreResource.FactoryImpl.ECORE_SUFFIX, _factoryImpl);
  final ResourceSet resourceSet = EcoreUtil2.<ResourceSet>clone(cloneInto, this.getLanguage().getGrammar().eResource().getResourceSet());
  EObject _head = IterableExtensions.<EObject>head(resourceSet.getResource(this.getLanguage().getGrammar().eResource().getURI(), true).getContents());
  final Grammar copy = ((Grammar) _head);
  String _xifexpression = null;
  if ((this.xmlVersion == null)) {
    _xifexpression = GrammarUtil.getClasspathRelativePathToBinGrammar(copy);
  } else {
    String _xblockexpression = null;
    {
      String _simpleName = GrammarAccessFragment2.class.getSimpleName();
      String _plus = ("The property \'xmlVersion\' has been specified for this " + _simpleName);
      String _plus_1 = (_plus + ". Therefore, the grammar is persisted as XMI and not as binary. This can be a performance drawback.");
      GrammarAccessFragment2.LOG.warn(_plus_1);
      _xblockexpression = GrammarUtil.getClasspathRelativePathToXmi(copy);
    }
    _xifexpression = _xblockexpression;
  }
  final String path = _xifexpression;
  final URI uri = this.getProjectConfig().getRuntime().getSrcGen().getURI(path);
  final Resource resource = resourceSet.createResource(uri, ContentHandler.UNSPECIFIED_CONTENT_TYPE);
  HashSet<Grammar> _hashSet = new HashSet<Grammar>();
  this.addAllGrammarsToResource(resource, copy, _hashSet);
  isSaving.set(Boolean.valueOf(true));
  final Map<String, Object> saveOptions = CollectionLiterals.<String, Object>newHashMap();
  if ((resource instanceof XMLResource)) {
    String _elvis = null;
    if (this.xmlVersion != null) {
      _elvis = this.xmlVersion;
    } else {
      _elvis = "1.0";
    }
    ((XMLResource)resource).setXMLVersion(_elvis);
  } else {
    if ((resource instanceof BinaryResourceImpl)) {
      saveOptions.put(BinaryResourceImpl.OPTION_VERSION, BinaryResourceImpl.BinaryIO.Version.VERSION_1_1);
      saveOptions.put(BinaryResourceImpl.OPTION_STYLE_DATA_CONVERTER, Boolean.valueOf(true));
    }
  }
  try {
    resource.save(saveOptions);
  } catch (final Throwable _t) {
    if (_t instanceof IOException) {
      final IOException e = (IOException)_t;
      GrammarAccessFragment2.LOG.error(e.getMessage(), e);
    } else {
      throw Exceptions.sneakyThrow(_t);
    }
  } finally {
    isSaving.set(Boolean.valueOf(false));
  }
}
 
Example 14
Source File: NamedSerializationContextProvider.java    From xtext-core with Eclipse Public License 2.0 4 votes vote down vote up
public <T extends Object> List<NamedSerializationContexts<T>> getNamedContexts(final SerializationContextMap<T> map) {
  final ArrayList<NamedSerializationContexts<T>> result = CollectionLiterals.<NamedSerializationContexts<T>>newArrayList();
  final HashMap<String, Integer> names = CollectionLiterals.<String, Integer>newHashMap();
  List<SerializationContextMap.Entry<T>> _values = map.values();
  for (final SerializationContextMap.Entry<T> e : _values) {
    Set<EClass> _types = e.getTypes();
    for (final EClass t : _types) {
      {
        final List<ISerializationContext> ctx = e.getContexts(t);
        String _xifexpression = null;
        if ((t == null)) {
          _xifexpression = "";
        } else {
          _xifexpression = t.getName();
        }
        String _plus = (_xifexpression + "_");
        String _significantGrammarElement = this.getSignificantGrammarElement(ctx);
        final String name = (_plus + _significantGrammarElement);
        final Integer dup = names.get(name);
        String _xifexpression_1 = null;
        if ((dup == null)) {
          String _xblockexpression = null;
          {
            names.put(name, Integer.valueOf(1));
            _xblockexpression = name;
          }
          _xifexpression_1 = _xblockexpression;
        } else {
          String _xblockexpression_1 = null;
          {
            names.put(name, Integer.valueOf(((dup).intValue() + 1)));
            _xblockexpression_1 = ((name + "_") + dup);
          }
          _xifexpression_1 = _xblockexpression_1;
        }
        final String unique = _xifexpression_1;
        T _value = e.getValue();
        NamedSerializationContexts<T> _namedSerializationContexts = new NamedSerializationContexts<T>(unique, t, ctx, _value);
        result.add(_namedSerializationContexts);
      }
    }
  }
  return result;
}