Java Code Examples for org.eclipse.core.filesystem.IFileStore#getName()

The following examples show how to use org.eclipse.core.filesystem.IFileStore#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: XdsSymbolParser.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Reports the identifier is already defined for the given symbol.
 * 
 * @param symbol the already defined symbol
 * @param position the position of duplicated identifier 
 */
protected void errorIdentifierAlreadyDefined( IModulaSymbol symbol
                                            , TextPosition position ) 
{
    String moduleFileName = "";
    IFileStore sourceFileStore = ModulaSymbolUtils.getSourceFileStore(symbol);
    if (sourceFileStore != null) {
        moduleFileName = sourceFileStore.getName();
    }
    
    int line   = 0;
    int column = 0; 
    TextPosition symbolPosition = symbol.getPosition();
    if (symbolPosition != null) {
        line   = symbolPosition.getLine();
        column = symbolPosition.getColumn();
    }
    String name = symbol.getName();
    error( position, name.length(), XdsMessages.IdentifierAlreadyDefined
         , name, moduleFileName, line, column ); 
}
 
Example 2
Source File: GoNavigatorLabelProvider.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
@Override
protected DefaultGetStyledStringSwitcher getStyledString_switcher() {
	return new DefaultGetStyledStringSwitcher() {
		@Override
		public StyledString visitGoPathElement(GoPathElement goPathElement) {
			return getStyledText_GoPathElement(goPathElement);
		}
		
		@Override
		public StyledString visitFileStoreElement(IFileStore fileStore) {
			return new StyledString(fileStore.getName());
		}
		
		@Override
		public StyledString visitBundleElement(IBundleModelElement bundleElement) {
			return new BundleModelGetStyledStringSwitcher() {
				
			}.switchBundleElement(bundleElement);
		}
		
	};
}
 
Example 3
Source File: RemoteImportTracesOperation.java    From tracecompass with Eclipse Public License 2.0 5 votes vote down vote up
private IResource downloadFileTrace(IFileStore trace, IFolder traceFolder, IProgressMonitor monitor) throws CoreException, IOException, InterruptedException {

        IFolder folder = traceFolder;
        String traceName = trace.getName();

        traceName = TmfTraceCoreUtils.validateName(traceName);

        IResource resource = folder.findMember(traceName);
        if ((resource != null) && resource.exists()) {
            String newName = fConflictHandler.checkAndHandleNameClash(resource.getFullPath(), monitor);
            if (newName == null) {
                return null;
            }
            traceName = newName;
        }
        SubMonitor subMonitor = SubMonitor.convert(monitor, 1);
        subMonitor.beginTask(RemoteMessages.RemoteImportTracesOperation_DownloadTask, 1);

        IPath destination = folder.getLocation().addTrailingSeparator().append(traceName);
        IFileInfo info = trace.fetchInfo();
        subMonitor.setTaskName(RemoteMessages.RemoteImportTracesOperation_DownloadTask + ' ' + trace.getName() + '/' + trace.getName());
        try (InputStream in = trace.openInputStream(EFS.NONE, new NullProgressMonitor())) {
            copy(in, folder, destination, subMonitor, info.getLength());
        }
        folder.refreshLocal(IResource.DEPTH_INFINITE, null);
        return folder.findMember(traceName);
    }
 
Example 4
Source File: CloakingUtils.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param fileStore
 *            the file store to be checked
 * @return true if the file should be cloaked, false otherwise
 */
public static boolean isFileCloaked(IFileStore fileStore) {
	String filename = fileStore.getName();
    String filepath = fileStore.toString();
    String[] expressions = getCloakedExpressions();
    for (String expression : expressions) {
        if (filename.matches(expression) || filepath.matches(expression)) {
            return true;
        }
    }
    return false;
}
 
Example 5
Source File: FileTree.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
public IFileInfo getFileInfo(IFileStore store) {
	IFileInfo result = infoMap.get(store);
	if (result != null) {
		return result;
	}
	return new FileInfo(store.getName());
}
 
