Search in sources :

Example 46 with IFileInfo

use of org.eclipse.core.filesystem.IFileInfo in project titan.EclipsePlug-ins by eclipse.

the class TITANBuilderResourceVisitor method visit.

@Override
public boolean visit(final IResource resource) {
    if (resource == null || !resource.isAccessible()) {
        return false;
    }
    final URI resourceLocation = resource.getLocationURI();
    resourcename = resource.getName();
    if (resourcename == null || resourcename.startsWith(".")) {
        return false;
    }
    try {
        final URI resolved = resource.getWorkspace().getPathVariableManager().resolveURI(resourceLocation);
        final IFileStore store = EFS.getStore(resolved);
        final IFileInfo fileInfo = store.fetchInfo();
        if (!fileInfo.exists()) {
            ErrorReporter.logError("The resource `" + resource.getFullPath() + "' points to a non-existing location.");
            return false;
        }
    } catch (CoreException e) {
        ErrorReporter.logExceptionStackTrace(e);
        return false;
    }
    switch(resource.getType()) {
        case IResource.FILE:
            if (!ResourceExclusionHelper.isDirectlyExcluded((IFile) resource) && !helper.isExcludedByRegexp(resourcename)) {
                boolean inExcluded = false;
                final IPath resourceFullPath = resource.getFullPath();
                for (int i = 0; i < excludedFolders.size(); i++) {
                    final IPath excludedFolder = excludedFolders.get(i);
                    if (excludedFolder.isPrefixOf(resourceFullPath)) {
                        inExcluded = true;
                        break;
                    }
                }
                IFile file = (IFile) resource;
                if (inExcluded) {
                    excludedFiles.put(resource.getName(), file);
                    return false;
                }
                boolean inCentralStorage = false;
                for (int i = 0; i < centralStorages.size(); i++) {
                    final URI centralFolder = centralStorages.get(i);
                    if (centralFolder.getHost() == resourceLocation.getHost() && resourceLocation.getPath().startsWith(centralFolder.getPath())) {
                        inCentralStorage = true;
                        break;
                    }
                }
                file = (IFile) resource;
                if (inCentralStorage) {
                    if (file.getLocation() == null) {
                        centralStorageFiles.put(file.getName(), file);
                    } else {
                        centralStorageFiles.put(file.getLocation().toOSString(), file);
                    }
                } else {
                    files.put(resourcename, file);
                }
            } else if (resourceLocation != null) {
                excludedFiles.put(resource.getName(), (IFile) resource);
            }
            return false;
        case IResource.FOLDER:
            for (IContainer workingDirectory : workingDirectories) {
                if (workingDirectory.equals(resource)) {
                    return false;
                }
            }
            try {
                if (ResourceExclusionHelper.isDirectlyExcluded((IFolder) resource) || helper.isExcludedByRegexp(resourcename)) {
                    excludedFolders.add(resource.getFullPath());
                }
                if (TRUE.equals(resource.getPersistentProperty(new QualifiedName(FolderBuildPropertyData.QUALIFIER, FolderBuildPropertyData.CENTRAL_STORAGE_PROPERTY)))) {
                    centralStorages.add(resourceLocation);
                }
            } catch (CoreException e) {
                return false;
            }
            break;
        default:
    }
    return true;
}
Also used : IFileInfo(org.eclipse.core.filesystem.IFileInfo) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) IPath(org.eclipse.core.runtime.IPath) QualifiedName(org.eclipse.core.runtime.QualifiedName) IFileStore(org.eclipse.core.filesystem.IFileStore) IContainer(org.eclipse.core.resources.IContainer) URI(java.net.URI) IFolder(org.eclipse.core.resources.IFolder)

Example 47 with IFileInfo

use of org.eclipse.core.filesystem.IFileInfo in project titan.EclipsePlug-ins by eclipse.

the class PreprocessedTokenStream method processIncludeDirective.

