if (!ns.isGlobal()) { for (CsmProject lib : ns.getProject().getLibraries()) { CsmNamespace n = lib.findNamespace(ns.getQualifiedName()); if (n != null && !handledNS.contains(n)) { filterDeclarations(n, res, kinds, strPrefix, match, returnUnnamedInCurrentNs); Collection<CsmNamespace> namespacesToSearchIn = searchNestedUnnamedNamespaces ? ns.getNestedNamespaces() : ns.getInlinedNamespaces(); CsmNamespace nestedNs = (CsmNamespace) it.next(); boolean goDeeper = (searchNestedUnnamedNamespaces && nestedNs.getName().length() == 0) || nestedNs.isInline(); CsmNamespace parentNS = ns.getParent(); while(parentNS != null && !handledNS.contains(parentNS) && !ns.isGlobal()) { handledNS.add(parentNS); strPrefix = ns.getName() + SCOPE + strPrefix; // NOI18N filterDeclarations(parentNS, res, kinds, strPrefix, match, returnUnnamedInParentNs); parentNS = parentNS.getParent();
@Override public Iterator<CsmOffsetableDeclaration> getDeclarations(CsmNamespace namespace, CsmFilter filter) { if (namespace instanceof NamespaceImpl){ Iterator<CsmOffsetableDeclaration> res = analyzeFilter((NamespaceImpl)namespace, filter); if (res != null) { return res; } return ((NamespaceImpl)namespace).getDeclarations(filter); } return namespace.getDeclarations().iterator(); }
private Action createOpenAction() { CsmNamespace ns = getNamespace(); if (ns != null){ Collection<? extends CsmOffsetableDeclaration> arr = ns.getDefinitions(); if (arr.size() > 0) { return new GoToDeclarationAction(arr.iterator().next()); } } return null; }
@Override public String getItemText() { return displayFullNamespacePath ? pkg.getQualifiedName().toString() : pkg.getName().toString(); }
public static CharSequence getQualifiedName(CharSequence name, CsmNamespace parent) { if (parent != null && !parent.isGlobal()) { return CharSequenceUtils.concatenate(parent.getQualifiedName(), "::", name); // NOI18N } return name; }
NamespaceBaseKey(CsmNamespace ns) { super(((ProjectBase) ns.getProject()).getUnitId()); this.fqn = ns.getQualifiedName(); }
private Map<CharSequence, CsmNamespace> getNestedNamespaces(CsmNamespace ns, String strPrefix, boolean match, Set<CsmNamespace> handledNS) { Map<CharSequence, CsmNamespace> res = new LinkedHashMap<CharSequence, CsmNamespace>(); // order is important if(ns != null) { handledNS.add(ns); CsmProject nsProject = ns.getProject(); if(nsProject != null) { // handle all nested namespaces for (CsmProject lib : nsProject.getLibraries()) { CsmNamespace n = lib.findNamespace(ns.getQualifiedName()); if (n != null && !handledNS.contains(n)) { res.putAll(getNestedNamespaces(n, strPrefix, match, handledNS)); } } for (Iterator it = ns.getNestedNamespaces().iterator(); it.hasNext();) { CsmNamespace nestedNs = (CsmNamespace) it.next(); // TODO: consider when we add nested namespaces if ((nestedNs.getName().length() != 0) && matchName(nestedNs.getName(), strPrefix, match)) { res.put(nestedNs.getQualifiedName(), nestedNs); // TODO: Think if we really need nested namespaces here if (nestedNs.isInline()) { res.putAll(getNestedNamespaces(nestedNs, strPrefix, match, handledNS)); } } } } } return res; }
@Override public Collection<CsmDeclaration> findUsedDeclarations(CsmNamespace namespace) { List<CsmUsingDeclaration> res = new ArrayList<>(); Iterator<CsmOffsetableDeclaration> udecls = CsmSelect.getDeclarations( namespace, CsmSelect.getFilterBuilder().createKindFilter(CsmDeclaration.Kind.USING_DECLARATION)); while (udecls.hasNext()) { res.add((CsmUsingDeclaration) udecls.next()); } // Let's also look for similarly named namespace in libraries, // like it's done in CsmProjectContentResolver.getNamespaceMembers() if (!namespace.isGlobal()) { for(CsmProject lib : namespace.getProject().getLibraries()){ CsmNamespace ns = lib.findNamespace(namespace.getQualifiedName()); if (ns != null) { Iterator<CsmOffsetableDeclaration> it = CsmSelect.getDeclarations( ns, CsmSelect.getFilterBuilder().createKindFilter(CsmDeclaration.Kind.USING_DECLARATION)); while (it.hasNext()) { res.add((CsmUsingDeclaration) it.next()); } } } } return extractDeclarations(res); }
@Override public CharSequence getQualifiedName() { return wrapped.getQualifiedName(); }
private CsmNamespace findNamespace(CsmNamespace ns, CharSequence qualifiedNamePart) { CsmNamespace result = null; if (ns == null) { result = findNamespace(qualifiedNamePart); } else { CsmNamespace containingNs = ns; while (containingNs != null && result == null) { String fqn = (containingNs.isGlobal() ? "" : (containingNs.getQualifiedName() + "::")) + qualifiedNamePart; // NOI18N result = findNamespace(fqn); if (result == null) { result = findNamespaceInInlined(containingNs, qualifiedNamePart); } containingNs = containingNs.getParent(); } } return result; }
/** * Finds all namespaces visible in given namespace (unnamed, inlined or through "using" directives). * * @param namespace namespace of interest * @return unmodifiable collection of namespaces visible in given namespace though "using" directives */ @Override public Collection<CsmNamespace> findVisibleNamespaces(CsmNamespace namespace, CsmProject startPrj) { List<CsmNamespace> res = new ArrayList<>(); if (!namespace.isGlobal()) { for (CsmNamespace ns : namespace.getNestedNamespaces()) { if (ns.getName().length() == 0 || ns.isInline()) { res.add(ns); } } } res.addAll(extractNamespaces(findUsingDirectives(namespace), startPrj)); return res; }
private CsmNamespace findNamespaceInInlined(CsmNamespace ns, CharSequence qualifiedNamePart) { CsmNamespace result = null; if (ns != null) { for (CsmNamespace inlinedNs : ns.getInlinedNamespaces()) { String fqn = (inlinedNs.isGlobal() ? "" : (inlinedNs.getQualifiedName() + "::")) + qualifiedNamePart; // NOI18N result = findNamespace(fqn); if (result == null) { result = findNamespaceInInlined(inlinedNs, qualifiedNamePart); } if (result != null) { break; } } } return result; }
public static CharSequence getNamespaceDisplayName(CsmNamespace ns){ CharSequence displayName = ns.getName(); if (displayName.length() == 0) { Collection<CsmNamespaceDefinition> definitions = ns.getDefinitions(); CharSequence fileName = null; if (definitions.size() == 1) { CsmNamespaceDefinition def = definitions.iterator().next(); CsmScope file = def.getScope(); if (file instanceof CsmFile) { fileName = ((CsmFile)file).getName(); } } displayName = ns.getQualifiedName(); int scope = CharSequenceUtils.lastIndexOf(displayName, "::"); // NOI18N if (scope != -1) { displayName = displayName.subSequence(scope + 2, displayName.length()); } int start = CharSequenceUtils.indexOf(displayName, '<'); int end = CharSequenceUtils.indexOf(displayName, '>'); if (start >=0 && end >= 0 && start < end && fileName != null) { CharSequence name = displayName.subSequence(start+1, end); displayName = name+" ("+fileName+")"; // NOI18N } else { if (CharSequenceUtils.indexOf(displayName, '<') >=0 || CharSequenceUtils.indexOf(displayName, '>') >=0) { // NOI18N displayName = displayName.toString().replace('<', ' ').replace('>', ' '); // NOI18N } } } return NameCache.getManager().getString(displayName); }
ns = (CsmNamespace)nsObj; CharSequence token = nameTokens[i]; nsName = ns.getQualifiedName() + "::" + token; // NOI18N } else { break; StringBuilder sb = new StringBuilder(ns.getQualifiedName()); for (int j = i; j < nameTokens.length; j++) { sb.append("::"); // NOI18N Collection<CsmNamespace> namespaces = ns.getNestedNamespaces(); for (CsmNamespace namespace : namespaces) { if (namespace.getName().toString().equals(name.toString())) { newNs = namespace; break;
/** it's a list, not just collection because order matters */ private List<CsmNamespace> getContextNamespaces(CsmContext context) { CsmNamespace ns = CsmContextUtilities.getNamespace(context); List<CsmNamespace> out = new ArrayList<CsmNamespace>(); while (ns != null && !ns.isGlobal()) { out.add(ns); ns = ns.getParent(); } return out; }
private Collection<CsmNamespace> filterNamespaces(Collection<CsmNamespace> orig, CsmProject prj) { LinkedHashSet<CsmNamespace> out = new LinkedHashSet<CsmNamespace>(orig.size()); for (CsmNamespace ns : orig) { if (ns != null && (prj == null || ns.getProject() == prj)) { out.add(ns); } } return out; } }
private CsmClassifier findClassifier(CsmNamespace ns, CharSequence qualifiedNamePart, AtomicBoolean outVisibility) { outVisibility.set(false); CsmClassifier result = null; CsmClassifier backupResult = null; while ( ns != null && result == null) { String fqn = ns.getQualifiedName() + "::" + qualifiedNamePart; // NOI18N CsmClassifier aCls = findClassifierUsedInFile(fqn, outVisibility); if (aCls != null) { if (!ForwardClass.isForwardClass(aCls) || needForwardClassesOnly()) { if (outVisibility.get()) { return aCls; } } if (backupResult == null) { backupResult = aCls; } } ns = ns.getParent(); } if (result == null) { result = backupResult; } return result; }
@Override public boolean isGlobal() { return wrapped.isGlobal(); }
private CsmObject resolveInInlinedNamespacesImpl(CsmObject result, Set<CharSequence> checked, CsmNamespace namespace, CharSequence nameToken, AtomicBoolean outVisibility) { if (result == null || !outVisibility.get()) { for (CsmNamespace ns : namespace.getInlinedNamespaces()) { final CharSequence name = ns.getQualifiedName(); if (checked.add(name)) { String fqn = name + "::" + nameToken; // NOI18N if (fqn.startsWith("::")) { // NOI18N fqn = fqn.substring(2); } result = findClassifierUsedInFile(fqn, outVisibility); result = resolveInInlinedNamespacesImpl(result, checked, ns, nameToken, outVisibility); if (result != null && outVisibility.get()) { break; } } } } return result; }
private void resolveContext(CsmNamespace context, CharSequence qualifiedName[], int current, Collection<CsmObject> result) { CharSequence[] cnn = qualifiedName; if (current >= cnn.length - 1) { result.add(context); return; } CsmSelect.CsmFilter filter = createNamespaceFilter(qualifiedName[current]); Iterator<CsmOffsetableDeclaration> decls = CsmSelect.getDeclarations(context, filter); if (!decls.hasNext() && hasTemplateSuffix(qualifiedName[current])) { filter = createNamespaceFilter(trimTemplateSuffix(qualifiedName[current])); decls = CsmSelect.getDeclarations(context, filter); } handleNamespaceDecls(decls, cnn, current, result); if (!hasTemplateSuffix(qualifiedName[current])) { Set<CsmNamespace> handledNamespaces = new HashSet<>(); for (CsmNamespace nested : context.getNestedNamespaces()) { if (!handledNamespaces.contains(nested)) { handledNamespaces.add(nested); if (qualifiedName[current].toString().equals(nested.getName().toString())) { resolveContext(nested, qualifiedName, current + 1, result); } } } } }