Example 6
Source File: CompilationUnitDocumentProvider.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Creates a fake compilation unit.
 *
 * @param editorInput the URI editor input
 * @return the fake compilation unit
 * @since 3.3
 */
private ICompilationUnit createFakeCompiltationUnit(IURIEditorInput editorInput) {
	try {
		final URI uri= editorInput.getURI();
		final IFileStore fileStore= EFS.getStore(uri);
		final IPath path= URIUtil.toPath(uri);
		String fileStoreName= fileStore.getName();
		if (fileStoreName == null || path == null)
			return null;

		WorkingCopyOwner woc= new WorkingCopyOwner() {
			/*
			 * @see org.eclipse.jdt.core.WorkingCopyOwner#createBuffer(org.eclipse.jdt.core.ICompilationUnit)
			 * @since 3.2
			 */
			@Override
			public IBuffer createBuffer(ICompilationUnit workingCopy) {
				return new DocumentAdapter(workingCopy, fileStore, path);
			}
		};

		IClasspathEntry[] cpEntries= null;
		IJavaProject jp= findJavaProject(path);
		if (jp != null)
			cpEntries= jp.getResolvedClasspath(true);

		if (cpEntries == null || cpEntries.length == 0)
			cpEntries= new IClasspathEntry[] { JavaRuntime.getDefaultJREContainerEntry() };

		final ICompilationUnit cu= woc.newWorkingCopy(fileStoreName, cpEntries, getProgressMonitor());

		if (!isModifiable(editorInput))
			JavaModelUtil.reconcile(cu);

		return cu;
	} catch (CoreException ex) {
		return null;
	}
}
 
Example 7
Source File: CompilationDirector.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
private FrontEndLanguage findLanguage(IFileStore source, String defaultLanguage) {
    String fullName = source.getName();
    if (languages.containsKey(fullName))
        // full-name matching is stronger
        return languages.get(fullName);
    String extension = new Path(fullName).getFileExtension();
    // a null or .mdd extension means we should use the default extension
    // (if available)
    if (extension == null || extension.equals(MDD_FILE_EXTENSION)) {
        if (defaultLanguage == null)
            return null;
        extension = defaultLanguage;
    }
    return languages.get(extension);
}
 
Example 8
Source File: XdsNonWorkspaceCompilationUnit.java    From xds-ide with Eclipse Public License 1.0 4 votes vote down vote up
public XdsNonWorkspaceCompilationUnit(IFileStore absoluteFile, IXdsProject xdsProject, IXdsContainer parent) {
	super(xdsProject, parent);
	this.absoluteFile = absoluteFile;
	this.name = absoluteFile.getName();
}
 
Example 9
Source File: RemoteGenerateManifestOperation.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
/**
 * Scan traceFolder for files that match the patterns specified in the
 * template file. When there is a match, the trace package element is used
 * to determine the trace name and trace type.
 *
 * @param traceGroup
 *                The parent trace group element
 * @param parentElement
 *                The immediate parent trace group or folder element
 * @param traceFolder
 *                The folder to scan
 * @param recursionLevel
 *                The recursion level (needed to find directory traces under the traceFolder
 * @param monitor
 *                The progress monitor
 * @throws CoreException
 *                Thrown by the file system implementation
 * @throws InterruptedException
 *                Thrown if operation was cancelled
 */
