/** Replies the canonical name of the given object. * * @param object the object. * @return the canonical name or <code>null</code> if it cannot be computed. */ protected String canonicalName(EObject object) { if (object instanceof JvmIdentifiableElement) { return ((JvmIdentifiableElement) object).getQualifiedName(); } final EObject jvmElement = this.associations.getPrimaryJvmElement(object); if (jvmElement instanceof JvmIdentifiableElement) { return ((JvmIdentifiableElement) jvmElement).getQualifiedName(); } return null; }
/** Check if all the fields are initialized in a SARL behavior. * * @param behavior the behavior. */ @Check public void checkFinalFieldInitialization(SarlBehavior behavior) { final JvmGenericType inferredType = this.associations.getInferredType(behavior); if (inferredType != null) { checkFinalFieldInitialization(inferredType); } }
@Override public JvmVisibility getDefaultJvmVisibility(EObject element) { EObject realObject = element; if (realObject instanceof JvmIdentifiableElement) { final EObject obj = this.associations.getPrimarySourceElement(realObject); if (obj != null) { realObject = obj; } } if (realObject instanceof XtendMemberImplCustom) { try { return (JvmVisibility) this.visiblityMethod.invoke(realObject); } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException exception) { throw new RuntimeException(exception); } } return JvmVisibility.DEFAULT; }
assert simpleName != null; assert feature != null; final JvmOperation operation = this.associations.getDirectlyInferredOperation(feature); if (operation != null) { if (this.conversions == null) {
/** Check if the given field has a valid name. * * @param field the field to test. * @see SARLFeatureNameValidator */ @Check(CheckType.FAST) public void checkFieldName(SarlField field) { final JvmField inferredType = this.associations.getJvmField(field); final QualifiedName name = Utils.getQualifiedName(inferredType); if (this.featureNames.isDisallowedName(name)) { final String validName = Utils.fixHiddenMember(field.getName()); error(MessageFormat.format( Messages.SARLValidator_41, field.getName()), field, XTEND_FIELD__NAME, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, VARIABLE_NAME_DISALLOWED, validName); } else if (this.grammarAccess.getOccurrenceKeyword().equals(field.getName())) { error(MessageFormat.format( Messages.SARLValidator_41, this.grammarAccess.getOccurrenceKeyword()), field, XTEND_FIELD__NAME, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, VARIABLE_NAME_DISALLOWED); } }
/** Replies if the type candidate is a subtype of the given super type. * * @param candidate the type to test. * @param jvmSuperType the expected JVM super-type. * @param sarlSuperType the expected SARL super-type. * @return <code>true</code> if the candidate is a sub-type of the super-type. */ public boolean isSubTypeOf(LightweightTypeReference candidate, Class<?> jvmSuperType, Class<? extends XtendTypeDeclaration> sarlSuperType) { if (candidate.isSubtypeOf(jvmSuperType)) { return true; } if (sarlSuperType != null) { final JvmType type = candidate.getType(); if (type instanceof JvmGenericType) { final JvmGenericType genType = (JvmGenericType) type; if (genType.getSuperTypes().isEmpty()) { for (final EObject sarlObject : this.sarlAssociations.getSourceElements(type)) { if (sarlSuperType.isInstance(sarlObject)) { return true; } } } } } return false; }
private InferredPrototype getInferredPrototype(JvmOperation operation) { final XtendFunction fct = this.associations.getXtendFunction(operation); if (fct != null) { return getInferredPrototype(fct); } final QualifiedActionName actionKey = this.actionPrototypes.createQualifiedActionName( operation.getDeclaringType(), operation.getSimpleName()); // Compute the different action prototypes associated to the action to create. return this.actionPrototypes.createPrototypeFromJvmModel( actionKey, operation.isVarArgs(), operation.getParameters()); }
/** Check if the given action has a valid name. * * @param action the action to test. * @see SARLFeatureNameValidator */ @Check(CheckType.FAST) public void checkActionName(SarlAction action) { final JvmOperation inferredType = this.associations.getDirectlyInferredOperation(action); final QualifiedName name = QualifiedName.create(inferredType.getQualifiedName('.').split("\\.")); //$NON-NLS-1$ if (this.featureNames.isDisallowedName(name)) { final String validName = Utils.fixHiddenMember(action.getName()); error(MessageFormat.format( Messages.SARLValidator_39, action.getName()), action, XTEND_FUNCTION__NAME, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, INVALID_MEMBER_NAME, validName); } else if (!isIgnored(DISCOURAGED_FUNCTION_NAME) && this.featureNames.isDiscouragedName(name)) { warning(MessageFormat.format( Messages.SARLValidator_39, action.getName()), action, XTEND_FUNCTION__NAME, ValidationMessageAcceptor.INSIGNIFICANT_INDEX, DISCOURAGED_FUNCTION_NAME); } }
if (!isIgnored(VARIABLE_NAME_SHADOWING) && !Utils.isHiddenMember(field.getName())) { final JvmField inferredField = this.associations.getJvmField(field); final Map<String, JvmField> inheritedFields = new TreeMap<>(); Utils.populateInheritanceContext(
@Override protected JvmOperation deriveGenericDispatchOperationSignature( Iterable<JvmOperation> localOperations, JvmGenericType target) { final JvmOperation dispatcher = super.deriveGenericDispatchOperationSignature(localOperations, target); // // Fixing the behavior for determining the visibility of the dispatcher since // it does not fit the SARL requirements. // JvmVisibility higherVisibility = JvmVisibility.PRIVATE; for (final JvmOperation jvmOperation : localOperations) { final Iterable<XtendFunction> xtendFunctions = Iterables.filter( this.sarlAssociations.getSourceElements(jvmOperation), XtendFunction.class); for (final XtendFunction func : xtendFunctions) { JvmVisibility visibility = func.getVisibility(); if (visibility == null) { visibility = this.defaultVisibilityProvider.getDefaultJvmVisibility(func); } if (this.visibilityComparator.compare(visibility, higherVisibility) > 0) { higherVisibility = visibility; } } } dispatcher.setVisibility(higherVisibility); return dispatcher; }
/** Check if all the fields are initialized in a SARL skill. * * @param skill the skill. */ @Check public void checkFinalFieldInitialization(SarlSkill skill) { final JvmGenericType inferredType = this.associations.getInferredType(skill); if (inferredType != null) { checkFinalFieldInitialization(inferredType); } }
/** Transform the field. * * @param source the feature to transform. * @param container the target container of the transformation result. */ @Override protected void transform(XtendField source, JvmGenericType container) { super.transform(source, container); // Override the visibility final JvmField field = (JvmField) this.sarlAssociations.getPrimaryJvmElement(source); setVisibility(field, source); final GenerationContext context = getContext(container); if (context != null) { final String name = source.getName(); if (!Strings.isNullOrEmpty(name)) { context.incrementSerial(name.hashCode()); } final JvmTypeReference type = source.getType(); if (type != null) { context.incrementSerial(type.getIdentifier().hashCode()); } } }
@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; }
/** Replies the expected type of the given executable. * * @param executable the executable. * @param declaredReturnType the declared return type, if one. * @return the expected type or {@code null} if none ({@code void}). */ protected LightweightTypeReference getExpectedType(XtendExecutable executable, JvmTypeReference declaredReturnType) { if (declaredReturnType == null) { // Try to get any inferred return type. if (executable instanceof XtendFunction) { final XtendFunction function = (XtendFunction) executable; final JvmOperation operation = this.sarlAssociations.getDirectlyInferredOperation(function); if (operation != null) { return Utils.toLightweightTypeReference(operation.getReturnType(), this.services); } } if (!getEarlyExitComputer().isEarlyExit(executable.getExpression())) { return getExpectedType(executable.getExpression()); } return null; } if (!"void".equals(declaredReturnType.getIdentifier())) { //$NON-NLS-1$ return Utils.toLightweightTypeReference(declaredReturnType, this.services); } return null; }
public void checkUnsynchronizedField(XtendField field) { if (doCheckValidMemberName(field) && !isIgnored(IssueCodes.POTENTIAL_FIELD_SYNCHRONIZATION_PROBLEM)) { final JvmField jvmField = this.associations.getJvmField(field); if (jvmField == null || jvmField.eContainer() == null || jvmField.isConstant() || jvmField.isFinal()) { return;
/** Check if all the fields are initialized in a SARL agent. * * @param agent the agent. */ @Check public void checkFinalFieldInitialization(SarlAgent agent) { final JvmGenericType inferredType = this.associations.getInferredType(agent); if (inferredType != null) { checkFinalFieldInitialization(inferredType); } }
if (!isIgnored(UNUSED_AGENT_CAPACITY)) { final XtendTypeDeclaration container = uses.getDeclaringType(); final JvmDeclaredType jvmContainer = (JvmDeclaredType) this.associations.getPrimaryJvmElement(container); final Map<String, JvmOperation> importedFeatures = CollectionLiterals.newHashMap(); for (final JvmOperation operation : jvmContainer.getDeclaredOperations()) {
EObject realObject = container; if (realObject instanceof JvmIdentifiableElement) { final EObject obj = this.associations.getPrimarySourceElement(realObject); if (obj != null) { realObject = obj;
/** Check if all the fields are initialized in a SARL event. * * @param event the event. */ @Check public void checkFinalFieldInitialization(SarlEvent event) { final JvmGenericType inferredType = this.associations.getInferredType(event); if (inferredType != null) { checkFinalFieldInitialization(inferredType); } }
@Override public Object execute(ExecutionEvent event) throws ExecutionException { final IStructuredSelection activeSelection = HandlerUtil.getCurrentStructuredSelection(event); if (activeSelection != null && activeSelection != StructuredSelection.EMPTY) { final ElementDescription selectedElement = this.typeSelector.searchAndSelect(false, activeSelection.toArray()); if (selectedElement != null) { IJavaElement realJavaElement = null; if (selectedElement.element instanceof IJavaElement) { realJavaElement = (IJavaElement) selectedElement.element; } else if (selectedElement.element instanceof XtendTypeDeclaration) { final EObject jvmElement = this.sarlAssociations.getPrimaryJvmElement((XtendTypeDeclaration) selectedElement.element); if (jvmElement instanceof JvmIdentifiableElement) { realJavaElement = this.javaElementFinder.findElementFor((JvmIdentifiableElement) jvmElement); } } if (realJavaElement != null) { OpenTypeHierarchyUtil.open(realJavaElement, PlatformUI.getWorkbench().getActiveWorkbenchWindow()); } } else { final OpenTypeHierarchyAction jdtTool = new OpenTypeHierarchyAction(HandlerUtil.getActiveSite(event)); jdtTool.run(activeSelection); } } return null; }