<commit_before>/*
 * Copyright (c) 2011 Google Inc.
 *
 * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
 * Public License v1.0 which accompanies this distribution, and is available at
 *
 * http://www.eclipse.org/legal/epl-v10.html
 */
package com.google.eclipse.protobuf.ui.contentassist;

import static com.google.eclipse.protobuf.protobuf.Modifier.*;
import static com.google.eclipse.protobuf.protobuf.ScalarType.STRING;
import static java.lang.String.valueOf;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Image;
import org.eclipse.xtext.*;
import org.eclipse.xtext.ui.PluginImageHelper;
import org.eclipse.xtext.ui.editor.contentassist.*;

import com.google.common.collect.ImmutableList;
import com.google.eclipse.protobuf.protobuf.*;
import com.google.eclipse.protobuf.protobuf.Enum;
import com.google.eclipse.protobuf.scoping.GlobalScope;
import com.google.eclipse.protobuf.ui.grammar.CompoundElements;
import com.google.eclipse.protobuf.ui.grammar.Keywords;
import com.google.eclipse.protobuf.ui.labeling.Images;
import com.google.eclipse.protobuf.ui.util.*;
import com.google.eclipse.protobuf.util.EObjectFinder;
import com.google.inject.Inject;

/**
 * @author <EMAIL> (<NAME>)
 *
 * @see http://www.eclipse.org/Xtext/documentation/latest/xtext.html#contentAssist on how to customize content assistant
 */
public class ProtobufProposalProvider extends AbstractProtobufProposalProvider {

  @Inject private CompoundElements compoundElements;
  @Inject private EObjectFinder finder;
  @Inject private GlobalScope globalScope;
  @Inject private PluginImageHelper imageHelper;
  @Inject private Images imageRegistry;
  @Inject private Keywords keywords;
  @Inject private Literals literals;
  @Inject private Properties properties;
  @Inject private Strings strings;

  @Override public void completeOption_Name(EObject model, Assignment assignment, ContentAssistContext context,
      ICompletionProposalAcceptor acceptor) {
    EObject container = model.eContainer();
    if (container instanceof Protobuf) {
      proposeCommonFileOptions(context, acceptor);
      return;
    }
  }

  private void proposeCommonFileOptions(ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    for (Property fileOption : globalScope.fileOptions()) {
      String displayString = fileOption.getName();
      String proposalText = displayString + " " + keywords.equalSign().getValue() + " ";
      boolean isStringOption = properties.isStringProperty(fileOption);
      if (isStringOption)
        proposalText = proposalText + compoundElements.emptyString() + keywords.semicolon().getValue();
      ICompletionProposal proposal = createCompletionProposal(proposalText, displayString, context);
      if (isStringOption && proposal instanceof ConfigurableCompletionProposal) {<commit_msg>Renamed GlobalScope to Globals, to avoid name conflicts with Xtext's own elements.<commit_after>/*
 * Copyright (c) 2011 Google Inc.
 *
 * All rights reserved. This program and the accompanying materials are made available under the terms of the Eclipse
 * Public License v1.0 which accompanies this distribution, and is available at
 *
 * http://www.eclipse.org/legal/epl-v10.html
 */
package com.google.eclipse.protobuf.ui.contentassist;

import static com.google.eclipse.protobuf.protobuf.Modifier.*;
import static com.google.eclipse.protobuf.protobuf.ScalarType.STRING;
import static java.lang.String.valueOf;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.jface.text.contentassist.ICompletionProposal;
import org.eclipse.swt.custom.StyledText;
import org.eclipse.swt.graphics.Image;
import org.eclipse.xtext.*;
import org.eclipse.xtext.ui.PluginImageHelper;
import org.eclipse.xtext.ui.editor.contentassist.*;

import com.google.common.collect.ImmutableList;
import com.google.eclipse.protobuf.protobuf.*;
import com.google.eclipse.protobuf.protobuf.Enum;
import com.google.eclipse.protobuf.scoping.Globals;
import com.google.eclipse.protobuf.ui.grammar.CompoundElements;
import com.google.eclipse.protobuf.ui.grammar.Keywords;
import com.google.eclipse.protobuf.ui.labeling.Images;
import com.google.eclipse.protobuf.ui.util.*;
import com.google.eclipse.protobuf.util.EObjectFinder;
import com.google.inject.Inject;

/**
 * @author <EMAIL> (<NAME>)
 *
 * @see http://www.eclipse.org/Xtext/documentation/latest/xtext.html#contentAssist on how to customize content assistant
 */
public class ProtobufProposalProvider extends AbstractProtobufProposalProvider {

  @Inject private CompoundElements compoundElements;
  @Inject private EObjectFinder finder;
  @Inject private Globals globalScope;
  @Inject private PluginImageHelper imageHelper;
  @Inject private Images imageRegistry;
  @Inject private Keywords keywords;
  @Inject private Literals literals;
  @Inject private Properties properties;
  @Inject private Strings strings;

  @Override public void completeOption_Name(EObject model, Assignment assignment, ContentAssistContext context,
      ICompletionProposalAcceptor acceptor) {
    EObject container = model.eContainer();
    if (container instanceof Protobuf) {
      proposeCommonFileOptions(context, acceptor);
      return;
    }
  }

  private void proposeCommonFileOptions(ContentAssistContext context, ICompletionProposalAcceptor acceptor) {
    for (Property fileOption : globalScope.fileOptions()) {
      String displayString = fileOption.getName();
      String proposalText = displayString + " " + keywords.equalSign().getValue() + " ";
      boolean isStringOption = properties.isStringProperty(fileOption);
      if (isStringOption)
        proposalText = proposalText + compoundElements.emptyString() + keywords.semicolon().getValue();
      ICompletionProposal proposal = createCompletionProposal(proposalText, displayString, context);
      if (isStringOption && proposal instanceof ConfigurableCompletionProposal) {
{'fraction_non_alphanumeric': 0.09453885497442666, 'fraction_numerical': 0.002639828411153275, 'mean_word_length': 5.23021582733813, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3442634', 'n_tokens_mistral': 1643, 'n_tokens_neox': 1632, 'n_words': 391}