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

The following examples show how to use org.eclipse.xtext.xbase.lib.StringExtensions. 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 Project: xtext-extras   Author: eclipse   File: ImplicitlyImportedFeatures.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected List<Class<?>> getExtensionClasses() {
	return Lists.<Class<?>> newArrayList(
		ArrayExtensions.class,
		BigDecimalExtensions.class,
		BigIntegerExtensions.class,
		BooleanExtensions.class,
		ByteExtensions.class,
		CharacterExtensions.class,
		CollectionExtensions.class,
		ComparableExtensions.class,
		DoubleExtensions.class,
		FloatExtensions.class,
		FunctionExtensions.class,
		IntegerExtensions.class,
		IterableExtensions.class,
		IteratorExtensions.class,
		ListExtensions.class,
		LongExtensions.class,
		MapExtensions.class,
		ObjectExtensions.class,
		ProcedureExtensions.class,
		ShortExtensions.class,
		StringExtensions.class);
}
 
Example #2
Source Project: xtext-web   Author: eclipse   File: EntitiesValidator.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Check
public void checkPropertyNamesAreUnique(Entity entity) {
	Multimap<String, Property> name2properties = HashMultimap.create();
	IterableExtensions
			.filter(Iterables.filter(entity.getFeatures(), Property.class),
					(f) -> !StringExtensions.isNullOrEmpty(f.getName()))
			.forEach((p) -> name2properties.put(p.getName(), p));
	name2properties.asMap().values().forEach((properties) -> {
		if (properties.size() > 1) {
			properties.forEach((p) -> {
				error("Duplicate property " + p.getName(), p, DomainmodelPackage.Literals.FEATURE__NAME,
						IssueCodes.DUPLICATE_PROPERTY);
			});
		}
	});
}
 
Example #3
Source Project: xtext-lib   Author: eclipse   File: PropertyProcessor.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void doTransform(final MutableFieldDeclaration it, @Extension final TransformationContext context) {
  @Extension
  final AccessorsProcessor.Util util = new AccessorsProcessor.Util(context);
  boolean _hasGetter = util.hasGetter(it);
  boolean _not = (!_hasGetter);
  if (_not) {
    util.addGetter(it, Visibility.PUBLIC);
  }
  if (((!it.isFinal()) && (!util.hasSetter(it)))) {
    util.addSetter(it, Visibility.PUBLIC);
  }
  String _firstLower = StringExtensions.toFirstLower(it.getSimpleName());
  String _plus = ("_" + _firstLower);
  it.setSimpleName(_plus);
}
 
Example #4
Source Project: xtext-lib   Author: eclipse   File: AccessorsProcessor.java    License: Eclipse Public License 2.0 6 votes vote down vote up
public List<String> getPossibleGetterNames(final FieldDeclaration it) {
  final ArrayList<String> names = CollectionLiterals.<String>newArrayList();
  if ((((this.isBooleanType(this.orObject(it.getType())) && it.getSimpleName().startsWith("is")) && (it.getSimpleName().length() > 2)) && Character.isUpperCase(it.getSimpleName().charAt(2)))) {
    String _simpleName = it.getSimpleName();
    names.add(_simpleName);
  }
  List<String> _xifexpression = null;
  boolean _isBooleanType = this.isBooleanType(this.orObject(it.getType()));
  if (_isBooleanType) {
    _xifexpression = Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("is", "get"));
  } else {
    _xifexpression = Collections.<String>unmodifiableList(CollectionLiterals.<String>newArrayList("get"));
  }
  final Function1<String, String> _function = (String prefix) -> {
    String _firstUpper = StringExtensions.toFirstUpper(it.getSimpleName());
    return (prefix + _firstUpper);
  };
  names.addAll(ListExtensions.<String, String>map(_xifexpression, _function));
  return names;
}
 
Example #5
Source Project: xtext-eclipse   Author: eclipse   File: StatemachineGenerator.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected CharSequence declareCommand(final Command command) {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("protected void do");
  String _firstUpper = StringExtensions.toFirstUpper(command.getName());
  _builder.append(_firstUpper);
  _builder.append("() {");
  _builder.newLineIfNotEmpty();
  _builder.append("\t");
  _builder.append("System.out.println(\"Executing command ");
  String _name = command.getName();
  _builder.append(_name, "\t");
  _builder.append(" (");
  String _code = command.getCode();
  _builder.append(_code, "\t");
  _builder.append(")\");");
  _builder.newLineIfNotEmpty();
  _builder.append("}");
  _builder.newLine();
  return _builder;
}
 
Example #6
Source Project: xtext-eclipse   Author: eclipse   File: FormatterTester.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected ArrayList<TextReplacement> createMissingEditReplacements(XtextResource res, Collection<TextReplacement> edits, int offset,
		int length) {
	Set<Integer> offsets = IterableExtensions
			.toSet(Iterables.transform(edits, (TextReplacement it) -> Integer.valueOf(it.getOffset())));
	ArrayList<TextReplacement> result = new ArrayList<>();
	int lastOffset = 0;
	IParseResult parseResult = res.getParseResult();
	if (parseResult != null) {
		ICompositeNode rootNode = parseResult.getRootNode();
		if (rootNode != null) {
			for (ILeafNode leaf : rootNode.getLeafNodes()) {
				if (!leaf.isHidden() || !StringExtensions.isNullOrEmpty(leaf.getText().trim())) {
					ITextRegion leafRegion = leaf.getTextRegion();
					if (lastOffset >= offset && leafRegion.getOffset() <= offset + length && !offsets.contains(Integer.valueOf(lastOffset))) {
						result.add(new TextReplacement(lastOffset, leafRegion.getOffset() - lastOffset, "!!"));
					}
					lastOffset = leafRegion.getOffset() + leafRegion.getLength();
				}
			}
		}
	}
	return result;
}
 
Example #7
Source Project: xtext-core   Author: eclipse   File: TracedAccessorsProcessor.java    License: Eclipse Public License 2.0 6 votes vote down vote up
public String featureName(final ResolvedMethod m) {
  String _xblockexpression = null;
  {
    final String n = m.getDeclaration().getSimpleName();
    int _xifexpression = (int) 0;
    boolean _startsWith = n.startsWith("get");
    if (_startsWith) {
      _xifexpression = 3;
    } else {
      _xifexpression = 2;
    }
    final int skip = _xifexpression;
    _xblockexpression = StringExtensions.toFirstLower(m.getDeclaration().getSimpleName().substring(skip));
  }
  return _xblockexpression;
}
 
Example #8
Source Project: xtext-core   Author: eclipse   File: SignatureHelpServiceImpl.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public SignatureHelp getSignatureHelp(final Document document, final XtextResource resource, final SignatureHelpParams params, final CancelIndicator cancelIndicator) {
  final int offset = document.getOffSet(params.getPosition());
  Preconditions.<XtextResource>checkNotNull(resource, "resource");
  Preconditions.checkArgument((offset >= 0), ("offset >= 0. Was: " + Integer.valueOf(offset)));
  final EObject object = this.offsetHelper.resolveContainedElementAt(resource, offset);
  if ((object instanceof OperationCall)) {
    final String operationName = this.getOperationName(((OperationCall)object));
    boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(operationName);
    boolean _not = (!_isNullOrEmpty);
    if (_not) {
      return this.getSignatureHelp(((OperationCall)object), operationName, offset);
    }
  }
  return ISignatureHelpService.EMPTY;
}
 
Example #9
Source Project: xtext-core   Author: eclipse   File: Formatter2Fragment2.java    License: Eclipse Public License 2.0 6 votes vote down vote up
protected String toVarName(final ENamedElement element, final String... reservedNames) {
  String _xblockexpression = null;
  {
    if ((element instanceof EReference)) {
      return this.toVarName(((EReference)element).getEReferenceType(), reservedNames);
    }
    String name = StringExtensions.toFirstLower(element.getName());
    boolean _contains = XtendFileAccess.XTEND_KEYWORDS.contains(name);
    if (_contains) {
      name = ("_" + name);
    }
    boolean _contains_1 = ArrayExtensions.contains(reservedNames, name);
    if (_contains_1) {
      name = ("_" + name);
    }
    _xblockexpression = name;
  }
  return _xblockexpression;
}
 
