@Override public Object caseEOperation(EOperation object) { Operation operation = new Operation(object.getName()); operation.type = getType(object.getEType()); operation.setBounds(object.getLowerBound(), object.getUpperBound()); operation.setStatic(false); operation.setScope(Scope.PUBLIC); for (EParameter epar : object.getEParameters()) { TypedElement fpar = new TypedElement(epar.getName()); fpar.type = getType(epar.getEType()); operation.addFormalParameter(fpar); } return operation; }
@Override public String getColumnText(Object element, int index) { if (element instanceof EParameter) { EParameter eParameter = (EParameter) element; StringBuilder builder = new StringBuilder(); builder.append(eParameter.getName()); builder.append(' '); builder.append(':'); builder.append(' '); return EcoreTextUtil.append(builder, eParameter.getEType()).toString(); } return getText(element); }
/** * Returns the {@link EStructuralFeature} and {@link EOperation} syntax completion proposals for * the given prefix and root. * * @param prefix the syntax prefix * @param root the root AST node * @param propertyCallType the {@link PropertyCallType} * @return the syntax completion proposals */ protected List<SyntaxCompletionProposal> getEFeatureProposals( final String prefix, final EObject root, final PropertyCallType propertyCallType) { if (propertyCallType != PropertyCallType.REGULAR || !(root instanceof org.eclipselabs.simpleocl.Module)) { return Collections.<SyntaxCompletionProposal>emptyList(); } final String strippedPrefix = stripPropertyCallPrefix(prefix); final SortedSet<String> features = new TreeSet<String>(); final Map<String, URL> images = new HashMap<String, URL>(); final Map<String, String> displayStrings = new HashMap<String, String>(); final org.eclipselabs.simpleocl.Module module = (org.eclipselabs.simpleocl.Module) root; final ExecEnv env = EmftvmFactory.eINSTANCE.createExecEnv(); loadMetamodels(module, env); for (OclMetamodel metamodel : module.getMetamodels()) { try { final URI emfURI = URI.createURI(metamodel.getUri()); final ResourceSet rs = new ResourceSetImpl(); final Resource resource = rs.getResource(emfURI, true); for (EObject eObject : new ResourceIterable(resource)) { if (!(eObject.eContainer() instanceof EClassifier)) { continue; } if (eObject instanceof EStructuralFeature || eObject instanceof EOperation) { String name = ((ETypedElement) eObject).getName(); if (strippedPrefix.isEmpty() || name.startsWith(strippedPrefix)) { StringBuilder sb = new StringBuilder(name); StringBuilder displayString = new StringBuilder(name); if (eObject instanceof EOperation) { sb.append('('); displayString.append('('); boolean first = true; for (EParameter par : ((EOperation) eObject).getEParameters()) { if (!first) { sb.append(", "); displayString.append(", "); } sb.append(par.getName()); displayString .append(par.getName()) .append(" : ") .append(toPrettyString(par, env)); first = false; } sb.append(')'); displayString.append(')'); } displayString .append(" : ") .append(toPrettyString((ETypedElement) eObject, env)) .append(" - ") .append(EMFTVMUtil.toPrettyString(eObject.eContainer(), env)); features.add(sb.toString()); ItemProviderAdapter itemProviderAdapter = (ItemProviderAdapter) ecoreItemProviderFactory.createAdapter(eObject); images.put( sb.toString(), getItemProviderImageURL(itemProviderAdapter.getImage(eObject))); displayStrings.put(sb.toString(), displayString.toString()); } } } } catch (RuntimeException e) { SimpleoclUIPlugin.logError(e.getLocalizedMessage(), e); } } return buildProposals(prefix, root, features, images, displayStrings); }