⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 javaclasslaunchdelegate.java

📁 AStar算法
💻 JAVA
字号:
/******************************************************************************* * Copyright © 2008 Sandro Badame. All Rights Reserved. *  * This software and the accompanying materials is available under the  * Eclipse Public License 1.0 (EPL), which accompanies this distribution, and is * available at http://visualjpf.sourceforge.net/epl-v10.html ******************************************************************************/package com.javapathfinder.vjp.delegates;import java.io.IOException;import java.io.PipedInputStream;import java.io.PipedOutputStream;import java.io.PrintStream;import org.eclipse.core.resources.IFile;import org.eclipse.core.resources.IProject;import org.eclipse.core.resources.IResource;import org.eclipse.core.runtime.CoreException;import org.eclipse.core.runtime.IPath;import org.eclipse.jface.action.IAction;import org.eclipse.jface.viewers.ISelection;import org.eclipse.jface.viewers.TreeSelection;import org.eclipse.ui.IObjectActionDelegate;import org.eclipse.ui.IWorkbenchPart;import org.eclipse.jdt.core.JavaModelException;import org.eclipse.jdt.internal.core.CompilationUnit;import com.javapathfinder.vjp.VJP;import com.javapathfinder.vjp.verify.VerifyJob;/** * JavaClassLaunchDelegate is used then the 'Verify...' selection is chosen * from right clicking on a Java Source file.  *  * Once run the package and name of the class is determined. A JPF configuration * file is then created in the same directory as the source file, with the  * target property defined.  *  * A VerifyJob is then created and scheduled to be executed. *  * While this class does use discouraged objects (namely  * org.eclipse.jdt.internal.core.CompilationUnit) * it got the job done on time. So this definatly needs to be changed to using * the proper classes.  *  * @author Sandro Badame * */public class JavaClassLaunchDelegate implements IObjectActionDelegate {    private CompilationUnit compilation;    //TODO stop using the Compilation unit class  public void selectionChanged(IAction action, ISelection selection) {    TreeSelection s = (TreeSelection) selection;    compilation = (CompilationUnit) s.getFirstElement();  }  public void run(IAction action) {    String p = new String(compilation.getPackageName()[0]);    String m = new String(compilation.getMainTypeName());    String target = p + "." + m;        try {      IFile f = (IFile)compilation.getCorrespondingResource();      IProject project = f.getProject();      IPath path = f.getProjectRelativePath().removeLastSegments(1).append(m+".jpf");      IFile file = project.getFile(path);      if (file.getLocation().toFile().createNewFile()){        file.refreshLocal(IResource.DEPTH_INFINITE, null);        file = project.getFile(path);        initJPFFile(file, target);      }      VerifyJob.verify(file, file.getProject(), true);    } catch (JavaModelException e) {      VJP.logError(e.getMessage(),e);    } catch (IOException e) {      VJP.logError(e.getMessage(),e);         } catch (CoreException e) {      VJP.logError(e.getMessage(),e);         }   }    private void initJPFFile(IFile file, String target) throws IOException, CoreException{    PipedInputStream fileData = new PipedInputStream();    PipedOutputStream propertyData = new PipedOutputStream(fileData);    PrintStream writer = new PrintStream(propertyData);    writer.println("#Target class");    writer.println("target="+target);        writer.flush();    writer.close();    file.setContents(fileData, true, true, null);    fileData.close();  }  public void setActivePart(IAction action, IWorkbenchPart targetPart) {}}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -