Search in sources :

Example 61 with ProjectSourceParser

use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.

the class RenameRefactoring method reanalyseAstAfterRefactoring.

/**
 * Re-analyzes AST after a rename-refactoring finished
 * At first reports outdating for the projects containing file has been refactored.
 * Then analyzes the project where the reanalysis started from (and its dependencies)
 * @param project  The project where the renaming started from
 * @param modules The modules containing renaming
 */
public static void reanalyseAstAfterRefactoring(final IProject project, final Set<Module> modules) {
    final ConcurrentLinkedQueue<WorkspaceJob> reportOutdatingJobs = new ConcurrentLinkedQueue<WorkspaceJob>();
    for (Module tempModule : modules) {
        final IFile f = (IFile) tempModule.getLocation().getFile();
        final WorkspaceJob op = new WorkspaceJob("Reports outdating for file: " + f.getName()) {

            @Override
            public IStatus runInWorkspace(final IProgressMonitor monitor) {
                IProject proj = f.getProject();
                reportOutdatingJobs.add(GlobalParser.getProjectSourceParser(proj).reportOutdating(f));
                return Status.OK_STATUS;
            }
        };
        op.setPriority(Job.LONG);
        op.setSystem(true);
        op.setUser(false);
        // waiting for f to be released
        op.setRule(f);
        op.setProperty(IProgressConstants.ICON_PROPERTY, ImageCache.getImageDescriptor("titan.gif"));
        reportOutdatingJobs.add(op);
        op.schedule();
    }
    // Waits for finishing update then analyzes all projects related to this change
    final WorkspaceJob op = new WorkspaceJob("Analyzes all projects related to this change") {

        @Override
        public IStatus runInWorkspace(final IProgressMonitor monitor) {
            while (!reportOutdatingJobs.isEmpty()) {
                WorkspaceJob job = reportOutdatingJobs.poll();
                try {
                    if (job != null) {
                        job.join();
                    }
                } catch (InterruptedException e) {
                    ErrorReporter.logExceptionStackTrace(e);
                }
            }
            // Now everything is released and reported outdated, so the analysis can start:
            final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(project);
            projectSourceParser.analyzeAll();
            return Status.OK_STATUS;
        }
    };
    op.setPriority(Job.LONG);
    op.setSystem(true);
    op.setUser(false);
    // op.setRule(file); //waiting for file to be released << Don't apply, it will wait forever!!!
    op.setProperty(IProgressConstants.ICON_PROPERTY, ImageCache.getImageDescriptor("titan.gif"));
    op.schedule();
}
Also used : IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFile(org.eclipse.core.resources.IFile) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) ConcurrentLinkedQueue(java.util.concurrent.ConcurrentLinkedQueue) Module(org.eclipse.titan.designer.AST.Module) ASN1Module(org.eclipse.titan.designer.AST.ASN1.definitions.ASN1Module) IProject(org.eclipse.core.resources.IProject) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 62 with ProjectSourceParser

use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.

the class NewASN1ModuleCreationWizardPage method validatePage.

/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.dialogs.WizardNewFileCreationPage#validatePage()
	 */
@Override
protected boolean validatePage() {
    if (!super.validatePage()) {
        return false;
    }
    final String extension = getContainerFullPath().append(getFileName()).getFileExtension();
    if (extension == null) {
        // test what will happen if we add the extension
        IPath fullPath = getContainerFullPath().append(getFileName()).addFileExtension(GlobalParser.SUPPORTED_ASN1_EXTENSIONS[1]);
        // path is invalid if any prefix is occupied by a file
        final IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        while (fullPath.segmentCount() > 1) {
            if (root.getFile(fullPath).exists()) {
                setErrorMessage(OCCUPIED);
                return false;
            }
            fullPath = fullPath.removeLastSegments(1);
        }
    } else {
        // test the extension
        boolean valid = false;
        for (int i = 0; i < GlobalParser.SUPPORTED_ASN1_EXTENSIONS.length; i++) {
            if (GlobalParser.SUPPORTED_ASN1_EXTENSIONS[i].equals(extension)) {
                valid = true;
                break;
            }
        }
        if (!valid) {
            setErrorMessage(ERROR_MESSAGE);
            return false;
        }
    }
    // check modulename
    final IPath path = getContainerFullPath();
    if (hasLicense && path != null) {
        final IFile file = createFileHandle(path.append(getFileName()));
        final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(file.getProject());
        if (projectSourceParser.getLastTimeChecked() == null) {
            final WorkspaceJob job = projectSourceParser.analyzeAll();
            if (job != null) {
                try {
                    job.join();
                } catch (InterruptedException e) {
                    ErrorReporter.logExceptionStackTrace(e);
                }
            }
        }
        final String moduleName = getFileName();
        final int dotIndex = moduleName.indexOf('.');
        final String dotLessModuleName = dotIndex == -1 ? moduleName : moduleName.substring(0, dotIndex);
        final Module module = projectSourceParser.getModuleByName(dotLessModuleName);
        if (module != null) {
            setErrorMessage("A module with the name " + moduleName + " already exists in the project " + file.getProject().getName());
            return false;
        }
    }
    // validate the syntax of the module name
    validateName();
    setErrorMessage(null);
    return true;
}
Also used : IFile(org.eclipse.core.resources.IFile) IPath(org.eclipse.core.runtime.IPath) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) Module(org.eclipse.titan.designer.AST.Module) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 63 with ProjectSourceParser

