utils.java
来自「plugin for eclipse」· Java 代码 · 共 96 行
JAVA
96 行
package isis.tinydt;
import isis.anp.nesc.ot.FunctionDeclaration;
import isis.anp.nesc.ot.Outline;
import isis.anp.nesc.ot.ParameterDeclaration;
import isis.anp.nesc.ot.types.FunctionType;
import java.util.Iterator;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.Path;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.console.IConsoleConstants;
import org.eclipse.ui.console.IConsoleView;
import org.eclipse.ui.ide.IDE;
public class Utils
{
static public String getLocationFromFullResourcePath( String resourcePath )
{
Path path = new Path(resourcePath);
String proj = path.segment(0);
String file = path.removeFirstSegments(1).toString();
IProject p = ResourcesPlugin.getWorkspace().getRoot().getProject(proj);
if( p==null || p.getLocation()==null || file==null )
return null;
return p.getLocation().toString() + '/' + file;
}
static public String getFuncDeclString( FunctionDeclaration decl )
{
String s = decl.getName() + "(";
boolean first = true;
FunctionType ft = (FunctionType)decl.getType();
Iterator it = ft.getParameterTypeList().getParameterDeclarations().iterator();
while(it.hasNext())
{
ParameterDeclaration pd = (ParameterDeclaration) it.next();
if(!first)
s += ", ";
Outline outline = new Outline();
pd.getType().outline(outline);
s += outline.toString();
first = false;
}
s += ")";
return s;
}
static public String addDotToFileName( String f )
{
IPath p1 = new Path(f);
String s1 = p1.lastSegment().toString();
String s2 = p1.removeLastSegments(1).toString();
String s3 = s2 + "/." + s1;
return s3;
}
static public String removeDotFromFileName( String f )
{
IPath p1 = new Path(f);
String s1 = p1.lastSegment().toString();
if( s1.charAt(0) == '.')
s1 = s1.substring(1);
String s2 = p1.removeLastSegments(1).toString();
String s3 = s2 + "/" + s1;
return s3;
}
static public void openEditor( String fileName )
{
IWorkbenchPage page = TinydtPlugin.getDefault().getWorkbench().getActiveWorkbenchWindow()
.getActivePage();
IFile f = ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(
new Path(fileName));
try
{
IDE.openEditor(page, f);
}
catch( Exception e )
{
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?