protected String getIdentifier(JvmIdentifiableElement identifiable) { if (identifiable == null) return "/null/"; return identifiable.getIdentifier(); }
GenerationContextNotFoundInternalError(JvmIdentifiableElement type) { super("generation context cannot be found for: " + type.getIdentifier()); //$NON-NLS-1$ }
@Override public String toString() { return getClass().getSimpleName() + " [" + resolvedElement.getIdentifier() + "]"; }
private static void updateReferenceList(List<XAbstractFeatureCall> references, Set<String> identifiers, XAbstractFeatureCall featureCall) { final JvmIdentifiableElement feature = featureCall.getFeature(); if (feature instanceof JvmFormalParameter || feature instanceof XVariableDeclaration || feature instanceof JvmField) { if (identifiers.add(feature.getIdentifier())) { references.add(featureCall); } } else if (!references.contains(featureCall)) { references.add(featureCall); } }
protected String canonicalName(JvmIdentifiableElement element) { return (element != null) ? notNull(element.getIdentifier()) : null; }
/** Replies the SARL-specific generation context. * * @param type the generated type. * @return the SARL-specific generation context. */ protected final synchronized GenerationContext getContext(JvmIdentifiableElement type) { for (final GenerationContext candidate : this.bufferedContexes) { if (Objects.equal(candidate.getTypeIdentifier(), type.getIdentifier())) { return candidate; } } throw new GenerationContextNotFoundInternalError(type); }
@Override public String toString() { return String.format("%s:%s [key: %s]", getName(), getElementOrProxy().getIdentifier(), getShadowingKey()); }
private static void loopReceiver(LinkedList<String> sourceFeature, Object obj) { if (obj instanceof XMemberFeatureCall) { final XMemberFeatureCall memberFeatureCall = (XMemberFeatureCall) obj; sourceFeature.addFirst(memberFeatureCall.getFeature().getSimpleName()); loopReceiver(sourceFeature, memberFeatureCall.getMemberCallTarget()); } else if (obj instanceof XFeatureCall) { final XFeatureCall featureCall = (XFeatureCall) obj; sourceFeature.addFirst(featureCall.getFeature().getIdentifier()); } }
@Override public String getConcreteSyntaxFeatureName() { List<INode> list = NodeModelUtils.findNodesForFeature(this, XbasePackage.Literals.XABSTRACT_FEATURE_CALL__FEATURE); if (list.size()!=1) { if (feature == null || feature.eIsProxy()) return "<unkown>"; return String.format("<implicit: %s>", feature.getIdentifier()); } INode node = list.get(0); if (node instanceof ILeafNode) { return node.getText(); } StringBuilder result = new StringBuilder(); for(ILeafNode leafNode: node.getLeafNodes()) { if (!leafNode.isHidden()) result.append(leafNode.getText()); } return result.toString(); }
/** Check if the call is forbidden. * * <p>One example of a forbidden feature is {@link System#exit(int)}. * * @param expression the expression. */ @Check(CheckType.FAST) public void checkForbiddenCalls(XAbstractFeatureCall expression) { if (this.featureCallValidator.isDisallowedCall(expression)) { error( MessageFormat.format( Messages.SARLValidator_36, expression.getFeature().getIdentifier()), expression, null, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, FORBIDDEN_REFERENCE); } }
/** Check for usage of the event functions in the behavior units. * * @param unit the unit to analyze. */ @Check(CheckType.EXPENSIVE) public void checkUnmodifiableEventAccess(SarlBehaviorUnit unit) { final boolean enable1 = !isIgnored(IssueCodes.DISCOURAGED_OCCURRENCE_READONLY_USE); final XExpression root = unit.getExpression(); final String occurrenceKw = this.grammarAccess.getOccurrenceKeyword(); for (final XFeatureCall child : EcoreUtil2.getAllContentsOfType(root, XFeatureCall.class)) { if (occurrenceKw.equals(child.getFeature().getIdentifier())) { checkUnmodifiableFeatureAccess(enable1, child, occurrenceKw); } } }
/** Convert a full call to a feature. * * <p>This function is supposed to change the two list parameters for reflecting the conversion. * * @param simpleName the simple name of the feature to be called. * @param calledFeature the called feature. * @param leftOperand the description of the elements into the left operand (usually, before assignment sign). * @param receiver the description of the receiver, i.e. the object on which the feature is called. * @param arguments the list of the arguments. * @return a description of the conversion; or {@code null} for ignoring the call. */ public ConversionResult convertFeatureCall(String simpleName, JvmIdentifiableElement calledFeature, List<Object> leftOperand, List<Object> receiver, List<XExpression> arguments) { if (this.conversions == null) { this.conversions = initMapping(); } final List<Pair<FeaturePattern, FeatureReplacement>> struct = this.conversions.get(getKey(simpleName)); if (struct != null) { final String replacementId = calledFeature.getIdentifier(); final FeatureReplacement replacement = matchFirstPattern(struct, replacementId, simpleName, receiver); if (replacement != null) { if (replacement.hasReplacement()) { return replacement.replace(calledFeature, leftOperand, receiver, arguments); } return null; } } return new ConversionResult(simpleName); }
id = ((JvmTypeReference) eobject).getIdentifier(); } else if (eobject instanceof JvmIdentifiableElement) { id = ((JvmIdentifiableElement) eobject).getIdentifier(); } else { id = null;
/** Test if the given expression has side effects. * * @param expression the expression. * @param context the list of context expressions. * @return {@code true} if the expression has side effects. */ protected Boolean _hasSideEffects(XAssignment expression, ISideEffectContext context) { if (internalHasOperationSideEffects(expression, context, true)) { return true; } if (hasSideEffects(expression.getValue(), context)) { return true; } final JvmIdentifiableElement feature = expression.getFeature(); if (feature instanceof XVariableDeclaration) { context.assignVariable(feature.getIdentifier(), expression.getValue()); } return false; }
final List<Pair<FeaturePattern, FeatureReplacement>> struct = this.conversions.get(getKey(simpleName)); if (struct != null) { final String replacementId = featureCall.getFeature().getIdentifier(); final FeatureReplacement replacement = matchFirstPattern(struct, replacementId, simpleName, receiver); if (replacement != null) {
@Override protected boolean isInitialized(JvmField input) { if (super.isInitialized(input)) { return true; } // Check initialization into a static constructor. final XtendField sarlField = (XtendField) this.associations.getPrimarySourceElement(input); if (sarlField == null) { return false; } final XtendTypeDeclaration declaringType = sarlField.getDeclaringType(); if (declaringType == null) { return false; } for (final XtendConstructor staticConstructor : Iterables.filter(Iterables.filter( declaringType.getMembers(), XtendConstructor.class), it -> it.isStatic())) { if (staticConstructor.getExpression() != null) { for (final XAssignment assign : EcoreUtil2.getAllContentsOfType(staticConstructor.getExpression(), XAssignment.class)) { if (assign.isStatic() && Strings.equal(input.getIdentifier(), assign.getFeature().getIdentifier())) { // Mark the field as initialized in order to be faster during the next initialization test. this.readAndWriteTracking.markInitialized(input, null); return true; } } } } return false; }
"A value of type '" + rightType.getQualifiedName('.') + "' can not be assigned to the feature " + feature.getIdentifier(), Mwe2Package.Literals.ASSIGNMENT__VALUE, ValidationMessageAcceptor.INSIGNIFICANT_INDEX,
@Override public String getFragment(EObject obj, IFragmentProvider.Fallback fallback) { if (obj instanceof JvmTypeParameter) return getFragment(obj.eContainer(), fallback) + "/" + ((JvmTypeParameter) obj).getName(); if (obj instanceof JvmTypeReference || obj instanceof JvmFormalParameter) return fallback.getFragment(obj); if (obj instanceof JvmIdentifiableElement) { if (obj instanceof JvmArrayType) { if (obj.eContainer() instanceof JvmGenericArrayTypeReference) return fallback.getFragment(obj); if (obj.eContainer() instanceof JvmIdentifiableElement) { return getFragment(obj.eContainer(), fallback) + "[]"; } } return ((JvmIdentifiableElement) obj).getIdentifier(); } return fallback.getFragment(obj); }
public String getFragment(EObject obj, IFragmentProvider.Fallback fallback) { if (obj instanceof JvmTypeParameter) return getFragment(obj.eContainer(), fallback) + "/" + ((JvmTypeParameter) obj).getName(); if (obj instanceof JvmTypeReference || obj instanceof JvmFormalParameter) return fallback.getFragment(obj); if (obj instanceof JvmIdentifiableElement) { if (obj instanceof JvmArrayType) { if (obj.eContainer() instanceof JvmGenericArrayTypeReference) return fallback.getFragment(obj); if (obj.eContainer() instanceof JvmIdentifiableElement) { return getFragment(obj.eContainer(), fallback) + "[]"; } } return ((JvmIdentifiableElement) obj).getIdentifier(); } return fallback.getFragment(obj); }
private static boolean isCalledOperation(JvmOperation operation, List<InferredPrototype> prototypes) { final String container = operation.getDeclaringType().getQualifiedName(); for (final InferredPrototype prototype : prototypes) { if (Strings.equal(container, prototype.getActionName().getDeclaringType().getIdentifier()) && Strings.equal(operation.getSimpleName(), prototype.getActionName().getActionName())) { final String prefix = container + "."; //$NON-NLS-1$ final String operationId = operation.getIdentifier(); for (final ActionParameterTypes types : prototype.getParameterTypeAlternatives()) { String name = prefix + types.toActionPrototype(operation.getSimpleName()).toString(); if (Strings.equal(operationId, name)) { return true; } name = prefix + types.toRawActionPrototype(operation.getSimpleName()).toString(); if (Strings.equal(operationId, name)) { return true; } } } } return false; }