Java 类org.eclipse.core.resources.IStorage 实例源码

项目:n4js    文件:N4JSStorage2UriMapper.java   
@Override
public URI getUri(IStorage storage) {
    if (!uriValidator.isPossiblyManaged(storage)) {
        return null;
    }
    URI uri = internalGetUri(storage);

    if (null == uri) {
        uri = super.getUri(storage);
    }

    if (uri != null && isValidUri(uri, storage)) {
        return uri;
    }
    return null;
}
项目:n4js    文件:NfarStorageMapper.java   
@Override
public Iterable<Pair<IStorage, IProject>> getStorages(URI uri) {
    if (uri.isArchive()) {
        URIBasedStorage storage = new URIBasedStorage(uri);
        String authority = uri.authority();
        URI archiveFileURI = URI.createURI(authority.substring(0, authority.length() - 1));
        Optional<? extends IN4JSEclipseProject> optionalProject = eclipseCore.findProject(archiveFileURI);
        if (optionalProject.isPresent()) {
            return Collections.singletonList(Tuples.<IStorage, IProject> create(storage, optionalProject.get()
                    .getProject()));
        } else {
            return Collections.singletonList(Tuples.create(storage, null));
        }
    } else {
        return Collections.emptyList();
    }
}
项目:n4js    文件:BuildInstruction.java   
private boolean shouldGenerate(Resource resource, IProject aProject) {
    try {
        Iterable<Pair<IStorage, IProject>> storages = storage2UriMapper.getStorages(resource.getURI());
        for (Pair<IStorage, IProject> pair : storages) {
            if (pair.getFirst() instanceof IFile && pair.getSecond().equals(aProject)) {
                IFile file = (IFile) pair.getFirst();
                int findMaxProblemSeverity = file.findMaxProblemSeverity(null, true, IResource.DEPTH_INFINITE);
                // If the generator itself placed an error marker on the resource, we have to ignore that error.
                // Easiest way here is to remove that error marker-type and look for other severe errors once more:
                if (findMaxProblemSeverity == IMarker.SEVERITY_ERROR) {
                    // clean
                    GeneratorMarkerSupport generatorMarkerSupport = injector
                            .getInstance(GeneratorMarkerSupport.class);
                    generatorMarkerSupport.deleteMarker(resource);
                    // and recompute:
                    findMaxProblemSeverity = file.findMaxProblemSeverity(null, true, IResource.DEPTH_INFINITE);
                }
                // the final decision to build:
                return findMaxProblemSeverity != IMarker.SEVERITY_ERROR;
            }
        }
        return false;
    } catch (CoreException exc) {
        throw new WrappedException(exc);
    }
}
项目:n4js    文件:N4JSResourceLinkHelper.java   
@Override
public IStructuredSelection findSelection(final IEditorInput input) {
    final IStructuredSelection selection = super.findSelection(input);
    if (null == selection || selection.isEmpty() && input instanceof XtextReadonlyEditorInput) {
        try {
            final IStorage storage = ((XtextReadonlyEditorInput) input).getStorage();
            if (storage instanceof URIBasedStorage) {
                final URI uri = ((URIBasedStorage) storage).getURI();
                if (uri.isFile()) {
                    final File file = new File(uri.toFileString());
                    if (file.exists() && file.isFile()) {
                        final Node node = getResourceNode(file);
                        if (null != node) {
                            return new StructuredSelection(node);
                        }
                    }
                }
            }
        } catch (final CoreException e) {
            LOGGER.error("Error while extracting storage from read-only Xtext editor input.", e);
            return EMPTY;
        }
    }
    return selection;
}
项目:n4js    文件:N4MFEditor.java   
/**
 * Provides input so that the Project Explorer can locate the editor's input in its tree.
 */
@Override
public ShowInContext getShowInContext() {
    IEditorInput editorInput = getEditorInput();
    if (editorInput instanceof FileEditorInput) {
        FileEditorInput fei = (FileEditorInput) getEditorInput();
        return new ShowInContext(fei.getFile(), null);
    } else if (editorInput instanceof XtextReadonlyEditorInput) {
        XtextReadonlyEditorInput readOnlyEditorInput = (XtextReadonlyEditorInput) editorInput;
        IStorage storage;
        try {
            storage = readOnlyEditorInput.getStorage();
            return new ShowInContext(storage.getFullPath(), null);
        } catch (CoreException e) {
            // Do nothing
        }
    }
    return new ShowInContext(null, null);
}
项目:dsl-devkit    文件:CheckMarkerUpdateJob.java   
/**
 * Gets an {@link IFile} from the {@link IStorage2UriMapper} corresponding to given {@link URI}. If none
 * could be found, <code>null</code> is returned.
 * 
 * @param storage2UriMapper
 *          the storage to URI mapper
 * @param fileUri
 *          the URI
 * @return the file from the storage to URI mapper or <code>null</code> if no match found
 */
