Search in sources :

Example 1 with VisibilityModifier

use of org.eclipse.titan.designer.AST.TTCN3.definitions.VisibilityModifier in project titan.EclipsePlug-ins by eclipse.

the class ChangeCreator method calculateEditLocations.

private WorkspaceJob calculateEditLocations(final NavigableSet<ILocateableNode> nodes, final IFile file, final List<Location> locations_out) throws CoreException {
    final WorkspaceJob job = new WorkspaceJob("MinimizeVisibilityRefactoring: calculate edit locations") {

        @Override
        public IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
            final int BUF_LEN = 8;
            try {
                InputStream is = file.getContents();
                InputStreamReader isr = new InputStreamReader(is);
                int currOffset = 0;
                char[] content = new char[BUF_LEN];
                for (ILocateableNode node : nodes) {
                    int toSkip = node.getLocation().getOffset() - currOffset;
                    if (toSkip < 0) {
                        ErrorReporter.logError("MinimizeVisibilityRefactoring.ChangeCreator: Negative skip value" + " while parsing file: " + file.getName() + ", offset: " + node.getLocation().getOffset() + "->" + currOffset);
                        continue;
                    }
                    isr.skip(toSkip);
                    isr.read(content);
                    String str = new String(content);
                    VisibilityModifier vm = parseVisibilityModifier(str);
                    int vmLen = 0;
                    if (vm != null) {
                        switch(vm) {
                            case Public:
                                vmLen = 7;
                                break;
                            case Friend:
                                vmLen = 7;
                                break;
                            case Private:
                                vmLen = 8;
                                break;
                        }
                    }
                    locations_out.add(new Location(node.getLocation().getFile(), node.getLocation().getLine(), node.getLocation().getOffset(), node.getLocation().getOffset() + vmLen));
                    currOffset = node.getLocation().getOffset() + BUF_LEN;
                }
                isr.close();
                is.close();
            } catch (IOException ioe) {
                ErrorReporter.logError("MinimizeVisibilityRefactoring.CreateChange: " + "Error while reading source project.");
                return Status.CANCEL_STATUS;
            }
            return Status.OK_STATUS;
        }
    };
    job.setUser(true);
    job.schedule();
    return job;
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) InputStreamReader(java.io.InputStreamReader) InputStream(java.io.InputStream) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) ILocateableNode(org.eclipse.titan.designer.AST.ILocateableNode) VisibilityModifier(org.eclipse.titan.designer.AST.TTCN3.definitions.VisibilityModifier) IOException(java.io.IOException) Location(org.eclipse.titan.designer.AST.Location)

Aggregations

IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1 ILocateableNode (org.eclipse.titan.designer.AST.ILocateableNode)1 Location (org.eclipse.titan.designer.AST.Location)1 VisibilityModifier (org.eclipse.titan.designer.AST.TTCN3.definitions.VisibilityModifier)1