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 File: TypeSystem.java    From xsemantics with 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 #2
Source File: TypeSystem.java    From xsemantics with 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 #3
Source File: TypeSystem.java    From xsemantics with 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 #4
Source File: ImplicitlyImportedFeatures.java    From xtext-extras with 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 #5
Source File: EntitiesValidator.java    From xtext-web with 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 #6
Source File: PropertyProcessor.java    From xtext-lib with 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 #7
Source File: AccessorsProcessor.java    From xtext-lib with 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 #8
Source File: TypeSystem.java    From xsemantics with 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 #9
Source File: TypeSystem.java    From xsemantics with 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 #10
Source File: TypeSystem.java    From xsemantics with 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 #11
Source File: StatemachineGenerator.java    From xtext-eclipse with 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 #12
Source File: FormatterTester.java    From xtext-eclipse with 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 #13
Source File: TestsEMFGeneratorFragment.java    From xtext-core with 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 #14
Source File: TestsEMFGeneratorFragment.java    From xtext-core with 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 #15
Source File: Formatter2Fragment2.java    From xtext-core with 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 #16
Source File: TracedAccessorsProcessor.java    From xtext-core with 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 #17
Source File: SignatureHelpServiceImpl.java    From xtext-core with 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 #18
Source File: TypeSystem.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
protected Result<EObject> applyRuleEClassEObject(final RuleEnvironment G, final RuleApplicationTrace _trace_, final EClass _createEObject) throws RuleFailedException {
  String _string = new String();
  String _firstUpper = StringExtensions.toFirstUpper("bar");
  String _plus = (_string + _firstUpper);
  /* 'foo' == new String() + 'bar'.toFirstUpper */
  if (!Objects.equal("foo", _plus)) {
    sneakyThrowRuleFailedException("\'foo\' == new String() + \'bar\'.toFirstUpper");
  }
  return new Result<EObject>(_applyRuleEClassEObject_1(G, _createEObject));
}
 
Example #19
Source File: CPPDefaultFeatureValueProvider.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void setDefaultValue(FeatureType featureType, FeatureParameterValue parameterValue,
		EObject contextElement) {
	GeneratorEntry entry = (GeneratorEntry) contextElement;
	Statechart statechart = (Statechart) entry.getElementRef();
	
	if (parameterValue.getParameter().getName().equals(ICFeatureConstants.PARAMETER_NAMING_MODULE_NAME)) {
		parameterValue.setValue(asIdentifier(statechart.getName(), "_"));
	} else if (parameterValue.getParameter().getName()
			.equals(ICFeatureConstants.PARAMETER_NAMING_STATEMACHINE_PREFIX)) {
		parameterValue.setValue(StringExtensions.toFirstLower(asIdentifier(statechart.getName(), "_")));
	} else if (parameterValue.getParameter().getName()
			.equals(ICFeatureConstants.PARAMETER_NAMING_MAX_IDENTIFIER_LENGTH)) {
		parameterValue.setValue(31);
	} else if (parameterValue.getParameter().getName().equals(ICFeatureConstants.PARAMETER_NAMING_SEPARATOR)) {
		parameterValue.setValue("_");
	} else if (parameterValue.getParameter().getName()
			.equals(CPPFeatureConstants.PARAMETER_INNER_FUNCTION_VISIBILITY)) {
		parameterValue.setValue(Visibility.PRIVATE.toString().toLowerCase());
	} else if (parameterValue.getParameter().getName().equals(CPPFeatureConstants.PARAMETER_STATIC_OPC)) {
		parameterValue.setValue(false);
	} else if (parameterValue.getParameter().getName().equals(CPPFeatureConstants.PARAMETER_INCLUDES_USE_RELATIVE_PATHS)) {
		parameterValue.setValue(true);
	} else if (parameterValue.getParameter().getName().equals(CPPFeatureConstants.PARAMETER_API_CHECK_UNIMPLEMENTED_OCBS)) {
		parameterValue.setValue(true);
	} else if (parameterValue.getParameter().getName().equals(CPPFeatureConstants.PARAMETER_IN_EVENT_QUEUE)) {
		parameterValue.setValue(false);
	}
}
 
Example #20
Source File: TypeSystem.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
protected Result<EObject> applyRuleEClassEObject(final RuleEnvironment G, final RuleApplicationTrace _trace_, final EClass _createEObject) throws RuleFailedException {
  String _string = new String();
  String _firstUpper = StringExtensions.toFirstUpper("bar");
  String _plus = (_string + _firstUpper);
  /* 'foo' == new String() + 'bar'.toFirstUpper */
  if (!Objects.equal("foo", _plus)) {
    sneakyThrowRuleFailedException("\'foo\' == new String() + \'bar\'.toFirstUpper");
  }
  return new Result<EObject>(_applyRuleEClassEObject_1(G, _createEObject));
}
 