private IFile getFileFromStorageMapper(final IStorage2UriMapper storage2UriMapper, final URI fileUri) {
  if (storage2UriMapper == null) {
    return null; // Should not occur
  }

  for (Pair<IStorage, IProject> storage : storage2UriMapper.getStorages(fileUri)) {
    if (storage.getFirst() instanceof IFile) {
      return (IFile) storage.getFirst();
    }
  }
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug(MessageFormat.format("Could not find storage for URI {0}", fileUri.toString())); //$NON-NLS-1$
  }
  return null;
}
项目:dsl-devkit    文件:AbstractUtilTest.java   
/**
 * Prepare mocks for all tests.
 */
public static void prepareMocksBase() {
  oldDesc = mock(IResourceDescription.class);
  newDesc = mock(IResourceDescription.class);
  delta = mock(Delta.class);
  resource = mock(Resource.class);
  uriCorrect = mock(URI.class);
  when(uriCorrect.isPlatformResource()).thenReturn(true);
  when(uriCorrect.isFile()).thenReturn(true);
  when(uriCorrect.toFileString()).thenReturn(DUMMY_PATH);
  when(uriCorrect.toPlatformString(true)).thenReturn(DUMMY_PATH);
  when(delta.getNew()).thenReturn(newDesc);
  when(delta.getOld()).thenReturn(oldDesc);
  when(delta.getUri()).thenReturn(uriCorrect);
  when(resource.getURI()).thenReturn(uriCorrect);
  file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(uriCorrect.toPlatformString(true)));
  Iterable<Pair<IStorage, IProject>> storages = singleton(Tuples.<IStorage, IProject> create(file, file.getProject()));
  mapperCorrect = mock(Storage2UriMapperImpl.class);
  when(mapperCorrect.getStorages(uriCorrect)).thenReturn(storages);
}
项目:dsl-devkit    文件:ValidMarkerUpdateJob.java   
/**
 * Gets an {@link IFile} from the {@link IStorage2UriMapper} corresponding to given {@link URI}. If none
 * could be found, <code>null</code> is returned.
 *
 * @param uri
 *          the URI
 * @return the file from the storage to URI mapper or <code>null</code> if no match found
 */
private IFile getFileFromStorageMapper(final URI uri) {
  if (storage2UriMapper == null) {
    return null; // Should not occur
  }

  for (Pair<IStorage, IProject> storage : storage2UriMapper.getStorages(uri)) {
    if (storage.getFirst() instanceof IFile) {
      return (IFile) storage.getFirst();
    }
  }
  if (LOGGER.isDebugEnabled()) {
    LOGGER.debug(MessageFormat.format("Could not find storage for URI {0}", uri.toString())); //$NON-NLS-1$
  }
  return null;
}
项目:dsl-devkit    文件:RuntimeProjectUtil.java   
/**
 * Returns the file {@link IFile} based on its {@link URI}.
 *
 * @param uri
 *          the URI of the resource for which an IFile is to be returned
 * @param mapper
 *          class returning e.g. set of storages {@link IStorage} matching given URI; injected by concrete BuilderParticipant
 * @return the file associated with given URI
 */
public static IFile findFileStorage(final URI uri, final IStorage2UriMapper mapper) {
  Iterable<Pair<IStorage, IProject>> storages = mapper.getStorages(uri);
  try {
    Pair<IStorage, IProject> fileStorage = Iterables.find(storages, new Predicate<Pair<IStorage, IProject>>() {
      @Override
      public boolean apply(final Pair<IStorage, IProject> input) {
        IStorage storage = input.getFirst();
        if (storage instanceof IFile) {
          return true;
        }
        return false;
      }
    });

    return (IFile) fileStorage.getFirst();
  } catch (NoSuchElementException e) {
    LOGGER.debug("Cannot find file storage for " + uri); //$NON-NLS-1$
    return null;
  }
}
项目:bts    文件:Storage2UriMapperJavaImpl.java   
@Override
protected URI internalGetUri(IStorage storage) {
    if (!uriValidator.isPossiblyManaged(storage))
        return null;
    URI uri = super.internalGetUri(storage);
    if (uri != null)
        return uri;
    if (storage instanceof IJarEntryResource) {
        final IJarEntryResource storage2 = (IJarEntryResource) storage;
        Map<URI, IStorage> data = getAllEntries(storage2.getPackageFragmentRoot());
        for (Map.Entry<URI, IStorage> entry : data.entrySet()) {
            if (entry.getValue().equals(storage2))
                return entry.getKey();
        }
    }
    return null;
}
项目:bts    文件:SourceAttachmentPackageFragmentRootWalker.java   
/**
 * Converts the physical URI to a logic URI based on the bundle symbolic name.
 */