Example #10
Source Project: xtext-core   Author: eclipse   File: TestsEMFGeneratorFragment.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected String getEcoreFilePath(final Grammar grammar) {
  String _xifexpression = null;
  boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(this.ecoreModel);
  boolean _not = (!_isNullOrEmpty);
  if (_not) {
    _xifexpression = this.ecoreModel;
  } else {
    String _javaModelDirectory = this.getJavaModelDirectory();
    String _plus = (_javaModelDirectory + "/");
    String _replace = grammar.getName().substring(0, grammar.getName().lastIndexOf(".")).replace(".", "/");
    String _plus_1 = (_plus + _replace);
    String _plus_2 = (_plus_1 + "/");
    String _modelName = this.getModelName(grammar);
    String _plus_3 = (_plus_2 + _modelName);
    _xifexpression = (_plus_3 + ".ecore");
  }
  return _xifexpression;
}
 
Example #11
Source Project: xtext-core   Author: eclipse   File: TestsEMFGeneratorFragment.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
protected String getGenModelPath(final Grammar grammar) {
  String _xifexpression = null;
  boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(this.genModel);
  boolean _not = (!_isNullOrEmpty);
  if (_not) {
    _xifexpression = this.genModel;
  } else {
    String _javaModelDirectory = this.getJavaModelDirectory();
    String _plus = (_javaModelDirectory + "/");
    String _replace = grammar.getName().substring(0, grammar.getName().lastIndexOf(".")).replace(".", "/");
    String _plus_1 = (_plus + _replace);
    String _plus_2 = (_plus_1 + "/");
    String _modelName = this.getModelName(grammar);
    String _plus_3 = (_plus_2 + _modelName);
    _xifexpression = (_plus_3 + ".genmodel");
  }
  return _xifexpression;
}
 
Example #12
Source Project: xsemantics   Author: eclipse   File: TypeSystem.java    License: Eclipse Public License 1.0 6 votes vote down vote up
protected Result<Boolean> applyRuleEClassEClass(final RuleEnvironment G, final RuleApplicationTrace _trace_, final EClass eClass1, final EClass eClass2) throws RuleFailedException {
  String _string = new String();
  String _firstUpper = StringExtensions.toFirstUpper("bar");
  String _plus = (_string + _firstUpper);
  boolean _equals = Objects.equal("foo", _plus);
  /* 'foo' == new String() + 'bar'.toFirstUpper */
  if (!_equals) {
    sneakyThrowRuleFailedException("\'foo\' == new String() + \'bar\'.toFirstUpper");
  }
  final EClass eC = EcoreFactory.eINSTANCE.createEClass();
  eC.setName("MyEClass");
  /* eClass1 == eC */
  if (!Objects.equal(eClass1, eC)) {
    sneakyThrowRuleFailedException("eClass1 == eC");
  }
  return new Result<Boolean>(true);
}
 
Example #13
Source Project: xsemantics   Author: eclipse   File: TypeSystem.java    License: Eclipse Public License 1.0 6 votes vote down vote up
protected Result<Boolean> applyRuleEClassEObject(final RuleEnvironment G, final RuleApplicationTrace _trace_, final EClass eClass, final EObject object) throws RuleFailedException {
  String _string = new String();
  String _firstUpper = StringExtensions.toFirstUpper("bar");
  String _plus = (_string + _firstUpper);
  boolean _equals = Objects.equal("foo", _plus);
  /* 'foo' == new String() + 'bar'.toFirstUpper */
  if (!_equals) {
    sneakyThrowRuleFailedException("\'foo\' == new String() + \'bar\'.toFirstUpper");
  }
  final EClass eC = EcoreFactory.eINSTANCE.createEClass();
  eC.setName("MyEClass");
  /* eClass == eC */
  if (!Objects.equal(eClass, eC)) {
    sneakyThrowRuleFailedException("eClass == eC");
  }
  return new Result<Boolean>(true);
}
 