private void generateElementsFromArchive(
        final RemoteImportTraceGroupElement traceGroup,
        final TracePackageElement parentElement,
        final IFileStore traceFolder,
        final int recursionLevel,
        IProgressMonitor monitor)
                throws CoreException, InterruptedException {

    int localRecursionLevel = recursionLevel + 1;
    IFileStore[] sources = traceFolder.childStores(EFS.NONE, monitor);

    for (int i = 0; i < sources.length; i++) {
        ModalContext.checkCanceled(monitor);
        SubMonitor subMonitor = SubMonitor.convert(monitor, sources.length);

        IFileStore fileStore = sources[i];
        IPath fullArchivePath = TmfTraceCoreUtils.newSafePath(fileStore.toURI().getPath());

        IFileInfo sourceInfo = fileStore.fetchInfo();
        if (!sourceInfo.isDirectory()) {

            String rootPathString = traceGroup.getRootImportPath();
            IPath rootPath = TmfTraceCoreUtils.newSafePath(rootPathString);
            IPath relativeTracePath = Path.EMPTY;
            if (rootPath.isPrefixOf(fullArchivePath)) {
                relativeTracePath = fullArchivePath.makeRelativeTo(rootPath);
            }
            Entry<Pattern, TracePackageTraceElement> matchingTemplateEntry = getMatchingTemplateElement(relativeTracePath);
            if (matchingTemplateEntry != null) {
                TracePackageTraceElement matchingTemplateElement = matchingTemplateEntry.getValue();
                String traceType = matchingTemplateElement.getTraceType();

                // If a single file is part of a directory trace, use the parent directory instead
                TracePackageElement parent = parentElement;
                if (matchesDirectoryTrace(relativeTracePath, matchingTemplateEntry)) {
                    fullArchivePath = fullArchivePath.removeLastSegments(1);
                    fDirectoryTraces.add(fullArchivePath);
                    fileStore = fileStore.getParent();
                    sourceInfo = fileStore.fetchInfo();
                    parent = parentElement.getParent();
                    // Let the auto-detection choose the best trace type
                    traceType = null;
                } else if ((localRecursionLevel > 1) && (!traceGroup.isRecursive())) {
                    // Don't consider file traces on level 2 if it's not recursive
                    continue;
                }

                if (sourceInfo.getLength() > 0 || sourceInfo.isDirectory()) {
                    // Only add non-empty files
                    String traceName = fullArchivePath.lastSegment();
                    String fileName = fileStore.getName();
                    // create new elements to decouple from input elements
                    TracePackageTraceElement traceElement = new TracePackageTraceElement(parent, traceName, traceType);
                    RemoteImportTraceFilesElement tracePackageFilesElement = new RemoteImportTraceFilesElement(traceElement, fileName, fileStore);
                    tracePackageFilesElement.setVisible(false);
                }
            }
        } else {
            if (traceGroup.isRecursive() || localRecursionLevel < 2) {
                RemoteImportFolderElement folder = new RemoteImportFolderElement(parentElement, fileStore.getName());
                generateElementsFromArchive(traceGroup, folder, fileStore, localRecursionLevel, subMonitor);
            }
        }
    }
}
 
Example 10
Source File: RemoteImportTracesOperation.java    From tracecompass with Eclipse Public License 2.0 4 votes vote down vote up
private IResource downloadDirectoryTrace(IFileStore trace, IFolder traceFolder, IProgressMonitor monitor) throws CoreException, IOException, InterruptedException {

        IFileStore[] sources = trace.childStores(EFS.NONE, monitor);

        // Don't import just the metadata file
        if (sources.length > 1) {
            String traceName = trace.getName();

            traceName = TmfTraceCoreUtils.validateName(traceName);

            IFolder folder = traceFolder.getFolder(traceName);
            String newName = fConflictHandler.checkAndHandleNameClash(folder.getFullPath(), monitor);
            if (newName == null) {
                return null;
            }

            folder = traceFolder.getFolder(newName);
            folder.create(true, true, null);

            SubMonitor subMonitor = SubMonitor.convert(monitor, sources.length);
            subMonitor.beginTask(RemoteMessages.RemoteImportTracesOperation_DownloadTask, sources.length);

            for (IFileStore source : sources) {
                if (subMonitor.isCanceled()) {
                    throw new InterruptedException();
                }

                IPath destination = folder.getLocation().addTrailingSeparator().append(source.getName());
                IFileInfo info = source.fetchInfo();
                // TODO allow for downloading index directory and files
                if (!info.isDirectory()) {
                    SubMonitor childMonitor = subMonitor.newChild(1);
                    childMonitor.setTaskName(RemoteMessages.RemoteImportTracesOperation_DownloadTask + ' ' + trace.getName() + '/' + source.getName());
                    try (InputStream in = source.openInputStream(EFS.NONE, new NullProgressMonitor())) {
                        copy(in, folder, destination, childMonitor, info.getLength());
                    }
                }
            }
            folder.refreshLocal(IResource.DEPTH_INFINITE, null);
            return folder;
        }
        return null;
    }
 