protected URI getLogicalURI(URI uri, IStorage storage, TraversalState state) {
    if (bundleSymbolicName != null) {
        URI logicalURI = URI.createPlatformResourceURI(bundleSymbolicName, false);
        List<?> parents = state.getParents();
        for (int i = 1; i < parents.size(); i++) {
            Object obj = parents.get(i);
            if (obj instanceof IPackageFragment) {
                logicalURI = logicalURI.appendSegments(((IPackageFragment) obj).getElementName().split("\\."));
            } else if (obj instanceof IJarEntryResource) {
                logicalURI = logicalURI.appendSegment(((IJarEntryResource) obj).getName());
            } else if (obj instanceof IFolder) {
                logicalURI = logicalURI.appendSegment(((IFolder) obj).getName());
            }
        }
        return logicalURI.appendSegment(uri.lastSegment());
    }
    return uri;
}
项目:bts    文件:Storage2UriMapperImpl.java   
/**
 * @since 2.4
 */
public Map<URI, IStorage> getAllEntries(IContainer container) {
    final Map<URI,IStorage> result = newLinkedHashMap();
    try {
        container.accept(new IResourceVisitor() {
            public boolean visit(IResource resource) throws CoreException {
                if (resource instanceof IFile) {
                    final IFile storage = (IFile) resource;
                    URI uri = getUri(storage);
                    if (uri != null)
                        result.put(uri, storage);
                }
                if (resource instanceof IFolder) {
                    return isHandled((IFolder)resource);
                }
                return true;
            }
        });
    } catch (CoreException e) {
        log.error(e.getMessage(), e);
    }
    return result;
}
项目:bts    文件:UriValidator.java   
/**
 * @since 2.4
 */
