/** * Returns the packageName: PatternModel.packageName + Pattern.name, packageName is ignored, when nullOrEmpty. */ public String getPackageNameOld(final Pattern pattern) { EObject _eContainer = pattern.eContainer(); String packageName = ((PatternModel) _eContainer).getPackageName(); boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(packageName); if (_isNullOrEmpty) { packageName = ""; } else { packageName = (packageName + "."); } String _name = pattern.getName(); String _plus = (packageName + _name); return _plus.toLowerCase(); }
/** * Returns the name of the container package of the selected pattern * @return a name of the pattern; never null, but may be empty string */ public static String getPackageName(Pattern pattern) { if(pattern == null || pattern.eIsProxy()) { return ""; } PatternModel patternModel = (PatternModel) pattern.eContainer(); return (patternModel == null) ? null : patternModel.getPackageName(); }
@Check public void checkPrivatePatternCall(PatternCall call) { final Pattern calledPattern = call.getPatternRef(); if (calledPattern != null) { if (Iterables.any(calledPattern.getModifiers(), new Predicate<Modifiers>() { @Override public boolean apply(Modifiers input) { return input.isPrivate(); } }) && calledPattern.eResource() != call.eResource()) { error(String.format("The pattern %s is not visible.", getFormattedPattern(calledPattern)), PatternLanguagePackage.Literals.PATTERN_CALL__PATTERN_REF, IssueCodes.PRIVATE_PATTERN_CALLED); } } }
private String getFormattedPattern(Pattern pattern) { StringBuilder builder = new StringBuilder(); builder.append(pattern.getName()); builder.append("("); for (Iterator<Variable> iter = pattern.getParameters().iterator(); iter.hasNext();) { builder.append(iter.next().getName()); if (iter.hasNext()) { builder.append(", "); } } builder.append(")"); return builder.toString(); }
/** * Returns the parameter of a pattern by name * * @param pattern * @param name * @return the requested parameter of the pattern, or null if none exists * @since 0.7.0 */ public static Variable getParameterByName(final Pattern pattern, final String name) { return Iterables.find(pattern.getParameters(), new Predicate<Variable>() { @Override public boolean apply(Variable variable) { return name.equals(variable.getName()); } }, null); }
/** * Returns the name of the pattern, qualified by package name. */ public static String getFullyQualifiedName(Pattern pattern) { String packageName = getPackageName(pattern); if (packageName == null || packageName.isEmpty()) { return pattern.getName(); } else { return packageName + "." + pattern.getName(); } // TODO ("local pattern?") }
public Set<PBody> getBodies(Pattern pattern, PQuery query) throws QueryInitializationException { PatternBodyTransformer transformer = new PatternBodyTransformer(pattern); Set<PBody> pBodies = Sets.newLinkedHashSet(); for (PatternBody body : pattern.getBodies()) { EPMToPBody acceptor = new EPMToPBody(pattern, query, patternMap); PBody pBody = transformer.transform(body, acceptor); pBodies.add(pBody); } return pBodies; }
Map<String, Pattern> newPatternsByName = new HashMap<String, Pattern>(); for (Pattern current : newPatterns) { if (current == null || current.eIsProxy()) { nullPatternFound = true; problemsByPattern.put(current, new PProblem("Null/proxy pattern value")); currentPattern.eResource() == null ? null : currentPattern.eResource().getResourceSet();
for (PatternBody patternBody : pattern.getBodies()) { for (Variable variable : patternBody.getVariables()) { Set<EClassifier> possibleClassifiers = emfTypeProvider.getIrreducibleClassifiersForVariableInBody( } else { boolean isParameter = false; for (Variable parameter : pattern.getParameters()) { if (parameter.getName().equals(variable.getName())) { isParameter = true;
/** * Returns the first annotation of a given name from a pattern. This method ignores multiple defined annotations by * the same name. For getting a filtered collections of annotations, see * {@link #getAnnotationsByName(Pattern, String)} * * @param pattern * the pattern instance * @param name * the name of the annotation to return * @returns the first annotation or null if no such annotation exists * @since 0.7.0 */ public static Annotation getFirstAnnotationByName(Pattern pattern, String name) { return Iterables.find(pattern.getAnnotations(), new AnnotationNameFilter(name), null); }
@Override public boolean apply(Pattern pattern) { final String name = CorePatternLanguageHelper.getFullyQualifiedName(pattern); return !pattern.eIsProxy() && !"".equals(name) && !patternMap.containsKey(name); } }));
Set<Resource> containerResources = new HashSet<Resource>(); for (Pattern pattern : patternSet) { Resource resource = pattern.eResource(); if (resource != null) { containerResources.add(resource);
/** * Returns the packageName: PatternModel.packageName or "" when nullOrEmpty. */ public String getPackageName(final Pattern pattern) { EObject _eContainer = pattern.eContainer(); String packageName = ((PatternModel) _eContainer).getPackageName(); boolean _isNullOrEmpty = StringExtensions.isNullOrEmpty(packageName); if (_isNullOrEmpty) { packageName = ""; } return packageName.toLowerCase(); }
/** * @param pattern * @return true if the pattern contains xbase check() or eval() expressions, false otherwise. */ public static boolean hasXBaseExpression(Pattern pattern) { final TreeIterator<EObject> eAllContents = pattern.eAllContents(); while (eAllContents.hasNext()) { if (eAllContents.next() instanceof XExpression) return true; } return false; }
/** * @param pattern * @return true if the pattern has a private modifier, false otherwise. */ public static boolean isPrivate(Pattern pattern) { for (Modifiers mod : pattern.getModifiers()) { if (mod.isPrivate()) { return true; } } return false; }
@Override public List<PParameter> getParameters() { return Lists.transform(pattern.getParameters(), new Function<Variable, PParameter>() { @Override public PParameter apply(Variable var) { if (var == null) { return new PParameter("", ""); } else { IEMFTypeProvider typeProvider = XtextInjectorProvider.INSTANCE.getInjector().getInstance(IEMFTypeProvider.class); JvmTypeReference ref = typeProvider.getVariableType(var); // bug 411866: JvmUnknownTypeReference.getType() returns null in Xtext 2.4 String clazz = (ref == null || ref instanceof JvmUnknownTypeReference) ? "" : ref.getType() .getQualifiedName(); return new PParameter(var.getName(), clazz); } } }); }
/** * This method returns the pattern name. * If the pattern name contains the package (any dot), * then removes all segment except the last one. */ public String realPatternName(final Pattern pattern) { String name = pattern.getName(); boolean _contains = name.contains("."); if (_contains) { int _lastIndexOf = name.lastIndexOf("."); int _plus = (_lastIndexOf + 1); return name.substring(_plus); } return name; }
private static String getExpressionPostfix(final XExpression xExpression) { final Pattern pattern = EcoreUtil2.<Pattern>getContainerOfType(xExpression, Pattern.class); boolean _notEquals = (!Objects.equal(pattern, null)); Preconditions.checkArgument(_notEquals, "Expression is not inside a pattern"); int bodyNo = 0; EList<PatternBody> _bodies = pattern.getBodies(); for (final PatternBody patternBody : _bodies) { { bodyNo = (bodyNo + 1); int exNo = 0; Collection<XExpression> _allTopLevelXBaseExpressions = CorePatternLanguageHelper.getAllTopLevelXBaseExpressions(patternBody); for (final XExpression xExpression2 : _allTopLevelXBaseExpressions) { { exNo = (exNo + 1); boolean _equals = xExpression.equals(xExpression2); if (_equals) { String _plus = (Integer.valueOf(bodyNo) + "_"); return (_plus + Integer.valueOf(exNo)); } } } } } throw new RuntimeException("Expression not found in pattern"); } }
@Check public void checkPatternCallParameters(PatternCall call) { if (call.getPatternRef() != null && call.getPatternRef().getName() != null && call.getParameters() != null) { final int definitionParameterSize = call.getPatternRef().getParameters().size(); final int callParameterSize = call.getParameters().size(); if (definitionParameterSize != callParameterSize) { error("The pattern " + getFormattedPattern(call.getPatternRef()) + " is not applicable for the arguments(" + getFormattedArgumentsList(call) + ")", PatternLanguagePackage.Literals.PATTERN_CALL__PATTERN_REF, IssueCodes.WRONG_NUMBER_PATTERNCALL_PARAMETER); } } }
/** * Returns the collection of annotations of a pattern by a name. For getting the first annotations by name, see * {@link #getAnnotationByName(Pattern, String)} * * @param pattern * the pattern instance * @param name * the name of the annotation to return * @returns a non-null, but possibly empty collection of annotations * @since 0.7.0 */ public static Collection<Annotation> getAnnotationsByName(Pattern pattern, String name) { return Collections2.filter(pattern.getAnnotations(), new AnnotationNameFilter(name)); }