Java源码示例:org.eclipse.xtext.xbase.lib.StringExtensions
示例1
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);
}
示例2
@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);
});
}
});
}
示例3
@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);
}
示例4
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;
}
示例5
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;
}
示例6
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;
}
示例7
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;
}
示例8
@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;
}
示例9
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;
}
示例10
@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;
}
示例11
@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;
}
示例12
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);
}
示例13
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);
}
示例14
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);
}
示例15
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);
}
示例16
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);
}
示例17
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);
}
示例18
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);
}
}
}
示例19
@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);
}
示例20
@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)
);
}
});
}
示例21
@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());
});
}
示例22
@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));
}
}
示例23
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;
}
示例24
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);
}
}
示例25
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);
}
}
示例26
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;
}
示例27
/**
* @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);
}
示例28
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();
}
示例29
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();
}
}
}
示例30
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);
}