Example 11
Source File: ContentDescriberUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Returns an {@link IFile} for the file backing an input stream. This method
 * is tailored to work with
 * {@link org.eclipse.core.runtime.content.IContentDescriber}, using it
 * elsewhere will likely not work.
 * 
 * @return the filename, or null if it could not be determined
 */
public static IFile resolveFileFromInputStream(
    InputStream contentInputStream) {
  try {

    if (!(contentInputStream instanceof LazyInputStream)) {
      return null;
    }

    Class<?> c = contentInputStream.getClass();

    Field in = c.getDeclaredField("in");
    in.setAccessible(true);
    Object lazyFileInputStreamObj = in.get(contentInputStream);

    if (lazyFileInputStreamObj == null) {
      return null;
    }

    if (!Class.forName(
        "org.eclipse.core.internal.resources.ContentDescriptionManager$LazyFileInputStream").isAssignableFrom(
        lazyFileInputStreamObj.getClass())) {
      return null;
    }

    Field target = lazyFileInputStreamObj.getClass().getDeclaredField(
        "target");
    target.setAccessible(true);
    Object fileStoreObj = target.get(lazyFileInputStreamObj);
    if (fileStoreObj == null) {
      return null;
    }

    if (!(fileStoreObj instanceof IFileStore)) {
      return null;
    }

    IFileStore fileStore = (IFileStore) fileStoreObj;

    String name = fileStore.getName();

    if (name == null || name.length() == 0) {
      return null;
    }

    IFile[] files = ResourcesPlugin.getWorkspace().getRoot().findFilesForLocationURI(
        fileStore.toURI());
    return files.length > 0 ? files[0] : null;

  } catch (Throwable e) {
    // Ignore on purpose
  }

  return null;
}
 
Example 12
Source File: HTMLContentAssistProcessor.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param offset
 * @param valuePrefix
 * @param editorStoreURI
 *            The URI of the current file. We use this to eliminate it from list of possible completions.
 * @param parent
 *            The parent we're grabbing children for.
 * @return
 * @throws CoreException
 */
protected List<ICompletionProposal> suggestChildrenOfFileStore(int offset, String valuePrefix, URI editorStoreURI,
		IFileStore parent) throws CoreException
{
	IFileStore[] children = parent.childStores(EFS.NONE, new NullProgressMonitor());
	if (children == null || children.length == 0)
	{
		return Collections.emptyList();
	}

	List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>();
	Image[] userAgentIcons = this.getAllUserAgentIcons();
	for (IFileStore f : children)
	{
		String name = f.getName();
		// Don't include the current file in the list
		// FIXME this is a possible perf issue. We really only need to check for editor store on local URIs
		if (name.charAt(0) == '.' || f.toURI().equals(editorStoreURI))
		{
			continue;
		}
		if (valuePrefix != null && valuePrefix.length() > 0 && !name.startsWith(valuePrefix))
		{
			continue;
		}

		IFileInfo info = f.fetchInfo();
		boolean isDir = false;
		if (info.isDirectory())
		{
			isDir = true;
		}

		// build proposal
		int replaceOffset = offset;
		int replaceLength = 0;
		if (this._replaceRange != null)
		{
			replaceOffset = this._replaceRange.getStartingOffset();
			replaceLength = this._replaceRange.getLength();
		}

		CommonCompletionProposal proposal = new URIPathProposal(name, replaceOffset, replaceLength, isDir,
				userAgentIcons);
		proposals.add(proposal);
	}
	return proposals;
}