use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.

the class OrganizeImportsOp method run.

@Override
public void run(final IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
    final Set<IProject> projects = new HashSet<IProject>();
    for (final IFile f : files) {
        projects.add(f.getProject());
    }
    monitor.beginTask("Organize imports", files.size() + projects.size() * 20);
    for (final IProject project : projects) {
        final ProjectSourceParser parser = GlobalParser.getProjectSourceParser(project);
        parser.reportOutdating(files);
        final WorkspaceJob job = parser.analyzeAll();
        monitor.subTask("Waiting for semantic analysis on project " + project.getName());
        try {
            job.join();
        } catch (InterruptedException e) {
            ErrorReporter.logExceptionStackTrace("Error while waiting for the analysis to finish", e);
        }
        if (monitor.isCanceled()) {
            throw new InterruptedException();
        }
        monitor.worked(20);
    }
    final CompositeChange compChange = new CompositeChange("Organize imports");
    for (final IFile f : files) {
        monitor.subTask("Organizing " + f.getName());
        try {
            final TextFileChange change = OrganizeImports.organizeImportsChange(f);
            compChange.add(change);
            compChange.perform(new SubProgressMonitor(monitor, 1));
            final MultiTextEdit edit = (MultiTextEdit) change.getEdit();
            if (edit != null && edit.getChildrenSize() > 0) {
                final WorkspaceJob job = GlobalParser.getProjectSourceParser(f.getProject()).reportOutdating(f);
                try {
                    job.join();
                } catch (InterruptedException e) {
                    ErrorReporter.logExceptionStackTrace("Error while waiting for the outdating report to finish", e);
                }
            }
        } catch (CoreException e) {
            ErrorReporter.logExceptionStackTrace("Error while organizing file " + f.getName(), e);
        }
        if (monitor.isCanceled()) {
            throw new InterruptedException();
        }
        monitor.worked(1);
    }
    for (final IProject project : projects) {
        GlobalParser.getProjectSourceParser(project).analyzeAll();
    }
    monitor.done();
}
Also used : IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) CompositeChange(org.eclipse.ltk.core.refactoring.CompositeChange) TextFileChange(org.eclipse.ltk.core.refactoring.TextFileChange) IProject(org.eclipse.core.resources.IProject) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) SubProgressMonitor(org.eclipse.core.runtime.SubProgressMonitor) MultiTextEdit(org.eclipse.text.edits.MultiTextEdit) HashSet(java.util.HashSet)

Example 64 with ProjectSourceParser

use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.

the class ComponentGraphGenerator method analyzeProject.

private void analyzeProject() {
    final ProjectSourceParser projectSourceParser = GlobalParser.getProjectSourceParser(project);
    if (projectSourceParser.getLastTimeChecked() == null) {
        WorkspaceJob job = projectSourceParser.analyzeAll();
        while (job == null) {
            try {
                Thread.sleep(500);
                job = projectSourceParser.analyzeAll();
            } catch (InterruptedException e) {
                ErrorReporter.logExceptionStackTrace("Error while waiting for analyzis result", e);
            }
        }
        try {
            job.join();
        } catch (InterruptedException e) {
            ErrorReporter.logExceptionStackTrace("Error while waiting for analyzis result", e);
        }
    }
}
Also used : WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser)

Example 65 with ProjectSourceParser