Example #14
Source Project: xsemantics   Author: eclipse   File: TypeSystem.java    License: Eclipse Public License 1.0 6 votes vote down vote up
protected Result<Boolean> applyRuleEClassEObject(final RuleEnvironment G, final RuleApplicationTrace _trace_, final EClass eClass, final EObject object) throws RuleFailedException {
  String _string = new String();
  String _firstUpper = StringExtensions.toFirstUpper("bar");
  String _plus = (_string + _firstUpper);
  boolean _equals = Objects.equal("foo", _plus);
  /* 'foo' == new String() + 'bar'.toFirstUpper */
  if (!_equals) {
    sneakyThrowRuleFailedException("\'foo\' == new String() + \'bar\'.toFirstUpper");
  }
  final EClass eC = EcoreFactory.eINSTANCE.createEClass();
  eC.setName("MyEClass");
  /* eClass == eC */
  if (!Objects.equal(eClass, eC)) {
    sneakyThrowRuleFailedException("eClass == eC");
  }
  return new Result<Boolean>(true);
}
 
Example #15
Source Project: xsemantics   Author: eclipse   File: TypeSystem.java    License: Eclipse Public License 1.0 6 votes vote down vote up
protected Result<Boolean> applyRuleEClassEClass(final RuleEnvironment G, final RuleApplicationTrace _trace_, final EClass eClass1, final EClass eClass2) throws RuleFailedException {
  String _string = new String();
  String _firstUpper = StringExtensions.toFirstUpper("bar");
  String _plus = (_string + _firstUpper);
  boolean _equals = Objects.equal("foo", _plus);
  /* 'foo' == new String() + 'bar'.toFirstUpper */
  if (!_equals) {
    sneakyThrowRuleFailedException("\'foo\' == new String() + \'bar\'.toFirstUpper");
  }
  final EClass eC = EcoreFactory.eINSTANCE.createEClass();
  eC.setName("MyEClass");
  /* eClass1 == eC */
  if (!Objects.equal(eClass1, eC)) {
    sneakyThrowRuleFailedException("eClass1 == eC");
  }
  return new Result<Boolean>(true);
}
 
Example #16
Source Project: xsemantics   Author: eclipse   File: TypeSystem.java    License: Eclipse Public License 1.0 6 votes vote down vote up
protected Result<Boolean> applyRuleEClassEObject(final RuleEnvironment G, final RuleApplicationTrace _trace_, final EClass eClass, final EObject object) throws RuleFailedException {
  String _string = new String();
  String _firstUpper = StringExtensions.toFirstUpper("bar");
  String _plus = (_string + _firstUpper);
  boolean _equals = Objects.equal("foo", _plus);
  /* 'foo' == new String() + 'bar'.toFirstUpper */
  if (!_equals) {
    sneakyThrowRuleFailedException("\'foo\' == new String() + \'bar\'.toFirstUpper");
  }
  final EClass eC = EcoreFactory.eINSTANCE.createEClass();
  eC.setName("MyEClass");
  /* eClass == eC */
  if (!Objects.equal(eClass, eC)) {
    sneakyThrowRuleFailedException("eClass == eC");
  }
  return new Result<Boolean>(true);
}
 
Example #17
Source Project: xsemantics   Author: eclipse   File: TypeSystem.java    License: Eclipse Public License 1.0 6 votes vote down vote up
protected Result<Boolean> applyRuleEClassEClass(final RuleEnvironment G, final RuleApplicationTrace _trace_, final EClass eClass1, final EClass eClass2) throws RuleFailedException {
  String _string = new String();
  String _firstUpper = StringExtensions.toFirstUpper("bar");
  String _plus = (_string + _firstUpper);
  boolean _equals = Objects.equal("foo", _plus);
  /* 'foo' == new String() + 'bar'.toFirstUpper */
  if (!_equals) {
    sneakyThrowRuleFailedException("\'foo\' == new String() + \'bar\'.toFirstUpper");
  }
  final EClass eC = EcoreFactory.eINSTANCE.createEClass();
  eC.setName("MyEClass");
  /* eClass1 == eC */
  if (!Objects.equal(eClass1, eC)) {
    sneakyThrowRuleFailedException("eClass1 == eC");
  }
  return new Result<Boolean>(true);
}
 