/**
 * Adds a new lexer to the lexer stack to read tokens from the included
 * file
 *
 * @param fileName
 *                the file name paramtere of the #include directive
 */
private void processIncludeDirective(final PreprocessorDirective ppDirective) {
    if (ppDirective.str == null || "".equals(ppDirective.str)) {
        TITANMarker marker = new TITANMarker("File name was not provided", ppDirective.line, -1, -1, IMarker.SEVERITY_ERROR, IMarker.PRIORITY_NORMAL);
        unsupportedConstructs.add(marker);
        return;
    }
    IFile includedFile = GlobalParser.getProjectSourceParser(actualFile.getProject()).getTTCN3IncludeFileByName(ppDirective.str);
    if (includedFile == null) {
        TITANMarker marker = new TITANMarker(MessageFormat.format("Included file `{0}'' could not be found", ppDirective.str), ppDirective.line, -1, -1, IMarker.SEVERITY_ERROR, IMarker.PRIORITY_NORMAL);
        unsupportedConstructs.add(marker);
        return;
    }
    // check extension
    if (!GlobalParser.TTCNIN_EXTENSION.equals(includedFile.getFileExtension())) {
        TITANMarker marker = new TITANMarker(MessageFormat.format("File `{0}'' does not have the `{1}'' extension", ppDirective.str, GlobalParser.TTCNIN_EXTENSION), ppDirective.line, -1, -1, IMarker.SEVERITY_WARNING, IMarker.PRIORITY_NORMAL);
        warnings.add(marker);
    }
    // check if the file is already loaded into an editor
    String code = null;
    if (EditorTracker.containsKey(includedFile)) {
        List<ISemanticTITANEditor> editors = EditorTracker.getEditor(includedFile);
        ISemanticTITANEditor editor = editors.get(0);
        IDocument document = editor.getDocument();
        code = document.get();
    }
    // create lexer and set it up
    Reader reader = null;
    CharStream charStream = null;
    Ttcn3Lexer lexer = null;
    int rootInt;
    if (code != null) {
        reader = new StringReader(code);
        charStream = new UnbufferedCharStream(reader);
        lexer = new Ttcn3Lexer(charStream);
        lexer.setTokenFactory(new CommonTokenFactory(true));
        rootInt = code.length();
    } else {
        try {
            InputStreamReader temp = new InputStreamReader(includedFile.getContents());
            if (!includedFile.getCharset().equals(temp.getEncoding())) {
                try {
                    temp.close();
                } catch (IOException e) {
                    ErrorReporter.logWarningExceptionStackTrace(e);
                }
                temp = new InputStreamReader(includedFile.getContents(), includedFile.getCharset());
            }
            reader = new BufferedReader(temp);
        } catch (CoreException e) {
            ErrorReporter.logExceptionStackTrace(e);
            return;
        } catch (UnsupportedEncodingException e) {
            ErrorReporter.logExceptionStackTrace(e);
            return;
        }
        charStream = new UnbufferedCharStream(reader);
        lexer = new Ttcn3Lexer(charStream);
        lexer.setTokenFactory(new CommonTokenFactory(true));
        lexerListener = new TitanListener();
        // remove ConsoleErrorListener
        lexer.removeErrorListeners();
        lexer.addErrorListener(lexerListener);
        IFileStore store;
        try {
            store = EFS.getStore(includedFile.getLocationURI());
        } catch (CoreException e) {
            ErrorReporter.logExceptionStackTrace(e);
            return;
        }
        IFileInfo fileInfo = store.fetchInfo();
        rootInt = (int) fileInfo.getLength();
    }
    lexer.setTokenFactory(new CommonTokenFactory(true));
    lexer.setTTCNPP();
    lexer.initRootInterval(rootInt);
    lexer.setActualFile(includedFile);
    // add the lexer to the stack of lexers
    tokenStreamStack.push(new TokenStreamData(lexer, includedFile, reader));
    if (parser != null) {
        parser.setActualFile(includedFile);
    }
    includedFiles.add(includedFile);
}
Also used : IFile(org.eclipse.core.resources.IFile) CommonTokenFactory(org.antlr.v4.runtime.CommonTokenFactory) InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) CharStream(org.antlr.v4.runtime.CharStream) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream) TitanListener(org.eclipse.titan.common.parsers.TitanListener) TITANMarker(org.eclipse.titan.common.parsers.TITANMarker) IFileInfo(org.eclipse.core.filesystem.IFileInfo) CoreException(org.eclipse.core.runtime.CoreException) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) IFileStore(org.eclipse.core.filesystem.IFileStore) UnbufferedCharStream(org.antlr.v4.runtime.UnbufferedCharStream) ISemanticTITANEditor(org.eclipse.titan.designer.editors.ISemanticTITANEditor) IDocument(org.eclipse.jface.text.IDocument)