use of org.eclipse.titan.designer.parsers.ProjectSourceParser in project titan.EclipsePlug-ins by eclipse.

the class AstWalkerJava method run.

public void run(IAction action) {
    /**/
    IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
    for (IProject p : projects) {
        if (p.getName().equals("org.eclipse.titan.codegenerator.output"))
            try {
                p.delete(true, true, null);
            } catch (Exception e) {
                e.printStackTrace();
            }
    }
    IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject("org.eclipse.titan.codegenerator.output");
    try {
        project.create(null);
        project.open(null);
        IProjectDescription description = project.getDescription();
        description.setNatureIds(new String[] { JavaCore.NATURE_ID });
        project.setDescription(description, null);
        IJavaProject javaProject = JavaCore.create(project);
        IFolder binFolder = project.getFolder("bin");
        binFolder.create(false, true, null);
        javaProject.setOutputLocation(binFolder.getFullPath(), null);
        List<IClasspathEntry> entries = new ArrayList<IClasspathEntry>();
        IVMInstall vmInstall = JavaRuntime.getDefaultVMInstall();
        LibraryLocation[] locations = JavaRuntime.getLibraryLocations(vmInstall);
        for (LibraryLocation element : locations) {
            entries.add(JavaCore.newLibraryEntry(element.getSystemLibraryPath(), null, null));
        }
        javaProject.setRawClasspath(entries.toArray(new IClasspathEntry[entries.size()]), null);
        IFolder sourceFolder = project.getFolder("src");
        sourceFolder.create(false, true, null);
        IPackageFragmentRoot root = javaProject.getPackageFragmentRoot(sourceFolder);
        IClasspathEntry[] oldEntries = javaProject.getRawClasspath();
        IClasspathEntry[] newEntries = new IClasspathEntry[oldEntries.length + 1];
        System.arraycopy(oldEntries, 0, newEntries, 0, oldEntries.length);
        newEntries[oldEntries.length] = JavaCore.newSourceEntry(root.getPath());
        javaProject.setRawClasspath(newEntries, null);
        javaProject.getPackageFragmentRoot(sourceFolder).createPackageFragment("org.eclipse.titan.codegenerator.javagen", false, null);
        javaProject.getPackageFragmentRoot(sourceFolder).createPackageFragment("org.eclipse.titan.codegenerator.TTCN3JavaAPI", false, null);
    } catch (Exception e) {
        e.printStackTrace();
    }
    String destpath = new String("");
    String wspath = ResourcesPlugin.getWorkspace().getRoot().getLocation().toString().replaceAll("/", "\\\\");
    destpath += wspath;
    destpath += "\\org.eclipse.titan.codegenerator.output\\src\\org\\eclipse\\titan\\codegenerator\\javagen\\";
    props.setProperty("javafile.path", destpath);
    /**/
    AstWalkerJava.files.clear();
    AstWalkerJava.fileNames.clear();
    AstWalkerJava.componentList.clear();
    AstWalkerJava.testCaseList.clear();
    AstWalkerJava.testCaseRunsOnList.clear();
    AstWalkerJava.functionList.clear();
    AstWalkerJava.functionRunsOnList.clear();
    AstWalkerJava.initOutputFolder();
    AstWalkerJava.getActiveProject();
    /*
		 * // init console logger IConsole myConsole = findConsole("myLogger");
		 * IWorkbenchPage page = window.getActivePage(); String id =
		 * IConsoleConstants.ID_CONSOLE_VIEW; IConsoleView view; try { view =
		 * (IConsoleView) page.showView(id); view.display(myConsole); } catch
		 * (PartInitException e) { // TODO Auto-generated catch block
		 * e.printStackTrace(); }
		 */
    // initialize common files
    myASTVisitor.currentFileName = "TTCN_functions";
    myASTVisitor.visualizeNodeToJava(myASTVisitor.importListStrings);
    myASTVisitor.visualizeNodeToJava("class TTCN_functions{\r\n}\r\n");
    Def_Template_Visit_Handler.isTemplate = false;
    final ProjectSourceParser sourceParser = GlobalParser.getProjectSourceParser(selectedProject);
    sourceParser.analyzeAll();
    logToConsole("Version built on 2016.10.24");
    logToConsole("Starting to generate files into: " + props.getProperty("javafile.path"));
    myASTVisitor visitor = new myASTVisitor();
    for (Module module : sourceParser.getModules()) {
        // start AST processing
        walkChildren(visitor, module.getOutlineChildren());
    }
    visitor.finish();
    logToConsole("Files generated into: " + props.getProperty("javafile.path"));
    // write additional classes
    Additional_Class_Writer additional_class = new Additional_Class_Writer();
    myASTVisitor.currentFileName = "HC";
    myASTVisitor.visualizeNodeToJava(myASTVisitor.importListStrings);
    myASTVisitor.visualizeNodeToJava(additional_class.writeHCClass());
    myASTVisitor.currentFileName = "HCType";
    myASTVisitor.visualizeNodeToJava(myASTVisitor.importListStrings);
    myASTVisitor.visualizeNodeToJava(additional_class.writeHCTypeClass());
    // clear lists
    logger.severe("analysis complete");
    /**/
    File fromdir = new File(wspath + "\\org.eclipse.titan.codegenerator\\src\\org\\eclipse\\titan\\codegenerator\\TTCN3JavaAPI\\");
    String toapidir = wspath + "\\org.eclipse.titan.codegenerator.output\\src\\org\\eclipse\\titan\\codegenerator\\TTCN3JavaAPI\\";
    File[] fromfiles = fromdir.listFiles();
    for (File f : fromfiles) {
        try {
            Files.copy(Paths.get(f.getAbsolutePath()), Paths.get(toapidir + f.getName()), StandardCopyOption.REPLACE_EXISTING);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    String tppath = wspath + "\\" + selectedProject.getFullPath().toString().split("/")[1] + "\\src\\";
    File tp_cfg_dir = new File(tppath);
    String togendir = wspath + "\\org.eclipse.titan.codegenerator.output\\src\\org\\eclipse\\titan\\codegenerator\\javagen\\";
    File[] from_testports_cfg = tp_cfg_dir.listFiles();
    for (File f : from_testports_cfg) {
        if (f.getName().endsWith(".java")) {
            try {
                Files.copy(Paths.get(f.getAbsolutePath()), Paths.get(togendir + f.getName()), StandardCopyOption.REPLACE_EXISTING);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        if (f.getName().endsWith(".cfg")) {
            try {
                Files.copy(Paths.get(f.getAbsolutePath()), Paths.get(toapidir + "cfg.cfg"), StandardCopyOption.REPLACE_EXISTING);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    }
    try {
        ResourcesPlugin.getWorkspace().getRoot().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor());
    } catch (Exception e) {
        e.printStackTrace();
    }
/**/
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ArrayList(java.util.ArrayList) LibraryLocation(org.eclipse.jdt.launching.LibraryLocation) IProject(org.eclipse.core.resources.IProject) PartInitException(org.eclipse.ui.PartInitException) IOException(java.io.IOException) ProjectSourceParser(org.eclipse.titan.designer.parsers.ProjectSourceParser) IPackageFragmentRoot(org.eclipse.jdt.core.IPackageFragmentRoot) IJavaProject(org.eclipse.jdt.core.IJavaProject) IVMInstall(org.eclipse.jdt.launching.IVMInstall) IProjectDescription(org.eclipse.core.resources.IProjectDescription) TTCN3Module(org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module) Module(org.eclipse.titan.designer.AST.Module) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder)

Aggregations

ProjectSourceParser (org.eclipse.titan.designer.parsers.ProjectSourceParser)72 Module (org.eclipse.titan.designer.AST.Module)51 IFile (org.eclipse.core.resources.IFile)34 ArrayList (java.util.ArrayList)23 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)23 IProject (org.eclipse.core.resources.IProject)19 TTCN3Module (org.eclipse.titan.designer.AST.TTCN3.definitions.TTCN3Module)14 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)12 IPreferencesService (org.eclipse.core.runtime.preferences.IPreferencesService)11 Identifier (org.eclipse.titan.designer.AST.Identifier)11 MultiTextEdit (org.eclipse.text.edits.MultiTextEdit)10 Location (org.eclipse.titan.designer.AST.Location)10 List (java.util.List)9 Reference (org.eclipse.titan.designer.AST.Reference)9 ImportModule (org.eclipse.titan.designer.AST.TTCN3.definitions.ImportModule)9 CoreException (org.eclipse.core.runtime.CoreException)8 TextSelection (org.eclipse.jface.text.TextSelection)8 TextFileChange (org.eclipse.ltk.core.refactoring.TextFileChange)8 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)7