Example #18
Source Project: xtext-extras   Author: eclipse   File: JvmModelGenerator.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public void generateJavaDoc(final EObject it, final ITreeAppendable appendable, final GeneratorConfig config) {
  final DocumentationAdapter adapter = IterableExtensions.<DocumentationAdapter>head(Iterables.<DocumentationAdapter>filter(it.eAdapters(), DocumentationAdapter.class));
  if (((adapter != null) && (!StringExtensions.isNullOrEmpty(adapter.getDocumentation())))) {
    final Set<EObject> sourceElements = this.getSourceElements(it);
    if (((sourceElements.size() == 1) && (this.documentationProvider instanceof IEObjectDocumentationProviderExtension))) {
      final List<INode> documentationNodes = ((IEObjectDocumentationProviderExtension) this.documentationProvider).getDocumentationNodes(IterableExtensions.<EObject>head(sourceElements));
      this.addJavaDocImports(it, appendable, documentationNodes);
      this.generateDocumentation(adapter.getDocumentation(), documentationNodes, appendable, config);
    } else {
      this.generateDocumentation(adapter.getDocumentation(), CollectionLiterals.<INode>emptyList(), appendable, config);
    }
  }
}
 
Example #19
Source Project: xtext-eclipse   Author: eclipse   File: ProgressReportingTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void beginTask(final String name, final int totalWork) {
  String _xifexpression = null;
  boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(name);
  if (_isNullOrEmpty) {
    _xifexpression = "(";
  } else {
    _xifexpression = " (";
  }
  String _plus = (("BeginTask " + name) + _xifexpression);
  String _plus_1 = (_plus + Integer.valueOf(totalWork));
  String _plus_2 = (_plus_1 + ")");
  this.events.add(_plus_2);
}
 
Example #20
Source Project: xtext-eclipse   Author: eclipse   File: DomainmodelValidator.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Check
public void checkPropertyNamesAreUnique(Entity entity) {
	Map<String, List<Feature>> name2properties = entity.getFeatures().stream()
		.filter(Property.class::isInstance)
		.filter(it -> !StringExtensions.isNullOrEmpty(it.getName()))
		.collect(Collectors.groupingBy(Feature::getName));
	name2properties.values().forEach(properties -> {
		if (properties.size() > 1) {
			properties.forEach(it ->
				error("Duplicate property " + it.getName(), it, DomainmodelPackage.Literals.FEATURE__NAME,
						IssueCodes.DUPLICATE_PROPERTY)
			);
		}
	});
}
 
Example #21
Source Project: xtext-eclipse   Author: eclipse   File: StatemachineQuickfixProvider.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Fix(StatemachineValidator.INVALID_NAME)
public void convertNameToFirstLowerCase(Issue issue, IssueResolutionAcceptor acceptor) {
	String[] data = issue.getData();
	String firstLower = StringExtensions.toFirstLower(data[0]);
	String label = "Change to \'" + firstLower + "\'.";
	acceptor.accept(issue, label, label, "upcase.png", (IModification) (IModificationContext ctx) -> {
		IXtextDocument xtextDocument = ctx.getXtextDocument();
		String firstLetter = xtextDocument.get(issue.getOffset(), 1);
		xtextDocument.replace(issue.getOffset(), 1, firstLetter.toLowerCase());
	});
}
 
Example #22
Source Project: xtext-eclipse   Author: eclipse   File: FeatureProjectFactory.java    License: Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected void enhanceProject(final IProject project, final SubMonitor subMonitor, final Shell shell) throws CoreException {
  super.enhanceProject(project, subMonitor, shell);
  this.createManifest(project, subMonitor.newChild(1));
  this.createBuildProperties(project, subMonitor.newChild(1));
  boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(this.mainCategoryName);
  boolean _not = (!_isNullOrEmpty);
  if (_not) {
    this.createCategoryFile(project, this.mainCategoryName, subMonitor.newChild(1));
  }
}
 
Example #23
Source Project: xtext-xtend   Author: eclipse   File: Case_2.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public String aOrB(final String a, final String b) {
  String _xifexpression = null;
  boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(a);
  if (_isNullOrEmpty) {
    _xifexpression = b;
  } else {
    _xifexpression = a;
  }
  return _xifexpression;
}
 
