public String migrate(String formattedString, String toBeFormattedString, Pattern format) { if (Strings.isEmpty(toBeFormattedString) || Strings.isEmpty(formattedString)) return toBeFormattedString; FormattedString formatted = createFormattedString(formattedString, format); FormattedString toBeFormatted = createFormattedString(toBeFormattedString, format); if (formatted.semantic.equals(toBeFormatted.semantic)) return formattedString; List<Mapping> mappings = Lists.newArrayList(); List<Region> remainingRegions = Lists.newArrayList(); findLinearMatches(formatted, toBeFormatted, mappings, remainingRegions); for (Mapping m : mappings) toBeFormatted.migrateFrom(formatted, m); return toBeFormatted.toString(); }
@Override public String getQualifiedName(char innerClassDelimiter) { if (simpleName == null) return null; JvmDeclaredType declaringType = getDeclaringType(); if (declaringType == null) { if (Strings.isEmpty(packageName)) return simpleName; return packageName + "." + simpleName; } String parentName = declaringType.getQualifiedName(innerClassDelimiter); if (parentName == null) return null; return parentName + innerClassDelimiter + simpleName; }
@Override protected String computeIdentifier() { if (simpleName == null) return null; JvmDeclaredType declaringType = internalGetDeclaringType(); if (declaringType == null) { if (Strings.isEmpty(packageName)) return simpleName; return packageName + "." + simpleName; } String parentName = declaringType.getIdentifier(); if (parentName == null) return null; return parentName + '$' + simpleName; }
@Override protected List<ImportNormalizer> internalGetImportedNamespaceResolvers( EObject context, boolean ignoreCase) { if (!(context instanceof XtendFile)) return Collections.emptyList(); List<ImportNormalizer> importedNamespaceResolvers = super.internalGetImportedNamespaceResolvers(context, ignoreCase); if (context instanceof XtendFile && !Strings.isEmpty(((XtendFile) context).getPackage())) { importedNamespaceResolvers.add( new ImportNormalizer( nameConverter.toQualifiedName(((XtendFile) context).getPackage()), true, ignoreCase)); } return importedNamespaceResolvers; }
public Number toValue(String string, INode node) { if (Strings.isEmpty(string)) throw new ValueConverterException("Couldn't convert empty string to number", node, null); try { if (string.contains(".") || string.contains("e") || string.contains("e")) { return new BigDecimal(string); } else { return new BigInteger(string); } } catch (NumberFormatException e) { throw new ValueConverterException("Couldn't convert '" + string + "' to number", node, e); } }
/** * Create a new {@link ImportNormalizer} for the given namespace. * * @param namespace the namespace. * @param ignoreCase <code>true</code> if the resolver should be case insensitive. * @return a new {@link ImportNormalizer} or <code>null</code> if the namespace cannot be * converted to a valid qualified name. */ protected ImportNormalizer createImportedNamespaceResolver( final String namespace, boolean ignoreCase) { if (Strings.isEmpty(namespace)) return null; QualifiedName importedNamespace = qualifiedNameConverter.toQualifiedName(namespace); if (importedNamespace == null || importedNamespace.getSegmentCount() < 1) { return null; } boolean hasWildcard = ignoreCase ? importedNamespace.getLastSegment().equalsIgnoreCase(getWildcard()) : importedNamespace.getLastSegment().equals(getWildcard()); if (hasWildcard) { if (importedNamespace.getSegmentCount() <= 1) return null; return doCreateImportNormalizer(importedNamespace.skipLast(1), true, ignoreCase); } else { return doCreateImportNormalizer(importedNamespace, false, ignoreCase); } }
public String check(IEObjectDescription input) { if (input instanceof IValidatedEObjectDescription) { final IValidatedEObjectDescription validatedDescription = (IValidatedEObjectDescription) input; JvmIdentifiableElement identifiable = validatedDescription.getEObjectOrProxy(); if (identifiable.eIsProxy()) identifiable = (JvmIdentifiableElement) EcoreUtil.resolve(identifiable, context); String issueCode; if (identifiable.eIsProxy()) issueCode = UNRESOLVABLE_PROXY; else if (!validatedDescription.isValid()) { if (Strings.isEmpty(validatedDescription.getIssueCode())) issueCode = FEATURE_NOT_VISIBLE; else return validatedDescription.getIssueCode(); } else issueCode = dispatcher.invoke(identifiable, context, reference, validatedDescription); validatedDescription.setIssueCode(issueCode); return issueCode; } return null; }
protected IScope getLocalElementsScope( IScope parent, IScope globalScope, EObject context, EReference reference) { IScope result = parent; QualifiedName name = getQualifiedNameOfLocalElement(context); boolean ignoreCase = isIgnoreCase(reference); ISelectable resourceOnlySelectable = getAllDescriptions(context.eResource()); ISelectable globalScopeSelectable = new ScopeBasedSelectable(globalScope); // imports List<ImportNormalizer> explicitImports = getImportedNamespaceResolvers(context, ignoreCase); if (!explicitImports.isEmpty()) { result = createImportScope( result, explicitImports, globalScopeSelectable, reference.getEReferenceType(), ignoreCase); } // local element if (name != null) { ImportNormalizer localNormalizer = doCreateImportNormalizer(name, true, ignoreCase); result = createImportScope( result, singletonList(localNormalizer), resourceOnlySelectable, reference.getEReferenceType(), ignoreCase); } // scope for jvm elements Set<EObject> elements = associations.getJvmElements(context); for (EObject derivedJvmElement : elements) { // scope for JvmDeclaredTypes if (derivedJvmElement instanceof JvmDeclaredType) { JvmDeclaredType declaredType = (JvmDeclaredType) derivedJvmElement; QualifiedName jvmTypeName = getQualifiedNameOfLocalElement(declaredType); if (declaredType.getDeclaringType() == null && !Strings.isEmpty(declaredType.getPackageName())) { QualifiedName packageName = this.qualifiedNameConverter.toQualifiedName(declaredType.getPackageName()); ImportNormalizer normalizer = doCreateImportNormalizer(packageName, true, ignoreCase); result = createImportScope( result, singletonList(normalizer), globalScopeSelectable, reference.getEReferenceType(), ignoreCase); } if (jvmTypeName != null && !jvmTypeName.equals(name)) { ImportNormalizer localNormalizer = doCreateImportNormalizer(jvmTypeName, true, ignoreCase); result = createImportScope( result, singletonList(localNormalizer), resourceOnlySelectable, reference.getEReferenceType(), ignoreCase); } } // scope for JvmTypeParameterDeclarator if (derivedJvmElement instanceof JvmTypeParameterDeclarator) { JvmTypeParameterDeclarator parameterDeclarator = (JvmTypeParameterDeclarator) derivedJvmElement; List<IEObjectDescription> descriptions = null; for (JvmTypeParameter param : parameterDeclarator.getTypeParameters()) { if (param.getSimpleName() != null) { if (descriptions == null) descriptions = Lists.newArrayList(); QualifiedName paramName = QualifiedName.create(param.getSimpleName()); descriptions.add(EObjectDescription.create(paramName, param)); } } if (descriptions != null && !descriptions.isEmpty()) result = MapBasedScope.createScope(result, descriptions); } } return result; }
String text(PuppetManifest ele) { String s = ele.eResource().getURI().lastSegment(); return Strings.isEmpty(s) ? "<unnamed>" : URI.decode(s); }