Example 48 with IFileInfo

use of org.eclipse.core.filesystem.IFileInfo in project erlide_eclipse by erlang.

the class EditorUtility method getEditorInput.

private static IEditorInput getEditorInput(final IErlElement element0) {
    IErlElement element = element0;
    final IResource resource = element.getResource();
    if (resource instanceof IFile) {
        IFile file = (IFile) resource;
        file = EditorUtility.resolveFile(file);
        return new FileEditorInput(file);
    }
    String filePath = element.getFilePath();
    while (filePath == null) {
        final IParent parent = element.getParent();
        if (parent instanceof IErlElement) {
            element = (IErlElement) parent;
            filePath = element.getFilePath();
        } else {
            break;
        }
    }
    if (filePath != null) {
        final IPath path = new Path(filePath);
        IFileStore fileStore = EFS.getLocalFileSystem().getStore(path.removeLastSegments(1));
        fileStore = fileStore.getChild(path.lastSegment());
        final IFileInfo fetchInfo = fileStore.fetchInfo();
        if (!fetchInfo.isDirectory() && fetchInfo.exists()) {
            if (element instanceof IErlModule && element.getParent() instanceof IErlExternal) {
                return new ErlangExternalEditorInput(fileStore, (IErlModule) element);
            }
            return new FileStoreEditorInput(fileStore);
        }
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IParent(org.erlide.engine.model.IParent) IErlElement(org.erlide.engine.model.IErlElement) IFileInfo(org.eclipse.core.filesystem.IFileInfo) IErlExternal(org.erlide.engine.model.root.IErlExternal) IFileEditorInput(org.eclipse.ui.IFileEditorInput) FileEditorInput(org.eclipse.ui.part.FileEditorInput) IErlModule(org.erlide.engine.model.root.IErlModule) IFileStore(org.eclipse.core.filesystem.IFileStore) IResource(org.eclipse.core.resources.IResource) FileStoreEditorInput(org.eclipse.ui.ide.FileStoreEditorInput)

Aggregations

IFileInfo (org.eclipse.core.filesystem.IFileInfo)48 IFileStore (org.eclipse.core.filesystem.IFileStore)32 CoreException (org.eclipse.core.runtime.CoreException)22 IOException (java.io.IOException)13 URI (java.net.URI)12 IPath (org.eclipse.core.runtime.IPath)11 IFile (org.eclipse.core.resources.IFile)10 Test (org.junit.Test)8 URISyntaxException (java.net.URISyntaxException)7 OutputStream (java.io.OutputStream)6 IRemoteFileProxy (org.eclipse.linuxtools.profiling.launch.IRemoteFileProxy)6 BufferedReader (java.io.BufferedReader)5 InputStreamReader (java.io.InputStreamReader)5 ITextFileBuffer (org.eclipse.core.filebuffers.ITextFileBuffer)5 IStatus (org.eclipse.core.runtime.IStatus)5 IDocument (org.eclipse.jface.text.IDocument)5 InputStream (java.io.InputStream)4 Path (org.eclipse.core.runtime.Path)4 Status (org.eclipse.core.runtime.Status)4 Reader (java.io.Reader)3