public boolean canBuild(URI uri, IStorage storage) {
    if (uri == null)
        return false;
    IResourceServiceProvider resourceServiceProvider = registry.getResourceServiceProvider(uri);
    if (resourceServiceProvider != null) {
        if (resourceServiceProvider instanceof IResourceUIServiceProviderExtension) {
            return ((IResourceUIServiceProviderExtension) resourceServiceProvider).canBuild(uri, storage);
        } else if (resourceServiceProvider instanceof IResourceUIServiceProvider) {
            return ((IResourceUIServiceProvider) resourceServiceProvider).canHandle(uri, storage);
        } else {
            return resourceServiceProvider.canHandle(uri);
        }
    }
    return false;
}
项目:bts    文件:WorkspaceProjectsStateHelper.java   
public Collection<URI> initContainedURIs(String containerHandle) {
    try {
        IPath projectPath = new Path(null, containerHandle).makeAbsolute();
        if (projectPath.segmentCount()!=1) 
            return Collections.emptySet();
        IProject project = getWorkspaceRoot().getProject(containerHandle);
        if (project != null && isAccessibleXtextProject(project)) {
            Map<URI, IStorage> entries = getMapper().getAllEntries(project);
            return entries.keySet();
        }
    } catch (IllegalArgumentException e) {
        if (log.isDebugEnabled())
            log.debug("Cannot init contained URIs for containerHandle '" + containerHandle + "'", e);
    }
    return Collections.emptyList();
}
项目:bts    文件:JavaProjectsStateHelper.java   
protected IPackageFragmentRoot getJarWithEntry(URI uri) {
    Iterable<Pair<IStorage, IProject>> storages = getStorages(uri);
    IPackageFragmentRoot result = null;
    for (Pair<IStorage, IProject> storage2Project : storages) {
        IStorage storage = storage2Project.getFirst();
        if (storage instanceof IJarEntryResource) {
            IPackageFragmentRoot fragmentRoot = ((IJarEntryResource) storage).getPackageFragmentRoot();
            if (fragmentRoot != null) {
                IJavaProject javaProject = fragmentRoot.getJavaProject();
                if (isAccessibleXtextProject(javaProject.getProject()))
                    return fragmentRoot;
                if (result != null)
                    result = fragmentRoot;
            }
        }
    }
    return result;
}
项目:bts    文件:CompareInputResourceProvider.java   
protected IResource getResource(ITypedElement typedElement) {
    IResource result = null;
    if (typedElement instanceof IResourceProvider) {
        IResourceProvider resourceProvider = (IResourceProvider) typedElement;
        result = resourceProvider.getResource();
    } else if (typedElement instanceof org.eclipse.team.internal.ui.StorageTypedElement) {
        org.eclipse.team.internal.ui.StorageTypedElement storageTypedElement = (org.eclipse.team.internal.ui.StorageTypedElement) typedElement;
        IStorage bufferedStorage = storageTypedElement.getBufferedStorage();
        result = getExistingFile(bufferedStorage != null ? bufferedStorage.getFullPath() : Path.EMPTY);
    }
    if (result == null) {
        IProject projectFromInput = getProjectFromInput();
        List<String> path = getPath(typedElement);
        for (int i = 0; i < path.size() && result == null; i++) {
            IProject project = getWorkspaceRoot().getProject(path.get(i));
            String subPath = IPath.SEPARATOR + Joiner.on(IPath.SEPARATOR).join(path.subList(i, path.size()));
            if (project.exists()) {
                result = getExistingFile(new Path(subPath));
            } else if (projectFromInput != null) {
                String pathInProject = IPath.SEPARATOR + projectFromInput.getName() + subPath;
                result = getExistingFile(new Path(pathInProject));
            }
        }
    }
    return result;
}
项目:bts    文件:GlobalURIEditorOpener.java   
protected IEditorPart openDefaultEditor(URI uri, EReference crossReference, int indexInList, boolean select) {
    Iterator<Pair<IStorage, IProject>> storages = mapper.getStorages(uri.trimFragment()).iterator();
    if (storages != null && storages.hasNext()) {
        try {
            IStorage storage = storages.next().getFirst();
            IEditorPart editor = null;
            if (storage instanceof IFile) {
                editor = openDefaultEditor((IFile) storage);
            } else {
                editor = openDefaultEditor(storage, uri);
            }
            selectAndReveal(editor, uri, crossReference, indexInList, select);
            return editor;
        } catch (WrappedException e) {
            logger.error("Error while opening editor part for EMF URI '" + uri + "'", e.getCause());
        } catch (PartInitException partInitException) {
            logger.error("Error while opening editor part for EMF URI '" + uri + "'", partInitException);
        }
    }
    return null;
}
项目:bts    文件:ResourceForIEditorInputFactory.java   
protected ResourceSet getResourceSet(IStorage storage) {
    if (storage instanceof IFile) {
        return resourceSetProvider.get(((IFile) storage).getProject());
    }
    if (workspace != null && storage != null) {
        IPath path = storage.getFullPath();
        if (path != null && !path.isEmpty()) {
            String firstSegment = path.segment(0);
            if (firstSegment != null) {
                IProject project = workspace.getRoot().getProject(firstSegment);
                if (project.isAccessible()) {
                    return resourceSetProvider.get(project);
                }
            }
        }
    }
    return resourceSetProvider.get(null);
}
项目:bts    文件:XtextDocumentProvider.java   
@Override
public String getEncoding(Object element) {
    String encoding = super.getEncoding(element);
    if (encoding == null && element instanceof IStorageEditorInput) {
        try {
            IStorage storage = ((IStorageEditorInput) element).getStorage();
            URI uri = storage2UriMapper.getUri(storage);
            if (uri != null) {
                encoding = encodingProvider.getEncoding(uri);
            } else if (storage instanceof IEncodedStorage) {
                encoding = ((IEncodedStorage)storage).getCharset();
            }
        } catch (CoreException e) {
            throw new WrappedException(e);
        }
    }
    return encoding;
}
项目:bts    文件:LoadingResourceAccess.java   
public <R> R readOnly(URI targetURI, IUnitOfWork<R, ResourceSet> work) {
    Iterable<Pair<IStorage, IProject>> storages = storage2UriMapper.getStorages(targetURI.trimFragment());
    Iterator<Pair<IStorage, IProject>> iterator = storages.iterator();
    while(iterator.hasNext()) {
        Pair<IStorage, IProject> pair = iterator.next();
        IProject project = pair.getSecond();
        if (project != null) {
            ResourceSet resourceSet = resourceSetProvider.get(project);
            if(resourceSet != null)
                resourceSet.getResource(targetURI, true);
                try {
                    return work.exec(resourceSet);
                } catch (Exception e) {
                    throw new WrappedException(e);
                }
        }
    }
    return null;
}
项目:bts    文件:ResourceAccess.java   
public <R> R readOnly(URI targetURI, IUnitOfWork<R, ResourceSet> work) {
    URI resourceURI = targetURI.trimFragment();
    Iterable<Pair<IStorage, IProject>> storages = storage2UriMapper.getStorages(resourceURI);
    Iterator<Pair<IStorage, IProject>> iterator = storages.iterator();
    ResourceSet resourceSet = fallBackResourceSet; 
    while(iterator.hasNext()) {
        Pair<IStorage, IProject> pair = iterator.next();
        IProject project = pair.getSecond();
        if (project != null) {
            resourceSet = getResourceSet(project);
            break;
        }
    }
    if(resourceSet != null) {
        resourceSet.getResource(resourceURI, true);
        try {
            return work.exec(resourceSet);
        } catch (Exception e) {
            throw new WrappedException(e);
        }
    }
    return null;
}
项目:bts    文件:LanguageSpecificURIEditorOpener.java   
public IEditorPart open(URI uri, EReference crossReference, int indexInList, boolean select) {
    Iterator<Pair<IStorage, IProject>> storages = mapper.getStorages(uri.trimFragment()).iterator();
    if (storages != null && storages.hasNext()) {
        try {
            IStorage storage = storages.next().getFirst();
            // TODO we should create a JarEntryEditorInput if storage is a NonJavaResource from jdt to match the editor input used when double clicking on the same resource in a jar.
            IEditorInput editorInput = (storage instanceof IFile) ? new FileEditorInput((IFile) storage)
                    : new XtextReadonlyEditorInput(storage);
            IWorkbenchPage activePage = workbench.getActiveWorkbenchWindow().getActivePage();
            IEditorPart editor = IDE.openEditor(activePage, editorInput, editorID);
            selectAndReveal(editor, uri, crossReference, indexInList, select);
            return EditorUtils.getXtextEditor(editor);
        } catch (WrappedException e) {
            logger.error("Error while opening editor part for EMF URI '" + uri + "'", e.getCause());
        } catch (PartInitException partInitException) {
            logger.error("Error while opening editor part for EMF URI '" + uri + "'", partInitException);
        }
    }
    return null;
}
项目:bts    文件:ProjectUtil.java   
/**
 * @return null if there is no such file or the file is not editable
 */