Example #21
Source File: ValidatorFragment2.java    From xtext-core with 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 #22
Source File: TypeSystem.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
protected Result2<EClass, EObject> applyRuleEClassEObject2(final RuleEnvironment G, final RuleApplicationTrace _trace_, final String s) throws RuleFailedException {
  EClass _createEObject = null; // output parameter
  String _string = new String();
  String _firstUpper = StringExtensions.toFirstUpper("bar");
  String _plus = (_string + _firstUpper);
  /* 'foo' == new String() + 'bar'.toFirstUpper */
  if (!Objects.equal("foo", _plus)) {
    sneakyThrowRuleFailedException("\'foo\' == new String() + \'bar\'.toFirstUpper");
  }
  return new Result2<EClass, EObject>(_createEObject, _applyRuleEClassEObject2_2(G, s));
}
 
Example #23
Source File: AbstractLanguageServerTest.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected String _toExpectation(final SymbolInformation it) {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("symbol \"");
  String _name = it.getName();
  _builder.append(_name);
  _builder.append("\" {");
  _builder.newLineIfNotEmpty();
  _builder.append("    ");
  _builder.append("kind: ");
  int _value = it.getKind().getValue();
  _builder.append(_value, "    ");
  _builder.newLineIfNotEmpty();
  _builder.append("    ");
  _builder.append("location: ");
  String _expectation = this.toExpectation(it.getLocation());
  _builder.append(_expectation, "    ");
  _builder.newLineIfNotEmpty();
  {
    boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(it.getContainerName());
    boolean _not = (!_isNullOrEmpty);
    if (_not) {
      _builder.append("    ");
      _builder.append("container: \"");
      String _containerName = it.getContainerName();
      _builder.append(_containerName, "    ");
      _builder.append("\"");
      _builder.newLineIfNotEmpty();
    }
  }
  _builder.append("}");
  _builder.newLine();
  return _builder.toString();
}
 
Example #24
Source File: RuntimeProjectDescriptor.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
private CharSequence defaultGrammar() {
  StringConcatenation _builder = new StringConcatenation();
  _builder.append("grammar ");
  String _name = this.getConfig().getLanguage().getName();
  _builder.append(_name);
  _builder.append(" with org.eclipse.xtext.common.Terminals");
  _builder.newLineIfNotEmpty();
  _builder.newLine();
  _builder.append("generate ");
  String _firstLower = StringExtensions.toFirstLower(this.getConfig().getLanguage().getSimpleName());
  _builder.append(_firstLower);
  _builder.append(" \"");
  String _nsURI = this.getConfig().getLanguage().getNsURI();
  _builder.append(_nsURI);
  _builder.append("\"");
  _builder.newLineIfNotEmpty();
  _builder.newLine();
  _builder.append("Model:");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("greetings+=Greeting*;");
  _builder.newLine();
  _builder.append("\t");
  _builder.newLine();
  _builder.append("Greeting:");
  _builder.newLine();
  _builder.append("\t");
  _builder.append("\'Hello\' name=ID \'!\';");
  _builder.newLine();
  return _builder;
}
 
Example #25
Source File: TypeSystem.java    From xsemantics with Eclipse Public License 1.0 5 votes vote down vote up
protected Result2<EClass, EObject> applyRuleEClassEObject2(final RuleEnvironment G, final RuleApplicationTrace _trace_, final String s) throws RuleFailedException {
  EClass _createEObject = null; // output parameter
  String _string = new String();
  String _firstUpper = StringExtensions.toFirstUpper("bar");
  String _plus = (_string + _firstUpper);
  /* 'foo' == new String() + 'bar'.toFirstUpper */
  if (!Objects.equal("foo", _plus)) {
    sneakyThrowRuleFailedException("\'foo\' == new String() + \'bar\'.toFirstUpper");
  }
  return new Result2<EClass, EObject>(_createEObject, _applyRuleEClassEObject2_2(G, s));
}
 
Example #26
Source File: EMFGeneratorFragment2.java    From xtext-core with Eclipse Public License 2.0 5 votes vote down vote up
protected String getJavaModelDirectory() {
  if ((this.javaModelDirectory != null)) {
    return this.javaModelDirectory;
  }
  final String srcGenPath = this.getProjectConfig().getRuntime().getSrcGen().getPath();
  final String rootPath = this.getProjectConfig().getRuntime().getRoot().getPath();
  if (((!StringExtensions.isNullOrEmpty(rootPath)) && srcGenPath.startsWith(rootPath))) {
    String _modelPluginID = this.getModelPluginID();
    String _plus = ("/" + _modelPluginID);
    String _substring = srcGenPath.substring(rootPath.length());
    return (_plus + _substring);
  }
  throw new RuntimeException(
    "Could not derive the Java model directory from the project configuration. Please set the property \'javaModelDirectory\' explicitly.");
}
 
Example #27
Source File: GrammarAccessExtensions.java    From xtext-core with 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);
}
 
Example #28
Source File: XtextGenerator.java    From xtext-core with 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 #29
Source File: XtextGeneratorNaming.java    From xtext-core with 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 #30
Source File: CategoryImplCustom.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public String getName() {

  if (!StringExtensions.isNullOrEmpty(getId())) {
    return getId();
  } else {
    return CheckUtil.toIdentifier(getLabel());
  }
}