private void initRelativeNamespace(ISourceModule sourceModule, int offset, String lastWord) { String nsName = lastWord; String fullName = lastWord; nsPrefix = null; if (lastWord.lastIndexOf(NamespaceReference.NAMESPACE_SEPARATOR) > 0) { nsPrefix = lastWord.substring(0, lastWord.lastIndexOf(NamespaceReference.NAMESPACE_SEPARATOR)); nsName = nsName.substring(0, nsName.lastIndexOf(NamespaceReference.NAMESPACE_SEPARATOR) + 1); try { namespaces = PHPModelUtils.getNamespaceOf(nsName, sourceModule, offset, null, null); } catch (ModelException e) { if (DLTKCore.DEBUG) { e.printStackTrace(); } } } else { namespaces = PhpModelAccess.NULL_TYPES; } if (lastWord.startsWith(NamespaceReference.NAMESPACE_DELIMITER)) { nsPrefix = null; } else { currentNS = null; try { IModelElement enclosingElement = getEnclosingElement(); if (enclosingElement != null) { IType type = (IType) enclosingElement.getAncestor(IModelElement.TYPE); if (type != null && type.getParent() instanceof IType) { type = (IType) type.getParent(); } if (type != null && (PHPFlags.isNamespace(type.getFlags()))) { currentNS = type; fullName = NamespaceReference.NAMESPACE_SEPARATOR + currentNS.getElementName() + NamespaceReference.NAMESPACE_SEPARATOR + lastWord; } else { } } } catch (ModelException e1) { e1.printStackTrace(); } if (currentNS != null) { if (nsPrefix == null) { nsPrefix = currentNS.getElementName(); } else { nsPrefix = currentNS.getElementName() + NamespaceReference.NAMESPACE_SEPARATOR + nsPrefix; } } } IDLTKSearchScope scope = SearchEngine.createSearchScope(sourceModule.getScriptProject()); if (fullName.startsWith(NamespaceReference.NAMESPACE_DELIMITER)) { fullName = fullName.substring(1); } possibleNamespaces = PhpModelAccess.getDefault() .findNamespaces(null, fullName, MatchRule.PREFIX, 0, 0, scope, null); }
@Override public Image getImage(Object element) { IModelElement modelElement = null; if (element instanceof ExternalProjectFragment) { return PHPPluginImages.get(PHPPluginImages.IMG_OBJS_LIBRARY); } if (element instanceof IncludePath) { Object entry = ((IncludePath) element).getEntry(); // An included PHP project if (entry instanceof IBuildpathEntry) { int entryKind = ((IBuildpathEntry) entry).getEntryKind(); if (entryKind == IBuildpathEntry.BPE_PROJECT) { return PHPPluginImages.get(PHPPluginImages.IMG_OBJS_PHP_PROJECT); } // A library if (entryKind == IBuildpathEntry.BPE_LIBRARY || entryKind == IBuildpathEntry.BPE_CONTAINER) { return PHPPluginImages.get(PHPPluginImages.IMG_OBJS_LIBRARY); } } if (entry instanceof ExternalProjectFragment) { return PHPPluginImages.get(PHPPluginImages.IMG_OBJS_LIBRARY); } // Folder in the include path, should have same image as in the PHP // Explorer . if (entry instanceof IFolder) { IModelElement createdScriptFolder = DLTKCore.create((IFolder) entry); if (null == createdScriptFolder) return getImage(entry); return getImage(createdScriptFolder); } if (entry instanceof IResource) { return (getImage((IResource) entry)); } return null; } if (element instanceof IResource) { modelElement = DLTKCore.create((IResource) element); } else if (element instanceof IModelElement) { modelElement = (IModelElement) element; } if (modelElement != null) { IScriptProject project = modelElement.getScriptProject(); if (!project.isOnBuildpath(modelElement)) { // not in build path, // hence: hollow, // non-pakg icons if (modelElement.getElementType() == IModelElement.SOURCE_MODULE) return PHPPluginImages.get(PHPPluginImages.IMG_OBJS_CUNIT_RESOURCE); if (modelElement.getElementType() == IModelElement.PROJECT_FRAGMENT || modelElement.getElementType() == IModelElement.SCRIPT_FOLDER) return PHPPluginImages.get(PHPPluginImages.IMG_OBJS_PHP_FOLDER); } else { // in build path ... if (modelElement.getElementType() == IModelElement.SCRIPT_FOLDER || element instanceof IFolder) return PHPPluginImages.get(PHPPluginImages.IMG_OBJS_PHPFOLDER_ROOT); } } try { if (element instanceof IType && PHPFlags.isTrait(((IType) element).getFlags())) { return PHPPluginImages.get(PHPPluginImages.IMG_OBJS_TRAIT); } } catch (ModelException e) { } if (element != null) { for (ILabelProvider provider : TreeContentProviderRegistry.getInstance().getLabelProviders()) { Image image = provider.getImage(element); if (image != null) { return image; } } } return super.getImage(element); }