/** * Returns the name of the type with its qualified name * * @param type a type * @return the name of the type with its qualified name */ public static String getTypeLabel(Type type, Namespace model) { String label = ""; // $NON-NLS-1$ List<Package> importedPackages = new ArrayList<Package>(model.getImportedPackages()); List<Package> visitedPackages = new ArrayList<Package>(); Package currentPackage = type.getNearestPackage(); boolean rootFound = false; while (currentPackage != null && !rootFound) { visitedPackages.add(currentPackage); if (importedPackages.contains(currentPackage) || currentPackage == model) { rootFound = true; } Element owner = currentPackage.getOwner(); while (owner != null && !(owner instanceof Package)) owner = owner.getOwner(); currentPackage = owner != null ? (Package) owner : null; } for (int i = visitedPackages.size() - 1; i >= 0; i--) { label += visitedPackages.get(i).getName() + "::"; // $NON-NLS-1$ } return label + type.getName(); }
/** * Utility methods which returns the list of classifiers that are directly or indirectly owned by * the namespaces imported by a context namespace * * @param context The context namespace * @return the list of classifiers that are directly or indirectly owned by the namespaces * imported by the context namespace */ private List<Classifier> getRecursivelyImportedClassifiers(Namespace context) { List<Classifier> recursivelyImportedClassifiers = new ArrayList<Classifier>(); List<Package> importedPackages = context.getImportedPackages(); for (Package p : importedPackages) { recursivelyImportedClassifiers.addAll(getRecursivelyOwnedClassifiers(p)); } return recursivelyImportedClassifiers; }
/** * Provides custom completion for the root element in a qualified name * * @see * org.eclipse.papyrus.uml.textedit.property.xtext.ui.contentassist.AbstractUmlPropertyProposalProvider#completeTypeRule_Path(org.eclipse.emf.ecore.EObject, * org.eclipse.xtext.Assignment, * org.eclipse.xtext.ui.editor.contentassist.ContentAssistContext, * org.eclipse.xtext.ui.editor.contentassist.ICompletionProposalAcceptor) */ @Override public void completeTypeRule_Path( EObject model, Assignment assignment, ContentAssistContext context, ICompletionProposalAcceptor acceptor) { Namespace root = (Namespace) EcoreUtil.getRootContainer(ContextElementUtil.getContextElement(model.eResource())); if (root == null) { return; } // first accept the root Model String completionString = root.getName() + "::"; String displayString = root.getName() + "::"; // String displayString = c.getName() ; CustomCompletionProposal completionProposal = CompletionProposalUtils.createCompletionProposalWithReplacementOfPrefix( root, completionString, displayString, context); acceptor.accept(completionProposal); // then accepts all packages imported by Model List<Package> importedPackages = root.getImportedPackages(); for (Package p : importedPackages) { if (p.getName().toLowerCase().contains(context.getPrefix().toLowerCase())) { completionString = p.getName() + "::"; displayString = p.getName() + "::"; // String displayString = c.getName() ; completionProposal = CompletionProposalUtils.createCompletionProposalWithReplacementOfPrefix( root, completionString, displayString, context); acceptor.accept(completionProposal); } } }