public IFile findFileStorage(final URI uri, final boolean validateEdit) {
    Iterable<Pair<IStorage, IProject>> storages = mapper.getStorages(uri);
    try {
        Pair<IStorage, IProject> fileStorage = Iterables.find(storages, new Predicate<Pair<IStorage, IProject>>() {
            public boolean apply(Pair<IStorage, IProject> input) {
                IStorage storage = input.getFirst();
                if (storage instanceof IFile) {
                    IFile file = (IFile) storage;
                    return file.isAccessible()
                            && (!validateEdit || !file.isReadOnly() || workspace.validateEdit(new IFile[] { file },
                                    null).isOK());
                }
                return false;
            }
        });
        return (IFile) fileStorage.getFirst();
    } catch (NoSuchElementException e) {
        return null;
    }
}
项目:gwt-eclipse-plugin    文件:UiBinderJavaValidator.java   
private Set<IPath> getUiXmlWorkspaceRelativePaths(
    TypeDeclaration ownerTypeDecl) {
  Set<IPath> paths = new HashSet<IPath>();

  String ownerTypeName = ownerTypeDecl.resolveBinding().getQualifiedName();
  for (IType uiBinderSubtype : uiBinderToOwner.getUiBinderTypes(ownerTypeName)) {
    IPath uiXmlClasspathRelativePath = ownerToUiXml.getUiXmlPath(uiBinderSubtype);
    try {
      IStorage uiXmlFile = ClasspathResourceUtilities.resolveFile(
          uiXmlClasspathRelativePath, javaProject);

      // Verify that the ui.xml exists and is not in a JAR
      if (uiXmlFile instanceof IFile) {
        paths.add(uiXmlFile.getFullPath());
      }
    } catch (JavaModelException e) {
      GWTPluginLog.logError(e);
    }
  }
  return paths;
}
项目:SecureBPMN    文件:ActivitiMultiPageEditor.java   
public void doSave(IProgressMonitor monitor) {
  int activePage = getActivePage();
  if (activePage == 0) {
    getEditor(0).doSave(monitor);
  } else if (activePage == 1) {

    // Save BPMN editor contents
    getEditor(1).doSave(monitor);

    // sync Activiti Diagram
    DiagramEditorInput diagramEditorInput = (DiagramEditorInput) getEditor(0).getEditorInput();
    Diagram diagram = diagramEditorInput.getDiagram();
    FileEditorInput bpmn2EditorInput = (FileEditorInput) getEditor(1).getEditorInput();

    IStorage bpmnStorage = bpmn2EditorInput.getStorage();
    //DiagramUpdater.syncDiagram(diagramEditor, diagram, bpmnStorage);

    // Save BPMN editor contents
    getEditor(0).doSave(monitor);
  }
}
项目:SecureBPMN    文件:DiagramUpdater.java   
private static BpmnParser readBpmn(IStorage bpmnStorage) {

    BpmnParser bpmnParser = new BpmnParser();
    try {
      XMLInputFactory xif = XMLInputFactory.newInstance();
      InputStreamReader in = new InputStreamReader(bpmnStorage.getContents(), "UTF-8");
      XMLStreamReader xtr = xif.createXMLStreamReader(in);

      bpmnParser.parseBpmn(xtr);

      xtr.close();
      in.close();

    } catch (Exception e) {
      e.printStackTrace();
    }
    return bpmnParser;
  }