Example #24
Source Project: xtext-xtend   Author: eclipse   File: AbstractSuperTypesTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public void assertSuperTypes(final Pair<String, String> type, final String... superTypes) {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("def ");
    {
      boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(type.getValue());
      boolean _not = (!_isNullOrEmpty);
      if (_not) {
        _builder.append("<");
        String _value = type.getValue();
        _builder.append(_value);
        _builder.append("> ");
      }
    }
    _builder.append("void method(");
    String _key = type.getKey();
    _builder.append(_key);
    _builder.append(" type) {}");
    final String signature = _builder.toString();
    final XtendFunction function = this.function(signature.toString());
    final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
    final LightweightTypeReference subtype = this.toLightweightTypeReference(IterableExtensions.<JvmFormalParameter>head(operation.getParameters()).getParameterType());
    final Function1<LightweightTypeReference, String> _function = (LightweightTypeReference it) -> {
      return it.getSimpleName();
    };
    Assert.assertEquals(IterableExtensions.<String>toList(((Iterable<String>)Conversions.doWrapArray(superTypes))), IterableExtensions.<String>toList(IterableExtensions.<LightweightTypeReference, String>map(this.collectSuperTypes(subtype), _function)));
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #25
Source Project: xtext-xtend   Author: eclipse   File: ActualTypeArgumentMergeTest.java    License: Eclipse Public License 2.0 5 votes vote down vote up
public Map<JvmTypeParameter, List<LightweightBoundTypeArgument>> mappedBy(final String typeParameters, final String... alternatingTypeReferences) {
  try {
    StringConcatenation _builder = new StringConcatenation();
    _builder.append("def ");
    {
      boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(typeParameters);
      boolean _not = (!_isNullOrEmpty);
      if (_not) {
        _builder.append("<");
        _builder.append(typeParameters);
        _builder.append(">");
      }
    }
    _builder.append(" void method(");
    final Function1<String, CharSequence> _function = (String it) -> {
      return it;
    };
    String _join = IterableExtensions.<String>join(((Iterable<String>)Conversions.doWrapArray(alternatingTypeReferences)), null, " p, ", " p", _function);
    _builder.append(_join);
    _builder.append(") {}");
    final String signature = _builder.toString();
    final XtendFunction function = this.function(signature.toString());
    final JvmOperation operation = this._iXtendJvmAssociations.getDirectlyInferredOperation(function);
    EList<JvmTypeParameter> _typeParameters = operation.getTypeParameters();
    ITypeReferenceOwner _owner = this.getOwner();
    final ActualTypeArgumentCollector collector = new ActualTypeArgumentCollector(_typeParameters, BoundTypeArgumentSource.INFERRED, _owner);
    int _size = ((List<String>)Conversions.doWrapArray(alternatingTypeReferences)).size();
    int _minus = (_size - 1);
    IntegerRange _withStep = new IntegerRange(0, _minus).withStep(2);
    for (final Integer i : _withStep) {
      collector.populateTypeParameterMapping(this.toLightweightTypeReference(operation.getParameters().get((i).intValue()).getParameterType()), this.toLightweightTypeReference(operation.getParameters().get(((i).intValue() + 1)).getParameterType()));
    }
    return collector.getTypeParameterMapping();
  } catch (Throwable _e) {
    throw Exceptions.sneakyThrow(_e);
  }
}
 
Example #26
Source Project: xtext-core   Author: eclipse   File: CodeActionService.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private Command fixInvalidName(Diagnostic d, ICodeActionService2.Options options) {
	String string = options.getDocument().getSubstring(d.getRange());
	Command command = new Command();
	command.setCommand("my.textedit.command");
	command.setTitle("Make '" + string + "' upper case");
	WorkspaceEdit workspaceEdit = new WorkspaceEdit();
	TextEdit textEdit = new TextEdit();
	textEdit.setNewText(StringExtensions.toFirstUpper(string));
	textEdit.setRange(d.getRange());
	workspaceEdit.getChanges().put(options.getCodeActionParams().getTextDocument().getUri(),
			Lists.newArrayList(textEdit));
	command.setArguments(Lists.newArrayList(workspaceEdit));
	return command;
}
 
Example #27
Source Project: xtext-core   Author: eclipse   File: XtextGeneratorNaming.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * @return name for the eclipsePlugin Activator or <code>null</code> if
 * eclipsePlugin has no name
 */
public TypeReference getEclipsePluginActivator() {
	String pluginName = projectConfig.getEclipsePlugin().getName();
	if (pluginName == null) {
		return null;
	}
	String activatorName = pluginName.replaceAll("\\.ui$", "");
	activatorName = StringExtensions.toFirstUpper(activatorName.substring(activatorName.lastIndexOf('.') + 1))
			+ "Activator";
	return new TypeReference(pluginName + ".internal", activatorName);
}
 
Example #28
Source Project: xtext-core   Author: eclipse   File: ValidatorFragment2.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected String getGeneratedEPackageName(final EPackage pack) {
  StringConcatenation _builder = new StringConcatenation();
  String _runtimeBasePackage = this._xtextGeneratorNaming.getRuntimeBasePackage(this.getGrammar());
  _builder.append(_runtimeBasePackage);
  _builder.append(".");
  String _name = pack.getName();
  _builder.append(_name);
  _builder.append(".");
  String _firstUpper = StringExtensions.toFirstUpper(pack.getName());
  _builder.append(_firstUpper);
  _builder.append("Package");
  return _builder.toString();
}
 
Example #29
Source Project: xtext-core   Author: eclipse   File: XtextGenerator.java    License: Eclipse Public License 2.0 5 votes vote down vote up
protected void mergeManifest(final ManifestAccess manifest, final IXtextGeneratorFileSystemAccess metaInf) throws IOException {
  InputStream in = null;
  try {
    in = metaInf.readBinaryFile(manifest.getPath());
    String _bundleName = manifest.getBundleName();
    final MergeableManifest2 merge = new MergeableManifest2(in, _bundleName);
    merge.setLineDelimiter(this.codeConfig.getLineDelimiter());
    merge.addExportedPackages(manifest.getExportedPackages());
    merge.addRequiredBundles(manifest.getRequiredBundles());
    merge.addImportedPackages(manifest.getImportedPackages());
    if (((manifest.getActivator() != null) && StringExtensions.isNullOrEmpty(merge.getBundleActivator()))) {
      merge.setBundleActivator(manifest.getActivator().getName());
    }
    boolean _isModified = merge.isModified();
    if (_isModified) {
      final ByteArrayOutputStream out = new ByteArrayOutputStream();
      merge.write(out);
      String _path = manifest.getPath();
      byte[] _byteArray = out.toByteArray();
      ByteArrayInputStream _byteArrayInputStream = new ByteArrayInputStream(_byteArray);
      metaInf.generateFile(_path, _byteArrayInputStream);
    }
  } finally {
    if ((in != null)) {
      in.close();
    }
  }
}
 
Example #30
Source Project: xtext-core   Author: eclipse   File: GrammarAccessExtensions.java    License: Eclipse Public License 2.0 5 votes vote down vote up
private String toJavaIdentifierSegment(final String text, final boolean isFirst, final boolean uppercaseFirst) {
  final String special = GrammarAccessExtensions.SPECIAL_CHARS.get(text);
  if ((special != null)) {
    String _xifexpression = null;
    if (uppercaseFirst) {
      _xifexpression = StringExtensions.toFirstUpper(special);
    } else {
      _xifexpression = special;
    }
    return _xifexpression;
  }
  final String r = this.toJavaIdentifierSegmentInt(text, isFirst, uppercaseFirst);
  int _length = r.length();
  boolean _greaterThan = (_length > 0);
  if (_greaterThan) {
    return r;
  }
  final StringBuilder builder = new StringBuilder();
  char[] _charArray = text.toCharArray();
  for (final char c : _charArray) {
    {
      final String n = this.getUnicodeName(c);
      if ((n != null)) {
        builder.append((n + " "));
      }
    }
  }
  return this.toJavaIdentifierSegmentInt(builder.toString().toLowerCase().trim(), isFirst, true);
}