项目:PDFReporter-Studio    文件:SelectionHelper.java   
public static final void openEditor(String content, String name) {
    IStorageEditorInput input = streditors.get(content);
    if (input == null) {
        IStorage storage = new StringStorage(content);
        input = new StringInput(storage);
        streditors.put(content, input);
    }
    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    if (window == null)
        window = PlatformUI.getWorkbench().getWorkbenchWindows()[0];
    IWorkbenchPage page = window.getActivePage();
    try {
        IEditorReference[] er = page.findEditors(input, name, IWorkbenchPage.MATCH_INPUT);
        if (er != null)
            page.closeEditors(er, false);

        page.openEditor(input, name);
    } catch (PartInitException e) {
        UIUtils.showError(e);
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:NLSHintHelper.java   
public static IStorage getResourceBundle(IPackageFragmentRoot root, String packageName, String resourceName) throws JavaModelException {
    IPackageFragment packageFragment= root.getPackageFragment(packageName);
    if (packageFragment.exists()) {
        Object[] resources= packageFragment.isDefaultPackage() ? root.getNonJavaResources() : packageFragment.getNonJavaResources();
        for (int j= 0; j < resources.length; j++) {
            Object object= resources[j];
            if (JavaModelUtil.isOpenableStorage(object)) {
                IStorage storage= (IStorage)object;
                if (storage.getName().equals(resourceName)) {
                    return storage;
                }
            }
        }
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:NLSHintHelper.java   
public static IStorage getResourceBundle(IJavaProject javaProject, AccessorClassReference accessorClassReference) throws JavaModelException {
    String resourceBundle= accessorClassReference.getResourceBundleName();
    if (resourceBundle == null)
        return null;

    String resourceName= Signature.getSimpleName(resourceBundle) + NLSRefactoring.PROPERTY_FILE_EXT;
    String packName= Signature.getQualifier(resourceBundle);
    ITypeBinding accessorClass= accessorClassReference.getBinding();

    if (accessorClass.isFromSource())
        return getResourceBundle(javaProject, packName, resourceName);
    else if (accessorClass.getJavaElement() != null)
        return getResourceBundle((IPackageFragmentRoot)accessorClass.getJavaElement().getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT), packName, resourceName);

    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaElementLabels.java   
/**
 * Returns the styled label of the given object. The object must be of type {@link IJavaElement} or adapt to {@link IWorkbenchAdapter}.
 * If the element type is not known, the empty string is returned.
 * The returned label is BiDi-processed with {@link TextProcessor#process(String, String)}.
 *
 * @param obj object to get the label for
 * @param flags the rendering flags
 * @return the label or the empty string if the object type is not supported
 *
 * @since 3.4
 */
public static StyledString getStyledTextLabel(Object obj, long flags) {
    if (obj instanceof IJavaElement) {
        return getStyledElementLabel((IJavaElement) obj, flags);

    } else if (obj instanceof IResource) {
        return getStyledResourceLabel((IResource) obj);

    } else if (obj instanceof ClassPathContainer) {
        ClassPathContainer container= (ClassPathContainer) obj;
        return getStyledContainerEntryLabel(container.getClasspathEntry().getPath(), container.getJavaProject());

    } else if (obj instanceof IStorage) {
        return getStyledStorageLabel((IStorage) obj);

    } else if (obj instanceof IAdaptable) {
        IWorkbenchAdapter wbadapter= (IWorkbenchAdapter) ((IAdaptable)obj).getAdapter(IWorkbenchAdapter.class);
        if (wbadapter != null) {
            return Strings.markLTR(new StyledString(wbadapter.getLabel(obj)));
        }
    }
    return new StyledString();
}
项目:Eclipse-Postfix-Code-Completion    文件:JavaElementComparator.java   
private String getNonJavaElementLabel(Viewer viewer, Object element) {
    // try to use the workbench adapter for non - java resources or if not available, use the viewers label provider
    if (element instanceof IResource) {
        return ((IResource) element).getName();
    }
    if (element instanceof IStorage) {
        return ((IStorage) element).getName();
    }
    if (element instanceof IAdaptable) {
        IWorkbenchAdapter adapter= (IWorkbenchAdapter) ((IAdaptable) element).getAdapter(IWorkbenchAdapter.class);
        if (adapter != null) {
            return adapter.getLabel(element);
        }
    }
    if (viewer instanceof ContentViewer) {
        IBaseLabelProvider prov = ((ContentViewer) viewer).getLabelProvider();
        if (prov instanceof ILabelProvider) {
            return ((ILabelProvider) prov).getText(element);
        }
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion    文件:PropertyKeyHyperlinkDetector.java   
private static boolean isEclipseNLSAvailable(IStorageEditorInput editorInput) {
    IStorage storage;
    try {
        storage= editorInput.getStorage();
    } catch (CoreException ex) {
        return false;
    }
    if (!(storage instanceof IJarEntryResource))
        return false;

    IJavaProject javaProject= ((IJarEntryResource) storage).getPackageFragmentRoot().getJavaProject();

    if (javaProject == null || !javaProject.exists())
        return false;

    try {
        return javaProject.findType("org.eclipse.osgi.util.NLS") != null; //$NON-NLS-1$
    } catch (JavaModelException e) {
        return false;
    }
}
项目:Eclipse-Postfix-Code-Completion    文件:FindBrokenNLSKeysAction.java   
public static IStorage getResourceBundle(ICompilationUnit compilationUnit) throws JavaModelException {
    if (compilationUnit == null)
        return null;

    if (!ActionUtil.isOnBuildPath(compilationUnit))
        return null;

    IType[] types= compilationUnit.getTypes();
    if (types.length != 1)
        return null;

    if (!isPotentialNLSAccessor(compilationUnit))
        return null;

    return NLSHintHelper.getResourceBundle(compilationUnit);
}
项目:Eclipse-Postfix-Code-Completion    文件:NonJavaElementFilter.java   
@Override
public boolean select(Viewer viewer, Object parent, Object element) {
    if (element instanceof IJavaElement)
        return true;

    if (element instanceof IResource) {
        IProject project= ((IResource)element).getProject();
        return project == null || !project.isOpen();
    }

    // Exclude all IStorage elements which are neither Java elements nor resources
    if (element instanceof IStorage)
        return false;

    return true;
}
项目:sadlos2    文件:SadlDirtyStateEditorSupport.java   
protected URI getOwlURI(URIConverter conv, URI sadlURI) {
    URI norm = conv.normalize(sadlURI);
    if (norm.isPlatformResource()) {
        List<String> seg = Lists.newArrayList(norm.trimFileExtension()
                .appendFileExtension(ResourceManager.getOwlFileExtension()).segmentsList()); // "owl").segmentsList());
        seg.remove(0);
        seg.add(1, "OwlModels");
        norm = URI.createPlatformResourceURI(Joiner.on("/").join(seg), false);
        for (Pair<IStorage,IProject> storages: mapper.getStorages(norm)) {
            IStorage s = storages.getFirst();
            if (s instanceof IResource) {
                norm = URI.createURI(((IResource) s).getLocationURI()
                        .toString());
            }
        }
    }
    return norm;
}
项目:syncope    文件:TemplateEditorInput.java   
public IStorage getStorage() throws CoreException {
    return new IStorage() {
        public InputStream getContents() throws CoreException {
            return new ByteArrayInputStream(inputString.getBytes(
                java.nio.charset.Charset.defaultCharset()));
        }

        public IPath getFullPath() {
            return null;
        }

        public String getName() {
            return TemplateEditorInput.this.getName();
        }

        public boolean isReadOnly() {
            return false;
        }

        public <T> T getAdapter(final Class<T> adapter) {
            return null;
        }
    };
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:NLSHintHelper.java   
public static IStorage getResourceBundle(IPackageFragmentRoot root, String packageName, String resourceName) throws JavaModelException {
    IPackageFragment packageFragment= root.getPackageFragment(packageName);
    if (packageFragment.exists()) {
        Object[] resources= packageFragment.isDefaultPackage() ? root.getNonJavaResources() : packageFragment.getNonJavaResources();
        for (int j= 0; j < resources.length; j++) {
            Object object= resources[j];
            if (JavaModelUtil.isOpenableStorage(object)) {
                IStorage storage= (IStorage)object;
                if (storage.getName().equals(resourceName)) {
                    return storage;
                }
            }
        }
    }
    return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:NLSHintHelper.java   
public static IStorage getResourceBundle(IJavaProject javaProject, AccessorClassReference accessorClassReference) throws JavaModelException {
    String resourceBundle= accessorClassReference.getResourceBundleName();
    if (resourceBundle == null)
        return null;

    String resourceName= Signature.getSimpleName(resourceBundle) + NLSRefactoring.PROPERTY_FILE_EXT;
    String packName= Signature.getQualifier(resourceBundle);
    ITypeBinding accessorClass= accessorClassReference.getBinding();

    if (accessorClass.isFromSource())
        return getResourceBundle(javaProject, packName, resourceName);
    else if (accessorClass.getJavaElement() != null)
        return getResourceBundle((IPackageFragmentRoot)accessorClass.getJavaElement().getAncestor(IJavaElement.PACKAGE_FRAGMENT_ROOT), packName, resourceName);

    return null;
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaElementLabels.java   
/**
 * Returns the styled label of the given object. The object must be of type {@link IJavaElement} or adapt to {@link IWorkbenchAdapter}.
 * If the element type is not known, the empty string is returned.
 * The returned label is BiDi-processed with {@link TextProcessor#process(String, String)}.
 *
 * @param obj object to get the label for
 * @param flags the rendering flags
 * @return the label or the empty string if the object type is not supported
 *
 * @since 3.4
 */
public static StyledString getStyledTextLabel(Object obj, long flags) {
    if (obj instanceof IJavaElement) {
        return getStyledElementLabel((IJavaElement) obj, flags);

    } else if (obj instanceof IResource) {
        return getStyledResourceLabel((IResource) obj);

    } else if (obj instanceof ClassPathContainer) {
        ClassPathContainer container= (ClassPathContainer) obj;
        return getStyledContainerEntryLabel(container.getClasspathEntry().getPath(), container.getJavaProject());

    } else if (obj instanceof IStorage) {
        return getStyledStorageLabel((IStorage) obj);

    } else if (obj instanceof IAdaptable) {
        IWorkbenchAdapter wbadapter= (IWorkbenchAdapter) ((IAdaptable)obj).getAdapter(IWorkbenchAdapter.class);
        if (wbadapter != null) {
            return Strings.markLTR(new StyledString(wbadapter.getLabel(obj)));
        }
    }
    return new StyledString();
}
项目:Eclipse-Postfix-Code-Completion-Juno38    文件:JavaElementComparator.java   
private String getNonJavaElementLabel(Viewer viewer, Object element) {
    // try to use the workbench adapter for non - java resources or if not available, use the viewers label provider
    if (element instanceof IResource) {
        return ((IResource) element).getName();
    }
    if (element instanceof IStorage) {
        return ((IStorage) element).getName();
    }
    if (element instanceof IAdaptable) {
        IWorkbenchAdapter adapter= (IWorkbenchAdapter) ((IAdaptable) element).getAdapter(IWorkbenchAdapter.class);
        if (adapter != null) {
            return adapter.getLabel(element);
        }
    }
    if (viewer instanceof ContentViewer) {
        IBaseLabelProvider prov = ((ContentViewer) viewer).getLabelProvider();
        if (prov instanceof ILabelProvider) {
            return ((ILabelProvider) prov).getText(element);
        }
    }
    return null;
}